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

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

Issue 2989323002: Revert of Break peerconnection_jni.cc into multiple files, in "pc" directory. (Closed)
Patch Set: 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
(Empty)
1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <memory>
12
13 #include "webrtc/api/datachannelinterface.h"
14 #include "webrtc/sdk/android/src/jni/jni_helpers.h"
15 #include "webrtc/sdk/android/src/jni/pc/datachannelobserver_jni.h"
16
17 namespace webrtc_jni {
18
19 static webrtc::DataChannelInterface* ExtractNativeDC(JNIEnv* jni,
20 jobject j_dc) {
21 jfieldID native_dc_id =
22 GetFieldID(jni, GetObjectClass(jni, j_dc), "nativeDataChannel", "J");
23 jlong j_d = GetLongField(jni, j_dc, native_dc_id);
24 return reinterpret_cast<webrtc::DataChannelInterface*>(j_d);
25 }
26
27 JOW(jlong, DataChannel_registerObserverNative)
28 (JNIEnv* jni, jobject j_dc, jobject j_observer) {
29 std::unique_ptr<DataChannelObserverJni> observer(
30 new DataChannelObserverJni(jni, j_observer));
31 ExtractNativeDC(jni, j_dc)->RegisterObserver(observer.get());
32 return jlongFromPointer(observer.release());
33 }
34
35 JOW(void, DataChannel_unregisterObserverNative)
36 (JNIEnv* jni, jobject j_dc, jlong native_observer) {
37 ExtractNativeDC(jni, j_dc)->UnregisterObserver();
38 delete reinterpret_cast<DataChannelObserverJni*>(native_observer);
39 }
40
41 JOW(jstring, DataChannel_label)(JNIEnv* jni, jobject j_dc) {
42 return JavaStringFromStdString(jni, ExtractNativeDC(jni, j_dc)->label());
43 }
44
45 JOW(jint, DataChannel_id)(JNIEnv* jni, jobject j_dc) {
46 int id = ExtractNativeDC(jni, j_dc)->id();
47 RTC_CHECK_LE(id, std::numeric_limits<int32_t>::max())
48 << "id overflowed jint!";
49 return static_cast<jint>(id);
50 }
51
52 JOW(jobject, DataChannel_state)(JNIEnv* jni, jobject j_dc) {
53 return JavaEnumFromIndexAndClassName(jni, "DataChannel$State",
54 ExtractNativeDC(jni, j_dc)->state());
55 }
56
57 JOW(jlong, DataChannel_bufferedAmount)(JNIEnv* jni, jobject j_dc) {
58 uint64_t buffered_amount = ExtractNativeDC(jni, j_dc)->buffered_amount();
59 RTC_CHECK_LE(buffered_amount, std::numeric_limits<int64_t>::max())
60 << "buffered_amount overflowed jlong!";
61 return static_cast<jlong>(buffered_amount);
62 }
63
64 JOW(void, DataChannel_close)(JNIEnv* jni, jobject j_dc) {
65 ExtractNativeDC(jni, j_dc)->Close();
66 }
67
68 JOW(jboolean, DataChannel_sendNative)
69 (JNIEnv* jni, jobject j_dc, jbyteArray data, jboolean binary) {
70 jbyte* bytes = jni->GetByteArrayElements(data, NULL);
71 bool ret = ExtractNativeDC(jni, j_dc)->Send(webrtc::DataBuffer(
72 rtc::CopyOnWriteBuffer(bytes, jni->GetArrayLength(data)), binary));
73 jni->ReleaseByteArrayElements(data, bytes, JNI_ABORT);
74 return ret;
75 }
76
77 JOW(void, DataChannel_dispose)(JNIEnv* jni, jobject j_dc) {
78 CHECK_RELEASE(ExtractNativeDC(jni, j_dc));
79 }
80
81 } // namespace webrtc_jni
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698