Skip to content

Commit

Permalink
Revert "Changes for fake audio on headless platform"
Browse files Browse the repository at this point in the history
This reverts commit 61912d5.

This change introduced too much code in header, and some code doesn't
with 108. Revert it and apply it manually later if it's needed.
  • Loading branch information
jianjunz committed Dec 13, 2022
1 parent 846553f commit d99c35a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 92 deletions.
4 changes: 0 additions & 4 deletions media/engine/webrtc_voice_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "media/engine/webrtc_media_engine.h"
#include "modules/async_audio_processing/async_audio_processing.h"
#include "modules/audio_device/audio_device_impl.h"
#include "modules/audio_device/include/fake_audio_device.h"
#include "modules/audio_mixer/audio_mixer_impl.h"
#include "modules/audio_processing/aec_dump/aec_dump_factory.h"
#include "modules/audio_processing/include/audio_processing.h"
Expand Down Expand Up @@ -359,9 +358,6 @@ void WebRtcVoiceEngine::Init() {
webrtc::AudioDeviceModule::kPlatformDefaultAudio, task_queue_factory_);
}
#endif // WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE
if (!adm_) {
adm_ = new rtc::RefCountedObject<webrtc::FakeAudioDeviceModule>();
}
RTC_CHECK(adm());
webrtc::adm_helpers::Init(adm());

Expand Down
94 changes: 10 additions & 84 deletions modules/audio_device/include/audio_device_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@
#ifndef MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_DEFAULT_H_
#define MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_DEFAULT_H_

#include "modules/audio_device/audio_device_buffer.h"
#include "modules/audio_device/include/audio_device.h"
#include "api/task_queue/default_task_queue_factory.h"
#include "api/task_queue/task_queue_factory.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/time_utils.h"
#include "system_wrappers/include/sleep.h"

namespace webrtc {
namespace webrtc_impl {
Expand All @@ -29,15 +22,11 @@ namespace webrtc_impl {
template <typename T>
class AudioDeviceModuleDefault : public T {
public:
AudioDeviceModuleDefault() {
task_queue_factory = webrtc::CreateDefaultTaskQueueFactory();
audio_device_buffer.reset(new AudioDeviceBuffer(task_queue_factory.get()));
playout_frames_in_10ms = 48000 / 100;
}
AudioDeviceModuleDefault() {}
virtual ~AudioDeviceModuleDefault() {}

int32_t RegisterAudioCallback(AudioTransport* audioCallback) override {
return audio_device_buffer->RegisterAudioCallback(audioCallback);
return 0;
}
int32_t Init() override { return 0; }
int32_t InitSpeaker() override { return 0; }
Expand All @@ -47,17 +36,7 @@ class AudioDeviceModuleDefault : public T {
return 0;
}
int32_t SetStereoPlayout(bool enable) override { return 0; }
int32_t StopPlayout() override {
{
rtc::CritScope lock(&_critSect);
playing = false;
}
if (play_thread.get()) {
play_thread->Stop();
play_thread.reset();
}
return 0;
}
int32_t StopPlayout() override { return 0; }
int32_t InitMicrophone() override { return 0; }
int32_t SetRecordingDevice(uint16_t index) override { return 0; }
int32_t SetRecordingDevice(
Expand Down Expand Up @@ -86,35 +65,16 @@ class AudioDeviceModuleDefault : public T {
char guid[kAdmMaxGuidSize]) override {
return 0;
}
int32_t PlayoutIsAvailable(bool* available) override {
*available = true;
return 0;
}
int32_t InitPlayout() override {
rtc::CritScope lock(&_critSect);
if (audio_device_buffer.get()) {
audio_device_buffer->SetPlayoutSampleRate(48000);
audio_device_buffer->SetPlayoutChannels(2);
}
return 0;
}
int32_t PlayoutIsAvailable(bool* available) override { return 0; }
int32_t InitPlayout() override { return 0; }
bool PlayoutIsInitialized() const override { return true; }
int32_t RecordingIsAvailable(bool* available) override { return 0; }
int32_t InitRecording() override { return 0; }
bool RecordingIsInitialized() const override { return true; }
int32_t StartPlayout() override {
if (playing)
return 0;

playing = true;
play_thread.reset(new rtc::PlatformThread(PlayThreadFunc,
this, "fake_audio_play_thread", rtc::kRealtimePriority));
play_thread->Start();
return 0;
}
bool Playing() const override { return playing; }
int32_t StartPlayout() override { return 0; }
bool Playing() const override { return false; }
int32_t StartRecording() override { return 0; }
bool Recording() const override { return true; }
bool Recording() const override { return false; }
bool SpeakerIsInitialized() const override { return true; }
bool MicrophoneIsInitialized() const override { return true; }
int32_t SpeakerVolumeIsAvailable(bool* available) override { return 0; }
Expand All @@ -134,12 +94,12 @@ class AudioDeviceModuleDefault : public T {
int32_t SetMicrophoneMute(bool enable) override { return 0; }
int32_t MicrophoneMute(bool* enabled) const override { return 0; }
int32_t StereoPlayoutIsAvailable(bool* available) const override {
*available = true;
*available = false;
return 0;
}
int32_t StereoPlayout(bool* enabled) const override { return 0; }
int32_t StereoRecordingIsAvailable(bool* available) const override {
*available = true;
*available = false;
return 0;
}
int32_t StereoRecording(bool* enabled) const override { return 0; }
Expand All @@ -156,40 +116,6 @@ class AudioDeviceModuleDefault : public T {

int32_t GetPlayoutUnderrunCount() const override { return -1; }

bool PlayThreadProcess() {
if (!playing)
return false;
int64_t current_time = rtc::TimeMillis();

_critSect.Enter();
if (last_call_millis == 0 ||
current_time - last_call_millis >= 10) {
_critSect.Leave();
audio_device_buffer->RequestPlayoutData(playout_frames_in_10ms);
_critSect.Enter();
last_call_millis = current_time;
}
_critSect.Leave();
int64_t delta_time = rtc::TimeMillis() - current_time;
if (delta_time < 10) {
SleepMs(10 - delta_time);
}
return true;
}

static void PlayThreadFunc(void* pThis) {
AudioDeviceModuleDefault* device = static_cast<AudioDeviceModuleDefault*>(pThis);
while (device->PlayThreadProcess()) {
}
}
std::unique_ptr<AudioDeviceBuffer> audio_device_buffer;
std::unique_ptr<rtc::PlatformThread> play_thread;
size_t playout_frames_in_10ms;
rtc::CriticalSection _critSect;
bool playing = false;
int64_t last_call_millis = 0;
std::unique_ptr<webrtc::TaskQueueFactory> task_queue_factory;

#if defined(WEBRTC_IOS)
int GetPlayoutAudioParameters(AudioParameters* params) const override {
return -1;
Expand Down
4 changes: 0 additions & 4 deletions modules/audio_processing/audio_processing_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1790,9 +1790,6 @@ void AudioProcessingImpl::InitializeHighPassFilter(bool forced_reset) {
}

void AudioProcessingImpl::InitializeEchoController() {
#if defined(WEBRTC_LINUX)
return;
#else
bool use_echo_controller =
echo_control_factory_ ||
(config_.echo_canceller.enabled && !config_.echo_canceller.mobile_mode);
Expand Down Expand Up @@ -1869,7 +1866,6 @@ void AudioProcessingImpl::InitializeEchoController() {

submodules_.echo_control_mobile.reset();
aecm_render_signal_queue_.reset();
#endif
}

void AudioProcessingImpl::InitializeGainController1() {
Expand Down

0 comments on commit d99c35a

Please sign in to comment.