Remove VoEHardware interface.

BUG=webrtc:4690

Review-Url: https://codereview.webrtc.org/2753753004
Cr-Commit-Position: refs/heads/master@{#17255}
This commit is contained in:
solenberg 2017-03-15 08:08:07 -07:00 committed by Commit bot
parent 0cf3aa6d0d
commit 5b3e49a29e
15 changed files with 2 additions and 919 deletions

View File

@ -78,7 +78,6 @@ rtc_static_library("voice_engine") {
"include/voe_codec.h",
"include/voe_errors.h",
"include/voe_file.h",
"include/voe_hardware.h",
"include/voe_network.h",
"include/voe_rtp_rtcp.h",
"monitor_module.h",
@ -100,8 +99,6 @@ rtc_static_library("voice_engine") {
"voe_codec_impl.h",
"voe_file_impl.cc",
"voe_file_impl.h",
"voe_hardware_impl.cc",
"voe_hardware_impl.h",
"voe_network_impl.cc",
"voe_network_impl.h",
"voe_rtp_rtcp_impl.cc",
@ -272,8 +269,6 @@ if (rtc_include_tests) {
"test/auto_test/standard/dtmf_test.cc",
"test/auto_test/standard/file_before_streaming_test.cc",
"test/auto_test/standard/file_test.cc",
"test/auto_test/standard/hardware_before_initializing_test.cc",
"test/auto_test/standard/hardware_test.cc",
"test/auto_test/standard/mixing_test.cc",
"test/auto_test/standard/rtp_rtcp_before_streaming_test.cc",
"test/auto_test/standard/rtp_rtcp_extensions.cc",
@ -285,12 +280,6 @@ if (rtc_include_tests) {
"test/auto_test/voe_test_defines.h",
]
if (!is_android) {
# Some tests are not supported on android yet, exclude these tests.
sources +=
[ "test/auto_test/standard/hardware_before_streaming_test.cc" ]
}
defines = []
if (rtc_enable_protobuf) {

View File

@ -1,109 +0,0 @@
/*
* Copyright (c) 2011 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:
//
// - Audio device handling.
// - Device information.
// - CPU load monitoring.
//
// Usage example, omitting error checking:
//
// using namespace webrtc;
// VoiceEngine* voe = VoiceEngine::Create();
// VoEBase* base = VoEBase::GetInterface(voe);
// VoEHardware* hardware = VoEHardware::GetInterface(voe);
// base->Init();
// ...
// int n_devices = hardware->GetNumOfPlayoutDevices();
// ...
// base->Terminate();
// base->Release();
// hardware->Release();
// VoiceEngine::Delete(voe);
//
#ifndef WEBRTC_VOICE_ENGINE_VOE_HARDWARE_H
#define WEBRTC_VOICE_ENGINE_VOE_HARDWARE_H
#include "webrtc/common_types.h"
namespace webrtc {
class VoiceEngine;
class WEBRTC_DLLEXPORT VoEHardware {
public:
// Factory for the VoEHardware sub-API. Increases an internal
// reference counter if successful. Returns NULL if the API is not
// supported or if construction fails.
static VoEHardware* GetInterface(VoiceEngine* voiceEngine);
// Releases the VoEHardware 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 audio devices available for recording.
virtual int GetNumOfRecordingDevices(int& devices) = 0;
// Gets the number of audio devices available for playout.
virtual int GetNumOfPlayoutDevices(int& devices) = 0;
// Gets the name of a specific recording device given by an |index|.
// On Windows Vista/7, it also retrieves an additional unique ID
// (GUID) for the recording device.
virtual int GetRecordingDeviceName(int index,
char strNameUTF8[128],
char strGuidUTF8[128]) = 0;
// Gets the name of a specific playout device given by an |index|.
// On Windows Vista/7, it also retrieves an additional unique ID
// (GUID) for the playout device.
virtual int GetPlayoutDeviceName(int index,
char strNameUTF8[128],
char strGuidUTF8[128]) = 0;
// Sets the audio device used for recording.
virtual int SetRecordingDevice(
int index,
StereoChannel recordingChannel = kStereoBoth) = 0;
// Sets the audio device used for playout.
virtual int SetPlayoutDevice(int index) = 0;
// Sets the type of audio device layer to use.
virtual int SetAudioDeviceLayer(AudioLayers audioLayer) = 0;
// Gets the currently used (active) audio device layer.
virtual int GetAudioDeviceLayer(AudioLayers& audioLayer) = 0;
// Native sample rate controls (samples/sec)
virtual int SetRecordingSampleRate(unsigned int samples_per_sec) = 0;
virtual int RecordingSampleRate(unsigned int* samples_per_sec) const = 0;
virtual int SetPlayoutSampleRate(unsigned int samples_per_sec) = 0;
virtual int PlayoutSampleRate(unsigned int* samples_per_sec) const = 0;
// Queries and controls platform audio effects on Android devices.
virtual bool BuiltInAECIsAvailable() const = 0;
virtual int EnableBuiltInAEC(bool enable) = 0;
virtual bool BuiltInAGCIsAvailable() const = 0;
virtual int EnableBuiltInAGC(bool enable) = 0;
virtual bool BuiltInNSIsAvailable() const = 0;
virtual int EnableBuiltInNS(bool enable) = 0;
protected:
VoEHardware() {}
virtual ~VoEHardware() {}
};
} // namespace webrtc
#endif // WEBRTC_VOICE_ENGINE_VOE_HARDWARE_H

View File

@ -40,7 +40,6 @@ SharedData::SharedData()
_engineStatistics,
_channelManager);
}
_audioDeviceLayer = AudioDeviceModule::kPlatformDefaultAudio;
}
SharedData::~SharedData()

View File

@ -46,12 +46,6 @@ public:
OutputMixer* output_mixer() { return _outputMixerPtr; }
rtc::CriticalSection* crit_sec() { return &_apiCritPtr; }
ProcessThread* process_thread() { return _moduleProcessThreadPtr.get(); }
AudioDeviceModule::AudioLayer audio_device_layer() const {
return _audioDeviceLayer;
}
void set_audio_device_layer(AudioDeviceModule::AudioLayer layer) {
_audioDeviceLayer = layer;
}
int NumOfSendingChannels();
int NumOfPlayingChannels();
@ -73,8 +67,6 @@ protected:
std::unique_ptr<AudioProcessing> audioproc_;
std::unique_ptr<ProcessThread> _moduleProcessThreadPtr;
AudioDeviceModule::AudioLayer _audioDeviceLayer;
SharedData();
virtual ~SharedData();
};

View File

@ -21,7 +21,6 @@ BeforeInitializationFixture::BeforeInitializationFixture()
voe_rtp_rtcp_ = webrtc::VoERTP_RTCP::GetInterface(voice_engine_);
voe_network_ = webrtc::VoENetwork::GetInterface(voice_engine_);
voe_file_ = webrtc::VoEFile::GetInterface(voice_engine_);
voe_hardware_ = webrtc::VoEHardware::GetInterface(voice_engine_);
}
BeforeInitializationFixture::~BeforeInitializationFixture() {
@ -30,7 +29,6 @@ BeforeInitializationFixture::~BeforeInitializationFixture() {
voe_rtp_rtcp_->Release();
voe_network_->Release();
voe_file_->Release();
voe_hardware_->Release();
EXPECT_TRUE(webrtc::VoiceEngine::Delete(voice_engine_));
}

View File

@ -19,7 +19,6 @@
#include "webrtc/voice_engine/include/voe_codec.h"
#include "webrtc/voice_engine/include/voe_errors.h"
#include "webrtc/voice_engine/include/voe_file.h"
#include "webrtc/voice_engine/include/voe_hardware.h"
#include "webrtc/voice_engine/include/voe_network.h"
#include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
#include "webrtc/voice_engine/test/auto_test/voe_test_common.h"
@ -50,7 +49,6 @@ class BeforeInitializationFixture : public testing::Test {
webrtc::VoERTP_RTCP* voe_rtp_rtcp_;
webrtc::VoENetwork* voe_network_;
webrtc::VoEFile* voe_file_;
webrtc::VoEHardware* voe_hardware_;
};
#endif // SRC_VOICE_ENGINE_MAIN_TEST_AUTO_TEST_STANDARD_TEST_BASE_H_

View File

@ -1,27 +0,0 @@
/*
* Copyright (c) 2011 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 "webrtc/common_types.h"
#include "webrtc/voice_engine/test/auto_test/fixtures/before_initialization_fixture.h"
using namespace webrtc;
class HardwareBeforeInitializingTest : public BeforeInitializationFixture {
};
TEST_F(HardwareBeforeInitializingTest,
SetAudioDeviceLayerAcceptsPlatformDefaultBeforeInitializing) {
AudioLayers wanted_layer = kAudioPlatformDefault;
AudioLayers given_layer;
EXPECT_EQ(0, voe_hardware_->SetAudioDeviceLayer(wanted_layer));
EXPECT_EQ(0, voe_hardware_->GetAudioDeviceLayer(given_layer));
EXPECT_EQ(wanted_layer, given_layer) <<
"These should be the same before initializing.";
}

View File

@ -1,122 +0,0 @@
/*
* Copyright (c) 2011 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 <string.h>
#include "webrtc/voice_engine/test/auto_test/fixtures/after_initialization_fixture.h"
using namespace webrtc;
class HardwareBeforeStreamingTest : public AfterInitializationFixture {
};
// Tests that apply to both mobile and desktop:
TEST_F(HardwareBeforeStreamingTest,
SetAudioDeviceLayerFailsSinceTheVoiceEngineHasBeenInitialized) {
EXPECT_NE(0, voe_hardware_->SetAudioDeviceLayer(kAudioPlatformDefault));
EXPECT_EQ(VE_ALREADY_INITED, voe_base_->LastError());
}
// Tests that only apply to desktop:
#if !defined(WEBRTC_IOS) & !defined(WEBRTC_ANDROID)
static const char* kNoDevicesErrorMessage =
"Either you have no recording / playout device "
"on your system, or the method failed.";
// Win, Mac and Linux sound device tests.
TEST_F(HardwareBeforeStreamingTest,
GetRecordingDeviceNameRetrievesDeviceNames) {
char device_name[128] = {0};
char guid_name[128] = {0};
#ifdef _WIN32
EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
-1, device_name, guid_name));
EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
device_name[0] = '\0';
EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
-1, device_name, guid_name));
EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
#else
EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
0, device_name, guid_name));
EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
device_name[0] = '\0';
EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
0, device_name, guid_name));
EXPECT_GT(strlen(device_name), 0u) << kNoDevicesErrorMessage;
#endif // !WIN32
}
TEST_F(HardwareBeforeStreamingTest,
AllEnumeratedRecordingDevicesCanBeSetAsRecordingDevice) {
// Check recording side.
// Extended Win32 enumeration tests: unique GUID outputs on Vista and up:
// Win XP and below : device_name is copied to guid_name.
// Win Vista and up : device_name is the friendly name and GUID is a unique
// identifier.
// Other : guid_name is left unchanged.
int num_of_recording_devices = 0;
EXPECT_EQ(0, voe_hardware_->GetNumOfRecordingDevices(
num_of_recording_devices));
EXPECT_GT(num_of_recording_devices, 0) << kNoDevicesErrorMessage;
char device_name[128] = {0};
char guid_name[128] = {0};
for (int i = 0; i < num_of_recording_devices; i++) {
EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
i, device_name, guid_name));
EXPECT_GT(strlen(device_name), 0u) <<
"There should be no empty device names "
"among the ones the system gives us.";
EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(i));
}
}
TEST_F(HardwareBeforeStreamingTest,
AllEnumeratedPlayoutDevicesCanBeSetAsPlayoutDevice) {
// Check playout side (see recording side test for more info on GUIDs).
int num_of_playout_devices = 0;
EXPECT_EQ(0, voe_hardware_->GetNumOfPlayoutDevices(
num_of_playout_devices));
EXPECT_GT(num_of_playout_devices, 0) << kNoDevicesErrorMessage;
char device_name[128] = {0};
char guid_name[128] = {0};
for (int i = 0; i < num_of_playout_devices; ++i) {
EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
i, device_name, guid_name));
EXPECT_GT(strlen(device_name), 0u) <<
"There should be no empty device names "
"among the ones the system gives us.";
EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(i));
}
}
TEST_F(HardwareBeforeStreamingTest,
SetDeviceWithMagicalArgumentsSetsDefaultSoundDevices) {
#ifdef _WIN32
// -1 means "default device" on Windows.
EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(-1));
EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(-1));
#else
EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(0));
EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(0));
#endif
}
#endif // !defined(WEBRTC_IOS) & !defined(WEBRTC_ANDROID)

View File

@ -1,55 +0,0 @@
/*
* Copyright (c) 2011 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 "webrtc/modules/audio_device/include/audio_device.h"
#include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
class HardwareTest : public AfterStreamingFixture {
};
#if !defined(WEBRTC_IOS) && !defined(WEBRTC_ANDROID)
TEST_F(HardwareTest, AbleToQueryForDevices) {
int num_recording_devices = 0;
int num_playout_devices = 0;
EXPECT_EQ(0, voe_hardware_->GetNumOfRecordingDevices(num_recording_devices));
EXPECT_EQ(0, voe_hardware_->GetNumOfPlayoutDevices(num_playout_devices));
ASSERT_GT(num_recording_devices, 0) <<
"There seem to be no recording devices on your system, "
"and this test really doesn't make sense then.";
ASSERT_GT(num_playout_devices, 0) <<
"There seem to be no playout devices on your system, "
"and this test really doesn't make sense then.";
// Recording devices are handled a bit differently on Windows - we can
// just tell it to set the 'default' communication device there.
#ifdef _WIN32
// Should also work while already recording.
EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(
webrtc::AudioDeviceModule::kDefaultCommunicationDevice));
// Should also work while already playing.
EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(
webrtc::AudioDeviceModule::kDefaultCommunicationDevice));
#else
// For other platforms, just use the first device encountered.
EXPECT_EQ(0, voe_hardware_->SetRecordingDevice(0));
EXPECT_EQ(0, voe_hardware_->SetPlayoutDevice(0));
#endif
// It's hard to know what names this will return (it's system-dependent),
// so just check that it's possible to do it.
char device_name[128] = {0};
char guid_name[128] = {0};
EXPECT_EQ(0, voe_hardware_->GetRecordingDeviceName(
0, device_name, guid_name));
EXPECT_EQ(0, voe_hardware_->GetPlayoutDeviceName(
0, device_name, guid_name));
}
#endif

View File

@ -18,19 +18,10 @@
// settings in voice_engine_configurations.h.
#define _TEST_BASE_
#define _TEST_RTP_RTCP_
#define _TEST_HARDWARE_
#define _TEST_CODEC_
#define _TEST_FILE_
#define _TEST_NETWORK_
#define TESTED_AUDIO_LAYER kAudioPlatformDefault
//#define TESTED_AUDIO_LAYER kAudioLinuxPulse
// #define _ENABLE_VISUAL_LEAK_DETECTOR_ // Enables VLD to find memory leaks
// #define _ENABLE_IPV6_TESTS_ // Enables IPv6 tests in network xtest
// #define _USE_EXTENDED_TRACE_ // Adds unique trace files for extended test
// #define _MEMORY_TEST_
// Enable this when running instrumentation of some kind to exclude tests
// that will not pass due to slowed down execution.
// #define _INSTRUMENTATION_TESTING_

View File

@ -196,8 +196,8 @@ int VoEBaseImpl::Init(
#else
// Create the internal ADM implementation.
shared_->set_audio_device(AudioDeviceModule::Create(
VoEId(shared_->instance_id(), -1), shared_->audio_device_layer()));
VoEId(shared_->instance_id(), -1),
AudioDeviceModule::kPlatformDefaultAudio));
if (shared_->audio_device() == nullptr) {
shared_->SetLastError(VE_NO_MEMORY, kTraceCritical,
"Init() failed to create the ADM");

View File

@ -15,7 +15,6 @@
#include "webrtc/modules/audio_device/include/fake_audio_device.h"
#include "webrtc/test/gtest.h"
#include "webrtc/voice_engine/include/voe_base.h"
#include "webrtc/voice_engine/include/voe_hardware.h"
#include "webrtc/voice_engine/voice_engine_defines.h"
namespace webrtc {

View File

@ -1,502 +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 "webrtc/voice_engine/voe_hardware_impl.h"
#include <assert.h>
#include "webrtc/system_wrappers/include/trace.h"
#include "webrtc/voice_engine/include/voe_errors.h"
#include "webrtc/voice_engine/voice_engine_impl.h"
namespace webrtc {
VoEHardware* VoEHardware::GetInterface(VoiceEngine* voiceEngine) {
if (NULL == voiceEngine) {
return NULL;
}
VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
s->AddRef();
return s;
}
VoEHardwareImpl::VoEHardwareImpl(voe::SharedData* shared) : _shared(shared) {
WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
"VoEHardwareImpl() - ctor");
}
VoEHardwareImpl::~VoEHardwareImpl() {
WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
"~VoEHardwareImpl() - dtor");
}
int VoEHardwareImpl::SetAudioDeviceLayer(AudioLayers audioLayer) {
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"SetAudioDeviceLayer(audioLayer=%d)", audioLayer);
// Don't allow a change if VoE is initialized
if (_shared->statistics().Initialized()) {
_shared->SetLastError(VE_ALREADY_INITED, kTraceError);
return -1;
}
// Map to AudioDeviceModule::AudioLayer
AudioDeviceModule::AudioLayer wantedLayer(
AudioDeviceModule::kPlatformDefaultAudio);
switch (audioLayer) {
case kAudioPlatformDefault:
// already set above
break;
case kAudioWindowsCore:
wantedLayer = AudioDeviceModule::kWindowsCoreAudio;
break;
case kAudioLinuxAlsa:
wantedLayer = AudioDeviceModule::kLinuxAlsaAudio;
break;
case kAudioLinuxPulse:
wantedLayer = AudioDeviceModule::kLinuxPulseAudio;
break;
}
// Save the audio device layer for Init()
_shared->set_audio_device_layer(wantedLayer);
return 0;
}
int VoEHardwareImpl::GetAudioDeviceLayer(AudioLayers& audioLayer) {
// Can always be called regardless of VoE state
AudioDeviceModule::AudioLayer activeLayer(
AudioDeviceModule::kPlatformDefaultAudio);
if (_shared->audio_device()) {
// Get active audio layer from ADM
if (_shared->audio_device()->ActiveAudioLayer(&activeLayer) != 0) {
_shared->SetLastError(VE_UNDEFINED_SC_ERR, kTraceError,
" Audio Device error");
return -1;
}
} else {
// Return VoE's internal layer setting
activeLayer = _shared->audio_device_layer();
}
// Map to AudioLayers
switch (activeLayer) {
case AudioDeviceModule::kPlatformDefaultAudio:
audioLayer = kAudioPlatformDefault;
break;
case AudioDeviceModule::kWindowsCoreAudio:
audioLayer = kAudioWindowsCore;
break;
case AudioDeviceModule::kLinuxAlsaAudio:
audioLayer = kAudioLinuxAlsa;
break;
case AudioDeviceModule::kLinuxPulseAudio:
audioLayer = kAudioLinuxPulse;
break;
default:
_shared->SetLastError(VE_UNDEFINED_SC_ERR, kTraceError,
" unknown audio layer");
}
return 0;
}
int VoEHardwareImpl::GetNumOfRecordingDevices(int& devices) {
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
devices = static_cast<int>(_shared->audio_device()->RecordingDevices());
return 0;
}
int VoEHardwareImpl::GetNumOfPlayoutDevices(int& devices) {
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
devices = static_cast<int>(_shared->audio_device()->PlayoutDevices());
return 0;
}
int VoEHardwareImpl::GetRecordingDeviceName(int index,
char strNameUTF8[128],
char strGuidUTF8[128]) {
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
if (strNameUTF8 == NULL) {
_shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
"GetRecordingDeviceName() invalid argument");
return -1;
}
// Note that strGuidUTF8 is allowed to be NULL
// Init len variable to length of supplied vectors
const uint16_t strLen = 128;
// Check if length has been changed in module
static_assert(strLen == kAdmMaxDeviceNameSize, "");
static_assert(strLen == kAdmMaxGuidSize, "");
char name[strLen];
char guid[strLen];
// Get names from module
if (_shared->audio_device()->RecordingDeviceName(index, name, guid) != 0) {
_shared->SetLastError(VE_CANNOT_RETRIEVE_DEVICE_NAME, kTraceError,
"GetRecordingDeviceName() failed to get device name");
return -1;
}
// Copy to vectors supplied by user
strncpy(strNameUTF8, name, strLen);
if (strGuidUTF8 != NULL) {
strncpy(strGuidUTF8, guid, strLen);
}
return 0;
}
int VoEHardwareImpl::GetPlayoutDeviceName(int index,
char strNameUTF8[128],
char strGuidUTF8[128]) {
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
if (strNameUTF8 == NULL) {
_shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError,
"GetPlayoutDeviceName() invalid argument");
return -1;
}
// Note that strGuidUTF8 is allowed to be NULL
// Init len variable to length of supplied vectors
const uint16_t strLen = 128;
// Check if length has been changed in module
static_assert(strLen == kAdmMaxDeviceNameSize, "");
static_assert(strLen == kAdmMaxGuidSize, "");
char name[strLen];
char guid[strLen];
// Get names from module
if (_shared->audio_device()->PlayoutDeviceName(index, name, guid) != 0) {
_shared->SetLastError(VE_CANNOT_RETRIEVE_DEVICE_NAME, kTraceError,
"GetPlayoutDeviceName() failed to get device name");
return -1;
}
// Copy to vectors supplied by user
strncpy(strNameUTF8, name, strLen);
if (strGuidUTF8 != NULL) {
strncpy(strGuidUTF8, guid, strLen);
}
return 0;
}
int VoEHardwareImpl::SetRecordingDevice(int index,
StereoChannel recordingChannel) {
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"SetRecordingDevice(index=%d, recordingChannel=%d)", index,
(int)recordingChannel);
rtc::CritScope cs(_shared->crit_sec());
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
bool isRecording(false);
// Store state about activated recording to be able to restore it after the
// recording device has been modified.
if (_shared->audio_device()->Recording()) {
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
"SetRecordingDevice() device is modified while recording"
" is active...");
isRecording = true;
if (_shared->audio_device()->StopRecording() == -1) {
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
"SetRecordingDevice() unable to stop recording");
return -1;
}
}
// We let the module do the index sanity
// Set recording channel
AudioDeviceModule::ChannelType recCh = AudioDeviceModule::kChannelBoth;
switch (recordingChannel) {
case kStereoLeft:
recCh = AudioDeviceModule::kChannelLeft;
break;
case kStereoRight:
recCh = AudioDeviceModule::kChannelRight;
break;
case kStereoBoth:
// default setting kChannelBoth (<=> mono)
break;
}
if (_shared->audio_device()->SetRecordingChannel(recCh) != 0) {
_shared->SetLastError(
VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning,
"SetRecordingChannel() unable to set the recording channel");
}
// Map indices to unsigned since underlying functions need that
uint16_t indexU = static_cast<uint16_t>(index);
int32_t res(0);
if (index == -1) {
res = _shared->audio_device()->SetRecordingDevice(
AudioDeviceModule::kDefaultCommunicationDevice);
} else if (index == -2) {
res = _shared->audio_device()->SetRecordingDevice(
AudioDeviceModule::kDefaultDevice);
} else {
res = _shared->audio_device()->SetRecordingDevice(indexU);
}
if (res != 0) {
_shared->SetLastError(
VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
"SetRecordingDevice() unable to set the recording device");
return -1;
}
// Init microphone, so user can do volume settings etc
if (_shared->audio_device()->InitMicrophone() == -1) {
_shared->SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceWarning,
"SetRecordingDevice() cannot access microphone");
}
// Set number of channels
bool available = false;
if (_shared->audio_device()->StereoRecordingIsAvailable(&available) != 0) {
_shared->SetLastError(
VE_SOUNDCARD_ERROR, kTraceWarning,
"StereoRecordingIsAvailable() failed to query stereo recording");
}
if (_shared->audio_device()->SetStereoRecording(available) != 0) {
_shared->SetLastError(
VE_SOUNDCARD_ERROR, kTraceWarning,
"SetRecordingDevice() failed to set mono recording mode");
}
// Restore recording if it was enabled already when calling this function.
if (isRecording) {
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
"SetRecordingDevice() recording is now being restored...");
if (_shared->audio_device()->InitRecording() != 0) {
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"SetRecordingDevice() failed to initialize recording");
return -1;
}
if (_shared->audio_device()->StartRecording() != 0) {
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"SetRecordingDevice() failed to start recording");
return -1;
}
}
return 0;
}
int VoEHardwareImpl::SetPlayoutDevice(int index) {
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"SetPlayoutDevice(index=%d)", index);
rtc::CritScope cs(_shared->crit_sec());
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
bool isPlaying(false);
// Store state about activated playout to be able to restore it after the
// playout device has been modified.
if (_shared->audio_device()->Playing()) {
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
"SetPlayoutDevice() device is modified while playout is "
"active...");
isPlaying = true;
if (_shared->audio_device()->StopPlayout() == -1) {
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
"SetPlayoutDevice() unable to stop playout");
return -1;
}
}
// We let the module do the index sanity
// Map indices to unsigned since underlying functions need that
uint16_t indexU = static_cast<uint16_t>(index);
int32_t res(0);
if (index == -1) {
res = _shared->audio_device()->SetPlayoutDevice(
AudioDeviceModule::kDefaultCommunicationDevice);
} else if (index == -2) {
res = _shared->audio_device()->SetPlayoutDevice(
AudioDeviceModule::kDefaultDevice);
} else {
res = _shared->audio_device()->SetPlayoutDevice(indexU);
}
if (res != 0) {
_shared->SetLastError(
VE_SOUNDCARD_ERROR, kTraceError,
"SetPlayoutDevice() unable to set the playout device");
return -1;
}
// Init speaker, so user can do volume settings etc
if (_shared->audio_device()->InitSpeaker() == -1) {
_shared->SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, kTraceWarning,
"SetPlayoutDevice() cannot access speaker");
}
// Set number of channels
bool available = false;
_shared->audio_device()->StereoPlayoutIsAvailable(&available);
if (_shared->audio_device()->SetStereoPlayout(available) != 0) {
_shared->SetLastError(
VE_SOUNDCARD_ERROR, kTraceWarning,
"SetPlayoutDevice() failed to set stereo playout mode");
}
// Restore playout if it was enabled already when calling this function.
if (isPlaying) {
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
"SetPlayoutDevice() playout is now being restored...");
if (_shared->audio_device()->InitPlayout() != 0) {
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"SetPlayoutDevice() failed to initialize playout");
return -1;
}
if (_shared->audio_device()->StartPlayout() != 0) {
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"SetPlayoutDevice() failed to start playout");
return -1;
}
}
return 0;
}
int VoEHardwareImpl::SetRecordingSampleRate(unsigned int samples_per_sec) {
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"%s", __FUNCTION__);
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return false;
}
return _shared->audio_device()->SetRecordingSampleRate(samples_per_sec);
}
int VoEHardwareImpl::RecordingSampleRate(unsigned int* samples_per_sec) const {
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return false;
}
return _shared->audio_device()->RecordingSampleRate(samples_per_sec);
}
int VoEHardwareImpl::SetPlayoutSampleRate(unsigned int samples_per_sec) {
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"%s", __FUNCTION__);
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return false;
}
return _shared->audio_device()->SetPlayoutSampleRate(samples_per_sec);
}
int VoEHardwareImpl::PlayoutSampleRate(unsigned int* samples_per_sec) const {
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return false;
}
return _shared->audio_device()->PlayoutSampleRate(samples_per_sec);
}
bool VoEHardwareImpl::BuiltInAECIsAvailable() const {
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return false;
}
return _shared->audio_device()->BuiltInAECIsAvailable();
}
int VoEHardwareImpl::EnableBuiltInAEC(bool enable) {
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
return _shared->audio_device()->EnableBuiltInAEC(enable);
}
bool VoEHardwareImpl::BuiltInAGCIsAvailable() const {
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return false;
}
return _shared->audio_device()->BuiltInAGCIsAvailable();
}
int VoEHardwareImpl::EnableBuiltInAGC(bool enable) {
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
return _shared->audio_device()->EnableBuiltInAGC(enable);
}
bool VoEHardwareImpl::BuiltInNSIsAvailable() const {
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return false;
}
return _shared->audio_device()->BuiltInNSIsAvailable();
}
int VoEHardwareImpl::EnableBuiltInNS(bool enable) {
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
return _shared->audio_device()->EnableBuiltInNS(enable);
}
} // namespace webrtc

View File

@ -1,65 +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 WEBRTC_VOICE_ENGINE_VOE_HARDWARE_IMPL_H
#define WEBRTC_VOICE_ENGINE_VOE_HARDWARE_IMPL_H
#include "webrtc/voice_engine/include/voe_hardware.h"
#include "webrtc/voice_engine/shared_data.h"
namespace webrtc {
class VoEHardwareImpl : public VoEHardware {
public:
int GetNumOfRecordingDevices(int& devices) override;
int GetNumOfPlayoutDevices(int& devices) override;
int GetRecordingDeviceName(int index,
char strNameUTF8[128],
char strGuidUTF8[128]) override;
int GetPlayoutDeviceName(int index,
char strNameUTF8[128],
char strGuidUTF8[128]) override;
int SetRecordingDevice(int index,
StereoChannel recordingChannel = kStereoBoth) override;
int SetPlayoutDevice(int index) override;
int SetAudioDeviceLayer(AudioLayers audioLayer) override;
int GetAudioDeviceLayer(AudioLayers& audioLayer) override;
int SetRecordingSampleRate(unsigned int samples_per_sec) override;
int RecordingSampleRate(unsigned int* samples_per_sec) const override;
int SetPlayoutSampleRate(unsigned int samples_per_sec) override;
int PlayoutSampleRate(unsigned int* samples_per_sec) const override;
bool BuiltInAECIsAvailable() const override;
int EnableBuiltInAEC(bool enable) override;
bool BuiltInAGCIsAvailable() const override;
int EnableBuiltInAGC(bool enable) override;
bool BuiltInNSIsAvailable() const override;
int EnableBuiltInNS(bool enable) override;
protected:
VoEHardwareImpl(voe::SharedData* shared);
~VoEHardwareImpl() override;
private:
voe::SharedData* _shared;
};
} // namespace webrtc
#endif // WEBRTC_VOICE_ENGINE_VOE_HARDWARE_IMPL_H

View File

@ -18,7 +18,6 @@
#include "webrtc/voice_engine/voe_base_impl.h"
#include "webrtc/voice_engine/voe_codec_impl.h"
#include "webrtc/voice_engine/voe_file_impl.h"
#include "webrtc/voice_engine/voe_hardware_impl.h"
#include "webrtc/voice_engine/voe_network_impl.h"
#include "webrtc/voice_engine/voe_rtp_rtcp_impl.h"
@ -31,7 +30,6 @@ class VoiceEngineImpl : public voe::SharedData, // Must be the first base class
public VoiceEngine,
public VoECodecImpl,
public VoEFileImpl,
public VoEHardwareImpl,
public VoENetworkImpl,
public VoERTP_RTCPImpl,
public VoEBaseImpl {
@ -40,7 +38,6 @@ class VoiceEngineImpl : public voe::SharedData, // Must be the first base class
: SharedData(),
VoECodecImpl(this),
VoEFileImpl(this),
VoEHardwareImpl(this),
VoENetworkImpl(this),
VoERTP_RTCPImpl(this),
VoEBaseImpl(this),