blob: d089c0490d80bfdb9bbc64d6beaef5423401e200 [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
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000011#include "webrtc/video_engine/vie_image_process_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +000013#include "webrtc/system_wrappers/interface/logging.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000014#include "webrtc/video_engine/include/vie_errors.h"
15#include "webrtc/video_engine/vie_capturer.h"
16#include "webrtc/video_engine/vie_channel.h"
17#include "webrtc/video_engine/vie_channel_manager.h"
18#include "webrtc/video_engine/vie_defines.h"
19#include "webrtc/video_engine/vie_encoder.h"
20#include "webrtc/video_engine/vie_impl.h"
21#include "webrtc/video_engine/vie_input_manager.h"
22#include "webrtc/video_engine/vie_shared_data.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000024namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000025
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000026ViEImageProcess* ViEImageProcess::GetInterface(VideoEngine* video_engine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000027#ifdef WEBRTC_VIDEO_ENGINE_IMAGE_PROCESS_API
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000028 if (!video_engine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000029 return NULL;
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000030 }
andrew@webrtc.orgd72262d2013-05-09 02:12:07 +000031 VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000032 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;
niklase@google.com470e71d2011-07-07 08:21:25 +000038#endif
39}
40
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000041int ViEImageProcessImpl::Release() {
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000042 // Decrease ref count.
43 (*this)--;
niklase@google.com470e71d2011-07-07 08:21:25 +000044
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000045 int32_t ref_count = GetCount();
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000046 if (ref_count < 0) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +000047 LOG(LS_ERROR) << "ViEImageProcess release too many times";
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000048 shared_data_->SetLastError(kViEAPIDoesNotExist);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000049 return -1;
50 }
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000051 return ref_count;
niklase@google.com470e71d2011-07-07 08:21:25 +000052}
53
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000054ViEImageProcessImpl::ViEImageProcessImpl(ViESharedData* shared_data)
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +000055 : shared_data_(shared_data) {}
niklase@google.com470e71d2011-07-07 08:21:25 +000056
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +000057ViEImageProcessImpl::~ViEImageProcessImpl() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000058
niklase@google.com470e71d2011-07-07 08:21:25 +000059int ViEImageProcessImpl::RegisterCaptureEffectFilter(
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000060 const int capture_id,
61 ViEEffectFilter& capture_filter) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +000062 LOG_F(LS_INFO) << "capture_id: " << capture_id;
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000063 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000064 ViECapturer* vie_capture = is.Capture(capture_id);
65 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000066 shared_data_->SetLastError(kViEImageProcessInvalidCaptureId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000067 return -1;
68 }
69 if (vie_capture->RegisterEffectFilter(&capture_filter) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000070 shared_data_->SetLastError(kViEImageProcessFilterExists);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000071 return -1;
72 }
73 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000074}
75
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000076int ViEImageProcessImpl::DeregisterCaptureEffectFilter(const int capture_id) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +000077 LOG_F(LS_INFO) << "capture_id: " << capture_id;
niklase@google.com470e71d2011-07-07 08:21:25 +000078
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000079 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000080 ViECapturer* vie_capture = is.Capture(capture_id);
81 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000082 shared_data_->SetLastError(kViEImageProcessInvalidCaptureId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000083 return -1;
84 }
85 if (vie_capture->RegisterEffectFilter(NULL) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000086 shared_data_->SetLastError(kViEImageProcessFilterDoesNotExist);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000087 return -1;
88 }
89 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000090}
91
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000092int ViEImageProcessImpl::RegisterSendEffectFilter(
93 const int video_channel,
94 ViEEffectFilter& send_filter) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +000095 LOG_F(LS_INFO) << "video_channel: " << video_channel;
niklase@google.com470e71d2011-07-07 08:21:25 +000096
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +000097 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +000098 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
99 if (vie_encoder == NULL) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000100 shared_data_->SetLastError(kViEImageProcessInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000101 return -1;
102 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000104 if (vie_encoder->RegisterEffectFilter(&send_filter) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000105 shared_data_->SetLastError(kViEImageProcessFilterExists);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000106 return -1;
107 }
108 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109}
110
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000111int ViEImageProcessImpl::DeregisterSendEffectFilter(const int video_channel) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000112 LOG_F(LS_INFO) << "video_channel: " << video_channel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000114 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000115 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
116 if (vie_encoder == NULL) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000117 shared_data_->SetLastError(kViEImageProcessInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000118 return -1;
119 }
120 if (vie_encoder->RegisterEffectFilter(NULL) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000121 shared_data_->SetLastError(kViEImageProcessFilterDoesNotExist);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000122 return -1;
123 }
124 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000125}
126
niklase@google.com470e71d2011-07-07 08:21:25 +0000127int ViEImageProcessImpl::RegisterRenderEffectFilter(
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000128 const int video_channel,
129 ViEEffectFilter& render_filter) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000130 LOG_F(LS_INFO) << "video_channel: " << video_channel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000131
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000132 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000133 ViEChannel* vie_channel = cs.Channel(video_channel);
134 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000135 shared_data_->SetLastError(kViEImageProcessInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000136 return -1;
137 }
138 if (vie_channel->RegisterEffectFilter(&render_filter) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000139 shared_data_->SetLastError(kViEImageProcessFilterExists);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000140 return -1;
141 }
142 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000143}
144
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000145int ViEImageProcessImpl::DeregisterRenderEffectFilter(const int video_channel) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000146 LOG_F(LS_INFO) << "video_channel: " << video_channel;
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000148 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000149 ViEChannel* vie_channel = cs.Channel(video_channel);
150 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000151 shared_data_->SetLastError(kViEImageProcessInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000152 return -1;
153 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000154
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000155 if (vie_channel->RegisterEffectFilter(NULL) != 0) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000156 shared_data_->SetLastError(kViEImageProcessFilterDoesNotExist);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000157 return -1;
158 }
159 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000160}
161
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000162int ViEImageProcessImpl::EnableDeflickering(const int capture_id,
163 const bool enable) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000164 LOG_F(LS_INFO) << "capture_id: " << capture_id
165 << " enable: " << (enable ? "on" : "off");
niklase@google.com470e71d2011-07-07 08:21:25 +0000166
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000167 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000168 ViECapturer* vie_capture = is.Capture(capture_id);
169 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000170 shared_data_->SetLastError(kViEImageProcessInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000171 return -1;
172 }
173
174 if (vie_capture->EnableDeflickering(enable) != 0) {
175 if (enable) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000176 shared_data_->SetLastError(kViEImageProcessAlreadyEnabled);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000177 } else {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000178 shared_data_->SetLastError(kViEImageProcessAlreadyDisabled);
niklase@google.com470e71d2011-07-07 08:21:25 +0000179 }
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000180 return -1;
181 }
182 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000183}
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000184
185int ViEImageProcessImpl::EnableDenoising(const int capture_id,
186 const bool enable) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000187 LOG_F(LS_INFO) << "capture_id: " << capture_id
188 << " enable: " << (enable ? "on" : "off");
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000189
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000190 ViEInputManagerScoped is(*(shared_data_->input_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000191 ViECapturer* vie_capture = is.Capture(capture_id);
192 if (!vie_capture) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000193 shared_data_->SetLastError(kViEImageProcessInvalidCaptureId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000194 return -1;
195 }
196
197 if (vie_capture->EnableDenoising(enable) != 0) {
198 if (enable) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000199 shared_data_->SetLastError(kViEImageProcessAlreadyEnabled);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000200 } else {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000201 shared_data_->SetLastError(kViEImageProcessAlreadyDisabled);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000202 }
203 return -1;
204 }
205 return 0;
206}
207
208int ViEImageProcessImpl::EnableColorEnhancement(const int video_channel,
209 const bool enable) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000210 LOG_F(LS_INFO) << "video_channel: " << video_channel
211 << " enable: " << (enable ? "on" : "off");
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000212
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000213 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000214 ViEChannel* vie_channel = cs.Channel(video_channel);
215 if (!vie_channel) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000216 shared_data_->SetLastError(kViEImageProcessInvalidChannelId);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000217 return -1;
218 }
219 if (vie_channel->EnableColorEnhancement(enable) != 0) {
220 if (enable) {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000221 shared_data_->SetLastError(kViEImageProcessAlreadyEnabled);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000222 } else {
mflodman@webrtc.orgb11424b2012-01-25 13:42:03 +0000223 shared_data_->SetLastError(kViEImageProcessAlreadyDisabled);
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000224 }
225 return -1;
226 }
227 return 0;
228}
229
pbos@webrtc.orgfe1ef932013-10-21 10:34:43 +0000230void ViEImageProcessImpl::RegisterPreEncodeCallback(
231 int video_channel,
232 I420FrameCallback* pre_encode_callback) {
233 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
234 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
235 vie_encoder->RegisterPreEncodeCallback(pre_encode_callback);
236}
237
238void ViEImageProcessImpl::DeRegisterPreEncodeCallback(int video_channel) {
239 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
240 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
241 assert(vie_encoder != NULL);
242 vie_encoder->DeRegisterPreEncodeCallback();
243}
244
sprang@webrtc.org40709352013-11-26 11:41:59 +0000245void ViEImageProcessImpl::RegisterPostEncodeImageCallback(
246 int video_channel,
247 EncodedImageCallback* post_encode_callback) {
248 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
249 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
250 assert(vie_encoder != NULL);
251 vie_encoder->RegisterPostEncodeImageCallback(post_encode_callback);
252}
253
254void ViEImageProcessImpl::DeRegisterPostEncodeCallback(int video_channel) {
255 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
256 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
257 assert(vie_encoder != NULL);
258 vie_encoder->DeRegisterPostEncodeImageCallback();
259}
260
261void ViEImageProcessImpl::RegisterPreDecodeImageCallback(
262 int video_channel,
263 EncodedImageCallback* pre_decode_callback) {
264 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
265 ViEChannel* channel = cs.Channel(video_channel);
266 channel->RegisterPreDecodeImageCallback(pre_decode_callback);
267}
268
269void ViEImageProcessImpl::DeRegisterPreDecodeCallback(int video_channel) {
270 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
271 ViEChannel* channel = cs.Channel(video_channel);
272 channel->RegisterPreDecodeImageCallback(NULL);
273}
274
pbos@webrtc.orgfe1ef932013-10-21 10:34:43 +0000275void ViEImageProcessImpl::RegisterPreRenderCallback(
276 int video_channel,
277 I420FrameCallback* pre_render_callback) {
278 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
279 ViEChannel* vie_channel = cs.Channel(video_channel);
280 assert(vie_channel != NULL);
281 vie_channel->RegisterPreRenderCallback(pre_render_callback);
282}
283
284void ViEImageProcessImpl::DeRegisterPreRenderCallback(int video_channel) {
285 ViEChannelManagerScoped cs(*(shared_data_->channel_manager()));
286 ViEChannel* vie_channel = cs.Channel(video_channel);
287 assert(vie_channel != NULL);
288 vie_channel->RegisterPreRenderCallback(NULL);
289}
290
mflodman@webrtc.org1bdf1df2011-12-20 11:57:47 +0000291} // namespace webrtc