diff options
Diffstat (limited to 'webrtc/voice_engine')
50 files changed, 1116 insertions, 633 deletions
diff --git a/webrtc/voice_engine/BUILD.gn b/webrtc/voice_engine/BUILD.gn index efe4781be7..82cd92355c 100644 --- a/webrtc/voice_engine/BUILD.gn +++ b/webrtc/voice_engine/BUILD.gn @@ -14,6 +14,8 @@ source_set("voice_engine") { "channel.h", "channel_manager.cc", "channel_manager.h", + "channel_proxy.cc", + "channel_proxy.h", "dtmf_inband.cc", "dtmf_inband.h", "dtmf_inband_queue.cc", @@ -104,6 +106,7 @@ source_set("voice_engine") { "../modules/audio_processing", "../modules/bitrate_controller", "../modules/media_file", + "../modules/pacing", "../modules/rtp_rtcp", "../modules/utility", "../system_wrappers", diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index 013f908d34..b1b55e8acc 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -11,23 +11,26 @@ #include "webrtc/voice_engine/channel.h" #include <algorithm> +#include <utility> #include "webrtc/base/checks.h" #include "webrtc/base/format_macros.h" +#include "webrtc/base/logging.h" +#include "webrtc/base/thread_checker.h" #include "webrtc/base/timeutils.h" #include "webrtc/common.h" #include "webrtc/config.h" #include "webrtc/modules/audio_device/include/audio_device.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" -#include "webrtc/modules/interface/module_common_types.h" -#include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h" +#include "webrtc/modules/include/module_common_types.h" +#include "webrtc/modules/pacing/packet_router.h" +#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_strategy.h" -#include "webrtc/modules/utility/interface/audio_frame_operations.h" -#include "webrtc/modules/utility/interface/process_thread.h" +#include "webrtc/modules/utility/include/audio_frame_operations.h" +#include "webrtc/modules/utility/include/process_thread.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/logging.h" #include "webrtc/system_wrappers/include/trace.h" #include "webrtc/voice_engine/include/voe_base.h" #include "webrtc/voice_engine/include/voe_external_media.h" @@ -44,6 +47,104 @@ namespace webrtc { namespace voe { +class TransportFeedbackProxy : public TransportFeedbackObserver { + public: + TransportFeedbackProxy() : feedback_observer_(nullptr) { + pacer_thread_.DetachFromThread(); + network_thread_.DetachFromThread(); + } + + void SetTransportFeedbackObserver( + TransportFeedbackObserver* feedback_observer) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + rtc::CritScope lock(&crit_); + feedback_observer_ = feedback_observer; + } + + // Implements TransportFeedbackObserver. + void AddPacket(uint16_t sequence_number, + size_t length, + bool was_paced) override { + RTC_DCHECK(pacer_thread_.CalledOnValidThread()); + rtc::CritScope lock(&crit_); + if (feedback_observer_) + feedback_observer_->AddPacket(sequence_number, length, was_paced); + } + void OnTransportFeedback(const rtcp::TransportFeedback& feedback) override { + RTC_DCHECK(network_thread_.CalledOnValidThread()); + rtc::CritScope lock(&crit_); + if (feedback_observer_) + feedback_observer_->OnTransportFeedback(feedback); + } + + private: + rtc::CriticalSection crit_; + rtc::ThreadChecker thread_checker_; + rtc::ThreadChecker pacer_thread_; + rtc::ThreadChecker network_thread_; + TransportFeedbackObserver* feedback_observer_ GUARDED_BY(&crit_); +}; + +class TransportSequenceNumberProxy : public TransportSequenceNumberAllocator { + public: + TransportSequenceNumberProxy() : seq_num_allocator_(nullptr) { + pacer_thread_.DetachFromThread(); + } + + void SetSequenceNumberAllocator( + TransportSequenceNumberAllocator* seq_num_allocator) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + rtc::CritScope lock(&crit_); + seq_num_allocator_ = seq_num_allocator; + } + + // Implements TransportSequenceNumberAllocator. + uint16_t AllocateSequenceNumber() override { + RTC_DCHECK(pacer_thread_.CalledOnValidThread()); + rtc::CritScope lock(&crit_); + if (!seq_num_allocator_) + return 0; + return seq_num_allocator_->AllocateSequenceNumber(); + } + + private: + rtc::CriticalSection crit_; + rtc::ThreadChecker thread_checker_; + rtc::ThreadChecker pacer_thread_; + TransportSequenceNumberAllocator* seq_num_allocator_ GUARDED_BY(&crit_); +}; + +class RtpPacketSenderProxy : public RtpPacketSender { + public: + RtpPacketSenderProxy() : rtp_packet_sender_(nullptr) { + } + + void SetPacketSender(RtpPacketSender* rtp_packet_sender) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + rtc::CritScope lock(&crit_); + rtp_packet_sender_ = rtp_packet_sender; + } + + // Implements RtpPacketSender. + void InsertPacket(Priority priority, + uint32_t ssrc, + uint16_t sequence_number, + int64_t capture_time_ms, + size_t bytes, + bool retransmission) override { + rtc::CritScope lock(&crit_); + if (rtp_packet_sender_) { + rtp_packet_sender_->InsertPacket(priority, ssrc, sequence_number, + capture_time_ms, bytes, retransmission); + } + } + + private: + rtc::ThreadChecker thread_checker_; + rtc::CriticalSection crit_; + RtpPacketSender* rtp_packet_sender_ GUARDED_BY(&crit_); +}; + // Extend the default RTCP statistics struct with max_jitter, defined as the // maximum jitter value seen in an RTCP report block. struct ChannelStatistics : public RtcpStatistics { @@ -318,11 +419,11 @@ int32_t Channel::OnInitializeDecoder( int8_t payloadType, const char payloadName[RTP_PAYLOAD_NAME_SIZE], int frequency, - uint8_t channels, + size_t channels, uint32_t rate) { WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), "Channel::OnInitializeDecoder(payloadType=%d, " - "payloadName=%s, frequency=%u, channels=%u, rate=%u)", + "payloadName=%s, frequency=%u, channels=%" PRIuS ", rate=%u)", payloadType, payloadName, frequency, channels, rate); CodecInst receiveCodec = {0}; @@ -358,7 +459,7 @@ Channel::OnReceivedPayloadData(const uint8_t* payloadData, { WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,_channelId), "Channel::OnReceivedPayloadData(payloadSize=%" PRIuS "," - " payloadType=%u, audioChannel=%u)", + " payloadType=%u, audioChannel=%" PRIuS ")", payloadSize, rtpHeader->header.payloadType, rtpHeader->type.Audio.channel); @@ -460,6 +561,21 @@ int32_t Channel::GetAudioFrame(int32_t id, AudioFrame* audioFrame) } } + { + // Pass the audio buffers to an optional sink callback, before applying + // scaling/panning, as that applies to the mix operation. + // External recipients of the audio (e.g. via AudioTrack), will do their + // own mixing/dynamic processing. + CriticalSectionScoped cs(&_callbackCritSect); + if (audio_sink_) { + AudioSinkInterface::Data data( + &audioFrame->data_[0], + audioFrame->samples_per_channel_, audioFrame->sample_rate_hz_, + audioFrame->num_channels_, audioFrame->timestamp_); + audio_sink_->OnData(data); + } + } + float output_gain = 1.0f; float left_pan = 1.0f; float right_pan = 1.0f; @@ -508,13 +624,10 @@ int32_t Channel::GetAudioFrame(int32_t id, AudioFrame* audioFrame) const bool isStereo = (audioFrame->num_channels_ == 2); if (_outputExternalMediaCallbackPtr) { - _outputExternalMediaCallbackPtr->Process( - _channelId, - kPlaybackPerChannel, - (int16_t*)audioFrame->data_, - audioFrame->samples_per_channel_, - audioFrame->sample_rate_hz_, - isStereo); + _outputExternalMediaCallbackPtr->Process( + _channelId, kPlaybackPerChannel, (int16_t*)audioFrame->data_, + audioFrame->samples_per_channel_, audioFrame->sample_rate_hz_, + isStereo); } } @@ -690,89 +803,97 @@ Channel::Channel(int32_t channelId, uint32_t instanceId, RtcEventLog* const event_log, const Config& config) - : _fileCritSect(*CriticalSectionWrapper::CreateCriticalSection()), - _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()), - volume_settings_critsect_(*CriticalSectionWrapper::CreateCriticalSection()), - _instanceId(instanceId), - _channelId(channelId), - event_log_(event_log), - rtp_header_parser_(RtpHeaderParser::Create()), - rtp_payload_registry_( - new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(true))), - rtp_receive_statistics_( - ReceiveStatistics::Create(Clock::GetRealTimeClock())), - rtp_receiver_( - RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(), - this, - this, - this, - rtp_payload_registry_.get())), - telephone_event_handler_(rtp_receiver_->GetTelephoneEventHandler()), - _outputAudioLevel(), - _externalTransport(false), - _inputFilePlayerPtr(NULL), - _outputFilePlayerPtr(NULL), - _outputFileRecorderPtr(NULL), - // Avoid conflict with other channels by adding 1024 - 1026, - // won't use as much as 1024 channels. - _inputFilePlayerId(VoEModuleId(instanceId, channelId) + 1024), - _outputFilePlayerId(VoEModuleId(instanceId, channelId) + 1025), - _outputFileRecorderId(VoEModuleId(instanceId, channelId) + 1026), - _outputFileRecording(false), - _inbandDtmfQueue(VoEModuleId(instanceId, channelId)), - _inbandDtmfGenerator(VoEModuleId(instanceId, channelId)), - _outputExternalMedia(false), - _inputExternalMediaCallbackPtr(NULL), - _outputExternalMediaCallbackPtr(NULL), - _timeStamp(0), // This is just an offset, RTP module will add it's own - // random offset - _sendTelephoneEventPayloadType(106), - ntp_estimator_(Clock::GetRealTimeClock()), - jitter_buffer_playout_timestamp_(0), - playout_timestamp_rtp_(0), - playout_timestamp_rtcp_(0), - playout_delay_ms_(0), - _numberOfDiscardedPackets(0), - send_sequence_number_(0), - ts_stats_lock_(CriticalSectionWrapper::CreateCriticalSection()), - rtp_ts_wraparound_handler_(new rtc::TimestampWrapAroundHandler()), - capture_start_rtp_time_stamp_(-1), - capture_start_ntp_time_ms_(-1), - _engineStatisticsPtr(NULL), - _outputMixerPtr(NULL), - _transmitMixerPtr(NULL), - _moduleProcessThreadPtr(NULL), - _audioDeviceModulePtr(NULL), - _voiceEngineObserverPtr(NULL), - _callbackCritSectPtr(NULL), - _transportPtr(NULL), - _rxVadObserverPtr(NULL), - _oldVadDecision(-1), - _sendFrameType(0), - _externalMixing(false), - _mixFileWithMicrophone(false), - _mute(false), - _panLeft(1.0f), - _panRight(1.0f), - _outputGain(1.0f), - _playOutbandDtmfEvent(false), - _playInbandDtmfEvent(false), - _lastLocalTimeStamp(0), - _lastPayloadType(0), - _includeAudioLevelIndication(false), - _outputSpeechType(AudioFrame::kNormalSpeech), - video_sync_lock_(CriticalSectionWrapper::CreateCriticalSection()), - _average_jitter_buffer_delay_us(0), - _previousTimestamp(0), - _recPacketDelayMs(20), - _RxVadDetection(false), - _rxAgcIsEnabled(false), - _rxNsIsEnabled(false), - restored_packet_in_use_(false), - rtcp_observer_(new VoERtcpObserver(this)), - network_predictor_(new NetworkPredictor(Clock::GetRealTimeClock())), - assoc_send_channel_lock_(CriticalSectionWrapper::CreateCriticalSection()), - associate_send_channel_(ChannelOwner(nullptr)) { + : _fileCritSect(*CriticalSectionWrapper::CreateCriticalSection()), + _callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()), + volume_settings_critsect_( + *CriticalSectionWrapper::CreateCriticalSection()), + _instanceId(instanceId), + _channelId(channelId), + event_log_(event_log), + rtp_header_parser_(RtpHeaderParser::Create()), + rtp_payload_registry_( + new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(true))), + rtp_receive_statistics_( + ReceiveStatistics::Create(Clock::GetRealTimeClock())), + rtp_receiver_( + RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(), + this, + this, + this, + rtp_payload_registry_.get())), + telephone_event_handler_(rtp_receiver_->GetTelephoneEventHandler()), + _outputAudioLevel(), + _externalTransport(false), + _inputFilePlayerPtr(NULL), + _outputFilePlayerPtr(NULL), + _outputFileRecorderPtr(NULL), + // Avoid conflict with other channels by adding 1024 - 1026, + // won't use as much as 1024 channels. + _inputFilePlayerId(VoEModuleId(instanceId, channelId) + 1024), + _outputFilePlayerId(VoEModuleId(instanceId, channelId) + 1025), + _outputFileRecorderId(VoEModuleId(instanceId, channelId) + 1026), + _outputFileRecording(false), + _inbandDtmfQueue(VoEModuleId(instanceId, channelId)), + _inbandDtmfGenerator(VoEModuleId(instanceId, channelId)), + _outputExternalMedia(false), + _inputExternalMediaCallbackPtr(NULL), + _outputExternalMediaCallbackPtr(NULL), + _timeStamp(0), // This is just an offset, RTP module will add it's own + // random offset + _sendTelephoneEventPayloadType(106), + ntp_estimator_(Clock::GetRealTimeClock()), + jitter_buffer_playout_timestamp_(0), + playout_timestamp_rtp_(0), + playout_timestamp_rtcp_(0), + playout_delay_ms_(0), + _numberOfDiscardedPackets(0), + send_sequence_number_(0), + ts_stats_lock_(CriticalSectionWrapper::CreateCriticalSection()), + rtp_ts_wraparound_handler_(new rtc::TimestampWrapAroundHandler()), + capture_start_rtp_time_stamp_(-1), + capture_start_ntp_time_ms_(-1), + _engineStatisticsPtr(NULL), + _outputMixerPtr(NULL), + _transmitMixerPtr(NULL), + _moduleProcessThreadPtr(NULL), + _audioDeviceModulePtr(NULL), + _voiceEngineObserverPtr(NULL), + _callbackCritSectPtr(NULL), + _transportPtr(NULL), + _rxVadObserverPtr(NULL), + _oldVadDecision(-1), + _sendFrameType(0), + _externalMixing(false), + _mixFileWithMicrophone(false), + _mute(false), + _panLeft(1.0f), + _panRight(1.0f), + _outputGain(1.0f), + _playOutbandDtmfEvent(false), + _playInbandDtmfEvent(false), + _lastLocalTimeStamp(0), + _lastPayloadType(0), + _includeAudioLevelIndication(false), + _outputSpeechType(AudioFrame::kNormalSpeech), + video_sync_lock_(CriticalSectionWrapper::CreateCriticalSection()), + _average_jitter_buffer_delay_us(0), + _previousTimestamp(0), + _recPacketDelayMs(20), + _RxVadDetection(false), + _rxAgcIsEnabled(false), + _rxNsIsEnabled(false), + restored_packet_in_use_(false), + rtcp_observer_(new VoERtcpObserver(this)), + network_predictor_(new NetworkPredictor(Clock::GetRealTimeClock())), + assoc_send_channel_lock_(CriticalSectionWrapper::CreateCriticalSection()), + associate_send_channel_(ChannelOwner(nullptr)), + pacing_enabled_(config.Get<VoicePacing>().enabled), + feedback_observer_proxy_(pacing_enabled_ ? new TransportFeedbackProxy() + : nullptr), + seq_num_allocator_proxy_( + pacing_enabled_ ? new TransportSequenceNumberProxy() : nullptr), + rtp_packet_sender_proxy_(pacing_enabled_ ? new RtpPacketSenderProxy() + : nullptr) { WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,_channelId), "Channel::Channel() - ctor"); AudioCodingModule::Config acm_config; @@ -797,6 +918,10 @@ Channel::Channel(int32_t channelId, configuration.audio_messages = this; configuration.receive_statistics = rtp_receive_statistics_.get(); configuration.bandwidth_callback = rtcp_observer_.get(); + configuration.paced_sender = rtp_packet_sender_proxy_.get(); + configuration.transport_sequence_number_allocator = + seq_num_allocator_proxy_.get(); + configuration.transport_feedback_callback = feedback_observer_proxy_.get(); _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration)); @@ -954,8 +1079,8 @@ Channel::Init() { WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId,_channelId), - "Channel::Init() unable to register %s (%d/%d/%d/%d) " - "to RTP/RTCP receiver", + "Channel::Init() unable to register %s " + "(%d/%d/%" PRIuS "/%d) to RTP/RTCP receiver", codec.plname, codec.pltype, codec.plfreq, codec.channels, codec.rate); } @@ -963,8 +1088,8 @@ Channel::Init() { WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), - "Channel::Init() %s (%d/%d/%d/%d) has been added to " - "the RTP/RTCP receiver", + "Channel::Init() %s (%d/%d/%" PRIuS "/%d) has been " + "added to the RTP/RTCP receiver", codec.plname, codec.pltype, codec.plfreq, codec.channels, codec.rate); } @@ -1020,11 +1145,11 @@ Channel::Init() } if (rx_audioproc_->noise_suppression()->set_level(kDefaultNsMode) != 0) { - LOG_FERR1(LS_ERROR, noise_suppression()->set_level, kDefaultNsMode); + LOG(LS_ERROR) << "noise_suppression()->set_level(kDefaultNsMode) failed."; return -1; } if (rx_audioproc_->gain_control()->set_mode(kDefaultRxAgcMode) != 0) { - LOG_FERR1(LS_ERROR, gain_control()->set_mode, kDefaultRxAgcMode); + LOG(LS_ERROR) << "gain_control()->set_mode(kDefaultRxAgcMode) failed."; return -1; } @@ -1060,6 +1185,11 @@ Channel::UpdateLocalTimeStamp() return 0; } +void Channel::SetSink(rtc::scoped_ptr<AudioSinkInterface> sink) { + CriticalSectionScoped cs(&_callbackCritSect); + audio_sink_ = std::move(sink); +} + int32_t Channel::StartPlayout() { @@ -1242,7 +1372,12 @@ Channel::DeRegisterVoiceEngineObserver() int32_t Channel::GetSendCodec(CodecInst& codec) { - return (audio_coding_->SendCodec(&codec)); + auto send_codec = audio_coding_->SendCodec(); + if (send_codec) { + codec = *send_codec; + return 0; + } + return -1; } int32_t @@ -1456,7 +1591,7 @@ Channel::SetSendCNPayloadType(int type, PayloadFrequencies frequency) CodecInst codec; int32_t samplingFreqHz(-1); - const int kMono = 1; + const size_t kMono = 1; if (frequency == kFreq32000Hz) samplingFreqHz = 32000; else if (frequency == kFreq16000Hz) @@ -2367,6 +2502,9 @@ int Channel::SendTelephoneEventOutband(unsigned char eventCode, WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), "Channel::SendTelephoneEventOutband(..., playDtmfEvent=%d)", playDtmfEvent); + if (!Sending()) { + return -1; + } _playOutbandDtmfEvent = playDtmfEvent; @@ -2779,6 +2917,38 @@ int Channel::SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id) { return 0; } +void Channel::EnableSendTransportSequenceNumber(int id) { + int ret = + SetSendRtpHeaderExtension(true, kRtpExtensionTransportSequenceNumber, id); + RTC_DCHECK_EQ(0, ret); +} + +void Channel::SetCongestionControlObjects( + RtpPacketSender* rtp_packet_sender, + TransportFeedbackObserver* transport_feedback_observer, + PacketRouter* packet_router) { + RTC_DCHECK(packet_router != nullptr || packet_router_ != nullptr); + if (transport_feedback_observer) { + RTC_DCHECK(feedback_observer_proxy_.get()); + feedback_observer_proxy_->SetTransportFeedbackObserver( + transport_feedback_observer); + } + if (rtp_packet_sender) { + RTC_DCHECK(rtp_packet_sender_proxy_.get()); + rtp_packet_sender_proxy_->SetPacketSender(rtp_packet_sender); + } + if (seq_num_allocator_proxy_.get()) { + seq_num_allocator_proxy_->SetSequenceNumberAllocator(packet_router); + } + _rtpRtcpModule->SetStorePacketsStatus(rtp_packet_sender != nullptr, 600); + if (packet_router != nullptr) { + packet_router->AddRtpModule(_rtpRtcpModule.get()); + } else { + packet_router_->RemoveRtpModule(_rtpRtcpModule.get()); + } + packet_router_ = packet_router; +} + void Channel::SetRTCPStatus(bool enable) { WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), "Channel::SetRTCPStatus()"); @@ -3122,9 +3292,8 @@ Channel::GetREDStatus(bool& enabled, int& redPayloadtype) enabled = audio_coding_->REDStatus(); if (enabled) { - int8_t payloadType(0); - if (_rtpRtcpModule->SendREDPayloadType(payloadType) != 0) - { + int8_t payloadType = 0; + if (_rtpRtcpModule->SendREDPayloadType(&payloadType) != 0) { _engineStatisticsPtr->SetLastError( VE_RTP_RTCP_MODULE_ERROR, kTraceError, "GetREDStatus() failed to retrieve RED PT from RTP/RTCP " @@ -3157,7 +3326,9 @@ bool Channel::GetCodecFECStatus() { void Channel::SetNACKStatus(bool enable, int maxNumberOfPackets) { // None of these functions can fail. - _rtpRtcpModule->SetStorePacketsStatus(enable, maxNumberOfPackets); + // If pacing is enabled we always store packets. + if (!pacing_enabled_) + _rtpRtcpModule->SetStorePacketsStatus(enable, maxNumberOfPackets); rtp_receive_statistics_->SetMaxReorderingThreshold(maxNumberOfPackets); rtp_receiver_->SetNACKStatus(enable ? kNackRtcp : kNackOff); if (enable) @@ -3184,7 +3355,7 @@ Channel::Demultiplex(const AudioFrame& audioFrame) void Channel::Demultiplex(const int16_t* audio_data, int sample_rate, size_t number_of_frames, - int number_of_channels) { + size_t number_of_channels) { CodecInst codec; GetSendCodec(codec); @@ -3410,33 +3581,17 @@ bool Channel::GetDelayEstimate(int* jitter_buffer_delay_ms, return true; } -int Channel::LeastRequiredDelayMs() const { - return audio_coding_->LeastRequiredDelayMs(); +uint32_t Channel::GetDelayEstimate() const { + int jitter_buffer_delay_ms = 0; + int playout_buffer_delay_ms = 0; + GetDelayEstimate(&jitter_buffer_delay_ms, &playout_buffer_delay_ms); + return jitter_buffer_delay_ms + playout_buffer_delay_ms; } -int Channel::SetInitialPlayoutDelay(int delay_ms) -{ - WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId), - "Channel::SetInitialPlayoutDelay()"); - if ((delay_ms < kVoiceEngineMinMinPlayoutDelayMs) || - (delay_ms > kVoiceEngineMaxMinPlayoutDelayMs)) - { - _engineStatisticsPtr->SetLastError( - VE_INVALID_ARGUMENT, kTraceError, - "SetInitialPlayoutDelay() invalid min delay"); - return -1; - } - if (audio_coding_->SetInitialPlayoutDelay(delay_ms) != 0) - { - _engineStatisticsPtr->SetLastError( - VE_AUDIO_CODING_MODULE_ERROR, kTraceError, - "SetInitialPlayoutDelay() failed to set min playout delay"); - return -1; - } - return 0; +int Channel::LeastRequiredDelayMs() const { + return audio_coding_->LeastRequiredDelayMs(); } - int Channel::SetMinimumPlayoutDelay(int delayMs) { @@ -3687,7 +3842,7 @@ Channel::InsertInbandDtmfTone() sample < _audioFrame.samples_per_channel_; sample++) { - for (int channel = 0; + for (size_t channel = 0; channel < _audioFrame.num_channels_; channel++) { @@ -3821,7 +3976,8 @@ Channel::RegisterReceiveCodecsToRTPModule() kTraceVoice, VoEId(_instanceId, _channelId), "Channel::RegisterReceiveCodecsToRTPModule() unable" - " to register %s (%d/%d/%d/%d) to RTP/RTCP receiver", + " to register %s (%d/%d/%" PRIuS "/%d) to RTP/RTCP " + "receiver", codec.plname, codec.pltype, codec.plfreq, codec.channels, codec.rate); } @@ -3831,7 +3987,7 @@ Channel::RegisterReceiveCodecsToRTPModule() kTraceVoice, VoEId(_instanceId, _channelId), "Channel::RegisterReceiveCodecsToRTPModule() %s " - "(%d/%d/%d/%d) has been added to the RTP/RTCP " + "(%d/%d/%" PRIuS "/%d) has been added to the RTP/RTCP " "receiver", codec.plname, codec.pltype, codec.plfreq, codec.channels, codec.rate); diff --git a/webrtc/voice_engine/channel.h b/webrtc/voice_engine/channel.h index 46e67502d8..d15f9dbca7 100644 --- a/webrtc/voice_engine/channel.h +++ b/webrtc/voice_engine/channel.h @@ -11,18 +11,19 @@ #ifndef WEBRTC_VOICE_ENGINE_CHANNEL_H_ #define WEBRTC_VOICE_ENGINE_CHANNEL_H_ +#include "webrtc/audio/audio_sink.h" +#include "webrtc/base/criticalsection.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/common_audio/resampler/include/push_resampler.h" #include "webrtc/common_types.h" -#include "webrtc/modules/audio_coding/main/include/audio_coding_module.h" -#include "webrtc/modules/audio_conference_mixer/interface/audio_conference_mixer_defines.h" +#include "webrtc/modules/audio_coding/include/audio_coding_module.h" +#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h" #include "webrtc/modules/audio_processing/rms_level.h" -#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" -#include "webrtc/modules/rtp_rtcp/interface/remote_ntp_time_estimator.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" -#include "webrtc/modules/utility/interface/file_player.h" -#include "webrtc/modules/utility/interface/file_recorder.h" +#include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" +#include "webrtc/modules/utility/include/file_player.h" +#include "webrtc/modules/utility/include/file_recorder.h" #include "webrtc/voice_engine/dtmf_inband.h" #include "webrtc/voice_engine/dtmf_inband_queue.h" #include "webrtc/voice_engine/include/voe_audio_processing.h" @@ -48,6 +49,7 @@ class AudioDeviceModule; class Config; class CriticalSectionWrapper; class FileWrapper; +class PacketRouter; class ProcessThread; class ReceiveStatistics; class RemoteNtpTimeEstimator; @@ -68,9 +70,12 @@ struct SenderInfo; namespace voe { class OutputMixer; +class RtpPacketSenderProxy; class Statistics; class StatisticsProxy; +class TransportFeedbackProxy; class TransmitMixer; +class TransportSequenceNumberProxy; class VoERtcpObserver; // Helper class to simplify locking scheme for members that are accessed from @@ -188,6 +193,8 @@ public: CriticalSectionWrapper* callbackCritSect); int32_t UpdateLocalTimeStamp(); + void SetSink(rtc::scoped_ptr<AudioSinkInterface> sink); + // API methods // VoEBase @@ -279,8 +286,8 @@ public: // VoEVideoSync bool GetDelayEstimate(int* jitter_buffer_delay_ms, int* playout_buffer_delay_ms) const; + uint32_t GetDelayEstimate() const; int LeastRequiredDelayMs() const; - int SetInitialPlayoutDelay(int delay_ms); int SetMinimumPlayoutDelay(int delayMs); int GetPlayoutTimestamp(unsigned int& timestamp); int SetInitTimestamp(unsigned int timestamp); @@ -321,6 +328,13 @@ public: int SetReceiveAudioLevelIndicationStatus(bool enable, unsigned char id); int SetSendAbsoluteSenderTimeStatus(bool enable, unsigned char id); int SetReceiveAbsoluteSenderTimeStatus(bool enable, unsigned char id); + void EnableSendTransportSequenceNumber(int id); + + void SetCongestionControlObjects( + RtpPacketSender* rtp_packet_sender, + TransportFeedbackObserver* transport_feedback_observer, + PacketRouter* packet_router); + void SetRTCPStatus(bool enable); int GetRTCPStatus(bool& enabled); int SetRTCP_CNAME(const char cName[256]); @@ -367,7 +381,7 @@ public: int32_t OnInitializeDecoder(int8_t payloadType, const char payloadName[RTP_PAYLOAD_NAME_SIZE], int frequency, - uint8_t channels, + size_t channels, uint32_t rate) override; void OnIncomingSSRCChanged(uint32_t ssrc) override; void OnIncomingCSRCChanged(uint32_t CSRC, bool added) override; @@ -437,7 +451,7 @@ public: void Demultiplex(const int16_t* audio_data, int sample_rate, size_t number_of_frames, - int number_of_channels); + size_t number_of_channels); uint32_t PrepareEncodeAndSend(int mixingFrequency); uint32_t EncodeAndSend(); @@ -497,6 +511,7 @@ private: TelephoneEventHandler* telephone_event_handler_; rtc::scoped_ptr<RtpRtcp> _rtpRtcpModule; rtc::scoped_ptr<AudioCodingModule> audio_coding_; + rtc::scoped_ptr<AudioSinkInterface> audio_sink_; AudioLevel _outputAudioLevel; bool _externalTransport; AudioFrame _audioFrame; @@ -584,6 +599,12 @@ private: // An associated send channel. rtc::scoped_ptr<CriticalSectionWrapper> assoc_send_channel_lock_; ChannelOwner associate_send_channel_ GUARDED_BY(assoc_send_channel_lock_); + + bool pacing_enabled_; + PacketRouter* packet_router_ = nullptr; + rtc::scoped_ptr<TransportFeedbackProxy> feedback_observer_proxy_; + rtc::scoped_ptr<TransportSequenceNumberProxy> seq_num_allocator_proxy_; + rtc::scoped_ptr<RtpPacketSenderProxy> rtp_packet_sender_proxy_; }; } // namespace voe diff --git a/webrtc/voice_engine/channel_proxy.cc b/webrtc/voice_engine/channel_proxy.cc new file mode 100644 index 0000000000..f54c81ec47 --- /dev/null +++ b/webrtc/voice_engine/channel_proxy.cc @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "webrtc/voice_engine/channel_proxy.h" + +#include <utility> + +#include "webrtc/audio/audio_sink.h" +#include "webrtc/base/checks.h" +#include "webrtc/voice_engine/channel.h" + +namespace webrtc { +namespace voe { +ChannelProxy::ChannelProxy() : channel_owner_(nullptr) {} + +ChannelProxy::ChannelProxy(const ChannelOwner& channel_owner) : + channel_owner_(channel_owner) { + RTC_CHECK(channel_owner_.channel()); +} + +ChannelProxy::~ChannelProxy() {} + +void ChannelProxy::SetRTCPStatus(bool enable) { + channel()->SetRTCPStatus(enable); +} + +void ChannelProxy::SetLocalSSRC(uint32_t ssrc) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + int error = channel()->SetLocalSSRC(ssrc); + RTC_DCHECK_EQ(0, error); +} + +void ChannelProxy::SetRTCP_CNAME(const std::string& c_name) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + // Note: VoERTP_RTCP::SetRTCP_CNAME() accepts a char[256] array. + std::string c_name_limited = c_name.substr(0, 255); + int error = channel()->SetRTCP_CNAME(c_name_limited.c_str()); + RTC_DCHECK_EQ(0, error); +} + +void ChannelProxy::SetSendAbsoluteSenderTimeStatus(bool enable, int id) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + int error = channel()->SetSendAbsoluteSenderTimeStatus(enable, id); + RTC_DCHECK_EQ(0, error); +} + +void ChannelProxy::SetSendAudioLevelIndicationStatus(bool enable, int id) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + int error = channel()->SetSendAudioLevelIndicationStatus(enable, id); + RTC_DCHECK_EQ(0, error); +} + +void ChannelProxy::EnableSendTransportSequenceNumber(int id) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + channel()->EnableSendTransportSequenceNumber(id); +} + +void ChannelProxy::SetReceiveAbsoluteSenderTimeStatus(bool enable, int id) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + int error = channel()->SetReceiveAbsoluteSenderTimeStatus(enable, id); + RTC_DCHECK_EQ(0, error); +} + +void ChannelProxy::SetReceiveAudioLevelIndicationStatus(bool enable, int id) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + int error = channel()->SetReceiveAudioLevelIndicationStatus(enable, id); + RTC_DCHECK_EQ(0, error); +} + +void ChannelProxy::SetCongestionControlObjects( + RtpPacketSender* rtp_packet_sender, + TransportFeedbackObserver* transport_feedback_observer, + PacketRouter* packet_router) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + channel()->SetCongestionControlObjects( + rtp_packet_sender, transport_feedback_observer, packet_router); +} + +CallStatistics ChannelProxy::GetRTCPStatistics() const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + CallStatistics stats = {0}; + int error = channel()->GetRTPStatistics(stats); + RTC_DCHECK_EQ(0, error); + return stats; +} + +std::vector<ReportBlock> ChannelProxy::GetRemoteRTCPReportBlocks() const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + std::vector<webrtc::ReportBlock> blocks; + int error = channel()->GetRemoteRTCPReportBlocks(&blocks); + RTC_DCHECK_EQ(0, error); + return blocks; +} + +NetworkStatistics ChannelProxy::GetNetworkStatistics() const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + NetworkStatistics stats = {0}; + int error = channel()->GetNetworkStatistics(stats); + RTC_DCHECK_EQ(0, error); + return stats; +} + +AudioDecodingCallStats ChannelProxy::GetDecodingCallStatistics() const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + AudioDecodingCallStats stats; + channel()->GetDecodingCallStatistics(&stats); + return stats; +} + +int32_t ChannelProxy::GetSpeechOutputLevelFullRange() const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + uint32_t level = 0; + int error = channel()->GetSpeechOutputLevelFullRange(level); + RTC_DCHECK_EQ(0, error); + return static_cast<int32_t>(level); +} + +uint32_t ChannelProxy::GetDelayEstimate() const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + return channel()->GetDelayEstimate(); +} + +bool ChannelProxy::SetSendTelephoneEventPayloadType(int payload_type) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + return channel()->SetSendTelephoneEventPayloadType(payload_type) == 0; +} + +bool ChannelProxy::SendTelephoneEventOutband(uint8_t event, + uint32_t duration_ms) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + return + channel()->SendTelephoneEventOutband(event, duration_ms, 10, false) == 0; +} + +void ChannelProxy::SetSink(rtc::scoped_ptr<AudioSinkInterface> sink) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + channel()->SetSink(std::move(sink)); +} + +Channel* ChannelProxy::channel() const { + RTC_DCHECK(channel_owner_.channel()); + return channel_owner_.channel(); +} + +} // namespace voe +} // namespace webrtc diff --git a/webrtc/voice_engine/channel_proxy.h b/webrtc/voice_engine/channel_proxy.h new file mode 100644 index 0000000000..b990d91734 --- /dev/null +++ b/webrtc/voice_engine/channel_proxy.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_VOICE_ENGINE_CHANNEL_PROXY_H_ +#define WEBRTC_VOICE_ENGINE_CHANNEL_PROXY_H_ + +#include "webrtc/base/thread_checker.h" +#include "webrtc/voice_engine/channel_manager.h" +#include "webrtc/voice_engine/include/voe_rtp_rtcp.h" + +#include <string> +#include <vector> + +namespace webrtc { + +class AudioSinkInterface; +class PacketRouter; +class RtpPacketSender; +class TransportFeedbackObserver; + +namespace voe { + +class Channel; + +// This class provides the "view" of a voe::Channel that we need to implement +// webrtc::AudioSendStream and webrtc::AudioReceiveStream. It serves two +// purposes: +// 1. Allow mocking just the interfaces used, instead of the entire +// voe::Channel class. +// 2. Provide a refined interface for the stream classes, including assumptions +// on return values and input adaptation. +class ChannelProxy { + public: + ChannelProxy(); + explicit ChannelProxy(const ChannelOwner& channel_owner); + virtual ~ChannelProxy(); + + virtual void SetRTCPStatus(bool enable); + virtual void SetLocalSSRC(uint32_t ssrc); + virtual void SetRTCP_CNAME(const std::string& c_name); + virtual void SetSendAbsoluteSenderTimeStatus(bool enable, int id); + virtual void SetSendAudioLevelIndicationStatus(bool enable, int id); + virtual void EnableSendTransportSequenceNumber(int id); + virtual void SetReceiveAbsoluteSenderTimeStatus(bool enable, int id); + virtual void SetReceiveAudioLevelIndicationStatus(bool enable, int id); + virtual void SetCongestionControlObjects( + RtpPacketSender* rtp_packet_sender, + TransportFeedbackObserver* transport_feedback_observer, + PacketRouter* packet_router); + + virtual CallStatistics GetRTCPStatistics() const; + virtual std::vector<ReportBlock> GetRemoteRTCPReportBlocks() const; + virtual NetworkStatistics GetNetworkStatistics() const; + virtual AudioDecodingCallStats GetDecodingCallStatistics() const; + virtual int32_t GetSpeechOutputLevelFullRange() const; + virtual uint32_t GetDelayEstimate() const; + + virtual bool SetSendTelephoneEventPayloadType(int payload_type); + virtual bool SendTelephoneEventOutband(uint8_t event, uint32_t duration_ms); + + virtual void SetSink(rtc::scoped_ptr<AudioSinkInterface> sink); + + private: + Channel* channel() const; + + rtc::ThreadChecker thread_checker_; + ChannelOwner channel_owner_; +}; +} // namespace voe +} // namespace webrtc + +#endif // WEBRTC_VOICE_ENGINE_CHANNEL_PROXY_H_ diff --git a/webrtc/voice_engine/include/voe_base.h b/webrtc/voice_engine/include/voe_base.h index c82ad3dc3a..3d07fa78ff 100644 --- a/webrtc/voice_engine/include/voe_base.h +++ b/webrtc/voice_engine/include/voe_base.h @@ -87,6 +87,8 @@ class WEBRTC_DLLEXPORT VoiceEngine { static int SetAndroidObjects(void* javaVM, void* context); #endif + static std::string GetVersionString(); + protected: VoiceEngine() {} ~VoiceEngine() {} diff --git a/webrtc/voice_engine/include/voe_rtp_rtcp.h b/webrtc/voice_engine/include/voe_rtp_rtcp.h index 6d17501772..dd3609aa00 100644 --- a/webrtc/voice_engine/include/voe_rtp_rtcp.h +++ b/webrtc/voice_engine/include/voe_rtp_rtcp.h @@ -201,20 +201,6 @@ class WEBRTC_DLLEXPORT VoERTP_RTCP { return -1; } - // Sets the Forward Error Correction (FEC) status on a specific |channel|. - // TODO(minyue): Remove SetFECStatus() when SetFECStatus() is replaced by - // SetREDStatus() in fakewebrtcvoiceengine. - virtual int SetFECStatus(int channel, bool enable, int redPayloadtype = -1) { - return SetREDStatus(channel, enable, redPayloadtype); - }; - - // Gets the FEC status on a specific |channel|. - // TODO(minyue): Remove GetFECStatus() when GetFECStatus() is replaced by - // GetREDStatus() in fakewebrtcvoiceengine. - virtual int GetFECStatus(int channel, bool& enabled, int& redPayloadtype) { - return SetREDStatus(channel, enabled, redPayloadtype); - } - // This function enables Negative Acknowledgment (NACK) using RTCP, // implemented based on RFC 4585. NACK retransmits RTP packets if lost on // the network. This creates a lossless transport at the expense of delay. diff --git a/webrtc/voice_engine/include/voe_video_sync.h b/webrtc/voice_engine/include/voe_video_sync.h index 1143cefb0e..655ba63543 100644 --- a/webrtc/voice_engine/include/voe_video_sync.h +++ b/webrtc/voice_engine/include/voe_video_sync.h @@ -64,13 +64,6 @@ class WEBRTC_DLLEXPORT VoEVideoSync { // computes based on inter-arrival times and its playout mode. virtual int SetMinimumPlayoutDelay(int channel, int delay_ms) = 0; - // Sets an initial delay for the playout jitter buffer. The playout of the - // audio is delayed by |delay_ms| in milliseconds. Thereafter, the delay is - // maintained, unless NetEq's internal mechanism requires a higher latency. - // Such a latency is computed based on inter-arrival times and NetEq's - // playout mode. - virtual int SetInitialPlayoutDelay(int channel, int delay_ms) = 0; - // Gets the |jitter_buffer_delay_ms| (including the algorithmic delay), and // the |playout_buffer_delay_ms| for a specified |channel|. virtual int GetDelayEstimate(int channel, diff --git a/webrtc/voice_engine/level_indicator.cc b/webrtc/voice_engine/level_indicator.cc index 059b15f927..68a837edb9 100644 --- a/webrtc/voice_engine/level_indicator.cc +++ b/webrtc/voice_engine/level_indicator.cc @@ -9,7 +9,7 @@ */ #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" -#include "webrtc/modules/interface/module_common_types.h" +#include "webrtc/modules/include/module_common_types.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/voice_engine/level_indicator.h" diff --git a/webrtc/voice_engine/monitor_module.h b/webrtc/voice_engine/monitor_module.h index 42ea74d7e2..fe915b320b 100644 --- a/webrtc/voice_engine/monitor_module.h +++ b/webrtc/voice_engine/monitor_module.h @@ -11,7 +11,7 @@ #ifndef WEBRTC_VOICE_ENGINE_MONITOR_MODULE_H #define WEBRTC_VOICE_ENGINE_MONITOR_MODULE_H -#include "webrtc/modules/interface/module.h" +#include "webrtc/modules/include/module.h" #include "webrtc/typedefs.h" #include "webrtc/voice_engine/voice_engine_defines.h" diff --git a/webrtc/voice_engine/output_mixer.cc b/webrtc/voice_engine/output_mixer.cc index 31b429c498..0dacf35eaf 100644 --- a/webrtc/voice_engine/output_mixer.cc +++ b/webrtc/voice_engine/output_mixer.cc @@ -10,8 +10,9 @@ #include "webrtc/voice_engine/output_mixer.h" +#include "webrtc/base/format_macros.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" -#include "webrtc/modules/utility/interface/audio_frame_operations.h" +#include "webrtc/modules/utility/include/audio_frame_operations.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/file_wrapper.h" #include "webrtc/system_wrappers/include/trace.h" @@ -462,11 +463,12 @@ int OutputMixer::StopRecordingPlayout() } int OutputMixer::GetMixedAudio(int sample_rate_hz, - int num_channels, + size_t num_channels, AudioFrame* frame) { - WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,-1), - "OutputMixer::GetMixedAudio(sample_rate_hz=%d, num_channels=%d)", - sample_rate_hz, num_channels); + WEBRTC_TRACE( + kTraceStream, kTraceVoice, VoEId(_instanceId,-1), + "OutputMixer::GetMixedAudio(sample_rate_hz=%d, num_channels=%" PRIuS ")", + sample_rate_hz, num_channels); // --- Record playout if enabled { @@ -517,8 +519,20 @@ OutputMixer::DoOperationsOnCombinedSignal(bool feed_data_to_apm) } // --- Far-end Voice Quality Enhancement (AudioProcessing Module) - if (feed_data_to_apm) - APMProcessReverseStream(); + if (feed_data_to_apm) { + // Convert from mixing to AudioProcessing sample rate, similarly to how it + // is done on the send side. Downmix to mono. + AudioFrame frame; + frame.num_channels_ = 1; + frame.sample_rate_hz_ = _audioProcessingModulePtr->input_sample_rate_hz(); + RemixAndResample(_audioFrame, &audioproc_resampler_, &frame); + + if (_audioProcessingModulePtr->AnalyzeReverseStream(&frame) != 0) { + WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1), + "AudioProcessingModule::AnalyzeReverseStream() => error"); + RTC_DCHECK(false); + } + } // --- External media processing { @@ -549,13 +563,6 @@ OutputMixer::DoOperationsOnCombinedSignal(bool feed_data_to_apm) // Private methods // ---------------------------------------------------------------------------- -void OutputMixer::APMProcessReverseStream() { - if (_audioProcessingModulePtr->ProcessReverseStream(&_audioFrame) == -1) { - WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, -1), - "AudioProcessingModule::ProcessReverseStream() => error"); - } -} - int OutputMixer::InsertInbandDtmfTone() { diff --git a/webrtc/voice_engine/output_mixer.h b/webrtc/voice_engine/output_mixer.h index 71e55e4885..91387e6256 100644 --- a/webrtc/voice_engine/output_mixer.h +++ b/webrtc/voice_engine/output_mixer.h @@ -13,9 +13,9 @@ #include "webrtc/common_audio/resampler/include/push_resampler.h" #include "webrtc/common_types.h" -#include "webrtc/modules/audio_conference_mixer/interface/audio_conference_mixer.h" -#include "webrtc/modules/audio_conference_mixer/interface/audio_conference_mixer_defines.h" -#include "webrtc/modules/utility/interface/file_recorder.h" +#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer.h" +#include "webrtc/modules/audio_conference_mixer/include/audio_conference_mixer_defines.h" +#include "webrtc/modules/utility/include/file_recorder.h" #include "webrtc/voice_engine/dtmf_inband.h" #include "webrtc/voice_engine/level_indicator.h" #include "webrtc/voice_engine/voice_engine_defines.h" @@ -63,7 +63,7 @@ public: int32_t SetAnonymousMixabilityStatus(MixerParticipant& participant, bool mixable); - int GetMixedAudio(int sample_rate_hz, int num_channels, + int GetMixedAudio(int sample_rate_hz, size_t num_channels, AudioFrame* audioFrame); // VoEVolumeControl @@ -102,7 +102,6 @@ public: private: OutputMixer(uint32_t instanceId); - void APMProcessReverseStream(); int InsertInbandDtmfTone(); // uses diff --git a/webrtc/voice_engine/shared_data.h b/webrtc/voice_engine/shared_data.h index 311bfa063d..9c3d4b1c57 100644 --- a/webrtc/voice_engine/shared_data.h +++ b/webrtc/voice_engine/shared_data.h @@ -14,7 +14,7 @@ #include "webrtc/base/scoped_ptr.h" #include "webrtc/modules/audio_device/include/audio_device.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" -#include "webrtc/modules/utility/interface/process_thread.h" +#include "webrtc/modules/utility/include/process_thread.h" #include "webrtc/voice_engine/channel_manager.h" #include "webrtc/voice_engine/statistics.h" #include "webrtc/voice_engine/voice_engine_defines.h" diff --git a/webrtc/voice_engine/test/android/android_test/jni/android_test.cc b/webrtc/voice_engine/test/android/android_test/jni/android_test.cc index ceafca9da3..766b9e7a8e 100644 --- a/webrtc/voice_engine/test/android/android_test/jni/android_test.cc +++ b/webrtc/voice_engine/test/android/android_test/jni/android_test.cc @@ -15,7 +15,7 @@ #include "webrtc/voice_engine/test/android/android_test/jni/org_webrtc_voiceengine_test_AndroidTest.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/voice_engine/include/voe_audio_processing.h" #include "webrtc/voice_engine/include/voe_base.h" @@ -177,7 +177,7 @@ private: static bool Run(void* ptr); bool Process(); private: - rtc::scoped_ptr<ThreadWrapper> _thread; + rtc::PlatformThread _thread; }; ThreadTest::~ThreadTest() @@ -188,7 +188,7 @@ ThreadTest::~ThreadTest() ThreadTest::ThreadTest() { - _thread = ThreadWrapper::CreateThread(Run, this, "ThreadTest thread"); + _thread(Run, this, "ThreadTest thread"); } bool ThreadTest::Run(void* ptr) diff --git a/webrtc/voice_engine/test/auto_test/fakes/conference_transport.cc b/webrtc/voice_engine/test/auto_test/fakes/conference_transport.cc index 28ab352608..70f68298f5 100644 --- a/webrtc/voice_engine/test/auto_test/fakes/conference_transport.cc +++ b/webrtc/voice_engine/test/auto_test/fakes/conference_transport.cc @@ -40,9 +40,7 @@ ConferenceTransport::ConferenceTransport() : pq_crit_(webrtc::CriticalSectionWrapper::CreateCriticalSection()), stream_crit_(webrtc::CriticalSectionWrapper::CreateCriticalSection()), packet_event_(webrtc::EventWrapper::Create()), - thread_(webrtc::ThreadWrapper::CreateThread(Run, - this, - "ConferenceTransport")), + thread_(Run, this, "ConferenceTransport"), rtt_ms_(0), stream_count_(0), rtp_header_parser_(webrtc::RtpHeaderParser::Create()) { @@ -79,8 +77,8 @@ ConferenceTransport::ConferenceTransport() EXPECT_EQ(0, remote_network_->RegisterExternalTransport(reflector_, *this)); EXPECT_EQ(0, remote_rtp_rtcp_->SetLocalSSRC(reflector_, kReflectorSsrc)); - thread_->Start(); - thread_->SetPriority(webrtc::kHighPriority); + thread_.Start(); + thread_.SetPriority(rtc::kHighPriority); } ConferenceTransport::~ConferenceTransport() { @@ -93,7 +91,7 @@ ConferenceTransport::~ConferenceTransport() { RemoveStream(stream->first); } - EXPECT_TRUE(thread_->Stop()); + thread_.Stop(); remote_file_->Release(); remote_rtp_rtcp_->Release(); diff --git a/webrtc/voice_engine/test/auto_test/fakes/conference_transport.h b/webrtc/voice_engine/test/auto_test/fakes/conference_transport.h index 7b45e6d3e1..5d105aa39e 100644 --- a/webrtc/voice_engine/test/auto_test/fakes/conference_transport.h +++ b/webrtc/voice_engine/test/auto_test/fakes/conference_transport.h @@ -17,12 +17,12 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/basictypes.h" +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/common_types.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/voice_engine/include/voe_base.h" #include "webrtc/voice_engine/include/voe_codec.h" #include "webrtc/voice_engine/include/voe_file.h" @@ -131,7 +131,7 @@ class ConferenceTransport: public webrtc::Transport { const rtc::scoped_ptr<webrtc::CriticalSectionWrapper> pq_crit_; const rtc::scoped_ptr<webrtc::CriticalSectionWrapper> stream_crit_; const rtc::scoped_ptr<webrtc::EventWrapper> packet_event_; - const rtc::scoped_ptr<webrtc::ThreadWrapper> thread_; + rtc::PlatformThread thread_; unsigned int rtt_ms_; unsigned int stream_count_; diff --git a/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h b/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h index 1a1075c585..116ff0aec3 100644 --- a/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h +++ b/webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h @@ -13,6 +13,7 @@ #include <deque> +#include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/common_types.h" #include "webrtc/modules/rtp_rtcp/source/byte_io.h" @@ -20,7 +21,6 @@ #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/system_wrappers/include/thread_wrapper.h" #include "webrtc/voice_engine/test/auto_test/fixtures/before_initialization_fixture.h" class TestErrorObserver; @@ -30,16 +30,14 @@ class LoopBackTransport : public webrtc::Transport { LoopBackTransport(webrtc::VoENetwork* voe_network, int channel) : crit_(webrtc::CriticalSectionWrapper::CreateCriticalSection()), packet_event_(webrtc::EventWrapper::Create()), - thread_(webrtc::ThreadWrapper::CreateThread(NetworkProcess, - this, - "LoopBackTransport")), + thread_(NetworkProcess, this, "LoopBackTransport"), channel_(channel), voe_network_(voe_network), transmitted_packets_(0) { - thread_->Start(); + thread_.Start(); } - ~LoopBackTransport() { thread_->Stop(); } + ~LoopBackTransport() { thread_.Stop(); } bool SendRtp(const uint8_t* data, size_t len, @@ -147,7 +145,7 @@ class LoopBackTransport : public webrtc::Transport { const rtc::scoped_ptr<webrtc::CriticalSectionWrapper> crit_; const rtc::scoped_ptr<webrtc::EventWrapper> packet_event_; - const rtc::scoped_ptr<webrtc::ThreadWrapper> thread_; + rtc::PlatformThread thread_; std::deque<Packet> packet_queue_ GUARDED_BY(crit_.get()); const int channel_; std::map<uint32_t, int> channels_ GUARDED_BY(crit_.get()); diff --git a/webrtc/voice_engine/test/auto_test/fixtures/before_initialization_fixture.h b/webrtc/voice_engine/test/auto_test/fixtures/before_initialization_fixture.h index 7a3fad8399..51db985b4a 100644 --- a/webrtc/voice_engine/test/auto_test/fixtures/before_initialization_fixture.h +++ b/webrtc/voice_engine/test/auto_test/fixtures/before_initialization_fixture.h @@ -16,7 +16,6 @@ #include "webrtc/common.h" #include "webrtc/common_types.h" #include "webrtc/engine_configurations.h" -#include "webrtc/test/testsupport/gtest_disable.h" #include "webrtc/voice_engine/include/voe_audio_processing.h" #include "webrtc/voice_engine/include/voe_base.h" #include "webrtc/voice_engine/include/voe_codec.h" diff --git a/webrtc/voice_engine/test/auto_test/standard/codec_test.cc b/webrtc/voice_engine/test/auto_test/standard/codec_test.cc index eeb12aba04..3a3d83031d 100644 --- a/webrtc/voice_engine/test/auto_test/standard/codec_test.cc +++ b/webrtc/voice_engine/test/auto_test/standard/codec_test.cc @@ -50,7 +50,7 @@ static bool IsNotViableSendCodec(const char* codec_name) { TEST_F(CodecTest, PcmuIsDefaultCodecAndHasTheRightValues) { EXPECT_EQ(0, voe_codec_->GetSendCodec(channel_, codec_instance_)); - EXPECT_EQ(1, codec_instance_.channels); + EXPECT_EQ(1u, codec_instance_.channels); EXPECT_EQ(160, codec_instance_.pacsize); EXPECT_EQ(8000, codec_instance_.plfreq); EXPECT_EQ(0, codec_instance_.pltype); @@ -153,17 +153,6 @@ TEST_F(CodecTest, OpusMaxPlaybackRateCanBeSet) { } } -TEST_F(CodecTest, OpusMaxPlaybackRateCannotBeSetForNonOpus) { - for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) { - voe_codec_->GetCodec(i, codec_instance_); - if (!_stricmp("opus", codec_instance_.plname)) { - continue; - } - voe_codec_->SetSendCodec(channel_, codec_instance_); - EXPECT_EQ(-1, voe_codec_->SetOpusMaxPlaybackRate(channel_, 16000)); - } -} - TEST_F(CodecTest, OpusDtxCanBeSetForOpus) { for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) { voe_codec_->GetCodec(i, codec_instance_); @@ -183,7 +172,6 @@ TEST_F(CodecTest, OpusDtxCannotBeSetForNonOpus) { continue; } voe_codec_->SetSendCodec(channel_, codec_instance_); - EXPECT_EQ(-1, voe_codec_->SetOpusDtx(channel_, false)); EXPECT_EQ(-1, voe_codec_->SetOpusDtx(channel_, true)); } } diff --git a/webrtc/voice_engine/test/auto_test/standard/external_media_test.cc b/webrtc/voice_engine/test/auto_test/standard/external_media_test.cc index b4daba5afd..4f86010a18 100644 --- a/webrtc/voice_engine/test/auto_test/standard/external_media_test.cc +++ b/webrtc/voice_engine/test/auto_test/standard/external_media_test.cc @@ -9,7 +9,7 @@ */ #include "webrtc/base/arraysize.h" -#include "webrtc/modules/interface/module_common_types.h" +#include "webrtc/modules/include/module_common_types.h" #include "webrtc/voice_engine/include/voe_external_media.h" #include "webrtc/voice_engine/test/auto_test/fakes/fake_media_process.h" #include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h" diff --git a/webrtc/voice_engine/test/auto_test/standard/rtp_rtcp_extensions.cc b/webrtc/voice_engine/test/auto_test/standard/rtp_rtcp_extensions.cc index 780a7f7ba9..1dc15dff49 100644 --- a/webrtc/voice_engine/test/auto_test/standard/rtp_rtcp_extensions.cc +++ b/webrtc/voice_engine/test/auto_test/standard/rtp_rtcp_extensions.cc @@ -8,8 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include "webrtc/modules/interface/module_common_types.h" -#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" +#include "webrtc/modules/include/module_common_types.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" #include "webrtc/system_wrappers/include/atomic32.h" #include "webrtc/system_wrappers/include/sleep.h" #include "webrtc/voice_engine/test/auto_test/fixtures/before_streaming_fixture.h" diff --git a/webrtc/voice_engine/test/auto_test/standard/rtp_rtcp_test.cc b/webrtc/voice_engine/test/auto_test/standard/rtp_rtcp_test.cc index 14dca27d1c..6efa55d516 100644 --- a/webrtc/voice_engine/test/auto_test/standard/rtp_rtcp_test.cc +++ b/webrtc/voice_engine/test/auto_test/standard/rtp_rtcp_test.cc @@ -101,8 +101,7 @@ TEST_F(RtpRtcpTest, RemoteRtcpCnameHasPropagatedToRemoteSide) { EXPECT_STREQ(RTCP_CNAME, char_buffer); } -// Flakily hangs on Linux. code.google.com/p/webrtc/issues/detail?id=2178. -TEST_F(RtpRtcpTest, DISABLED_ON_LINUX(SSRCPropagatesCorrectly)) { +TEST_F(RtpRtcpTest, SSRCPropagatesCorrectly) { unsigned int local_ssrc = 1234; EXPECT_EQ(0, voe_base_->StopSend(channel_)); EXPECT_EQ(0, voe_rtp_rtcp_->SetLocalSSRC(channel_, local_ssrc)); diff --git a/webrtc/voice_engine/test/auto_test/voe_cpu_test.cc b/webrtc/voice_engine/test/auto_test/voe_cpu_test.cc index ad6116dcdd..5666b3f8d1 100644 --- a/webrtc/voice_engine/test/auto_test/voe_cpu_test.cc +++ b/webrtc/voice_engine/test/auto_test/voe_cpu_test.cc @@ -18,7 +18,7 @@ #endif #include "webrtc/base/scoped_ptr.h" -#include "webrtc/test/channel_transport/include/channel_transport.h" +#include "webrtc/test/channel_transport/channel_transport.h" #include "webrtc/voice_engine/test/auto_test/voe_test_defines.h" using namespace webrtc; diff --git a/webrtc/voice_engine/test/auto_test/voe_output_test.cc b/webrtc/voice_engine/test/auto_test/voe_output_test.cc new file mode 100644 index 0000000000..3bedbc3b17 --- /dev/null +++ b/webrtc/voice_engine/test/auto_test/voe_output_test.cc @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/random.h" +#include "webrtc/base/scoped_ptr.h" +#include "webrtc/base/timeutils.h" +#include "webrtc/system_wrappers/include/sleep.h" +#include "webrtc/test/channel_transport/channel_transport.h" +#include "webrtc/test/testsupport/fileutils.h" +#include "webrtc/voice_engine/test/auto_test/voe_standard_test.h" + +namespace { + +const char kIp[] = "127.0.0.1"; +const int kPort = 1234; +const webrtc::CodecInst kCodecInst = {120, "opus", 48000, 960, 2, 64000}; + +} // namespace + +namespace voetest { + +using webrtc::Random; +using webrtc::test::VoiceChannelTransport; + +// This test allows a check on the output signal in an end-to-end call. +class OutputTest { + public: + OutputTest(int16_t lower_bound, int16_t upper_bound); + ~OutputTest(); + + void Start(); + + void EnableOutputCheck(); + void DisableOutputCheck(); + void SetOutputBound(int16_t lower_bound, int16_t upper_bound); + void Mute(); + void Unmute(); + void SetBitRate(int rate); + + private: + // This class checks all output values and count the number of samples that + // go out of a defined range. + class VoEOutputCheckMediaProcess : public VoEMediaProcess { + public: + VoEOutputCheckMediaProcess(int16_t lower_bound, int16_t upper_bound); + + void set_enabled(bool enabled) { enabled_ = enabled; } + void Process(int channel, + ProcessingTypes type, + int16_t audio10ms[], + size_t length, + int samplingFreq, + bool isStereo) override; + + private: + bool enabled_; + int16_t lower_bound_; + int16_t upper_bound_; + }; + + VoETestManager manager_; + VoEOutputCheckMediaProcess output_checker_; + + int channel_; +}; + +OutputTest::OutputTest(int16_t lower_bound, int16_t upper_bound) + : output_checker_(lower_bound, upper_bound) { + EXPECT_TRUE(manager_.Init()); + manager_.GetInterfaces(); + + VoEBase* base = manager_.BasePtr(); + VoECodec* codec = manager_.CodecPtr(); + VoENetwork* network = manager_.NetworkPtr(); + + EXPECT_EQ(0, base->Init()); + + channel_ = base->CreateChannel(); + + // |network| will take care of the life time of |transport|. + VoiceChannelTransport* transport = + new VoiceChannelTransport(network, channel_); + + EXPECT_EQ(0, transport->SetSendDestination(kIp, kPort)); + EXPECT_EQ(0, transport->SetLocalReceiver(kPort)); + + EXPECT_EQ(0, codec->SetSendCodec(channel_, kCodecInst)); + EXPECT_EQ(0, codec->SetOpusDtx(channel_, true)); + + EXPECT_EQ(0, manager_.VolumeControlPtr()->SetSpeakerVolume(255)); + + manager_.ExternalMediaPtr()->RegisterExternalMediaProcessing( + channel_, ProcessingTypes::kPlaybackPerChannel, output_checker_); +} + +OutputTest::~OutputTest() { + EXPECT_EQ(0, manager_.NetworkPtr()->DeRegisterExternalTransport(channel_)); + EXPECT_EQ(0, manager_.ReleaseInterfaces()); +} + +void OutputTest::Start() { + const std::string file_name = + webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"); + const webrtc::FileFormats kInputFormat = webrtc::kFileFormatPcm32kHzFile; + + ASSERT_EQ(0, manager_.FilePtr()->StartPlayingFileAsMicrophone( + channel_, file_name.c_str(), true, false, kInputFormat, 1.0)); + + VoEBase* base = manager_.BasePtr(); + ASSERT_EQ(0, base->StartPlayout(channel_)); + ASSERT_EQ(0, base->StartSend(channel_)); +} + +void OutputTest::EnableOutputCheck() { + output_checker_.set_enabled(true); +} + +void OutputTest::DisableOutputCheck() { + output_checker_.set_enabled(false); +} + +void OutputTest::Mute() { + manager_.VolumeControlPtr()->SetInputMute(channel_, true); +} + +void OutputTest::Unmute() { + manager_.VolumeControlPtr()->SetInputMute(channel_, false); +} + +void OutputTest::SetBitRate(int rate) { + manager_.CodecPtr()->SetBitRate(channel_, rate); +} + +OutputTest::VoEOutputCheckMediaProcess::VoEOutputCheckMediaProcess( + int16_t lower_bound, int16_t upper_bound) + : enabled_(false), + lower_bound_(lower_bound), + upper_bound_(upper_bound) {} + +void OutputTest::VoEOutputCheckMediaProcess::Process(int channel, + ProcessingTypes type, + int16_t* audio10ms, + size_t length, + int samplingFreq, + bool isStereo) { + if (!enabled_) + return; + const int num_channels = isStereo ? 2 : 1; + for (size_t i = 0; i < length; ++i) { + for (int c = 0; c < num_channels; ++c) { + ASSERT_GE(audio10ms[i * num_channels + c], lower_bound_); + ASSERT_LE(audio10ms[i * num_channels + c], upper_bound_); + } + } +} + +// This test checks if the Opus does not produce high noise (noise pump) when +// DTX is enabled. The microphone is toggled on and off, and values of the +// output signal during muting should be bounded. +// We do not run this test on bots. Developers that want to see the result +// and/or listen to sound quality can run this test manually. +TEST(OutputTest, DISABLED_OpusDtxHasNoNoisePump) { + const int kRuntimeMs = 20000; + const uint32_t kUnmuteTimeMs = 1000; + const int kCheckAfterMute = 2000; + const uint32_t kCheckTimeMs = 2000; + const int kMinOpusRate = 6000; + const int kMaxOpusRate = 64000; + +#if defined(OPUS_FIXED_POINT) + const int16_t kDtxBoundForSilence = 20; +#else + const int16_t kDtxBoundForSilence = 2; +#endif + + OutputTest test(-kDtxBoundForSilence, kDtxBoundForSilence); + Random random(1234ull); + + uint32_t start_time = rtc::Time(); + test.Start(); + while (rtc::TimeSince(start_time) < kRuntimeMs) { + webrtc::SleepMs(random.Rand(kUnmuteTimeMs - kUnmuteTimeMs / 10, + kUnmuteTimeMs + kUnmuteTimeMs / 10)); + test.Mute(); + webrtc::SleepMs(kCheckAfterMute); + test.EnableOutputCheck(); + webrtc::SleepMs(random.Rand(kCheckTimeMs - kCheckTimeMs / 10, + kCheckTimeMs + kCheckTimeMs / 10)); + test.DisableOutputCheck(); + test.SetBitRate(random.Rand(kMinOpusRate, kMaxOpusRate)); + test.Unmute(); + } +} + +} // namespace voetest diff --git a/webrtc/voice_engine/test/auto_test/voe_standard_test.cc b/webrtc/voice_engine/test/auto_test/voe_standard_test.cc index 22eee15bf0..a187c4bb6c 100644 --- a/webrtc/voice_engine/test/auto_test/voe_standard_test.cc +++ b/webrtc/voice_engine/test/auto_test/voe_standard_test.cc @@ -117,14 +117,6 @@ bool VoETestManager::Init() { if (initialized_) return true; - if (VoiceEngine::SetTraceFile(NULL) != -1) { - // should not be possible to call a Trace method before the VoE is - // created - TEST_LOG("\nError at line: %i (VoiceEngine::SetTraceFile()" - "should fail)!\n", __LINE__); - return false; - } - voice_engine_ = VoiceEngine::Create(); if (!voice_engine_) { TEST_LOG("Failed to create VoiceEngine\n"); @@ -230,11 +222,6 @@ int VoETestManager::ReleaseInterfaces() { releaseOK = false; } - if (VoiceEngine::SetTraceFile(NULL) != -1) { - TEST_LOG("\nError at line: %i (VoiceEngine::SetTraceFile()" - "should fail)!\n", __LINE__); - } - return (releaseOK == true) ? 0 : -1; } diff --git a/webrtc/voice_engine/test/auto_test/voe_standard_test.h b/webrtc/voice_engine/test/auto_test/voe_standard_test.h index 3bf89362d5..b92595982c 100644 --- a/webrtc/voice_engine/test/auto_test/voe_standard_test.h +++ b/webrtc/voice_engine/test/auto_test/voe_standard_test.h @@ -44,7 +44,6 @@ #ifdef WEBRTC_VOICE_ENGINE_NETEQ_STATS_API namespace webrtc { class CriticalSectionWrapper; -class ThreadWrapper; class VoENetEqStats; } #endif diff --git a/webrtc/voice_engine/test/auto_test/voe_stress_test.cc b/webrtc/voice_engine/test/auto_test/voe_stress_test.cc index 960276b699..259eff0ccc 100644 --- a/webrtc/voice_engine/test/auto_test/voe_stress_test.cc +++ b/webrtc/voice_engine/test/auto_test/voe_stress_test.cc @@ -26,7 +26,7 @@ #include "webrtc/base/scoped_ptr.h" #include "webrtc/system_wrappers/include/sleep.h" -#include "webrtc/test/channel_transport/include/channel_transport.h" +#include "webrtc/test/channel_transport/channel_transport.h" #include "webrtc/voice_engine/test/auto_test/voe_standard_test.h" #include "webrtc/voice_engine/test/auto_test/voe_test_defines.h" #include "webrtc/voice_engine/voice_engine_defines.h" // defines build macros @@ -334,9 +334,9 @@ int VoEStressTest::MultipleThreadsTest() { int rnd(0); // Start extra thread - _ptrExtraApiThread = ThreadWrapper::CreateThread(RunExtraApi, this, - "StressTestExtraApiThread"); - VALIDATE_STRESS(!_ptrExtraApiThread->Start()); + _ptrExtraApiThread.reset( + new rtc::PlatformThread(RunExtraApi, this, "StressTestExtraApiThread")); + _ptrExtraApiThread->Start(); // Some possible extensions include: // Add more API calls to randomize @@ -365,7 +365,7 @@ int VoEStressTest::MultipleThreadsTest() { ANL(); // Stop extra thread - VALIDATE_STRESS(!_ptrExtraApiThread->Stop()); + _ptrExtraApiThread->Stop(); ///////////// End test ///////////// diff --git a/webrtc/voice_engine/test/auto_test/voe_stress_test.h b/webrtc/voice_engine/test/auto_test/voe_stress_test.h index 69b3a92bb3..715e8ef724 100644 --- a/webrtc/voice_engine/test/auto_test/voe_stress_test.h +++ b/webrtc/voice_engine/test/auto_test/voe_stress_test.h @@ -11,11 +11,10 @@ #ifndef WEBRTC_VOICE_ENGINE_VOE_STRESS_TEST_H #define WEBRTC_VOICE_ENGINE_VOE_STRESS_TEST_H -#include "webrtc/system_wrappers/include/thread_wrapper.h" +#include "webrtc/base/platform_thread.h" +#include "webrtc/base/scoped_ptr.h" namespace voetest { -// TODO(andrew): using directives are not permitted. -using namespace webrtc; class VoETestManager; @@ -38,7 +37,8 @@ class VoEStressTest { VoETestManager& _mgr; - rtc::scoped_ptr<ThreadWrapper> _ptrExtraApiThread; + // TODO(pbos): Remove scoped_ptr and use PlatformThread directly. + rtc::scoped_ptr<rtc::PlatformThread> _ptrExtraApiThread; }; } // namespace voetest diff --git a/webrtc/voice_engine/test/cmd_test/voe_cmd_test.cc b/webrtc/voice_engine/test/cmd_test/voe_cmd_test.cc index 312ac7ca31..ccfe3c2bde 100644 --- a/webrtc/voice_engine/test/cmd_test/voe_cmd_test.cc +++ b/webrtc/voice_engine/test/cmd_test/voe_cmd_test.cc @@ -19,11 +19,12 @@ #include "gflags/gflags.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/format_macros.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/call/rtc_event_log.h" #include "webrtc/engine_configurations.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" -#include "webrtc/test/channel_transport/include/channel_transport.h" +#include "webrtc/test/channel_transport/channel_transport.h" #include "webrtc/test/testsupport/fileutils.h" #include "webrtc/test/testsupport/trace_to_stderr.h" #include "webrtc/voice_engine/include/voe_audio_processing.h" @@ -113,8 +114,8 @@ void PrintCodecs(bool opus_stereo) { int res = codec->GetCodec(i, codec_params); VALIDATE; SetStereoIfOpus(opus_stereo, &codec_params); - printf("%2d. %3d %s/%d/%d \n", i, codec_params.pltype, codec_params.plname, - codec_params.plfreq, codec_params.channels); + printf("%2d. %3d %s/%d/%" PRIuS " \n", i, codec_params.pltype, + codec_params.plname, codec_params.plfreq, codec_params.channels); } } diff --git a/webrtc/voice_engine/transmit_mixer.cc b/webrtc/voice_engine/transmit_mixer.cc index 94592cf616..1204b04b50 100644 --- a/webrtc/voice_engine/transmit_mixer.cc +++ b/webrtc/voice_engine/transmit_mixer.cc @@ -11,10 +11,10 @@ #include "webrtc/voice_engine/transmit_mixer.h" #include "webrtc/base/format_macros.h" -#include "webrtc/modules/utility/interface/audio_frame_operations.h" +#include "webrtc/base/logging.h" +#include "webrtc/modules/utility/include/audio_frame_operations.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/event_wrapper.h" -#include "webrtc/system_wrappers/include/logging.h" #include "webrtc/system_wrappers/include/trace.h" #include "webrtc/voice_engine/channel.h" #include "webrtc/voice_engine/channel_manager.h" @@ -23,8 +23,6 @@ #include "webrtc/voice_engine/utility.h" #include "webrtc/voice_engine/voe_base_impl.h" -#define WEBRTC_ABS(a) (((a) < 0) ? -(a) : (a)) - namespace webrtc { namespace voe { @@ -36,12 +34,20 @@ TransmitMixer::OnPeriodicProcess() "TransmitMixer::OnPeriodicProcess()"); #if defined(WEBRTC_VOICE_ENGINE_TYPING_DETECTION) - if (_typingNoiseWarningPending) + bool send_typing_noise_warning = false; + bool typing_noise_detected = false; { + CriticalSectionScoped cs(&_critSect); + if (_typingNoiseWarningPending) { + send_typing_noise_warning = true; + typing_noise_detected = _typingNoiseDetected; + _typingNoiseWarningPending = false; + } + } + if (send_typing_noise_warning) { CriticalSectionScoped cs(&_callbackCritSect); - if (_voiceEngineObserverPtr) - { - if (_typingNoiseDetected) { + if (_voiceEngineObserverPtr) { + if (typing_noise_detected) { WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), "TransmitMixer::OnPeriodicProcess() => " "CallbackOnError(VE_TYPING_NOISE_WARNING)"); @@ -57,7 +63,6 @@ TransmitMixer::OnPeriodicProcess() VE_TYPING_NOISE_OFF_WARNING); } } - _typingNoiseWarningPending = false; } #endif @@ -295,7 +300,8 @@ TransmitMixer::SetAudioProcessingModule(AudioProcessing* audioProcessingModule) return 0; } -void TransmitMixer::GetSendCodecInfo(int* max_sample_rate, int* max_channels) { +void TransmitMixer::GetSendCodecInfo(int* max_sample_rate, + size_t* max_channels) { *max_sample_rate = 8000; *max_channels = 1; for (ChannelManager::Iterator it(_channelManagerPtr); it.IsValid(); @@ -313,7 +319,7 @@ void TransmitMixer::GetSendCodecInfo(int* max_sample_rate, int* max_channels) { int32_t TransmitMixer::PrepareDemux(const void* audioSamples, size_t nSamples, - uint8_t nChannels, + size_t nChannels, uint32_t samplesPerSec, uint16_t totalDelayMS, int32_t clockDrift, @@ -322,7 +328,7 @@ TransmitMixer::PrepareDemux(const void* audioSamples, { WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), "TransmitMixer::PrepareDemux(nSamples=%" PRIuS ", " - "nChannels=%u, samplesPerSec=%u, totalDelayMS=%u, " + "nChannels=%" PRIuS ", samplesPerSec=%u, totalDelayMS=%u, " "clockDrift=%d, currentMicLevel=%u)", nSamples, nChannels, samplesPerSec, totalDelayMS, clockDrift, currentMicLevel); @@ -427,8 +433,8 @@ TransmitMixer::DemuxAndMix() } void TransmitMixer::DemuxAndMix(const int voe_channels[], - int number_of_voe_channels) { - for (int i = 0; i < number_of_voe_channels; ++i) { + size_t number_of_voe_channels) { + for (size_t i = 0; i < number_of_voe_channels; ++i) { voe::ChannelOwner ch = _channelManagerPtr->GetChannel(voe_channels[i]); voe::Channel* channel_ptr = ch.channel(); if (channel_ptr) { @@ -460,8 +466,8 @@ TransmitMixer::EncodeAndSend() } void TransmitMixer::EncodeAndSend(const int voe_channels[], - int number_of_voe_channels) { - for (int i = 0; i < number_of_voe_channels; ++i) { + size_t number_of_voe_channels) { + for (size_t i = 0; i < number_of_voe_channels; ++i) { voe::ChannelOwner ch = _channelManagerPtr->GetChannel(voe_channels[i]); voe::Channel* channel_ptr = ch.channel(); if (channel_ptr && channel_ptr->Sending()) @@ -693,8 +699,7 @@ int TransmitMixer::StartRecordingMicrophone(const char* fileName, const uint32_t notificationTime(0); // Not supported in VoE CodecInst dummyCodec = { 100, "L16", 16000, 320, 1, 320000 }; - if (codecInst != NULL && - (codecInst->channels < 0 || codecInst->channels > 2)) + if (codecInst != NULL && codecInst->channels > 2) { _engineStatisticsPtr->SetLastError( VE_BAD_ARGUMENT, kTraceError, @@ -1128,10 +1133,10 @@ bool TransmitMixer::IsRecordingMic() void TransmitMixer::GenerateAudioFrame(const int16_t* audio, size_t samples_per_channel, - int num_channels, + size_t num_channels, int sample_rate_hz) { int codec_rate; - int num_codec_channels; + size_t num_codec_channels; GetSendCodecInfo(&codec_rate, &num_codec_channels); stereo_codec_ = num_codec_channels == 2; @@ -1236,15 +1241,13 @@ int32_t TransmitMixer::MixOrReplaceAudioWithFile( void TransmitMixer::ProcessAudio(int delay_ms, int clock_drift, int current_mic_level, bool key_pressed) { if (audioproc_->set_stream_delay_ms(delay_ms) != 0) { - // A redundant warning is reported in AudioDevice, which we've throttled - // to avoid flooding the logs. Relegate this one to LS_VERBOSE to avoid - // repeating the problem here. - LOG_FERR1(LS_VERBOSE, set_stream_delay_ms, delay_ms); + // Silently ignore this failure to avoid flooding the logs. } GainControl* agc = audioproc_->gain_control(); if (agc->set_stream_analog_level(current_mic_level) != 0) { - LOG_FERR1(LS_ERROR, set_stream_analog_level, current_mic_level); + LOG(LS_ERROR) << "set_stream_analog_level failed: current_mic_level = " + << current_mic_level; assert(false); } @@ -1279,9 +1282,11 @@ void TransmitMixer::TypingDetection(bool keyPressed) bool vadActive = _audioFrame.vad_activity_ == AudioFrame::kVadActive; if (_typingDetection.Process(keyPressed, vadActive)) { + CriticalSectionScoped cs(&_critSect); _typingNoiseWarningPending = true; _typingNoiseDetected = true; } else { + CriticalSectionScoped cs(&_critSect); // If there is already a warning pending, do not change the state. // Otherwise set a warning pending if last callback was for noise detected. if (!_typingNoiseWarningPending && _typingNoiseDetected) { diff --git a/webrtc/voice_engine/transmit_mixer.h b/webrtc/voice_engine/transmit_mixer.h index 714efb48dc..0aee106231 100644 --- a/webrtc/voice_engine/transmit_mixer.h +++ b/webrtc/voice_engine/transmit_mixer.h @@ -15,9 +15,9 @@ #include "webrtc/common_audio/resampler/include/push_resampler.h" #include "webrtc/common_types.h" #include "webrtc/modules/audio_processing/typing_detection.h" -#include "webrtc/modules/interface/module_common_types.h" -#include "webrtc/modules/utility/interface/file_player.h" -#include "webrtc/modules/utility/interface/file_recorder.h" +#include "webrtc/modules/include/module_common_types.h" +#include "webrtc/modules/utility/include/file_player.h" +#include "webrtc/modules/utility/include/file_recorder.h" #include "webrtc/voice_engine/include/voe_base.h" #include "webrtc/voice_engine/level_indicator.h" #include "webrtc/voice_engine/monitor_module.h" @@ -52,7 +52,7 @@ public: int32_t PrepareDemux(const void* audioSamples, size_t nSamples, - uint8_t nChannels, + size_t nChannels, uint32_t samplesPerSec, uint16_t totalDelayMS, int32_t clockDrift, @@ -63,12 +63,12 @@ public: int32_t DemuxAndMix(); // Used by the Chrome to pass the recording data to the specific VoE // channels for demux. - void DemuxAndMix(const int voe_channels[], int number_of_voe_channels); + void DemuxAndMix(const int voe_channels[], size_t number_of_voe_channels); int32_t EncodeAndSend(); // Used by the Chrome to pass the recording data to the specific VoE // channels for encoding and sending to the network. - void EncodeAndSend(const int voe_channels[], int number_of_voe_channels); + void EncodeAndSend(const int voe_channels[], size_t number_of_voe_channels); // Must be called on the same thread as PrepareDemux(). uint32_t CaptureLevel() const; @@ -170,11 +170,11 @@ private: // Gets the maximum sample rate and number of channels over all currently // sending codecs. - void GetSendCodecInfo(int* max_sample_rate, int* max_channels); + void GetSendCodecInfo(int* max_sample_rate, size_t* max_channels); void GenerateAudioFrame(const int16_t audioSamples[], size_t nSamples, - int nChannels, + size_t nChannels, int samplesPerSec); int32_t RecordAudioToFile(uint32_t mixingFrequency); diff --git a/webrtc/voice_engine/utility.cc b/webrtc/voice_engine/utility.cc index 7bc7e0e963..605e55369e 100644 --- a/webrtc/voice_engine/utility.cc +++ b/webrtc/voice_engine/utility.cc @@ -10,12 +10,12 @@ #include "webrtc/voice_engine/utility.h" +#include "webrtc/base/logging.h" #include "webrtc/common_audio/resampler/include/push_resampler.h" #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" #include "webrtc/common_types.h" -#include "webrtc/modules/interface/module_common_types.h" -#include "webrtc/modules/utility/interface/audio_frame_operations.h" -#include "webrtc/system_wrappers/include/logging.h" +#include "webrtc/modules/include/module_common_types.h" +#include "webrtc/modules/utility/include/audio_frame_operations.h" #include "webrtc/voice_engine/voice_engine_defines.h" namespace webrtc { @@ -34,12 +34,12 @@ void RemixAndResample(const AudioFrame& src_frame, void RemixAndResample(const int16_t* src_data, size_t samples_per_channel, - int num_channels, + size_t num_channels, int sample_rate_hz, PushResampler<int16_t>* resampler, AudioFrame* dst_frame) { const int16_t* audio_ptr = src_data; - int audio_ptr_num_channels = num_channels; + size_t audio_ptr_num_channels = num_channels; int16_t mono_audio[AudioFrame::kMaxDataSizeSamples]; // Downmix before resampling. @@ -52,8 +52,10 @@ void RemixAndResample(const int16_t* src_data, if (resampler->InitializeIfNeeded(sample_rate_hz, dst_frame->sample_rate_hz_, audio_ptr_num_channels) == -1) { - LOG_FERR3(LS_ERROR, InitializeIfNeeded, sample_rate_hz, - dst_frame->sample_rate_hz_, audio_ptr_num_channels); + LOG(LS_ERROR) << "InitializeIfNeeded failed: sample_rate_hz = " + << sample_rate_hz << ", dst_frame->sample_rate_hz_ = " + << dst_frame->sample_rate_hz_ + << ", audio_ptr_num_channels = " << audio_ptr_num_channels; assert(false); } @@ -61,11 +63,12 @@ void RemixAndResample(const int16_t* src_data, int out_length = resampler->Resample(audio_ptr, src_length, dst_frame->data_, AudioFrame::kMaxDataSizeSamples); if (out_length == -1) { - LOG_FERR3(LS_ERROR, Resample, audio_ptr, src_length, dst_frame->data_); + LOG(LS_ERROR) << "Resample failed: audio_ptr = " << audio_ptr + << ", src_length = " << src_length + << ", dst_frame->data_ = " << dst_frame->data_; assert(false); } - dst_frame->samples_per_channel_ = - static_cast<size_t>(out_length / audio_ptr_num_channels); + dst_frame->samples_per_channel_ = out_length / audio_ptr_num_channels; // Upmix after resampling. if (num_channels == 1 && dst_frame->num_channels_ == 2) { @@ -77,9 +80,9 @@ void RemixAndResample(const int16_t* src_data, } void MixWithSat(int16_t target[], - int target_channel, + size_t target_channel, const int16_t source[], - int source_channel, + size_t source_channel, size_t source_len) { assert(target_channel == 1 || target_channel == 2); assert(source_channel == 1 || source_channel == 2); diff --git a/webrtc/voice_engine/utility.h b/webrtc/voice_engine/utility.h index cc44533665..4139f05cfd 100644 --- a/webrtc/voice_engine/utility.h +++ b/webrtc/voice_engine/utility.h @@ -40,15 +40,15 @@ void RemixAndResample(const AudioFrame& src_frame, // parameters. void RemixAndResample(const int16_t* src_data, size_t samples_per_channel, - int num_channels, + size_t num_channels, int sample_rate_hz, PushResampler<int16_t>* resampler, AudioFrame* dst_frame); void MixWithSat(int16_t target[], - int target_channel, + size_t target_channel, const int16_t source[], - int source_channel, + size_t source_channel, size_t source_len); } // namespace voe diff --git a/webrtc/voice_engine/utility_unittest.cc b/webrtc/voice_engine/utility_unittest.cc index 226e38366d..921c3e5085 100644 --- a/webrtc/voice_engine/utility_unittest.cc +++ b/webrtc/voice_engine/utility_unittest.cc @@ -13,7 +13,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/format_macros.h" #include "webrtc/common_audio/resampler/include/push_resampler.h" -#include "webrtc/modules/interface/module_common_types.h" +#include "webrtc/modules/include/module_common_types.h" #include "webrtc/voice_engine/utility.h" #include "webrtc/voice_engine/voice_engine_defines.h" diff --git a/webrtc/voice_engine/voe_audio_processing_impl.cc b/webrtc/voice_engine/voe_audio_processing_impl.cc index 83f70fe68e..c95726339c 100644 --- a/webrtc/voice_engine/voe_audio_processing_impl.cc +++ b/webrtc/voice_engine/voe_audio_processing_impl.cc @@ -10,9 +10,9 @@ #include "webrtc/voice_engine/voe_audio_processing_impl.h" +#include "webrtc/base/logging.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/logging.h" #include "webrtc/system_wrappers/include/trace.h" #include "webrtc/voice_engine/channel.h" #include "webrtc/voice_engine/include/voe_errors.h" @@ -317,7 +317,6 @@ int VoEAudioProcessingImpl::GetAgcConfig(AgcConfig& config) { int VoEAudioProcessingImpl::SetRxNsStatus(int channel, bool enable, NsModes mode) { - LOG_API3(channel, enable, mode); #ifdef WEBRTC_VOICE_ENGINE_NR if (!_shared->statistics().Initialized()) { _shared->SetLastError(VE_NOT_INITED, kTraceError); @@ -469,7 +468,6 @@ bool VoEAudioProcessing::DriftCompensationSupported() { } int VoEAudioProcessingImpl::EnableDriftCompensation(bool enable) { - LOG_API1(enable); WEBRTC_VOICE_INIT_CHECK(); if (!DriftCompensationSupported()) { @@ -489,7 +487,6 @@ int VoEAudioProcessingImpl::EnableDriftCompensation(bool enable) { } bool VoEAudioProcessingImpl::DriftCompensationEnabled() { - LOG_API0(); WEBRTC_VOICE_INIT_CHECK_BOOL(); EchoCancellation* aec = _shared->audio_processing()->echo_cancellation(); @@ -1038,12 +1035,10 @@ int VoEAudioProcessingImpl::SetTypingDetectionParameters(int timeWindow, } void VoEAudioProcessingImpl::EnableStereoChannelSwapping(bool enable) { - LOG_API1(enable); _shared->transmit_mixer()->EnableStereoChannelSwapping(enable); } bool VoEAudioProcessingImpl::IsStereoChannelSwappingEnabled() { - LOG_API0(); return _shared->transmit_mixer()->IsStereoChannelSwappingEnabled(); } diff --git a/webrtc/voice_engine/voe_base_impl.cc b/webrtc/voice_engine/voe_base_impl.cc index 8ea3f6314a..3e5cfbb14b 100644 --- a/webrtc/voice_engine/voe_base_impl.cc +++ b/webrtc/voice_engine/voe_base_impl.cc @@ -11,14 +11,14 @@ #include "webrtc/voice_engine/voe_base_impl.h" #include "webrtc/base/format_macros.h" +#include "webrtc/base/logging.h" #include "webrtc/common.h" #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" -#include "webrtc/modules/audio_coding/main/include/audio_coding_module.h" +#include "webrtc/modules/audio_coding/include/audio_coding_module.h" #include "webrtc/modules/audio_device/audio_device_impl.h" #include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/file_wrapper.h" -#include "webrtc/system_wrappers/include/logging.h" #include "webrtc/voice_engine/channel.h" #include "webrtc/voice_engine/include/voe_errors.h" #include "webrtc/voice_engine/output_mixer.h" @@ -47,7 +47,7 @@ VoEBaseImpl::~VoEBaseImpl() { delete &callbackCritSect_; } -void VoEBaseImpl::OnErrorIsReported(ErrorCode error) { +void VoEBaseImpl::OnErrorIsReported(const ErrorCode error) { CriticalSectionScoped cs(&callbackCritSect_); int errCode = 0; if (error == AudioDeviceObserver::kRecordingError) { @@ -63,7 +63,7 @@ void VoEBaseImpl::OnErrorIsReported(ErrorCode error) { } } -void VoEBaseImpl::OnWarningIsReported(WarningCode warning) { +void VoEBaseImpl::OnWarningIsReported(const WarningCode warning) { CriticalSectionScoped cs(&callbackCritSect_); int warningCode = 0; if (warning == AudioDeviceObserver::kRecordingWarning) { @@ -79,34 +79,40 @@ void VoEBaseImpl::OnWarningIsReported(WarningCode warning) { } } -int32_t VoEBaseImpl::RecordedDataIsAvailable( - const void* audioSamples, size_t nSamples, size_t nBytesPerSample, - uint8_t nChannels, uint32_t samplesPerSec, uint32_t totalDelayMS, - int32_t clockDrift, uint32_t micLevel, bool keyPressed, - uint32_t& newMicLevel) { +int32_t VoEBaseImpl::RecordedDataIsAvailable(const void* audioSamples, + const size_t nSamples, + const size_t nBytesPerSample, + const size_t nChannels, + const uint32_t samplesPerSec, + const uint32_t totalDelayMS, + const int32_t clockDrift, + const uint32_t currentMicLevel, + const bool keyPressed, + uint32_t& newMicLevel) { newMicLevel = static_cast<uint32_t>(ProcessRecordedDataWithAPM( nullptr, 0, audioSamples, samplesPerSec, nChannels, nSamples, - totalDelayMS, clockDrift, micLevel, keyPressed)); + totalDelayMS, clockDrift, currentMicLevel, keyPressed)); return 0; } -int32_t VoEBaseImpl::NeedMorePlayData(size_t nSamples, - size_t nBytesPerSample, - uint8_t nChannels, uint32_t samplesPerSec, - void* audioSamples, size_t& nSamplesOut, +int32_t VoEBaseImpl::NeedMorePlayData(const size_t nSamples, + const size_t nBytesPerSample, + const size_t nChannels, + const uint32_t samplesPerSec, + void* audioSamples, + size_t& nSamplesOut, int64_t* elapsed_time_ms, int64_t* ntp_time_ms) { - GetPlayoutData(static_cast<int>(samplesPerSec), static_cast<int>(nChannels), - nSamples, true, audioSamples, - elapsed_time_ms, ntp_time_ms); + GetPlayoutData(static_cast<int>(samplesPerSec), nChannels, nSamples, true, + audioSamples, elapsed_time_ms, ntp_time_ms); nSamplesOut = audioFrame_.samples_per_channel_; return 0; } int VoEBaseImpl::OnDataAvailable(const int voe_channels[], - int number_of_voe_channels, + size_t number_of_voe_channels, const int16_t* audio_data, int sample_rate, - int number_of_channels, + size_t number_of_channels, size_t number_of_frames, int audio_delay_milliseconds, int volume, bool key_pressed, bool need_audio_processing) { @@ -121,7 +127,7 @@ int VoEBaseImpl::OnDataAvailable(const int voe_channels[], // No need to go through the APM, demultiplex the data to each VoE channel, // encode and send to the network. - for (int i = 0; i < number_of_voe_channels; ++i) { + for (size_t i = 0; i < number_of_voe_channels; ++i) { // TODO(ajm): In the case where multiple channels are using the same codec // rate, this path needlessly does extra conversions. We should convert once // and share between channels. @@ -135,14 +141,14 @@ int VoEBaseImpl::OnDataAvailable(const int voe_channels[], void VoEBaseImpl::OnData(int voe_channel, const void* audio_data, int bits_per_sample, int sample_rate, - int number_of_channels, size_t number_of_frames) { + size_t number_of_channels, size_t number_of_frames) { PushCaptureData(voe_channel, audio_data, bits_per_sample, sample_rate, number_of_channels, number_of_frames); } void VoEBaseImpl::PushCaptureData(int voe_channel, const void* audio_data, int bits_per_sample, int sample_rate, - int number_of_channels, + size_t number_of_channels, size_t number_of_frames) { voe::ChannelOwner ch = shared_->channel_manager().GetChannel(voe_channel); voe::Channel* channel_ptr = ch.channel(); @@ -158,7 +164,7 @@ void VoEBaseImpl::PushCaptureData(int voe_channel, const void* audio_data, void VoEBaseImpl::PullRenderData(int bits_per_sample, int sample_rate, - int number_of_channels, + size_t number_of_channels, size_t number_of_frames, void* audio_data, int64_t* elapsed_time_ms, int64_t* ntp_time_ms) { @@ -575,69 +581,19 @@ int VoEBaseImpl::StopSend(int channel) { } int VoEBaseImpl::GetVersion(char version[1024]) { - static_assert(kVoiceEngineVersionMaxMessageSize == 1024, ""); - if (version == nullptr) { shared_->SetLastError(VE_INVALID_ARGUMENT, kTraceError); - return (-1); - } - - char versionBuf[kVoiceEngineVersionMaxMessageSize]; - char* versionPtr = versionBuf; - - int32_t len = 0; - int32_t accLen = 0; - - len = AddVoEVersion(versionPtr); - if (len == -1) { return -1; } - versionPtr += len; - accLen += len; - assert(accLen < kVoiceEngineVersionMaxMessageSize); - -#ifdef WEBRTC_EXTERNAL_TRANSPORT - len = AddExternalTransportBuild(versionPtr); - if (len == -1) { - return -1; - } - versionPtr += len; - accLen += len; - assert(accLen < kVoiceEngineVersionMaxMessageSize); -#endif - - memcpy(version, versionBuf, accLen); - version[accLen] = '\0'; - - // to avoid the truncation in the trace, split the string into parts - char partOfVersion[256]; - for (int partStart = 0; partStart < accLen;) { - memset(partOfVersion, 0, sizeof(partOfVersion)); - int partEnd = partStart + 180; - while (version[partEnd] != '\n' && version[partEnd] != '\0') { - partEnd--; - } - if (partEnd < accLen) { - memcpy(partOfVersion, &version[partStart], partEnd - partStart); - } else { - memcpy(partOfVersion, &version[partStart], accLen - partStart); - } - partStart = partEnd; - } + std::string versionString = VoiceEngine::GetVersionString(); + RTC_DCHECK_GT(1024u, versionString.size() + 1); + char* end = std::copy(versionString.cbegin(), versionString.cend(), version); + end[0] = '\n'; + end[1] = '\0'; return 0; } -int32_t VoEBaseImpl::AddVoEVersion(char* str) const { - return sprintf(str, "VoiceEngine 4.1.0\n"); -} - -#ifdef WEBRTC_EXTERNAL_TRANSPORT -int32_t VoEBaseImpl::AddExternalTransportBuild(char* str) const { - return sprintf(str, "External transport build\n"); -} -#endif - int VoEBaseImpl::LastError() { return (shared_->statistics().LastError()); } int32_t VoEBaseImpl::StartPlayout() { @@ -742,8 +698,8 @@ int32_t VoEBaseImpl::TerminateInternal() { } int VoEBaseImpl::ProcessRecordedDataWithAPM( - const int voe_channels[], int number_of_voe_channels, - const void* audio_data, uint32_t sample_rate, uint8_t number_of_channels, + const int voe_channels[], size_t number_of_voe_channels, + const void* audio_data, uint32_t sample_rate, size_t number_of_channels, size_t number_of_frames, uint32_t audio_delay_milliseconds, int32_t clock_drift, uint32_t volume, bool key_pressed) { assert(shared_->transmit_mixer() != nullptr); @@ -808,7 +764,7 @@ int VoEBaseImpl::ProcessRecordedDataWithAPM( return 0; } -void VoEBaseImpl::GetPlayoutData(int sample_rate, int number_of_channels, +void VoEBaseImpl::GetPlayoutData(int sample_rate, size_t number_of_channels, size_t number_of_frames, bool feed_data_to_apm, void* audio_data, int64_t* elapsed_time_ms, int64_t* ntp_time_ms) { diff --git a/webrtc/voice_engine/voe_base_impl.h b/webrtc/voice_engine/voe_base_impl.h index f0ac959dcd..58e0387423 100644 --- a/webrtc/voice_engine/voe_base_impl.h +++ b/webrtc/voice_engine/voe_base_impl.h @@ -13,7 +13,7 @@ #include "webrtc/voice_engine/include/voe_base.h" -#include "webrtc/modules/interface/module_common_types.h" +#include "webrtc/modules/include/module_common_types.h" #include "webrtc/voice_engine/shared_data.h" namespace webrtc { @@ -54,37 +54,57 @@ class VoEBaseImpl : public VoEBase, int AssociateSendChannel(int channel, int accociate_send_channel) override; // AudioTransport - int32_t RecordedDataIsAvailable(const void* audioSamples, size_t nSamples, - size_t nBytesPerSample, uint8_t nChannels, - uint32_t samplesPerSec, uint32_t totalDelayMS, - int32_t clockDrift, uint32_t micLevel, - bool keyPressed, + int32_t RecordedDataIsAvailable(const void* audioSamples, + const size_t nSamples, + const size_t nBytesPerSample, + const size_t nChannels, + const uint32_t samplesPerSec, + const uint32_t totalDelayMS, + const int32_t clockDrift, + const uint32_t currentMicLevel, + const bool keyPressed, uint32_t& newMicLevel) override; - int32_t NeedMorePlayData(size_t nSamples, size_t nBytesPerSample, - uint8_t nChannels, uint32_t samplesPerSec, - void* audioSamples, size_t& nSamplesOut, + int32_t NeedMorePlayData(const size_t nSamples, + const size_t nBytesPerSample, + const size_t nChannels, + const uint32_t samplesPerSec, + void* audioSamples, + size_t& nSamplesOut, int64_t* elapsed_time_ms, int64_t* ntp_time_ms) override; - int OnDataAvailable(const int voe_channels[], int number_of_voe_channels, - const int16_t* audio_data, int sample_rate, - int number_of_channels, size_t number_of_frames, - int audio_delay_milliseconds, int volume, - bool key_pressed, bool need_audio_processing) override; - void OnData(int voe_channel, const void* audio_data, int bits_per_sample, - int sample_rate, int number_of_channels, + int OnDataAvailable(const int voe_channels[], + size_t number_of_voe_channels, + const int16_t* audio_data, + int sample_rate, + size_t number_of_channels, + size_t number_of_frames, + int audio_delay_milliseconds, + int current_volume, + bool key_pressed, + bool need_audio_processing) override; + void OnData(int voe_channel, + const void* audio_data, + int bits_per_sample, + int sample_rate, + size_t number_of_channels, size_t number_of_frames) override; - void PushCaptureData(int voe_channel, const void* audio_data, - int bits_per_sample, int sample_rate, - int number_of_channels, + void PushCaptureData(int voe_channel, + const void* audio_data, + int bits_per_sample, + int sample_rate, + size_t number_of_channels, size_t number_of_frames) override; - void PullRenderData(int bits_per_sample, int sample_rate, - int number_of_channels, size_t number_of_frames, - void* audio_data, int64_t* elapsed_time_ms, + void PullRenderData(int bits_per_sample, + int sample_rate, + size_t number_of_channels, + size_t number_of_frames, + void* audio_data, + int64_t* elapsed_time_ms, int64_t* ntp_time_ms) override; // AudioDeviceObserver - void OnErrorIsReported(ErrorCode error) override; - void OnWarningIsReported(WarningCode warning) override; + void OnErrorIsReported(const ErrorCode error) override; + void OnWarningIsReported(const WarningCode warning) override; protected: VoEBaseImpl(voe::SharedData* shared); @@ -104,24 +124,19 @@ class VoEBaseImpl : public VoEBase, // It returns new AGC microphone volume or 0 if no volume changes // should be done. int ProcessRecordedDataWithAPM( - const int voe_channels[], int number_of_voe_channels, - const void* audio_data, uint32_t sample_rate, uint8_t number_of_channels, + const int voe_channels[], size_t number_of_voe_channels, + const void* audio_data, uint32_t sample_rate, size_t number_of_channels, size_t number_of_frames, uint32_t audio_delay_milliseconds, int32_t clock_drift, uint32_t volume, bool key_pressed); - void GetPlayoutData(int sample_rate, int number_of_channels, + void GetPlayoutData(int sample_rate, size_t number_of_channels, size_t number_of_frames, bool feed_data_to_apm, void* audio_data, int64_t* elapsed_time_ms, int64_t* ntp_time_ms); - int32_t AddVoEVersion(char* str) const; - // Initialize channel by setting Engine Information then initializing // channel. int InitializeChannel(voe::ChannelOwner* channel_owner); -#ifdef WEBRTC_EXTERNAL_TRANSPORT - int32_t AddExternalTransportBuild(char* str) const; -#endif VoiceEngineObserver* voiceEngineObserverPtr_; CriticalSectionWrapper& callbackCritSect_; diff --git a/webrtc/voice_engine/voe_base_unittest.cc b/webrtc/voice_engine/voe_base_unittest.cc index 5c71784b4f..e53dee2eff 100644 --- a/webrtc/voice_engine/voe_base_unittest.cc +++ b/webrtc/voice_engine/voe_base_unittest.cc @@ -78,4 +78,10 @@ TEST_F(VoEBaseTest, AssociateSendChannel) { EXPECT_EQ(1, reference.use_count()); } +TEST_F(VoEBaseTest, GetVersion) { + char v1[1024] = {75}; + base_->GetVersion(v1); + std::string v2 = VoiceEngine::GetVersionString() + "\n"; + EXPECT_EQ(v2, v1); +} } // namespace webrtc diff --git a/webrtc/voice_engine/voe_codec_impl.cc b/webrtc/voice_engine/voe_codec_impl.cc index 2631372bbf..6eb11b759c 100644 --- a/webrtc/voice_engine/voe_codec_impl.cc +++ b/webrtc/voice_engine/voe_codec_impl.cc @@ -10,7 +10,8 @@ #include "webrtc/voice_engine/voe_codec_impl.h" -#include "webrtc/modules/audio_coding/main/include/audio_coding_module.h" +#include "webrtc/base/format_macros.h" +#include "webrtc/modules/audio_coding/include/audio_coding_module.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/trace.h" #include "webrtc/voice_engine/channel.h" @@ -51,25 +52,20 @@ int VoECodecImpl::NumOfCodecs() { } int VoECodecImpl::GetCodec(int index, CodecInst& codec) { - CodecInst acmCodec; - if (AudioCodingModule::Codec(index, &acmCodec) == -1) { + if (AudioCodingModule::Codec(index, &codec) == -1) { _shared->SetLastError(VE_INVALID_LISTNR, kTraceError, "GetCodec() invalid index"); return -1; } - ACMToExternalCodecRepresentation(codec, acmCodec); return 0; } int VoECodecImpl::SetSendCodec(int channel, const CodecInst& codec) { - CodecInst copyCodec; - ExternalToACMCodecRepresentation(copyCodec, codec); - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), "SetSendCodec(channel=%d, codec)", channel); WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), "codec: plname=%s, pacsize=%d, plfreq=%d, pltype=%d, " - "channels=%d, rate=%d", + "channels=%" PRIuS ", rate=%d", codec.plname, codec.pacsize, codec.plfreq, codec.pltype, codec.channels, codec.rate); if (!_shared->statistics().Initialized()) { @@ -77,20 +73,19 @@ int VoECodecImpl::SetSendCodec(int channel, const CodecInst& codec) { return -1; } // External sanity checks performed outside the ACM - if ((STR_CASE_CMP(copyCodec.plname, "L16") == 0) && - (copyCodec.pacsize >= 960)) { + if ((STR_CASE_CMP(codec.plname, "L16") == 0) && (codec.pacsize >= 960)) { _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, "SetSendCodec() invalid L16 packet size"); return -1; } - if (!STR_CASE_CMP(copyCodec.plname, "CN") || - !STR_CASE_CMP(copyCodec.plname, "TELEPHONE-EVENT") || - !STR_CASE_CMP(copyCodec.plname, "RED")) { + if (!STR_CASE_CMP(codec.plname, "CN") || + !STR_CASE_CMP(codec.plname, "TELEPHONE-EVENT") || + !STR_CASE_CMP(codec.plname, "RED")) { _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, "SetSendCodec() invalid codec name"); return -1; } - if ((copyCodec.channels != 1) && (copyCodec.channels != 2)) { + if ((codec.channels != 1) && (codec.channels != 2)) { _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, "SetSendCodec() invalid number of channels"); return -1; @@ -102,12 +97,12 @@ int VoECodecImpl::SetSendCodec(int channel, const CodecInst& codec) { "GetSendCodec() failed to locate channel"); return -1; } - if (!AudioCodingModule::IsCodecValid((CodecInst&)copyCodec)) { + if (!AudioCodingModule::IsCodecValid(codec)) { _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, "SetSendCodec() invalid codec"); return -1; } - if (channelPtr->SetSendCodec(copyCodec) != 0) { + if (channelPtr->SetSendCodec(codec) != 0) { _shared->SetLastError(VE_CANNOT_SET_SEND_CODEC, kTraceError, "SetSendCodec() failed to set send codec"); return -1; @@ -128,13 +123,11 @@ int VoECodecImpl::GetSendCodec(int channel, CodecInst& codec) { "GetSendCodec() failed to locate channel"); return -1; } - CodecInst acmCodec; - if (channelPtr->GetSendCodec(acmCodec) != 0) { + if (channelPtr->GetSendCodec(codec) != 0) { _shared->SetLastError(VE_CANNOT_GET_SEND_CODEC, kTraceError, "GetSendCodec() failed to get send codec"); return -1; } - ACMToExternalCodecRepresentation(codec, acmCodec); return 0; } @@ -162,19 +155,14 @@ int VoECodecImpl::GetRecCodec(int channel, CodecInst& codec) { "GetRecCodec() failed to locate channel"); return -1; } - CodecInst acmCodec; - if (channelPtr->GetRecCodec(acmCodec) != 0) { - return -1; - } - ACMToExternalCodecRepresentation(codec, acmCodec); - return 0; + return channelPtr->GetRecCodec(codec); } int VoECodecImpl::SetRecPayloadType(int channel, const CodecInst& codec) { WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), "SetRecPayloadType(channel=%d, codec)", channel); WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), - "codec: plname=%s, plfreq=%d, pltype=%d, channels=%u, " + "codec: plname=%s, plfreq=%d, pltype=%d, channels=%" PRIuS ", " "pacsize=%d, rate=%d", codec.plname, codec.plfreq, codec.pltype, codec.channels, codec.pacsize, codec.rate); @@ -389,54 +377,6 @@ int VoECodecImpl::SetOpusDtx(int channel, bool enable_dtx) { return channelPtr->SetOpusDtx(enable_dtx); } -void VoECodecImpl::ACMToExternalCodecRepresentation(CodecInst& toInst, - const CodecInst& fromInst) { - toInst = fromInst; - if (STR_CASE_CMP(fromInst.plname, "SILK") == 0) { - if (fromInst.plfreq == 12000) { - if (fromInst.pacsize == 320) { - toInst.pacsize = 240; - } else if (fromInst.pacsize == 640) { - toInst.pacsize = 480; - } else if (fromInst.pacsize == 960) { - toInst.pacsize = 720; - } - } else if (fromInst.plfreq == 24000) { - if (fromInst.pacsize == 640) { - toInst.pacsize = 480; - } else if (fromInst.pacsize == 1280) { - toInst.pacsize = 960; - } else if (fromInst.pacsize == 1920) { - toInst.pacsize = 1440; - } - } - } -} - -void VoECodecImpl::ExternalToACMCodecRepresentation(CodecInst& toInst, - const CodecInst& fromInst) { - toInst = fromInst; - if (STR_CASE_CMP(fromInst.plname, "SILK") == 0) { - if (fromInst.plfreq == 12000) { - if (fromInst.pacsize == 240) { - toInst.pacsize = 320; - } else if (fromInst.pacsize == 480) { - toInst.pacsize = 640; - } else if (fromInst.pacsize == 720) { - toInst.pacsize = 960; - } - } else if (fromInst.plfreq == 24000) { - if (fromInst.pacsize == 480) { - toInst.pacsize = 640; - } else if (fromInst.pacsize == 960) { - toInst.pacsize = 1280; - } else if (fromInst.pacsize == 1440) { - toInst.pacsize = 1920; - } - } - } -} - RtcEventLog* VoECodecImpl::GetEventLog() { return _shared->channel_manager().GetEventLog(); } diff --git a/webrtc/voice_engine/voe_codec_impl.h b/webrtc/voice_engine/voe_codec_impl.h index a0eed4d38c..5095f6e232 100644 --- a/webrtc/voice_engine/voe_codec_impl.h +++ b/webrtc/voice_engine/voe_codec_impl.h @@ -65,12 +65,6 @@ class VoECodecImpl : public VoECodec { ~VoECodecImpl() override; private: - void ACMToExternalCodecRepresentation(CodecInst& toInst, - const CodecInst& fromInst); - - void ExternalToACMCodecRepresentation(CodecInst& toInst, - const CodecInst& fromInst); - voe::SharedData* _shared; }; diff --git a/webrtc/voice_engine/voe_codec_unittest.cc b/webrtc/voice_engine/voe_codec_unittest.cc index 52aa537544..f09e19e685 100644 --- a/webrtc/voice_engine/voe_codec_unittest.cc +++ b/webrtc/voice_engine/voe_codec_unittest.cc @@ -13,7 +13,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/modules/audio_device/include/fake_audio_device.h" -#include "webrtc/test/testsupport/gtest_disable.h" #include "webrtc/voice_engine/include/voe_base.h" #include "webrtc/voice_engine/include/voe_hardware.h" #include "webrtc/voice_engine/voice_engine_defines.h" diff --git a/webrtc/voice_engine/voe_file_impl.cc b/webrtc/voice_engine/voe_file_impl.cc index 7927f9ff05..2091e7073b 100644 --- a/webrtc/voice_engine/voe_file_impl.cc +++ b/webrtc/voice_engine/voe_file_impl.cc @@ -10,7 +10,7 @@ #include "webrtc/voice_engine/voe_file_impl.h" -#include "webrtc/modules/media_file/interface/media_file.h" +#include "webrtc/modules/media_file/media_file.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/file_wrapper.h" #include "webrtc/system_wrappers/include/trace.h" diff --git a/webrtc/voice_engine/voe_neteq_stats_impl.cc b/webrtc/voice_engine/voe_neteq_stats_impl.cc index 00e04d8f99..807325b4f8 100644 --- a/webrtc/voice_engine/voe_neteq_stats_impl.cc +++ b/webrtc/voice_engine/voe_neteq_stats_impl.cc @@ -10,7 +10,7 @@ #include "webrtc/voice_engine/voe_neteq_stats_impl.h" -#include "webrtc/modules/audio_coding/main/include/audio_coding_module.h" +#include "webrtc/modules/audio_coding/include/audio_coding_module.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/trace.h" #include "webrtc/voice_engine/channel.h" diff --git a/webrtc/voice_engine/voe_network_impl.cc b/webrtc/voice_engine/voe_network_impl.cc index 4a0c3f7861..0574aa9f05 100644 --- a/webrtc/voice_engine/voe_network_impl.cc +++ b/webrtc/voice_engine/voe_network_impl.cc @@ -12,8 +12,8 @@ #include "webrtc/base/checks.h" #include "webrtc/base/format_macros.h" +#include "webrtc/base/logging.h" #include "webrtc/system_wrappers/include/critical_section_wrapper.h" -#include "webrtc/system_wrappers/include/logging.h" #include "webrtc/system_wrappers/include/trace.h" #include "webrtc/voice_engine/channel.h" #include "webrtc/voice_engine/include/voe_errors.h" diff --git a/webrtc/voice_engine/voe_video_sync_impl.cc b/webrtc/voice_engine/voe_video_sync_impl.cc index 811bb4ec5e..77517c633c 100644 --- a/webrtc/voice_engine/voe_video_sync_impl.cc +++ b/webrtc/voice_engine/voe_video_sync_impl.cc @@ -116,25 +116,6 @@ int VoEVideoSyncImpl::SetMinimumPlayoutDelay(int channel, int delayMs) { return channelPtr->SetMinimumPlayoutDelay(delayMs); } -int VoEVideoSyncImpl::SetInitialPlayoutDelay(int channel, int delay_ms) { - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "SetInitialPlayoutDelay(channel=%d, delay_ms=%d)", channel, - delay_ms); - - if (!_shared->statistics().Initialized()) { - _shared->SetLastError(VE_NOT_INITED, kTraceError); - return -1; - } - voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); - voe::Channel* channelPtr = ch.channel(); - if (channelPtr == NULL) { - _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, - "SetInitialPlayoutDelay() failed to locate channel"); - return -1; - } - return channelPtr->SetInitialPlayoutDelay(delay_ms); -} - int VoEVideoSyncImpl::GetDelayEstimate(int channel, int* jitter_buffer_delay_ms, int* playout_buffer_delay_ms) { diff --git a/webrtc/voice_engine/voe_video_sync_impl.h b/webrtc/voice_engine/voe_video_sync_impl.h index aac575c250..8b367eeae1 100644 --- a/webrtc/voice_engine/voe_video_sync_impl.h +++ b/webrtc/voice_engine/voe_video_sync_impl.h @@ -23,8 +23,6 @@ class VoEVideoSyncImpl : public VoEVideoSync { int SetMinimumPlayoutDelay(int channel, int delayMs) override; - int SetInitialPlayoutDelay(int channel, int delay_ms) override; - int GetDelayEstimate(int channel, int* jitter_buffer_delay_ms, int* playout_buffer_delay_ms) override; diff --git a/webrtc/voice_engine/voice_engine.gyp b/webrtc/voice_engine/voice_engine.gyp index 221b2aa681..ff588d8ead 100644 --- a/webrtc/voice_engine/voice_engine.gyp +++ b/webrtc/voice_engine/voice_engine.gyp @@ -23,11 +23,15 @@ '<(webrtc_root)/modules/modules.gyp:audio_processing', '<(webrtc_root)/modules/modules.gyp:bitrate_controller', '<(webrtc_root)/modules/modules.gyp:media_file', + '<(webrtc_root)/modules/modules.gyp:paced_sender', '<(webrtc_root)/modules/modules.gyp:rtp_rtcp', '<(webrtc_root)/modules/modules.gyp:webrtc_utility', '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', '<(webrtc_root)/webrtc.gyp:rtc_event_log', ], + 'export_dependent_settings': [ + '<(webrtc_root)/modules/modules.gyp:audio_coding_module', + ], 'sources': [ 'include/voe_audio_processing.h', 'include/voe_base.h', @@ -46,6 +50,8 @@ 'channel.h', 'channel_manager.cc', 'channel_manager.h', + 'channel_proxy.cc', + 'channel_proxy.h', 'dtmf_inband.cc', 'dtmf_inband.h', 'dtmf_inband_queue.cc', @@ -143,83 +149,6 @@ ], }, { - 'target_name': 'voe_auto_test', - 'type': 'executable', - 'dependencies': [ - 'voice_engine', - '<(DEPTH)/testing/gmock.gyp:gmock', - '<(DEPTH)/testing/gtest.gyp:gtest', - '<(DEPTH)/third_party/gflags/gflags.gyp:gflags', - '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', - '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers_default', - '<(webrtc_root)/test/test.gyp:channel_transport', - '<(webrtc_root)/test/test.gyp:test_support', - '<(webrtc_root)/webrtc.gyp:rtc_event_log', - ], - 'sources': [ - 'test/auto_test/automated_mode.cc', - 'test/auto_test/extended/agc_config_test.cc', - 'test/auto_test/extended/ec_metrics_test.cc', - 'test/auto_test/fakes/conference_transport.cc', - 'test/auto_test/fakes/conference_transport.h', - 'test/auto_test/fakes/loudest_filter.cc', - 'test/auto_test/fakes/loudest_filter.h', - 'test/auto_test/fixtures/after_initialization_fixture.cc', - 'test/auto_test/fixtures/after_initialization_fixture.h', - 'test/auto_test/fixtures/after_streaming_fixture.cc', - 'test/auto_test/fixtures/after_streaming_fixture.h', - 'test/auto_test/fixtures/before_initialization_fixture.cc', - 'test/auto_test/fixtures/before_initialization_fixture.h', - 'test/auto_test/fixtures/before_streaming_fixture.cc', - 'test/auto_test/fixtures/before_streaming_fixture.h', - 'test/auto_test/standard/audio_processing_test.cc', - 'test/auto_test/standard/codec_before_streaming_test.cc', - 'test/auto_test/standard/codec_test.cc', - 'test/auto_test/standard/dtmf_test.cc', - 'test/auto_test/standard/external_media_test.cc', - 'test/auto_test/standard/file_before_streaming_test.cc', - 'test/auto_test/standard/file_test.cc', - 'test/auto_test/standard/hardware_before_initializing_test.cc', - 'test/auto_test/standard/hardware_before_streaming_test.cc', - 'test/auto_test/standard/hardware_test.cc', - 'test/auto_test/standard/mixing_test.cc', - 'test/auto_test/standard/neteq_stats_test.cc', - 'test/auto_test/standard/rtp_rtcp_before_streaming_test.cc', - 'test/auto_test/standard/rtp_rtcp_extensions.cc', - 'test/auto_test/standard/rtp_rtcp_test.cc', - 'test/auto_test/standard/voe_base_misc_test.cc', - 'test/auto_test/standard/video_sync_test.cc', - 'test/auto_test/standard/volume_test.cc', - 'test/auto_test/resource_manager.cc', - 'test/auto_test/voe_conference_test.cc', - 'test/auto_test/voe_cpu_test.cc', - 'test/auto_test/voe_cpu_test.h', - 'test/auto_test/voe_standard_test.cc', - 'test/auto_test/voe_standard_test.h', - 'test/auto_test/voe_stress_test.cc', - 'test/auto_test/voe_stress_test.h', - 'test/auto_test/voe_test_defines.h', - 'test/auto_test/voe_test_interface.h', - ], - 'conditions': [ - ['OS=="android"', { - # some tests are not supported on android yet, exclude these tests. - 'sources!': [ - 'test/auto_test/standard/hardware_before_streaming_test.cc', - ], - }], - ['enable_protobuf==1', { - 'defines': [ - 'ENABLE_RTC_EVENT_LOG', - ], - }], - ], - # Disable warnings to enable Win64 build, issue 1323. - 'msvs_disabled_warnings': [ - 4267, # size_t to int truncation. - ], - }, - { # command line test that should work on linux/mac/win 'target_name': 'voe_cmd_test', 'type': 'executable', @@ -239,6 +168,89 @@ }, ], # targets 'conditions': [ + ['OS!="ios"', { + 'targets': [ + { + 'target_name': 'voe_auto_test', + 'type': 'executable', + 'dependencies': [ + 'voice_engine', + '<(DEPTH)/testing/gmock.gyp:gmock', + '<(DEPTH)/testing/gtest.gyp:gtest', + '<(DEPTH)/third_party/gflags/gflags.gyp:gflags', + '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers', + '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers_default', + '<(webrtc_root)/test/test.gyp:channel_transport', + '<(webrtc_root)/test/test.gyp:test_support', + '<(webrtc_root)/test/webrtc_test_common.gyp:webrtc_test_common', + '<(webrtc_root)/webrtc.gyp:rtc_event_log', + ], + 'sources': [ + 'test/auto_test/automated_mode.cc', + 'test/auto_test/extended/agc_config_test.cc', + 'test/auto_test/extended/ec_metrics_test.cc', + 'test/auto_test/fakes/conference_transport.cc', + 'test/auto_test/fakes/conference_transport.h', + 'test/auto_test/fakes/loudest_filter.cc', + 'test/auto_test/fakes/loudest_filter.h', + 'test/auto_test/fixtures/after_initialization_fixture.cc', + 'test/auto_test/fixtures/after_initialization_fixture.h', + 'test/auto_test/fixtures/after_streaming_fixture.cc', + 'test/auto_test/fixtures/after_streaming_fixture.h', + 'test/auto_test/fixtures/before_initialization_fixture.cc', + 'test/auto_test/fixtures/before_initialization_fixture.h', + 'test/auto_test/fixtures/before_streaming_fixture.cc', + 'test/auto_test/fixtures/before_streaming_fixture.h', + 'test/auto_test/standard/audio_processing_test.cc', + 'test/auto_test/standard/codec_before_streaming_test.cc', + 'test/auto_test/standard/codec_test.cc', + 'test/auto_test/standard/dtmf_test.cc', + 'test/auto_test/standard/external_media_test.cc', + 'test/auto_test/standard/file_before_streaming_test.cc', + 'test/auto_test/standard/file_test.cc', + 'test/auto_test/standard/hardware_before_initializing_test.cc', + 'test/auto_test/standard/hardware_before_streaming_test.cc', + 'test/auto_test/standard/hardware_test.cc', + 'test/auto_test/standard/mixing_test.cc', + 'test/auto_test/standard/neteq_stats_test.cc', + 'test/auto_test/standard/rtp_rtcp_before_streaming_test.cc', + 'test/auto_test/standard/rtp_rtcp_extensions.cc', + 'test/auto_test/standard/rtp_rtcp_test.cc', + 'test/auto_test/standard/voe_base_misc_test.cc', + 'test/auto_test/standard/video_sync_test.cc', + 'test/auto_test/standard/volume_test.cc', + 'test/auto_test/resource_manager.cc', + 'test/auto_test/voe_conference_test.cc', + 'test/auto_test/voe_cpu_test.cc', + 'test/auto_test/voe_cpu_test.h', + 'test/auto_test/voe_output_test.cc', + 'test/auto_test/voe_standard_test.cc', + 'test/auto_test/voe_standard_test.h', + 'test/auto_test/voe_stress_test.cc', + 'test/auto_test/voe_stress_test.h', + 'test/auto_test/voe_test_defines.h', + 'test/auto_test/voe_test_interface.h', + ], + 'conditions': [ + ['OS=="android"', { + # some tests are not supported on android yet, exclude these tests. + 'sources!': [ + 'test/auto_test/standard/hardware_before_streaming_test.cc', + ], + }], + ['enable_protobuf==1', { + 'defines': [ + 'ENABLE_RTC_EVENT_LOG', + ], + }], + ], + # Disable warnings to enable Win64 build, issue 1323. + 'msvs_disabled_warnings': [ + 4267, # size_t to int truncation. + ], + }, + ], + }], ['OS=="android"', { 'targets': [ { @@ -281,6 +293,6 @@ ], }], ], # conditions - }], # include_tests + }], # include_tests==1 ], # conditions } diff --git a/webrtc/voice_engine/voice_engine_defines.h b/webrtc/voice_engine/voice_engine_defines.h index f78fb2c558..f4bdd957e9 100644 --- a/webrtc/voice_engine/voice_engine_defines.h +++ b/webrtc/voice_engine/voice_engine_defines.h @@ -57,9 +57,6 @@ enum { kVoiceEngineMaxIpPacketSizeBytes = 1500 }; // assumes Ethernet enum { kVoiceEngineMaxModuleVersionSize = 960 }; -// Base -enum { kVoiceEngineVersionMaxMessageSize = 1024 }; - // Audio processing const NoiseSuppression::Level kDefaultNsMode = NoiseSuppression::kModerate; const GainControl::Mode kDefaultAgcMode = @@ -135,7 +132,7 @@ enum { kVoiceEngineMaxRtpExtensionId = 14 }; stat.SetLastError(VE_FUNC_NOT_SUPPORTED); \ return -1; -#if (defined(_DEBUG) && defined(_WIN32) && (_MSC_VER >= 1400)) +#if (!defined(NDEBUG) && defined(_WIN32) && (_MSC_VER >= 1400)) #include <windows.h> #include <stdio.h> #define DEBUG_PRINT(...) \ @@ -147,7 +144,7 @@ enum { kVoiceEngineMaxRtpExtensionId = 14 }; #else // special fix for visual 2003 #define DEBUG_PRINT(exp) ((void)0) -#endif // defined(_DEBUG) && defined(_WIN32) +#endif // !defined(NDEBUG) && defined(_WIN32) #define CHECK_CHANNEL(channel) \ if (CheckChannel(channel) == -1) \ diff --git a/webrtc/voice_engine/voice_engine_impl.cc b/webrtc/voice_engine/voice_engine_impl.cc index c8761bc38d..7caf93343f 100644 --- a/webrtc/voice_engine/voice_engine_impl.cc +++ b/webrtc/voice_engine/voice_engine_impl.cc @@ -12,11 +12,14 @@ #include "webrtc/modules/audio_device/android/audio_device_template.h" #include "webrtc/modules/audio_device/android/audio_record_jni.h" #include "webrtc/modules/audio_device/android/audio_track_jni.h" -#include "webrtc/modules/utility/interface/jvm_android.h" +#include "webrtc/modules/utility/include/jvm_android.h" #endif -#include "webrtc/modules/audio_coding/main/include/audio_coding_module.h" +#include "webrtc/base/checks.h" +#include "webrtc/modules/audio_coding/include/audio_coding_module.h" +#include "webrtc/system_wrappers/include/critical_section_wrapper.h" #include "webrtc/system_wrappers/include/trace.h" +#include "webrtc/voice_engine/channel_proxy.h" #include "webrtc/voice_engine/voice_engine_impl.h" namespace webrtc { @@ -28,23 +31,6 @@ namespace webrtc { static int32_t gVoiceEngineInstanceCounter = 0; VoiceEngine* GetVoiceEngine(const Config* config, bool owns_config) { -#if (defined _WIN32) - HMODULE hmod = LoadLibrary(TEXT("VoiceEngineTestingDynamic.dll")); - - if (hmod) { - typedef VoiceEngine* (*PfnGetVoiceEngine)(void); - PfnGetVoiceEngine pfn = - (PfnGetVoiceEngine)GetProcAddress(hmod, "GetVoiceEngine"); - if (pfn) { - VoiceEngine* self = pfn(); - if (owns_config) { - delete config; - } - return (self); - } - } -#endif - VoiceEngineImpl* self = new VoiceEngineImpl(config, owns_config); if (self != NULL) { self->AddRef(); // First reference. Released in VoiceEngine::Delete. @@ -77,6 +63,15 @@ int VoiceEngineImpl::Release() { return new_ref; } +rtc::scoped_ptr<voe::ChannelProxy> VoiceEngineImpl::GetChannelProxy( + int channel_id) { + RTC_DCHECK(channel_id >= 0); + CriticalSectionScoped cs(crit_sec()); + RTC_DCHECK(statistics().Initialized()); + return rtc::scoped_ptr<voe::ChannelProxy>( + new voe::ChannelProxy(channel_manager().GetChannel(channel_id))); +} + VoiceEngine* VoiceEngine::Create() { Config* config = new Config(); return GetVoiceEngine(config, true); @@ -153,4 +148,12 @@ int VoiceEngine::SetAndroidObjects(void* javaVM, void* context) { } #endif +std::string VoiceEngine::GetVersionString() { + std::string version = "VoiceEngine 4.1.0"; +#ifdef WEBRTC_EXTERNAL_TRANSPORT + version += " (External transport build)"; +#endif + return version; +} + } // namespace webrtc diff --git a/webrtc/voice_engine/voice_engine_impl.h b/webrtc/voice_engine/voice_engine_impl.h index c3b2e5ced9..f98f881214 100644 --- a/webrtc/voice_engine/voice_engine_impl.h +++ b/webrtc/voice_engine/voice_engine_impl.h @@ -11,6 +11,7 @@ #ifndef WEBRTC_VOICE_ENGINE_VOICE_ENGINE_IMPL_H #define WEBRTC_VOICE_ENGINE_VOICE_ENGINE_IMPL_H +#include "webrtc/base/scoped_ptr.h" #include "webrtc/engine_configurations.h" #include "webrtc/system_wrappers/include/atomic32.h" #include "webrtc/voice_engine/voe_base_impl.h" @@ -48,6 +49,9 @@ #endif namespace webrtc { +namespace voe { +class ChannelProxy; +} // namespace voe class VoiceEngineImpl : public voe::SharedData, // Must be the first base class public VoiceEngine, @@ -128,6 +132,10 @@ class VoiceEngineImpl : public voe::SharedData, // Must be the first base class // This implements the Release() method for all the inherited interfaces. int Release() override; + // Backdoor to access a voe::Channel object without a channel ID. This is only + // to be used while refactoring the VoE API! + virtual rtc::scoped_ptr<voe::ChannelProxy> GetChannelProxy(int channel_id); + // This is *protected* so that FakeVoiceEngine can inherit from the class and // manipulate the reference count. See: fake_voice_engine.h. protected: |