blob: e4c146d596e0e85c664c1c31477f71db2d485e7b [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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.org1bdf1df2011-12-20 11:57:47 +000011#include "video_engine/vie_image_process_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000013#include "system_wrappers/interface/trace.h"
mflodman@webrtc.orga4863db2011-12-22 08:51:52 +000014#include "video_engine/include/vie_errors.h"
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000015#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.com470e71d2011-07-07 08:21:25 +000022
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000023namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000024
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000025ViEImageProcess* ViEImageProcess::GetInterface(VideoEngine* video_engine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000026#ifdef WEBRTC_VIDEO_ENGINE_IMAGE_PROCESS_API
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000027 if (!video_engine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000028 return NULL;
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000029 }
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.com470e71d2011-07-07 08:21:25 +000037#endif
38}
39
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000040int ViEImageProcessImpl::Release() {
41 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, instance_id_,
niklase@google.com470e71d2011-07-07 08:21:25 +000042 "ViEImageProcess::Release()");
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000043 // Decrease ref count.
44 (*this)--;
niklase@google.com470e71d2011-07-07 08:21:25 +000045
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000046 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.com470e71d2011-07-07 08:21:25 +000056}
57
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000058ViEImageProcessImpl::ViEImageProcessImpl() {
59 WEBRTC_TRACE(kTraceMemory, kTraceVideo, instance_id_,
niklase@google.com470e71d2011-07-07 08:21:25 +000060 "ViEImageProcessImpl::ViEImageProcessImpl() Ctor");
61}
62
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000063ViEImageProcessImpl::~ViEImageProcessImpl() {
64 WEBRTC_TRACE(kTraceMemory, kTraceVideo, instance_id_,
niklase@google.com470e71d2011-07-07 08:21:25 +000065 "ViEImageProcessImpl::~ViEImageProcessImpl() Dtor");
66}
67
niklase@google.com470e71d2011-07-07 08:21:25 +000068int ViEImageProcessImpl::RegisterCaptureEffectFilter(
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000069 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.com470e71d2011-07-07 08:21:25 +000080
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000081 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.com470e71d2011-07-07 08:21:25 +000095}
96
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000097int ViEImageProcessImpl::DeregisterCaptureEffectFilter(const int capture_id) {
98 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_),
99 "%s(capture_id: %d)", __FUNCTION__, capture_id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000101 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.com470e71d2011-07-07 08:21:25 +0000115}
116
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000117int 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.com470e71d2011-07-07 08:21:25 +0000122
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000123 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.com470e71d2011-07-07 08:21:25 +0000131
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000132 if (vie_encoder->RegisterEffectFilter(&send_filter) != 0) {
133 SetLastError(kViEImageProcessFilterExists);
134 return -1;
135 }
136 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000137}
138
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000139int ViEImageProcessImpl::DeregisterSendEffectFilter(const int video_channel) {
140 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_),
141 "%s(video_channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000143 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.com470e71d2011-07-07 08:21:25 +0000156}
157
niklase@google.com470e71d2011-07-07 08:21:25 +0000158int ViEImageProcessImpl::RegisterRenderEffectFilter(
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000159 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.com470e71d2011-07-07 08:21:25 +0000163
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000164 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.com470e71d2011-07-07 08:21:25 +0000177}
178
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000179int ViEImageProcessImpl::DeregisterRenderEffectFilter(const int video_channel) {
180 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_),
181 "%s(video_channel: %d)", __FUNCTION__, video_channel);
niklase@google.com470e71d2011-07-07 08:21:25 +0000182
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000183 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.com470e71d2011-07-07 08:21:25 +0000191
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000192 if (vie_channel->RegisterEffectFilter(NULL) != 0) {
193 SetLastError(kViEImageProcessFilterDoesNotExist);
194 return -1;
195 }
196 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000197}
198
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000199int 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.com470e71d2011-07-07 08:21:25 +0000203 enable);
204
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000205 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.com470e71d2011-07-07 08:21:25 +0000220 }
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000221 return -1;
222 }
223 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000224}
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000225
226int 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
253int 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