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 <memory> | 11 #include <memory> |
12 | 12 |
13 #include "webrtc/api/datachannelinterface.h" | 13 #include "webrtc/api/datachannelinterface.h" |
14 #include "webrtc/sdk/android/src/jni/jni_helpers.h" | 14 #include "webrtc/sdk/android/src/jni/jni_helpers.h" |
15 #include "webrtc/sdk/android/src/jni/pc/datachannelobserver_jni.h" | 15 #include "webrtc/sdk/android/src/jni/pc/datachannelobserver_jni.h" |
16 | 16 |
17 namespace webrtc_jni { | 17 namespace webrtc { |
| 18 namespace jni { |
18 | 19 |
19 static webrtc::DataChannelInterface* ExtractNativeDC(JNIEnv* jni, | 20 static DataChannelInterface* ExtractNativeDC(JNIEnv* jni, jobject j_dc) { |
20 jobject j_dc) { | |
21 jfieldID native_dc_id = | 21 jfieldID native_dc_id = |
22 GetFieldID(jni, GetObjectClass(jni, j_dc), "nativeDataChannel", "J"); | 22 GetFieldID(jni, GetObjectClass(jni, j_dc), "nativeDataChannel", "J"); |
23 jlong j_d = GetLongField(jni, j_dc, native_dc_id); | 23 jlong j_d = GetLongField(jni, j_dc, native_dc_id); |
24 return reinterpret_cast<webrtc::DataChannelInterface*>(j_d); | 24 return reinterpret_cast<DataChannelInterface*>(j_d); |
25 } | 25 } |
26 | 26 |
27 JNI_FUNCTION_DECLARATION(jlong, | 27 JNI_FUNCTION_DECLARATION(jlong, |
28 DataChannel_registerObserverNative, | 28 DataChannel_registerObserverNative, |
29 JNIEnv* jni, | 29 JNIEnv* jni, |
30 jobject j_dc, | 30 jobject j_dc, |
31 jobject j_observer) { | 31 jobject j_observer) { |
32 std::unique_ptr<DataChannelObserverJni> observer( | 32 std::unique_ptr<DataChannelObserverJni> observer( |
33 new DataChannelObserverJni(jni, j_observer)); | 33 new DataChannelObserverJni(jni, j_observer)); |
34 ExtractNativeDC(jni, j_dc)->RegisterObserver(observer.get()); | 34 ExtractNativeDC(jni, j_dc)->RegisterObserver(observer.get()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 ExtractNativeDC(jni, j_dc)->Close(); | 80 ExtractNativeDC(jni, j_dc)->Close(); |
81 } | 81 } |
82 | 82 |
83 JNI_FUNCTION_DECLARATION(jboolean, | 83 JNI_FUNCTION_DECLARATION(jboolean, |
84 DataChannel_sendNative, | 84 DataChannel_sendNative, |
85 JNIEnv* jni, | 85 JNIEnv* jni, |
86 jobject j_dc, | 86 jobject j_dc, |
87 jbyteArray data, | 87 jbyteArray data, |
88 jboolean binary) { | 88 jboolean binary) { |
89 jbyte* bytes = jni->GetByteArrayElements(data, NULL); | 89 jbyte* bytes = jni->GetByteArrayElements(data, NULL); |
90 bool ret = ExtractNativeDC(jni, j_dc)->Send(webrtc::DataBuffer( | 90 bool ret = ExtractNativeDC(jni, j_dc)->Send(DataBuffer( |
91 rtc::CopyOnWriteBuffer(bytes, jni->GetArrayLength(data)), binary)); | 91 rtc::CopyOnWriteBuffer(bytes, jni->GetArrayLength(data)), binary)); |
92 jni->ReleaseByteArrayElements(data, bytes, JNI_ABORT); | 92 jni->ReleaseByteArrayElements(data, bytes, JNI_ABORT); |
93 return ret; | 93 return ret; |
94 } | 94 } |
95 | 95 |
96 JNI_FUNCTION_DECLARATION(void, DataChannel_dispose, JNIEnv* jni, jobject j_dc) { | 96 JNI_FUNCTION_DECLARATION(void, DataChannel_dispose, JNIEnv* jni, jobject j_dc) { |
97 CHECK_RELEASE(ExtractNativeDC(jni, j_dc)); | 97 CHECK_RELEASE(ExtractNativeDC(jni, j_dc)); |
98 } | 98 } |
99 | 99 |
100 } // namespace webrtc_jni | 100 } // namespace jni |
| 101 } // namespace webrtc |
OLD | NEW |