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

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

Issue 3009613002: Android: Replace webrtc_jni namespace with nested jni namespace (Closed)
Patch Set: Rebase Created 3 years, 3 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/pc/statsobserver_jni.h" 11 #include "webrtc/sdk/android/src/jni/pc/statsobserver_jni.h"
12 12
13 #include "webrtc/sdk/android/src/jni/classreferenceholder.h" 13 #include "webrtc/sdk/android/src/jni/classreferenceholder.h"
14 14
15 namespace webrtc_jni { 15 namespace webrtc {
16 namespace jni {
16 17
17 // Convenience, used since callbacks occur on the signaling thread, which may 18 // Convenience, used since callbacks occur on the signaling thread, which may
18 // be a non-Java thread. 19 // be a non-Java thread.
19 static JNIEnv* jni() { 20 static JNIEnv* jni() {
20 return AttachCurrentThreadIfNeeded(); 21 return AttachCurrentThreadIfNeeded();
21 } 22 }
22 23
23 StatsObserverJni::StatsObserverJni(JNIEnv* jni, jobject j_observer) 24 StatsObserverJni::StatsObserverJni(JNIEnv* jni, jobject j_observer)
24 : j_observer_global_(jni, j_observer), 25 : j_observer_global_(jni, j_observer),
25 j_observer_class_(jni, GetObjectClass(jni, j_observer)), 26 j_observer_class_(jni, GetObjectClass(jni, j_observer)),
26 j_stats_report_class_(jni, FindClass(jni, "org/webrtc/StatsReport")), 27 j_stats_report_class_(jni, FindClass(jni, "org/webrtc/StatsReport")),
27 j_stats_report_ctor_(GetMethodID(jni, 28 j_stats_report_ctor_(GetMethodID(jni,
28 *j_stats_report_class_, 29 *j_stats_report_class_,
29 "<init>", 30 "<init>",
30 "(Ljava/lang/String;Ljava/lang/String;D" 31 "(Ljava/lang/String;Ljava/lang/String;D"
31 "[Lorg/webrtc/StatsReport$Value;)V")), 32 "[Lorg/webrtc/StatsReport$Value;)V")),
32 j_value_class_(jni, FindClass(jni, "org/webrtc/StatsReport$Value")), 33 j_value_class_(jni, FindClass(jni, "org/webrtc/StatsReport$Value")),
33 j_value_ctor_(GetMethodID(jni, 34 j_value_ctor_(GetMethodID(jni,
34 *j_value_class_, 35 *j_value_class_,
35 "<init>", 36 "<init>",
36 "(Ljava/lang/String;Ljava/lang/String;)V")) {} 37 "(Ljava/lang/String;Ljava/lang/String;)V")) {}
37 38
38 void StatsObserverJni::OnComplete(const webrtc::StatsReports& reports) { 39 void StatsObserverJni::OnComplete(const StatsReports& reports) {
39 ScopedLocalRefFrame local_ref_frame(jni()); 40 ScopedLocalRefFrame local_ref_frame(jni());
40 jobjectArray j_reports = ReportsToJava(jni(), reports); 41 jobjectArray j_reports = ReportsToJava(jni(), reports);
41 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onComplete", 42 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onComplete",
42 "([Lorg/webrtc/StatsReport;)V"); 43 "([Lorg/webrtc/StatsReport;)V");
43 jni()->CallVoidMethod(*j_observer_global_, m, j_reports); 44 jni()->CallVoidMethod(*j_observer_global_, m, j_reports);
44 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; 45 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
45 } 46 }
46 47
47 jobjectArray StatsObserverJni::ReportsToJava( 48 jobjectArray StatsObserverJni::ReportsToJava(JNIEnv* jni,
48 JNIEnv* jni, 49 const StatsReports& reports) {
49 const webrtc::StatsReports& reports) {
50 jobjectArray reports_array = 50 jobjectArray reports_array =
51 jni->NewObjectArray(reports.size(), *j_stats_report_class_, NULL); 51 jni->NewObjectArray(reports.size(), *j_stats_report_class_, NULL);
52 int i = 0; 52 int i = 0;
53 for (const auto* report : reports) { 53 for (const auto* report : reports) {
54 ScopedLocalRefFrame local_ref_frame(jni); 54 ScopedLocalRefFrame local_ref_frame(jni);
55 jstring j_id = JavaStringFromStdString(jni, report->id()->ToString()); 55 jstring j_id = JavaStringFromStdString(jni, report->id()->ToString());
56 jstring j_type = JavaStringFromStdString(jni, report->TypeToString()); 56 jstring j_type = JavaStringFromStdString(jni, report->TypeToString());
57 jobjectArray j_values = ValuesToJava(jni, report->values()); 57 jobjectArray j_values = ValuesToJava(jni, report->values());
58 jobject j_report = 58 jobject j_report =
59 jni->NewObject(*j_stats_report_class_, j_stats_report_ctor_, j_id, 59 jni->NewObject(*j_stats_report_class_, j_stats_report_ctor_, j_id,
60 j_type, report->timestamp(), j_values); 60 j_type, report->timestamp(), j_values);
61 jni->SetObjectArrayElement(reports_array, i++, j_report); 61 jni->SetObjectArrayElement(reports_array, i++, j_report);
62 } 62 }
63 return reports_array; 63 return reports_array;
64 } 64 }
65 65
66 jobjectArray StatsObserverJni::ValuesToJava( 66 jobjectArray StatsObserverJni::ValuesToJava(JNIEnv* jni,
67 JNIEnv* jni, 67 const StatsReport::Values& values) {
68 const webrtc::StatsReport::Values& values) {
69 jobjectArray j_values = 68 jobjectArray j_values =
70 jni->NewObjectArray(values.size(), *j_value_class_, NULL); 69 jni->NewObjectArray(values.size(), *j_value_class_, NULL);
71 int i = 0; 70 int i = 0;
72 for (const auto& it : values) { 71 for (const auto& it : values) {
73 ScopedLocalRefFrame local_ref_frame(jni); 72 ScopedLocalRefFrame local_ref_frame(jni);
74 // Should we use the '.name' enum value here instead of converting the 73 // Should we use the '.name' enum value here instead of converting the
75 // name to a string? 74 // name to a string?
76 jstring j_name = JavaStringFromStdString(jni, it.second->display_name()); 75 jstring j_name = JavaStringFromStdString(jni, it.second->display_name());
77 jstring j_value = JavaStringFromStdString(jni, it.second->ToString()); 76 jstring j_value = JavaStringFromStdString(jni, it.second->ToString());
78 jobject j_element_value = 77 jobject j_element_value =
79 jni->NewObject(*j_value_class_, j_value_ctor_, j_name, j_value); 78 jni->NewObject(*j_value_class_, j_value_ctor_, j_name, j_value);
80 jni->SetObjectArrayElement(j_values, i++, j_element_value); 79 jni->SetObjectArrayElement(j_values, i++, j_element_value);
81 } 80 }
82 return j_values; 81 return j_values;
83 } 82 }
84 83
85 } // namespace webrtc_jni 84 } // namespace jni
85 } // namespace webrtc
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