Injectable audio encoders: voice_engine/channel changes.
Adds a SetEncoder call to voe::Channel, so that we can move encoder setup outside of Voice Engine. BUG=webrtc:5806 Review-Url: https://codereview.webrtc.org/2703373006 Cr-Commit-Position: refs/heads/master@{#17572}
This commit is contained in:
parent
5f4aaeb0a4
commit
1ffbd6c93c
@ -22,6 +22,14 @@ namespace test {
|
||||
|
||||
class MockVoEChannelProxy : public voe::ChannelProxy {
|
||||
public:
|
||||
// GTest doesn't like move-only types, like std::unique_ptr
|
||||
bool SetEncoder(int payload_type,
|
||||
std::unique_ptr<AudioEncoder> encoder) {
|
||||
return SetEncoderForMock(payload_type, &encoder);
|
||||
}
|
||||
MOCK_METHOD2(SetEncoderForMock,
|
||||
bool(int payload_type,
|
||||
std::unique_ptr<AudioEncoder>* encoder));
|
||||
MOCK_METHOD1(SetRTCPStatus, void(bool enable));
|
||||
MOCK_METHOD1(SetLocalSSRC, void(uint32_t ssrc));
|
||||
MOCK_METHOD1(SetRTCP_CNAME, void(const std::string& c_name));
|
||||
|
||||
@ -146,6 +146,7 @@ rtc_static_library("voice_engine") {
|
||||
"../call:call_interfaces",
|
||||
"../common_audio",
|
||||
"../logging:rtc_event_log_api",
|
||||
"../modules/audio_coding:audio_encoder_interface",
|
||||
"../modules/audio_coding:audio_format_conversion",
|
||||
"../modules/audio_coding:rent_a_codec",
|
||||
"../modules/audio_conference_mixer",
|
||||
|
||||
@ -1274,6 +1274,38 @@ void Channel::StopSend() {
|
||||
_rtpRtcpModule->SetSendingMediaStatus(false);
|
||||
}
|
||||
|
||||
bool Channel::SetEncoder(int payload_type,
|
||||
std::unique_ptr<AudioEncoder> encoder) {
|
||||
RTC_DCHECK_GE(payload_type, 0);
|
||||
RTC_DCHECK_LE(payload_type, 127);
|
||||
// TODO(ossu): Make a CodecInst up for now. It seems like very little of this
|
||||
// information is actually used, possibly only payload type and clock rate.
|
||||
CodecInst lies;
|
||||
lies.pltype = payload_type;
|
||||
strncpy(lies.plname, "audio", sizeof(lies.plname));
|
||||
lies.plname[sizeof(lies.plname) - 1] = 0;
|
||||
// Seems unclear if it should be clock rate or sample rate. CodecInst
|
||||
// supposedly carries the sample rate, but only clock rate seems sensible to
|
||||
// send to the RTP/RTCP module.
|
||||
lies.plfreq = encoder->RtpTimestampRateHz();
|
||||
lies.pacsize = 0;
|
||||
lies.channels = encoder->NumChannels();
|
||||
lies.rate = 0;
|
||||
|
||||
if (_rtpRtcpModule->RegisterSendPayload(lies) != 0) {
|
||||
_rtpRtcpModule->DeRegisterSendPayload(payload_type);
|
||||
if (_rtpRtcpModule->RegisterSendPayload(lies) != 0) {
|
||||
WEBRTC_TRACE(
|
||||
kTraceError, kTraceVoice, VoEId(_instanceId, _channelId),
|
||||
"SetEncoder() failed to register codec to RTP/RTCP module");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
audio_coding_->SetEncoder(std::move(encoder));
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t Channel::RegisterVoiceEngineObserver(VoiceEngineObserver& observer) {
|
||||
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId),
|
||||
"Channel::RegisterVoiceEngineObserver()");
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/modules/audio_coding/acm2/codec_manager.h"
|
||||
#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/audio_encoder.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"
|
||||
@ -172,6 +173,9 @@ class Channel
|
||||
|
||||
void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs);
|
||||
|
||||
// Send using this encoder, with this payload type.
|
||||
bool SetEncoder(int payload_type, std::unique_ptr<AudioEncoder> encoder);
|
||||
|
||||
// API methods
|
||||
|
||||
// VoEBase
|
||||
|
||||
@ -30,6 +30,12 @@ ChannelProxy::ChannelProxy(const ChannelOwner& channel_owner) :
|
||||
|
||||
ChannelProxy::~ChannelProxy() {}
|
||||
|
||||
bool ChannelProxy::SetEncoder(int payload_type,
|
||||
std::unique_ptr<AudioEncoder> encoder) {
|
||||
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
|
||||
return channel()->SetEncoder(payload_type, std::move(encoder));
|
||||
}
|
||||
|
||||
void ChannelProxy::SetRTCPStatus(bool enable) {
|
||||
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
|
||||
channel()->SetRTCPStatus(enable);
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
#include "webrtc/base/race_checker.h"
|
||||
#include "webrtc/base/thread_checker.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
|
||||
#include "webrtc/voice_engine/channel_manager.h"
|
||||
#include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
|
||||
|
||||
@ -54,6 +55,9 @@ class ChannelProxy {
|
||||
explicit ChannelProxy(const ChannelOwner& channel_owner);
|
||||
virtual ~ChannelProxy();
|
||||
|
||||
virtual bool SetEncoder(int payload_type,
|
||||
std::unique_ptr<AudioEncoder> encoder);
|
||||
|
||||
virtual void SetRTCPStatus(bool enable);
|
||||
virtual void SetLocalSSRC(uint32_t ssrc);
|
||||
virtual void SetRTCP_CNAME(const std::string& c_name);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user