blob: 349a996f74ada4fef96ea33b173e7856ddb30a81 [file] [log] [blame]
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +00001/*
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.orgad2b3682013-05-13 10:50:50 +000011#include "webrtc/video_engine/vie_impl.h"
12
13#include "webrtc/common.h"
14#include "webrtc/system_wrappers/interface/trace.h"
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000015
16#ifdef WEBRTC_ANDROID
andrew@webrtc.org5f6856f2012-10-30 21:58:00 +000017#include "webrtc/modules/video_capture/include/video_capture_factory.h"
andrew@webrtc.orgb43b6112012-10-31 05:22:11 +000018#include "webrtc/modules/video_render/include/video_render.h"
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000019#endif
20
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000021namespace webrtc {
22
andresp@webrtc.orge1556262013-05-08 19:20:23 +000023enum { kModuleId = 0 };
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000024
25VideoEngine* VideoEngine::Create() {
andresp@webrtc.orgad2b3682013-05-13 10:50:50 +000026 return new VideoEngineImpl(new Config(), true /* owns_config */);
27}
28
29VideoEngine* VideoEngine::Create(const Config& config) {
30 return new VideoEngineImpl(&config, false /* owns_config */);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000031}
32
33bool VideoEngine::Delete(VideoEngine*& video_engine) {
34 if (!video_engine) {
andresp@webrtc.orge1556262013-05-08 19:20:23 +000035 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000036 "VideoEngine::Delete - No argument");
37 return false;
38 }
andresp@webrtc.orge1556262013-05-08 19:20:23 +000039 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000040 "VideoEngine::Delete(vie = 0x%p)", video_engine);
andrew@webrtc.orgd3d364e2013-05-09 02:12:07 +000041 VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000042
43 // Check all reference counters.
44 ViEBaseImpl* vie_base = vie_impl;
45 if (vie_base->GetCount() > 0) {
andresp@webrtc.orge1556262013-05-08 19:20:23 +000046 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000047 "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.orge1556262013-05-08 19:20:23 +000053 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000054 "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.orge1556262013-05-08 19:20:23 +000061 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000062 "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.orge1556262013-05-08 19:20:23 +000069 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000070 "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.orge1556262013-05-08 19:20:23 +000077 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000078 "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.orge1556262013-05-08 19:20:23 +000085 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000086 "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.orge1556262013-05-08 19:20:23 +000093 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000094 "ViEImageProcess ref count: %d",
95 vie_image_process->GetCount());
96 return false;
97 }
98#endif
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000099 ViENetworkImpl* vie_network = vie_impl;
100 if (vie_network->GetCount() > 0) {
andresp@webrtc.orge1556262013-05-08 19:20:23 +0000101 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000102 "ViENetwork ref count: %d", vie_network->GetCount());
103 return false;
104 }
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000105#ifdef WEBRTC_VIDEO_ENGINE_RENDER_API
106 ViERenderImpl* vie_render = vie_impl;
107 if (vie_render->GetCount() > 0) {
andresp@webrtc.orge1556262013-05-08 19:20:23 +0000108 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000109 "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.orge1556262013-05-08 19:20:23 +0000116 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000117 "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.orge1556262013-05-08 19:20:23 +0000126 WEBRTC_TRACE(kTraceInfo, kTraceVideo, kModuleId,
127 "%s: instance deleted.", __FUNCTION__);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000128 return true;
129}
130
131int 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.orge1556262013-05-08 19:20:23 +0000139 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000140 "SetTraceFileName(file_nameUTF8 = %s, add_file_counter = %d",
141 file_nameUTF8, add_file_counter);
142 return 0;
143}
144
145int VideoEngine::SetTraceFilter(const unsigned int filter) {
pbos@webrtc.org2a5d2292013-04-09 13:41:51 +0000146 uint32_t old_filter = 0;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000147 Trace::LevelFilter(old_filter);
148
149 if (filter == kTraceNone && old_filter != kTraceNone) {
150 // Do the logging before turning it off.
andresp@webrtc.orge1556262013-05-08 19:20:23 +0000151 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000152 "SetTraceFilter(filter = 0x%x)", filter);
153 }
154
pbos@webrtc.org2a5d2292013-04-09 13:41:51 +0000155 int32_t error = Trace::SetLevelFilter(filter);
andresp@webrtc.orge1556262013-05-08 19:20:23 +0000156 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000157 "SetTraceFilter(filter = 0x%x)", filter);
158 if (error != 0) {
andresp@webrtc.orge1556262013-05-08 19:20:23 +0000159 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000160 "SetTraceFilter error: %d", error);
161 return -1;
162 }
163 return 0;
164}
165
166int VideoEngine::SetTraceCallback(TraceCallback* callback) {
andresp@webrtc.orge1556262013-05-08 19:20:23 +0000167 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000168 "SetTraceCallback(TraceCallback = 0x%p)", callback);
169 return Trace::SetTraceCallback(callback);
170}
171
172int VideoEngine::SetAndroidObjects(void* javaVM, void* javaContext) {
andresp@webrtc.orge1556262013-05-08 19:20:23 +0000173 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000174 "SetAndroidObjects()");
175
176#if defined(WEBRTC_ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
177 if (SetCaptureAndroidVM(javaVM, javaContext) != 0) {
andresp@webrtc.orge1556262013-05-08 19:20:23 +0000178 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000179 "Could not set capture Android VM");
180 return -1;
181 }
182 if (SetRenderAndroidVM(javaVM) != 0) {
andresp@webrtc.orge1556262013-05-08 19:20:23 +0000183 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000184 "Could not set render Android VM");
185 return -1;
186 }
187 return 0;
188#else
andresp@webrtc.orge1556262013-05-08 19:20:23 +0000189 WEBRTC_TRACE(kTraceError, kTraceVideo, kModuleId,
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000190 "WEBRTC_ANDROID not defined for VideoEngine::SetAndroidObjects");
191 return -1;
192#endif
193}
194
195} // namespace webrtc