Index: webrtc/sdk/android/src/jni/pc/peerconnectionobserver_jni.h |
diff --git a/webrtc/sdk/android/src/jni/rtcstatscollectorcallbackwrapper.h b/webrtc/sdk/android/src/jni/pc/peerconnectionobserver_jni.h |
similarity index 14% |
copy from webrtc/sdk/android/src/jni/rtcstatscollectorcallbackwrapper.h |
copy to webrtc/sdk/android/src/jni/pc/peerconnectionobserver_jni.h |
index 5f1eb66bd216b2cbedcc8f1b40cd21103397dc82..2d9d749a6b2014f43820549c06da9d85d400d107 100644 |
--- a/webrtc/sdk/android/src/jni/rtcstatscollectorcallbackwrapper.h |
+++ b/webrtc/sdk/android/src/jni/pc/peerconnectionobserver_jni.h |
@@ -8,58 +8,93 @@ |
* 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_PEERCONNECTIONOBSERVER_JNI_H_ |
+#define WEBRTC_SDK_ANDROID_SRC_JNI_PC_PEERCONNECTIONOBSERVER_JNI_H_ |
-#include <jni.h> |
+#include <map> |
+#include <memory> |
+#include <vector> |
#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 between the C++ PeerConnectionObserver interface and the Java |
+// PeerConnection.Observer interface. Wraps an instance of the Java interface |
+// and dispatches C++ callbacks to Java. |
+class PeerConnectionObserverJni : public webrtc::PeerConnectionObserver { |
public: |
- RTCStatsCollectorCallbackWrapper(JNIEnv* jni, jobject j_callback); |
+ PeerConnectionObserverJni(JNIEnv* jni, jobject j_observer); |
+ virtual ~PeerConnectionObserverJni(); |
- void OnStatsDelivered( |
- const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report) override; |
+ // Implementation of PeerConnectionObserver interface, which propagates |
+ // the callbacks to the Java observer. |
+ void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; |
+ void OnIceCandidatesRemoved( |
+ const std::vector<cricket::Candidate>& candidates) override; |
+ void OnSignalingChange( |
+ webrtc::PeerConnectionInterface::SignalingState new_state) override; |
+ void OnIceConnectionChange( |
+ webrtc::PeerConnectionInterface::IceConnectionState new_state) override; |
+ void OnIceConnectionReceivingChange(bool receiving) override; |
+ void OnIceGatheringChange( |
+ webrtc::PeerConnectionInterface::IceGatheringState new_state) override; |
+ void OnAddStream( |
+ rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override; |
+ void OnRemoveStream( |
+ rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override; |
+ void OnDataChannel( |
+ rtc::scoped_refptr<webrtc::DataChannelInterface> channel) override; |
+ void OnRenegotiationNeeded() override; |
+ void OnAddTrack( |
+ rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver, |
+ const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>& |
+ streams) override; |
+ |
+ void SetConstraints(MediaConstraintsJni* constraints); |
+ const MediaConstraintsJni* constraints() { return constraints_.get(); } |
private: |
- // Helper functions for converting C++ RTCStatsReport to Java equivalent. |
- jobject ReportToJava( |
+ typedef std::map<webrtc::MediaStreamInterface*, jobject> |
+ NativeToJavaStreamsMap; |
+ typedef std::map<webrtc::RtpReceiverInterface*, jobject> |
+ NativeToJavaRtpReceiverMap; |
+ |
+ void DisposeRemoteStream(const NativeToJavaStreamsMap::iterator& it); |
+ void DisposeRtpReceiver(const NativeToJavaRtpReceiverMap::iterator& it); |
+ |
+ // If the NativeToJavaStreamsMap contains the stream, return it. |
+ // Otherwise, create a new Java MediaStream. |
+ jobject GetOrCreateJavaStream( |
+ const rtc::scoped_refptr<webrtc::MediaStreamInterface>& stream); |
+ |
+ // Converts array of streams, creating or re-using Java streams as necessary. |
+ jobjectArray NativeToJavaMediaStreamArray( |
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 std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>& |
+ streams); |
- 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_; |
+ const ScopedGlobalRef<jobject> j_observer_global_; |
+ const ScopedGlobalRef<jclass> j_observer_class_; |
+ const ScopedGlobalRef<jclass> j_media_stream_class_; |
+ const jmethodID j_media_stream_ctor_; |
+ const ScopedGlobalRef<jclass> j_audio_track_class_; |
+ const jmethodID j_audio_track_ctor_; |
+ const ScopedGlobalRef<jclass> j_video_track_class_; |
+ const jmethodID j_video_track_ctor_; |
+ const ScopedGlobalRef<jclass> j_data_channel_class_; |
+ const jmethodID j_data_channel_ctor_; |
+ const ScopedGlobalRef<jclass> j_rtp_receiver_class_; |
+ const jmethodID j_rtp_receiver_ctor_; |
+ // C++ -> Java remote streams. The stored jobects are global refs and must be |
+ // manually deleted upon removal. Use DisposeRemoteStream(). |
+ NativeToJavaStreamsMap remote_streams_; |
+ NativeToJavaRtpReceiverMap rtp_receivers_; |
+ std::unique_ptr<MediaConstraintsJni> constraints_; |
}; |
} // namespace webrtc_jni |
-#endif // WEBRTC_SDK_ANDROID_SRC_JNI_RTCSTATSCOLLECTORCALLBACKWRAPPER_H_ |
+#endif // WEBRTC_SDK_ANDROID_SRC_JNI_PC_PEERCONNECTIONOBSERVER_JNI_H_ |