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 11 #include "webrtc/video_engine/vie_impl.h" 12 13 #include "webrtc/common.h" 14 #include "webrtc/system_wrappers/interface/logging.h" 15 #include "webrtc/system_wrappers/interface/trace.h" 16 17 #ifdef WEBRTC_ANDROID 18 #include "webrtc/modules/video_capture/include/video_capture_factory.h" 19 #include "webrtc/modules/video_render/include/video_render.h" 20 #endif 21 22 namespace webrtc { 23 24 enum { kModuleId = 0 }; 25 26 VideoEngine* VideoEngine::Create() { 27 return new VideoEngineImpl(new Config(), true /* owns_config */); 28 } 29 30 VideoEngine* VideoEngine::Create(const Config& config) { 31 return new VideoEngineImpl(&config, false /* owns_config */); 32 } 33 34 bool VideoEngine::Delete(VideoEngine*& video_engine) { 35 if (!video_engine) 36 return false; 37 38 LOG_F(LS_INFO); 39 VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine); 40 41 // Check all reference counters. 42 ViEBaseImpl* vie_base = vie_impl; 43 if (vie_base->GetCount() > 0) { 44 LOG(LS_ERROR) << "ViEBase ref count > 0: " << vie_base->GetCount(); 45 return false; 46 } 47 #ifdef WEBRTC_VIDEO_ENGINE_CAPTURE_API 48 ViECaptureImpl* vie_capture = vie_impl; 49 if (vie_capture->GetCount() > 0) { 50 LOG(LS_ERROR) << "ViECapture ref count > 0: " << vie_capture->GetCount(); 51 return false; 52 } 53 #endif 54 #ifdef WEBRTC_VIDEO_ENGINE_CODEC_API 55 ViECodecImpl* vie_codec = vie_impl; 56 if (vie_codec->GetCount() > 0) { 57 LOG(LS_ERROR) << "ViECodec ref count > 0: " << vie_codec->GetCount(); 58 return false; 59 } 60 #endif 61 #ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API 62 ViEExternalCodecImpl* vie_external_codec = vie_impl; 63 if (vie_external_codec->GetCount() > 0) { 64 LOG(LS_ERROR) << "ViEExternalCodec ref count > 0: " 65 << vie_external_codec->GetCount(); 66 return false; 67 } 68 #endif 69 #ifdef WEBRTC_VIDEO_ENGINE_FILE_API 70 ViEFileImpl* vie_file = vie_impl; 71 if (vie_file->GetCount() > 0) { 72 LOG(LS_ERROR) << "ViEFile ref count > 0: " << vie_file->GetCount(); 73 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) { 79 LOG(LS_ERROR) << "ViEImageProcess ref count > 0: " 80 << vie_image_process->GetCount(); 81 return false; 82 } 83 #endif 84 ViENetworkImpl* vie_network = vie_impl; 85 if (vie_network->GetCount() > 0) { 86 LOG(LS_ERROR) << "ViENetwork ref count > 0: " << vie_network->GetCount(); 87 return false; 88 } 89 #ifdef WEBRTC_VIDEO_ENGINE_RENDER_API 90 ViERenderImpl* vie_render = vie_impl; 91 if (vie_render->GetCount() > 0) { 92 LOG(LS_ERROR) << "ViERender ref count > 0: " << vie_render->GetCount(); 93 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) { 99 LOG(LS_ERROR) << "ViERTP_RTCP ref count > 0: " << vie_rtp_rtcp->GetCount(); 100 return false; 101 } 102 #endif 103 104 delete vie_impl; 105 vie_impl = NULL; 106 video_engine = NULL; 107 108 return true; 109 } 110 111 int 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 } 119 LOG_F(LS_INFO) << "filename: " << file_nameUTF8 120 << " add_file_counter: " << (add_file_counter ? "yes" : "no"); 121 return 0; 122 } 123 124 int VideoEngine::SetTraceFilter(const unsigned int filter) { 125 uint32_t old_filter = Trace::level_filter(); 126 127 if (filter == kTraceNone && old_filter != kTraceNone) { 128 // Do the logging before turning it off. 129 LOG_F(LS_INFO) << "filter: " << filter; 130 } 131 132 Trace::set_level_filter(filter); 133 LOG_F(LS_INFO) << "filter: " << filter; 134 return 0; 135 } 136 137 int VideoEngine::SetTraceCallback(TraceCallback* callback) { 138 LOG_F(LS_INFO); 139 return Trace::SetTraceCallback(callback); 140 } 141 142 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 143 int VideoEngine::SetAndroidObjects(JavaVM* javaVM, jobject context) { 144 LOG_F(LS_INFO); 145 146 if (SetCaptureAndroidVM(javaVM, context) != 0) { 147 LOG(LS_ERROR) << "Could not set capture Android VM"; 148 return -1; 149 } 150 if (SetRenderAndroidVM(javaVM) != 0) { 151 LOG(LS_ERROR) << "Could not set render Android VM"; 152 return -1; 153 } 154 return 0; 155 } 156 #endif 157 158 } // namespace webrtc 159