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