2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-31 12:22:14 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-21 13:52:32 +00:00
|
|
|
#include "webrtc/voice_engine/voe_base_impl.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-11-13 00:02:48 +00:00
|
|
|
#include "webrtc/common.h"
|
2013-05-21 13:52:32 +00:00
|
|
|
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
|
|
|
|
|
#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
|
|
|
|
|
#include "webrtc/modules/audio_device/audio_device_impl.h"
|
|
|
|
|
#include "webrtc/modules/audio_processing/include/audio_processing.h"
|
|
|
|
|
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
|
|
|
|
|
#include "webrtc/system_wrappers/interface/file_wrapper.h"
|
|
|
|
|
#include "webrtc/system_wrappers/interface/trace.h"
|
|
|
|
|
#include "webrtc/voice_engine/channel.h"
|
|
|
|
|
#include "webrtc/voice_engine/include/voe_errors.h"
|
|
|
|
|
#include "webrtc/voice_engine/output_mixer.h"
|
|
|
|
|
#include "webrtc/voice_engine/transmit_mixer.h"
|
|
|
|
|
#include "webrtc/voice_engine/utility.h"
|
|
|
|
|
#include "webrtc/voice_engine/voice_engine_impl.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
VoEBase* VoEBase::GetInterface(VoiceEngine* voiceEngine)
|
|
|
|
|
{
|
|
|
|
|
if (NULL == voiceEngine)
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2013-02-15 15:07:32 +00:00
|
|
|
VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
|
2012-04-26 15:28:22 +00:00
|
|
|
s->AddRef();
|
|
|
|
|
return s;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-04 14:57:19 +00:00
|
|
|
VoEBaseImpl::VoEBaseImpl(voe::SharedData* shared) :
|
2011-07-07 08:21:25 +00:00
|
|
|
_voiceEngineObserverPtr(NULL),
|
|
|
|
|
_callbackCritSect(*CriticalSectionWrapper::CreateCriticalSection()),
|
2014-02-18 20:24:56 +00:00
|
|
|
_voiceEngineObserver(false), _shared(shared)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"VoEBaseImpl() - ctor");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VoEBaseImpl::~VoEBaseImpl()
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"~VoEBaseImpl() - dtor");
|
|
|
|
|
|
|
|
|
|
TerminateInternal();
|
|
|
|
|
|
|
|
|
|
delete &_callbackCritSect;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-14 08:31:39 +00:00
|
|
|
void VoEBaseImpl::OnErrorIsReported(ErrorCode error)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-03-07 08:12:21 +00:00
|
|
|
CriticalSectionScoped cs(&_callbackCritSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
if (_voiceEngineObserver)
|
|
|
|
|
{
|
|
|
|
|
if (_voiceEngineObserverPtr)
|
|
|
|
|
{
|
|
|
|
|
int errCode(0);
|
|
|
|
|
if (error == AudioDeviceObserver::kRecordingError)
|
|
|
|
|
{
|
|
|
|
|
errCode = VE_RUNTIME_REC_ERROR;
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceInfo, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"VoEBaseImpl::OnErrorIsReported() => VE_RUNTIME_REC_ERROR");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
else if (error == AudioDeviceObserver::kPlayoutError)
|
|
|
|
|
{
|
|
|
|
|
errCode = VE_RUNTIME_PLAY_ERROR;
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceInfo, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"VoEBaseImpl::OnErrorIsReported() => "
|
|
|
|
|
"VE_RUNTIME_PLAY_ERROR");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
// Deliver callback (-1 <=> no channel dependency)
|
|
|
|
|
_voiceEngineObserverPtr->CallbackOnError(-1, errCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-14 08:31:39 +00:00
|
|
|
void VoEBaseImpl::OnWarningIsReported(WarningCode warning)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-03-07 08:12:21 +00:00
|
|
|
CriticalSectionScoped cs(&_callbackCritSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
if (_voiceEngineObserver)
|
|
|
|
|
{
|
|
|
|
|
if (_voiceEngineObserverPtr)
|
|
|
|
|
{
|
|
|
|
|
int warningCode(0);
|
|
|
|
|
if (warning == AudioDeviceObserver::kRecordingWarning)
|
|
|
|
|
{
|
|
|
|
|
warningCode = VE_RUNTIME_REC_WARNING;
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceInfo, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"VoEBaseImpl::OnErrorIsReported() => "
|
|
|
|
|
"VE_RUNTIME_REC_WARNING");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
else if (warning == AudioDeviceObserver::kPlayoutWarning)
|
|
|
|
|
{
|
|
|
|
|
warningCode = VE_RUNTIME_PLAY_WARNING;
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceInfo, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"VoEBaseImpl::OnErrorIsReported() => "
|
|
|
|
|
"VE_RUNTIME_PLAY_WARNING");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
// Deliver callback (-1 <=> no channel dependency)
|
|
|
|
|
_voiceEngineObserverPtr->CallbackOnError(-1, warningCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t VoEBaseImpl::RecordedDataIsAvailable(
|
2012-03-09 08:59:19 +00:00
|
|
|
const void* audioSamples,
|
2013-05-14 08:31:39 +00:00
|
|
|
uint32_t nSamples,
|
|
|
|
|
uint8_t nBytesPerSample,
|
|
|
|
|
uint8_t nChannels,
|
|
|
|
|
uint32_t samplesPerSec,
|
|
|
|
|
uint32_t totalDelayMS,
|
|
|
|
|
int32_t clockDrift,
|
2014-02-18 20:24:56 +00:00
|
|
|
uint32_t micLevel,
|
2013-05-14 08:31:39 +00:00
|
|
|
bool keyPressed,
|
2013-04-09 10:09:10 +00:00
|
|
|
uint32_t& newMicLevel)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"VoEBaseImpl::RecordedDataIsAvailable(nSamples=%u, "
|
|
|
|
|
"nBytesPerSample=%u, nChannels=%u, samplesPerSec=%u, "
|
2014-02-18 20:24:56 +00:00
|
|
|
"totalDelayMS=%u, clockDrift=%d, micLevel=%u)",
|
2011-07-07 08:21:25 +00:00
|
|
|
nSamples, nBytesPerSample, nChannels, samplesPerSec,
|
2014-02-18 20:24:56 +00:00
|
|
|
totalDelayMS, clockDrift, micLevel);
|
2013-07-31 16:27:42 +00:00
|
|
|
newMicLevel = static_cast<uint32_t>(ProcessRecordedDataWithAPM(
|
|
|
|
|
NULL, 0, audioSamples, samplesPerSec, nChannels, nSamples,
|
2014-02-18 20:24:56 +00:00
|
|
|
totalDelayMS, clockDrift, micLevel, keyPressed));
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t VoEBaseImpl::NeedMorePlayData(
|
2013-05-14 08:31:39 +00:00
|
|
|
uint32_t nSamples,
|
|
|
|
|
uint8_t nBytesPerSample,
|
|
|
|
|
uint8_t nChannels,
|
|
|
|
|
uint32_t samplesPerSec,
|
2012-03-09 08:59:19 +00:00
|
|
|
void* audioSamples,
|
2014-05-19 17:39:11 +00:00
|
|
|
uint32_t& nSamplesOut,
|
2014-06-05 20:34:08 +00:00
|
|
|
int64_t* elapsed_time_ms,
|
2014-05-19 17:39:11 +00:00
|
|
|
int64_t* ntp_time_ms)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2014-04-14 10:50:37 +00:00
|
|
|
WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"VoEBaseImpl::NeedMorePlayData(nSamples=%u, "
|
|
|
|
|
"nBytesPerSample=%d, nChannels=%d, samplesPerSec=%u)",
|
|
|
|
|
nSamples, nBytesPerSample, nChannels, samplesPerSec);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-04-14 10:50:37 +00:00
|
|
|
GetPlayoutData(static_cast<int>(samplesPerSec),
|
|
|
|
|
static_cast<int>(nChannels),
|
2014-05-19 17:39:11 +00:00
|
|
|
static_cast<int>(nSamples), true, audioSamples,
|
2014-06-05 20:34:08 +00:00
|
|
|
elapsed_time_ms, ntp_time_ms);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-04-14 10:50:37 +00:00
|
|
|
nSamplesOut = _audioFrame.samples_per_channel_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-04-14 10:50:37 +00:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-31 16:27:42 +00:00
|
|
|
int VoEBaseImpl::OnDataAvailable(const int voe_channels[],
|
2013-07-31 16:23:37 +00:00
|
|
|
int number_of_voe_channels,
|
|
|
|
|
const int16_t* audio_data,
|
|
|
|
|
int sample_rate,
|
|
|
|
|
int number_of_channels,
|
|
|
|
|
int number_of_frames,
|
|
|
|
|
int audio_delay_milliseconds,
|
2014-02-18 20:24:56 +00:00
|
|
|
int volume,
|
2013-07-31 16:23:37 +00:00
|
|
|
bool key_pressed,
|
|
|
|
|
bool need_audio_processing) {
|
|
|
|
|
WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"VoEBaseImpl::OnDataAvailable(number_of_voe_channels=%d, "
|
|
|
|
|
"sample_rate=%d, number_of_channels=%d, number_of_frames=%d, "
|
2014-02-18 20:24:56 +00:00
|
|
|
"audio_delay_milliseconds=%d, volume=%d, "
|
2013-07-31 16:23:37 +00:00
|
|
|
"key_pressed=%d, need_audio_processing=%d)",
|
|
|
|
|
number_of_voe_channels, sample_rate, number_of_channels,
|
2014-02-18 20:24:56 +00:00
|
|
|
number_of_frames, audio_delay_milliseconds, volume,
|
2013-07-31 16:23:37 +00:00
|
|
|
key_pressed, need_audio_processing);
|
2013-07-31 16:27:42 +00:00
|
|
|
if (number_of_voe_channels == 0)
|
|
|
|
|
return 0;
|
2013-07-31 16:23:37 +00:00
|
|
|
|
|
|
|
|
if (need_audio_processing) {
|
2013-07-31 16:27:42 +00:00
|
|
|
return ProcessRecordedDataWithAPM(
|
|
|
|
|
voe_channels, number_of_voe_channels, audio_data, sample_rate,
|
|
|
|
|
number_of_channels, number_of_frames, audio_delay_milliseconds,
|
2014-02-18 20:24:56 +00:00
|
|
|
0, volume, key_pressed);
|
2013-07-31 16:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// No need to go through the APM, demultiplex the data to each VoE channel,
|
|
|
|
|
// encode and send to the network.
|
|
|
|
|
for (int i = 0; i < number_of_voe_channels; ++i) {
|
Consolidate audio conversion from Channel and TransmitMixer.
Replace the two versions with a single DownConvertToCodecFormat. As
mentioned in comments, this could be further consolidated with
RemixAndResample but we should write a full audio converter class in
that case.
Along the way:
- Fix the bug present in Channel::Demultiplex with mono input and a
stereo codec.
- Remove the 32 kHz max from the OnDataAvailable path. This avoids a
48 -> 32 -> 48 conversion when VoE is passed 48 kHz audio; instead we
get a straight pass-through to ACM. The 32 kHz conversion is still
needed in the RecordedDataIsAvailable path until APM natively supports
48 kHz.
- Merge resampler improvements from ACM1 to ACM2. This allows ACM to
handle 44.1 kHz audio passed to VoE and was originally done here:
https://webrtc-codereview.appspot.com/1590004
- Reuse the RemixAndResample unit tests for DownConvertToCodecFormat.
- Remove unused functions from utility.cc.
BUG=3155,3000,b/12867572
TESTED=voe_cmd_test using both the OnDataAvailable and
RecordedDataIsAvailable paths, with a captured audio format of all
combinations of {44.1,48} kHz and {1,2} channels, running through all
codecs, and finally using both ACM1 and ACM2.
R=henrika@webrtc.org, turaj@webrtc.org, xians@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/11019005
git-svn-id: http://webrtc.googlecode.com/svn/trunk@5843 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-04-03 21:56:01 +00:00
|
|
|
// TODO(ajm): In the case where multiple channels are using the same codec
|
|
|
|
|
// rate, this path needlessly does extra conversions. We should convert once
|
|
|
|
|
// and share between channels.
|
2014-04-14 10:50:37 +00:00
|
|
|
PushCaptureData(voe_channels[i], audio_data, 16, sample_rate,
|
|
|
|
|
number_of_channels, number_of_frames);
|
2013-07-31 16:23:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return 0 to indicate no need to change the volume.
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-02 15:30:20 +00:00
|
|
|
void VoEBaseImpl::OnData(int voe_channel, const void* audio_data,
|
|
|
|
|
int bits_per_sample, int sample_rate,
|
|
|
|
|
int number_of_channels,
|
|
|
|
|
int number_of_frames) {
|
2014-04-14 10:50:37 +00:00
|
|
|
PushCaptureData(voe_channel, audio_data, bits_per_sample, sample_rate,
|
|
|
|
|
number_of_channels, number_of_frames);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VoEBaseImpl::PushCaptureData(int voe_channel, const void* audio_data,
|
|
|
|
|
int bits_per_sample, int sample_rate,
|
|
|
|
|
int number_of_channels,
|
|
|
|
|
int number_of_frames) {
|
2014-01-29 13:54:02 +00:00
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(voe_channel);
|
|
|
|
|
voe::Channel* channel_ptr = ch.channel();
|
|
|
|
|
if (!channel_ptr)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-04-17 10:45:01 +00:00
|
|
|
if (channel_ptr->Sending()) {
|
2014-01-29 13:54:02 +00:00
|
|
|
channel_ptr->Demultiplex(static_cast<const int16_t*>(audio_data),
|
|
|
|
|
sample_rate, number_of_frames, number_of_channels);
|
|
|
|
|
channel_ptr->PrepareEncodeAndSend(sample_rate);
|
|
|
|
|
channel_ptr->EncodeAndSend();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 10:50:37 +00:00
|
|
|
void VoEBaseImpl::PullRenderData(int bits_per_sample, int sample_rate,
|
|
|
|
|
int number_of_channels, int number_of_frames,
|
2014-05-19 17:39:11 +00:00
|
|
|
void* audio_data,
|
2014-06-05 20:34:08 +00:00
|
|
|
int64_t* elapsed_time_ms,
|
2014-05-19 17:39:11 +00:00
|
|
|
int64_t* ntp_time_ms) {
|
2014-04-14 10:50:37 +00:00
|
|
|
assert(bits_per_sample == 16);
|
|
|
|
|
assert(number_of_frames == static_cast<int>(sample_rate / 100));
|
|
|
|
|
|
|
|
|
|
GetPlayoutData(sample_rate, number_of_channels, number_of_frames, false,
|
2014-06-05 20:34:08 +00:00
|
|
|
audio_data, elapsed_time_ms, ntp_time_ms);
|
2014-04-14 10:50:37 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
int VoEBaseImpl::RegisterVoiceEngineObserver(VoiceEngineObserver& observer)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"RegisterVoiceEngineObserver(observer=0x%d)", &observer);
|
2012-03-07 08:12:21 +00:00
|
|
|
CriticalSectionScoped cs(&_callbackCritSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
if (_voiceEngineObserverPtr)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_INVALID_OPERATION, kTraceError,
|
|
|
|
|
"RegisterVoiceEngineObserver() observer already enabled");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Register the observer in all active channels
|
2013-08-07 17:57:36 +00:00
|
|
|
for (voe::ChannelManager::Iterator it(&_shared->channel_manager());
|
|
|
|
|
it.IsValid();
|
|
|
|
|
it.Increment()) {
|
|
|
|
|
it.GetChannel()->RegisterVoiceEngineObserver(observer);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->transmit_mixer()->RegisterVoiceEngineObserver(observer);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
_voiceEngineObserverPtr = &observer;
|
|
|
|
|
_voiceEngineObserver = true;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VoEBaseImpl::DeRegisterVoiceEngineObserver()
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"DeRegisterVoiceEngineObserver()");
|
2012-03-07 08:12:21 +00:00
|
|
|
CriticalSectionScoped cs(&_callbackCritSect);
|
2011-07-07 08:21:25 +00:00
|
|
|
if (!_voiceEngineObserverPtr)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_INVALID_OPERATION, kTraceError,
|
2011-10-03 15:22:28 +00:00
|
|
|
"DeRegisterVoiceEngineObserver() observer already disabled");
|
2011-07-07 08:21:25 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_voiceEngineObserver = false;
|
|
|
|
|
_voiceEngineObserverPtr = NULL;
|
|
|
|
|
|
|
|
|
|
// Deregister the observer in all active channels
|
2013-08-07 17:57:36 +00:00
|
|
|
for (voe::ChannelManager::Iterator it(&_shared->channel_manager());
|
|
|
|
|
it.IsValid();
|
|
|
|
|
it.Increment()) {
|
|
|
|
|
it.GetChannel()->DeRegisterVoiceEngineObserver();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 01:12:49 +00:00
|
|
|
int VoEBaseImpl::Init(AudioDeviceModule* external_adm,
|
|
|
|
|
AudioProcessing* audioproc)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-09-07 15:11:18 +00:00
|
|
|
"Init(external_adm=0x%p)", external_adm);
|
2012-04-04 14:57:19 +00:00
|
|
|
CriticalSectionScoped cs(_shared->crit_sec());
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-09-08 00:09:26 +00:00
|
|
|
WebRtcSpl_Init();
|
|
|
|
|
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->statistics().Initialized())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->process_thread())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->process_thread()->Start() != 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_THREAD_ERROR, kTraceError,
|
2011-10-03 15:22:28 +00:00
|
|
|
"Init() failed to start module process thread");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-21 18:00:59 +00:00
|
|
|
// Create an internal ADM if the user has not added an external
|
2011-11-16 10:33:53 +00:00
|
|
|
// ADM implementation as input to Init().
|
|
|
|
|
if (external_adm == NULL)
|
|
|
|
|
{
|
|
|
|
|
// Create the internal ADM implementation.
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->set_audio_device(AudioDeviceModuleImpl::Create(
|
|
|
|
|
VoEId(_shared->instance_id(), -1), _shared->audio_device_layer()));
|
2011-11-16 10:33:53 +00:00
|
|
|
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device() == NULL)
|
2011-11-16 10:33:53 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_NO_MEMORY, kTraceCritical,
|
|
|
|
|
"Init() failed to create the ADM");
|
2011-11-16 10:33:53 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Use the already existing external ADM implementation.
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->set_audio_device(external_adm);
|
|
|
|
|
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-11-16 10:33:53 +00:00
|
|
|
"An external ADM implementation will be used in VoiceEngine");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Register the ADM to the process thread, which will drive the error
|
|
|
|
|
// callback mechanism
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->process_thread() &&
|
|
|
|
|
_shared->process_thread()->RegisterModule(_shared->audio_device()) != 0)
|
2011-11-16 10:33:53 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
|
|
|
|
|
"Init() failed to register the ADM");
|
2011-11-16 10:33:53 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool available(false);
|
|
|
|
|
|
|
|
|
|
// --------------------
|
|
|
|
|
// Reinitialize the ADM
|
|
|
|
|
|
|
|
|
|
// Register the AudioObserver implementation
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->RegisterEventObserver(this) != 0) {
|
|
|
|
|
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning,
|
|
|
|
|
"Init() failed to register event observer for the ADM");
|
2012-01-31 12:22:14 +00:00
|
|
|
}
|
2011-11-16 10:33:53 +00:00
|
|
|
|
|
|
|
|
// Register the AudioTransport implementation
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->RegisterAudioCallback(this) != 0) {
|
|
|
|
|
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning,
|
|
|
|
|
"Init() failed to register audio callback for the ADM");
|
2012-01-31 12:22:14 +00:00
|
|
|
}
|
2011-11-16 10:33:53 +00:00
|
|
|
|
|
|
|
|
// ADM initialization
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->Init() != 0)
|
2011-11-16 10:33:53 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
|
|
|
|
|
"Init() failed to initialize the ADM");
|
2011-11-16 10:33:53 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize the default speaker
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->SetPlayoutDevice(
|
|
|
|
|
WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0)
|
2011-11-16 10:33:53 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceInfo,
|
2011-11-16 10:33:53 +00:00
|
|
|
"Init() failed to set the default output device");
|
|
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->InitSpeaker() != 0)
|
2011-11-16 10:33:53 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_CANNOT_ACCESS_SPEAKER_VOL, kTraceInfo,
|
2011-11-16 10:33:53 +00:00
|
|
|
"Init() failed to initialize the speaker");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize the default microphone
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->SetRecordingDevice(
|
|
|
|
|
WEBRTC_VOICE_ENGINE_DEFAULT_DEVICE) != 0)
|
2011-11-16 10:33:53 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceInfo,
|
2011-11-16 10:33:53 +00:00
|
|
|
"Init() failed to set the default input device");
|
|
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->InitMicrophone() != 0)
|
2011-11-16 10:33:53 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_CANNOT_ACCESS_MIC_VOL, kTraceInfo,
|
2011-11-16 10:33:53 +00:00
|
|
|
"Init() failed to initialize the microphone");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set number of channels
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->StereoPlayoutIsAvailable(&available) != 0) {
|
|
|
|
|
_shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning,
|
|
|
|
|
"Init() failed to query stereo playout mode");
|
2012-01-31 12:22:14 +00:00
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->SetStereoPlayout(available) != 0)
|
2011-11-16 10:33:53 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning,
|
2011-11-16 10:33:53 +00:00
|
|
|
"Init() failed to set mono/stereo playout mode");
|
|
|
|
|
}
|
2011-12-21 18:00:59 +00:00
|
|
|
|
|
|
|
|
// TODO(andrew): These functions don't tell us whether stereo recording
|
|
|
|
|
// is truly available. We simply set the AudioProcessing input to stereo
|
|
|
|
|
// here, because we have to wait until receiving the first frame to
|
|
|
|
|
// determine the actual number of channels anyway.
|
|
|
|
|
//
|
|
|
|
|
// These functions may be changed; tracked here:
|
|
|
|
|
// http://code.google.com/p/webrtc/issues/detail?id=204
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->audio_device()->StereoRecordingIsAvailable(&available);
|
|
|
|
|
if (_shared->audio_device()->SetStereoRecording(available) != 0)
|
2011-11-16 10:33:53 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning,
|
2011-11-16 10:33:53 +00:00
|
|
|
"Init() failed to set mono/stereo recording mode");
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 01:12:49 +00:00
|
|
|
if (!audioproc) {
|
|
|
|
|
audioproc = AudioProcessing::Create(VoEId(_shared->instance_id(), -1));
|
|
|
|
|
if (!audioproc) {
|
|
|
|
|
LOG(LS_ERROR) << "Failed to create AudioProcessing.";
|
|
|
|
|
_shared->SetLastError(VE_NO_MEMORY);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_shared->set_audio_processing(audioproc);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-03-05 01:12:49 +00:00
|
|
|
// Set the error state for any failures in this block.
|
|
|
|
|
_shared->SetLastError(VE_APM_ERROR);
|
2013-10-04 17:54:09 +00:00
|
|
|
// Configure AudioProcessing components.
|
2013-03-05 01:12:49 +00:00
|
|
|
if (audioproc->high_pass_filter()->Enable(true) != 0) {
|
|
|
|
|
LOG_FERR1(LS_ERROR, high_pass_filter()->Enable, true);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (audioproc->echo_cancellation()->enable_drift_compensation(false) != 0) {
|
|
|
|
|
LOG_FERR1(LS_ERROR, enable_drift_compensation, false);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (audioproc->noise_suppression()->set_level(kDefaultNsMode) != 0) {
|
|
|
|
|
LOG_FERR1(LS_ERROR, noise_suppression()->set_level, kDefaultNsMode);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
GainControl* agc = audioproc->gain_control();
|
|
|
|
|
if (agc->set_analog_level_limits(kMinVolumeLevel, kMaxVolumeLevel) != 0) {
|
|
|
|
|
LOG_FERR2(LS_ERROR, agc->set_analog_level_limits, kMinVolumeLevel,
|
|
|
|
|
kMaxVolumeLevel);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (agc->set_mode(kDefaultAgcMode) != 0) {
|
|
|
|
|
LOG_FERR1(LS_ERROR, agc->set_mode, kDefaultAgcMode);
|
|
|
|
|
return -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-03-05 01:12:49 +00:00
|
|
|
if (agc->Enable(kDefaultAgcState) != 0) {
|
|
|
|
|
LOG_FERR1(LS_ERROR, agc->Enable, kDefaultAgcState);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
_shared->SetLastError(0); // Clear error state.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#ifdef WEBRTC_VOICE_ENGINE_AGC
|
2013-03-05 01:12:49 +00:00
|
|
|
bool agc_enabled = agc->mode() == GainControl::kAdaptiveAnalog &&
|
|
|
|
|
agc->is_enabled();
|
|
|
|
|
if (_shared->audio_device()->SetAGC(agc_enabled) != 0) {
|
|
|
|
|
LOG_FERR1(LS_ERROR, audio_device()->SetAGC, agc_enabled);
|
|
|
|
|
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR);
|
2013-03-05 23:36:10 +00:00
|
|
|
// TODO(ajm): No error return here due to
|
|
|
|
|
// https://code.google.com/p/webrtc/issues/detail?id=1464
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-04-04 14:57:19 +00:00
|
|
|
return _shared->statistics().SetInitialized();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VoEBaseImpl::Terminate()
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"Terminate()");
|
2012-04-04 14:57:19 +00:00
|
|
|
CriticalSectionScoped cs(_shared->crit_sec());
|
2011-07-07 08:21:25 +00:00
|
|
|
return TerminateInternal();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-13 00:02:48 +00:00
|
|
|
int VoEBaseImpl::CreateChannel() {
|
|
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"CreateChannel()");
|
|
|
|
|
CriticalSectionScoped cs(_shared->crit_sec());
|
|
|
|
|
if (!_shared->statistics().Initialized()) {
|
|
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-11-13 00:02:48 +00:00
|
|
|
voe::ChannelOwner channel_owner = _shared->channel_manager().CreateChannel();
|
|
|
|
|
|
|
|
|
|
return InitializeChannel(&channel_owner);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-11-13 00:02:48 +00:00
|
|
|
int VoEBaseImpl::CreateChannel(const Config& config) {
|
|
|
|
|
CriticalSectionScoped cs(_shared->crit_sec());
|
|
|
|
|
if (!_shared->statistics().Initialized()) {
|
|
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
voe::ChannelOwner channel_owner = _shared->channel_manager().CreateChannel(
|
|
|
|
|
config);
|
|
|
|
|
return InitializeChannel(&channel_owner);
|
|
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
|
2013-11-13 00:02:48 +00:00
|
|
|
int VoEBaseImpl::InitializeChannel(voe::ChannelOwner* channel_owner)
|
|
|
|
|
{
|
|
|
|
|
if (channel_owner->channel()->SetEngineInformation(
|
2013-08-07 17:57:36 +00:00
|
|
|
_shared->statistics(),
|
|
|
|
|
*_shared->output_mixer(),
|
|
|
|
|
*_shared->transmit_mixer(),
|
|
|
|
|
*_shared->process_thread(),
|
|
|
|
|
*_shared->audio_device(),
|
|
|
|
|
_voiceEngineObserverPtr,
|
|
|
|
|
&_callbackCritSect) != 0) {
|
|
|
|
|
_shared->SetLastError(
|
|
|
|
|
VE_CHANNEL_NOT_CREATED,
|
|
|
|
|
kTraceError,
|
|
|
|
|
"CreateChannel() failed to associate engine and channel."
|
|
|
|
|
" Destroying channel.");
|
|
|
|
|
_shared->channel_manager()
|
2013-11-13 00:02:48 +00:00
|
|
|
.DestroyChannel(channel_owner->channel()->ChannelId());
|
2013-08-07 17:57:36 +00:00
|
|
|
return -1;
|
2013-11-13 00:02:48 +00:00
|
|
|
} else if (channel_owner->channel()->Init() != 0) {
|
2013-08-07 17:57:36 +00:00
|
|
|
_shared->SetLastError(
|
|
|
|
|
VE_CHANNEL_NOT_CREATED,
|
|
|
|
|
kTraceError,
|
|
|
|
|
"CreateChannel() failed to initialize channel. Destroying"
|
|
|
|
|
" channel.");
|
|
|
|
|
_shared->channel_manager()
|
2013-11-13 00:02:48 +00:00
|
|
|
.DestroyChannel(channel_owner->channel()->ChannelId());
|
2013-08-07 17:57:36 +00:00
|
|
|
return -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceStateInfo, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1),
|
2013-11-13 00:02:48 +00:00
|
|
|
"CreateChannel() => %d", channel_owner->channel()->ChannelId());
|
|
|
|
|
return channel_owner->channel()->ChannelId();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VoEBaseImpl::DeleteChannel(int channel)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"DeleteChannel(channel=%d)", channel);
|
2012-04-04 14:57:19 +00:00
|
|
|
CriticalSectionScoped cs(_shared->crit_sec());
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-04-04 14:57:19 +00:00
|
|
|
if (!_shared->statistics().Initialized())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2013-08-07 17:57:36 +00:00
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channelPtr = ch.channel();
|
2011-07-07 08:21:25 +00:00
|
|
|
if (channelPtr == NULL)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"DeleteChannel() failed to locate channel");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
_shared->channel_manager().DestroyChannel(channel);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
if (StopSend() != 0)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StopPlayout() != 0)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2013-03-13 23:20:57 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VoEBaseImpl::StartReceive(int channel)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"StartReceive(channel=%d)", channel);
|
2012-04-04 14:57:19 +00:00
|
|
|
CriticalSectionScoped cs(_shared->crit_sec());
|
|
|
|
|
if (!_shared->statistics().Initialized())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channelPtr = ch.channel();
|
2011-07-07 08:21:25 +00:00
|
|
|
if (channelPtr == NULL)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"StartReceive() failed to locate channel");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return channelPtr->StartReceiving();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VoEBaseImpl::StopReceive(int channel)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"StopListen(channel=%d)", channel);
|
2012-04-04 14:57:19 +00:00
|
|
|
CriticalSectionScoped cs(_shared->crit_sec());
|
|
|
|
|
if (!_shared->statistics().Initialized())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channelPtr = ch.channel();
|
2011-07-07 08:21:25 +00:00
|
|
|
if (channelPtr == NULL)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"SetLocalReceiver() failed to locate channel");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return channelPtr->StopReceiving();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VoEBaseImpl::StartPlayout(int channel)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"StartPlayout(channel=%d)", channel);
|
2012-04-04 14:57:19 +00:00
|
|
|
CriticalSectionScoped cs(_shared->crit_sec());
|
|
|
|
|
if (!_shared->statistics().Initialized())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channelPtr = ch.channel();
|
2011-07-07 08:21:25 +00:00
|
|
|
if (channelPtr == NULL)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"StartPlayout() failed to locate channel");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (channelPtr->Playing())
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (StartPlayout() != 0)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
|
|
|
|
|
"StartPlayout() failed to start playout");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return channelPtr->StartPlayout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VoEBaseImpl::StopPlayout(int channel)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"StopPlayout(channel=%d)", channel);
|
2012-04-04 14:57:19 +00:00
|
|
|
CriticalSectionScoped cs(_shared->crit_sec());
|
|
|
|
|
if (!_shared->statistics().Initialized())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channelPtr = ch.channel();
|
2011-07-07 08:21:25 +00:00
|
|
|
if (channelPtr == NULL)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"StopPlayout() failed to locate channel");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (channelPtr->StopPlayout() != 0)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceWarning, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"StopPlayout() failed to stop playout for channel %d", channel);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
return StopPlayout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VoEBaseImpl::StartSend(int channel)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"StartSend(channel=%d)", channel);
|
2012-04-04 14:57:19 +00:00
|
|
|
CriticalSectionScoped cs(_shared->crit_sec());
|
|
|
|
|
if (!_shared->statistics().Initialized())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channelPtr = ch.channel();
|
2011-07-07 08:21:25 +00:00
|
|
|
if (channelPtr == NULL)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"StartSend() failed to locate channel");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (channelPtr->Sending())
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (StartSend() != 0)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
|
|
|
|
|
"StartSend() failed to start recording");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return channelPtr->StartSend();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VoEBaseImpl::StopSend(int channel)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"StopSend(channel=%d)", channel);
|
2012-04-04 14:57:19 +00:00
|
|
|
CriticalSectionScoped cs(_shared->crit_sec());
|
|
|
|
|
if (!_shared->statistics().Initialized())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_NOT_INITED, kTraceError);
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
|
|
|
|
|
voe::Channel* channelPtr = ch.channel();
|
2011-07-07 08:21:25 +00:00
|
|
|
if (channelPtr == NULL)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
|
|
|
|
|
"StopSend() failed to locate channel");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (channelPtr->StopSend() != 0)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceWarning, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"StopSend() failed to stop sending for channel %d", channel);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
return StopSend();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VoEBaseImpl::GetVersion(char version[1024])
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"GetVersion(version=?)");
|
|
|
|
|
assert(kVoiceEngineVersionMaxMessageSize == 1024);
|
|
|
|
|
|
|
|
|
|
if (version == NULL)
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError);
|
2011-07-07 08:21:25 +00:00
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char versionBuf[kVoiceEngineVersionMaxMessageSize];
|
|
|
|
|
char* versionPtr = versionBuf;
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t len = 0;
|
|
|
|
|
int32_t accLen = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
len = AddVoEVersion(versionPtr);
|
|
|
|
|
if (len == -1)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
versionPtr += len;
|
|
|
|
|
accLen += len;
|
|
|
|
|
assert(accLen < kVoiceEngineVersionMaxMessageSize);
|
|
|
|
|
|
|
|
|
|
len = AddBuildInfo(versionPtr);
|
|
|
|
|
if (len == -1)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
versionPtr += len;
|
|
|
|
|
accLen += len;
|
|
|
|
|
assert(accLen < kVoiceEngineVersionMaxMessageSize);
|
|
|
|
|
|
2013-03-13 23:20:57 +00:00
|
|
|
#ifdef WEBRTC_EXTERNAL_TRANSPORT
|
|
|
|
|
len = AddExternalTransportBuild(versionPtr);
|
|
|
|
|
if (len == -1)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
versionPtr += len;
|
|
|
|
|
accLen += len;
|
|
|
|
|
assert(accLen < kVoiceEngineVersionMaxMessageSize);
|
|
|
|
|
#endif
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
memcpy(version, versionBuf, accLen);
|
|
|
|
|
version[accLen] = '\0';
|
|
|
|
|
|
|
|
|
|
// to avoid the truncation in the trace, split the string into parts
|
|
|
|
|
char partOfVersion[256];
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceStateInfo, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1), "GetVersion() =>");
|
2011-07-07 08:21:25 +00:00
|
|
|
for (int partStart = 0; partStart < accLen;)
|
|
|
|
|
{
|
|
|
|
|
memset(partOfVersion, 0, sizeof(partOfVersion));
|
|
|
|
|
int partEnd = partStart + 180;
|
|
|
|
|
while (version[partEnd] != '\n' && version[partEnd] != '\0')
|
|
|
|
|
{
|
|
|
|
|
partEnd--;
|
|
|
|
|
}
|
|
|
|
|
if (partEnd < accLen)
|
|
|
|
|
{
|
|
|
|
|
memcpy(partOfVersion, &version[partStart], partEnd - partStart);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
memcpy(partOfVersion, &version[partStart], accLen - partStart);
|
|
|
|
|
}
|
|
|
|
|
partStart = partEnd;
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceStateInfo, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1), "%s", partOfVersion);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t VoEBaseImpl::AddBuildInfo(char* str) const
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2013-12-04 17:00:44 +00:00
|
|
|
return sprintf(str, "Build: %s\n", BUILDINFO);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t VoEBaseImpl::AddVoEVersion(char* str) const
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
return sprintf(str, "VoiceEngine 4.1.0\n");
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-13 23:20:57 +00:00
|
|
|
#ifdef WEBRTC_EXTERNAL_TRANSPORT
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t VoEBaseImpl::AddExternalTransportBuild(char* str) const
|
2013-03-13 23:20:57 +00:00
|
|
|
{
|
|
|
|
|
return sprintf(str, "External transport build\n");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
int VoEBaseImpl::LastError()
|
|
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"LastError()");
|
2012-04-04 14:57:19 +00:00
|
|
|
return (_shared->statistics().LastError());
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t VoEBaseImpl::StartPlayout()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"VoEBaseImpl::StartPlayout()");
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->Playing())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
if (!_shared->ext_playout())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->InitPlayout() != 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"StartPlayout() failed to initialize playout");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->StartPlayout() != 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"StartPlayout() failed to start playout");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
int32_t VoEBaseImpl::StopPlayout() {
|
|
|
|
|
WEBRTC_TRACE(kTraceInfo,
|
|
|
|
|
kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"VoEBaseImpl::StopPlayout()");
|
|
|
|
|
// Stop audio-device playing if no channel is playing out
|
2013-10-17 16:15:34 +00:00
|
|
|
if (_shared->NumOfPlayingChannels() == 0) {
|
2013-08-07 17:57:36 +00:00
|
|
|
if (_shared->audio_device()->StopPlayout() != 0) {
|
|
|
|
|
_shared->SetLastError(VE_CANNOT_STOP_PLAYOUT,
|
|
|
|
|
kTraceError,
|
|
|
|
|
"StopPlayout() failed to stop playout");
|
|
|
|
|
return -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t VoEBaseImpl::StartSend()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"VoEBaseImpl::StartSend()");
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->Recording())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
if (!_shared->ext_recording())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->InitRecording() != 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"StartSend() failed to initialize recording");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->StartRecording() != 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceError, kTraceVoice,
|
|
|
|
|
VoEId(_shared->instance_id(), -1),
|
|
|
|
|
"StartSend() failed to start recording");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t VoEBaseImpl::StopSend()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"VoEBaseImpl::StopSend()");
|
|
|
|
|
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->NumOfSendingChannels() == 0 &&
|
|
|
|
|
!_shared->transmit_mixer()->IsRecordingMic())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
|
|
|
|
// Stop audio-device recording if no channel is recording
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->StopRecording() != 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_CANNOT_STOP_RECORDING, kTraceError,
|
|
|
|
|
"StopSend() failed to stop recording");
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->transmit_mixer()->StopSend();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t VoEBaseImpl::TerminateInternal()
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
|
2011-07-07 08:21:25 +00:00
|
|
|
"VoEBaseImpl::TerminateInternal()");
|
|
|
|
|
|
|
|
|
|
// Delete any remaining channel objects
|
2013-08-07 17:57:36 +00:00
|
|
|
_shared->channel_manager().DestroyAllChannels();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->process_thread())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->process_thread()->
|
|
|
|
|
DeRegisterModule(_shared->audio_device()) != 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_THREAD_ERROR, kTraceError,
|
|
|
|
|
"TerminateInternal() failed to deregister ADM");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->process_thread()->Stop() != 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_THREAD_ERROR, kTraceError,
|
|
|
|
|
"TerminateInternal() failed to stop module process thread");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 01:12:49 +00:00
|
|
|
if (_shared->audio_device())
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->StopPlayout() != 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning,
|
|
|
|
|
"TerminateInternal() failed to stop playout");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->StopRecording() != 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_SOUNDCARD_ERROR, kTraceWarning,
|
|
|
|
|
"TerminateInternal() failed to stop recording");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->RegisterEventObserver(NULL) != 0) {
|
|
|
|
|
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning,
|
|
|
|
|
"TerminateInternal() failed to de-register event observer "
|
|
|
|
|
"for the ADM");
|
2012-01-31 12:22:14 +00:00
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->RegisterAudioCallback(NULL) != 0) {
|
|
|
|
|
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceWarning,
|
|
|
|
|
"TerminateInternal() failed to de-register audio callback "
|
|
|
|
|
"for the ADM");
|
2012-01-31 12:22:14 +00:00
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
if (_shared->audio_device()->Terminate() != 0)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->SetLastError(VE_AUDIO_DEVICE_MODULE_ERROR, kTraceError,
|
|
|
|
|
"TerminateInternal() failed to terminate the ADM");
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->set_audio_device(NULL);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-05 01:12:49 +00:00
|
|
|
if (_shared->audio_processing()) {
|
2012-04-04 14:57:19 +00:00
|
|
|
_shared->set_audio_processing(NULL);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-04 14:57:19 +00:00
|
|
|
return _shared->statistics().SetUnInitialized();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-31 16:27:42 +00:00
|
|
|
int VoEBaseImpl::ProcessRecordedDataWithAPM(
|
|
|
|
|
const int voe_channels[],
|
|
|
|
|
int number_of_voe_channels,
|
|
|
|
|
const void* audio_data,
|
|
|
|
|
uint32_t sample_rate,
|
|
|
|
|
uint8_t number_of_channels,
|
|
|
|
|
uint32_t number_of_frames,
|
|
|
|
|
uint32_t audio_delay_milliseconds,
|
|
|
|
|
int32_t clock_drift,
|
2014-02-18 20:24:56 +00:00
|
|
|
uint32_t volume,
|
2013-07-31 16:27:42 +00:00
|
|
|
bool key_pressed) {
|
|
|
|
|
assert(_shared->transmit_mixer() != NULL);
|
|
|
|
|
assert(_shared->audio_device() != NULL);
|
|
|
|
|
|
|
|
|
|
uint32_t max_volume = 0;
|
2014-02-18 20:24:56 +00:00
|
|
|
uint16_t voe_mic_level = 0;
|
2014-01-11 01:25:53 +00:00
|
|
|
// Check for zero to skip this calculation; the consumer may use this to
|
|
|
|
|
// indicate no volume is available.
|
2014-02-18 20:24:56 +00:00
|
|
|
if (volume != 0) {
|
2013-07-31 16:27:42 +00:00
|
|
|
// Scale from ADM to VoE level range
|
|
|
|
|
if (_shared->audio_device()->MaxMicrophoneVolume(&max_volume) == 0) {
|
|
|
|
|
if (max_volume) {
|
2014-02-18 20:24:56 +00:00
|
|
|
voe_mic_level = static_cast<uint16_t>(
|
|
|
|
|
(volume * kMaxVolumeLevel +
|
2013-07-31 16:27:42 +00:00
|
|
|
static_cast<int>(max_volume / 2)) / max_volume);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-18 20:24:56 +00:00
|
|
|
// We learned that on certain systems (e.g Linux) the voe_mic_level
|
2013-07-31 16:27:42 +00:00
|
|
|
// can be greater than the maxVolumeLevel therefore
|
2014-02-18 20:24:56 +00:00
|
|
|
// we are going to cap the voe_mic_level to the maxVolumeLevel
|
|
|
|
|
// and change the maxVolume to volume if it turns out that
|
|
|
|
|
// the voe_mic_level is indeed greater than the maxVolumeLevel.
|
|
|
|
|
if (voe_mic_level > kMaxVolumeLevel) {
|
|
|
|
|
voe_mic_level = kMaxVolumeLevel;
|
|
|
|
|
max_volume = volume;
|
2013-07-31 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Perform channel-independent operations
|
|
|
|
|
// (APM, mix with file, record to file, mute, etc.)
|
|
|
|
|
_shared->transmit_mixer()->PrepareDemux(
|
|
|
|
|
audio_data, number_of_frames, number_of_channels, sample_rate,
|
|
|
|
|
static_cast<uint16_t>(audio_delay_milliseconds), clock_drift,
|
2014-02-18 20:24:56 +00:00
|
|
|
voe_mic_level, key_pressed);
|
2013-07-31 16:27:42 +00:00
|
|
|
|
|
|
|
|
// Copy the audio frame to each sending channel and perform
|
|
|
|
|
// channel-dependent operations (file mixing, mute, etc.), encode and
|
|
|
|
|
// packetize+transmit the RTP packet. When |number_of_voe_channels| == 0,
|
|
|
|
|
// do the operations on all the existing VoE channels; otherwise the
|
|
|
|
|
// operations will be done on specific channels.
|
|
|
|
|
if (number_of_voe_channels == 0) {
|
|
|
|
|
_shared->transmit_mixer()->DemuxAndMix();
|
|
|
|
|
_shared->transmit_mixer()->EncodeAndSend();
|
|
|
|
|
} else {
|
|
|
|
|
_shared->transmit_mixer()->DemuxAndMix(voe_channels,
|
|
|
|
|
number_of_voe_channels);
|
|
|
|
|
_shared->transmit_mixer()->EncodeAndSend(voe_channels,
|
|
|
|
|
number_of_voe_channels);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Scale from VoE to ADM level range.
|
|
|
|
|
uint32_t new_voe_mic_level = _shared->transmit_mixer()->CaptureLevel();
|
|
|
|
|
|
2014-02-18 20:24:56 +00:00
|
|
|
if (new_voe_mic_level != voe_mic_level) {
|
2013-07-31 16:27:42 +00:00
|
|
|
// Return the new volume if AGC has changed the volume.
|
|
|
|
|
return static_cast<int>(
|
|
|
|
|
(new_voe_mic_level * max_volume +
|
|
|
|
|
static_cast<int>(kMaxVolumeLevel / 2)) / kMaxVolumeLevel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return 0 to indicate no change on the volume.
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 10:50:37 +00:00
|
|
|
void VoEBaseImpl::GetPlayoutData(int sample_rate, int number_of_channels,
|
|
|
|
|
int number_of_frames, bool feed_data_to_apm,
|
2014-05-19 17:39:11 +00:00
|
|
|
void* audio_data,
|
2014-06-05 20:34:08 +00:00
|
|
|
int64_t* elapsed_time_ms,
|
2014-05-19 17:39:11 +00:00
|
|
|
int64_t* ntp_time_ms) {
|
2014-04-14 10:50:37 +00:00
|
|
|
assert(_shared->output_mixer() != NULL);
|
|
|
|
|
|
|
|
|
|
// TODO(andrew): if the device is running in mono, we should tell the mixer
|
|
|
|
|
// here so that it will only request mono from AudioCodingModule.
|
|
|
|
|
// Perform mixing of all active participants (channel-based mixing)
|
|
|
|
|
_shared->output_mixer()->MixActiveChannels();
|
|
|
|
|
|
|
|
|
|
// Additional operations on the combined signal
|
|
|
|
|
_shared->output_mixer()->DoOperationsOnCombinedSignal(feed_data_to_apm);
|
|
|
|
|
|
|
|
|
|
// Retrieve the final output mix (resampled to match the ADM)
|
|
|
|
|
_shared->output_mixer()->GetMixedAudio(sample_rate, number_of_channels,
|
|
|
|
|
&_audioFrame);
|
|
|
|
|
|
|
|
|
|
assert(number_of_frames == _audioFrame.samples_per_channel_);
|
|
|
|
|
assert(sample_rate == _audioFrame.sample_rate_hz_);
|
|
|
|
|
|
|
|
|
|
// Deliver audio (PCM) samples to the ADM
|
|
|
|
|
memcpy(audio_data, _audioFrame.data_,
|
|
|
|
|
sizeof(int16_t) * number_of_frames * number_of_channels);
|
2014-05-19 17:39:11 +00:00
|
|
|
|
2014-06-05 20:34:08 +00:00
|
|
|
*elapsed_time_ms = _audioFrame.elapsed_time_ms_;
|
2014-05-19 17:39:11 +00:00
|
|
|
*ntp_time_ms = _audioFrame.ntp_time_ms_;
|
2014-04-14 10:50:37 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|