niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
mflodman@webrtc.org | 9ba151b | 2012-06-21 10:02:13 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
mflodman@webrtc.org | 9ba151b | 2012-06-21 10:02:13 +0000 | [diff] [blame] | 13 | #include "engine_configurations.h" // NOLINT |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 14 | #include "system_wrappers/interface/trace.h" |
mflodman@webrtc.org | a4863db | 2011-12-22 08:51:52 +0000 | [diff] [blame] | 15 | #include "video_engine/include/vie_errors.h" |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 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" |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 20 | #include "video_engine/vie_shared_data.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 22 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 24 | ViEExternalCodec* ViEExternalCodec::GetInterface(VideoEngine* video_engine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | #ifdef WEBRTC_VIDEO_ENGINE_EXTERNAL_CODEC_API |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 26 | if (video_engine == NULL) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | return NULL; |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 28 | } |
| 29 | VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine); |
| 30 | ViEExternalCodecImpl* vie_external_codec_impl = vie_impl; |
| 31 | // Increase ref count. |
| 32 | (*vie_external_codec_impl)++; |
| 33 | return vie_external_codec_impl; |
| 34 | #else |
| 35 | return NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | #endif |
| 37 | } |
| 38 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 39 | int ViEExternalCodecImpl::Release() { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 40 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_->instance_id(), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | "ViEExternalCodec::Release()"); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 42 | // Decrease ref count. |
| 43 | (*this)--; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 44 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 45 | WebRtc_Word32 ref_count = GetCount(); |
| 46 | if (ref_count < 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 47 | WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 48 | "ViEExternalCodec release too many times"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 49 | shared_data_->SetLastError(kViEAPIDoesNotExist); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 50 | return -1; |
| 51 | } |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 52 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 53 | "ViEExternalCodec reference count: %d", ref_count); |
| 54 | return ref_count; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | } |
| 56 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 57 | ViEExternalCodecImpl::ViEExternalCodecImpl(ViESharedData* shared_data) |
| 58 | : shared_data_(shared_data) { |
| 59 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(), |
| 60 | "ViEExternalCodecImpl::ViEExternalCodecImpl() Ctor"); |
| 61 | } |
| 62 | |
| 63 | ViEExternalCodecImpl::~ViEExternalCodecImpl() { |
| 64 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(), |
| 65 | "ViEExternalCodecImpl::~ViEExternalCodecImpl() Dtor"); |
| 66 | } |
| 67 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 68 | int ViEExternalCodecImpl::RegisterExternalSendCodec(const int video_channel, |
| 69 | const unsigned char pl_type, |
| 70 | VideoEncoder* encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 71 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 72 | "%s channel %d pl_type %d encoder 0x%x", __FUNCTION__, |
| 73 | video_channel, pl_type, encoder); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 75 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 76 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 77 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 78 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 79 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 80 | "%s: Invalid argument video_channel %u. Does it exist?", |
| 81 | __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 82 | shared_data_->SetLastError(kViECodecInvalidArgument); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 83 | return -1; |
| 84 | } |
| 85 | if (!encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 86 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 87 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 88 | "%s: Invalid argument Encoder 0x%x.", __FUNCTION__, encoder); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 89 | shared_data_->SetLastError(kViECodecInvalidArgument); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 90 | return -1; |
| 91 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 92 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 93 | if (vie_encoder->RegisterExternalEncoder(encoder, pl_type) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 94 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 95 | return -1; |
| 96 | } |
| 97 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | int ViEExternalCodecImpl::DeRegisterExternalSendCodec( |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 101 | const int video_channel, const unsigned char pl_type) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 102 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 103 | "%s channel %d pl_type %d", __FUNCTION__, video_channel, |
| 104 | pl_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 106 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 107 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 108 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 109 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 110 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 111 | "%s: Invalid argument video_channel %u. Does it exist?", |
| 112 | __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 113 | shared_data_->SetLastError(kViECodecInvalidArgument); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 114 | return -1; |
| 115 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 117 | if (vie_encoder->DeRegisterExternalEncoder(pl_type) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 118 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 119 | return -1; |
| 120 | } |
| 121 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | int ViEExternalCodecImpl::RegisterExternalReceiveCodec( |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 125 | const int video_channel, |
| 126 | const unsigned int pl_type, |
| 127 | VideoDecoder* decoder, |
| 128 | bool decoder_render, |
| 129 | int render_delay) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 130 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 131 | "%s channel %d pl_type %d decoder 0x%x, decoder_render %d, " |
| 132 | "renderDelay %d", __FUNCTION__, video_channel, pl_type, decoder, |
| 133 | decoder_render, render_delay); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 135 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 136 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 137 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 138 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 139 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 140 | "%s: Invalid argument video_channel %u. Does it exist?", |
| 141 | __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 142 | shared_data_->SetLastError(kViECodecInvalidArgument); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 143 | return -1; |
| 144 | } |
| 145 | if (!decoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 146 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 147 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 148 | "%s: Invalid argument decoder 0x%x.", __FUNCTION__, decoder); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 149 | shared_data_->SetLastError(kViECodecInvalidArgument); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 150 | return -1; |
| 151 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 152 | |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 153 | if (vie_channel->RegisterExternalDecoder(pl_type, decoder, decoder_render, |
| 154 | render_delay) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 155 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 156 | return -1; |
| 157 | } |
| 158 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | int ViEExternalCodecImpl::DeRegisterExternalReceiveCodec( |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 162 | const int video_channel, const unsigned char pl_type) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 163 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 164 | "%s channel %d pl_type %u", __FUNCTION__, video_channel, |
| 165 | pl_type); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 166 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 167 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 168 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 169 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 170 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 171 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 172 | "%s: Invalid argument video_channel %u. Does it exist?", |
| 173 | __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 174 | shared_data_->SetLastError(kViECodecInvalidArgument); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 175 | return -1; |
| 176 | } |
| 177 | if (vie_channel->DeRegisterExternalDecoder(pl_type) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 178 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 179 | return -1; |
| 180 | } |
| 181 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 182 | } |
mflodman@webrtc.org | 813b4ef | 2011-12-20 10:39:30 +0000 | [diff] [blame] | 183 | |
| 184 | } // namespace webrtc |