Activate 'offload debug dump recordings from audio thread to TaskQueue'.

A low priority task queue is added to WebRTCVoiceEngine. The
start/stop debug calls make file logging happen on the task queue.

In a dependent CL (https://codereview.webrtc.org/2888303003), the task queue is moved to PeerConnectionFactory,
so that it can be shared for low priority tasks between different
subcomponents. It will require some changes to MediaEngine,
CompositeMediaEngine, WebRTCVoiceEngine, and changes in internal
projects.

A task queue must be created and destroyed from the same thread. With
this CL that will be the worker thread, which creates and destroys
WebRTCVoiceEngine. With the dependent CL, it will probably change to
the signaling thread.

NOTRY=True # tests just passed

BUG=webrtc:7404

Review-Url: https://codereview.webrtc.org/2896813002
Cr-Commit-Position: refs/heads/master@{#18252}
This commit is contained in:
aleloi 2017-05-24 01:47:18 -07:00 committed by Commit bot
parent d5115e0cac
commit c61bf947b4
4 changed files with 25 additions and 29 deletions

View File

@ -220,6 +220,11 @@ rtc_static_library("rtc_media") {
public_configs += [ ":rtc_media_defines_config" ]
deps += [ "../modules/video_capture:video_capture_internal_impl" ]
}
if (rtc_enable_protobuf) {
deps += [ "../modules/audio_processing/aec_dump:aec_dump_impl" ]
} else {
deps += [ "../modules/audio_processing/aec_dump:null_aec_dump_factory" ]
}
deps += [
":rtc_media_base",
"..:webrtc_common",
@ -237,6 +242,7 @@ rtc_static_library("rtc_media") {
"../modules/audio_device:audio_device",
"../modules/audio_mixer:audio_mixer_impl",
"../modules/audio_processing:audio_processing",
"../modules/audio_processing/aec_dump",
"../modules/video_capture:video_capture_module",
"../modules/video_coding",
"../modules/video_coding:webrtc_h264",

View File

@ -38,6 +38,7 @@
#include "webrtc/media/engine/webrtcmediaengine.h"
#include "webrtc/media/engine/webrtcvoe.h"
#include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
#include "webrtc/modules/audio_processing/aec_dump/aec_dump_factory.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h"
#include "webrtc/system_wrappers/include/field_trial.h"
#include "webrtc/system_wrappers/include/metrics.h"
@ -228,7 +229,8 @@ WebRtcVoiceEngine::WebRtcVoiceEngine(
const rtc::scoped_refptr<webrtc::AudioDecoderFactory>& decoder_factory,
rtc::scoped_refptr<webrtc::AudioMixer> audio_mixer,
VoEWrapper* voe_wrapper)
: adm_(adm),
: low_priority_worker_queue_("rtc-low-prio", rtc::TaskQueue::Priority::LOW),
adm_(adm),
encoder_factory_(encoder_factory),
decoder_factory_(decoder_factory),
voe_wrapper_(voe_wrapper) {
@ -687,46 +689,28 @@ void WebRtcVoiceEngine::UnregisterChannel(WebRtcVoiceMediaChannel* channel) {
bool WebRtcVoiceEngine::StartAecDump(rtc::PlatformFile file,
int64_t max_size_bytes) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
FILE* aec_dump_file_stream = rtc::FdopenPlatformFileForWriting(file);
if (!aec_dump_file_stream) {
LOG(LS_ERROR) << "Could not open AEC dump file stream.";
if (!rtc::ClosePlatformFile(file))
LOG(LS_WARNING) << "Could not close file.";
auto aec_dump = webrtc::AecDumpFactory::Create(file, max_size_bytes,
&low_priority_worker_queue_);
if (!aec_dump) {
return false;
}
StopAecDump();
if (apm()->StartDebugRecording(aec_dump_file_stream, max_size_bytes) !=
webrtc::AudioProcessing::kNoError) {
LOG_RTCERR0(StartDebugRecording);
fclose(aec_dump_file_stream);
return false;
}
is_dumping_aec_ = true;
apm()->AttachAecDump(std::move(aec_dump));
return true;
}
void WebRtcVoiceEngine::StartAecDump(const std::string& filename) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
if (!is_dumping_aec_) {
// Start dumping AEC when we are not dumping.
if (apm()->StartDebugRecording(filename.c_str(), -1) !=
webrtc::AudioProcessing::kNoError) {
LOG_RTCERR1(StartDebugRecording, filename.c_str());
} else {
is_dumping_aec_ = true;
}
auto aec_dump =
webrtc::AecDumpFactory::Create(filename, -1, &low_priority_worker_queue_);
if (aec_dump) {
apm()->AttachAecDump(std::move(aec_dump));
}
}
void WebRtcVoiceEngine::StopAecDump() {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
if (is_dumping_aec_) {
// Stop dumping AEC when we are dumping.
if (apm()->StopDebugRecording() != webrtc::AudioProcessing::kNoError) {
LOG_RTCERR0(StopDebugRecording);
}
is_dumping_aec_ = false;
}
apm()->DetachAecDump();
}
int WebRtcVoiceEngine::CreateVoEChannel() {

View File

@ -22,6 +22,7 @@
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/networkroute.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/base/task_queue.h"
#include "webrtc/base/thread_checker.h"
#include "webrtc/call/audio_state.h"
#include "webrtc/call/call.h"
@ -110,6 +111,9 @@ class WebRtcVoiceEngine final : public webrtc::TraceCallback {
void StartAecDump(const std::string& filename);
int CreateVoEChannel();
rtc::TaskQueue low_priority_worker_queue_;
webrtc::AudioDeviceModule* adm();
webrtc::AudioProcessing* apm();
webrtc::voe::TransmitMixer* transmit_mixer();

View File

@ -125,6 +125,7 @@ TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) {
EXPECT_CALL(apm, ApplyConfig(testing::_));
EXPECT_CALL(apm, SetExtraOptions(testing::_));
EXPECT_CALL(apm, Initialize()).WillOnce(Return(0));
EXPECT_CALL(apm, DetachAecDump());
StrictMock<MockTransmitMixer> transmit_mixer;
EXPECT_CALL(transmit_mixer, EnableStereoChannelSwapping(false));
cricket::FakeWebRtcVoiceEngine voe(&apm, &transmit_mixer);
@ -163,6 +164,7 @@ class WebRtcVoiceEngineTestFake : public testing::Test {
EXPECT_CALL(apm_, ApplyConfig(testing::_));
EXPECT_CALL(apm_, SetExtraOptions(testing::_));
EXPECT_CALL(apm_, Initialize()).WillOnce(Return(0));
EXPECT_CALL(apm_, DetachAecDump());
// Default Options.
EXPECT_CALL(apm_ec_, Enable(true)).WillOnce(Return(0));
EXPECT_CALL(apm_ec_, enable_metrics(true)).WillOnce(Return(0));