blob: 18f841c296083990f4db59bb9153db526ecfd84b [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.
25static WebRtc_Word32 gVoiceEngineInstanceCounter = 0;
26
27extern "C"
28{
29WEBRTC_DLLEXPORT VoiceEngine* GetVoiceEngine();
30
31VoiceEngine* GetVoiceEngine()
32{
33 VoiceEngineImpl* self = new VoiceEngineImpl();
tommi@webrtc.orga990e122012-04-26 15:28:22 +000034 VoiceEngine* ve = reinterpret_cast<VoiceEngine*>(self);
niklase@google.com470e71d2011-07-07 08:21:25 +000035 if (ve != NULL)
36 {
tommi@webrtc.orga990e122012-04-26 15:28:22 +000037 self->AddRef(); // First reference. Released in VoiceEngine::Delete.
niklase@google.com470e71d2011-07-07 08:21:25 +000038 gVoiceEngineInstanceCounter++;
39 }
40 return ve;
41}
42} // extern "C"
43
tommi@webrtc.orga990e122012-04-26 15:28:22 +000044int VoiceEngineImpl::AddRef() {
45 return ++_ref_count;
46}
47
48// This implements the Release() method for all the inherited interfaces.
49int VoiceEngineImpl::Release() {
50 int new_ref = --_ref_count;
51 assert(new_ref >= 0);
52 if (new_ref == 0) {
53 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, -1,
54 "VoiceEngineImpl self deleting (voiceEngine=0x%p)",
55 this);
56
57 delete this;
58 }
59
60 return new_ref;
61}
62
niklase@google.com470e71d2011-07-07 08:21:25 +000063VoiceEngine* VoiceEngine::Create()
64{
65#if (defined _WIN32)
66 HMODULE hmod_ = LoadLibrary(TEXT("VoiceEngineTestingDynamic.dll"));
67
68 if (hmod_)
69 {
70 typedef VoiceEngine* (*PfnGetVoiceEngine)(void);
71 PfnGetVoiceEngine pfn = (PfnGetVoiceEngine)GetProcAddress(
72 hmod_,"GetVoiceEngine");
73 if (pfn)
74 {
75 VoiceEngine* self = pfn();
76 return (self);
77 }
78 }
79#endif
80
81 return GetVoiceEngine();
82}
83
84int VoiceEngine::SetTraceFilter(const unsigned int filter)
85{
86 WEBRTC_TRACE(kTraceApiCall, kTraceVoice,
87 VoEId(gVoiceEngineInstanceCounter, -1),
88 "SetTraceFilter(filter=0x%x)", filter);
89
90 // Remember old filter
91 WebRtc_UWord32 oldFilter = 0;
92 Trace::LevelFilter(oldFilter);
93
94 // Set new filter
95 WebRtc_Word32 ret = Trace::SetLevelFilter(filter);
96
97 // If previous log was ignored, log again after changing filter
98 if (kTraceNone == oldFilter)
99 {
100 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, -1,
101 "SetTraceFilter(filter=0x%x)", filter);
102 }
103
104 return (ret);
105}
106
107int VoiceEngine::SetTraceFile(const char* fileNameUTF8,
108 const bool addFileCounter)
109{
110 int ret = Trace::SetTraceFile(fileNameUTF8, addFileCounter);
111 WEBRTC_TRACE(kTraceApiCall, kTraceVoice,
112 VoEId(gVoiceEngineInstanceCounter, -1),
113 "SetTraceFile(fileNameUTF8=%s, addFileCounter=%d)",
114 fileNameUTF8, addFileCounter);
115 return (ret);
116}
117
118int VoiceEngine::SetTraceCallback(TraceCallback* callback)
119{
120 WEBRTC_TRACE(kTraceApiCall, kTraceVoice,
121 VoEId(gVoiceEngineInstanceCounter, -1),
122 "SetTraceCallback(callback=0x%x)", callback);
123 return (Trace::SetTraceCallback(callback));
124}
125
tommi@webrtc.orga990e122012-04-26 15:28:22 +0000126bool VoiceEngine::Delete(VoiceEngine*& voiceEngine)
niklase@google.com470e71d2011-07-07 08:21:25 +0000127{
128 if (voiceEngine == NULL)
niklase@google.com470e71d2011-07-07 08:21:25 +0000129 return false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000130
tommi@webrtc.orga990e122012-04-26 15:28:22 +0000131 VoiceEngineImpl* s = reinterpret_cast<VoiceEngineImpl*>(voiceEngine);
132 // Release the reference that was added in GetVoiceEngine.
133 int ref = s->Release();
niklase@google.com470e71d2011-07-07 08:21:25 +0000134 voiceEngine = NULL;
135
tommi@webrtc.orga990e122012-04-26 15:28:22 +0000136 if (ref != 0) {
137 WEBRTC_TRACE(kTraceWarning, kTraceVoice, -1,
138 "VoiceEngine::Delete did not release the very last reference. "
139 "%d references remain.", ref);
140 }
141
niklase@google.com470e71d2011-07-07 08:21:25 +0000142 return true;
143}
144
145int VoiceEngine::SetAndroidObjects(void* javaVM, void* env, void* context)
146{
leozwang@webrtc.orgcf1375a2012-09-21 17:39:45 +0000147#ifdef WEBRTC_ANDROID
148#ifdef WEBRTC_ANDROID_OPENSLES
149 return 0;
150#else
leozwang@webrtc.org2db85bc2012-09-18 20:19:00 +0000151 return AudioDeviceAndroidJni::SetAndroidAudioDeviceObjects(
152 javaVM, env, context);
leozwang@webrtc.orgcf1375a2012-09-21 17:39:45 +0000153#endif
niklase@google.com470e71d2011-07-07 08:21:25 +0000154#else
leozwang@webrtc.org2db85bc2012-09-18 20:19:00 +0000155 return -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000156#endif
157}
158
159} //namespace webrtc