Android: Generate JNI code for RTCStats

Bug: webrtc:8278
Change-Id: I183cec54ec3e97894db7f26e365eb9941a1ab458
Reviewed-on: https://webrtc-review.googlesource.com/25660
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20879}
This commit is contained in:
Magnus Jedvert 2017-11-24 18:46:15 +01:00 committed by Commit Bot
parent 6bd39025ec
commit c4c8876f70
6 changed files with 26 additions and 25 deletions

View file

@ -282,6 +282,9 @@ generate_jni("generated_peerconnection_jni") {
"api/org/webrtc/MediaConstraints.java", "api/org/webrtc/MediaConstraints.java",
"api/org/webrtc/NetworkMonitor.java", "api/org/webrtc/NetworkMonitor.java",
"api/org/webrtc/NetworkMonitorAutoDetect.java", "api/org/webrtc/NetworkMonitorAutoDetect.java",
"api/org/webrtc/RTCStats.java",
"api/org/webrtc/RTCStatsCollectorCallback.java",
"api/org/webrtc/RTCStatsReport.java",
] ]
jni_package = "" jni_package = ""
jni_generator_include = "//sdk/android/src/jni/jni_generator_helper.h" jni_generator_include = "//sdk/android/src/jni/jni_generator_helper.h"

View file

@ -103,4 +103,11 @@ public class RTCStats {
builder.append(value); builder.append(value);
} }
} }
// TODO(bugs.webrtc.org/8557) Use ctor directly with full Map type.
@SuppressWarnings("unchecked")
@CalledByNative
static RTCStats create(long timestampUs, String type, String id, Map members) {
return new RTCStats(timestampUs, type, id, members);
}
} }

View file

@ -13,5 +13,5 @@ package org.webrtc;
/** Interface for receiving stats reports (see webrtc::RTCStatsCollectorCallback). */ /** Interface for receiving stats reports (see webrtc::RTCStatsCollectorCallback). */
public interface RTCStatsCollectorCallback { public interface RTCStatsCollectorCallback {
/** Called when the stats report is ready. */ /** Called when the stats report is ready. */
public void onStatsDelivered(RTCStatsReport report); @CalledByNative public void onStatsDelivered(RTCStatsReport report);
} }

View file

@ -52,4 +52,11 @@ public class RTCStatsReport {
builder.append(" ] }"); builder.append(" ] }");
return builder.toString(); return builder.toString();
} }
// TODO(bugs.webrtc.org/8557) Use ctor directly with full Map type.
@SuppressWarnings("unchecked")
@CalledByNative
private static RTCStatsReport create(long timestampUs, Map stats) {
return new RTCStatsReport(timestampUs, stats);
}
} }

View file

@ -13,6 +13,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "sdk/android/generated_peerconnection_jni/jni/RTCStatsCollectorCallback_jni.h"
#include "sdk/android/generated_peerconnection_jni/jni/RTCStatsReport_jni.h"
#include "sdk/android/generated_peerconnection_jni/jni/RTCStats_jni.h"
#include "sdk/android/src/jni/classreferenceholder.h" #include "sdk/android/src/jni/classreferenceholder.h"
namespace webrtc { namespace webrtc {
@ -23,17 +26,6 @@ RTCStatsCollectorCallbackWrapper::RTCStatsCollectorCallbackWrapper(
jobject j_callback) jobject j_callback)
: j_callback_global_(jni, j_callback), : j_callback_global_(jni, j_callback),
j_callback_class_(jni, GetObjectClass(jni, j_callback)), j_callback_class_(jni, GetObjectClass(jni, j_callback)),
j_stats_report_class_(FindClass(jni, "org/webrtc/RTCStatsReport")),
j_stats_report_ctor_(GetMethodID(jni,
j_stats_report_class_,
"<init>",
"(JLjava/util/Map;)V")),
j_stats_class_(FindClass(jni, "org/webrtc/RTCStats")),
j_stats_ctor_(GetMethodID(
jni,
j_stats_class_,
"<init>",
"(JLjava/lang/String;Ljava/lang/String;Ljava/util/Map;)V")),
j_linked_hash_map_class_(FindClass(jni, "java/util/LinkedHashMap")), j_linked_hash_map_class_(FindClass(jni, "java/util/LinkedHashMap")),
j_linked_hash_map_ctor_( j_linked_hash_map_ctor_(
GetMethodID(jni, j_linked_hash_map_class_, "<init>", "()V")), GetMethodID(jni, j_linked_hash_map_class_, "<init>", "()V")),
@ -61,10 +53,8 @@ void RTCStatsCollectorCallbackWrapper::OnStatsDelivered(
JNIEnv* jni = AttachCurrentThreadIfNeeded(); JNIEnv* jni = AttachCurrentThreadIfNeeded();
ScopedLocalRefFrame local_ref_frame(jni); ScopedLocalRefFrame local_ref_frame(jni);
jobject j_report = ReportToJava(jni, report); jobject j_report = ReportToJava(jni, report);
jmethodID m = GetMethodID(jni, *j_callback_class_, "onStatsDelivered", Java_RTCStatsCollectorCallback_onStatsDelivered(jni, *j_callback_global_,
"(Lorg/webrtc/RTCStatsReport;)V"); j_report);
jni->CallVoidMethod(*j_callback_global_, m, j_report);
CHECK_EXCEPTION(jni) << "error during CallVoidMethod";
} }
jobject RTCStatsCollectorCallbackWrapper::ReportToJava( jobject RTCStatsCollectorCallbackWrapper::ReportToJava(
@ -82,9 +72,8 @@ jobject RTCStatsCollectorCallbackWrapper::ReportToJava(
jni->CallObjectMethod(j_stats_map, j_linked_hash_map_put_, j_id, j_stats); jni->CallObjectMethod(j_stats_map, j_linked_hash_map_put_, j_id, j_stats);
CHECK_EXCEPTION(jni) << "error during CallObjectMethod"; CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
} }
jobject j_report = jni->NewObject(j_stats_report_class_, j_stats_report_ctor_, jobject j_report =
report->timestamp_us(), j_stats_map); Java_RTCStatsReport_create(jni, report->timestamp_us(), j_stats_map);
CHECK_EXCEPTION(jni) << "error during NewObject";
return j_report; return j_report;
} }
@ -106,8 +95,7 @@ jobject RTCStatsCollectorCallbackWrapper::StatsToJava(JNIEnv* jni,
CHECK_EXCEPTION(jni) << "error during CallObjectMethod"; CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
} }
jobject j_stats = jobject j_stats =
jni->NewObject(j_stats_class_, j_stats_ctor_, stats.timestamp_us(), Java_RTCStats_create(jni, stats.timestamp_us(), j_type, j_id, j_members);
j_type, j_id, j_members);
CHECK_EXCEPTION(jni) << "error during NewObject"; CHECK_EXCEPTION(jni) << "error during NewObject";
return j_stats; return j_stats;
} }

View file

@ -38,10 +38,6 @@ class RTCStatsCollectorCallbackWrapper : public RTCStatsCollectorCallback {
const ScopedGlobalRef<jobject> j_callback_global_; const ScopedGlobalRef<jobject> j_callback_global_;
const ScopedGlobalRef<jclass> j_callback_class_; const ScopedGlobalRef<jclass> j_callback_class_;
const jclass j_stats_report_class_;
const jmethodID j_stats_report_ctor_;
const jclass j_stats_class_;
const jmethodID j_stats_ctor_;
const jclass j_linked_hash_map_class_; const jclass j_linked_hash_map_class_;
const jmethodID j_linked_hash_map_ctor_; const jmethodID j_linked_hash_map_ctor_;
const jmethodID j_linked_hash_map_put_; const jmethodID j_linked_hash_map_put_;