| 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_jni { |
| 18 | 18 |
| 19 static webrtc::DataChannelInterface* ExtractNativeDC(JNIEnv* jni, | 19 static webrtc::DataChannelInterface* ExtractNativeDC(JNIEnv* jni, |
| 20 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<webrtc::DataChannelInterface*>(j_d); |
| 25 } | 25 } |
| 26 | 26 |
| 27 JOW(jlong, DataChannel_registerObserverNative) | 27 JNI_FUNCTION_DECLARATION(jlong, |
| 28 (JNIEnv* jni, jobject j_dc, jobject j_observer) { | 28 DataChannel_registerObserverNative, |
| 29 JNIEnv* jni, |
| 30 jobject j_dc, |
| 31 jobject j_observer) { |
| 29 std::unique_ptr<DataChannelObserverJni> observer( | 32 std::unique_ptr<DataChannelObserverJni> observer( |
| 30 new DataChannelObserverJni(jni, j_observer)); | 33 new DataChannelObserverJni(jni, j_observer)); |
| 31 ExtractNativeDC(jni, j_dc)->RegisterObserver(observer.get()); | 34 ExtractNativeDC(jni, j_dc)->RegisterObserver(observer.get()); |
| 32 return jlongFromPointer(observer.release()); | 35 return jlongFromPointer(observer.release()); |
| 33 } | 36 } |
| 34 | 37 |
| 35 JOW(void, DataChannel_unregisterObserverNative) | 38 JNI_FUNCTION_DECLARATION(void, |
| 36 (JNIEnv* jni, jobject j_dc, jlong native_observer) { | 39 DataChannel_unregisterObserverNative, |
| 40 JNIEnv* jni, |
| 41 jobject j_dc, |
| 42 jlong native_observer) { |
| 37 ExtractNativeDC(jni, j_dc)->UnregisterObserver(); | 43 ExtractNativeDC(jni, j_dc)->UnregisterObserver(); |
| 38 delete reinterpret_cast<DataChannelObserverJni*>(native_observer); | 44 delete reinterpret_cast<DataChannelObserverJni*>(native_observer); |
| 39 } | 45 } |
| 40 | 46 |
| 41 JOW(jstring, DataChannel_label)(JNIEnv* jni, jobject j_dc) { | 47 JNI_FUNCTION_DECLARATION(jstring, |
| 48 DataChannel_label, |
| 49 JNIEnv* jni, |
| 50 jobject j_dc) { |
| 42 return JavaStringFromStdString(jni, ExtractNativeDC(jni, j_dc)->label()); | 51 return JavaStringFromStdString(jni, ExtractNativeDC(jni, j_dc)->label()); |
| 43 } | 52 } |
| 44 | 53 |
| 45 JOW(jint, DataChannel_id)(JNIEnv* jni, jobject j_dc) { | 54 JNI_FUNCTION_DECLARATION(jint, DataChannel_id, JNIEnv* jni, jobject j_dc) { |
| 46 int id = ExtractNativeDC(jni, j_dc)->id(); | 55 int id = ExtractNativeDC(jni, j_dc)->id(); |
| 47 RTC_CHECK_LE(id, std::numeric_limits<int32_t>::max()) | 56 RTC_CHECK_LE(id, std::numeric_limits<int32_t>::max()) |
| 48 << "id overflowed jint!"; | 57 << "id overflowed jint!"; |
| 49 return static_cast<jint>(id); | 58 return static_cast<jint>(id); |
| 50 } | 59 } |
| 51 | 60 |
| 52 JOW(jobject, DataChannel_state)(JNIEnv* jni, jobject j_dc) { | 61 JNI_FUNCTION_DECLARATION(jobject, |
| 62 DataChannel_state, |
| 63 JNIEnv* jni, |
| 64 jobject j_dc) { |
| 53 return JavaEnumFromIndexAndClassName(jni, "DataChannel$State", | 65 return JavaEnumFromIndexAndClassName(jni, "DataChannel$State", |
| 54 ExtractNativeDC(jni, j_dc)->state()); | 66 ExtractNativeDC(jni, j_dc)->state()); |
| 55 } | 67 } |
| 56 | 68 |
| 57 JOW(jlong, DataChannel_bufferedAmount)(JNIEnv* jni, jobject j_dc) { | 69 JNI_FUNCTION_DECLARATION(jlong, |
| 70 DataChannel_bufferedAmount, |
| 71 JNIEnv* jni, |
| 72 jobject j_dc) { |
| 58 uint64_t buffered_amount = ExtractNativeDC(jni, j_dc)->buffered_amount(); | 73 uint64_t buffered_amount = ExtractNativeDC(jni, j_dc)->buffered_amount(); |
| 59 RTC_CHECK_LE(buffered_amount, std::numeric_limits<int64_t>::max()) | 74 RTC_CHECK_LE(buffered_amount, std::numeric_limits<int64_t>::max()) |
| 60 << "buffered_amount overflowed jlong!"; | 75 << "buffered_amount overflowed jlong!"; |
| 61 return static_cast<jlong>(buffered_amount); | 76 return static_cast<jlong>(buffered_amount); |
| 62 } | 77 } |
| 63 | 78 |
| 64 JOW(void, DataChannel_close)(JNIEnv* jni, jobject j_dc) { | 79 JNI_FUNCTION_DECLARATION(void, DataChannel_close, JNIEnv* jni, jobject j_dc) { |
| 65 ExtractNativeDC(jni, j_dc)->Close(); | 80 ExtractNativeDC(jni, j_dc)->Close(); |
| 66 } | 81 } |
| 67 | 82 |
| 68 JOW(jboolean, DataChannel_sendNative) | 83 JNI_FUNCTION_DECLARATION(jboolean, |
| 69 (JNIEnv* jni, jobject j_dc, jbyteArray data, jboolean binary) { | 84 DataChannel_sendNative, |
| 85 JNIEnv* jni, |
| 86 jobject j_dc, |
| 87 jbyteArray data, |
| 88 jboolean binary) { |
| 70 jbyte* bytes = jni->GetByteArrayElements(data, NULL); | 89 jbyte* bytes = jni->GetByteArrayElements(data, NULL); |
| 71 bool ret = ExtractNativeDC(jni, j_dc)->Send(webrtc::DataBuffer( | 90 bool ret = ExtractNativeDC(jni, j_dc)->Send(webrtc::DataBuffer( |
| 72 rtc::CopyOnWriteBuffer(bytes, jni->GetArrayLength(data)), binary)); | 91 rtc::CopyOnWriteBuffer(bytes, jni->GetArrayLength(data)), binary)); |
| 73 jni->ReleaseByteArrayElements(data, bytes, JNI_ABORT); | 92 jni->ReleaseByteArrayElements(data, bytes, JNI_ABORT); |
| 74 return ret; | 93 return ret; |
| 75 } | 94 } |
| 76 | 95 |
| 77 JOW(void, DataChannel_dispose)(JNIEnv* jni, jobject j_dc) { | 96 JNI_FUNCTION_DECLARATION(void, DataChannel_dispose, JNIEnv* jni, jobject j_dc) { |
| 78 CHECK_RELEASE(ExtractNativeDC(jni, j_dc)); | 97 CHECK_RELEASE(ExtractNativeDC(jni, j_dc)); |
| 79 } | 98 } |
| 80 | 99 |
| 81 } // namespace webrtc_jni | 100 } // namespace webrtc_jni |
| OLD | NEW |