niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | ae19720 | 2012-04-04 14:43:54 +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 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 11 | #include "video_engine/vie_impl.h" |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 12 | #include "system_wrappers/interface/trace.h" |
| 13 | |
leozwang@google.com | 22b699d | 2011-08-09 17:27:33 +0000 | [diff] [blame] | 14 | #ifdef WEBRTC_ANDROID |
andrew@webrtc.org | 94caca7 | 2012-10-30 21:58:00 +0000 | [diff] [blame] | 15 | #include "webrtc/modules/video_capture/include/video_capture_factory.h" |
andrew@webrtc.org | 9841d92 | 2012-10-31 05:22:11 +0000 | [diff] [blame] | 16 | #include "webrtc/modules/video_render/include/video_render.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | #endif |
| 18 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 19 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 21 | enum { kModuleId = 0 }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 23 | VideoEngine* VideoEngine::Create() { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 24 | return new VideoEngineImpl(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | } |
| 26 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 27 | bool VideoEngine::Delete(VideoEngine*& video_engine) { |
| 28 | if (!video_engine) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 29 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 30 | "VideoEngine::Delete - No argument"); |
| 31 | return false; |
| 32 | } |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 33 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 34 | "VideoEngine::Delete(vie = 0x%p)", video_engine); |
andrew@webrtc.org | d72262d | 2013-05-09 02:12:07 +0000 | [diff] [blame] | 35 | VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 37 | // Check all reference counters. |
| 38 | ViEBaseImpl* vie_base = vie_impl; |
| 39 | if (vie_base->GetCount() > 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 40 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 41 | "ViEBase ref count: %d", vie_base->GetCount()); |
| 42 | return false; |
| 43 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | #ifdef WEBRTC_VIDEO_ENGINE_CAPTURE_API |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 45 | ViECaptureImpl* vie_capture = vie_impl; |
| 46 | if (vie_capture->GetCount() > 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 47 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 48 | "ViECapture ref count: %d", vie_capture->GetCount()); |
| 49 | return false; |
| 50 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | #endif |
| 52 | #ifdef WEBRTC_VIDEO_ENGINE_CODEC_API |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 53 | ViECodecImpl* vie_codec = vie_impl; |
| 54 | if (vie_codec->GetCount() > 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 55 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 56 | "ViECodec ref count: %d", vie_codec->GetCount()); |
| 57 | return false; |
| 58 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | #endif |
| 60 | #ifdef WEBRTC_VIDEO_ENGINE_ENCRYPTION_API |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 61 | ViEEncryptionImpl* vie_encryption = vie_impl; |
| 62 | if (vie_encryption->GetCount() > 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 63 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 64 | "ViEEncryption ref count: %d", vie_encryption->GetCount()); |
| 65 | return false; |
| 66 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | #endif |
| 68 | #ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 69 | ViEExternalCodecImpl* vie_external_codec = vie_impl; |
| 70 | if (vie_external_codec->GetCount() > 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 71 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 72 | "ViEEncryption ref count: %d", vie_encryption->GetCount()); |
| 73 | return false; |
| 74 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | #endif |
| 76 | #ifdef WEBRTC_VIDEO_ENGINE_FILE_API |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 77 | ViEFileImpl* vie_file = vie_impl; |
| 78 | if (vie_file->GetCount() > 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 79 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 80 | "ViEFile ref count: %d", vie_file->GetCount()); |
| 81 | return false; |
| 82 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | #endif |
| 84 | #ifdef WEBRTC_VIDEO_ENGINE_IMAGE_PROCESS_API |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 85 | ViEImageProcessImpl* vie_image_process = vie_impl; |
| 86 | if (vie_image_process->GetCount() > 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 87 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 88 | "ViEImageProcess ref count: %d", |
| 89 | vie_image_process->GetCount()); |
| 90 | return false; |
| 91 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 92 | #endif |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 93 | ViENetworkImpl* vie_network = vie_impl; |
| 94 | if (vie_network->GetCount() > 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 95 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 96 | "ViENetwork ref count: %d", vie_network->GetCount()); |
| 97 | return false; |
| 98 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | #ifdef WEBRTC_VIDEO_ENGINE_RENDER_API |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 100 | ViERenderImpl* vie_render = vie_impl; |
| 101 | if (vie_render->GetCount() > 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 102 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 103 | "ViERender ref count: %d", vie_render->GetCount()); |
| 104 | return false; |
| 105 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | #endif |
| 107 | #ifdef WEBRTC_VIDEO_ENGINE_RTP_RTCP_API |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 108 | ViERTP_RTCPImpl* vie_rtp_rtcp = vie_impl; |
| 109 | if (vie_rtp_rtcp->GetCount() > 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 110 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 111 | "ViERTP_RTCP ref count: %d", vie_rtp_rtcp->GetCount()); |
| 112 | return false; |
| 113 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | #endif |
| 115 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 116 | delete vie_impl; |
| 117 | vie_impl = NULL; |
| 118 | video_engine = NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 120 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, kModuleId, |
| 121 | "%s: instance deleted.", __FUNCTION__); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 122 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 123 | } |
| 124 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 125 | int VideoEngine::SetTraceFile(const char* file_nameUTF8, |
| 126 | const bool add_file_counter) { |
| 127 | if (!file_nameUTF8) { |
| 128 | return -1; |
| 129 | } |
| 130 | if (Trace::SetTraceFile(file_nameUTF8, add_file_counter) == -1) { |
| 131 | return -1; |
| 132 | } |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 133 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 134 | "SetTraceFileName(file_nameUTF8 = %s, add_file_counter = %d", |
| 135 | file_nameUTF8, add_file_counter); |
| 136 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | } |
| 138 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 139 | int VideoEngine::SetTraceFilter(const unsigned int filter) { |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 140 | uint32_t old_filter = 0; |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 141 | Trace::LevelFilter(old_filter); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 143 | if (filter == kTraceNone && old_filter != kTraceNone) { |
| 144 | // Do the logging before turning it off. |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 145 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 146 | "SetTraceFilter(filter = 0x%x)", filter); |
| 147 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 148 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 149 | int32_t error = Trace::SetLevelFilter(filter); |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 150 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 151 | "SetTraceFilter(filter = 0x%x)", filter); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 152 | if (error != 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 153 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 154 | "SetTraceFilter error: %d", error); |
| 155 | return -1; |
| 156 | } |
| 157 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 158 | } |
| 159 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 160 | int VideoEngine::SetTraceCallback(TraceCallback* callback) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 161 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 162 | "SetTraceCallback(TraceCallback = 0x%p)", callback); |
| 163 | return Trace::SetTraceCallback(callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 164 | } |
| 165 | |
leozwang@webrtc.org | f9cd693 | 2012-01-23 16:56:13 +0000 | [diff] [blame] | 166 | int VideoEngine::SetAndroidObjects(void* javaVM, void* javaContext) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 167 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 168 | "SetAndroidObjects()"); |
| 169 | |
leozwang@webrtc.org | 7760963 | 2012-07-13 22:00:43 +0000 | [diff] [blame] | 170 | #if defined(WEBRTC_ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) |
| 171 | if (SetCaptureAndroidVM(javaVM, javaContext) != 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 172 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
leozwang@webrtc.org | 7760963 | 2012-07-13 22:00:43 +0000 | [diff] [blame] | 173 | "Could not set capture Android VM"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 174 | return -1; |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 175 | } |
leozwang@webrtc.org | 7760963 | 2012-07-13 22:00:43 +0000 | [diff] [blame] | 176 | if (SetRenderAndroidVM(javaVM) != 0) { |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 177 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
leozwang@webrtc.org | 7760963 | 2012-07-13 22:00:43 +0000 | [diff] [blame] | 178 | "Could not set render Android VM"); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 179 | return -1; |
| 180 | } |
| 181 | return 0; |
| 182 | #else |
andresp@webrtc.org | 4427273 | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 183 | WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId, |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 184 | "WEBRTC_ANDROID not defined for VideoEngine::SetAndroidObjects"); |
| 185 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 186 | #endif |
| 187 | } |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 188 | |
| 189 | } // namespace webrtc |