niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 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 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 11 | #include "video_engine/vie_image_process_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 13 | #include "system_wrappers/interface/trace.h" |
mflodman@webrtc.org | a4863db | 2011-12-22 08:51:52 +0000 | [diff] [blame^] | 14 | #include "video_engine/include/vie_errors.h" |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 15 | #include "video_engine/vie_capturer.h" |
| 16 | #include "video_engine/vie_channel.h" |
| 17 | #include "video_engine/vie_channel_manager.h" |
| 18 | #include "video_engine/vie_defines.h" |
| 19 | #include "video_engine/vie_encoder.h" |
| 20 | #include "video_engine/vie_impl.h" |
| 21 | #include "video_engine/vie_input_manager.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 23 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 25 | ViEImageProcess* ViEImageProcess::GetInterface(VideoEngine* video_engine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | #ifdef WEBRTC_VIDEO_ENGINE_IMAGE_PROCESS_API |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 27 | if (!video_engine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | return NULL; |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 29 | } |
| 30 | VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine); |
| 31 | ViEImageProcessImpl* vie_image_process_impl = vie_impl; |
| 32 | // Increase ref count. |
| 33 | (*vie_image_process_impl)++; |
| 34 | return vie_image_process_impl; |
| 35 | #else |
| 36 | return NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | #endif |
| 38 | } |
| 39 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 40 | int ViEImageProcessImpl::Release() { |
| 41 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, instance_id_, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | "ViEImageProcess::Release()"); |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 43 | // Decrease ref count. |
| 44 | (*this)--; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 46 | WebRtc_Word32 ref_count = GetCount(); |
| 47 | if (ref_count < 0) { |
| 48 | WEBRTC_TRACE(kTraceWarning, kTraceVideo, instance_id_, |
| 49 | "ViEImageProcess release too many times"); |
| 50 | SetLastError(kViEAPIDoesNotExist); |
| 51 | return -1; |
| 52 | } |
| 53 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, instance_id_, |
| 54 | "ViEImageProcess reference count: %d", ref_count); |
| 55 | return ref_count; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | } |
| 57 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 58 | ViEImageProcessImpl::ViEImageProcessImpl() { |
| 59 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, instance_id_, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | "ViEImageProcessImpl::ViEImageProcessImpl() Ctor"); |
| 61 | } |
| 62 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 63 | ViEImageProcessImpl::~ViEImageProcessImpl() { |
| 64 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, instance_id_, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | "ViEImageProcessImpl::~ViEImageProcessImpl() Dtor"); |
| 66 | } |
| 67 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | int ViEImageProcessImpl::RegisterCaptureEffectFilter( |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 69 | const int capture_id, |
| 70 | ViEEffectFilter& capture_filter) { |
| 71 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), |
| 72 | "%s(capture_id: %d)", __FUNCTION__, capture_id); |
| 73 | if (!Initialized()) { |
| 74 | SetLastError(kViENotInitialized); |
| 75 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), |
| 76 | "%s - ViE instance %d not initialized", __FUNCTION__, |
| 77 | instance_id_); |
| 78 | return -1; |
| 79 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 81 | ViEInputManagerScoped is(input_manager_); |
| 82 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 83 | if (!vie_capture) { |
| 84 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), |
| 85 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 86 | capture_id); |
| 87 | SetLastError(kViEImageProcessInvalidCaptureId); |
| 88 | return -1; |
| 89 | } |
| 90 | if (vie_capture->RegisterEffectFilter(&capture_filter) != 0) { |
| 91 | SetLastError(kViEImageProcessFilterExists); |
| 92 | return -1; |
| 93 | } |
| 94 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | } |
| 96 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 97 | int ViEImageProcessImpl::DeregisterCaptureEffectFilter(const int capture_id) { |
| 98 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), |
| 99 | "%s(capture_id: %d)", __FUNCTION__, capture_id); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 101 | ViEInputManagerScoped is(input_manager_); |
| 102 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 103 | if (!vie_capture) { |
| 104 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), |
| 105 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 106 | capture_id); |
| 107 | SetLastError(kViEImageProcessInvalidCaptureId); |
| 108 | return -1; |
| 109 | } |
| 110 | if (vie_capture->RegisterEffectFilter(NULL) != 0) { |
| 111 | SetLastError(kViEImageProcessFilterDoesNotExist); |
| 112 | return -1; |
| 113 | } |
| 114 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | } |
| 116 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 117 | int ViEImageProcessImpl::RegisterSendEffectFilter( |
| 118 | const int video_channel, |
| 119 | ViEEffectFilter& send_filter) { |
| 120 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), |
| 121 | "%s(video_channel: %d)", __FUNCTION__, video_channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 123 | ViEChannelManagerScoped cs(channel_manager_); |
| 124 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 125 | if (vie_encoder == NULL) { |
| 126 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), |
| 127 | "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); |
| 128 | SetLastError(kViEImageProcessInvalidChannelId); |
| 129 | return -1; |
| 130 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 131 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 132 | if (vie_encoder->RegisterEffectFilter(&send_filter) != 0) { |
| 133 | SetLastError(kViEImageProcessFilterExists); |
| 134 | return -1; |
| 135 | } |
| 136 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 137 | } |
| 138 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 139 | int ViEImageProcessImpl::DeregisterSendEffectFilter(const int video_channel) { |
| 140 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), |
| 141 | "%s(video_channel: %d)", __FUNCTION__, video_channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 143 | ViEChannelManagerScoped cs(channel_manager_); |
| 144 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 145 | if (vie_encoder == NULL) { |
| 146 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), |
| 147 | "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); |
| 148 | SetLastError(kViEImageProcessInvalidChannelId); |
| 149 | return -1; |
| 150 | } |
| 151 | if (vie_encoder->RegisterEffectFilter(NULL) != 0) { |
| 152 | SetLastError(kViEImageProcessFilterDoesNotExist); |
| 153 | return -1; |
| 154 | } |
| 155 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 156 | } |
| 157 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 158 | int ViEImageProcessImpl::RegisterRenderEffectFilter( |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 159 | const int video_channel, |
| 160 | ViEEffectFilter& render_filter) { |
| 161 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), |
| 162 | "%s(video_channel: %d)", __FUNCTION__, video_channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 163 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 164 | ViEChannelManagerScoped cs(channel_manager_); |
| 165 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 166 | if (!vie_channel) { |
| 167 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), |
| 168 | "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); |
| 169 | SetLastError(kViEImageProcessInvalidChannelId); |
| 170 | return -1; |
| 171 | } |
| 172 | if (vie_channel->RegisterEffectFilter(&render_filter) != 0) { |
| 173 | SetLastError(kViEImageProcessFilterExists); |
| 174 | return -1; |
| 175 | } |
| 176 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 177 | } |
| 178 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 179 | int ViEImageProcessImpl::DeregisterRenderEffectFilter(const int video_channel) { |
| 180 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), |
| 181 | "%s(video_channel: %d)", __FUNCTION__, video_channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 182 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 183 | ViEChannelManagerScoped cs(channel_manager_); |
| 184 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 185 | if (!vie_channel) { |
| 186 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), |
| 187 | "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); |
| 188 | SetLastError(kViEImageProcessInvalidChannelId); |
| 189 | return -1; |
| 190 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 191 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 192 | if (vie_channel->RegisterEffectFilter(NULL) != 0) { |
| 193 | SetLastError(kViEImageProcessFilterDoesNotExist); |
| 194 | return -1; |
| 195 | } |
| 196 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 197 | } |
| 198 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 199 | int ViEImageProcessImpl::EnableDeflickering(const int capture_id, |
| 200 | const bool enable) { |
| 201 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), |
| 202 | "%s(capture_id: %d, enable: %d)", __FUNCTION__, capture_id, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 203 | enable); |
| 204 | |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 205 | ViEInputManagerScoped is(input_manager_); |
| 206 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 207 | if (!vie_capture) { |
| 208 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), |
| 209 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 210 | capture_id); |
| 211 | SetLastError(kViEImageProcessInvalidChannelId); |
| 212 | return -1; |
| 213 | } |
| 214 | |
| 215 | if (vie_capture->EnableDeflickering(enable) != 0) { |
| 216 | if (enable) { |
| 217 | SetLastError(kViEImageProcessAlreadyEnabled); |
| 218 | } else { |
| 219 | SetLastError(kViEImageProcessAlreadyDisabled); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 220 | } |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 221 | return -1; |
| 222 | } |
| 223 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 224 | } |
mflodman@webrtc.org | 1bdf1df | 2011-12-20 11:57:47 +0000 | [diff] [blame] | 225 | |
| 226 | int ViEImageProcessImpl::EnableDenoising(const int capture_id, |
| 227 | const bool enable) { |
| 228 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), |
| 229 | "%s(capture_id: %d, enable: %d)", __FUNCTION__, capture_id, |
| 230 | enable); |
| 231 | |
| 232 | ViEInputManagerScoped is(input_manager_); |
| 233 | ViECapturer* vie_capture = is.Capture(capture_id); |
| 234 | if (!vie_capture) { |
| 235 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), |
| 236 | "%s: Capture device %d doesn't exist", __FUNCTION__, |
| 237 | capture_id); |
| 238 | SetLastError(kViEImageProcessInvalidCaptureId); |
| 239 | return -1; |
| 240 | } |
| 241 | |
| 242 | if (vie_capture->EnableDenoising(enable) != 0) { |
| 243 | if (enable) { |
| 244 | SetLastError(kViEImageProcessAlreadyEnabled); |
| 245 | } else { |
| 246 | SetLastError(kViEImageProcessAlreadyDisabled); |
| 247 | } |
| 248 | return -1; |
| 249 | } |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | int ViEImageProcessImpl::EnableColorEnhancement(const int video_channel, |
| 254 | const bool enable) { |
| 255 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_), |
| 256 | "%s(video_channel: %d, enable: %d)", __FUNCTION__, video_channel, |
| 257 | enable); |
| 258 | |
| 259 | ViEChannelManagerScoped cs(channel_manager_); |
| 260 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 261 | if (!vie_channel) { |
| 262 | WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_), |
| 263 | "%s: Channel %d doesn't exist", __FUNCTION__, video_channel); |
| 264 | SetLastError(kViEImageProcessInvalidChannelId); |
| 265 | return -1; |
| 266 | } |
| 267 | if (vie_channel->EnableColorEnhancement(enable) != 0) { |
| 268 | if (enable) { |
| 269 | SetLastError(kViEImageProcessAlreadyEnabled); |
| 270 | } else { |
| 271 | SetLastError(kViEImageProcessAlreadyDisabled); |
| 272 | } |
| 273 | return -1; |
| 274 | } |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | } // namespace webrtc |