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

Side by Side Diff: webrtc/sdk/android/src/jni/pc/datachannelobserver_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/datachannelobserver_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 DataChannelObserverJni::DataChannelObserverJni(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_buffer_class_(jni, FindClass(jni, "org/webrtc/DataChannel$Buffer")),
27 } 27 j_on_buffered_amount_change_mid_(GetMethodID(jni,
28 *j_observer_class_,
29 "onBufferedAmountChange",
30 "(J)V")),
31 j_on_state_change_mid_(
32 GetMethodID(jni, *j_observer_class_, "onStateChange", "()V")),
33 j_on_message_mid_(GetMethodID(jni,
34 *j_observer_class_,
35 "onMessage",
36 "(Lorg/webrtc/DataChannel$Buffer;)V")),
37 j_buffer_ctor_(GetMethodID(jni,
38 *j_buffer_class_,
39 "<init>",
40 "(Ljava/nio/ByteBuffer;Z)V")) {}
41
42 void DataChannelObserverJni::OnBufferedAmountChange(uint64_t previous_amount) {
43 ScopedLocalRefFrame local_ref_frame(jni());
44 jni()->CallVoidMethod(*j_observer_global_, j_on_buffered_amount_change_mid_,
45 previous_amount);
46 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
28 } 47 }
29 48
30 void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() { 49 void DataChannelObserverJni::OnStateChange() {
31 JNIEnv* jni = AttachCurrentThreadIfNeeded(); 50 ScopedLocalRefFrame local_ref_frame(jni());
32 ScopedLocalRefFrame local_ref_frame(jni); 51 jni()->CallVoidMethod(*j_observer_global_, j_on_state_change_mid_);
33 jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory"); 52 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
34 jmethodID m = nullptr;
35 if (network_thread_->IsCurrent()) {
36 LOG(LS_INFO) << "Network thread JavaCallback";
37 m = GetStaticMethodID(jni, j_factory_class, "onNetworkThreadReady", "()V");
38 }
39 if (worker_thread_->IsCurrent()) {
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 } 53 }
53 54
54 void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() { 55 void DataChannelObserverJni::OnMessage(const webrtc::DataBuffer& buffer) {
55 LOG(LS_INFO) << "InvokeJavaCallbacksOnFactoryThreads."; 56 ScopedLocalRefFrame local_ref_frame(jni());
56 network_thread_->Invoke<void>(RTC_FROM_HERE, 57 jobject byte_buffer = jni()->NewDirectByteBuffer(
57 [this] { JavaCallbackOnFactoryThreads(); }); 58 const_cast<char*>(buffer.data.data<char>()), buffer.data.size());
58 worker_thread_->Invoke<void>(RTC_FROM_HERE, 59 jobject j_buffer = jni()->NewObject(*j_buffer_class_, j_buffer_ctor_,
59 [this] { JavaCallbackOnFactoryThreads(); }); 60 byte_buffer, buffer.binary);
60 signaling_thread_->Invoke<void>(RTC_FROM_HERE, 61 jni()->CallVoidMethod(*j_observer_global_, j_on_message_mid_, j_buffer);
61 [this] { JavaCallbackOnFactoryThreads(); }); 62 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
62 } 63 }
63 64
64 } // namespace webrtc_jni 65 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « webrtc/sdk/android/src/jni/pc/datachannelobserver_jni.h ('k') | webrtc/sdk/android/src/jni/pc/dtmfsender_jni.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698