niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 | |
henrike@webrtc.org | 82f014a | 2013-09-10 18:24:07 +0000 | [diff] [blame^] | 11 | #if defined(WEBRTC_ANDROID) |
| 12 | #if defined(WEBRTC_ANDROID_OPENSLES) |
| 13 | #include "webrtc/modules/audio_device/android/audio_manager_jni.h" |
| 14 | #else |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 15 | #include "webrtc/modules/audio_device/android/audio_device_jni_android.h" |
leozwang@webrtc.org | 2db85bc | 2012-09-18 20:19:00 +0000 | [diff] [blame] | 16 | #endif |
henrike@webrtc.org | 82f014a | 2013-09-10 18:24:07 +0000 | [diff] [blame^] | 17 | #endif |
leozwang@webrtc.org | 2db85bc | 2012-09-18 20:19:00 +0000 | [diff] [blame] | 18 | |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 19 | #include "webrtc/system_wrappers/interface/trace.h" |
| 20 | #include "webrtc/voice_engine/voice_engine_impl.h" |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 21 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | namespace webrtc |
| 23 | { |
| 24 | |
| 25 | // Counter to be ensure that we can add a correct ID in all static trace |
| 26 | // methods. It is not the nicest solution, especially not since we already |
| 27 | // have a counter in VoEBaseImpl. In other words, there is room for |
| 28 | // improvement here. |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 29 | static int32_t gVoiceEngineInstanceCounter = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | |
| 31 | extern "C" |
| 32 | { |
| 33 | WEBRTC_DLLEXPORT VoiceEngine* GetVoiceEngine(); |
| 34 | |
| 35 | VoiceEngine* GetVoiceEngine() |
| 36 | { |
| 37 | VoiceEngineImpl* self = new VoiceEngineImpl(); |
tommi@webrtc.org | 0989fb7 | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 38 | if (self != NULL) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | { |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 40 | self->AddRef(); // First reference. Released in VoiceEngine::Delete. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | gVoiceEngineInstanceCounter++; |
| 42 | } |
tommi@webrtc.org | 0989fb7 | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 43 | return self; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | } |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 45 | } // extern "C" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 47 | int VoiceEngineImpl::AddRef() { |
| 48 | return ++_ref_count; |
| 49 | } |
| 50 | |
| 51 | // This implements the Release() method for all the inherited interfaces. |
| 52 | int VoiceEngineImpl::Release() { |
| 53 | int new_ref = --_ref_count; |
| 54 | assert(new_ref >= 0); |
| 55 | if (new_ref == 0) { |
| 56 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, -1, |
| 57 | "VoiceEngineImpl self deleting (voiceEngine=0x%p)", |
| 58 | this); |
| 59 | |
| 60 | delete this; |
| 61 | } |
| 62 | |
| 63 | return new_ref; |
| 64 | } |
| 65 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | VoiceEngine* VoiceEngine::Create() |
| 67 | { |
| 68 | #if (defined _WIN32) |
| 69 | HMODULE hmod_ = LoadLibrary(TEXT("VoiceEngineTestingDynamic.dll")); |
| 70 | |
| 71 | if (hmod_) |
| 72 | { |
| 73 | typedef VoiceEngine* (*PfnGetVoiceEngine)(void); |
| 74 | PfnGetVoiceEngine pfn = (PfnGetVoiceEngine)GetProcAddress( |
| 75 | hmod_,"GetVoiceEngine"); |
| 76 | if (pfn) |
| 77 | { |
| 78 | VoiceEngine* self = pfn(); |
| 79 | return (self); |
| 80 | } |
| 81 | } |
| 82 | #endif |
| 83 | |
| 84 | return GetVoiceEngine(); |
| 85 | } |
| 86 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 87 | int VoiceEngine::SetTraceFilter(unsigned int filter) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 88 | { |
| 89 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, |
| 90 | VoEId(gVoiceEngineInstanceCounter, -1), |
| 91 | "SetTraceFilter(filter=0x%x)", filter); |
| 92 | |
| 93 | // Remember old filter |
andrew@webrtc.org | 9080518 | 2013-09-05 16:40:43 +0000 | [diff] [blame] | 94 | uint32_t oldFilter = Trace::level_filter(); |
| 95 | Trace::set_level_filter(filter); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
andrew@webrtc.org | 9080518 | 2013-09-05 16:40:43 +0000 | [diff] [blame] | 104 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | int VoiceEngine::SetTraceFile(const char* fileNameUTF8, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 108 | bool addFileCounter) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
| 118 | int 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.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 126 | bool VoiceEngine::Delete(VoiceEngine*& voiceEngine) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 127 | { |
| 128 | if (voiceEngine == NULL) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | return false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | |
tommi@webrtc.org | 0989fb7 | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 131 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 132 | // Release the reference that was added in GetVoiceEngine. |
| 133 | int ref = s->Release(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | voiceEngine = NULL; |
| 135 | |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 136 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | return true; |
| 143 | } |
| 144 | |
| 145 | int VoiceEngine::SetAndroidObjects(void* javaVM, void* env, void* context) |
| 146 | { |
leozwang@webrtc.org | cf1375a | 2012-09-21 17:39:45 +0000 | [diff] [blame] | 147 | #ifdef WEBRTC_ANDROID |
| 148 | #ifdef WEBRTC_ANDROID_OPENSLES |
henrike@webrtc.org | 82f014a | 2013-09-10 18:24:07 +0000 | [diff] [blame^] | 149 | AudioManagerJni::SetAndroidAudioDeviceObjects(javaVM, env, context); |
leozwang@webrtc.org | cf1375a | 2012-09-21 17:39:45 +0000 | [diff] [blame] | 150 | return 0; |
| 151 | #else |
leozwang@webrtc.org | 2db85bc | 2012-09-18 20:19:00 +0000 | [diff] [blame] | 152 | return AudioDeviceAndroidJni::SetAndroidAudioDeviceObjects( |
| 153 | javaVM, env, context); |
leozwang@webrtc.org | cf1375a | 2012-09-21 17:39:45 +0000 | [diff] [blame] | 154 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 155 | #else |
leozwang@webrtc.org | 2db85bc | 2012-09-18 20:19:00 +0000 | [diff] [blame] | 156 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 157 | #endif |
| 158 | } |
| 159 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 160 | } // namespace webrtc |