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)
|
2013-12-11 21:42:44 +00:00
|
|
|
#include "webrtc/modules/audio_device/android/audio_device_template.h"
|
|
|
|
|
#include "webrtc/modules/audio_device/android/audio_record_jni.h"
|
|
|
|
|
#include "webrtc/modules/audio_device/android/audio_track_jni.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
#include "webrtc/modules/utility/include/jvm_android.h"
|
2014-04-09 13:04:12 +00:00
|
|
|
#endif
|
2012-09-18 20:19:00 +00:00
|
|
|
|
2015-11-25 08:16:52 -08:00
|
|
|
#include "webrtc/base/checks.h"
|
2015-11-26 04:44:54 -08:00
|
|
|
#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/trace.h"
|
2015-11-25 08:16:52 -08:00
|
|
|
#include "webrtc/voice_engine/channel_proxy.h"
|
2013-05-21 13:52:32 +00:00
|
|
|
#include "webrtc/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
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
VoiceEngine* GetVoiceEngine(const Config* config, bool owns_config) {
|
|
|
|
|
VoiceEngineImpl* self = new VoiceEngineImpl(config, owns_config);
|
|
|
|
|
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) {
|
|
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, -1,
|
2015-05-04 14:15:32 +02:00
|
|
|
"VoiceEngineImpl self deleting (voiceEngine=0x%p)", this);
|
2012-04-26 15:28:22 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-25 08:16:52 -08:00
|
|
|
rtc::scoped_ptr<voe::ChannelProxy> VoiceEngineImpl::GetChannelProxy(
|
|
|
|
|
int channel_id) {
|
|
|
|
|
RTC_DCHECK(channel_id >= 0);
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope cs(crit_sec());
|
2015-11-25 08:16:52 -08:00
|
|
|
RTC_DCHECK(statistics().Initialized());
|
|
|
|
|
return rtc::scoped_ptr<voe::ChannelProxy>(
|
|
|
|
|
new voe::ChannelProxy(channel_manager().GetChannel(channel_id)));
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-12 17:03:00 +00:00
|
|
|
VoiceEngine* VoiceEngine::Create() {
|
|
|
|
|
Config* config = new Config();
|
|
|
|
|
return GetVoiceEngine(config, true);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-09-12 17:03:00 +00:00
|
|
|
VoiceEngine* VoiceEngine::Create(const Config& config) {
|
|
|
|
|
return GetVoiceEngine(&config, false);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
int VoiceEngine::SetTraceFilter(unsigned int filter) {
|
|
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice,
|
|
|
|
|
VoEId(gVoiceEngineInstanceCounter, -1),
|
|
|
|
|
"SetTraceFilter(filter=0x%x)", filter);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
// Remember old filter
|
|
|
|
|
uint32_t oldFilter = Trace::level_filter();
|
|
|
|
|
Trace::set_level_filter(filter);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
// If previous log was ignored, log again after changing filter
|
|
|
|
|
if (kTraceNone == oldFilter) {
|
|
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, -1, "SetTraceFilter(filter=0x%x)",
|
|
|
|
|
filter);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
int VoiceEngine::SetTraceFile(const char* fileNameUTF8, bool addFileCounter) {
|
|
|
|
|
int ret = Trace::SetTraceFile(fileNameUTF8, addFileCounter);
|
|
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice,
|
|
|
|
|
VoEId(gVoiceEngineInstanceCounter, -1),
|
|
|
|
|
"SetTraceFile(fileNameUTF8=%s, addFileCounter=%d)", fileNameUTF8,
|
|
|
|
|
addFileCounter);
|
|
|
|
|
return (ret);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
int VoiceEngine::SetTraceCallback(TraceCallback* callback) {
|
|
|
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice,
|
|
|
|
|
VoEId(gVoiceEngineInstanceCounter, -1),
|
|
|
|
|
"SetTraceCallback(callback=0x%x)", callback);
|
|
|
|
|
return (Trace::SetTraceCallback(callback));
|
|
|
|
|
}
|
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);
|
|
|
|
|
// Release the reference that was added in GetVoiceEngine.
|
|
|
|
|
int ref = s->Release();
|
|
|
|
|
voiceEngine = NULL;
|
|
|
|
|
|
|
|
|
|
if (ref != 0) {
|
|
|
|
|
WEBRTC_TRACE(
|
|
|
|
|
kTraceWarning, kTraceVoice, -1,
|
|
|
|
|
"VoiceEngine::Delete did not release the very last reference. "
|
|
|
|
|
"%d references remain.",
|
|
|
|
|
ref);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-05-04 14:15:32 +02:00
|
|
|
return true;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-09 13:04:12 +00:00
|
|
|
#if !defined(WEBRTC_CHROMIUM_BUILD)
|
Adding support for OpenSL ES output in native WebRTC
BUG=4573,2982,2175,3590
TEST=modules_unittests --gtest_filter=AudioDevice*, AppRTCDemo and WebRTCDemo
Summary:
- Removes dependency of the 'enable_android_opensl' compiler flag.
Instead, OpenSL ES is always supported, and will enabled for devices that
supports low-latency output.
- WebRTC no longer supports OpenSL ES for the input/recording side.
- Removes old code and demos using OpenSL ES for audio input.
- Improves accuracy of total delay estimates (better AEC performance).
- Reduces roundtrip audio latency; especially when OpenSL can be used.
Performance verified on: Nexus 5, 6, 7 and 9. Samsung Galaxy S4 and S6.
Android One device.
R=magjed@webrtc.org, phoglund@webrtc.org, tommi@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/51759004
Cr-Commit-Position: refs/heads/master@{#9208}
2015-05-18 16:49:16 +02:00
|
|
|
// TODO(henrika): change types to JavaVM* and jobject instead of void*.
|
2015-05-04 14:15:32 +02:00
|
|
|
int VoiceEngine::SetAndroidObjects(void* javaVM, void* context) {
|
2012-09-21 17:39:45 +00:00
|
|
|
#ifdef WEBRTC_ANDROID
|
Adding support for OpenSL ES output in native WebRTC
BUG=4573,2982,2175,3590
TEST=modules_unittests --gtest_filter=AudioDevice*, AppRTCDemo and WebRTCDemo
Summary:
- Removes dependency of the 'enable_android_opensl' compiler flag.
Instead, OpenSL ES is always supported, and will enabled for devices that
supports low-latency output.
- WebRTC no longer supports OpenSL ES for the input/recording side.
- Removes old code and demos using OpenSL ES for audio input.
- Improves accuracy of total delay estimates (better AEC performance).
- Reduces roundtrip audio latency; especially when OpenSL can be used.
Performance verified on: Nexus 5, 6, 7 and 9. Samsung Galaxy S4 and S6.
Android One device.
R=magjed@webrtc.org, phoglund@webrtc.org, tommi@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/51759004
Cr-Commit-Position: refs/heads/master@{#9208}
2015-05-18 16:49:16 +02:00
|
|
|
webrtc::JVM::Initialize(reinterpret_cast<JavaVM*>(javaVM),
|
|
|
|
|
reinterpret_cast<jobject>(context));
|
2014-01-10 22:58:06 +00:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
#else
|
2012-09-18 20:19:00 +00:00
|
|
|
return -1;
|
2011-07-07 08:21:25 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
2014-04-09 13:04:12 +00:00
|
|
|
#endif
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-02 06:19:36 -08:00
|
|
|
std::string VoiceEngine::GetVersionString() {
|
|
|
|
|
std::string version = "VoiceEngine 4.1.0";
|
|
|
|
|
#ifdef WEBRTC_EXTERNAL_TRANSPORT
|
|
|
|
|
version += " (External transport build)";
|
|
|
|
|
#endif
|
|
|
|
|
return version;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|