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