OLD | NEW |
| (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_PEERCONNECTIONOBSERVER_JNI_H_ | |
12 #define WEBRTC_SDK_ANDROID_SRC_JNI_PC_PEERCONNECTIONOBSERVER_JNI_H_ | |
13 | |
14 #include <map> | |
15 #include <memory> | |
16 #include <vector> | |
17 | |
18 #include "webrtc/api/peerconnectioninterface.h" | |
19 #include "webrtc/sdk/android/src/jni/jni_helpers.h" | |
20 #include "webrtc/sdk/android/src/jni/pc/mediaconstraints_jni.h" | |
21 | |
22 namespace webrtc_jni { | |
23 | |
24 // Adapter between the C++ PeerConnectionObserver interface and the Java | |
25 // PeerConnection.Observer interface. Wraps an instance of the Java interface | |
26 // and dispatches C++ callbacks to Java. | |
27 class PeerConnectionObserverJni : public webrtc::PeerConnectionObserver { | |
28 public: | |
29 PeerConnectionObserverJni(JNIEnv* jni, jobject j_observer); | |
30 virtual ~PeerConnectionObserverJni(); | |
31 | |
32 // Implementation of PeerConnectionObserver interface, which propagates | |
33 // the callbacks to the Java observer. | |
34 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; | |
35 void OnIceCandidatesRemoved( | |
36 const std::vector<cricket::Candidate>& candidates) override; | |
37 void OnSignalingChange( | |
38 webrtc::PeerConnectionInterface::SignalingState new_state) override; | |
39 void OnIceConnectionChange( | |
40 webrtc::PeerConnectionInterface::IceConnectionState new_state) override; | |
41 void OnIceConnectionReceivingChange(bool receiving) override; | |
42 void OnIceGatheringChange( | |
43 webrtc::PeerConnectionInterface::IceGatheringState new_state) override; | |
44 void OnAddStream( | |
45 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override; | |
46 void OnRemoveStream( | |
47 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override; | |
48 void OnDataChannel( | |
49 rtc::scoped_refptr<webrtc::DataChannelInterface> channel) override; | |
50 void OnRenegotiationNeeded() override; | |
51 void OnAddTrack( | |
52 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver, | |
53 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>& | |
54 streams) override; | |
55 | |
56 void SetConstraints(MediaConstraintsJni* constraints); | |
57 const MediaConstraintsJni* constraints() { return constraints_.get(); } | |
58 | |
59 private: | |
60 typedef std::map<webrtc::MediaStreamInterface*, jobject> | |
61 NativeToJavaStreamsMap; | |
62 typedef std::map<webrtc::RtpReceiverInterface*, jobject> | |
63 NativeToJavaRtpReceiverMap; | |
64 | |
65 void DisposeRemoteStream(const NativeToJavaStreamsMap::iterator& it); | |
66 void DisposeRtpReceiver(const NativeToJavaRtpReceiverMap::iterator& it); | |
67 | |
68 // If the NativeToJavaStreamsMap contains the stream, return it. | |
69 // Otherwise, create a new Java MediaStream. | |
70 jobject GetOrCreateJavaStream( | |
71 const rtc::scoped_refptr<webrtc::MediaStreamInterface>& stream); | |
72 | |
73 // Converts array of streams, creating or re-using Java streams as necessary. | |
74 jobjectArray NativeToJavaMediaStreamArray( | |
75 JNIEnv* jni, | |
76 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>& | |
77 streams); | |
78 | |
79 const ScopedGlobalRef<jobject> j_observer_global_; | |
80 const ScopedGlobalRef<jclass> j_observer_class_; | |
81 const ScopedGlobalRef<jclass> j_media_stream_class_; | |
82 const jmethodID j_media_stream_ctor_; | |
83 const ScopedGlobalRef<jclass> j_audio_track_class_; | |
84 const jmethodID j_audio_track_ctor_; | |
85 const ScopedGlobalRef<jclass> j_video_track_class_; | |
86 const jmethodID j_video_track_ctor_; | |
87 const ScopedGlobalRef<jclass> j_data_channel_class_; | |
88 const jmethodID j_data_channel_ctor_; | |
89 const ScopedGlobalRef<jclass> j_rtp_receiver_class_; | |
90 const jmethodID j_rtp_receiver_ctor_; | |
91 // C++ -> Java remote streams. The stored jobects are global refs and must be | |
92 // manually deleted upon removal. Use DisposeRemoteStream(). | |
93 NativeToJavaStreamsMap remote_streams_; | |
94 NativeToJavaRtpReceiverMap rtp_receivers_; | |
95 std::unique_ptr<MediaConstraintsJni> constraints_; | |
96 }; | |
97 | |
98 } // namespace webrtc_jni | |
99 | |
100 #endif // WEBRTC_SDK_ANDROID_SRC_JNI_PC_PEERCONNECTIONOBSERVER_JNI_H_ | |
OLD | NEW |