andrew@webrtc.org | b015cbe | 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 | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 11 | #include "webrtc/video_engine/vie_impl.h" |
| 12 | |
| 13 | #include "webrtc/common.h" |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 14 | #include "webrtc/system_wrappers/interface/logging.h" |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 15 | #include "webrtc/system_wrappers/interface/trace.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 16 | |
| 17 | #ifdef WEBRTC_ANDROID |
andrew@webrtc.org | 5e8ee6f | 2012-10-30 21:58:00 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/video_capture/include/video_capture_factory.h" |
andrew@webrtc.org | 07e96da | 2012-10-31 05:22:11 +0000 | [diff] [blame] | 19 | #include "webrtc/modules/video_render/include/video_render.h" |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 20 | #endif |
| 21 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 22 | namespace webrtc { |
| 23 | |
andresp@webrtc.org | 90f05ed | 2013-05-08 19:20:23 +0000 | [diff] [blame] | 24 | enum { kModuleId = 0 }; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 25 | |
| 26 | VideoEngine* VideoEngine::Create() { |
andresp@webrtc.org | ac6d919 | 2013-05-13 10:50:50 +0000 | [diff] [blame] | 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 */); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | bool VideoEngine::Delete(VideoEngine*& video_engine) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 35 | if (!video_engine) |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 36 | return false; |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 37 | |
| 38 | LOG_F(LS_INFO); |
andrew@webrtc.org | 7ab7268 | 2013-05-09 02:12:07 +0000 | [diff] [blame] | 39 | VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 40 | |
| 41 | // Check all reference counters. |
| 42 | ViEBaseImpl* vie_base = vie_impl; |
| 43 | if (vie_base->GetCount() > 0) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 44 | LOG(LS_ERROR) << "ViEBase ref count > 0: " << vie_base->GetCount(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 45 | return false; |
| 46 | } |
| 47 | #ifdef WEBRTC_VIDEO_ENGINE_CAPTURE_API |
| 48 | ViECaptureImpl* vie_capture = vie_impl; |
| 49 | if (vie_capture->GetCount() > 0) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 50 | LOG(LS_ERROR) << "ViECapture ref count > 0: " << vie_capture->GetCount(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 57 | LOG(LS_ERROR) << "ViECodec ref count > 0: " << vie_codec->GetCount(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 58 | return false; |
| 59 | } |
| 60 | #endif |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 61 | #ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API |
| 62 | ViEExternalCodecImpl* vie_external_codec = vie_impl; |
| 63 | if (vie_external_codec->GetCount() > 0) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 64 | LOG(LS_ERROR) << "ViEExternalCodec ref count > 0: " |
| 65 | << vie_external_codec->GetCount(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 72 | LOG(LS_ERROR) << "ViEFile ref count > 0: " << vie_file->GetCount(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 79 | LOG(LS_ERROR) << "ViEImageProcess ref count > 0: " |
| 80 | << vie_image_process->GetCount(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 81 | return false; |
| 82 | } |
| 83 | #endif |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 84 | ViENetworkImpl* vie_network = vie_impl; |
| 85 | if (vie_network->GetCount() > 0) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 86 | LOG(LS_ERROR) << "ViENetwork ref count > 0: " << vie_network->GetCount(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 87 | return false; |
| 88 | } |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 89 | #ifdef WEBRTC_VIDEO_ENGINE_RENDER_API |
| 90 | ViERenderImpl* vie_render = vie_impl; |
| 91 | if (vie_render->GetCount() > 0) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 92 | LOG(LS_ERROR) << "ViERender ref count > 0: " << vie_render->GetCount(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 99 | LOG(LS_ERROR) << "ViERTP_RTCP ref count > 0: " << vie_rtp_rtcp->GetCount(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | #endif |
| 103 | |
| 104 | delete vie_impl; |
| 105 | vie_impl = NULL; |
| 106 | video_engine = NULL; |
| 107 | |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 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 | } |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 119 | LOG_F(LS_INFO) << "filename: " << file_nameUTF8 |
| 120 | << " add_file_counter: " << (add_file_counter ? "yes" : "no"); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | int VideoEngine::SetTraceFilter(const unsigned int filter) { |
andrew@webrtc.org | 06eaa54 | 2013-09-05 16:40:43 +0000 | [diff] [blame] | 125 | uint32_t old_filter = Trace::level_filter(); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 126 | |
| 127 | if (filter == kTraceNone && old_filter != kTraceNone) { |
| 128 | // Do the logging before turning it off. |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 129 | LOG_F(LS_INFO) << "filter: " << filter; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 130 | } |
| 131 | |
andrew@webrtc.org | 06eaa54 | 2013-09-05 16:40:43 +0000 | [diff] [blame] | 132 | Trace::set_level_filter(filter); |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 133 | LOG_F(LS_INFO) << "filter: " << filter; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | int VideoEngine::SetTraceCallback(TraceCallback* callback) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 138 | LOG_F(LS_INFO); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 139 | return Trace::SetTraceCallback(callback); |
| 140 | } |
| 141 | |
fischman@webrtc.org | 81cd5ca | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 142 | #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) |
fischman@webrtc.org | 5101f84 | 2014-06-06 18:40:44 +0000 | [diff] [blame] | 143 | int VideoEngine::SetAndroidObjects(JavaVM* javaVM, jobject context) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 144 | LOG_F(LS_INFO); |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 145 | |
fischman@webrtc.org | 5101f84 | 2014-06-06 18:40:44 +0000 | [diff] [blame] | 146 | if (SetCaptureAndroidVM(javaVM, context) != 0) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 147 | LOG(LS_ERROR) << "Could not set capture Android VM"; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 148 | return -1; |
| 149 | } |
| 150 | if (SetRenderAndroidVM(javaVM) != 0) { |
pbos@webrtc.org | 3468f20 | 2014-05-14 08:02:22 +0000 | [diff] [blame] | 151 | LOG(LS_ERROR) << "Could not set render Android VM"; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 152 | return -1; |
| 153 | } |
| 154 | return 0; |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 155 | } |
fischman@webrtc.org | 81cd5ca | 2013-10-03 18:23:13 +0000 | [diff] [blame] | 156 | #endif |
andrew@webrtc.org | b015cbe | 2012-10-22 18:19:23 +0000 | [diff] [blame] | 157 | |
| 158 | } // namespace webrtc |