blob: f3a11d800a75cff9741193cf3c37b704c58285a9 [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.org813b4ef2011-12-20 10:39:30 +000011#include "video_engine/vie_external_codec_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
13#include "engine_configurations.h"
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000014#include "system_wrappers/interface/trace.h"
15#include "video_engine/main/interface/vie_errors.h"
16#include "video_engine/vie_channel.h"
17#include "video_engine/vie_channel_manager.h"
18#include "video_engine/vie_encoder.h"
19#include "video_engine/vie_impl.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000021namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000022
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000023ViEExternalCodec* ViEExternalCodec::GetInterface(VideoEngine* video_engine) {
niklase@google.com470e71d2011-07-07 08:21:25 +000024#ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000025 if (video_engine == NULL) {
niklase@google.com470e71d2011-07-07 08:21:25 +000026 return NULL;
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000027 }
28 VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine);
29 ViEExternalCodecImpl* vie_external_codec_impl = vie_impl;
30 // Increase ref count.
31 (*vie_external_codec_impl)++;
32 return vie_external_codec_impl;
33#else
34 return NULL;
niklase@google.com470e71d2011-07-07 08:21:25 +000035#endif
36}
37
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000038int ViEExternalCodecImpl::Release() {
39 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, instance_id_,
niklase@google.com470e71d2011-07-07 08:21:25 +000040 "ViEExternalCodec::Release()");
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000041 // Decrease ref count.
42 (*this)--;
niklase@google.com470e71d2011-07-07 08:21:25 +000043
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000044 WebRtc_Word32 ref_count = GetCount();
45 if (ref_count < 0) {
46 WEBRTC_TRACE(kTraceWarning, kTraceVideo, instance_id_,
47 "ViEExternalCodec release too many times");
48 SetLastError(kViEAPIDoesNotExist);
49 return -1;
50 }
51 WEBRTC_TRACE(kTraceInfo, kTraceVideo, instance_id_,
52 "ViEExternalCodec reference count: %d", ref_count);
53 return ref_count;
niklase@google.com470e71d2011-07-07 08:21:25 +000054}
55
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000056int ViEExternalCodecImpl::RegisterExternalSendCodec(const int video_channel,
57 const unsigned char pl_type,
58 VideoEncoder* encoder) {
59 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_),
60 "%s channel %d pl_type %d encoder 0x%x", __FUNCTION__,
61 video_channel, pl_type, encoder);
niklase@google.com470e71d2011-07-07 08:21:25 +000062
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000063 ViEChannelManagerScoped cs(channel_manager_);
64 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
65 if (!vie_encoder) {
66 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel),
67 "%s: Invalid argument video_channel %u. Does it exist?",
68 __FUNCTION__, video_channel);
69 SetLastError(kViECodecInvalidArgument);
70 return -1;
71 }
72 if (!encoder) {
73 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel),
74 "%s: Invalid argument Encoder 0x%x.", __FUNCTION__, encoder);
75 SetLastError(kViECodecInvalidArgument);
76 return -1;
77 }
niklase@google.com470e71d2011-07-07 08:21:25 +000078
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000079 if (vie_encoder->RegisterExternalEncoder(encoder, pl_type) != 0) {
80 SetLastError(kViECodecUnknownError);
81 return -1;
82 }
83 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000084}
85
86int ViEExternalCodecImpl::DeRegisterExternalSendCodec(
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000087 const int video_channel, const unsigned char pl_type) {
88 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_),
89 "%s channel %d pl_type %d", __FUNCTION__, video_channel,
90 pl_type);
niklase@google.com470e71d2011-07-07 08:21:25 +000091
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +000092 ViEChannelManagerScoped cs(channel_manager_);
93 ViEEncoder* vie_encoder = cs.Encoder(video_channel);
94 if (!vie_encoder) {
95 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel),
96 "%s: Invalid argument video_channel %u. Does it exist?",
97 __FUNCTION__, video_channel);
98 SetLastError(kViECodecInvalidArgument);
99 return -1;
100 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000101
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +0000102 if (vie_encoder->DeRegisterExternalEncoder(pl_type) != 0) {
103 SetLastError(kViECodecUnknownError);
104 return -1;
105 }
106 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107}
108
109int ViEExternalCodecImpl::RegisterExternalReceiveCodec(
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +0000110 const int video_channel,
111 const unsigned int pl_type,
112 VideoDecoder* decoder,
113 bool decoder_render,
114 int render_delay) {
115 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_),
116 "%s channel %d pl_type %d decoder 0x%x, decoder_render %d, "
117 "renderDelay %d", __FUNCTION__, video_channel, pl_type, decoder,
118 decoder_render, render_delay);
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +0000120 ViEChannelManagerScoped cs(channel_manager_);
121 ViEChannel* vie_channel = cs.Channel(video_channel);
122 if (!vie_channel) {
123 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel),
124 "%s: Invalid argument video_channel %u. Does it exist?",
125 __FUNCTION__, video_channel);
126 SetLastError(kViECodecInvalidArgument);
127 return -1;
128 }
129 if (!decoder) {
130 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel),
131 "%s: Invalid argument decoder 0x%x.", __FUNCTION__, decoder);
132 SetLastError(kViECodecInvalidArgument);
133 return -1;
134 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000135
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +0000136 if (vie_channel->RegisterExternalDecoder(pl_type, decoder, decoder_render,
137 render_delay) != 0) {
138 SetLastError(kViECodecUnknownError);
139 return -1;
140 }
141 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000142}
143
144int ViEExternalCodecImpl::DeRegisterExternalReceiveCodec(
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +0000145const int video_channel, const unsigned char pl_type) {
146 WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(instance_id_),
147 "%s channel %d pl_type %u", __FUNCTION__, video_channel,
148 pl_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000149
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +0000150 ViEChannelManagerScoped cs(channel_manager_);
151 ViEChannel* vie_channel = cs.Channel(video_channel);
152 if (!vie_channel) {
153 WEBRTC_TRACE(kTraceError, kTraceVideo, ViEId(instance_id_, video_channel),
154 "%s: Invalid argument video_channel %u. Does it exist?",
155 __FUNCTION__, video_channel);
156 SetLastError(kViECodecInvalidArgument);
157 return -1;
158 }
159 if (vie_channel->DeRegisterExternalDecoder(pl_type) != 0) {
160 SetLastError(kViECodecUnknownError);
161 return -1;
162 }
163 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000164}
mflodman@webrtc.org813b4ef2011-12-20 10:39:30 +0000165
166} // namespace webrtc