- Add temporary VoEBase::audio_device_module() method.

- Remove WVoE::SetAudioDeviceModule() - the ADM is now supplied in ctor.
- Remove WVoE::Init() and WVoE::Terminate().
- Remove MediaEngineInterface::Terminate().

BUG=webrtc:4690

Review URL: https://codereview.webrtc.org/1830213002

Cr-Commit-Position: refs/heads/master@{#12173}
This commit is contained in:
solenberg 2016-03-30 23:28:51 -07:00 committed by Commit bot
parent e71116e25d
commit ff97631e3c
13 changed files with 253 additions and 307 deletions

View File

@ -696,14 +696,12 @@ class FakeBaseEngine {
class FakeVoiceEngine : public FakeBaseEngine {
public:
FakeVoiceEngine()
explicit FakeVoiceEngine(webrtc::AudioDeviceModule* adm)
: output_volume_(-1) {
// Add a fake audio codec. Note that the name must not be "" as there are
// sanity checks against that.
codecs_.push_back(AudioCodec(101, "fake_audio_codec", 0, 0, 1, 0));
}
bool Init(rtc::Thread* worker_thread) { return true; }
void Terminate() {}
rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const {
return rtc::scoped_refptr<webrtc::AudioState>();
}
@ -810,7 +808,8 @@ class FakeVideoEngine : public FakeBaseEngine {
class FakeMediaEngine :
public CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine> {
public:
FakeMediaEngine() {}
FakeMediaEngine() :
CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine>(nullptr) {}
virtual ~FakeMediaEngine() {}
void SetAudioCodecs(const std::vector<AudioCodec>& codecs) {

View File

@ -33,6 +33,7 @@
#endif
namespace webrtc {
class AudioDeviceModule;
class Call;
}
@ -54,9 +55,7 @@ class MediaEngineInterface {
// Initialization
// Starts the engine.
virtual bool Init(rtc::Thread* worker_thread) = 0;
// Shuts down the engine.
virtual void Terminate() = 0;
virtual bool Init() = 0;
// TODO(solenberg): Remove once VoE API refactoring is done.
virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const = 0;
@ -125,16 +124,12 @@ class MediaEngineFactory {
template<class VOICE, class VIDEO>
class CompositeMediaEngine : public MediaEngineInterface {
public:
explicit CompositeMediaEngine(webrtc::AudioDeviceModule* adm) : voice_(adm) {}
virtual ~CompositeMediaEngine() {}
virtual bool Init(rtc::Thread* worker_thread) {
if (!voice_.Init(worker_thread))
return false;
virtual bool Init() {
video_.Init();
return true;
}
virtual void Terminate() {
voice_.Terminate();
}
virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const {
return voice_.GetAudioState();

View File

@ -25,6 +25,7 @@
#include "webrtc/media/engine/fakewebrtccommon.h"
#include "webrtc/media/engine/webrtcvoe.h"
#include "webrtc/modules/audio_coding/acm2/rent_a_codec.h"
#include "webrtc/modules/audio_device/include/fake_audio_device.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h"
namespace cricket {
@ -118,6 +119,26 @@ class FakeAudioProcessing : public webrtc::AudioProcessing {
bool experimental_ns_enabled_;
};
// TODO(solenberg): Swap this for a proper mock of the ADM.
class FakeAudioDeviceModule : public webrtc::FakeAudioDeviceModule {
public:
~FakeAudioDeviceModule() override {
RTC_DCHECK_EQ(0, ref_count_);
}
int32_t AddRef() const override {
ref_count_++;
return ref_count_;
}
int32_t Release() const override {
RTC_DCHECK_LT(0, ref_count_);
ref_count_--;
return ref_count_;
}
private:
mutable int32_t ref_count_ = 0;
};
class FakeWebRtcVoiceEngine
: public webrtc::VoEAudioProcessing,
public webrtc::VoEBase, public webrtc::VoECodec,
@ -193,7 +214,7 @@ class FakeWebRtcVoiceEngine
playout_sample_rate_(-1) {
memset(&agc_config_, 0, sizeof(agc_config_));
}
~FakeWebRtcVoiceEngine() {
~FakeWebRtcVoiceEngine() override {
RTC_CHECK(channels_.empty());
}
@ -306,6 +327,9 @@ class FakeWebRtcVoiceEngine
webrtc::AudioProcessing* audio_processing() override {
return &audio_processing_;
}
webrtc::AudioDeviceModule* audio_device_module() override {
return &audio_device_module_;
}
WEBRTC_FUNC(CreateChannel, ()) {
webrtc::Config empty_config;
return AddChannel(empty_config);
@ -775,6 +799,7 @@ class FakeWebRtcVoiceEngine
int recording_sample_rate_;
int playout_sample_rate_;
FakeAudioProcessing audio_processing_;
FakeAudioDeviceModule audio_device_module_;
};
} // namespace cricket

View File

@ -20,8 +20,8 @@ class WebRtcMediaEngineNullVideo
public:
WebRtcMediaEngineNullVideo(webrtc::AudioDeviceModule* adm,
WebRtcVideoEncoderFactory* encoder_factory,
WebRtcVideoDecoderFactory* decoder_factory) {
voice_.SetAudioDeviceModule(adm);
WebRtcVideoDecoderFactory* decoder_factory)
: CompositeMediaEngine<WebRtcVoiceEngine, NullWebRtcVideoEngine>(adm) {
video_.SetExternalDecoderFactory(decoder_factory);
video_.SetExternalEncoderFactory(encoder_factory);
}
@ -31,9 +31,7 @@ class WebRtcMediaEngineNullVideo
// required by CompositeMediaEngine.
TEST(NullWebRtcVideoEngineTest, CheckInterface) {
WebRtcMediaEngineNullVideo engine(nullptr, nullptr, nullptr);
EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
engine.Terminate();
EXPECT_TRUE(engine.Init());
}
} // namespace cricket

View File

@ -30,8 +30,12 @@ class WebRtcMediaEngine2
public:
WebRtcMediaEngine2(webrtc::AudioDeviceModule* adm,
WebRtcVideoEncoderFactory* encoder_factory,
WebRtcVideoDecoderFactory* decoder_factory) {
voice_.SetAudioDeviceModule(adm);
WebRtcVideoDecoderFactory* decoder_factory)
#ifdef HAVE_WEBRTC_VIDEO
: CompositeMediaEngine<WebRtcVoiceEngine, WebRtcVideoEngine2>(adm) {
#else
: CompositeMediaEngine<WebRtcVoiceEngine, NullWebRtcVideoEngine>(adm) {
#endif
video_.SetExternalDecoderFactory(decoder_factory);
video_.SetExternalEncoderFactory(encoder_factory);
}

View File

@ -102,6 +102,7 @@ class WebRtcVideoEngine2Test : public ::testing::Test {
const char* field_trials)
: override_field_trials_(field_trials),
call_(webrtc::Call::Create(webrtc::Call::Config())),
voice_engine_(nullptr),
engine_() {
std::vector<VideoCodec> engine_codecs = engine_.codecs();
RTC_DCHECK(!engine_codecs.empty());

View File

@ -249,7 +249,6 @@ class WebRtcVoiceCodecs final {
// TODO(solenberg): Do this filtering once off-line, add a simple AudioCodec
// list and add a test which verifies VoE supports the listed codecs.
static std::vector<AudioCodec> SupportedCodecs() {
LOG(LS_INFO) << "WebRtc VoiceEngine codecs:";
std::vector<AudioCodec> result;
for (webrtc::CodecInst voe_codec : webrtc::acm2::RentACodec::Database()) {
// Change the sample rate of G722 to 8000 to match SDP.
@ -276,7 +275,6 @@ class WebRtcVoiceCodecs final {
pref->payload_type, voe_codec.plname, voe_codec.plfreq,
voe_codec.rate, voe_codec.channels,
static_cast<int>(arraysize(kCodecPrefs)) - (pref - kCodecPrefs));
LOG(LS_INFO) << ToString(codec);
if (IsCodec(codec, kIsacCodecName)) {
// Indicate auto-bitrate in signaling.
codec.bitrate = 0;
@ -300,7 +298,7 @@ class WebRtcVoiceCodecs final {
}
result.push_back(codec);
} else {
LOG(LS_WARNING) << "Unexpected codec: " << ToString(voe_codec);
LOG(LS_INFO) << "[Unused] " << ToString(voe_codec);
}
}
// Make sure they are in local preference order.
@ -515,74 +513,46 @@ bool WebRtcVoiceEngine::ToCodecInst(const AudioCodec& in,
return WebRtcVoiceCodecs::ToCodecInst(in, out);
}
WebRtcVoiceEngine::WebRtcVoiceEngine()
: voe_wrapper_(new VoEWrapper()),
audio_state_(webrtc::AudioState::Create(MakeAudioStateConfig(voe()))) {
Construct();
WebRtcVoiceEngine::WebRtcVoiceEngine(webrtc::AudioDeviceModule* adm)
: WebRtcVoiceEngine(adm, new VoEWrapper()) {
audio_state_ = webrtc::AudioState::Create(MakeAudioStateConfig(voe()));
}
WebRtcVoiceEngine::WebRtcVoiceEngine(VoEWrapper* voe_wrapper)
: voe_wrapper_(voe_wrapper) {
Construct();
}
void WebRtcVoiceEngine::Construct() {
WebRtcVoiceEngine::WebRtcVoiceEngine(webrtc::AudioDeviceModule* adm,
VoEWrapper* voe_wrapper)
: adm_(adm), voe_wrapper_(voe_wrapper) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
LOG(LS_VERBOSE) << "WebRtcVoiceEngine::WebRtcVoiceEngine";
LOG(LS_INFO) << "WebRtcVoiceEngine::WebRtcVoiceEngine";
RTC_DCHECK(voe_wrapper);
signal_thread_checker_.DetachFromThread();
std::memset(&default_agc_config_, 0, sizeof(default_agc_config_));
voe_config_.Set<webrtc::VoicePacing>(new webrtc::VoicePacing(true));
webrtc::Trace::set_level_filter(kDefaultTraceFilter);
webrtc::Trace::SetTraceCallback(this);
// Load our audio codec list.
LOG(LS_INFO) << "Supported codecs in order of preference:";
codecs_ = WebRtcVoiceCodecs::SupportedCodecs();
}
WebRtcVoiceEngine::~WebRtcVoiceEngine() {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
LOG(LS_VERBOSE) << "WebRtcVoiceEngine::~WebRtcVoiceEngine";
if (adm_) {
voe_wrapper_.reset();
adm_->Release();
adm_ = NULL;
for (const AudioCodec& codec : codecs_) {
LOG(LS_INFO) << ToString(codec);
}
webrtc::Trace::SetTraceCallback(nullptr);
}
bool WebRtcVoiceEngine::Init(rtc::Thread* worker_thread) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
RTC_DCHECK(worker_thread == rtc::Thread::Current());
LOG(LS_INFO) << "WebRtcVoiceEngine::Init";
bool res = InitInternal();
if (res) {
LOG(LS_INFO) << "WebRtcVoiceEngine::Init Done!";
} else {
LOG(LS_ERROR) << "WebRtcVoiceEngine::Init failed";
Terminate();
}
return res;
}
voe_config_.Set<webrtc::VoicePacing>(new webrtc::VoicePacing(true));
bool WebRtcVoiceEngine::InitInternal() {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
// Temporarily turn logging level up for the Init call.
// Temporarily turn logging level up for the Init() call.
webrtc::Trace::SetTraceCallback(this);
webrtc::Trace::set_level_filter(kElevatedTraceFilter);
LOG(LS_INFO) << webrtc::VoiceEngine::GetVersionString();
if (voe_wrapper_->base()->Init(adm_) == -1) {
LOG_RTCERR0_EX(Init, voe_wrapper_->error());
return false;
}
RTC_CHECK_EQ(0, voe_wrapper_->base()->Init(adm_.get()));
webrtc::Trace::set_level_filter(kDefaultTraceFilter);
// No ADM supplied? Get the default one from VoE.
if (!adm_) {
adm_ = voe_wrapper_->base()->audio_device_module();
}
RTC_DCHECK(adm_);
// Save the default AGC configuration settings. This must happen before
// calling ApplyOptions or the default will be overwritten.
if (voe_wrapper_->processing()->GetAgcConfig(default_agc_config_) == -1) {
LOG_RTCERR0(GetAgcConfig);
return false;
}
int error = voe_wrapper_->processing()->GetAgcConfig(default_agc_config_);
RTC_DCHECK_EQ(0, error);
// Set default engine options.
{
@ -600,31 +570,19 @@ bool WebRtcVoiceEngine::InitInternal() {
options.extended_filter_aec = rtc::Optional<bool>(false);
options.delay_agnostic_aec = rtc::Optional<bool>(false);
options.experimental_ns = rtc::Optional<bool>(false);
if (!ApplyOptions(options)) {
return false;
}
}
// Print our codec list again for the call diagnostic log.
LOG(LS_INFO) << "WebRtc VoiceEngine codecs:";
for (const AudioCodec& codec : codecs_) {
LOG(LS_INFO) << ToString(codec);
bool error = ApplyOptions(options);
RTC_DCHECK(error);
}
SetDefaultDevices();
initialized_ = true;
return true;
}
void WebRtcVoiceEngine::Terminate() {
WebRtcVoiceEngine::~WebRtcVoiceEngine() {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
LOG(LS_INFO) << "WebRtcVoiceEngine::Terminate";
initialized_ = false;
LOG(LS_INFO) << "WebRtcVoiceEngine::~WebRtcVoiceEngine";
StopAecDump();
voe_wrapper_->base()->Terminate();
webrtc::Trace::SetTraceCallback(nullptr);
}
rtc::scoped_refptr<webrtc::AudioState>
@ -643,7 +601,7 @@ VoiceMediaChannel* WebRtcVoiceEngine::CreateChannel(
bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
LOG(LS_INFO) << "ApplyOptions: " << options_in.ToString();
LOG(LS_INFO) << "WebRtcVoiceEngine::ApplyOptions: " << options_in.ToString();
AudioOptions options = options_in; // The options are modified below.
// kEcConference is AEC with high suppression.
@ -1048,23 +1006,6 @@ bool WebRtcVoiceEngine::AdjustAgcLevel(int delta) {
return true;
}
bool WebRtcVoiceEngine::SetAudioDeviceModule(webrtc::AudioDeviceModule* adm) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
if (initialized_) {
LOG(LS_WARNING) << "SetAudioDeviceModule can not be called after Init.";
return false;
}
if (adm_) {
adm_->Release();
adm_ = NULL;
}
if (adm) {
adm_ = adm;
adm_->AddRef();
}
return true;
}
bool WebRtcVoiceEngine::StartAecDump(rtc::PlatformFile file,
int64_t max_size_bytes) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());

View File

@ -19,6 +19,7 @@
#include "webrtc/audio_state.h"
#include "webrtc/base/buffer.h"
#include "webrtc/base/networkroute.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/base/stream.h"
#include "webrtc/base/thread_checker.h"
#include "webrtc/call.h"
@ -44,12 +45,10 @@ class WebRtcVoiceEngine final : public webrtc::TraceCallback {
// Exposed for the WVoE/MC unit test.
static bool ToCodecInst(const AudioCodec& in, webrtc::CodecInst* out);
WebRtcVoiceEngine();
explicit WebRtcVoiceEngine(webrtc::AudioDeviceModule* adm);
// Dependency injection for testing.
explicit WebRtcVoiceEngine(VoEWrapper* voe_wrapper);
~WebRtcVoiceEngine();
bool Init(rtc::Thread* worker_thread);
void Terminate();
WebRtcVoiceEngine(webrtc::AudioDeviceModule* adm, VoEWrapper* voe_wrapper);
~WebRtcVoiceEngine() override;
rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const;
VoiceMediaChannel* CreateChannel(webrtc::Call* call,
@ -76,9 +75,6 @@ class WebRtcVoiceEngine final : public webrtc::TraceCallback {
VoEWrapper* voe() { return voe_wrapper_.get(); }
int GetLastEngineError();
// Set the external ADM. This can only be called before Init.
bool SetAudioDeviceModule(webrtc::AudioDeviceModule* adm);
// Starts AEC dump using an existing file. A maximum file size in bytes can be
// specified. When the maximum file size is reached, logging is stopped and
// the file is closed. If max_size_bytes is set to <= 0, no limit will be
@ -96,8 +92,6 @@ class WebRtcVoiceEngine final : public webrtc::TraceCallback {
void StopRtcEventLog();
private:
void Construct();
bool InitInternal();
// Every option that is "set" will be applied. Every option not "set" will be
// ignored. This allows us to selectively turn on and off different options
// easily at any time.
@ -113,15 +107,14 @@ class WebRtcVoiceEngine final : public webrtc::TraceCallback {
rtc::ThreadChecker signal_thread_checker_;
rtc::ThreadChecker worker_thread_checker_;
// The audio device manager.
rtc::scoped_refptr<webrtc::AudioDeviceModule> adm_;
// The primary instance of WebRtc VoiceEngine.
std::unique_ptr<VoEWrapper> voe_wrapper_;
rtc::scoped_refptr<webrtc::AudioState> audio_state_;
// The external audio device manager
webrtc::AudioDeviceModule* adm_ = nullptr;
std::vector<AudioCodec> codecs_;
std::vector<WebRtcVoiceMediaChannel*> channels_;
webrtc::Config voe_config_;
bool initialized_ = false;
bool is_dumping_aec_ = false;
webrtc::AgcConfig default_agc_config_;
@ -133,7 +126,7 @@ class WebRtcVoiceEngine final : public webrtc::TraceCallback {
rtc::Optional<bool> delay_agnostic_aec_;
rtc::Optional<bool> experimental_ns_;
RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcVoiceEngine);
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcVoiceEngine);
};
// WebRtcVoiceMediaChannel is an implementation of VoiceMediaChannel that uses
@ -157,8 +150,6 @@ class WebRtcVoiceMediaChannel final : public VoiceMediaChannel,
bool PausePlayout();
bool ResumePlayout();
void SetSend(bool send) override;
bool PauseSend();
bool ResumeSend();
bool SetAudioSend(uint32_t ssrc,
bool enable,
const AudioOptions* options,

File diff suppressed because it is too large Load Diff

View File

@ -174,7 +174,7 @@ bool ChannelManager::Init() {
bool ChannelManager::InitMediaEngine_w() {
ASSERT(worker_thread_ == rtc::Thread::Current());
return (media_engine_->Init(worker_thread_));
return media_engine_->Init();
}
void ChannelManager::Terminate() {
@ -200,7 +200,6 @@ void ChannelManager::Terminate_w() {
while (!voice_channels_.empty()) {
DestroyVoiceChannel_w(voice_channels_.back());
}
media_engine_->Terminate();
}
VoiceChannel* ChannelManager::CreateVoiceChannel(

View File

@ -11,6 +11,7 @@
#ifndef WEBRTC_VOICE_ENGINE_CHANNEL_PROXY_H_
#define WEBRTC_VOICE_ENGINE_CHANNEL_PROXY_H_
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/thread_checker.h"
#include "webrtc/voice_engine/channel_manager.h"
#include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
@ -77,6 +78,8 @@ class ChannelProxy {
rtc::ThreadChecker thread_checker_;
ChannelOwner channel_owner_;
RTC_DISALLOW_COPY_AND_ASSIGN(ChannelProxy);
};
} // namespace voe
} // namespace webrtc

View File

@ -132,6 +132,10 @@ class WEBRTC_DLLEXPORT VoEBase {
// Returns NULL before Init() is called.
virtual AudioProcessing* audio_processing() = 0;
// This method is WIP - DO NOT USE!
// Returns NULL before Init() is called.
virtual AudioDeviceModule* audio_device_module() = 0;
// Terminates all VoiceEngine functions and releases allocated resources.
// Returns 0.
virtual int Terminate() = 0;

View File

@ -33,6 +33,9 @@ class VoEBaseImpl : public VoEBase,
AudioProcessing* audio_processing() override {
return shared_->audio_processing();
}
AudioDeviceModule* audio_device_module() override {
return shared_->audio_device();
}
int Terminate() override;
int CreateChannel() override;