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

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

Issue 3007543002: Add PeerConnectionObserver#onRemoveTrack to android sdk
Patch Set: review fixes Created 3 years, 3 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
1 /* 1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_SDK_ANDROID_SRC_JNI_PC_PEERCONNECTIONOBSERVER_JNI_H_ 11 #ifndef WEBRTC_SDK_ANDROID_SRC_JNI_PC_PEERCONNECTIONOBSERVER_JNI_H_
12 #define WEBRTC_SDK_ANDROID_SRC_JNI_PC_PEERCONNECTIONOBSERVER_JNI_H_ 12 #define WEBRTC_SDK_ANDROID_SRC_JNI_PC_PEERCONNECTIONOBSERVER_JNI_H_
13 13
14 #include <webrtc/pc/mediastreamobserver.h>
14 #include <map> 15 #include <map>
15 #include <memory> 16 #include <memory>
16 #include <vector> 17 #include <vector>
17 18
18 #include "webrtc/api/peerconnectioninterface.h" 19 #include "webrtc/api/peerconnectioninterface.h"
19 #include "webrtc/sdk/android/src/jni/jni_helpers.h" 20 #include "webrtc/sdk/android/src/jni/jni_helpers.h"
20 #include "webrtc/sdk/android/src/jni/pc/mediaconstraints_jni.h" 21 #include "webrtc/sdk/android/src/jni/pc/mediaconstraints_jni.h"
21 22
22 namespace webrtc_jni { 23 namespace webrtc_jni {
23 24
24 // Adapter between the C++ PeerConnectionObserver interface and the Java 25 // Adapter between the C++ PeerConnectionObserver interface and the Java
25 // PeerConnection.Observer interface. Wraps an instance of the Java interface 26 // PeerConnection.Observer interface. Wraps an instance of the Java interface
26 // and dispatches C++ callbacks to Java. 27 // and dispatches C++ callbacks to Java.
27 class PeerConnectionObserverJni : public webrtc::PeerConnectionObserver { 28 class PeerConnectionObserverJni : public webrtc::PeerConnectionObserver,
29 public sigslot::has_slots<> {
28 public: 30 public:
29 PeerConnectionObserverJni(JNIEnv* jni, jobject j_observer); 31 PeerConnectionObserverJni(JNIEnv* jni, jobject j_observer);
30 virtual ~PeerConnectionObserverJni(); 32 virtual ~PeerConnectionObserverJni();
31 33
32 // Implementation of PeerConnectionObserver interface, which propagates 34 // Implementation of PeerConnectionObserver interface, which propagates
33 // the callbacks to the Java observer. 35 // the callbacks to the Java observer.
34 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override; 36 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
35 void OnIceCandidatesRemoved( 37 void OnIceCandidatesRemoved(
36 const std::vector<cricket::Candidate>& candidates) override; 38 const std::vector<cricket::Candidate>& candidates) override;
37 void OnSignalingChange( 39 void OnSignalingChange(
(...skipping 16 matching lines...) Expand all
54 streams) override; 56 streams) override;
55 57
56 void SetConstraints(MediaConstraintsJni* constraints); 58 void SetConstraints(MediaConstraintsJni* constraints);
57 const MediaConstraintsJni* constraints() { return constraints_.get(); } 59 const MediaConstraintsJni* constraints() { return constraints_.get(); }
58 60
59 private: 61 private:
60 typedef std::map<webrtc::MediaStreamInterface*, jobject> 62 typedef std::map<webrtc::MediaStreamInterface*, jobject>
61 NativeToJavaStreamsMap; 63 NativeToJavaStreamsMap;
62 typedef std::map<webrtc::RtpReceiverInterface*, jobject> 64 typedef std::map<webrtc::RtpReceiverInterface*, jobject>
63 NativeToJavaRtpReceiverMap; 65 NativeToJavaRtpReceiverMap;
66 typedef std::map<webrtc::MediaStreamTrackInterface*, jobject>
67 NativeToJavaMediaTrackMap;
68 typedef std::map<webrtc::MediaStreamTrackInterface*,
69 webrtc::RtpReceiverInterface*>
70 NativeMediaStreamTrackToNativeRtpReceiver;
64 71
65 void DisposeRemoteStream(const NativeToJavaStreamsMap::iterator& it); 72 void DisposeRemoteStream(const NativeToJavaStreamsMap::iterator& it);
66 void DisposeRtpReceiver(const NativeToJavaRtpReceiverMap::iterator& it); 73 void DisposeRtpReceiver(const NativeToJavaRtpReceiverMap::iterator& it);
74 void DisposeRemoteTrack(const NativeToJavaMediaTrackMap::iterator& it);
67 75
68 // If the NativeToJavaStreamsMap contains the stream, return it. 76 // If the NativeToJavaStreamsMap contains the stream, return it.
69 // Otherwise, create a new Java MediaStream. 77 // Otherwise, create a new Java MediaStream.
70 jobject GetOrCreateJavaStream( 78 jobject GetOrCreateJavaStream(
71 const rtc::scoped_refptr<webrtc::MediaStreamInterface>& stream); 79 const rtc::scoped_refptr<webrtc::MediaStreamInterface>& stream);
72 80
73 // Converts array of streams, creating or re-using Java streams as necessary. 81 // Converts array of streams, creating or re-using Java streams as necessary.
74 jobjectArray NativeToJavaMediaStreamArray( 82 jobjectArray NativeToJavaMediaStreamArray(
75 JNIEnv* jni, 83 JNIEnv* jni,
76 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>& 84 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
77 streams); 85 streams);
78 86
87 void OnAudioTrackAdded(webrtc::AudioTrackInterface* track,
88 webrtc::MediaStreamInterface* stream);
89 void OnVideoTrackAdded(webrtc::VideoTrackInterface* track,
90 webrtc::MediaStreamInterface* stream);
91 void OnAudioTrackRemoved(webrtc::AudioTrackInterface* track,
92 webrtc::MediaStreamInterface* stream);
93 void OnVideoTrackRemoved(webrtc::VideoTrackInterface* track,
94 webrtc::MediaStreamInterface* stream);
95
79 const ScopedGlobalRef<jobject> j_observer_global_; 96 const ScopedGlobalRef<jobject> j_observer_global_;
80 const ScopedGlobalRef<jclass> j_observer_class_; 97 const ScopedGlobalRef<jclass> j_observer_class_;
81 const ScopedGlobalRef<jclass> j_media_stream_class_; 98 const ScopedGlobalRef<jclass> j_media_stream_class_;
82 const jmethodID j_media_stream_ctor_; 99 const jmethodID j_media_stream_ctor_;
83 const ScopedGlobalRef<jclass> j_audio_track_class_; 100 const ScopedGlobalRef<jclass> j_audio_track_class_;
84 const jmethodID j_audio_track_ctor_; 101 const jmethodID j_audio_track_ctor_;
85 const ScopedGlobalRef<jclass> j_video_track_class_; 102 const ScopedGlobalRef<jclass> j_video_track_class_;
86 const jmethodID j_video_track_ctor_; 103 const jmethodID j_video_track_ctor_;
87 const ScopedGlobalRef<jclass> j_data_channel_class_; 104 const ScopedGlobalRef<jclass> j_data_channel_class_;
88 const jmethodID j_data_channel_ctor_; 105 const jmethodID j_data_channel_ctor_;
89 const ScopedGlobalRef<jclass> j_rtp_receiver_class_; 106 const ScopedGlobalRef<jclass> j_rtp_receiver_class_;
90 const jmethodID j_rtp_receiver_ctor_; 107 const jmethodID j_rtp_receiver_ctor_;
108
91 // C++ -> Java remote streams. The stored jobects are global refs and must be 109 // C++ -> Java remote streams. The stored jobects are global refs and must be
92 // manually deleted upon removal. Use DisposeRemoteStream(). 110 // manually deleted upon removal. Use DisposeRemoteStream().
93 NativeToJavaStreamsMap remote_streams_; 111 NativeToJavaStreamsMap remote_streams_;
112 std::unique_ptr<MediaConstraintsJni> constraints_;
94 NativeToJavaRtpReceiverMap rtp_receivers_; 113 NativeToJavaRtpReceiverMap rtp_receivers_;
95 std::unique_ptr<MediaConstraintsJni> constraints_; 114 NativeMediaStreamTrackToNativeRtpReceiver track_to_receiver_;
115 std::vector<std::unique_ptr<webrtc::MediaStreamObserver>> stream_observers_;
116 NativeToJavaMediaTrackMap remote_tracks_;
96 }; 117 };
97 118
98 } // namespace webrtc_jni 119 } // namespace webrtc_jni
99 120
100 #endif // WEBRTC_SDK_ANDROID_SRC_JNI_PC_PEERCONNECTIONOBSERVER_JNI_H_ 121 #endif // WEBRTC_SDK_ANDROID_SRC_JNI_PC_PEERCONNECTIONOBSERVER_JNI_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698