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

Side by Side Diff: webrtc/sdk/android/src/jni/pc/sdpobserver_jni.h

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 #ifndef WEBRTC_SDK_ANDROID_SRC_JNI_PC_SDPOBSERVER_JNI_H_
12 #define WEBRTC_SDK_ANDROID_SRC_JNI_PC_SDPOBSERVER_JNI_H_
13
14 #include <memory>
15 #include <string>
16
17 #include "webrtc/api/peerconnectioninterface.h"
18 #include "webrtc/sdk/android/src/jni/jni_helpers.h"
19 #include "webrtc/sdk/android/src/jni/pc/mediaconstraints_jni.h"
20
21 namespace webrtc_jni {
22
23 // Adapter for a Java StatsObserver presenting a C++
24 // CreateSessionDescriptionObserver or SetSessionDescriptionObserver and
25 // dispatching the callback from C++ back to Java.
26 template <class T> // T is one of {Create,Set}SessionDescriptionObserver.
27 class SdpObserverJni : public T {
28 public:
29 SdpObserverJni(JNIEnv* jni,
30 jobject j_observer,
31 MediaConstraintsJni* constraints)
32 : constraints_(constraints),
33 j_observer_global_(jni, j_observer),
34 j_observer_class_(jni, GetObjectClass(jni, j_observer)) {}
35
36 virtual ~SdpObserverJni() {}
37
38 // Can't mark override because of templating.
39 virtual void OnSuccess() {
40 ScopedLocalRefFrame local_ref_frame(jni());
41 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onSetSuccess", "()V");
42 jni()->CallVoidMethod(*j_observer_global_, m);
43 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
44 }
45
46 // Can't mark override because of templating.
47 virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc) {
48 ScopedLocalRefFrame local_ref_frame(jni());
49 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onCreateSuccess",
50 "(Lorg/webrtc/SessionDescription;)V");
51 jobject j_sdp = NativeToJavaSessionDescription(jni(), desc);
52 jni()->CallVoidMethod(*j_observer_global_, m, j_sdp);
53 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
54 // OnSuccess transfers ownership of the description (there's a TODO to make
55 // it use unique_ptr...).
56 delete desc;
57 }
58
59 protected:
60 // Common implementation for failure of Set & Create types, distinguished by
61 // |op| being "Set" or "Create".
62 void DoOnFailure(const std::string& op, const std::string& error) {
63 jmethodID m = GetMethodID(jni(), *j_observer_class_, "on" + op + "Failure",
64 "(Ljava/lang/String;)V");
65 jstring j_error_string = JavaStringFromStdString(jni(), error);
66 jni()->CallVoidMethod(*j_observer_global_, m, j_error_string);
67 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
68 }
69
70 JNIEnv* jni() { return AttachCurrentThreadIfNeeded(); }
71
72 private:
73 std::unique_ptr<MediaConstraintsJni> constraints_;
74 const ScopedGlobalRef<jobject> j_observer_global_;
75 const ScopedGlobalRef<jclass> j_observer_class_;
76 };
77
78 class CreateSdpObserverJni
79 : public SdpObserverJni<webrtc::CreateSessionDescriptionObserver> {
80 public:
81 CreateSdpObserverJni(JNIEnv* jni,
82 jobject j_observer,
83 MediaConstraintsJni* constraints)
84 : SdpObserverJni(jni, j_observer, constraints) {}
85
86 void OnFailure(const std::string& error) override {
87 ScopedLocalRefFrame local_ref_frame(jni());
88 SdpObserverJni::DoOnFailure(std::string("Create"), error);
89 }
90 };
91
92 class SetSdpObserverJni
93 : public SdpObserverJni<webrtc::SetSessionDescriptionObserver> {
94 public:
95 SetSdpObserverJni(JNIEnv* jni,
96 jobject j_observer,
97 MediaConstraintsJni* constraints)
98 : SdpObserverJni(jni, j_observer, constraints) {}
99
100 void OnFailure(const std::string& error) override {
101 ScopedLocalRefFrame local_ref_frame(jni());
102 SdpObserverJni::DoOnFailure(std::string("Set"), error);
103 }
104 };
105
106 } // namespace webrtc_jni
107
108 #endif // WEBRTC_SDK_ANDROID_SRC_JNI_PC_SDPOBSERVER_JNI_H_
OLDNEW
« no previous file with comments | « webrtc/sdk/android/src/jni/pc/rtpsender_jni.cc ('k') | webrtc/sdk/android/src/jni/pc/statsobserver_jni.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698