| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 83 } |
| 84 | 84 |
| 85 LocalAudioTrackHandler::LocalAudioTrackHandler( | 85 LocalAudioTrackHandler::LocalAudioTrackHandler( |
| 86 AudioTrackInterface* track, | 86 AudioTrackInterface* track, |
| 87 uint32 ssrc, | 87 uint32 ssrc, |
| 88 AudioProviderInterface* provider) | 88 AudioProviderInterface* provider) |
| 89 : TrackHandler(track, ssrc), | 89 : TrackHandler(track, ssrc), |
| 90 audio_track_(track), | 90 audio_track_(track), |
| 91 provider_(provider), | 91 provider_(provider), |
| 92 sink_adapter_(new LocalAudioSinkAdapter()) { | 92 sink_adapter_(new LocalAudioSinkAdapter()) { |
| 93 OnEnabledChanged(); | 93 Start(); |
| 94 track->AddSink(sink_adapter_.get()); | 94 track->AddSink(sink_adapter_.get()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 LocalAudioTrackHandler::~LocalAudioTrackHandler() { | 97 LocalAudioTrackHandler::~LocalAudioTrackHandler() { |
| 98 } | 98 } |
| 99 | 99 |
| 100 void LocalAudioTrackHandler::OnStateChanged() { | 100 void LocalAudioTrackHandler::OnStateChanged() { |
| 101 // TODO(perkj): What should happen when the state change? | 101 // TODO(perkj): What should happen when the state change? |
| 102 } | 102 } |
| 103 | 103 |
| 104 void LocalAudioTrackHandler::Start() { |
| 105 OnEnabledChanged(); |
| 106 } |
| 107 |
| 104 void LocalAudioTrackHandler::Stop() { | 108 void LocalAudioTrackHandler::Stop() { |
| 105 audio_track_->RemoveSink(sink_adapter_.get()); | 109 audio_track_->RemoveSink(sink_adapter_.get()); |
| 106 cricket::AudioOptions options; | 110 cricket::AudioOptions options; |
| 107 provider_->SetAudioSend(ssrc(), false, options, NULL); | 111 provider_->SetAudioSend(ssrc(), false, options, NULL); |
| 108 } | 112 } |
| 109 | 113 |
| 110 void LocalAudioTrackHandler::OnEnabledChanged() { | 114 void LocalAudioTrackHandler::OnEnabledChanged() { |
| 111 cricket::AudioOptions options; | 115 cricket::AudioOptions options; |
| 112 if (audio_track_->enabled() && audio_track_->GetSource()) { | 116 if (audio_track_->enabled() && audio_track_->GetSource()) { |
| 113 // TODO(xians): Remove this static_cast since we should be able to connect | 117 // TODO(xians): Remove this static_cast since we should be able to connect |
| (...skipping 11 matching lines...) Expand all Loading... |
| 125 } | 129 } |
| 126 | 130 |
| 127 RemoteAudioTrackHandler::RemoteAudioTrackHandler( | 131 RemoteAudioTrackHandler::RemoteAudioTrackHandler( |
| 128 AudioTrackInterface* track, | 132 AudioTrackInterface* track, |
| 129 uint32 ssrc, | 133 uint32 ssrc, |
| 130 AudioProviderInterface* provider) | 134 AudioProviderInterface* provider) |
| 131 : TrackHandler(track, ssrc), | 135 : TrackHandler(track, ssrc), |
| 132 audio_track_(track), | 136 audio_track_(track), |
| 133 provider_(provider) { | 137 provider_(provider) { |
| 134 track->GetSource()->RegisterAudioObserver(this); | 138 track->GetSource()->RegisterAudioObserver(this); |
| 135 OnEnabledChanged(); | 139 Start(); |
| 136 } | 140 } |
| 137 | 141 |
| 138 RemoteAudioTrackHandler::~RemoteAudioTrackHandler() { | 142 RemoteAudioTrackHandler::~RemoteAudioTrackHandler() { |
| 139 audio_track_->GetSource()->UnregisterAudioObserver(this); | 143 audio_track_->GetSource()->UnregisterAudioObserver(this); |
| 140 } | 144 } |
| 141 | 145 |
| 146 void RemoteAudioTrackHandler::Start() { |
| 147 // TODO(deadbeef) - Should we remember the audio playout volume last set, |
| 148 // and set it again in case the audio channel was destroyed and recreated? |
| 149 OnEnabledChanged(); |
| 150 } |
| 151 |
| 142 void RemoteAudioTrackHandler::Stop() { | 152 void RemoteAudioTrackHandler::Stop() { |
| 143 provider_->SetAudioPlayout(ssrc(), false, NULL); | 153 provider_->SetAudioPlayout(ssrc(), false, NULL); |
| 144 } | 154 } |
| 145 | 155 |
| 146 void RemoteAudioTrackHandler::OnStateChanged() { | 156 void RemoteAudioTrackHandler::OnStateChanged() { |
| 147 } | 157 } |
| 148 | 158 |
| 149 void RemoteAudioTrackHandler::OnEnabledChanged() { | 159 void RemoteAudioTrackHandler::OnEnabledChanged() { |
| 150 provider_->SetAudioPlayout(ssrc(), audio_track_->enabled(), | 160 provider_->SetAudioPlayout(ssrc(), audio_track_->enabled(), |
| 151 audio_track_->GetRenderer()); | 161 audio_track_->GetRenderer()); |
| 152 } | 162 } |
| 153 | 163 |
| 154 void RemoteAudioTrackHandler::OnSetVolume(double volume) { | 164 void RemoteAudioTrackHandler::OnSetVolume(double volume) { |
| 155 // When the track is disabled, the volume of the source, which is the | 165 // 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 | 166 // 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. | 167 // setting the volume to the source when the track is disabled. |
| 158 if (audio_track_->enabled()) | 168 if (audio_track_->enabled()) |
| 159 provider_->SetAudioPlayoutVolume(ssrc(), volume); | 169 provider_->SetAudioPlayoutVolume(ssrc(), volume); |
| 160 } | 170 } |
| 161 | 171 |
| 162 LocalVideoTrackHandler::LocalVideoTrackHandler( | 172 LocalVideoTrackHandler::LocalVideoTrackHandler( |
| 163 VideoTrackInterface* track, | 173 VideoTrackInterface* track, |
| 164 uint32 ssrc, | 174 uint32 ssrc, |
| 165 VideoProviderInterface* provider) | 175 VideoProviderInterface* provider) |
| 166 : TrackHandler(track, ssrc), | 176 : TrackHandler(track, ssrc), |
| 167 local_video_track_(track), | 177 local_video_track_(track), |
| 168 provider_(provider) { | 178 provider_(provider) { |
| 169 VideoSourceInterface* source = local_video_track_->GetSource(); | 179 Start(); |
| 170 if (source) | |
| 171 provider_->SetCaptureDevice(ssrc, source->GetVideoCapturer()); | |
| 172 OnEnabledChanged(); | |
| 173 } | 180 } |
| 174 | 181 |
| 175 LocalVideoTrackHandler::~LocalVideoTrackHandler() { | 182 LocalVideoTrackHandler::~LocalVideoTrackHandler() { |
| 176 } | 183 } |
| 177 | 184 |
| 178 void LocalVideoTrackHandler::OnStateChanged() { | 185 void LocalVideoTrackHandler::OnStateChanged() { |
| 179 } | 186 } |
| 180 | 187 |
| 188 void LocalVideoTrackHandler::Start() { |
| 189 VideoSourceInterface* source = local_video_track_->GetSource(); |
| 190 if (source) |
| 191 provider_->SetCaptureDevice(ssrc(), source->GetVideoCapturer()); |
| 192 OnEnabledChanged(); |
| 193 } |
| 194 |
| 181 void LocalVideoTrackHandler::Stop() { | 195 void LocalVideoTrackHandler::Stop() { |
| 182 provider_->SetCaptureDevice(ssrc(), NULL); | 196 provider_->SetCaptureDevice(ssrc(), NULL); |
| 183 provider_->SetVideoSend(ssrc(), false, NULL); | 197 provider_->SetVideoSend(ssrc(), false, NULL); |
| 184 } | 198 } |
| 185 | 199 |
| 186 void LocalVideoTrackHandler::OnEnabledChanged() { | 200 void LocalVideoTrackHandler::OnEnabledChanged() { |
| 187 const cricket::VideoOptions* options = NULL; | 201 const cricket::VideoOptions* options = NULL; |
| 188 VideoSourceInterface* source = local_video_track_->GetSource(); | 202 VideoSourceInterface* source = local_video_track_->GetSource(); |
| 189 if (local_video_track_->enabled() && source) { | 203 if (local_video_track_->enabled() && source) { |
| 190 options = source->options(); | 204 options = source->options(); |
| 191 } | 205 } |
| 192 provider_->SetVideoSend(ssrc(), local_video_track_->enabled(), options); | 206 provider_->SetVideoSend(ssrc(), local_video_track_->enabled(), options); |
| 193 } | 207 } |
| 194 | 208 |
| 195 RemoteVideoTrackHandler::RemoteVideoTrackHandler( | 209 RemoteVideoTrackHandler::RemoteVideoTrackHandler( |
| 196 VideoTrackInterface* track, | 210 VideoTrackInterface* track, |
| 197 uint32 ssrc, | 211 uint32 ssrc, |
| 198 VideoProviderInterface* provider) | 212 VideoProviderInterface* provider) |
| 199 : TrackHandler(track, ssrc), | 213 : TrackHandler(track, ssrc), |
| 200 remote_video_track_(track), | 214 remote_video_track_(track), |
| 201 provider_(provider) { | 215 provider_(provider) { |
| 202 OnEnabledChanged(); | 216 Start(); |
| 203 provider_->SetVideoPlayout(ssrc, true, | |
| 204 remote_video_track_->GetSource()->FrameInput()); | |
| 205 } | 217 } |
| 206 | 218 |
| 207 RemoteVideoTrackHandler::~RemoteVideoTrackHandler() { | 219 RemoteVideoTrackHandler::~RemoteVideoTrackHandler() { |
| 208 } | 220 } |
| 209 | 221 |
| 222 void RemoteVideoTrackHandler::Start() { |
| 223 OnEnabledChanged(); |
| 224 provider_->SetVideoPlayout(ssrc(), true, |
| 225 remote_video_track_->GetSource()->FrameInput()); |
| 226 } |
| 227 |
| 210 void RemoteVideoTrackHandler::Stop() { | 228 void RemoteVideoTrackHandler::Stop() { |
| 211 // Since cricket::VideoRenderer is not reference counted | 229 // Since cricket::VideoRenderer is not reference counted |
| 212 // we need to remove the renderer before we are deleted. | 230 // we need to remove the renderer before we are deleted. |
| 213 provider_->SetVideoPlayout(ssrc(), false, NULL); | 231 provider_->SetVideoPlayout(ssrc(), false, NULL); |
| 214 } | 232 } |
| 215 | 233 |
| 216 void RemoteVideoTrackHandler::OnStateChanged() { | 234 void RemoteVideoTrackHandler::OnStateChanged() { |
| 217 } | 235 } |
| 218 | 236 |
| 219 void RemoteVideoTrackHandler::OnEnabledChanged() { | 237 void RemoteVideoTrackHandler::OnEnabledChanged() { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 312 |
| 295 void LocalMediaStreamHandler::AddVideoTrack(VideoTrackInterface* video_track, | 313 void LocalMediaStreamHandler::AddVideoTrack(VideoTrackInterface* video_track, |
| 296 uint32 ssrc) { | 314 uint32 ssrc) { |
| 297 ASSERT(!FindTrackHandler(video_track)); | 315 ASSERT(!FindTrackHandler(video_track)); |
| 298 | 316 |
| 299 TrackHandler* handler(new LocalVideoTrackHandler(video_track, ssrc, | 317 TrackHandler* handler(new LocalVideoTrackHandler(video_track, ssrc, |
| 300 video_provider_)); | 318 video_provider_)); |
| 301 track_handlers_.push_back(handler); | 319 track_handlers_.push_back(handler); |
| 302 } | 320 } |
| 303 | 321 |
| 322 void LocalMediaStreamHandler::RestartAllTracks() { |
| 323 for (auto it : track_handlers_) { |
| 324 it->Start(); |
| 325 } |
| 326 } |
| 327 |
| 304 RemoteMediaStreamHandler::RemoteMediaStreamHandler( | 328 RemoteMediaStreamHandler::RemoteMediaStreamHandler( |
| 305 MediaStreamInterface* stream, | 329 MediaStreamInterface* stream, |
| 306 AudioProviderInterface* audio_provider, | 330 AudioProviderInterface* audio_provider, |
| 307 VideoProviderInterface* video_provider) | 331 VideoProviderInterface* video_provider) |
| 308 : MediaStreamHandler(stream, audio_provider, video_provider) { | 332 : MediaStreamHandler(stream, audio_provider, video_provider) { |
| 309 } | 333 } |
| 310 | 334 |
| 311 RemoteMediaStreamHandler::~RemoteMediaStreamHandler() { | 335 RemoteMediaStreamHandler::~RemoteMediaStreamHandler() { |
| 312 } | 336 } |
| 313 | 337 |
| 314 void RemoteMediaStreamHandler::AddAudioTrack(AudioTrackInterface* audio_track, | 338 void RemoteMediaStreamHandler::AddAudioTrack(AudioTrackInterface* audio_track, |
| 315 uint32 ssrc) { | 339 uint32 ssrc) { |
| 316 ASSERT(!FindTrackHandler(audio_track)); | 340 ASSERT(!FindTrackHandler(audio_track)); |
| 317 TrackHandler* handler( | 341 TrackHandler* handler( |
| 318 new RemoteAudioTrackHandler(audio_track, ssrc, audio_provider_)); | 342 new RemoteAudioTrackHandler(audio_track, ssrc, audio_provider_)); |
| 319 track_handlers_.push_back(handler); | 343 track_handlers_.push_back(handler); |
| 320 } | 344 } |
| 321 | 345 |
| 322 void RemoteMediaStreamHandler::AddVideoTrack(VideoTrackInterface* video_track, | 346 void RemoteMediaStreamHandler::AddVideoTrack(VideoTrackInterface* video_track, |
| 323 uint32 ssrc) { | 347 uint32 ssrc) { |
| 324 ASSERT(!FindTrackHandler(video_track)); | 348 ASSERT(!FindTrackHandler(video_track)); |
| 325 TrackHandler* handler( | 349 TrackHandler* handler( |
| 326 new RemoteVideoTrackHandler(video_track, ssrc, video_provider_)); | 350 new RemoteVideoTrackHandler(video_track, ssrc, video_provider_)); |
| 327 track_handlers_.push_back(handler); | 351 track_handlers_.push_back(handler); |
| 328 } | 352 } |
| 329 | 353 |
| 354 void RemoteMediaStreamHandler::RestartAllTracks() { |
| 355 for (auto it : track_handlers_) { |
| 356 it->Start(); |
| 357 } |
| 358 } |
| 359 |
| 330 MediaStreamHandlerContainer::MediaStreamHandlerContainer( | 360 MediaStreamHandlerContainer::MediaStreamHandlerContainer( |
| 331 AudioProviderInterface* audio_provider, | 361 AudioProviderInterface* audio_provider, |
| 332 VideoProviderInterface* video_provider) | 362 VideoProviderInterface* video_provider) |
| 333 : audio_provider_(audio_provider), | 363 : audio_provider_(audio_provider), |
| 334 video_provider_(video_provider) { | 364 video_provider_(video_provider) { |
| 335 } | 365 } |
| 336 | 366 |
| 337 MediaStreamHandlerContainer::~MediaStreamHandlerContainer() { | 367 MediaStreamHandlerContainer::~MediaStreamHandlerContainer() { |
| 338 ASSERT(remote_streams_handlers_.empty()); | 368 ASSERT(remote_streams_handlers_.empty()); |
| 339 ASSERT(local_streams_handlers_.empty()); | 369 ASSERT(local_streams_handlers_.empty()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 MediaStreamHandler* handler = FindStreamHandler(remote_streams_handlers_, | 419 MediaStreamHandler* handler = FindStreamHandler(remote_streams_handlers_, |
| 390 stream); | 420 stream); |
| 391 if (!VERIFY(handler != NULL)) { | 421 if (!VERIFY(handler != NULL)) { |
| 392 LOG(LS_WARNING) << "Local MediaStreamHandler for stream with id " | 422 LOG(LS_WARNING) << "Local MediaStreamHandler for stream with id " |
| 393 << stream->label() << "doesnt't exist."; | 423 << stream->label() << "doesnt't exist."; |
| 394 return; | 424 return; |
| 395 } | 425 } |
| 396 handler->RemoveTrack(track); | 426 handler->RemoveTrack(track); |
| 397 } | 427 } |
| 398 | 428 |
| 429 void MediaStreamHandlerContainer::RestartAllRemoteTracks() { |
| 430 for (auto it : remote_streams_handlers_) { |
| 431 it->RestartAllTracks(); |
| 432 } |
| 433 } |
| 434 |
| 399 void MediaStreamHandlerContainer::RemoveLocalStream( | 435 void MediaStreamHandlerContainer::RemoveLocalStream( |
| 400 MediaStreamInterface* stream) { | 436 MediaStreamInterface* stream) { |
| 401 DeleteStreamHandler(&local_streams_handlers_, stream); | 437 DeleteStreamHandler(&local_streams_handlers_, stream); |
| 402 } | 438 } |
| 403 | 439 |
| 404 void MediaStreamHandlerContainer::AddLocalAudioTrack( | 440 void MediaStreamHandlerContainer::AddLocalAudioTrack( |
| 405 MediaStreamInterface* stream, | 441 MediaStreamInterface* stream, |
| 406 AudioTrackInterface* audio_track, | 442 AudioTrackInterface* audio_track, |
| 407 uint32 ssrc) { | 443 uint32 ssrc) { |
| 408 MediaStreamHandler* handler = FindStreamHandler(local_streams_handlers_, | 444 MediaStreamHandler* handler = FindStreamHandler(local_streams_handlers_, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 431 MediaStreamHandler* handler = FindStreamHandler(local_streams_handlers_, | 467 MediaStreamHandler* handler = FindStreamHandler(local_streams_handlers_, |
| 432 stream); | 468 stream); |
| 433 if (!VERIFY(handler != NULL)) { | 469 if (!VERIFY(handler != NULL)) { |
| 434 LOG(LS_WARNING) << "Remote MediaStreamHandler for stream with id " | 470 LOG(LS_WARNING) << "Remote MediaStreamHandler for stream with id " |
| 435 << stream->label() << "doesnt't exist."; | 471 << stream->label() << "doesnt't exist."; |
| 436 return; | 472 return; |
| 437 } | 473 } |
| 438 handler->RemoveTrack(track); | 474 handler->RemoveTrack(track); |
| 439 } | 475 } |
| 440 | 476 |
| 477 void MediaStreamHandlerContainer::RestartAllLocalTracks() { |
| 478 for (auto it : local_streams_handlers_) { |
| 479 it->RestartAllTracks(); |
| 480 } |
| 481 } |
| 482 |
| 441 MediaStreamHandler* MediaStreamHandlerContainer::CreateRemoteStreamHandler( | 483 MediaStreamHandler* MediaStreamHandlerContainer::CreateRemoteStreamHandler( |
| 442 MediaStreamInterface* stream) { | 484 MediaStreamInterface* stream) { |
| 443 ASSERT(!FindStreamHandler(remote_streams_handlers_, stream)); | 485 ASSERT(!FindStreamHandler(remote_streams_handlers_, stream)); |
| 444 | 486 |
| 445 RemoteMediaStreamHandler* handler = | 487 RemoteMediaStreamHandler* handler = |
| 446 new RemoteMediaStreamHandler(stream, audio_provider_, video_provider_); | 488 new RemoteMediaStreamHandler(stream, audio_provider_, video_provider_); |
| 447 remote_streams_handlers_.push_back(handler); | 489 remote_streams_handlers_.push_back(handler); |
| 448 return handler; | 490 return handler; |
| 449 } | 491 } |
| 450 | 492 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 477 if ((*it)->stream() == stream) { | 519 if ((*it)->stream() == stream) { |
| 478 (*it)->Stop(); | 520 (*it)->Stop(); |
| 479 delete *it; | 521 delete *it; |
| 480 streamhandlers->erase(it); | 522 streamhandlers->erase(it); |
| 481 break; | 523 break; |
| 482 } | 524 } |
| 483 } | 525 } |
| 484 } | 526 } |
| 485 | 527 |
| 486 } // namespace webrtc | 528 } // namespace webrtc |
| OLD | NEW |