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 | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 11 | #include "video_engine/vie_external_codec_impl.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
| 13 | #include "engine_configurations.h" |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 14 | #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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 23 | ViEExternalCodec* ViEExternalCodec::GetInterface(VideoEngine* video_engine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | #ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 25 | if (video_engine == NULL) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | return NULL; |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 27 | } |
| 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | #endif |
| 36 | } |
| 37 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 38 | int ViEExternalCodecImpl::Release() { |
| 39 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, instance_id_, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | "ViEExternalCodec::Release()"); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 41 | // Decrease ref count. |
| 42 | (*this)--; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 44 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 54 | } |
| 55 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 56 | int 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 63 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 79 | if (vie_encoder->RegisterExternalEncoder(encoder, pl_type) != 0) { |
| 80 | SetLastError(kViECodecUnknownError); |
| 81 | return -1; |
| 82 | } |
| 83 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | int ViEExternalCodecImpl::DeRegisterExternalSendCodec( |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 87 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 92 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 102 | if (vie_encoder->DeRegisterExternalEncoder(pl_type) != 0) { |
| 103 | SetLastError(kViECodecUnknownError); |
| 104 | return -1; |
| 105 | } |
| 106 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | int ViEExternalCodecImpl::RegisterExternalReceiveCodec( |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 110 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 120 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 135 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 136 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | int ViEExternalCodecImpl::DeRegisterExternalReceiveCodec( |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 145 | const 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 149 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 150 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 164 | } |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame^] | 165 | |
| 166 | } // namespace webrtc |