OLD | NEW |
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/datachannelobserver_jni.h" | 11 #include "webrtc/sdk/android/src/jni/pc/datachannelobserver_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 DataChannelObserverJni::DataChannelObserverJni(JNIEnv* jni, jobject j_observer) | 24 DataChannelObserverJni::DataChannelObserverJni(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)), |
(...skipping 19 matching lines...) Expand all Loading... |
45 previous_amount); | 46 previous_amount); |
46 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; | 47 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; |
47 } | 48 } |
48 | 49 |
49 void DataChannelObserverJni::OnStateChange() { | 50 void DataChannelObserverJni::OnStateChange() { |
50 ScopedLocalRefFrame local_ref_frame(jni()); | 51 ScopedLocalRefFrame local_ref_frame(jni()); |
51 jni()->CallVoidMethod(*j_observer_global_, j_on_state_change_mid_); | 52 jni()->CallVoidMethod(*j_observer_global_, j_on_state_change_mid_); |
52 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; | 53 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; |
53 } | 54 } |
54 | 55 |
55 void DataChannelObserverJni::OnMessage(const webrtc::DataBuffer& buffer) { | 56 void DataChannelObserverJni::OnMessage(const DataBuffer& buffer) { |
56 ScopedLocalRefFrame local_ref_frame(jni()); | 57 ScopedLocalRefFrame local_ref_frame(jni()); |
57 jobject byte_buffer = jni()->NewDirectByteBuffer( | 58 jobject byte_buffer = jni()->NewDirectByteBuffer( |
58 const_cast<char*>(buffer.data.data<char>()), buffer.data.size()); | 59 const_cast<char*>(buffer.data.data<char>()), buffer.data.size()); |
59 jobject j_buffer = jni()->NewObject(*j_buffer_class_, j_buffer_ctor_, | 60 jobject j_buffer = jni()->NewObject(*j_buffer_class_, j_buffer_ctor_, |
60 byte_buffer, buffer.binary); | 61 byte_buffer, buffer.binary); |
61 jni()->CallVoidMethod(*j_observer_global_, j_on_message_mid_, j_buffer); | 62 jni()->CallVoidMethod(*j_observer_global_, j_on_message_mid_, j_buffer); |
62 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; | 63 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; |
63 } | 64 } |
64 | 65 |
65 } // namespace webrtc_jni | 66 } // namespace jni |
| 67 } // namespace webrtc |
OLD | NEW |