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

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

Issue 2992103002: Relanding: Break peerconnection_jni.cc into multiple files, in "pc" directory. (Closed)
Patch Set: Add jni/androidnetworkmonitor_jni.h include for backwards comaptibility. 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/sdk/android/src/jni/pc/sdpobserver_jni.h
diff --git a/webrtc/sdk/android/src/jni/rtcstatscollectorcallbackwrapper.h b/webrtc/sdk/android/src/jni/pc/sdpobserver_jni.h
similarity index 14%
rename from webrtc/sdk/android/src/jni/rtcstatscollectorcallbackwrapper.h
rename to webrtc/sdk/android/src/jni/pc/sdpobserver_jni.h
index 5f1eb66bd216b2cbedcc8f1b40cd21103397dc82..0113954065c9df82c278231a90b4694f3fc350aa 100644
--- a/webrtc/sdk/android/src/jni/rtcstatscollectorcallbackwrapper.h
+++ b/webrtc/sdk/android/src/jni/pc/sdpobserver_jni.h
@@ -8,58 +8,101 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#ifndef WEBRTC_SDK_ANDROID_SRC_JNI_RTCSTATSCOLLECTORCALLBACKWRAPPER_H_
-#define WEBRTC_SDK_ANDROID_SRC_JNI_RTCSTATSCOLLECTORCALLBACKWRAPPER_H_
+#ifndef WEBRTC_SDK_ANDROID_SRC_JNI_PC_SDPOBSERVER_JNI_H_
+#define WEBRTC_SDK_ANDROID_SRC_JNI_PC_SDPOBSERVER_JNI_H_
-#include <jni.h>
+#include <memory>
+#include <string>
#include "webrtc/api/peerconnectioninterface.h"
#include "webrtc/sdk/android/src/jni/jni_helpers.h"
+#include "webrtc/sdk/android/src/jni/pc/mediaconstraints_jni.h"
namespace webrtc_jni {
-// Adapter for a Java RTCStatsCollectorCallback presenting a C++
-// RTCStatsCollectorCallback and dispatching the callback from C++ back to
-// Java.
-class RTCStatsCollectorCallbackWrapper
- : public webrtc::RTCStatsCollectorCallback {
+// Adapter for a Java StatsObserver presenting a C++
+// CreateSessionDescriptionObserver or SetSessionDescriptionObserver and
+// dispatching the callback from C++ back to Java.
+template <class T> // T is one of {Create,Set}SessionDescriptionObserver.
+class SdpObserverJni : public T {
public:
- RTCStatsCollectorCallbackWrapper(JNIEnv* jni, jobject j_callback);
+ SdpObserverJni(JNIEnv* jni,
+ jobject j_observer,
+ MediaConstraintsJni* constraints)
+ : constraints_(constraints),
+ j_observer_global_(jni, j_observer),
+ j_observer_class_(jni, GetObjectClass(jni, j_observer)) {}
- void OnStatsDelivered(
- const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report) override;
+ virtual ~SdpObserverJni() {}
+
+ // Can't mark override because of templating.
+ virtual void OnSuccess() {
+ ScopedLocalRefFrame local_ref_frame(jni());
+ jmethodID m = GetMethodID(jni(), *j_observer_class_, "onSetSuccess", "()V");
+ jni()->CallVoidMethod(*j_observer_global_, m);
+ CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
+ }
+
+ // Can't mark override because of templating.
+ virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc) {
+ ScopedLocalRefFrame local_ref_frame(jni());
+ jmethodID m = GetMethodID(jni(), *j_observer_class_, "onCreateSuccess",
+ "(Lorg/webrtc/SessionDescription;)V");
+ jobject j_sdp = NativeToJavaSessionDescription(jni(), desc);
+ jni()->CallVoidMethod(*j_observer_global_, m, j_sdp);
+ CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
+ // OnSuccess transfers ownership of the description (there's a TODO to make
+ // it use unique_ptr...).
+ delete desc;
+ }
+
+ protected:
+ // Common implementation for failure of Set & Create types, distinguished by
+ // |op| being "Set" or "Create".
+ void DoOnFailure(const std::string& op, const std::string& error) {
+ jmethodID m = GetMethodID(jni(), *j_observer_class_, "on" + op + "Failure",
+ "(Ljava/lang/String;)V");
+ jstring j_error_string = JavaStringFromStdString(jni(), error);
+ jni()->CallVoidMethod(*j_observer_global_, m, j_error_string);
+ CHECK_EXCEPTION(jni()) << "error during CallVoidMethod";
+ }
+
+ JNIEnv* jni() { return AttachCurrentThreadIfNeeded(); }
private:
- // Helper functions for converting C++ RTCStatsReport to Java equivalent.
- jobject ReportToJava(
- JNIEnv* jni,
- const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report);
- jobject StatsToJava(JNIEnv* jni, const webrtc::RTCStats& stats);
- jobject MemberToJava(JNIEnv* jni,
- const webrtc::RTCStatsMemberInterface* member);
-
- const ScopedGlobalRef<jobject> j_callback_global_;
- const ScopedGlobalRef<jclass> j_callback_class_;
- const jclass j_stats_report_class_;
- const jmethodID j_stats_report_ctor_;
- const jclass j_stats_class_;
- const jmethodID j_stats_ctor_;
- const jclass j_linked_hash_map_class_;
- const jmethodID j_linked_hash_map_ctor_;
- const jmethodID j_linked_hash_map_put_;
- const jclass j_boolean_class_;
- const jmethodID j_boolean_ctor_;
- const jclass j_integer_class_;
- const jmethodID j_integer_ctor_;
- const jclass j_long_class_;
- const jmethodID j_long_ctor_;
- const jclass j_big_integer_class_;
- const jmethodID j_big_integer_ctor_;
- const jclass j_double_class_;
- const jmethodID j_double_ctor_;
- const jclass j_string_class_;
+ std::unique_ptr<MediaConstraintsJni> constraints_;
+ const ScopedGlobalRef<jobject> j_observer_global_;
+ const ScopedGlobalRef<jclass> j_observer_class_;
+};
+
+class CreateSdpObserverJni
+ : public SdpObserverJni<webrtc::CreateSessionDescriptionObserver> {
+ public:
+ CreateSdpObserverJni(JNIEnv* jni,
+ jobject j_observer,
+ MediaConstraintsJni* constraints)
+ : SdpObserverJni(jni, j_observer, constraints) {}
+
+ void OnFailure(const std::string& error) override {
+ ScopedLocalRefFrame local_ref_frame(jni());
+ SdpObserverJni::DoOnFailure(std::string("Create"), error);
+ }
+};
+
+class SetSdpObserverJni
+ : public SdpObserverJni<webrtc::SetSessionDescriptionObserver> {
+ public:
+ SetSdpObserverJni(JNIEnv* jni,
+ jobject j_observer,
+ MediaConstraintsJni* constraints)
+ : SdpObserverJni(jni, j_observer, constraints) {}
+
+ void OnFailure(const std::string& error) override {
+ ScopedLocalRefFrame local_ref_frame(jni());
+ SdpObserverJni::DoOnFailure(std::string("Set"), error);
+ }
};
} // namespace webrtc_jni
-#endif // WEBRTC_SDK_ANDROID_SRC_JNI_RTCSTATSCOLLECTORCALLBACKWRAPPER_H_
+#endif // WEBRTC_SDK_ANDROID_SRC_JNI_PC_SDPOBSERVER_JNI_H_
« 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