 Chromium Code Reviews
 Chromium Code Reviews Issue 1181653002:
  Base A/V synchronization on sync_labels.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master
    
  
    Issue 1181653002:
  Base A/V synchronization on sync_labels.  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * libjingle | 2 * libjingle | 
| 3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 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 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1617 return CreateVoiceChannel(voe_wrapper_.get()); | 1617 return CreateVoiceChannel(voe_wrapper_.get()); | 
| 1618 } | 1618 } | 
| 1619 | 1619 | 
| 1620 class WebRtcVoiceMediaChannel::WebRtcVoiceChannelRenderer | 1620 class WebRtcVoiceMediaChannel::WebRtcVoiceChannelRenderer | 
| 1621 : public AudioRenderer::Sink { | 1621 : public AudioRenderer::Sink { | 
| 1622 public: | 1622 public: | 
| 1623 WebRtcVoiceChannelRenderer(int ch, | 1623 WebRtcVoiceChannelRenderer(int ch, | 
| 1624 webrtc::AudioTransport* voe_audio_transport) | 1624 webrtc::AudioTransport* voe_audio_transport) | 
| 1625 : channel_(ch), | 1625 : channel_(ch), | 
| 1626 voe_audio_transport_(voe_audio_transport), | 1626 voe_audio_transport_(voe_audio_transport), | 
| 1627 renderer_(NULL) { | 1627 renderer_(NULL) {} | 
| 1628 } | |
| 1629 ~WebRtcVoiceChannelRenderer() override { Stop(); } | 1628 ~WebRtcVoiceChannelRenderer() override { Stop(); } | 
| 1630 | 1629 | 
| 1631 // Starts the rendering by setting a sink to the renderer to get data | 1630 // Starts the rendering by setting a sink to the renderer to get data | 
| 1632 // callback. | 1631 // callback. | 
| 1633 // This method is called on the libjingle worker thread. | 1632 // This method is called on the libjingle worker thread. | 
| 1634 // TODO(xians): Make sure Start() is called only once. | 1633 // TODO(xians): Make sure Start() is called only once. | 
| 1635 void Start(AudioRenderer* renderer) { | 1634 void Start(AudioRenderer* renderer) { | 
| 1636 rtc::CritScope lock(&lock_); | 1635 rtc::CritScope lock(&lock_); | 
| 1637 DCHECK(renderer != NULL); | 1636 DCHECK(renderer != NULL); | 
| 1638 if (renderer_ != NULL) { | 1637 if (renderer_ != NULL) { | 
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2472 return false; | 2471 return false; | 
| 2473 } | 2472 } | 
| 2474 | 2473 | 
| 2475 ConfigureSendChannel(channel); | 2474 ConfigureSendChannel(channel); | 
| 2476 } | 2475 } | 
| 2477 | 2476 | 
| 2478 // Save the channel to send_channels_, so that RemoveSendStream() can still | 2477 // Save the channel to send_channels_, so that RemoveSendStream() can still | 
| 2479 // delete the channel in case failure happens below. | 2478 // delete the channel in case failure happens below. | 
| 2480 webrtc::AudioTransport* audio_transport = | 2479 webrtc::AudioTransport* audio_transport = | 
| 2481 engine()->voe()->base()->audio_transport(); | 2480 engine()->voe()->base()->audio_transport(); | 
| 2482 send_channels_.insert(std::make_pair( | 2481 send_channels_.insert( | 
| 2483 sp.first_ssrc(), | 2482 std::make_pair(sp.first_ssrc(), | 
| 2484 new WebRtcVoiceChannelRenderer(channel, audio_transport))); | 2483 new WebRtcVoiceChannelRenderer(channel, audio_transport))); | 
| 2485 | 2484 | 
| 2486 // Set the send (local) SSRC. | 2485 // Set the send (local) SSRC. | 
| 2487 // If there are multiple send SSRCs, we can only set the first one here, and | 2486 // If there are multiple send SSRCs, we can only set the first one here, and | 
| 2488 // the rest of the SSRC(s) need to be set after SetSendCodec has been called | 2487 // the rest of the SSRC(s) need to be set after SetSendCodec has been called | 
| 2489 // (with a codec requires multiple SSRC(s)). | 2488 // (with a codec requires multiple SSRC(s)). | 
| 2490 if (engine()->voe()->rtp()->SetLocalSSRC(channel, sp.first_ssrc()) == -1) { | 2489 if (engine()->voe()->rtp()->SetLocalSSRC(channel, sp.first_ssrc()) == -1) { | 
| 2491 LOG_RTCERR2(SetSendSSRC, channel, sp.first_ssrc()); | 2490 LOG_RTCERR2(SetSendSSRC, channel, sp.first_ssrc()); | 
| 2492 return false; | 2491 return false; | 
| 2493 } | 2492 } | 
| 2494 | 2493 | 
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2567 if (ssrc == 0) { | 2566 if (ssrc == 0) { | 
| 2568 LOG(LS_WARNING) << "AddRecvStream with 0 ssrc is not supported."; | 2567 LOG(LS_WARNING) << "AddRecvStream with 0 ssrc is not supported."; | 
| 2569 return false; | 2568 return false; | 
| 2570 } | 2569 } | 
| 2571 | 2570 | 
| 2572 if (receive_channels_.find(ssrc) != receive_channels_.end()) { | 2571 if (receive_channels_.find(ssrc) != receive_channels_.end()) { | 
| 2573 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; | 2572 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; | 
| 2574 return false; | 2573 return false; | 
| 2575 } | 2574 } | 
| 2576 | 2575 | 
| 2577 TryAddAudioRecvStream(ssrc); | 2576 receive_stream_params_[ssrc] = sp; | 
| 
the sun
2015/06/11 15:38:48
DCHECK that there is no entry in map for this ssrc
 
pbos-webrtc
2015/06/12 15:53:14
Done.
 | |
| 2578 | 2577 | 
| 2579 // Reuse default channel for recv stream in non-conference mode call | 2578 // Reuse default channel for recv stream in non-conference mode call | 
| 2580 // when the default channel is not being used. | 2579 // when the default channel is not being used. | 
| 2581 webrtc::AudioTransport* audio_transport = | 2580 webrtc::AudioTransport* audio_transport = | 
| 2582 engine()->voe()->base()->audio_transport(); | 2581 engine()->voe()->base()->audio_transport(); | 
| 2583 if (!InConferenceMode() && default_receive_ssrc_ == 0) { | 2582 if (!InConferenceMode() && default_receive_ssrc_ == 0) { | 
| 2584 LOG(LS_INFO) << "Recv stream " << ssrc << " reuse default channel"; | 2583 LOG(LS_INFO) << "Recv stream " << ssrc << " reuse default channel"; | 
| 2585 default_receive_ssrc_ = ssrc; | 2584 default_receive_ssrc_ = ssrc; | 
| 2586 receive_channels_.insert(std::make_pair( | 2585 WebRtcVoiceChannelRenderer* channel_renderer = | 
| 2587 default_receive_ssrc_, | 2586 new WebRtcVoiceChannelRenderer(voe_channel(), audio_transport); | 
| 2588 new WebRtcVoiceChannelRenderer(voe_channel(), audio_transport))); | 2587 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); | 
| 2588 TryAddAudioRecvStream(ssrc); | |
| 2589 return SetPlayout(voe_channel(), playout_); | 2589 return SetPlayout(voe_channel(), playout_); | 
| 2590 } | 2590 } | 
| 2591 | 2591 | 
| 2592 // Create a new channel for receiving audio data. | 2592 // Create a new channel for receiving audio data. | 
| 2593 int channel = engine()->CreateMediaVoiceChannel(); | 2593 int channel = engine()->CreateMediaVoiceChannel(); | 
| 2594 if (channel == -1) { | 2594 if (channel == -1) { | 
| 2595 LOG_RTCERR0(CreateChannel); | 2595 LOG_RTCERR0(CreateChannel); | 
| 2596 return false; | 2596 return false; | 
| 2597 } | 2597 } | 
| 2598 | 2598 | 
| 2599 if (!ConfigureRecvChannel(channel)) { | 2599 if (!ConfigureRecvChannel(channel)) { | 
| 2600 DeleteChannel(channel); | 2600 DeleteChannel(channel); | 
| 2601 return false; | 2601 return false; | 
| 2602 } | 2602 } | 
| 2603 | 2603 | 
| 2604 receive_channels_.insert( | 2604 WebRtcVoiceChannelRenderer* channel_renderer = | 
| 2605 std::make_pair( | 2605 new WebRtcVoiceChannelRenderer(channel, audio_transport); | 
| 2606 ssrc, new WebRtcVoiceChannelRenderer(channel, audio_transport))); | 2606 receive_channels_.insert(std::make_pair(ssrc, channel_renderer)); | 
| 2607 TryAddAudioRecvStream(ssrc); | |
| 2607 | 2608 | 
| 2608 LOG(LS_INFO) << "New audio stream " << ssrc | 2609 LOG(LS_INFO) << "New audio stream " << ssrc | 
| 2609 << " registered to VoiceEngine channel #" | 2610 << " registered to VoiceEngine channel #" | 
| 2610 << channel << "."; | 2611 << channel << "."; | 
| 2611 return true; | 2612 return true; | 
| 2612 } | 2613 } | 
| 2613 | 2614 | 
| 2614 bool WebRtcVoiceMediaChannel::ConfigureRecvChannel(int channel) { | 2615 bool WebRtcVoiceMediaChannel::ConfigureRecvChannel(int channel) { | 
| 2615 // Configure to use external transport, like our default channel. | 2616 // Configure to use external transport, like our default channel. | 
| 2616 if (engine()->voe()->network()->RegisterExternalTransport( | 2617 if (engine()->voe()->network()->RegisterExternalTransport( | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2687 DCHECK(thread_checker_.CalledOnValidThread()); | 2688 DCHECK(thread_checker_.CalledOnValidThread()); | 
| 2688 rtc::CritScope lock(&receive_channels_cs_); | 2689 rtc::CritScope lock(&receive_channels_cs_); | 
| 2689 ChannelMap::iterator it = receive_channels_.find(ssrc); | 2690 ChannelMap::iterator it = receive_channels_.find(ssrc); | 
| 2690 if (it == receive_channels_.end()) { | 2691 if (it == receive_channels_.end()) { | 
| 2691 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc | 2692 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc | 
| 2692 << " which doesn't exist."; | 2693 << " which doesn't exist."; | 
| 2693 return false; | 2694 return false; | 
| 2694 } | 2695 } | 
| 2695 | 2696 | 
| 2696 TryRemoveAudioRecvStream(ssrc); | 2697 TryRemoveAudioRecvStream(ssrc); | 
| 2698 receive_stream_params_.erase(ssrc); | |
| 2697 | 2699 | 
| 2698 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this | 2700 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this | 
| 2699 // will disconnect the audio renderer with the receive channel. | 2701 // will disconnect the audio renderer with the receive channel. | 
| 2700 // Cache the channel before the deletion. | 2702 // Cache the channel before the deletion. | 
| 2701 const int channel = it->second->channel(); | 2703 const int channel = it->second->channel(); | 
| 2702 delete it->second; | 2704 delete it->second; | 
| 2703 receive_channels_.erase(it); | 2705 receive_channels_.erase(it); | 
| 2704 | 2706 | 
| 2705 if (ssrc == default_receive_ssrc_) { | 2707 if (ssrc == default_receive_ssrc_) { | 
| 2706 DCHECK(IsDefaultChannel(channel)); | 2708 DCHECK(IsDefaultChannel(channel)); | 
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3443 unsigned int ulevel; | 3445 unsigned int ulevel; | 
| 3444 int ret = | 3446 int ret = | 
| 3445 engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); | 3447 engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); | 
| 3446 return (ret == 0) ? static_cast<int>(ulevel) : -1; | 3448 return (ret == 0) ? static_cast<int>(ulevel) : -1; | 
| 3447 } | 3449 } | 
| 3448 | 3450 | 
| 3449 int WebRtcVoiceMediaChannel::GetReceiveChannelNum(uint32 ssrc) { | 3451 int WebRtcVoiceMediaChannel::GetReceiveChannelNum(uint32 ssrc) { | 
| 3450 ChannelMap::iterator it = receive_channels_.find(ssrc); | 3452 ChannelMap::iterator it = receive_channels_.find(ssrc); | 
| 3451 if (it != receive_channels_.end()) | 3453 if (it != receive_channels_.end()) | 
| 3452 return it->second->channel(); | 3454 return it->second->channel(); | 
| 3453 return (ssrc == default_receive_ssrc_) ? voe_channel() : -1; | 3455 return (ssrc == default_receive_ssrc_) ? voe_channel() : -1; | 
| 3454 } | 3456 } | 
| 3455 | 3457 | 
| 3456 int WebRtcVoiceMediaChannel::GetSendChannelNum(uint32 ssrc) { | 3458 int WebRtcVoiceMediaChannel::GetSendChannelNum(uint32 ssrc) { | 
| 3457 ChannelMap::iterator it = send_channels_.find(ssrc); | 3459 ChannelMap::iterator it = send_channels_.find(ssrc); | 
| 3458 if (it != send_channels_.end()) | 3460 if (it != send_channels_.end()) | 
| 3459 return it->second->channel(); | 3461 return it->second->channel(); | 
| 3460 | 3462 | 
| 3461 return -1; | 3463 return -1; | 
| 3462 } | 3464 } | 
| 3463 | 3465 | 
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3616 } | 3618 } | 
| 3617 if ((engine()->voe()->rtp()->*setter)(channel_id, enable, id) != 0) { | 3619 if ((engine()->voe()->rtp()->*setter)(channel_id, enable, id) != 0) { | 
| 3618 LOG_RTCERR4(*setter, uri, channel_id, enable, id); | 3620 LOG_RTCERR4(*setter, uri, channel_id, enable, id); | 
| 3619 return false; | 3621 return false; | 
| 3620 } | 3622 } | 
| 3621 return true; | 3623 return true; | 
| 3622 } | 3624 } | 
| 3623 | 3625 | 
| 3624 void WebRtcVoiceMediaChannel::TryAddAudioRecvStream(uint32 ssrc) { | 3626 void WebRtcVoiceMediaChannel::TryAddAudioRecvStream(uint32 ssrc) { | 
| 3625 DCHECK(thread_checker_.CalledOnValidThread()); | 3627 DCHECK(thread_checker_.CalledOnValidThread()); | 
| 3628 WebRtcVoiceChannelRenderer* channel = receive_channels_[ssrc]; | |
| 3629 DCHECK(channel != nullptr); | |
| 3630 DCHECK(receive_streams_.find(ssrc) == receive_streams_.end()); | |
| 3626 // If we are hooked up to a webrtc::Call, create an AudioReceiveStream too. | 3631 // If we are hooked up to a webrtc::Call, create an AudioReceiveStream too. | 
| 3627 if (call_ && options_.combined_audio_video_bwe.GetWithDefaultIfUnset(false)) { | 3632 if (!call_) { | 
| 3628 DCHECK(receive_streams_.find(ssrc) == receive_streams_.end()); | 3633 return; | 
| 3629 webrtc::AudioReceiveStream::Config config; | 3634 } | 
| 3630 config.rtp.remote_ssrc = ssrc; | 3635 webrtc::AudioReceiveStream::Config config; | 
| 3636 config.rtp.remote_ssrc = ssrc; | |
| 3637 // Only add RTP extensions if we support combined AV BWE. | |
| 3638 if (options_.combined_audio_video_bwe.GetWithDefaultIfUnset(false)) | |
| 3631 config.rtp.extensions = recv_rtp_extensions_; | 3639 config.rtp.extensions = recv_rtp_extensions_; | 
| 
the sun
2015/06/11 15:38:48
{}
 
pbos-webrtc
2015/06/12 15:53:14
:Done
 | |
| 3632 webrtc::AudioReceiveStream* s = call_->CreateAudioReceiveStream(config); | 3640 config.voe_channel_id = channel->channel(); | 
| 3633 receive_streams_.insert(std::make_pair(ssrc, s)); | 3641 config.sync_group = receive_stream_params_[ssrc].sync_label; | 
| 3634 } | 3642 webrtc::AudioReceiveStream* s = call_->CreateAudioReceiveStream(config); | 
| 3643 receive_streams_.insert(std::make_pair(ssrc, s)); | |
| 3635 } | 3644 } | 
| 3636 | 3645 | 
| 3637 void WebRtcVoiceMediaChannel::TryRemoveAudioRecvStream(uint32 ssrc) { | 3646 void WebRtcVoiceMediaChannel::TryRemoveAudioRecvStream(uint32 ssrc) { | 
| 3638 DCHECK(thread_checker_.CalledOnValidThread()); | 3647 DCHECK(thread_checker_.CalledOnValidThread()); | 
| 3639 // If we are hooked up to a webrtc::Call, assume there is an | 3648 // If we are hooked up to a webrtc::Call, assume there is an | 
| 3640 // AudioReceiveStream to destroy too. | 3649 // AudioReceiveStream to destroy too. | 
| 3641 if (call_) { | 3650 if (call_) { | 
| 3642 auto stream_it = receive_streams_.find(ssrc); | 3651 auto stream_it = receive_streams_.find(ssrc); | 
| 3643 if (stream_it != receive_streams_.end()) { | 3652 if (stream_it != receive_streams_.end()) { | 
| 3644 call_->DestroyAudioReceiveStream(stream_it->second); | 3653 call_->DestroyAudioReceiveStream(stream_it->second); | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 3655 | 3664 | 
| 3656 int WebRtcSoundclipStream::Rewind() { | 3665 int WebRtcSoundclipStream::Rewind() { | 
| 3657 mem_.Rewind(); | 3666 mem_.Rewind(); | 
| 3658 // Return -1 to keep VoiceEngine from looping. | 3667 // Return -1 to keep VoiceEngine from looping. | 
| 3659 return (loop_) ? 0 : -1; | 3668 return (loop_) ? 0 : -1; | 
| 3660 } | 3669 } | 
| 3661 | 3670 | 
| 3662 } // namespace cricket | 3671 } // namespace cricket | 
| 3663 | 3672 | 
| 3664 #endif // HAVE_WEBRTC_VOICE | 3673 #endif // HAVE_WEBRTC_VOICE | 
| OLD | NEW |