Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: talk/media/webrtc/webrtcvoiceengine.cc

Issue 1181653002: Base A/V synchronization on sync_labels. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/media/webrtc/webrtcvoiceengine.h ('k') | talk/media/webrtc/webrtcvoiceengine_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 DCHECK(receive_stream_params_.find(ssrc) == receive_stream_params_.end());
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 receive_stream_params_[ssrc] = sp;
2589 TryAddAudioRecvStream(ssrc);
2589 return SetPlayout(voe_channel(), playout_); 2590 return SetPlayout(voe_channel(), playout_);
2590 } 2591 }
2591 2592
2592 // Create a new channel for receiving audio data. 2593 // Create a new channel for receiving audio data.
2593 int channel = engine()->CreateMediaVoiceChannel(); 2594 int channel = engine()->CreateMediaVoiceChannel();
2594 if (channel == -1) { 2595 if (channel == -1) {
2595 LOG_RTCERR0(CreateChannel); 2596 LOG_RTCERR0(CreateChannel);
2596 return false; 2597 return false;
2597 } 2598 }
2598 2599
2599 if (!ConfigureRecvChannel(channel)) { 2600 if (!ConfigureRecvChannel(channel)) {
2600 DeleteChannel(channel); 2601 DeleteChannel(channel);
2601 return false; 2602 return false;
2602 } 2603 }
2603 2604
2604 receive_channels_.insert( 2605 WebRtcVoiceChannelRenderer* channel_renderer =
2605 std::make_pair( 2606 new WebRtcVoiceChannelRenderer(channel, audio_transport);
2606 ssrc, new WebRtcVoiceChannelRenderer(channel, audio_transport))); 2607 receive_channels_.insert(std::make_pair(ssrc, channel_renderer));
2608 receive_stream_params_[ssrc] = sp;
2609 TryAddAudioRecvStream(ssrc);
2607 2610
2608 LOG(LS_INFO) << "New audio stream " << ssrc 2611 LOG(LS_INFO) << "New audio stream " << ssrc
2609 << " registered to VoiceEngine channel #" 2612 << " registered to VoiceEngine channel #"
2610 << channel << "."; 2613 << channel << ".";
2611 return true; 2614 return true;
2612 } 2615 }
2613 2616
2614 bool WebRtcVoiceMediaChannel::ConfigureRecvChannel(int channel) { 2617 bool WebRtcVoiceMediaChannel::ConfigureRecvChannel(int channel) {
2615 // Configure to use external transport, like our default channel. 2618 // Configure to use external transport, like our default channel.
2616 if (engine()->voe()->network()->RegisterExternalTransport( 2619 if (engine()->voe()->network()->RegisterExternalTransport(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2687 DCHECK(thread_checker_.CalledOnValidThread()); 2690 DCHECK(thread_checker_.CalledOnValidThread());
2688 rtc::CritScope lock(&receive_channels_cs_); 2691 rtc::CritScope lock(&receive_channels_cs_);
2689 ChannelMap::iterator it = receive_channels_.find(ssrc); 2692 ChannelMap::iterator it = receive_channels_.find(ssrc);
2690 if (it == receive_channels_.end()) { 2693 if (it == receive_channels_.end()) {
2691 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc 2694 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc
2692 << " which doesn't exist."; 2695 << " which doesn't exist.";
2693 return false; 2696 return false;
2694 } 2697 }
2695 2698
2696 TryRemoveAudioRecvStream(ssrc); 2699 TryRemoveAudioRecvStream(ssrc);
2700 receive_stream_params_.erase(ssrc);
2697 2701
2698 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this 2702 // Delete the WebRtcVoiceChannelRenderer object connected to the channel, this
2699 // will disconnect the audio renderer with the receive channel. 2703 // will disconnect the audio renderer with the receive channel.
2700 // Cache the channel before the deletion. 2704 // Cache the channel before the deletion.
2701 const int channel = it->second->channel(); 2705 const int channel = it->second->channel();
2702 delete it->second; 2706 delete it->second;
2703 receive_channels_.erase(it); 2707 receive_channels_.erase(it);
2704 2708
2705 if (ssrc == default_receive_ssrc_) { 2709 if (ssrc == default_receive_ssrc_) {
2706 DCHECK(IsDefaultChannel(channel)); 2710 DCHECK(IsDefaultChannel(channel));
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
3443 unsigned int ulevel; 3447 unsigned int ulevel;
3444 int ret = 3448 int ret =
3445 engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel); 3449 engine()->voe()->volume()->GetSpeechOutputLevel(channel, ulevel);
3446 return (ret == 0) ? static_cast<int>(ulevel) : -1; 3450 return (ret == 0) ? static_cast<int>(ulevel) : -1;
3447 } 3451 }
3448 3452
3449 int WebRtcVoiceMediaChannel::GetReceiveChannelNum(uint32 ssrc) { 3453 int WebRtcVoiceMediaChannel::GetReceiveChannelNum(uint32 ssrc) {
3450 ChannelMap::iterator it = receive_channels_.find(ssrc); 3454 ChannelMap::iterator it = receive_channels_.find(ssrc);
3451 if (it != receive_channels_.end()) 3455 if (it != receive_channels_.end())
3452 return it->second->channel(); 3456 return it->second->channel();
3453 return (ssrc == default_receive_ssrc_) ? voe_channel() : -1; 3457 return (ssrc == default_receive_ssrc_) ? voe_channel() : -1;
3454 } 3458 }
3455 3459
3456 int WebRtcVoiceMediaChannel::GetSendChannelNum(uint32 ssrc) { 3460 int WebRtcVoiceMediaChannel::GetSendChannelNum(uint32 ssrc) {
3457 ChannelMap::iterator it = send_channels_.find(ssrc); 3461 ChannelMap::iterator it = send_channels_.find(ssrc);
3458 if (it != send_channels_.end()) 3462 if (it != send_channels_.end())
3459 return it->second->channel(); 3463 return it->second->channel();
3460 3464
3461 return -1; 3465 return -1;
3462 } 3466 }
3463 3467
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
3616 } 3620 }
3617 if ((engine()->voe()->rtp()->*setter)(channel_id, enable, id) != 0) { 3621 if ((engine()->voe()->rtp()->*setter)(channel_id, enable, id) != 0) {
3618 LOG_RTCERR4(*setter, uri, channel_id, enable, id); 3622 LOG_RTCERR4(*setter, uri, channel_id, enable, id);
3619 return false; 3623 return false;
3620 } 3624 }
3621 return true; 3625 return true;
3622 } 3626 }
3623 3627
3624 void WebRtcVoiceMediaChannel::TryAddAudioRecvStream(uint32 ssrc) { 3628 void WebRtcVoiceMediaChannel::TryAddAudioRecvStream(uint32 ssrc) {
3625 DCHECK(thread_checker_.CalledOnValidThread()); 3629 DCHECK(thread_checker_.CalledOnValidThread());
3630 WebRtcVoiceChannelRenderer* channel = receive_channels_[ssrc];
3631 DCHECK(channel != nullptr);
3632 DCHECK(receive_streams_.find(ssrc) == receive_streams_.end());
3626 // If we are hooked up to a webrtc::Call, create an AudioReceiveStream too. 3633 // If we are hooked up to a webrtc::Call, create an AudioReceiveStream too.
3627 if (call_ && options_.combined_audio_video_bwe.GetWithDefaultIfUnset(false)) { 3634 if (!call_) {
3628 DCHECK(receive_streams_.find(ssrc) == receive_streams_.end()); 3635 return;
3629 webrtc::AudioReceiveStream::Config config; 3636 }
3630 config.rtp.remote_ssrc = ssrc; 3637 webrtc::AudioReceiveStream::Config config;
3638 config.rtp.remote_ssrc = ssrc;
3639 // Only add RTP extensions if we support combined A/V BWE.
3640 if (options_.combined_audio_video_bwe.GetWithDefaultIfUnset(false)) {
3631 config.rtp.extensions = recv_rtp_extensions_; 3641 config.rtp.extensions = recv_rtp_extensions_;
3632 webrtc::AudioReceiveStream* s = call_->CreateAudioReceiveStream(config);
3633 receive_streams_.insert(std::make_pair(ssrc, s));
3634 } 3642 }
3643 config.voe_channel_id = channel->channel();
3644 config.sync_group = receive_stream_params_[ssrc].sync_label;
3645 webrtc::AudioReceiveStream* s = call_->CreateAudioReceiveStream(config);
3646 receive_streams_.insert(std::make_pair(ssrc, s));
3635 } 3647 }
3636 3648
3637 void WebRtcVoiceMediaChannel::TryRemoveAudioRecvStream(uint32 ssrc) { 3649 void WebRtcVoiceMediaChannel::TryRemoveAudioRecvStream(uint32 ssrc) {
3638 DCHECK(thread_checker_.CalledOnValidThread()); 3650 DCHECK(thread_checker_.CalledOnValidThread());
3639 // If we are hooked up to a webrtc::Call, assume there is an 3651 // If we are hooked up to a webrtc::Call, assume there is an
3640 // AudioReceiveStream to destroy too. 3652 // AudioReceiveStream to destroy too.
3641 if (call_) { 3653 if (call_) {
3642 auto stream_it = receive_streams_.find(ssrc); 3654 auto stream_it = receive_streams_.find(ssrc);
3643 if (stream_it != receive_streams_.end()) { 3655 if (stream_it != receive_streams_.end()) {
3644 call_->DestroyAudioReceiveStream(stream_it->second); 3656 call_->DestroyAudioReceiveStream(stream_it->second);
(...skipping 10 matching lines...) Expand all
3655 3667
3656 int WebRtcSoundclipStream::Rewind() { 3668 int WebRtcSoundclipStream::Rewind() {
3657 mem_.Rewind(); 3669 mem_.Rewind();
3658 // Return -1 to keep VoiceEngine from looping. 3670 // Return -1 to keep VoiceEngine from looping.
3659 return (loop_) ? 0 : -1; 3671 return (loop_) ? 0 : -1;
3660 } 3672 }
3661 3673
3662 } // namespace cricket 3674 } // namespace cricket
3663 3675
3664 #endif // HAVE_WEBRTC_VOICE 3676 #endif // HAVE_WEBRTC_VOICE
OLDNEW
« no previous file with comments | « talk/media/webrtc/webrtcvoiceengine.h ('k') | talk/media/webrtc/webrtcvoiceengine_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698