2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-04-26 15:28:22 +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-09-10 18:24:07 +00:00
|
|
|
#if defined(WEBRTC_ANDROID)
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_device/android/audio_device_template.h"
|
|
|
|
|
#include "modules/audio_device/android/audio_record_jni.h"
|
|
|
|
|
#include "modules/audio_device/android/audio_track_jni.h"
|
2014-04-09 13:04:12 +00:00
|
|
|
#endif
|
2012-09-18 20:19:00 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_coding/include/audio_coding_module.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "voice_engine/channel_proxy.h"
|
|
|
|
|
#include "voice_engine/voice_engine_impl.h"
|
2011-09-07 15:11:18 +00:00
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
namespace webrtc {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// Counter to be ensure that we can add a correct ID in all static trace
|
|
|
|
|
// methods. It is not the nicest solution, especially not since we already
|
|
|
|
|
// have a counter in VoEBaseImpl. In other words, there is room for
|
|
|
|
|
// improvement here.
|
2013-04-09 10:09:10 +00:00
|
|
|
static int32_t gVoiceEngineInstanceCounter = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-07 07:34:41 -07:00
|
|
|
VoiceEngine* GetVoiceEngine() {
|
|
|
|
|
VoiceEngineImpl* self = new VoiceEngineImpl();
|
2015-05-04 14:15:32 +02:00
|
|
|
if (self != NULL) {
|
|
|
|
|
self->AddRef(); // First reference. Released in VoiceEngine::Delete.
|
|
|
|
|
gVoiceEngineInstanceCounter++;
|
|
|
|
|
}
|
|
|
|
|
return self;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-26 15:28:22 +00:00
|
|
|
int VoiceEngineImpl::AddRef() {
|
|
|
|
|
return ++_ref_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This implements the Release() method for all the inherited interfaces.
|
|
|
|
|
int VoiceEngineImpl::Release() {
|
|
|
|
|
int new_ref = --_ref_count;
|
|
|
|
|
assert(new_ref >= 0);
|
|
|
|
|
if (new_ref == 0) {
|
2014-03-18 10:32:33 +00:00
|
|
|
// Clear any pointers before starting destruction. Otherwise worker-
|
|
|
|
|
// threads will still have pointers to a partially destructed object.
|
|
|
|
|
// Example: AudioDeviceBuffer::RequestPlayoutData() can access a
|
|
|
|
|
// partially deconstructed |_ptrCbAudioTransport| during destruction
|
|
|
|
|
// if we don't call Terminate here.
|
|
|
|
|
Terminate();
|
2012-04-26 15:28:22 +00:00
|
|
|
delete this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new_ref;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 10:04:18 -08:00
|
|
|
std::unique_ptr<voe::ChannelProxy> VoiceEngineImpl::GetChannelProxy(
|
2015-11-25 08:16:52 -08:00
|
|
|
int channel_id) {
|
|
|
|
|
RTC_DCHECK(channel_id >= 0);
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope cs(crit_sec());
|
2016-02-17 10:04:18 -08:00
|
|
|
return std::unique_ptr<voe::ChannelProxy>(
|
2015-11-25 08:16:52 -08:00
|
|
|
new voe::ChannelProxy(channel_manager().GetChannel(channel_id)));
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-12 17:03:00 +00:00
|
|
|
VoiceEngine* VoiceEngine::Create() {
|
2016-09-07 07:34:41 -07:00
|
|
|
return GetVoiceEngine();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
bool VoiceEngine::Delete(VoiceEngine*& voiceEngine) {
|
|
|
|
|
if (voiceEngine == NULL)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
|
2017-10-04 09:53:35 +02:00
|
|
|
s->Release();
|
2015-05-04 14:15:32 +02:00
|
|
|
voiceEngine = NULL;
|
|
|
|
|
return true;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|