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

Side by Side Diff: webrtc/voice_engine/channel.cc

Issue 1479023002: Prepare the AudioSendStream to be hooked up to send-side BWE. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix GN bots. Created 5 years 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/voice_engine/channel.h" 11 #include "webrtc/voice_engine/channel.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 14
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/base/format_macros.h" 16 #include "webrtc/base/format_macros.h"
17 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
18 #include "webrtc/base/timeutils.h" 18 #include "webrtc/base/timeutils.h"
19 #include "webrtc/common.h" 19 #include "webrtc/common.h"
20 #include "webrtc/config.h" 20 #include "webrtc/config.h"
21 #include "webrtc/modules/audio_device/include/audio_device.h" 21 #include "webrtc/modules/audio_device/include/audio_device.h"
22 #include "webrtc/modules/audio_processing/include/audio_processing.h" 22 #include "webrtc/modules/audio_processing/include/audio_processing.h"
23 #include "webrtc/modules/include/module_common_types.h" 23 #include "webrtc/modules/include/module_common_types.h"
24 #include "webrtc/modules/pacing/paced_sender.h"
24 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" 25 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
25 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" 26 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h"
26 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" 27 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h"
27 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h" 28 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h"
28 #include "webrtc/modules/utility/include/audio_frame_operations.h" 29 #include "webrtc/modules/utility/include/audio_frame_operations.h"
29 #include "webrtc/modules/utility/include/process_thread.h" 30 #include "webrtc/modules/utility/include/process_thread.h"
30 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 31 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
31 #include "webrtc/system_wrappers/include/trace.h" 32 #include "webrtc/system_wrappers/include/trace.h"
32 #include "webrtc/voice_engine/include/voe_base.h" 33 #include "webrtc/voice_engine/include/voe_base.h"
33 #include "webrtc/voice_engine/include/voe_external_media.h" 34 #include "webrtc/voice_engine/include/voe_external_media.h"
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, 684 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice,
684 VoEId(_instanceId,_channelId), 685 VoEId(_instanceId,_channelId),
685 "Channel::RecordFileEnded() => output file recorder module is" 686 "Channel::RecordFileEnded() => output file recorder module is"
686 " shutdown"); 687 " shutdown");
687 } 688 }
688 689
689 Channel::Channel(int32_t channelId, 690 Channel::Channel(int32_t channelId,
690 uint32_t instanceId, 691 uint32_t instanceId,
691 RtcEventLog* const event_log, 692 RtcEventLog* const event_log,
692 const Config& config) 693 const Config& config)
693 : _fileCritSect(*CriticalSectionWrapper::CreateCriticalSection()), 694 : _fileCritSect(*CriticalSectionWrapper::CreateCriticalSection()),
694 _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()), 695 _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()),
695 volume_settings_critsect_(*CriticalSectionWrapper::CreateCriticalSection()), 696 volume_settings_critsect_(
696 _instanceId(instanceId), 697 *CriticalSectionWrapper::CreateCriticalSection()),
697 _channelId(channelId), 698 _instanceId(instanceId),
698 event_log_(event_log), 699 _channelId(channelId),
699 rtp_header_parser_(RtpHeaderParser::Create()), 700 event_log_(event_log),
700 rtp_payload_registry_( 701 rtp_header_parser_(RtpHeaderParser::Create()),
701 new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(true))), 702 rtp_payload_registry_(
702 rtp_receive_statistics_( 703 new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(true))),
703 ReceiveStatistics::Create(Clock::GetRealTimeClock())), 704 rtp_receive_statistics_(
704 rtp_receiver_( 705 ReceiveStatistics::Create(Clock::GetRealTimeClock())),
705 RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(), 706 rtp_receiver_(
706 this, 707 RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(),
707 this, 708 this,
708 this, 709 this,
709 rtp_payload_registry_.get())), 710 this,
710 telephone_event_handler_(rtp_receiver_->GetTelephoneEventHandler()), 711 rtp_payload_registry_.get())),
711 _outputAudioLevel(), 712 telephone_event_handler_(rtp_receiver_->GetTelephoneEventHandler()),
712 _externalTransport(false), 713 _outputAudioLevel(),
713 _inputFilePlayerPtr(NULL), 714 _externalTransport(false),
714 _outputFilePlayerPtr(NULL), 715 _inputFilePlayerPtr(NULL),
715 _outputFileRecorderPtr(NULL), 716 _outputFilePlayerPtr(NULL),
716 // Avoid conflict with other channels by adding 1024 - 1026, 717 _outputFileRecorderPtr(NULL),
717 // won't use as much as 1024 channels. 718 // Avoid conflict with other channels by adding 1024 - 1026,
718 _inputFilePlayerId(VoEModuleId(instanceId, channelId) + 1024), 719 // won't use as much as 1024 channels.
719 _outputFilePlayerId(VoEModuleId(instanceId, channelId) + 1025), 720 _inputFilePlayerId(VoEModuleId(instanceId, channelId) + 1024),
720 _outputFileRecorderId(VoEModuleId(instanceId, channelId) + 1026), 721 _outputFilePlayerId(VoEModuleId(instanceId, channelId) + 1025),
721 _outputFileRecording(false), 722 _outputFileRecorderId(VoEModuleId(instanceId, channelId) + 1026),
722 _inbandDtmfQueue(VoEModuleId(instanceId, channelId)), 723 _outputFileRecording(false),
723 _inbandDtmfGenerator(VoEModuleId(instanceId, channelId)), 724 _inbandDtmfQueue(VoEModuleId(instanceId, channelId)),
724 _outputExternalMedia(false), 725 _inbandDtmfGenerator(VoEModuleId(instanceId, channelId)),
725 _inputExternalMediaCallbackPtr(NULL), 726 _outputExternalMedia(false),
726 _outputExternalMediaCallbackPtr(NULL), 727 _inputExternalMediaCallbackPtr(NULL),
727 _timeStamp(0), // This is just an offset, RTP module will add it's own 728 _outputExternalMediaCallbackPtr(NULL),
728 // random offset 729 _timeStamp(0), // This is just an offset, RTP module will add it's own
729 _sendTelephoneEventPayloadType(106), 730 // random offset
730 ntp_estimator_(Clock::GetRealTimeClock()), 731 _sendTelephoneEventPayloadType(106),
731 jitter_buffer_playout_timestamp_(0), 732 ntp_estimator_(Clock::GetRealTimeClock()),
732 playout_timestamp_rtp_(0), 733 jitter_buffer_playout_timestamp_(0),
733 playout_timestamp_rtcp_(0), 734 playout_timestamp_rtp_(0),
734 playout_delay_ms_(0), 735 playout_timestamp_rtcp_(0),
735 _numberOfDiscardedPackets(0), 736 playout_delay_ms_(0),
736 send_sequence_number_(0), 737 _numberOfDiscardedPackets(0),
737 ts_stats_lock_(CriticalSectionWrapper::CreateCriticalSection()), 738 send_sequence_number_(0),
738 rtp_ts_wraparound_handler_(new rtc::TimestampWrapAroundHandler()), 739 ts_stats_lock_(CriticalSectionWrapper::CreateCriticalSection()),
739 capture_start_rtp_time_stamp_(-1), 740 rtp_ts_wraparound_handler_(new rtc::TimestampWrapAroundHandler()),
740 capture_start_ntp_time_ms_(-1), 741 capture_start_rtp_time_stamp_(-1),
741 _engineStatisticsPtr(NULL), 742 capture_start_ntp_time_ms_(-1),
742 _outputMixerPtr(NULL), 743 _engineStatisticsPtr(NULL),
743 _transmitMixerPtr(NULL), 744 _outputMixerPtr(NULL),
744 _moduleProcessThreadPtr(NULL), 745 _transmitMixerPtr(NULL),
745 _audioDeviceModulePtr(NULL), 746 _moduleProcessThreadPtr(NULL),
746 _voiceEngineObserverPtr(NULL), 747 _audioDeviceModulePtr(NULL),
747 _callbackCritSectPtr(NULL), 748 _voiceEngineObserverPtr(NULL),
748 _transportPtr(NULL), 749 _callbackCritSectPtr(NULL),
749 _rxVadObserverPtr(NULL), 750 _transportPtr(NULL),
750 _oldVadDecision(-1), 751 _rxVadObserverPtr(NULL),
751 _sendFrameType(0), 752 _oldVadDecision(-1),
752 _externalMixing(false), 753 _sendFrameType(0),
753 _mixFileWithMicrophone(false), 754 _externalMixing(false),
754 _mute(false), 755 _mixFileWithMicrophone(false),
755 _panLeft(1.0f), 756 _mute(false),
756 _panRight(1.0f), 757 _panLeft(1.0f),
757 _outputGain(1.0f), 758 _panRight(1.0f),
758 _playOutbandDtmfEvent(false), 759 _outputGain(1.0f),
759 _playInbandDtmfEvent(false), 760 _playOutbandDtmfEvent(false),
760 _lastLocalTimeStamp(0), 761 _playInbandDtmfEvent(false),
761 _lastPayloadType(0), 762 _lastLocalTimeStamp(0),
762 _includeAudioLevelIndication(false), 763 _lastPayloadType(0),
763 _outputSpeechType(AudioFrame::kNormalSpeech), 764 _includeAudioLevelIndication(false),
764 video_sync_lock_(CriticalSectionWrapper::CreateCriticalSection()), 765 _outputSpeechType(AudioFrame::kNormalSpeech),
765 _average_jitter_buffer_delay_us(0), 766 video_sync_lock_(CriticalSectionWrapper::CreateCriticalSection()),
766 _previousTimestamp(0), 767 _average_jitter_buffer_delay_us(0),
767 _recPacketDelayMs(20), 768 _previousTimestamp(0),
768 _RxVadDetection(false), 769 _recPacketDelayMs(20),
769 _rxAgcIsEnabled(false), 770 _RxVadDetection(false),
770 _rxNsIsEnabled(false), 771 _rxAgcIsEnabled(false),
771 restored_packet_in_use_(false), 772 _rxNsIsEnabled(false),
772 rtcp_observer_(new VoERtcpObserver(this)), 773 restored_packet_in_use_(false),
773 network_predictor_(new NetworkPredictor(Clock::GetRealTimeClock())), 774 rtcp_observer_(new VoERtcpObserver(this)),
774 assoc_send_channel_lock_(CriticalSectionWrapper::CreateCriticalSection()), 775 network_predictor_(new NetworkPredictor(Clock::GetRealTimeClock())),
775 associate_send_channel_(ChannelOwner(nullptr)) { 776 assoc_send_channel_lock_(CriticalSectionWrapper::CreateCriticalSection()),
777 associate_send_channel_(ChannelOwner(nullptr)),
778 packet_sender_proxy_(config.Get<VoicePacing>().enabled
the sun 2015/11/30 12:37:20 By making PacketSenderProxy construct-and-config y
stefan-webrtc 2015/11/30 15:22:02 What do you mean with construct-and-config? The pr
the sun 2015/12/01 10:25:35 Sorry, I mean construct-from-config; that is, make
779 ? new PacketSenderProxy()
780 : nullptr),
781 packet_router_(nullptr) {
776 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,_channelId), 782 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,_channelId),
777 "Channel::Channel() - ctor"); 783 "Channel::Channel() - ctor");
778 AudioCodingModule::Config acm_config; 784 AudioCodingModule::Config acm_config;
779 acm_config.id = VoEModuleId(instanceId, channelId); 785 acm_config.id = VoEModuleId(instanceId, channelId);
780 if (config.Get<NetEqCapacityConfig>().enabled) { 786 if (config.Get<NetEqCapacityConfig>().enabled) {
781 // Clamping the buffer capacity at 20 packets. While going lower will 787 // Clamping the buffer capacity at 20 packets. While going lower will
782 // probably work, it makes little sense. 788 // probably work, it makes little sense.
783 acm_config.neteq_config.max_packets_in_buffer = 789 acm_config.neteq_config.max_packets_in_buffer =
784 std::max(20, config.Get<NetEqCapacityConfig>().capacity); 790 std::max(20, config.Get<NetEqCapacityConfig>().capacity);
785 } 791 }
786 acm_config.neteq_config.enable_fast_accelerate = 792 acm_config.neteq_config.enable_fast_accelerate =
787 config.Get<NetEqFastAccelerate>().enabled; 793 config.Get<NetEqFastAccelerate>().enabled;
788 audio_coding_.reset(AudioCodingModule::Create(acm_config)); 794 audio_coding_.reset(AudioCodingModule::Create(acm_config));
789 795
790 _inbandDtmfQueue.ResetDtmf(); 796 _inbandDtmfQueue.ResetDtmf();
791 _inbandDtmfGenerator.Init(); 797 _inbandDtmfGenerator.Init();
792 _outputAudioLevel.Clear(); 798 _outputAudioLevel.Clear();
793 799
794 RtpRtcp::Configuration configuration; 800 RtpRtcp::Configuration configuration;
795 configuration.audio = true; 801 configuration.audio = true;
796 configuration.outgoing_transport = this; 802 configuration.outgoing_transport = this;
797 configuration.audio_messages = this; 803 configuration.audio_messages = this;
798 configuration.receive_statistics = rtp_receive_statistics_.get(); 804 configuration.receive_statistics = rtp_receive_statistics_.get();
799 configuration.bandwidth_callback = rtcp_observer_.get(); 805 configuration.bandwidth_callback = rtcp_observer_.get();
806 configuration.paced_sender = packet_sender_proxy_.get();
800 807
801 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); 808 _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration));
802 809
803 statistics_proxy_.reset(new StatisticsProxy(_rtpRtcpModule->SSRC())); 810 statistics_proxy_.reset(new StatisticsProxy(_rtpRtcpModule->SSRC()));
804 rtp_receive_statistics_->RegisterRtcpStatisticsCallback( 811 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(
805 statistics_proxy_.get()); 812 statistics_proxy_.get());
806 813
807 Config audioproc_config; 814 Config audioproc_config;
808 audioproc_config.Set<ExperimentalAgc>(new ExperimentalAgc(false)); 815 audioproc_config.Set<ExperimentalAgc>(new ExperimentalAgc(false));
809 rx_audioproc_.reset(AudioProcessing::Create(audioproc_config)); 816 rx_audioproc_.reset(AudioProcessing::Create(audioproc_config));
810 } 817 }
811 818
812 Channel::~Channel() 819 Channel::~Channel()
813 { 820 {
814 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(NULL); 821 rtp_receive_statistics_->RegisterRtcpStatisticsCallback(NULL);
815 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,_channelId), 822 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,_channelId),
816 "Channel::~Channel() - dtor"); 823 "Channel::~Channel() - dtor");
817 824
818 if (_outputExternalMedia) 825 if (_outputExternalMedia)
819 { 826 {
820 DeRegisterExternalMediaProcessing(kPlaybackPerChannel); 827 DeRegisterExternalMediaProcessing(kPlaybackPerChannel);
821 } 828 }
822 if (channel_state_.Get().input_external_media) 829 if (channel_state_.Get().input_external_media)
823 { 830 {
824 DeRegisterExternalMediaProcessing(kRecordingPerChannel); 831 DeRegisterExternalMediaProcessing(kRecordingPerChannel);
825 } 832 }
826 StopSend(); 833 StopSend();
834 if (packet_router_ != nullptr)
835 packet_router_->RemoveRtpModule(_rtpRtcpModule.get());
the sun 2015/11/30 12:37:20 Seems like the PacketSenderProxy should handle thi
stefan-webrtc 2015/11/30 15:22:02 It could, but that would require it to keep around
the sun 2015/12/01 10:25:35 No, that would only make sense if the proxy class
827 StopPlayout(); 836 StopPlayout();
828 837
829 { 838 {
830 CriticalSectionScoped cs(&_fileCritSect); 839 CriticalSectionScoped cs(&_fileCritSect);
831 if (_inputFilePlayerPtr) 840 if (_inputFilePlayerPtr)
832 { 841 {
833 _inputFilePlayerPtr->RegisterModuleFileCallback(NULL); 842 _inputFilePlayerPtr->RegisterModuleFileCallback(NULL);
834 _inputFilePlayerPtr->StopPlayingFile(); 843 _inputFilePlayerPtr->StopPlayingFile();
835 FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr); 844 FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr);
836 _inputFilePlayerPtr = NULL; 845 _inputFilePlayerPtr = NULL;
(...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after
2777 int Channel::SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id) { 2786 int Channel::SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id) {
2778 rtp_header_parser_->DeregisterRtpHeaderExtension( 2787 rtp_header_parser_->DeregisterRtpHeaderExtension(
2779 kRtpExtensionAbsoluteSendTime); 2788 kRtpExtensionAbsoluteSendTime);
2780 if (enable && !rtp_header_parser_->RegisterRtpHeaderExtension( 2789 if (enable && !rtp_header_parser_->RegisterRtpHeaderExtension(
2781 kRtpExtensionAbsoluteSendTime, id)) { 2790 kRtpExtensionAbsoluteSendTime, id)) {
2782 return -1; 2791 return -1;
2783 } 2792 }
2784 return 0; 2793 return 0;
2785 } 2794 }
2786 2795
2796 void Channel::SetSendTransportSequenceNumber(int id) {
2797 int ret =
2798 SetSendRtpHeaderExtension(true, kRtpExtensionTransportSequenceNumber, id);
2799 RTC_DCHECK_EQ(0, ret);
2800 }
2801
2787 void Channel::SetRTCPStatus(bool enable) { 2802 void Channel::SetRTCPStatus(bool enable) {
2788 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), 2803 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId),
2789 "Channel::SetRTCPStatus()"); 2804 "Channel::SetRTCPStatus()");
2790 _rtpRtcpModule->SetRTCPStatus(enable ? RtcpMode::kCompound : RtcpMode::kOff); 2805 _rtpRtcpModule->SetRTCPStatus(enable ? RtcpMode::kCompound : RtcpMode::kOff);
2791 } 2806 }
2792 2807
2808 void Channel::SetCongestionControlObjects(
2809 RtpPacketSender* rtp_packet_sender,
2810 TransportFeedbackObserver* transport_feedback_observer,
2811 PacketRouter* packet_router) {
2812 RTC_DCHECK(packet_sender_proxy_.get());
2813 RTC_DCHECK(packet_router != nullptr || packet_router_ != nullptr);
2814 packet_sender_proxy_->SetCongestionControlObjects(
2815 rtp_packet_sender, transport_feedback_observer, packet_router);
2816 _rtpRtcpModule->SetStorePacketsStatus(rtp_packet_sender != nullptr, 600);
2817 if (packet_router != nullptr) {
2818 packet_router->AddRtpModule(_rtpRtcpModule.get());
2819 } else {
2820 packet_router_->RemoveRtpModule(_rtpRtcpModule.get());
2821 }
2822 packet_router_ = packet_router;
2823 }
2824
2793 int 2825 int
2794 Channel::GetRTCPStatus(bool& enabled) 2826 Channel::GetRTCPStatus(bool& enabled)
2795 { 2827 {
2796 RtcpMode method = _rtpRtcpModule->RTCP(); 2828 RtcpMode method = _rtpRtcpModule->RTCP();
2797 enabled = (method != RtcpMode::kOff); 2829 enabled = (method != RtcpMode::kOff);
2798 return 0; 2830 return 0;
2799 } 2831 }
2800 2832
2801 int 2833 int
2802 Channel::SetRTCP_CNAME(const char cName[256]) 2834 Channel::SetRTCP_CNAME(const char cName[256])
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after
3942 int64_t min_rtt = 0; 3974 int64_t min_rtt = 0;
3943 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) 3975 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt)
3944 != 0) { 3976 != 0) {
3945 return 0; 3977 return 0;
3946 } 3978 }
3947 return rtt; 3979 return rtt;
3948 } 3980 }
3949 3981
3950 } // namespace voe 3982 } // namespace voe
3951 } // namespace webrtc 3983 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698