blob: 3cdf5da2f1dc3a97e23845b6f9c1aff98c8f664b [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-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.orgac6d9192013-05-13 10:50:50 +000011#include "webrtc/video_engine/vie_impl.h"
12
13#include "webrtc/common.h"
pbos@webrtc.org3468f202014-05-14 08:02:22 +000014#include "webrtc/system_wrappers/interface/logging.h"
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +000015#include "webrtc/system_wrappers/interface/trace.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000016
17#ifdef WEBRTC_ANDROID
andrew@webrtc.org5e8ee6f2012-10-30 21:58:00 +000018#include "webrtc/modules/video_capture/include/video_capture_factory.h"
andrew@webrtc.org07e96da2012-10-31 05:22:11 +000019#include "webrtc/modules/video_render/include/video_render.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000020#endif
21
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000022namespace webrtc {
23
andresp@webrtc.org90f05ed2013-05-08 19:20:23 +000024enum { kModuleId = 0 };
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000025
26VideoEngine* VideoEngine::Create() {
andresp@webrtc.orgac6d9192013-05-13 10:50:50 +000027 return new VideoEngineImpl(new Config(), true /* owns_config */);
28}
29
30VideoEngine* VideoEngine::Create(const Config& config) {
31 return new VideoEngineImpl(&config, false /* owns_config */);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000032}
33
34bool VideoEngine::Delete(VideoEngine*& video_engine) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +000035 if (!video_engine)
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000036 return false;
pbos@webrtc.org3468f202014-05-14 08:02:22 +000037
38 LOG_F(LS_INFO);
andrew@webrtc.org7ab72682013-05-09 02:12:07 +000039 VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000040
41 // Check all reference counters.
42 ViEBaseImpl* vie_base = vie_impl;
43 if (vie_base->GetCount() > 0) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +000044 LOG(LS_ERROR) << "ViEBase ref count > 0: " << vie_base->GetCount();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000045 return false;
46 }
47#ifdef WEBRTC_VIDEO_ENGINE_CAPTURE_API
48 ViECaptureImpl* vie_capture = vie_impl;
49 if (vie_capture->GetCount() > 0) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +000050 LOG(LS_ERROR) << "ViECapture ref count > 0: " << vie_capture->GetCount();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000051 return false;
52 }
53#endif
54#ifdef WEBRTC_VIDEO_ENGINE_CODEC_API
55 ViECodecImpl* vie_codec = vie_impl;
56 if (vie_codec->GetCount() > 0) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +000057 LOG(LS_ERROR) << "ViECodec ref count > 0: " << vie_codec->GetCount();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000058 return false;
59 }
60#endif
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000061#ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API
62 ViEExternalCodecImpl* vie_external_codec = vie_impl;
63 if (vie_external_codec->GetCount() > 0) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +000064 LOG(LS_ERROR) << "ViEExternalCodec ref count > 0: "
65 << vie_external_codec->GetCount();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000066 return false;
67 }
68#endif
69#ifdef WEBRTC_VIDEO_ENGINE_FILE_API
70 ViEFileImpl* vie_file = vie_impl;
71 if (vie_file->GetCount() > 0) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +000072 LOG(LS_ERROR) << "ViEFile ref count > 0: " << vie_file->GetCount();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000073 return false;
74 }
75#endif
76#ifdef WEBRTC_VIDEO_ENGINE_IMAGE_PROCESS_API
77 ViEImageProcessImpl* vie_image_process = vie_impl;
78 if (vie_image_process->GetCount() > 0) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +000079 LOG(LS_ERROR) << "ViEImageProcess ref count > 0: "
80 << vie_image_process->GetCount();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000081 return false;
82 }
83#endif
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000084 ViENetworkImpl* vie_network = vie_impl;
85 if (vie_network->GetCount() > 0) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +000086 LOG(LS_ERROR) << "ViENetwork ref count > 0: " << vie_network->GetCount();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000087 return false;
88 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000089#ifdef WEBRTC_VIDEO_ENGINE_RENDER_API
90 ViERenderImpl* vie_render = vie_impl;
91 if (vie_render->GetCount() > 0) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +000092 LOG(LS_ERROR) << "ViERender ref count > 0: " << vie_render->GetCount();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000093 return false;
94 }
95#endif
96#ifdef WEBRTC_VIDEO_ENGINE_RTP_RTCP_API
97 ViERTP_RTCPImpl* vie_rtp_rtcp = vie_impl;
98 if (vie_rtp_rtcp->GetCount() > 0) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +000099 LOG(LS_ERROR) << "ViERTP_RTCP ref count > 0: " << vie_rtp_rtcp->GetCount();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000100 return false;
101 }
102#endif
103
104 delete vie_impl;
105 vie_impl = NULL;
106 video_engine = NULL;
107
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000108 return true;
109}
110
111int VideoEngine::SetTraceFile(const char* file_nameUTF8,
112 const bool add_file_counter) {
113 if (!file_nameUTF8) {
114 return -1;
115 }
116 if (Trace::SetTraceFile(file_nameUTF8, add_file_counter) == -1) {
117 return -1;
118 }
pbos@webrtc.org3468f202014-05-14 08:02:22 +0000119 LOG_F(LS_INFO) << "filename: " << file_nameUTF8
120 << " add_file_counter: " << (add_file_counter ? "yes" : "no");
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000121 return 0;
122}
123
124int VideoEngine::SetTraceFilter(const unsigned int filter) {
andrew@webrtc.org06eaa542013-09-05 16:40:43 +0000125 uint32_t old_filter = Trace::level_filter();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000126
127 if (filter == kTraceNone && old_filter != kTraceNone) {
128 // Do the logging before turning it off.
pbos@webrtc.org3468f202014-05-14 08:02:22 +0000129 LOG_F(LS_INFO) << "filter: " << filter;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000130 }
131
andrew@webrtc.org06eaa542013-09-05 16:40:43 +0000132 Trace::set_level_filter(filter);
pbos@webrtc.org3468f202014-05-14 08:02:22 +0000133 LOG_F(LS_INFO) << "filter: " << filter;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000134 return 0;
135}
136
137int VideoEngine::SetTraceCallback(TraceCallback* callback) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +0000138 LOG_F(LS_INFO);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000139 return Trace::SetTraceCallback(callback);
140}
141
fischman@webrtc.org81cd5ca2013-10-03 18:23:13 +0000142#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
fischman@webrtc.org5101f842014-06-06 18:40:44 +0000143int VideoEngine::SetAndroidObjects(JavaVM* javaVM, jobject context) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +0000144 LOG_F(LS_INFO);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000145
fischman@webrtc.org5101f842014-06-06 18:40:44 +0000146 if (SetCaptureAndroidVM(javaVM, context) != 0) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +0000147 LOG(LS_ERROR) << "Could not set capture Android VM";
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000148 return -1;
149 }
150 if (SetRenderAndroidVM(javaVM) != 0) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +0000151 LOG(LS_ERROR) << "Could not set render Android VM";
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000152 return -1;
153 }
154 return 0;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000155}
fischman@webrtc.org81cd5ca2013-10-03 18:23:13 +0000156#endif
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000157
158} // namespace webrtc