OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 namespace webrtc { | 45 namespace webrtc { |
46 | 46 |
47 // TrackHandler listen to events on a MediaStreamTrackInterface that is | 47 // TrackHandler listen to events on a MediaStreamTrackInterface that is |
48 // connected to a certain PeerConnection. | 48 // connected to a certain PeerConnection. |
49 class TrackHandler : public ObserverInterface { | 49 class TrackHandler : public ObserverInterface { |
50 public: | 50 public: |
51 TrackHandler(MediaStreamTrackInterface* track, uint32 ssrc); | 51 TrackHandler(MediaStreamTrackInterface* track, uint32 ssrc); |
52 virtual ~TrackHandler(); | 52 virtual ~TrackHandler(); |
53 virtual void OnChanged(); | 53 virtual void OnChanged(); |
| 54 // Associate |track_| with |ssrc_|. Can be called multiple times. |
| 55 virtual void Start() = 0; |
54 // Stop using |track_| on this PeerConnection. | 56 // Stop using |track_| on this PeerConnection. |
55 virtual void Stop() = 0; | 57 virtual void Stop() = 0; |
56 | 58 |
57 MediaStreamTrackInterface* track() { return track_; } | 59 MediaStreamTrackInterface* track() { return track_; } |
58 uint32 ssrc() const { return ssrc_; } | 60 uint32 ssrc() const { return ssrc_; } |
59 | 61 |
60 protected: | 62 protected: |
61 virtual void OnStateChanged() = 0; | 63 virtual void OnStateChanged() = 0; |
62 virtual void OnEnabledChanged() = 0; | 64 virtual void OnEnabledChanged() = 0; |
63 | 65 |
(...skipping 30 matching lines...) Expand all Loading... |
94 | 96 |
95 // LocalAudioTrackHandler listen to events on a local AudioTrack instance | 97 // LocalAudioTrackHandler listen to events on a local AudioTrack instance |
96 // connected to a PeerConnection and orders the |provider| to executes the | 98 // connected to a PeerConnection and orders the |provider| to executes the |
97 // requested change. | 99 // requested change. |
98 class LocalAudioTrackHandler : public TrackHandler { | 100 class LocalAudioTrackHandler : public TrackHandler { |
99 public: | 101 public: |
100 LocalAudioTrackHandler(AudioTrackInterface* track, | 102 LocalAudioTrackHandler(AudioTrackInterface* track, |
101 uint32 ssrc, | 103 uint32 ssrc, |
102 AudioProviderInterface* provider); | 104 AudioProviderInterface* provider); |
103 virtual ~LocalAudioTrackHandler(); | 105 virtual ~LocalAudioTrackHandler(); |
104 | 106 void Start() override; |
105 void Stop() override; | 107 void Stop() override; |
106 | 108 |
107 protected: | 109 protected: |
108 void OnStateChanged() override; | 110 void OnStateChanged() override; |
109 void OnEnabledChanged() override; | 111 void OnEnabledChanged() override; |
110 | 112 |
111 private: | 113 private: |
112 AudioTrackInterface* audio_track_; | 114 AudioTrackInterface* audio_track_; |
113 AudioProviderInterface* provider_; | 115 AudioProviderInterface* provider_; |
114 | 116 |
115 // Used to pass the data callback from the |audio_track_| to the other | 117 // Used to pass the data callback from the |audio_track_| to the other |
116 // end of cricket::AudioRenderer. | 118 // end of cricket::AudioRenderer. |
117 rtc::scoped_ptr<LocalAudioSinkAdapter> sink_adapter_; | 119 rtc::scoped_ptr<LocalAudioSinkAdapter> sink_adapter_; |
118 }; | 120 }; |
119 | 121 |
120 // RemoteAudioTrackHandler listen to events on a remote AudioTrack instance | 122 // RemoteAudioTrackHandler listen to events on a remote AudioTrack instance |
121 // connected to a PeerConnection and orders the |provider| to executes the | 123 // connected to a PeerConnection and orders the |provider| to executes the |
122 // requested change. | 124 // requested change. |
123 class RemoteAudioTrackHandler : public AudioSourceInterface::AudioObserver, | 125 class RemoteAudioTrackHandler : public AudioSourceInterface::AudioObserver, |
124 public TrackHandler { | 126 public TrackHandler { |
125 public: | 127 public: |
126 RemoteAudioTrackHandler(AudioTrackInterface* track, | 128 RemoteAudioTrackHandler(AudioTrackInterface* track, |
127 uint32 ssrc, | 129 uint32 ssrc, |
128 AudioProviderInterface* provider); | 130 AudioProviderInterface* provider); |
129 virtual ~RemoteAudioTrackHandler(); | 131 virtual ~RemoteAudioTrackHandler(); |
| 132 void Start() override; |
130 void Stop() override; | 133 void Stop() override; |
131 | 134 |
132 protected: | 135 protected: |
133 void OnStateChanged() override; | 136 void OnStateChanged() override; |
134 void OnEnabledChanged() override; | 137 void OnEnabledChanged() override; |
135 | 138 |
136 private: | 139 private: |
137 // AudioSourceInterface::AudioObserver implementation. | 140 // AudioSourceInterface::AudioObserver implementation. |
138 void OnSetVolume(double volume) override; | 141 void OnSetVolume(double volume) override; |
139 | 142 |
140 AudioTrackInterface* audio_track_; | 143 AudioTrackInterface* audio_track_; |
141 AudioProviderInterface* provider_; | 144 AudioProviderInterface* provider_; |
142 }; | 145 }; |
143 | 146 |
144 // LocalVideoTrackHandler listen to events on a local VideoTrack instance | 147 // LocalVideoTrackHandler listen to events on a local VideoTrack instance |
145 // connected to a PeerConnection and orders the |provider| to executes the | 148 // connected to a PeerConnection and orders the |provider| to executes the |
146 // requested change. | 149 // requested change. |
147 class LocalVideoTrackHandler : public TrackHandler { | 150 class LocalVideoTrackHandler : public TrackHandler { |
148 public: | 151 public: |
149 LocalVideoTrackHandler(VideoTrackInterface* track, | 152 LocalVideoTrackHandler(VideoTrackInterface* track, |
150 uint32 ssrc, | 153 uint32 ssrc, |
151 VideoProviderInterface* provider); | 154 VideoProviderInterface* provider); |
152 virtual ~LocalVideoTrackHandler(); | 155 virtual ~LocalVideoTrackHandler(); |
| 156 void Start() override; |
153 void Stop() override; | 157 void Stop() override; |
154 | 158 |
155 protected: | 159 protected: |
156 void OnStateChanged() override; | 160 void OnStateChanged() override; |
157 void OnEnabledChanged() override; | 161 void OnEnabledChanged() override; |
158 | 162 |
159 private: | 163 private: |
160 VideoTrackInterface* local_video_track_; | 164 VideoTrackInterface* local_video_track_; |
161 VideoProviderInterface* provider_; | 165 VideoProviderInterface* provider_; |
162 }; | 166 }; |
163 | 167 |
164 // RemoteVideoTrackHandler listen to events on a remote VideoTrack instance | 168 // RemoteVideoTrackHandler listen to events on a remote VideoTrack instance |
165 // connected to a PeerConnection and orders the |provider| to execute | 169 // connected to a PeerConnection and orders the |provider| to execute |
166 // requested changes. | 170 // requested changes. |
167 class RemoteVideoTrackHandler : public TrackHandler { | 171 class RemoteVideoTrackHandler : public TrackHandler { |
168 public: | 172 public: |
169 RemoteVideoTrackHandler(VideoTrackInterface* track, | 173 RemoteVideoTrackHandler(VideoTrackInterface* track, |
170 uint32 ssrc, | 174 uint32 ssrc, |
171 VideoProviderInterface* provider); | 175 VideoProviderInterface* provider); |
172 virtual ~RemoteVideoTrackHandler(); | 176 virtual ~RemoteVideoTrackHandler(); |
| 177 void Start() override; |
173 void Stop() override; | 178 void Stop() override; |
174 | 179 |
175 protected: | 180 protected: |
176 void OnStateChanged() override; | 181 void OnStateChanged() override; |
177 void OnEnabledChanged() override; | 182 void OnEnabledChanged() override; |
178 | 183 |
179 private: | 184 private: |
180 VideoTrackInterface* remote_video_track_; | 185 VideoTrackInterface* remote_video_track_; |
181 VideoProviderInterface* provider_; | 186 VideoProviderInterface* provider_; |
182 }; | 187 }; |
183 | 188 |
184 class MediaStreamHandler : public ObserverInterface { | 189 class MediaStreamHandler : public ObserverInterface { |
185 public: | 190 public: |
186 MediaStreamHandler(MediaStreamInterface* stream, | 191 MediaStreamHandler(MediaStreamInterface* stream, |
187 AudioProviderInterface* audio_provider, | 192 AudioProviderInterface* audio_provider, |
188 VideoProviderInterface* video_provider); | 193 VideoProviderInterface* video_provider); |
189 ~MediaStreamHandler(); | 194 ~MediaStreamHandler(); |
190 MediaStreamInterface* stream(); | 195 MediaStreamInterface* stream(); |
191 void Stop(); | 196 void Stop(); |
192 | 197 |
193 virtual void AddAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc) = 0; | 198 virtual void AddAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc) = 0; |
194 virtual void AddVideoTrack(VideoTrackInterface* video_track, uint32 ssrc) = 0; | 199 virtual void AddVideoTrack(VideoTrackInterface* video_track, uint32 ssrc) = 0; |
| 200 virtual void RestartAllTracks() = 0; |
195 | 201 |
196 virtual void RemoveTrack(MediaStreamTrackInterface* track); | 202 virtual void RemoveTrack(MediaStreamTrackInterface* track); |
197 void OnChanged() override; | 203 void OnChanged() override; |
198 | 204 |
199 protected: | 205 protected: |
200 TrackHandler* FindTrackHandler(MediaStreamTrackInterface* track); | 206 TrackHandler* FindTrackHandler(MediaStreamTrackInterface* track); |
201 rtc::scoped_refptr<MediaStreamInterface> stream_; | 207 rtc::scoped_refptr<MediaStreamInterface> stream_; |
202 AudioProviderInterface* audio_provider_; | 208 AudioProviderInterface* audio_provider_; |
203 VideoProviderInterface* video_provider_; | 209 VideoProviderInterface* video_provider_; |
204 typedef std::vector<TrackHandler*> TrackHandlers; | 210 typedef std::vector<TrackHandler*> TrackHandlers; |
205 TrackHandlers track_handlers_; | 211 TrackHandlers track_handlers_; |
206 }; | 212 }; |
207 | 213 |
208 class LocalMediaStreamHandler : public MediaStreamHandler { | 214 class LocalMediaStreamHandler : public MediaStreamHandler { |
209 public: | 215 public: |
210 LocalMediaStreamHandler(MediaStreamInterface* stream, | 216 LocalMediaStreamHandler(MediaStreamInterface* stream, |
211 AudioProviderInterface* audio_provider, | 217 AudioProviderInterface* audio_provider, |
212 VideoProviderInterface* video_provider); | 218 VideoProviderInterface* video_provider); |
213 ~LocalMediaStreamHandler(); | 219 ~LocalMediaStreamHandler(); |
214 | 220 |
215 void AddAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc) override; | 221 void AddAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc) override; |
216 void AddVideoTrack(VideoTrackInterface* video_track, uint32 ssrc) override; | 222 void AddVideoTrack(VideoTrackInterface* video_track, uint32 ssrc) override; |
| 223 void RestartAllTracks() override; |
217 }; | 224 }; |
218 | 225 |
219 class RemoteMediaStreamHandler : public MediaStreamHandler { | 226 class RemoteMediaStreamHandler : public MediaStreamHandler { |
220 public: | 227 public: |
221 RemoteMediaStreamHandler(MediaStreamInterface* stream, | 228 RemoteMediaStreamHandler(MediaStreamInterface* stream, |
222 AudioProviderInterface* audio_provider, | 229 AudioProviderInterface* audio_provider, |
223 VideoProviderInterface* video_provider); | 230 VideoProviderInterface* video_provider); |
224 ~RemoteMediaStreamHandler(); | 231 ~RemoteMediaStreamHandler(); |
225 void AddAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc) override; | 232 void AddAudioTrack(AudioTrackInterface* audio_track, uint32 ssrc) override; |
226 void AddVideoTrack(VideoTrackInterface* video_track, uint32 ssrc) override; | 233 void AddVideoTrack(VideoTrackInterface* video_track, uint32 ssrc) override; |
| 234 void RestartAllTracks() override; |
227 }; | 235 }; |
228 | 236 |
229 // Container for MediaStreamHandlers of currently known local and remote | 237 // Container for MediaStreamHandlers of currently known local and remote |
230 // MediaStreams. | 238 // MediaStreams. |
231 class MediaStreamHandlerContainer { | 239 class MediaStreamHandlerContainer { |
232 public: | 240 public: |
233 MediaStreamHandlerContainer(AudioProviderInterface* audio_provider, | 241 MediaStreamHandlerContainer(AudioProviderInterface* audio_provider, |
234 VideoProviderInterface* video_provider); | 242 VideoProviderInterface* video_provider); |
235 ~MediaStreamHandlerContainer(); | 243 ~MediaStreamHandlerContainer(); |
236 | 244 |
(...skipping 12 matching lines...) Expand all Loading... |
249 AudioTrackInterface* audio_track, | 257 AudioTrackInterface* audio_track, |
250 uint32 ssrc); | 258 uint32 ssrc); |
251 // Create a RemoteVideoTrackHandler and associate |video_track| with |ssrc|. | 259 // Create a RemoteVideoTrackHandler and associate |video_track| with |ssrc|. |
252 void AddRemoteVideoTrack(MediaStreamInterface* stream, | 260 void AddRemoteVideoTrack(MediaStreamInterface* stream, |
253 VideoTrackInterface* video_track, | 261 VideoTrackInterface* video_track, |
254 uint32 ssrc); | 262 uint32 ssrc); |
255 // Remove the TrackHandler for |track|. | 263 // Remove the TrackHandler for |track|. |
256 void RemoveRemoteTrack(MediaStreamInterface* stream, | 264 void RemoveRemoteTrack(MediaStreamInterface* stream, |
257 MediaStreamTrackInterface* track); | 265 MediaStreamTrackInterface* track); |
258 | 266 |
| 267 // Make all remote track handlers reassociate their corresponding tracks |
| 268 // with their corresponding SSRCs. |
| 269 void RestartAllRemoteTracks(); |
| 270 |
259 // Remove all TrackHandlers for tracks in |stream| and make sure | 271 // Remove all TrackHandlers for tracks in |stream| and make sure |
260 // the audio_provider and video_provider is notified that the tracks has been | 272 // the audio_provider and video_provider is notified that the tracks has been |
261 // removed. | 273 // removed. |
262 void RemoveLocalStream(MediaStreamInterface* stream); | 274 void RemoveLocalStream(MediaStreamInterface* stream); |
263 | 275 |
264 // Create a LocalAudioTrackHandler and associate |audio_track| with |ssrc|. | 276 // Create a LocalAudioTrackHandler and associate |audio_track| with |ssrc|. |
265 void AddLocalAudioTrack(MediaStreamInterface* stream, | 277 void AddLocalAudioTrack(MediaStreamInterface* stream, |
266 AudioTrackInterface* audio_track, | 278 AudioTrackInterface* audio_track, |
267 uint32 ssrc); | 279 uint32 ssrc); |
268 // Create a LocalVideoTrackHandler and associate |video_track| with |ssrc|. | 280 // Create a LocalVideoTrackHandler and associate |video_track| with |ssrc|. |
269 void AddLocalVideoTrack(MediaStreamInterface* stream, | 281 void AddLocalVideoTrack(MediaStreamInterface* stream, |
270 VideoTrackInterface* video_track, | 282 VideoTrackInterface* video_track, |
271 uint32 ssrc); | 283 uint32 ssrc); |
272 // Remove the TrackHandler for |track|. | 284 // Remove the TrackHandler for |track|. |
273 void RemoveLocalTrack(MediaStreamInterface* stream, | 285 void RemoveLocalTrack(MediaStreamInterface* stream, |
274 MediaStreamTrackInterface* track); | 286 MediaStreamTrackInterface* track); |
275 | 287 |
| 288 // Make all local track handlers reassociate their corresponding tracks |
| 289 // with their corresponding SSRCs. |
| 290 void RestartAllLocalTracks(); |
| 291 |
276 private: | 292 private: |
277 typedef std::list<MediaStreamHandler*> StreamHandlerList; | 293 typedef std::list<MediaStreamHandler*> StreamHandlerList; |
278 MediaStreamHandler* FindStreamHandler(const StreamHandlerList& handlers, | 294 MediaStreamHandler* FindStreamHandler(const StreamHandlerList& handlers, |
279 MediaStreamInterface* stream); | 295 MediaStreamInterface* stream); |
280 MediaStreamHandler* CreateRemoteStreamHandler(MediaStreamInterface* stream); | 296 MediaStreamHandler* CreateRemoteStreamHandler(MediaStreamInterface* stream); |
281 MediaStreamHandler* CreateLocalStreamHandler(MediaStreamInterface* stream); | 297 MediaStreamHandler* CreateLocalStreamHandler(MediaStreamInterface* stream); |
282 void DeleteStreamHandler(StreamHandlerList* streamhandlers, | 298 void DeleteStreamHandler(StreamHandlerList* streamhandlers, |
283 MediaStreamInterface* stream); | 299 MediaStreamInterface* stream); |
284 | 300 |
285 StreamHandlerList local_streams_handlers_; | 301 StreamHandlerList local_streams_handlers_; |
286 StreamHandlerList remote_streams_handlers_; | 302 StreamHandlerList remote_streams_handlers_; |
287 AudioProviderInterface* audio_provider_; | 303 AudioProviderInterface* audio_provider_; |
288 VideoProviderInterface* video_provider_; | 304 VideoProviderInterface* video_provider_; |
289 }; | 305 }; |
290 | 306 |
291 } // namespace webrtc | 307 } // namespace webrtc |
292 | 308 |
293 #endif // TALK_APP_WEBRTC_MEDIASTREAMHANDLER_H_ | 309 #endif // TALK_APP_WEBRTC_MEDIASTREAMHANDLER_H_ |
OLD | NEW |