Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: webrtc/sdk/android/src/jni/pc/statsobserver_jni.cc

Issue 2992103002: Relanding: Break peerconnection_jni.cc into multiple files, in "pc" directory. (Closed)
Patch Set: Add jni/androidnetworkmonitor_jni.h include for backwards comaptibility. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/sdk/android/src/jni/ownedfactoryandthreads.h" 11 #include "webrtc/sdk/android/src/jni/pc/statsobserver_jni.h"
12 12
13 #include "webrtc/rtc_base/logging.h"
14 #include "webrtc/sdk/android/src/jni/classreferenceholder.h" 13 #include "webrtc/sdk/android/src/jni/classreferenceholder.h"
15 #include "webrtc/sdk/android/src/jni/jni_helpers.h"
16 14
17 namespace webrtc_jni { 15 namespace webrtc_jni {
18 16
19 PeerConnectionFactoryInterface* factoryFromJava(jlong j_p) { 17 // Convenience, used since callbacks occur on the signaling thread, which may
20 return reinterpret_cast<OwnedFactoryAndThreads*>(j_p)->factory(); 18 // be a non-Java thread.
19 static JNIEnv* jni() {
20 return AttachCurrentThreadIfNeeded();
21 } 21 }
22 22
23 OwnedFactoryAndThreads::~OwnedFactoryAndThreads() { 23 StatsObserverJni::StatsObserverJni(JNIEnv* jni, jobject j_observer)
24 CHECK_RELEASE(factory_); 24 : j_observer_global_(jni, j_observer),
25 if (network_monitor_factory_ != nullptr) { 25 j_observer_class_(jni, GetObjectClass(jni, j_observer)),
26 rtc::NetworkMonitorFactory::ReleaseFactory(network_monitor_factory_); 26 j_stats_report_class_(jni, FindClass(jni, "org/webrtc/StatsReport")),
27 } 27 j_stats_report_ctor_(GetMethodID(jni,
28 *j_stats_report_class_,
29 "<init>",
30 "(Ljava/lang/String;Ljava/lang/String;D"
31 "[Lorg/webrtc/StatsReport$Value;)V")),
32 j_value_class_(jni, FindClass(jni, "org/webrtc/StatsReport$Value")),
33 j_value_ctor_(GetMethodID(jni,
34 *j_value_class_,
35 "<init>",
36 "(Ljava/lang/String;Ljava/lang/String;)V")) {}
37
38 void StatsObserverJni::OnComplete(const webrtc::StatsReports& reports) {
39 ScopedLocalRefFrame local_ref_frame(jni());
40 jobjectArray j_reports = ReportsToJava(jni(), reports);
41 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onComplete",
42 "([Lorg/webrtc/StatsReport;)V");
43 jni()->CallVoidMethod(*j_observer_global_, m, j_reports);
44 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
28 } 45 }
29 46
30 void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() { 47 jobjectArray StatsObserverJni::ReportsToJava(
31 JNIEnv* jni = AttachCurrentThreadIfNeeded(); 48 JNIEnv* jni,
32 ScopedLocalRefFrame local_ref_frame(jni); 49 const webrtc::StatsReports& reports) {
33 jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory"); 50 jobjectArray reports_array =
34 jmethodID m = nullptr; 51 jni->NewObjectArray(reports.size(), *j_stats_report_class_, NULL);
35 if (network_thread_->IsCurrent()) { 52 int i = 0;
36 LOG(LS_INFO) << "Network thread JavaCallback"; 53 for (const auto* report : reports) {
37 m = GetStaticMethodID(jni, j_factory_class, "onNetworkThreadReady", "()V"); 54 ScopedLocalRefFrame local_ref_frame(jni);
55 jstring j_id = JavaStringFromStdString(jni, report->id()->ToString());
56 jstring j_type = JavaStringFromStdString(jni, report->TypeToString());
57 jobjectArray j_values = ValuesToJava(jni, report->values());
58 jobject j_report =
59 jni->NewObject(*j_stats_report_class_, j_stats_report_ctor_, j_id,
60 j_type, report->timestamp(), j_values);
61 jni->SetObjectArrayElement(reports_array, i++, j_report);
38 } 62 }
39 if (worker_thread_->IsCurrent()) { 63 return reports_array;
40 LOG(LS_INFO) << "Worker thread JavaCallback";
41 m = GetStaticMethodID(jni, j_factory_class, "onWorkerThreadReady", "()V");
42 }
43 if (signaling_thread_->IsCurrent()) {
44 LOG(LS_INFO) << "Signaling thread JavaCallback";
45 m = GetStaticMethodID(jni, j_factory_class, "onSignalingThreadReady",
46 "()V");
47 }
48 if (m != nullptr) {
49 jni->CallStaticVoidMethod(j_factory_class, m);
50 CHECK_EXCEPTION(jni) << "error during JavaCallback::CallStaticVoidMethod";
51 }
52 } 64 }
53 65
54 void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() { 66 jobjectArray StatsObserverJni::ValuesToJava(
55 LOG(LS_INFO) << "InvokeJavaCallbacksOnFactoryThreads."; 67 JNIEnv* jni,
56 network_thread_->Invoke<void>(RTC_FROM_HERE, 68 const webrtc::StatsReport::Values& values) {
57 [this] { JavaCallbackOnFactoryThreads(); }); 69 jobjectArray j_values =
58 worker_thread_->Invoke<void>(RTC_FROM_HERE, 70 jni->NewObjectArray(values.size(), *j_value_class_, NULL);
59 [this] { JavaCallbackOnFactoryThreads(); }); 71 int i = 0;
60 signaling_thread_->Invoke<void>(RTC_FROM_HERE, 72 for (const auto& it : values) {
61 [this] { JavaCallbackOnFactoryThreads(); }); 73 ScopedLocalRefFrame local_ref_frame(jni);
74 // Should we use the '.name' enum value here instead of converting the
75 // name to a string?
76 jstring j_name = JavaStringFromStdString(jni, it.second->display_name());
77 jstring j_value = JavaStringFromStdString(jni, it.second->ToString());
78 jobject j_element_value =
79 jni->NewObject(*j_value_class_, j_value_ctor_, j_name, j_value);
80 jni->SetObjectArrayElement(j_values, i++, j_element_value);
81 }
82 return j_values;
62 } 83 }
63 84
64 } // namespace webrtc_jni 85 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « webrtc/sdk/android/src/jni/pc/statsobserver_jni.h ('k') | webrtc/sdk/android/src/jni/pc/video_jni.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698