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 15 matching lines...) Expand all Loading... |
26 */ | 26 */ |
27 | 27 |
28 #include "talk/app/webrtc/mediastreamhandler.h" | 28 #include "talk/app/webrtc/mediastreamhandler.h" |
29 | 29 |
30 #include "talk/app/webrtc/localaudiosource.h" | 30 #include "talk/app/webrtc/localaudiosource.h" |
31 #include "talk/app/webrtc/videosource.h" | 31 #include "talk/app/webrtc/videosource.h" |
32 #include "talk/app/webrtc/videosourceinterface.h" | 32 #include "talk/app/webrtc/videosourceinterface.h" |
33 | 33 |
34 namespace webrtc { | 34 namespace webrtc { |
35 | 35 |
36 TrackHandler::TrackHandler(MediaStreamTrackInterface* track, uint32 ssrc) | 36 TrackHandler::TrackHandler(MediaStreamTrackInterface* track, uint32_t ssrc) |
37 : track_(track), | 37 : track_(track), |
38 ssrc_(ssrc), | 38 ssrc_(ssrc), |
39 state_(track->state()), | 39 state_(track->state()), |
40 enabled_(track->enabled()) { | 40 enabled_(track->enabled()) { |
41 track_->RegisterObserver(this); | 41 track_->RegisterObserver(this); |
42 } | 42 } |
43 | 43 |
44 TrackHandler::~TrackHandler() { | 44 TrackHandler::~TrackHandler() { |
45 track_->UnregisterObserver(this); | 45 track_->UnregisterObserver(this); |
46 } | 46 } |
(...skipping 28 matching lines...) Expand all Loading... |
75 number_of_channels, number_of_frames); | 75 number_of_channels, number_of_frames); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 void LocalAudioSinkAdapter::SetSink(cricket::AudioRenderer::Sink* sink) { | 79 void LocalAudioSinkAdapter::SetSink(cricket::AudioRenderer::Sink* sink) { |
80 rtc::CritScope lock(&lock_); | 80 rtc::CritScope lock(&lock_); |
81 ASSERT(!sink || !sink_); | 81 ASSERT(!sink || !sink_); |
82 sink_ = sink; | 82 sink_ = sink; |
83 } | 83 } |
84 | 84 |
85 LocalAudioTrackHandler::LocalAudioTrackHandler( | 85 LocalAudioTrackHandler::LocalAudioTrackHandler(AudioTrackInterface* track, |
86 AudioTrackInterface* track, | 86 uint32_t ssrc, |
87 uint32 ssrc, | 87 AudioProviderInterface* provider) |
88 AudioProviderInterface* provider) | |
89 : TrackHandler(track, ssrc), | 88 : TrackHandler(track, ssrc), |
90 audio_track_(track), | 89 audio_track_(track), |
91 provider_(provider), | 90 provider_(provider), |
92 sink_adapter_(new LocalAudioSinkAdapter()) { | 91 sink_adapter_(new LocalAudioSinkAdapter()) { |
93 OnEnabledChanged(); | 92 OnEnabledChanged(); |
94 track->AddSink(sink_adapter_.get()); | 93 track->AddSink(sink_adapter_.get()); |
95 } | 94 } |
96 | 95 |
97 LocalAudioTrackHandler::~LocalAudioTrackHandler() { | 96 LocalAudioTrackHandler::~LocalAudioTrackHandler() { |
98 } | 97 } |
(...skipping 20 matching lines...) Expand all Loading... |
119 // Use the renderer if the audio track has one, otherwise use the sink | 118 // Use the renderer if the audio track has one, otherwise use the sink |
120 // adapter owned by this class. | 119 // adapter owned by this class. |
121 cricket::AudioRenderer* renderer = audio_track_->GetRenderer() ? | 120 cricket::AudioRenderer* renderer = audio_track_->GetRenderer() ? |
122 audio_track_->GetRenderer() : sink_adapter_.get(); | 121 audio_track_->GetRenderer() : sink_adapter_.get(); |
123 ASSERT(renderer != NULL); | 122 ASSERT(renderer != NULL); |
124 provider_->SetAudioSend(ssrc(), audio_track_->enabled(), options, renderer); | 123 provider_->SetAudioSend(ssrc(), audio_track_->enabled(), options, renderer); |
125 } | 124 } |
126 | 125 |
127 RemoteAudioTrackHandler::RemoteAudioTrackHandler( | 126 RemoteAudioTrackHandler::RemoteAudioTrackHandler( |
128 AudioTrackInterface* track, | 127 AudioTrackInterface* track, |
129 uint32 ssrc, | 128 uint32_t ssrc, |
130 AudioProviderInterface* provider) | 129 AudioProviderInterface* provider) |
131 : TrackHandler(track, ssrc), | 130 : TrackHandler(track, ssrc), audio_track_(track), provider_(provider) { |
132 audio_track_(track), | |
133 provider_(provider) { | |
134 track->GetSource()->RegisterAudioObserver(this); | 131 track->GetSource()->RegisterAudioObserver(this); |
135 OnEnabledChanged(); | 132 OnEnabledChanged(); |
136 } | 133 } |
137 | 134 |
138 RemoteAudioTrackHandler::~RemoteAudioTrackHandler() { | 135 RemoteAudioTrackHandler::~RemoteAudioTrackHandler() { |
139 audio_track_->GetSource()->UnregisterAudioObserver(this); | 136 audio_track_->GetSource()->UnregisterAudioObserver(this); |
140 } | 137 } |
141 | 138 |
142 void RemoteAudioTrackHandler::Stop() { | 139 void RemoteAudioTrackHandler::Stop() { |
143 provider_->SetAudioPlayout(ssrc(), false, NULL); | 140 provider_->SetAudioPlayout(ssrc(), false, NULL); |
144 } | 141 } |
145 | 142 |
146 void RemoteAudioTrackHandler::OnStateChanged() { | 143 void RemoteAudioTrackHandler::OnStateChanged() { |
147 } | 144 } |
148 | 145 |
149 void RemoteAudioTrackHandler::OnEnabledChanged() { | 146 void RemoteAudioTrackHandler::OnEnabledChanged() { |
150 provider_->SetAudioPlayout(ssrc(), audio_track_->enabled(), | 147 provider_->SetAudioPlayout(ssrc(), audio_track_->enabled(), |
151 audio_track_->GetRenderer()); | 148 audio_track_->GetRenderer()); |
152 } | 149 } |
153 | 150 |
154 void RemoteAudioTrackHandler::OnSetVolume(double volume) { | 151 void RemoteAudioTrackHandler::OnSetVolume(double volume) { |
155 // When the track is disabled, the volume of the source, which is the | 152 // When the track is disabled, the volume of the source, which is the |
156 // corresponding WebRtc Voice Engine channel will be 0. So we do not allow | 153 // corresponding WebRtc Voice Engine channel will be 0. So we do not allow |
157 // setting the volume to the source when the track is disabled. | 154 // setting the volume to the source when the track is disabled. |
158 if (audio_track_->enabled()) | 155 if (audio_track_->enabled()) |
159 provider_->SetAudioPlayoutVolume(ssrc(), volume); | 156 provider_->SetAudioPlayoutVolume(ssrc(), volume); |
160 } | 157 } |
161 | 158 |
162 LocalVideoTrackHandler::LocalVideoTrackHandler( | 159 LocalVideoTrackHandler::LocalVideoTrackHandler(VideoTrackInterface* track, |
163 VideoTrackInterface* track, | 160 uint32_t ssrc, |
164 uint32 ssrc, | 161 VideoProviderInterface* provider) |
165 VideoProviderInterface* provider) | |
166 : TrackHandler(track, ssrc), | 162 : TrackHandler(track, ssrc), |
167 local_video_track_(track), | 163 local_video_track_(track), |
168 provider_(provider) { | 164 provider_(provider) { |
169 VideoSourceInterface* source = local_video_track_->GetSource(); | 165 VideoSourceInterface* source = local_video_track_->GetSource(); |
170 if (source) | 166 if (source) |
171 provider_->SetCaptureDevice(ssrc, source->GetVideoCapturer()); | 167 provider_->SetCaptureDevice(ssrc, source->GetVideoCapturer()); |
172 OnEnabledChanged(); | 168 OnEnabledChanged(); |
173 } | 169 } |
174 | 170 |
175 LocalVideoTrackHandler::~LocalVideoTrackHandler() { | 171 LocalVideoTrackHandler::~LocalVideoTrackHandler() { |
(...skipping 11 matching lines...) Expand all Loading... |
187 const cricket::VideoOptions* options = NULL; | 183 const cricket::VideoOptions* options = NULL; |
188 VideoSourceInterface* source = local_video_track_->GetSource(); | 184 VideoSourceInterface* source = local_video_track_->GetSource(); |
189 if (local_video_track_->enabled() && source) { | 185 if (local_video_track_->enabled() && source) { |
190 options = source->options(); | 186 options = source->options(); |
191 } | 187 } |
192 provider_->SetVideoSend(ssrc(), local_video_track_->enabled(), options); | 188 provider_->SetVideoSend(ssrc(), local_video_track_->enabled(), options); |
193 } | 189 } |
194 | 190 |
195 RemoteVideoTrackHandler::RemoteVideoTrackHandler( | 191 RemoteVideoTrackHandler::RemoteVideoTrackHandler( |
196 VideoTrackInterface* track, | 192 VideoTrackInterface* track, |
197 uint32 ssrc, | 193 uint32_t ssrc, |
198 VideoProviderInterface* provider) | 194 VideoProviderInterface* provider) |
199 : TrackHandler(track, ssrc), | 195 : TrackHandler(track, ssrc), |
200 remote_video_track_(track), | 196 remote_video_track_(track), |
201 provider_(provider) { | 197 provider_(provider) { |
202 OnEnabledChanged(); | 198 OnEnabledChanged(); |
203 provider_->SetVideoPlayout(ssrc, true, | 199 provider_->SetVideoPlayout(ssrc, true, |
204 remote_video_track_->GetSource()->FrameInput()); | 200 remote_video_track_->GetSource()->FrameInput()); |
205 } | 201 } |
206 | 202 |
207 RemoteVideoTrackHandler::~RemoteVideoTrackHandler() { | 203 RemoteVideoTrackHandler::~RemoteVideoTrackHandler() { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 MediaStreamInterface* stream, | 273 MediaStreamInterface* stream, |
278 AudioProviderInterface* audio_provider, | 274 AudioProviderInterface* audio_provider, |
279 VideoProviderInterface* video_provider) | 275 VideoProviderInterface* video_provider) |
280 : MediaStreamHandler(stream, audio_provider, video_provider) { | 276 : MediaStreamHandler(stream, audio_provider, video_provider) { |
281 } | 277 } |
282 | 278 |
283 LocalMediaStreamHandler::~LocalMediaStreamHandler() { | 279 LocalMediaStreamHandler::~LocalMediaStreamHandler() { |
284 } | 280 } |
285 | 281 |
286 void LocalMediaStreamHandler::AddAudioTrack(AudioTrackInterface* audio_track, | 282 void LocalMediaStreamHandler::AddAudioTrack(AudioTrackInterface* audio_track, |
287 uint32 ssrc) { | 283 uint32_t ssrc) { |
288 ASSERT(!FindTrackHandler(audio_track)); | 284 ASSERT(!FindTrackHandler(audio_track)); |
289 | 285 |
290 TrackHandler* handler(new LocalAudioTrackHandler(audio_track, ssrc, | 286 TrackHandler* handler(new LocalAudioTrackHandler(audio_track, ssrc, |
291 audio_provider_)); | 287 audio_provider_)); |
292 track_handlers_.push_back(handler); | 288 track_handlers_.push_back(handler); |
293 } | 289 } |
294 | 290 |
295 void LocalMediaStreamHandler::AddVideoTrack(VideoTrackInterface* video_track, | 291 void LocalMediaStreamHandler::AddVideoTrack(VideoTrackInterface* video_track, |
296 uint32 ssrc) { | 292 uint32_t ssrc) { |
297 ASSERT(!FindTrackHandler(video_track)); | 293 ASSERT(!FindTrackHandler(video_track)); |
298 | 294 |
299 TrackHandler* handler(new LocalVideoTrackHandler(video_track, ssrc, | 295 TrackHandler* handler(new LocalVideoTrackHandler(video_track, ssrc, |
300 video_provider_)); | 296 video_provider_)); |
301 track_handlers_.push_back(handler); | 297 track_handlers_.push_back(handler); |
302 } | 298 } |
303 | 299 |
304 RemoteMediaStreamHandler::RemoteMediaStreamHandler( | 300 RemoteMediaStreamHandler::RemoteMediaStreamHandler( |
305 MediaStreamInterface* stream, | 301 MediaStreamInterface* stream, |
306 AudioProviderInterface* audio_provider, | 302 AudioProviderInterface* audio_provider, |
307 VideoProviderInterface* video_provider) | 303 VideoProviderInterface* video_provider) |
308 : MediaStreamHandler(stream, audio_provider, video_provider) { | 304 : MediaStreamHandler(stream, audio_provider, video_provider) { |
309 } | 305 } |
310 | 306 |
311 RemoteMediaStreamHandler::~RemoteMediaStreamHandler() { | 307 RemoteMediaStreamHandler::~RemoteMediaStreamHandler() { |
312 } | 308 } |
313 | 309 |
314 void RemoteMediaStreamHandler::AddAudioTrack(AudioTrackInterface* audio_track, | 310 void RemoteMediaStreamHandler::AddAudioTrack(AudioTrackInterface* audio_track, |
315 uint32 ssrc) { | 311 uint32_t ssrc) { |
316 ASSERT(!FindTrackHandler(audio_track)); | 312 ASSERT(!FindTrackHandler(audio_track)); |
317 TrackHandler* handler( | 313 TrackHandler* handler( |
318 new RemoteAudioTrackHandler(audio_track, ssrc, audio_provider_)); | 314 new RemoteAudioTrackHandler(audio_track, ssrc, audio_provider_)); |
319 track_handlers_.push_back(handler); | 315 track_handlers_.push_back(handler); |
320 } | 316 } |
321 | 317 |
322 void RemoteMediaStreamHandler::AddVideoTrack(VideoTrackInterface* video_track, | 318 void RemoteMediaStreamHandler::AddVideoTrack(VideoTrackInterface* video_track, |
323 uint32 ssrc) { | 319 uint32_t ssrc) { |
324 ASSERT(!FindTrackHandler(video_track)); | 320 ASSERT(!FindTrackHandler(video_track)); |
325 TrackHandler* handler( | 321 TrackHandler* handler( |
326 new RemoteVideoTrackHandler(video_track, ssrc, video_provider_)); | 322 new RemoteVideoTrackHandler(video_track, ssrc, video_provider_)); |
327 track_handlers_.push_back(handler); | 323 track_handlers_.push_back(handler); |
328 } | 324 } |
329 | 325 |
330 MediaStreamHandlerContainer::MediaStreamHandlerContainer( | 326 MediaStreamHandlerContainer::MediaStreamHandlerContainer( |
331 AudioProviderInterface* audio_provider, | 327 AudioProviderInterface* audio_provider, |
332 VideoProviderInterface* video_provider) | 328 VideoProviderInterface* video_provider) |
333 : audio_provider_(audio_provider), | 329 : audio_provider_(audio_provider), |
(...skipping 21 matching lines...) Expand all Loading... |
355 } | 351 } |
356 | 352 |
357 void MediaStreamHandlerContainer::RemoveRemoteStream( | 353 void MediaStreamHandlerContainer::RemoveRemoteStream( |
358 MediaStreamInterface* stream) { | 354 MediaStreamInterface* stream) { |
359 DeleteStreamHandler(&remote_streams_handlers_, stream); | 355 DeleteStreamHandler(&remote_streams_handlers_, stream); |
360 } | 356 } |
361 | 357 |
362 void MediaStreamHandlerContainer::AddRemoteAudioTrack( | 358 void MediaStreamHandlerContainer::AddRemoteAudioTrack( |
363 MediaStreamInterface* stream, | 359 MediaStreamInterface* stream, |
364 AudioTrackInterface* audio_track, | 360 AudioTrackInterface* audio_track, |
365 uint32 ssrc) { | 361 uint32_t ssrc) { |
366 MediaStreamHandler* handler = FindStreamHandler(remote_streams_handlers_, | 362 MediaStreamHandler* handler = FindStreamHandler(remote_streams_handlers_, |
367 stream); | 363 stream); |
368 if (handler == NULL) { | 364 if (handler == NULL) { |
369 handler = CreateRemoteStreamHandler(stream); | 365 handler = CreateRemoteStreamHandler(stream); |
370 } | 366 } |
371 handler->AddAudioTrack(audio_track, ssrc); | 367 handler->AddAudioTrack(audio_track, ssrc); |
372 } | 368 } |
373 | 369 |
374 void MediaStreamHandlerContainer::AddRemoteVideoTrack( | 370 void MediaStreamHandlerContainer::AddRemoteVideoTrack( |
375 MediaStreamInterface* stream, | 371 MediaStreamInterface* stream, |
376 VideoTrackInterface* video_track, | 372 VideoTrackInterface* video_track, |
377 uint32 ssrc) { | 373 uint32_t ssrc) { |
378 MediaStreamHandler* handler = FindStreamHandler(remote_streams_handlers_, | 374 MediaStreamHandler* handler = FindStreamHandler(remote_streams_handlers_, |
379 stream); | 375 stream); |
380 if (handler == NULL) { | 376 if (handler == NULL) { |
381 handler = CreateRemoteStreamHandler(stream); | 377 handler = CreateRemoteStreamHandler(stream); |
382 } | 378 } |
383 handler->AddVideoTrack(video_track, ssrc); | 379 handler->AddVideoTrack(video_track, ssrc); |
384 } | 380 } |
385 | 381 |
386 void MediaStreamHandlerContainer::RemoveRemoteTrack( | 382 void MediaStreamHandlerContainer::RemoveRemoteTrack( |
387 MediaStreamInterface* stream, | 383 MediaStreamInterface* stream, |
388 MediaStreamTrackInterface* track) { | 384 MediaStreamTrackInterface* track) { |
389 MediaStreamHandler* handler = FindStreamHandler(remote_streams_handlers_, | 385 MediaStreamHandler* handler = FindStreamHandler(remote_streams_handlers_, |
390 stream); | 386 stream); |
391 if (!VERIFY(handler != NULL)) { | 387 if (!VERIFY(handler != NULL)) { |
392 LOG(LS_WARNING) << "Local MediaStreamHandler for stream with id " | 388 LOG(LS_WARNING) << "Local MediaStreamHandler for stream with id " |
393 << stream->label() << "doesnt't exist."; | 389 << stream->label() << "doesnt't exist."; |
394 return; | 390 return; |
395 } | 391 } |
396 handler->RemoveTrack(track); | 392 handler->RemoveTrack(track); |
397 } | 393 } |
398 | 394 |
399 void MediaStreamHandlerContainer::RemoveLocalStream( | 395 void MediaStreamHandlerContainer::RemoveLocalStream( |
400 MediaStreamInterface* stream) { | 396 MediaStreamInterface* stream) { |
401 DeleteStreamHandler(&local_streams_handlers_, stream); | 397 DeleteStreamHandler(&local_streams_handlers_, stream); |
402 } | 398 } |
403 | 399 |
404 void MediaStreamHandlerContainer::AddLocalAudioTrack( | 400 void MediaStreamHandlerContainer::AddLocalAudioTrack( |
405 MediaStreamInterface* stream, | 401 MediaStreamInterface* stream, |
406 AudioTrackInterface* audio_track, | 402 AudioTrackInterface* audio_track, |
407 uint32 ssrc) { | 403 uint32_t ssrc) { |
408 MediaStreamHandler* handler = FindStreamHandler(local_streams_handlers_, | 404 MediaStreamHandler* handler = FindStreamHandler(local_streams_handlers_, |
409 stream); | 405 stream); |
410 if (handler == NULL) { | 406 if (handler == NULL) { |
411 handler = CreateLocalStreamHandler(stream); | 407 handler = CreateLocalStreamHandler(stream); |
412 } | 408 } |
413 handler->AddAudioTrack(audio_track, ssrc); | 409 handler->AddAudioTrack(audio_track, ssrc); |
414 } | 410 } |
415 | 411 |
416 void MediaStreamHandlerContainer::AddLocalVideoTrack( | 412 void MediaStreamHandlerContainer::AddLocalVideoTrack( |
417 MediaStreamInterface* stream, | 413 MediaStreamInterface* stream, |
418 VideoTrackInterface* video_track, | 414 VideoTrackInterface* video_track, |
419 uint32 ssrc) { | 415 uint32_t ssrc) { |
420 MediaStreamHandler* handler = FindStreamHandler(local_streams_handlers_, | 416 MediaStreamHandler* handler = FindStreamHandler(local_streams_handlers_, |
421 stream); | 417 stream); |
422 if (handler == NULL) { | 418 if (handler == NULL) { |
423 handler = CreateLocalStreamHandler(stream); | 419 handler = CreateLocalStreamHandler(stream); |
424 } | 420 } |
425 handler->AddVideoTrack(video_track, ssrc); | 421 handler->AddVideoTrack(video_track, ssrc); |
426 } | 422 } |
427 | 423 |
428 void MediaStreamHandlerContainer::RemoveLocalTrack( | 424 void MediaStreamHandlerContainer::RemoveLocalTrack( |
429 MediaStreamInterface* stream, | 425 MediaStreamInterface* stream, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 if ((*it)->stream() == stream) { | 473 if ((*it)->stream() == stream) { |
478 (*it)->Stop(); | 474 (*it)->Stop(); |
479 delete *it; | 475 delete *it; |
480 streamhandlers->erase(it); | 476 streamhandlers->erase(it); |
481 break; | 477 break; |
482 } | 478 } |
483 } | 479 } |
484 } | 480 } |
485 | 481 |
486 } // namespace webrtc | 482 } // namespace webrtc |
OLD | NEW |