blob: 30609b26f9f4611b419170a25270702f70672eb7 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
tommi@webrtc.orga990e122012-04-26 15:28:22 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
leozwang@webrtc.org2db85bc2012-09-18 20:19:00 +000011#if defined(WEBRTC_ANDROID) && !defined(WEBRTC_ANDROID_OPENSLES)
leozwang@webrtc.org2a84f632012-10-03 21:40:06 +000012#include "modules/audio_device/android/audio_device_jni_android.h"
leozwang@webrtc.org2db85bc2012-09-18 20:19:00 +000013#endif
14
niklase@google.com470e71d2011-07-07 08:21:25 +000015#include "voice_engine_impl.h"
16#include "trace.h"
henrika@google.com73d65512011-09-07 15:11:18 +000017
niklase@google.com470e71d2011-07-07 08:21:25 +000018namespace webrtc
19{
20
21// Counter to be ensure that we can add a correct ID in all static trace
22// methods. It is not the nicest solution, especially not since we already
23// have a counter in VoEBaseImpl. In other words, there is room for
24// improvement here.
pbos@webrtc.org6141e132013-04-09 10:09:10 +000025static int32_t gVoiceEngineInstanceCounter = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000026
27extern "C"
28{
29WEBRTC_DLLEXPORT VoiceEngine* GetVoiceEngine();
30
31VoiceEngine* GetVoiceEngine()
32{
33 VoiceEngineImpl* self = new VoiceEngineImpl();
tommi@webrtc.org0989fb72013-02-15 15:07:32 +000034 if (self != NULL)
niklase@google.com470e71d2011-07-07 08:21:25 +000035 {
tommi@webrtc.orga990e122012-04-26 15:28:22 +000036 self->AddRef(); // First reference. Released in VoiceEngine::Delete.
niklase@google.com470e71d2011-07-07 08:21:25 +000037 gVoiceEngineInstanceCounter++;
38 }
tommi@webrtc.org0989fb72013-02-15 15:07:32 +000039 return self;
niklase@google.com470e71d2011-07-07 08:21:25 +000040}
41} // extern "C"
42
tommi@webrtc.orga990e122012-04-26 15:28:22 +000043int VoiceEngineImpl::AddRef() {
44 return ++_ref_count;
45}
46
47// This implements the Release() method for all the inherited interfaces.
48int VoiceEngineImpl::Release() {
49 int new_ref = --_ref_count;
50 assert(new_ref >= 0);
51 if (new_ref == 0) {
52 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, -1,
53 "VoiceEngineImpl self deleting (voiceEngine=0x%p)",
54 this);
55
56 delete this;
57 }
58
59 return new_ref;
60}
61
niklase@google.com470e71d2011-07-07 08:21:25 +000062VoiceEngine* VoiceEngine::Create()
63{
64#if (defined _WIN32)
65 HMODULE hmod_ = LoadLibrary(TEXT("VoiceEngineTestingDynamic.dll"));
66
67 if (hmod_)
68 {
69 typedef VoiceEngine* (*PfnGetVoiceEngine)(void);
70 PfnGetVoiceEngine pfn = (PfnGetVoiceEngine)GetProcAddress(
71 hmod_,"GetVoiceEngine");
72 if (pfn)
73 {
74 VoiceEngine* self = pfn();
75 return (self);
76 }
77 }
78#endif
79
80 return GetVoiceEngine();
81}
82
pbos@webrtc.org92135212013-05-14 08:31:39 +000083int VoiceEngine::SetTraceFilter(unsigned int filter)
niklase@google.com470e71d2011-07-07 08:21:25 +000084{
85 WEBRTC_TRACE(kTraceApiCall, kTraceVoice,
86 VoEId(gVoiceEngineInstanceCounter, -1),
87 "SetTraceFilter(filter=0x%x)", filter);
88
89 // Remember old filter
pbos@webrtc.org6141e132013-04-09 10:09:10 +000090 uint32_t oldFilter = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000091 Trace::LevelFilter(oldFilter);
92
93 // Set new filter
pbos@webrtc.org6141e132013-04-09 10:09:10 +000094 int32_t ret = Trace::SetLevelFilter(filter);
niklase@google.com470e71d2011-07-07 08:21:25 +000095
96 // If previous log was ignored, log again after changing filter
97 if (kTraceNone == oldFilter)
98 {
99 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, -1,
100 "SetTraceFilter(filter=0x%x)", filter);
101 }
102
103 return (ret);
104}
105
106int VoiceEngine::SetTraceFile(const char* fileNameUTF8,
pbos@webrtc.org92135212013-05-14 08:31:39 +0000107 bool addFileCounter)
niklase@google.com470e71d2011-07-07 08:21:25 +0000108{
109 int ret = Trace::SetTraceFile(fileNameUTF8, addFileCounter);
110 WEBRTC_TRACE(kTraceApiCall, kTraceVoice,
111 VoEId(gVoiceEngineInstanceCounter, -1),
112 "SetTraceFile(fileNameUTF8=%s, addFileCounter=%d)",
113 fileNameUTF8, addFileCounter);
114 return (ret);
115}
116
117int VoiceEngine::SetTraceCallback(TraceCallback* callback)
118{
119 WEBRTC_TRACE(kTraceApiCall, kTraceVoice,
120 VoEId(gVoiceEngineInstanceCounter, -1),
121 "SetTraceCallback(callback=0x%x)", callback);
122 return (Trace::SetTraceCallback(callback));
123}
124
tommi@webrtc.orga990e122012-04-26 15:28:22 +0000125bool VoiceEngine::Delete(VoiceEngine*& voiceEngine)
niklase@google.com470e71d2011-07-07 08:21:25 +0000126{
127 if (voiceEngine == NULL)
niklase@google.com470e71d2011-07-07 08:21:25 +0000128 return false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
tommi@webrtc.org0989fb72013-02-15 15:07:32 +0000130 VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine);
tommi@webrtc.orga990e122012-04-26 15:28:22 +0000131 // Release the reference that was added in GetVoiceEngine.
132 int ref = s->Release();
niklase@google.com470e71d2011-07-07 08:21:25 +0000133 voiceEngine = NULL;
134
tommi@webrtc.orga990e122012-04-26 15:28:22 +0000135 if (ref != 0) {
136 WEBRTC_TRACE(kTraceWarning, kTraceVoice, -1,
137 "VoiceEngine::Delete did not release the very last reference. "
138 "%d references remain.", ref);
139 }
140
niklase@google.com470e71d2011-07-07 08:21:25 +0000141 return true;
142}
143
144int VoiceEngine::SetAndroidObjects(void* javaVM, void* env, void* context)
145{
leozwang@webrtc.orgcf1375a2012-09-21 17:39:45 +0000146#ifdef WEBRTC_ANDROID
147#ifdef WEBRTC_ANDROID_OPENSLES
148 return 0;
149#else
leozwang@webrtc.org2db85bc2012-09-18 20:19:00 +0000150 return AudioDeviceAndroidJni::SetAndroidAudioDeviceObjects(
151 javaVM, env, context);
leozwang@webrtc.orgcf1375a2012-09-21 17:39:45 +0000152#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000153#else
leozwang@webrtc.org2db85bc2012-09-18 20:19:00 +0000154 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000155#endif
156}
157
158} //namespace webrtc