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