I mistakenly ommitted the checks when logging.h was ported from libjingle to webrtc. This caused a significant CPU cost for logs which were later filtered out anyway. Verified with LS_VERBOSE logging in neteq4, running: $ out/Release/modules_unittests \ --gtest_filter=NetEqDecodingTest.TestBitExactness \ --gtest_repeat=50 > time.txt $ grep "case ran" time.txt | grep "[0-9]* ms" -o | sort Results on a MacBook Retina, averaged over 5 runs: Verbose logs disabled: 666 ms Exisiting implementation, verbose logs enabled: 944 ms (1.42x) New implementation, verbose logs enabled: 673 ms (1.01x) BUG=2314 R=henrik.lundin@webrtc.org, henrike@webrtc.org, kjellander@webrtc.org, turaj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/2160005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4682 4adac7df-926f-26a2-2b94-8c16560cd09d
156 lines
4.2 KiB
C++
156 lines
4.2 KiB
C++
/*
|
|
* 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.
|
|
*/
|
|
|
|
#if defined(WEBRTC_ANDROID) && !defined(WEBRTC_ANDROID_OPENSLES)
|
|
#include "webrtc/modules/audio_device/android/audio_device_jni_android.h"
|
|
#endif
|
|
|
|
#include "webrtc/system_wrappers/interface/trace.h"
|
|
#include "webrtc/voice_engine/voice_engine_impl.h"
|
|
|
|
namespace webrtc
|
|
{
|
|
|
|
// 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.
|
|
static int32_t gVoiceEngineInstanceCounter = 0;
|
|
|
|
extern "C"
|
|
{
|
|
WEBRTC_DLLEXPORT VoiceEngine* GetVoiceEngine();
|
|
|
|
VoiceEngine* GetVoiceEngine()
|
|
{
|
|
VoiceEngineImpl* self = new VoiceEngineImpl();
|
|
if (self != NULL)
|
|
{
|
|
self->AddRef(); // First reference. Released in VoiceEngine::Delete.
|
|
gVoiceEngineInstanceCounter++;
|
|
}
|
|
return self;
|
|
}
|
|
} // extern "C"
|
|
|
|
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,
|
|
"VoiceEngineImpl self deleting (voiceEngine=0x%p)",
|
|
this);
|
|
|
|
delete this;
|
|
}
|
|
|
|
return new_ref;
|
|
}
|
|
|
|
VoiceEngine* VoiceEngine::Create()
|
|
{
|
|
#if (defined _WIN32)
|
|
HMODULE hmod_ = LoadLibrary(TEXT("VoiceEngineTestingDynamic.dll"));
|
|
|
|
if (hmod_)
|
|
{
|
|
typedef VoiceEngine* (*PfnGetVoiceEngine)(void);
|
|
PfnGetVoiceEngine pfn = (PfnGetVoiceEngine)GetProcAddress(
|
|
hmod_,"GetVoiceEngine");
|
|
if (pfn)
|
|
{
|
|
VoiceEngine* self = pfn();
|
|
return (self);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return GetVoiceEngine();
|
|
}
|
|
|
|
int VoiceEngine::SetTraceFilter(unsigned int filter)
|
|
{
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice,
|
|
VoEId(gVoiceEngineInstanceCounter, -1),
|
|
"SetTraceFilter(filter=0x%x)", filter);
|
|
|
|
// Remember old filter
|
|
uint32_t oldFilter = Trace::level_filter();
|
|
Trace::set_level_filter(filter);
|
|
|
|
// If previous log was ignored, log again after changing filter
|
|
if (kTraceNone == oldFilter)
|
|
{
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, -1,
|
|
"SetTraceFilter(filter=0x%x)", filter);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
int VoiceEngine::SetTraceCallback(TraceCallback* callback)
|
|
{
|
|
WEBRTC_TRACE(kTraceApiCall, kTraceVoice,
|
|
VoEId(gVoiceEngineInstanceCounter, -1),
|
|
"SetTraceCallback(callback=0x%x)", callback);
|
|
return (Trace::SetTraceCallback(callback));
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
int VoiceEngine::SetAndroidObjects(void* javaVM, void* env, void* context)
|
|
{
|
|
#ifdef WEBRTC_ANDROID
|
|
#ifdef WEBRTC_ANDROID_OPENSLES
|
|
return 0;
|
|
#else
|
|
return AudioDeviceAndroidJni::SetAndroidAudioDeviceObjects(
|
|
javaVM, env, context);
|
|
#endif
|
|
#else
|
|
return -1;
|
|
#endif
|
|
}
|
|
|
|
} // namespace webrtc
|