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) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 12 | #include "modules/audio_device/android/audio_device_template.h" |
| 13 | #include "modules/audio_device/android/audio_record_jni.h" |
| 14 | #include "modules/audio_device/android/audio_track_jni.h" |
henrika@webrtc.org | 8883a0f | 2014-04-09 13:04:12 +0000 | [diff] [blame] | 15 | #endif |
leozwang@webrtc.org | 2db85bc | 2012-09-18 20:19:00 +0000 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/audio_coding/include/audio_coding_module.h" |
| 18 | #include "rtc_base/checks.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "voice_engine/channel_proxy.h" |
| 20 | #include "voice_engine/voice_engine_impl.h" |
henrika@google.com | 73d6551 | 2011-09-07 15:11:18 +0000 | [diff] [blame] | 21 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 22 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | // Counter to be ensure that we can add a correct ID in all static trace |
| 25 | // methods. It is not the nicest solution, especially not since we already |
| 26 | // have a counter in VoEBaseImpl. In other words, there is room for |
| 27 | // improvement here. |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 28 | static int32_t gVoiceEngineInstanceCounter = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 30 | VoiceEngine* GetVoiceEngine() { |
| 31 | VoiceEngineImpl* self = new VoiceEngineImpl(); |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 32 | if (self != NULL) { |
| 33 | self->AddRef(); // First reference. Released in VoiceEngine::Delete. |
| 34 | gVoiceEngineInstanceCounter++; |
| 35 | } |
| 36 | return self; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 39 | int VoiceEngineImpl::AddRef() { |
| 40 | return ++_ref_count; |
| 41 | } |
| 42 | |
| 43 | // This implements the Release() method for all the inherited interfaces. |
| 44 | int VoiceEngineImpl::Release() { |
| 45 | int new_ref = --_ref_count; |
| 46 | assert(new_ref >= 0); |
| 47 | if (new_ref == 0) { |
henrika@webrtc.org | 944cbeb | 2014-03-18 10:32:33 +0000 | [diff] [blame] | 48 | // Clear any pointers before starting destruction. Otherwise worker- |
| 49 | // threads will still have pointers to a partially destructed object. |
| 50 | // Example: AudioDeviceBuffer::RequestPlayoutData() can access a |
| 51 | // partially deconstructed |_ptrCbAudioTransport| during destruction |
| 52 | // if we don't call Terminate here. |
| 53 | Terminate(); |
tommi@webrtc.org | a990e12 | 2012-04-26 15:28:22 +0000 | [diff] [blame] | 54 | delete this; |
| 55 | } |
| 56 | |
| 57 | return new_ref; |
| 58 | } |
| 59 | |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 60 | std::unique_ptr<voe::ChannelProxy> VoiceEngineImpl::GetChannelProxy( |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 61 | int channel_id) { |
| 62 | RTC_DCHECK(channel_id >= 0); |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 63 | rtc::CritScope cs(crit_sec()); |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 64 | return std::unique_ptr<voe::ChannelProxy>( |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 65 | new voe::ChannelProxy(channel_manager().GetChannel(channel_id))); |
| 66 | } |
| 67 | |
minyue@webrtc.org | e509f94 | 2013-09-12 17:03:00 +0000 | [diff] [blame] | 68 | VoiceEngine* VoiceEngine::Create() { |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 69 | return GetVoiceEngine(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 72 | bool VoiceEngine::Delete(VoiceEngine*& voiceEngine) { |
| 73 | if (voiceEngine == NULL) |
| 74 | return false; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 76 | VoiceEngineImpl* s = static_cast<VoiceEngineImpl*>(voiceEngine); |
Fredrik Solenberg | 4332d09 | 2017-10-04 09:53:35 +0200 | [diff] [blame] | 77 | s->Release(); |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 78 | voiceEngine = NULL; |
Jelena Marusic | 0d26605 | 2015-05-04 14:15:32 +0200 | [diff] [blame] | 79 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | } |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 81 | } // namespace webrtc |