diff --git a/media/engine/webrtcvoe.h b/media/engine/webrtcvoe.h index fd4f92969c..5a25d44d29 100644 --- a/media/engine/webrtcvoe.h +++ b/media/engine/webrtcvoe.h @@ -16,7 +16,6 @@ #include "common_types.h" // NOLINT(build/include) #include "modules/audio_device/include/audio_device.h" #include "voice_engine/include/voe_base.h" -#include "voice_engine/include/voe_codec.h" #include "voice_engine/include/voe_errors.h" namespace cricket { diff --git a/test/mock_voice_engine.h b/test/mock_voice_engine.h index bd65b0ba5e..e388993cf6 100644 --- a/test/mock_voice_engine.h +++ b/test/mock_voice_engine.h @@ -113,27 +113,6 @@ class MockVoiceEngine : public VoiceEngineImpl { MOCK_METHOD1(StopSend, int(int channel)); MOCK_METHOD0(audio_transport, AudioTransport*()); - // VoECodec - MOCK_METHOD0(NumOfCodecs, int()); - MOCK_METHOD2(GetCodec, int(int index, CodecInst& codec)); - MOCK_METHOD2(SetSendCodec, int(int channel, const CodecInst& codec)); - MOCK_METHOD2(GetSendCodec, int(int channel, CodecInst& codec)); - MOCK_METHOD2(SetBitRate, int(int channel, int bitrate_bps)); - MOCK_METHOD2(GetRecCodec, int(int channel, CodecInst& codec)); - MOCK_METHOD2(SetRecPayloadType, int(int channel, const CodecInst& codec)); - MOCK_METHOD2(GetRecPayloadType, int(int channel, CodecInst& codec)); - MOCK_METHOD3(SetSendCNPayloadType, - int(int channel, int type, PayloadFrequencies frequency)); - MOCK_METHOD2(SetFECStatus, int(int channel, bool enable)); - MOCK_METHOD2(GetFECStatus, int(int channel, bool& enabled)); - MOCK_METHOD4(SetVADStatus, - int(int channel, bool enable, VadModes mode, bool disableDTX)); - MOCK_METHOD4( - GetVADStatus, - int(int channel, bool& enabled, VadModes& mode, bool& disabledDTX)); - MOCK_METHOD2(SetOpusMaxPlaybackRate, int(int channel, int frequency_hz)); - MOCK_METHOD2(SetOpusDtx, int(int channel, bool enable_dtx)); - // VoENetwork MOCK_METHOD2(RegisterExternalTransport, int(int channel, Transport& transport)); diff --git a/voice_engine/BUILD.gn b/voice_engine/BUILD.gn index 57a94e2a03..5f1ae034ca 100644 --- a/voice_engine/BUILD.gn +++ b/voice_engine/BUILD.gn @@ -17,7 +17,6 @@ rtc_static_library("voice_engine") { "channel_proxy.cc", "channel_proxy.h", "include/voe_base.h", - "include/voe_codec.h", "include/voe_errors.h", "include/voe_network.h", "include/voe_rtp_rtcp.h", @@ -36,8 +35,6 @@ rtc_static_library("voice_engine") { "utility.h", "voe_base_impl.cc", "voe_base_impl.h", - "voe_codec_impl.cc", - "voe_codec_impl.h", "voe_network_impl.cc", "voe_network_impl.h", "voe_rtp_rtcp_impl.cc", @@ -145,7 +142,6 @@ if (rtc_include_tests) { "transport_feedback_packet_loss_tracker_unittest.cc", "utility_unittest.cc", "voe_base_unittest.cc", - "voe_codec_unittest.cc", "voe_network_unittest.cc", "voice_engine_fixture.cc", "voice_engine_fixture.h", diff --git a/voice_engine/channel.cc b/voice_engine/channel.cc index e5435d6bda..49bc381746 100644 --- a/voice_engine/channel.cc +++ b/voice_engine/channel.cc @@ -912,6 +912,7 @@ int32_t Channel::Init() { return -1; } + // TODO(solenberg): Remove? // Register a default set of send codecs. const int nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); for (int idx = 0; idx < nSupportedCodecs; idx++) { @@ -948,51 +949,6 @@ int32_t Channel::Init() { return 0; } -void Channel::RegisterLegacyReceiveCodecs() { - const int nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); - for (int idx = 0; idx < nSupportedCodecs; idx++) { - CodecInst codec; - RTC_CHECK_EQ(0, audio_coding_->Codec(idx, &codec)); - - // Open up the RTP/RTCP receiver for all supported codecs - if (rtp_receiver_->RegisterReceivePayload(codec) == -1) { - WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), - "Channel::Init() unable to register %s " - "(%d/%d/%" PRIuS "/%d) to RTP/RTCP receiver", - codec.plname, codec.pltype, codec.plfreq, codec.channels, - codec.rate); - } else { - WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), - "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); - } - - // Register default PT for 'telephone-event' - if (STR_CASE_CMP(codec.plname, "telephone-event") == 0) { - if (!audio_coding_->RegisterReceiveCodec(codec.pltype, - CodecInstToSdp(codec))) { - WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), - "Channel::Init() failed to register inband " - "'telephone-event' (%d/%d) correctly", - codec.pltype, codec.plfreq); - } - } - - if (STR_CASE_CMP(codec.plname, "CN") == 0) { - if (!audio_coding_->RegisterReceiveCodec(codec.pltype, - CodecInstToSdp(codec))) { - WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), - "Channel::Init() failed to register CN (%d/%d) " - "correctly - 1", - codec.pltype, codec.plfreq); - } - } - } -} - void Channel::Terminate() { RTC_DCHECK(construction_thread_.CalledOnValidThread()); // Must be called on the same thread as Init(). @@ -1339,198 +1295,11 @@ void Channel::OnUplinkPacketLossRate(float packet_loss_rate) { }); } -int32_t Channel::SetVADStatus(bool enableVAD, - ACMVADMode mode, - bool disableDTX) { - WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), - "Channel::SetVADStatus(mode=%d)", mode); - RTC_DCHECK(!(disableDTX && enableVAD)); // disableDTX mode is deprecated. - if (!codec_manager_.SetVAD(enableVAD, mode) || - !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { - _engineStatisticsPtr->SetLastError(VE_AUDIO_CODING_MODULE_ERROR, - kTraceError, - "SetVADStatus() failed to set VAD"); - return -1; - } - return 0; -} - -int32_t Channel::GetVADStatus(bool& enabledVAD, - ACMVADMode& mode, - bool& disabledDTX) { - const auto* params = codec_manager_.GetStackParams(); - enabledVAD = params->use_cng; - mode = params->vad_mode; - disabledDTX = !params->use_cng; - return 0; -} - void Channel::SetReceiveCodecs(const std::map& codecs) { rtp_payload_registry_->SetAudioReceivePayloads(codecs); audio_coding_->SetReceiveCodecs(codecs); } -int32_t Channel::SetRecPayloadType(const CodecInst& codec) { - return SetRecPayloadType(codec.pltype, CodecInstToSdp(codec)); -} - -int32_t Channel::SetRecPayloadType(int payload_type, - const SdpAudioFormat& format) { - WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), - "Channel::SetRecPayloadType()"); - - if (channel_state_.Get().playing) { - _engineStatisticsPtr->SetLastError( - VE_ALREADY_PLAYING, kTraceError, - "SetRecPayloadType() unable to set PT while playing"); - return -1; - } - - const CodecInst codec = SdpToCodecInst(payload_type, format); - - if (payload_type == -1) { - // De-register the selected codec (RTP/RTCP module and ACM) - - int8_t pltype(-1); - CodecInst rxCodec = codec; - - // Get payload type for the given codec - rtp_payload_registry_->ReceivePayloadType(rxCodec, &pltype); - rxCodec.pltype = pltype; - - if (rtp_receiver_->DeRegisterReceivePayload(pltype) != 0) { - _engineStatisticsPtr->SetLastError( - VE_RTP_RTCP_MODULE_ERROR, kTraceError, - "SetRecPayloadType() RTP/RTCP-module deregistration " - "failed"); - return -1; - } - if (audio_coding_->UnregisterReceiveCodec(rxCodec.pltype) != 0) { - _engineStatisticsPtr->SetLastError( - VE_AUDIO_CODING_MODULE_ERROR, kTraceError, - "SetRecPayloadType() ACM deregistration failed - 1"); - return -1; - } - return 0; - } - - if (rtp_receiver_->RegisterReceivePayload(codec) != 0) { - // First attempt to register failed => de-register and try again - // TODO(kwiberg): Retrying is probably not necessary, since - // AcmReceiver::AddCodec also retries. - rtp_receiver_->DeRegisterReceivePayload(codec.pltype); - if (rtp_receiver_->RegisterReceivePayload(codec) != 0) { - _engineStatisticsPtr->SetLastError( - VE_RTP_RTCP_MODULE_ERROR, kTraceError, - "SetRecPayloadType() RTP/RTCP-module registration failed"); - return -1; - } - } - if (!audio_coding_->RegisterReceiveCodec(payload_type, format)) { - audio_coding_->UnregisterReceiveCodec(payload_type); - if (!audio_coding_->RegisterReceiveCodec(payload_type, format)) { - _engineStatisticsPtr->SetLastError( - VE_AUDIO_CODING_MODULE_ERROR, kTraceError, - "SetRecPayloadType() ACM registration failed - 1"); - return -1; - } - } - return 0; -} - -int32_t Channel::GetRecPayloadType(CodecInst& codec) { - int8_t payloadType(-1); - if (rtp_payload_registry_->ReceivePayloadType(codec, &payloadType) != 0) { - _engineStatisticsPtr->SetLastError( - VE_RTP_RTCP_MODULE_ERROR, kTraceWarning, - "GetRecPayloadType() failed to retrieve RX payload type"); - return -1; - } - codec.pltype = payloadType; - return 0; -} - -int32_t Channel::SetSendCNPayloadType(int type, PayloadFrequencies frequency) { - WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), - "Channel::SetSendCNPayloadType()"); - - CodecInst codec; - int32_t samplingFreqHz(-1); - const size_t kMono = 1; - if (frequency == kFreq32000Hz) - samplingFreqHz = 32000; - else if (frequency == kFreq16000Hz) - samplingFreqHz = 16000; - - if (audio_coding_->Codec("CN", &codec, samplingFreqHz, kMono) == -1) { - _engineStatisticsPtr->SetLastError( - VE_AUDIO_CODING_MODULE_ERROR, kTraceError, - "SetSendCNPayloadType() failed to retrieve default CN codec " - "settings"); - return -1; - } - - // Modify the payload type (must be set to dynamic range) - codec.pltype = type; - - if (!codec_manager_.RegisterEncoder(codec) || - !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { - _engineStatisticsPtr->SetLastError( - VE_AUDIO_CODING_MODULE_ERROR, kTraceError, - "SetSendCNPayloadType() failed to register CN to ACM"); - return -1; - } - - if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { - _rtpRtcpModule->DeRegisterSendPayload(codec.pltype); - if (_rtpRtcpModule->RegisterSendPayload(codec) != 0) { - _engineStatisticsPtr->SetLastError( - VE_RTP_RTCP_MODULE_ERROR, kTraceError, - "SetSendCNPayloadType() failed to register CN to RTP/RTCP " - "module"); - return -1; - } - } - return 0; -} - -int Channel::SetOpusMaxPlaybackRate(int frequency_hz) { - WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), - "Channel::SetOpusMaxPlaybackRate()"); - - if (audio_coding_->SetOpusMaxPlaybackRate(frequency_hz) != 0) { - _engineStatisticsPtr->SetLastError( - VE_AUDIO_CODING_MODULE_ERROR, kTraceError, - "SetOpusMaxPlaybackRate() failed to set maximum playback rate"); - return -1; - } - return 0; -} - -int Channel::SetOpusDtx(bool enable_dtx) { - WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), - "Channel::SetOpusDtx(%d)", enable_dtx); - int ret = enable_dtx ? audio_coding_->EnableOpusDtx() - : audio_coding_->DisableOpusDtx(); - if (ret != 0) { - _engineStatisticsPtr->SetLastError(VE_AUDIO_CODING_MODULE_ERROR, - kTraceError, "SetOpusDtx() failed"); - return -1; - } - return 0; -} - -int Channel::GetOpusDtx(bool* enabled) { - int success = -1; - audio_coding_->QueryEncoder([&](AudioEncoder const* encoder) { - if (encoder) { - *enabled = encoder->GetDtx(); - success = 0; - } - }); - return success; -} - bool Channel::EnableAudioNetworkAdaptor(const std::string& config_string) { bool success = false; audio_coding_->ModifyEncoder([&](std::unique_ptr* encoder) { @@ -2071,24 +1840,6 @@ int Channel::GetRTPStatistics(CallStatistics& stats) { return 0; } -int Channel::SetCodecFECStatus(bool enable) { - WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), - "Channel::SetCodecFECStatus()"); - - if (!codec_manager_.SetCodecFEC(enable) || - !codec_manager_.MakeEncoder(&rent_a_codec_, audio_coding_.get())) { - _engineStatisticsPtr->SetLastError( - VE_AUDIO_CODING_MODULE_ERROR, kTraceError, - "SetCodecFECStatus() failed to set FEC state"); - return -1; - } - return 0; -} - -bool Channel::GetCodecFECStatus() { - return codec_manager_.GetStackParams()->use_codec_fec; -} - void Channel::SetNACKStatus(bool enable, int maxNumberOfPackets) { // None of these functions can fail. // If pacing is enabled we always store packets. diff --git a/voice_engine/channel.h b/voice_engine/channel.h index d023f87753..5c95a64f1c 100644 --- a/voice_engine/channel.h +++ b/voice_engine/channel.h @@ -136,7 +136,6 @@ class Channel uint32_t instanceId, const VoEBase::ChannelConfig& config); int32_t Init(); - void RegisterLegacyReceiveCodecs(); void Terminate(); int32_t SetEngineInformation(Statistics& engineStatistics, OutputMixer& outputMixer, @@ -171,20 +170,11 @@ class Channel int32_t RegisterVoiceEngineObserver(VoiceEngineObserver& observer); int32_t DeRegisterVoiceEngineObserver(); - // VoECodec + // Codecs int32_t GetSendCodec(CodecInst& codec); int32_t GetRecCodec(CodecInst& codec); int32_t SetSendCodec(const CodecInst& codec); void SetBitRate(int bitrate_bps, int64_t probing_interval_ms); - int32_t SetVADStatus(bool enableVAD, ACMVADMode mode, bool disableDTX); - int32_t GetVADStatus(bool& enabledVAD, ACMVADMode& mode, bool& disabledDTX); - int32_t SetRecPayloadType(const CodecInst& codec); - int32_t SetRecPayloadType(int payload_type, const SdpAudioFormat& format); - int32_t GetRecPayloadType(CodecInst& codec); - int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency); - int SetOpusMaxPlaybackRate(int frequency_hz); - int SetOpusDtx(bool enable_dtx); - int GetOpusDtx(bool* enabled); bool EnableAudioNetworkAdaptor(const std::string& config_string); void DisableAudioNetworkAdaptor(); void SetReceiverFrameLengthRange(int min_frame_length_ms, @@ -250,8 +240,6 @@ class Channel unsigned short dataLengthInBytes); int GetRemoteRTCPReportBlocks(std::vector* report_blocks); int GetRTPStatistics(CallStatistics& stats); - int SetCodecFECStatus(bool enable); - bool GetCodecFECStatus(); void SetNACKStatus(bool enable, int maxNumberOfPackets); // From AudioPacketizationCallback in the ACM diff --git a/voice_engine/channel_proxy.cc b/voice_engine/channel_proxy.cc index a4d68ace08..f6013c2540 100644 --- a/voice_engine/channel_proxy.cc +++ b/voice_engine/channel_proxy.cc @@ -197,13 +197,6 @@ void ChannelProxy::SetBitrate(int bitrate_bps, int64_t probing_interval_ms) { channel()->SetBitRate(bitrate_bps, probing_interval_ms); } -void ChannelProxy::SetRecPayloadType(int payload_type, - const SdpAudioFormat& format) { - RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); - const int result = channel()->SetRecPayloadType(payload_type, format); - RTC_DCHECK_EQ(0, result); -} - void ChannelProxy::SetReceiveCodecs( const std::map& codecs) { RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); @@ -334,11 +327,6 @@ void ChannelProxy::OnRecoverableUplinkPacketLossRate( channel()->OnRecoverableUplinkPacketLossRate(recoverable_packet_loss_rate); } -void ChannelProxy::RegisterLegacyReceiveCodecs() { - RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); - channel()->RegisterLegacyReceiveCodecs(); -} - std::vector ChannelProxy::GetSources() const { RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); return channel()->GetSources(); diff --git a/voice_engine/channel_proxy.h b/voice_engine/channel_proxy.h index 7094b3e901..ca11b58764 100644 --- a/voice_engine/channel_proxy.h +++ b/voice_engine/channel_proxy.h @@ -93,8 +93,6 @@ class ChannelProxy : public RtpPacketSinkInterface { int payload_frequency); virtual bool SendTelephoneEventOutband(int event, int duration_ms); virtual void SetBitrate(int bitrate_bps, int64_t probing_interval_ms); - virtual void SetRecPayloadType(int payload_type, - const SdpAudioFormat& format); virtual void SetReceiveCodecs(const std::map& codecs); virtual void SetSink(std::unique_ptr sink); virtual void SetInputMute(bool muted); @@ -124,7 +122,6 @@ class ChannelProxy : public RtpPacketSinkInterface { virtual void OnTwccBasedUplinkPacketLossRate(float packet_loss_rate); virtual void OnRecoverableUplinkPacketLossRate( float recoverable_packet_loss_rate); - virtual void RegisterLegacyReceiveCodecs(); virtual std::vector GetSources() const; private: diff --git a/voice_engine/include/voe_codec.h b/voice_engine/include/voe_codec.h deleted file mode 100644 index 8ae0997132..0000000000 --- a/voice_engine/include/voe_codec.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2012 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. - */ - -// This sub-API supports the following functionalities: -// -// - Support of non-default codecs (e.g. iLBC, iSAC, etc.). -// - Voice Activity Detection (VAD) on a per channel basis. -// - Possibility to specify how to map received payload types to codecs. -// -// Usage example, omitting error checking: -// -// using namespace webrtc; -// VoiceEngine* voe = VoiceEngine::Create(); -// VoEBase* base = VoEBase::GetInterface(voe); -// VoECodec* codec = VoECodec::GetInterface(voe); -// base->Init(); -// int num_of_codecs = codec->NumOfCodecs() -// ... -// base->Terminate(); -// base->Release(); -// codec->Release(); -// VoiceEngine::Delete(voe); -// -#ifndef VOICE_ENGINE_VOE_CODEC_H_ -#define VOICE_ENGINE_VOE_CODEC_H_ - -#include "common_types.h" // NOLINT(build/include) - -namespace webrtc { - -class VoiceEngine; - -class WEBRTC_DLLEXPORT VoECodec { - public: - // Factory for the VoECodec sub-API. Increases an internal - // reference counter if successful. Returns NULL if the API is not - // supported or if construction fails. - static VoECodec* GetInterface(VoiceEngine* voiceEngine); - - // Releases the VoECodec sub-API and decreases an internal - // reference counter. Returns the new reference count. This value should - // be zero for all sub-API:s before the VoiceEngine object can be safely - // deleted. - virtual int Release() = 0; - - // Gets the number of supported codecs. - virtual int NumOfCodecs() = 0; - - // Get the |codec| information for a specified list |index|. - virtual int GetCodec(int index, CodecInst& codec) = 0; - - // Sets the |codec| for the |channel| to be used for sending. - virtual int SetSendCodec(int channel, const CodecInst& codec) = 0; - - // Gets the |codec| parameters for the sending codec on a specified - // |channel|. - virtual int GetSendCodec(int channel, CodecInst& codec) = 0; - - // Sets the bitrate on a specified |channel| to the specified value - // (in bits/sec). If the value is not supported by the codec, the codec will - // choose an appropriate value. - // Returns -1 on failure and 0 on success. - virtual int SetBitRate(int channel, int bitrate_bps) = 0; - - // Gets the currently received |codec| for a specific |channel|. - virtual int GetRecCodec(int channel, CodecInst& codec) = 0; - - // Sets the dynamic payload type number for a particular |codec| or - // disables (ignores) a codec for receiving. For instance, when receiving - // an invite from a SIP-based client, this function can be used to change - // the dynamic payload type number to match that in the INVITE SDP- - // message. The utilized parameters in the |codec| structure are: - // plname, plfreq, pltype and channels. - virtual int SetRecPayloadType(int channel, const CodecInst& codec) = 0; - - // Gets the actual payload type that is set for receiving a |codec| on a - // |channel|. The value it retrieves will either be the default payload - // type, or a value earlier set with SetRecPayloadType(). - virtual int GetRecPayloadType(int channel, CodecInst& codec) = 0; - - // Sets the payload |type| for the sending of SID-frames with background - // noise estimation during silence periods detected by the VAD. - virtual int SetSendCNPayloadType( - int channel, - int type, - PayloadFrequencies frequency = kFreq16000Hz) = 0; - - // Sets the codec internal FEC (forward error correction) status for a - // specified |channel|. Returns 0 if success, and -1 if failed. - // TODO(minyue): Make SetFECStatus() pure virtual when fakewebrtcvoiceengine - // in talk is ready. - virtual int SetFECStatus(int channel, bool enable) { return -1; } - - // Gets the codec internal FEC status for a specified |channel|. Returns 0 - // with the status stored in |enabled| if success, and -1 if encountered - // error. - // TODO(minyue): Make GetFECStatus() pure virtual when fakewebrtcvoiceengine - // in talk is ready. - virtual int GetFECStatus(int channel, bool& enabled) { return -1; } - - // Sets the VAD/DTX (silence suppression) status and |mode| for a - // specified |channel|. Disabling VAD (through |enable|) will also disable - // DTX; it is not necessary to explictly set |disableDTX| in this case. - virtual int SetVADStatus(int channel, - bool enable, - VadModes mode = kVadConventional, - bool disableDTX = false) = 0; - - // Gets the VAD/DTX status and |mode| for a specified |channel|. - virtual int GetVADStatus(int channel, - bool& enabled, - VadModes& mode, - bool& disabledDTX) = 0; - - // If send codec is Opus on a specified |channel|, sets the maximum playback - // rate the receiver will render: |frequency_hz| (in Hz). - // TODO(minyue): Make SetOpusMaxPlaybackRate() pure virtual when - // fakewebrtcvoiceengine in talk is ready. - virtual int SetOpusMaxPlaybackRate(int channel, int frequency_hz) { - return -1; - } - - // If send codec is Opus on a specified |channel|, set its DTX. Returns 0 if - // success, and -1 if failed. - virtual int SetOpusDtx(int channel, bool enable_dtx) = 0; - - // If send codec is Opus on a specified |channel|, return its DTX status. - // Returns 0 on success, and -1 if failed. - // TODO(ivoc): Make GetOpusDtxStatus() pure virtual when all deriving classes - // are updated. - virtual int GetOpusDtxStatus(int channel, bool* enabled) { return -1; } - - protected: - VoECodec() {} - virtual ~VoECodec() {} -}; - -} // namespace webrtc - -#endif // VOICE_ENGINE_VOE_CODEC_H_ diff --git a/voice_engine/voe_codec_impl.cc b/voice_engine/voe_codec_impl.cc deleted file mode 100644 index 7ba9ab3f05..0000000000 --- a/voice_engine/voe_codec_impl.cc +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright (c) 2012 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 "voice_engine/voe_codec_impl.h" - -#include "modules/audio_coding/include/audio_coding_module.h" -#include "rtc_base/format_macros.h" -#include "system_wrappers/include/trace.h" -#include "voice_engine/channel.h" -#include "voice_engine/include/voe_errors.h" -#include "voice_engine/voice_engine_impl.h" - -namespace webrtc { - -VoECodec* VoECodec::GetInterface(VoiceEngine* voiceEngine) { - if (NULL == voiceEngine) { - return NULL; - } - VoiceEngineImpl* s = static_cast(voiceEngine); - s->AddRef(); - return s; -} - -VoECodecImpl::VoECodecImpl(voe::SharedData* shared) : _shared(shared) { - WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), - "VoECodecImpl() - ctor"); -} - -VoECodecImpl::~VoECodecImpl() { - WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1), - "~VoECodecImpl() - dtor"); -} - -int VoECodecImpl::NumOfCodecs() { - // Number of supported codecs in the ACM - uint8_t nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); - return (nSupportedCodecs); -} - -int VoECodecImpl::GetCodec(int index, CodecInst& codec) { - if (AudioCodingModule::Codec(index, &codec) == -1) { - _shared->SetLastError(VE_INVALID_LISTNR, kTraceError, - "GetCodec() invalid index"); - return -1; - } - return 0; -} - -int VoECodecImpl::SetSendCodec(int channel, const CodecInst& 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=%" PRIuS ", rate=%d", - codec.plname, codec.pacsize, codec.plfreq, codec.pltype, - codec.channels, codec.rate); - if (!_shared->statistics().Initialized()) { - _shared->SetLastError(VE_NOT_INITED, kTraceError); - return -1; - } - // External sanity checks performed outside the ACM - 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(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 ((codec.channels != 1) && (codec.channels != 2)) { - _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, - "SetSendCodec() invalid number of channels"); - 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, - "GetSendCodec() failed to locate channel"); - return -1; - } - if (!AudioCodingModule::IsCodecValid(codec)) { - _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, - "SetSendCodec() invalid codec"); - return -1; - } - if (channelPtr->SetSendCodec(codec) != 0) { - _shared->SetLastError(VE_CANNOT_SET_SEND_CODEC, kTraceError, - "SetSendCodec() failed to set send codec"); - return -1; - } - - return 0; -} - -int VoECodecImpl::GetSendCodec(int channel, CodecInst& codec) { - 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, - "GetSendCodec() failed to locate channel"); - return -1; - } - if (channelPtr->GetSendCodec(codec) != 0) { - _shared->SetLastError(VE_CANNOT_GET_SEND_CODEC, kTraceError, - "GetSendCodec() failed to get send codec"); - return -1; - } - return 0; -} - -int VoECodecImpl::SetBitRate(int channel, int bitrate_bps) { - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "SetBitRate(bitrate_bps=%d)", bitrate_bps); - if (!_shared->statistics().Initialized()) { - _shared->SetLastError(VE_NOT_INITED, kTraceError); - return -1; - } - constexpr int64_t kDefaultProbingIntervalMs = 3000; - _shared->channel_manager().GetChannel(channel).channel()->SetBitRate( - bitrate_bps, kDefaultProbingIntervalMs); - return 0; -} - -int VoECodecImpl::GetRecCodec(int channel, CodecInst& codec) { - 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, - "GetRecCodec() failed to locate channel"); - return -1; - } - 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=%" PRIuS ", " - "pacsize=%d, rate=%d", - codec.plname, codec.plfreq, codec.pltype, codec.channels, - codec.pacsize, codec.rate); - 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, - "GetRecPayloadType() failed to locate channel"); - return -1; - } - return channelPtr->SetRecPayloadType(codec); -} - -int VoECodecImpl::GetRecPayloadType(int channel, CodecInst& codec) { - 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, - "GetRecPayloadType() failed to locate channel"); - return -1; - } - return channelPtr->GetRecPayloadType(codec); -} - -int VoECodecImpl::SetSendCNPayloadType(int channel, - int type, - PayloadFrequencies frequency) { - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "SetSendCNPayloadType(channel=%d, type=%d, frequency=%d)", - channel, type, frequency); - if (!_shared->statistics().Initialized()) { - _shared->SetLastError(VE_NOT_INITED, kTraceError); - return -1; - } - if (type < 96 || type > 127) { - // Only allow dynamic range: 96 to 127 - _shared->SetLastError(VE_INVALID_PLTYPE, kTraceError, - "SetSendCNPayloadType() invalid payload type"); - return -1; - } - if ((frequency != kFreq16000Hz) && (frequency != kFreq32000Hz)) { - // It is not possible to modify the payload type for CN/8000. - // We only allow modification of the CN payload type for CN/16000 - // and CN/32000. - _shared->SetLastError(VE_INVALID_PLFREQ, kTraceError, - "SetSendCNPayloadType() invalid payload frequency"); - 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, - "SetSendCNPayloadType() failed to locate channel"); - return -1; - } - return channelPtr->SetSendCNPayloadType(type, frequency); -} - -int VoECodecImpl::SetFECStatus(int channel, bool enable) { - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "SetCodecFECStatus(channel=%d, enable=%d)", channel, enable); - 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, - "SetCodecFECStatus() failed to locate channel"); - return -1; - } - return channelPtr->SetCodecFECStatus(enable); -} - -int VoECodecImpl::GetFECStatus(int channel, bool& enabled) { - 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, - "GetFECStatus() failed to locate channel"); - return -1; - } - enabled = channelPtr->GetCodecFECStatus(); - return 0; -} - -int VoECodecImpl::SetVADStatus(int channel, - bool enable, - VadModes mode, - bool disableDTX) { - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "SetVADStatus(channel=%i, enable=%i, mode=%i, disableDTX=%i)", - channel, enable, mode, disableDTX); - - 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, - "SetVADStatus failed to locate channel"); - return -1; - } - - ACMVADMode vadMode(VADNormal); - switch (mode) { - case kVadConventional: - vadMode = VADNormal; - break; - case kVadAggressiveLow: - vadMode = VADLowBitrate; - break; - case kVadAggressiveMid: - vadMode = VADAggr; - break; - case kVadAggressiveHigh: - vadMode = VADVeryAggr; - break; - } - return channelPtr->SetVADStatus(enable, vadMode, disableDTX); -} - -int VoECodecImpl::GetVADStatus(int channel, - bool& enabled, - VadModes& mode, - bool& disabledDTX) { - 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, - "GetVADStatus failed to locate channel"); - return -1; - } - - ACMVADMode vadMode; - int ret = channelPtr->GetVADStatus(enabled, vadMode, disabledDTX); - - if (ret != 0) { - _shared->SetLastError(VE_INVALID_OPERATION, kTraceError, - "GetVADStatus failed to get VAD mode"); - return -1; - } - switch (vadMode) { - case VADNormal: - mode = kVadConventional; - break; - case VADLowBitrate: - mode = kVadAggressiveLow; - break; - case VADAggr: - mode = kVadAggressiveMid; - break; - case VADVeryAggr: - mode = kVadAggressiveHigh; - break; - } - - return 0; -} - -int VoECodecImpl::SetOpusMaxPlaybackRate(int channel, int frequency_hz) { - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "SetOpusMaxPlaybackRate(channel=%d, frequency_hz=%d)", channel, - frequency_hz); - 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, - "SetOpusMaxPlaybackRate failed to locate channel"); - return -1; - } - return channelPtr->SetOpusMaxPlaybackRate(frequency_hz); -} - -int VoECodecImpl::SetOpusDtx(int channel, bool enable_dtx) { - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "SetOpusDtx(channel=%d, enable_dtx=%d)", channel, enable_dtx); - 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, - "SetOpusDtx failed to locate channel"); - return -1; - } - return channelPtr->SetOpusDtx(enable_dtx); -} - -int VoECodecImpl::GetOpusDtxStatus(int channel, bool* enabled) { - WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), - "GetOpusDtx(channel=%d)", channel); - 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, - "GetOpusDtx failed to locate channel"); - return -1; - } - return channelPtr->GetOpusDtx(enabled); -} - -} // namespace webrtc diff --git a/voice_engine/voe_codec_impl.h b/voice_engine/voe_codec_impl.h deleted file mode 100644 index 9101f5d62e..0000000000 --- a/voice_engine/voe_codec_impl.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2012 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 VOICE_ENGINE_VOE_CODEC_IMPL_H_ -#define VOICE_ENGINE_VOE_CODEC_IMPL_H_ - -#include "voice_engine/include/voe_codec.h" - -#include "voice_engine/shared_data.h" - -namespace webrtc { - -class VoECodecImpl : public VoECodec { - public: - int NumOfCodecs() override; - - int GetCodec(int index, CodecInst& codec) override; - - int SetSendCodec(int channel, const CodecInst& codec) override; - - int GetSendCodec(int channel, CodecInst& codec) override; - - int SetBitRate(int channel, int bitrate_bps) override; - - int GetRecCodec(int channel, CodecInst& codec) override; - - int SetSendCNPayloadType( - int channel, - int type, - PayloadFrequencies frequency = kFreq16000Hz) override; - - int SetRecPayloadType(int channel, const CodecInst& codec) override; - - int GetRecPayloadType(int channel, CodecInst& codec) override; - - int SetFECStatus(int channel, bool enable) override; - - int GetFECStatus(int channel, bool& enabled) override; - - int SetVADStatus(int channel, - bool enable, - VadModes mode = kVadConventional, - bool disableDTX = false) override; - - int GetVADStatus(int channel, - bool& enabled, - VadModes& mode, - bool& disabledDTX) override; - - int SetOpusMaxPlaybackRate(int channel, int frequency_hz) override; - - int SetOpusDtx(int channel, bool enable_dtx) override; - - int GetOpusDtxStatus(int channel, bool* enabled) override; - - protected: - VoECodecImpl(voe::SharedData* shared); - ~VoECodecImpl() override; - - private: - voe::SharedData* _shared; -}; - -} // namespace webrtc - -#endif // VOICE_ENGINE_VOE_CODEC_IMPL_H_ diff --git a/voice_engine/voe_codec_unittest.cc b/voice_engine/voe_codec_unittest.cc deleted file mode 100644 index 4585a672ae..0000000000 --- a/voice_engine/voe_codec_unittest.cc +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2012 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 - -#include "voice_engine/include/voe_codec.h" - -#include "modules/audio_device/include/fake_audio_device.h" -#include "modules/audio_processing/include/audio_processing.h" -#include "test/gtest.h" -#include "voice_engine/include/voe_base.h" -#include "voice_engine/voice_engine_defines.h" - -namespace webrtc { -namespace voe { -namespace { - -TEST(VoECodecInst, TestCompareCodecInstances) { - CodecInst codec1, codec2; - memset(&codec1, 0, sizeof(CodecInst)); - memset(&codec2, 0, sizeof(CodecInst)); - - codec1.pltype = 101; - strncpy(codec1.plname, "isac", 4); - codec1.plfreq = 8000; - codec1.pacsize = 110; - codec1.channels = 1; - codec1.rate = 8000; - memcpy(&codec2, &codec1, sizeof(CodecInst)); - // Compare two codecs now. - EXPECT_TRUE(codec1 == codec2); - EXPECT_FALSE(codec1 != codec2); - - // Changing pltype. - codec2.pltype = 102; - EXPECT_FALSE(codec1 == codec2); - EXPECT_TRUE(codec1 != codec2); - - // Reset to codec2 to codec1 state. - memcpy(&codec2, &codec1, sizeof(CodecInst)); - // payload name should be case insensitive. - strncpy(codec2.plname, "ISAC", 4); - EXPECT_TRUE(codec1 == codec2); - - // Test modifying the |plfreq| - codec2.plfreq = 16000; - EXPECT_FALSE(codec1 == codec2); - - // Reset to codec2 to codec1 state. - memcpy(&codec2, &codec1, sizeof(CodecInst)); - // Test modifying the |pacsize|. - codec2.pacsize = 440; - EXPECT_FALSE(codec1 == codec2); - - // Reset to codec2 to codec1 state. - memcpy(&codec2, &codec1, sizeof(CodecInst)); - // Test modifying the |channels|. - codec2.channels = 2; - EXPECT_FALSE(codec1 == codec2); - - // Reset to codec2 to codec1 state. - memcpy(&codec2, &codec1, sizeof(CodecInst)); - // Test modifying the |rate|. - codec2.rate = 0; - EXPECT_FALSE(codec1 == codec2); -} - -// This is a regression test for -// https://bugs.chromium.org/p/webrtc/issues/detail?id=6020 -// The Opus DTX setting was being forgotten after unrelated VoE calls. -TEST(VoECodecInst, RememberOpusDtxAfterSettingChange) { - VoiceEngine* voe(VoiceEngine::Create()); - VoEBase* base(VoEBase::GetInterface(voe)); - VoECodec* voe_codec(VoECodec::GetInterface(voe)); - std::unique_ptr adm(new FakeAudioDeviceModule); - std::unique_ptr apm(AudioProcessing::Create()); - - base->Init(adm.get(), apm.get()); - - CodecInst codec = {111, "opus", 48000, 960, 1, 32000}; - - int channel = base->CreateChannel(); - - bool DTX = false; - - EXPECT_EQ(0, voe_codec->SetSendCodec(channel, codec)); - EXPECT_EQ(0, voe_codec->SetOpusDtx(channel, true)); - EXPECT_EQ(0, voe_codec->SetFECStatus(channel, true)); - EXPECT_EQ(0, voe_codec->GetOpusDtxStatus(channel, &DTX)); - EXPECT_TRUE(DTX); - - base->DeleteChannel(channel); - base->Terminate(); - base->Release(); - voe_codec->Release(); - VoiceEngine::Delete(voe); -} - -} // namespace -} // namespace voe -} // namespace webrtc diff --git a/voice_engine/voice_engine_impl.h b/voice_engine/voice_engine_impl.h index 3a6fe276b0..ef03e706a1 100644 --- a/voice_engine/voice_engine_impl.h +++ b/voice_engine/voice_engine_impl.h @@ -16,7 +16,6 @@ #include "system_wrappers/include/atomic32.h" #include "typedefs.h" // NOLINT(build/include) #include "voice_engine/voe_base_impl.h" -#include "voice_engine/voe_codec_impl.h" #include "voice_engine/voe_network_impl.h" #include "voice_engine/voe_rtp_rtcp_impl.h" @@ -27,14 +26,12 @@ class ChannelProxy; class VoiceEngineImpl : public voe::SharedData, // Must be the first base class public VoiceEngine, - public VoECodecImpl, public VoENetworkImpl, public VoERTP_RTCPImpl, public VoEBaseImpl { public: VoiceEngineImpl() : SharedData(), - VoECodecImpl(this), VoENetworkImpl(this), VoERTP_RTCPImpl(this), VoEBaseImpl(this),