blob: 79f033b4e15c2df6291470d9f93104955cabafa8 [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"
pbos@webrtc.org04a721c2014-05-14 08:02:22 +000014#include "webrtc/system_wrappers/interface/logging.h"
andresp@webrtc.orgad2b3682013-05-13 10:50:50 +000015#include "webrtc/system_wrappers/interface/trace.h"
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000016
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000017namespace webrtc {
18
andresp@webrtc.orge1556262013-05-08 19:20:23 +000019enum { kModuleId = 0 };
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000020
21VideoEngine* VideoEngine::Create() {
andresp@webrtc.orgad2b3682013-05-13 10:50:50 +000022 return new VideoEngineImpl(new Config(), true /* owns_config */);
23}
24
25VideoEngine* VideoEngine::Create(const Config& config) {
26 return new VideoEngineImpl(&config, false /* owns_config */);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000027}
28
29bool VideoEngine::Delete(VideoEngine*& video_engine) {
pbos@webrtc.org04a721c2014-05-14 08:02:22 +000030 if (!video_engine)
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000031 return false;
pbos@webrtc.org04a721c2014-05-14 08:02:22 +000032
33 LOG_F(LS_INFO);
andrew@webrtc.orgd3d364e2013-05-09 02:12:07 +000034 VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000035
36 // Check all reference counters.
37 ViEBaseImpl* vie_base = vie_impl;
38 if (vie_base->GetCount() > 0) {
pbos@webrtc.org04a721c2014-05-14 08:02:22 +000039 LOG(LS_ERROR) << "ViEBase ref count > 0: " << vie_base->GetCount();
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000040 return false;
41 }
42#ifdef WEBRTC_VIDEO_ENGINE_CAPTURE_API
43 ViECaptureImpl* vie_capture = vie_impl;
44 if (vie_capture->GetCount() > 0) {
pbos@webrtc.org04a721c2014-05-14 08:02:22 +000045 LOG(LS_ERROR) << "ViECapture ref count > 0: " << vie_capture->GetCount();
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000046 return false;
47 }
48#endif
49#ifdef WEBRTC_VIDEO_ENGINE_CODEC_API
50 ViECodecImpl* vie_codec = vie_impl;
51 if (vie_codec->GetCount() > 0) {
pbos@webrtc.org04a721c2014-05-14 08:02:22 +000052 LOG(LS_ERROR) << "ViECodec ref count > 0: " << vie_codec->GetCount();
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000053 return false;
54 }
55#endif
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000056#ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API
57 ViEExternalCodecImpl* vie_external_codec = vie_impl;
58 if (vie_external_codec->GetCount() > 0) {
pbos@webrtc.org04a721c2014-05-14 08:02:22 +000059 LOG(LS_ERROR) << "ViEExternalCodec ref count > 0: "
60 << vie_external_codec->GetCount();
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000061 return false;
62 }
63#endif
64#ifdef WEBRTC_VIDEO_ENGINE_FILE_API
65 ViEFileImpl* vie_file = vie_impl;
66 if (vie_file->GetCount() > 0) {
pbos@webrtc.org04a721c2014-05-14 08:02:22 +000067 LOG(LS_ERROR) << "ViEFile ref count > 0: " << vie_file->GetCount();
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000068 return false;
69 }
70#endif
71#ifdef WEBRTC_VIDEO_ENGINE_IMAGE_PROCESS_API
72 ViEImageProcessImpl* vie_image_process = vie_impl;
73 if (vie_image_process->GetCount() > 0) {
pbos@webrtc.org04a721c2014-05-14 08:02:22 +000074 LOG(LS_ERROR) << "ViEImageProcess ref count > 0: "
75 << vie_image_process->GetCount();
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000076 return false;
77 }
78#endif
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000079 ViENetworkImpl* vie_network = vie_impl;
80 if (vie_network->GetCount() > 0) {
pbos@webrtc.org04a721c2014-05-14 08:02:22 +000081 LOG(LS_ERROR) << "ViENetwork ref count > 0: " << vie_network->GetCount();
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000082 return false;
83 }
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000084#ifdef WEBRTC_VIDEO_ENGINE_RENDER_API
85 ViERenderImpl* vie_render = vie_impl;
86 if (vie_render->GetCount() > 0) {
pbos@webrtc.org04a721c2014-05-14 08:02:22 +000087 LOG(LS_ERROR) << "ViERender ref count > 0: " << vie_render->GetCount();
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000088 return false;
89 }
90#endif
91#ifdef WEBRTC_VIDEO_ENGINE_RTP_RTCP_API
92 ViERTP_RTCPImpl* vie_rtp_rtcp = vie_impl;
93 if (vie_rtp_rtcp->GetCount() > 0) {
pbos@webrtc.org04a721c2014-05-14 08:02:22 +000094 LOG(LS_ERROR) << "ViERTP_RTCP ref count > 0: " << vie_rtp_rtcp->GetCount();
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +000095 return false;
96 }
97#endif
98
99 delete vie_impl;
100 vie_impl = NULL;
101 video_engine = NULL;
102
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000103 return true;
104}
105
106int VideoEngine::SetTraceFile(const char* file_nameUTF8,
107 const bool add_file_counter) {
108 if (!file_nameUTF8) {
109 return -1;
110 }
111 if (Trace::SetTraceFile(file_nameUTF8, add_file_counter) == -1) {
112 return -1;
113 }
pbos@webrtc.org04a721c2014-05-14 08:02:22 +0000114 LOG_F(LS_INFO) << "filename: " << file_nameUTF8
115 << " add_file_counter: " << (add_file_counter ? "yes" : "no");
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000116 return 0;
117}
118
119int VideoEngine::SetTraceFilter(const unsigned int filter) {
andrew@webrtc.org744235e2013-09-05 16:40:43 +0000120 uint32_t old_filter = Trace::level_filter();
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000121
122 if (filter == kTraceNone && old_filter != kTraceNone) {
123 // Do the logging before turning it off.
pbos@webrtc.org04a721c2014-05-14 08:02:22 +0000124 LOG_F(LS_INFO) << "filter: " << filter;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000125 }
126
andrew@webrtc.org744235e2013-09-05 16:40:43 +0000127 Trace::set_level_filter(filter);
pbos@webrtc.org04a721c2014-05-14 08:02:22 +0000128 LOG_F(LS_INFO) << "filter: " << filter;
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000129 return 0;
130}
131
132int VideoEngine::SetTraceCallback(TraceCallback* callback) {
pbos@webrtc.org04a721c2014-05-14 08:02:22 +0000133 LOG_F(LS_INFO);
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000134 return Trace::SetTraceCallback(callback);
135}
136
andrew@webrtc.orga7b57da2012-10-22 18:19:23 +0000137} // namespace webrtc