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 | |
leozwang@webrtc.org | 2db85bc | 2012-09-18 20:19:00 +0000 | [diff] [blame] | 11 | #if defined(WEBRTC_ANDROID) && !defined(WEBRTC_ANDROID_OPENSLES) |
leozwang@webrtc.org | 2a84f63 | 2012-10-03 21:40:06 +0000 | [diff] [blame] | 12 | #include "modules/audio_device/android/audio_device_jni_android.h" |
leozwang@webrtc.org | 2db85bc | 2012-09-18 20:19:00 +0000 | [diff] [blame] | 13 | #endif |
| 14 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 15 | #include "voice_engine_impl.h" |
| 16 | #include "trace.h" |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 17 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | namespace 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.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame^] | 25 | static int32_t gVoiceEngineInstanceCounter = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
| 27 | extern "C" |
| 28 | { |
| 29 | WEBRTC_DLLEXPORT VoiceEngine* GetVoiceEngine(); |
| 30 | |
| 31 | VoiceEngine* GetVoiceEngine() |
| 32 | { |
| 33 | VoiceEngineImpl* self = new VoiceEngineImpl(); |
tommi@webrtc.org | 0989fb7 | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 34 | if (self != NULL) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | { |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 36 | self->AddRef(); // First reference. Released in VoiceEngine::Delete. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | gVoiceEngineInstanceCounter++; |
| 38 | } |
tommi@webrtc.org | 0989fb7 | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 39 | return self; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | } |
| 41 | } // extern "C" |
| 42 | |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 43 | int VoiceEngineImpl::AddRef() { |
| 44 | return ++_ref_count; |
| 45 | } |
| 46 | |
| 47 | // This implements the Release() method for all the inherited interfaces. |
| 48 | int 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | VoiceEngine* 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 | |
| 83 | int VoiceEngine::SetTraceFilter(const unsigned int filter) |
| 84 | { |
| 85 | WEBRTC_TRACE(kTraceApiCall, kTraceVoice, |
| 86 | VoEId(gVoiceEngineInstanceCounter, -1), |
| 87 | "SetTraceFilter(filter=0x%x)", filter); |
| 88 | |
| 89 | // Remember old filter |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame^] | 90 | uint32_t oldFilter = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | Trace::LevelFilter(oldFilter); |
| 92 | |
| 93 | // Set new filter |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame^] | 94 | int32_t ret = Trace::SetLevelFilter(filter); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | |
| 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 | |
| 106 | int VoiceEngine::SetTraceFile(const char* fileNameUTF8, |
| 107 | const bool addFileCounter) |
| 108 | { |
| 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 | |
| 117 | int 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.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 125 | bool VoiceEngine::Delete(VoiceEngine*& voiceEngine) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 126 | { |
| 127 | if (voiceEngine == NULL) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | return false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | |
tommi@webrtc.org | 0989fb7 | 2013-02-15 15:07:32 +0000 | [diff] [blame] | 130 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 131 | // Release the reference that was added in GetVoiceEngine. |
| 132 | int ref = s->Release(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 133 | voiceEngine = NULL; |
| 134 | |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 135 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 141 | return true; |
| 142 | } |
| 143 | |
| 144 | int VoiceEngine::SetAndroidObjects(void* javaVM, void* env, void* context) |
| 145 | { |
leozwang@webrtc.org | cf1375a | 2012-09-21 17:39:45 +0000 | [diff] [blame] | 146 | #ifdef WEBRTC_ANDROID |
| 147 | #ifdef WEBRTC_ANDROID_OPENSLES |
| 148 | return 0; |
| 149 | #else |
leozwang@webrtc.org | 2db85bc | 2012-09-18 20:19:00 +0000 | [diff] [blame] | 150 | return AudioDeviceAndroidJni::SetAndroidAudioDeviceObjects( |
| 151 | javaVM, env, context); |
leozwang@webrtc.org | cf1375a | 2012-09-21 17:39:45 +0000 | [diff] [blame] | 152 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | #else |
leozwang@webrtc.org | 2db85bc | 2012-09-18 20:19:00 +0000 | [diff] [blame] | 154 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 155 | #endif |
| 156 | } |
| 157 | |
| 158 | } //namespace webrtc |