niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +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 | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 11 | #include "video_engine/vie_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 | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 14 | #include "modules/video_coding/main/interface/video_coding.h" |
| 15 | #include "system_wrappers/interface/trace.h" |
mflodman@webrtc.org | a4863db | 2011-12-22 08:51:52 +0000 | [diff] [blame] | 16 | #include "video_engine/include/vie_errors.h" |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 17 | #include "video_engine/vie_capturer.h" |
| 18 | #include "video_engine/vie_channel.h" |
| 19 | #include "video_engine/vie_channel_manager.h" |
| 20 | #include "video_engine/vie_defines.h" |
| 21 | #include "video_engine/vie_encoder.h" |
| 22 | #include "video_engine/vie_impl.h" |
| 23 | #include "video_engine/vie_input_manager.h" |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 24 | #include "video_engine/vie_shared_data.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 26 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 28 | ViECodec* ViECodec::GetInterface(VideoEngine* video_engine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | #ifdef WEBRTC_VIDEO_ENGINE_CODEC_API |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 30 | if (!video_engine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | return NULL; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 32 | } |
| 33 | VideoEngineImpl* vie_impl = reinterpret_cast<VideoEngineImpl*>(video_engine); |
| 34 | ViECodecImpl* vie_codec_impl = vie_impl; |
| 35 | // Increase ref count. |
| 36 | (*vie_codec_impl)++; |
| 37 | return vie_codec_impl; |
| 38 | #else |
| 39 | return NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | #endif |
| 41 | } |
| 42 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 43 | int ViECodecImpl::Release() { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 44 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, shared_data_->instance_id(), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | "ViECodecImpl::Release()"); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 46 | // Decrease ref count. |
| 47 | (*this)--; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 49 | WebRtc_Word32 ref_count = GetCount(); |
| 50 | if (ref_count < 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 51 | WEBRTC_TRACE(kTraceWarning, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 52 | "ViECodec released too many times"); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 53 | shared_data_->SetLastError(kViEAPIDoesNotExist); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 54 | return -1; |
| 55 | } |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 56 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, shared_data_->instance_id(), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 57 | "ViECodec reference count: %d", ref_count); |
| 58 | return ref_count; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | } |
| 60 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 61 | ViECodecImpl::ViECodecImpl(ViESharedData* shared_data) |
| 62 | : shared_data_(shared_data) { |
| 63 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | "ViECodecImpl::ViECodecImpl() Ctor"); |
| 65 | } |
| 66 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 67 | ViECodecImpl::~ViECodecImpl() { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 68 | WEBRTC_TRACE(kTraceMemory, kTraceVideo, shared_data_->instance_id(), |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | "ViECodecImpl::~ViECodecImpl() Dtor"); |
| 70 | } |
| 71 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 72 | int ViECodecImpl::NumberOfCodecs() const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 73 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 74 | "%s", __FUNCTION__); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 75 | // +2 because of FEC(RED and ULPFEC) |
| 76 | return static_cast<int>((VideoCodingModule::NumberOfCodecs() + 2)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | } |
| 78 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 79 | int ViECodecImpl::GetCodec(const unsigned char list_number, |
| 80 | VideoCodec& video_codec) const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 81 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 82 | "%s(list_number: %d, codec_type: %d)", __FUNCTION__, |
| 83 | list_number, video_codec.codecType); |
| 84 | if (list_number == VideoCodingModule::NumberOfCodecs()) { |
| 85 | memset(&video_codec, 0, sizeof(VideoCodec)); |
mflodman@webrtc.org | 9ba151b | 2012-06-21 10:02:13 +0000 | [diff] [blame] | 86 | strncpy(video_codec.plName, "red", 3); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 87 | video_codec.codecType = kVideoCodecRED; |
| 88 | video_codec.plType = VCM_RED_PAYLOAD_TYPE; |
| 89 | } else if (list_number == VideoCodingModule::NumberOfCodecs() + 1) { |
| 90 | memset(&video_codec, 0, sizeof(VideoCodec)); |
mflodman@webrtc.org | 9ba151b | 2012-06-21 10:02:13 +0000 | [diff] [blame] | 91 | strncpy(video_codec.plName, "ulpfec", 6); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 92 | video_codec.codecType = kVideoCodecULPFEC; |
| 93 | video_codec.plType = VCM_ULPFEC_PAYLOAD_TYPE; |
| 94 | } else if (VideoCodingModule::Codec(list_number, &video_codec) != VCM_OK) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 95 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 96 | "%s: Could not get codec for list_number: %u", __FUNCTION__, |
| 97 | list_number); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 98 | shared_data_->SetLastError(kViECodecInvalidArgument); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 99 | return -1; |
| 100 | } |
| 101 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | } |
| 103 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 104 | int ViECodecImpl::SetSendCodec(const int video_channel, |
| 105 | const VideoCodec& video_codec) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 106 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
mflodman@webrtc.org | 9ba151b | 2012-06-21 10:02:13 +0000 | [diff] [blame] | 107 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 108 | "%s(video_channel: %d, codec_type: %d)", __FUNCTION__, |
| 109 | video_channel, video_codec.codecType); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 110 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, |
| 111 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 112 | "%s: codec: %d, pl_type: %d, width: %d, height: %d, bitrate: %d" |
mflodman@webrtc.org | 9c0aedc | 2012-01-03 13:46:49 +0000 | [diff] [blame] | 113 | "maxBr: %d, min_br: %d, frame_rate: %d, qpMax: %u," |
| 114 | "numberOfSimulcastStreams: %u )", __FUNCTION__, |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 115 | video_codec.codecType, video_codec.plType, video_codec.width, |
| 116 | video_codec.height, video_codec.startBitrate, |
| 117 | video_codec.maxBitrate, video_codec.minBitrate, |
mflodman@webrtc.org | 9c0aedc | 2012-01-03 13:46:49 +0000 | [diff] [blame] | 118 | video_codec.maxFramerate, video_codec.qpMax, |
| 119 | video_codec.numberOfSimulcastStreams); |
| 120 | if (video_codec.codecType == kVideoCodecVP8) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 121 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, |
| 122 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 9c0aedc | 2012-01-03 13:46:49 +0000 | [diff] [blame] | 123 | "pictureLossIndicationOn: %d, feedbackModeOn: %d, " |
| 124 | "complexity: %d, resilience: %d, numberOfTemporalLayers: %u", |
| 125 | video_codec.codecSpecific.VP8.pictureLossIndicationOn, |
| 126 | video_codec.codecSpecific.VP8.feedbackModeOn, |
| 127 | video_codec.codecSpecific.VP8.complexity, |
| 128 | video_codec.codecSpecific.VP8.resilience, |
| 129 | video_codec.codecSpecific.VP8.numberOfTemporalLayers); |
| 130 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 131 | if (!CodecValid(video_codec)) { |
| 132 | // Error logged. |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 133 | shared_data_->SetLastError(kViECodecInvalidCodec); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 134 | return -1; |
| 135 | } |
stefan@webrtc.org | 791eec7 | 2011-10-11 07:53:43 +0000 | [diff] [blame] | 136 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 137 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 138 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 139 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 140 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 141 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 142 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 143 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
stefan@webrtc.org | 791eec7 | 2011-10-11 07:53:43 +0000 | [diff] [blame] | 144 | return -1; |
| 145 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 146 | |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 147 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 148 | assert(vie_encoder); |
| 149 | if (vie_encoder->Owner() != video_channel) { |
| 150 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 151 | ViEId(shared_data_->instance_id(), video_channel), |
| 152 | "%s: Receive only channel %d", __FUNCTION__, video_channel); |
| 153 | shared_data_->SetLastError(kViECodecReceiveOnlyChannel); |
| 154 | return -1; |
| 155 | } |
| 156 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 157 | // Set a max_bitrate if the user hasn't set one. |
| 158 | VideoCodec video_codec_internal; |
| 159 | memcpy(&video_codec_internal, &video_codec, sizeof(VideoCodec)); |
| 160 | if (video_codec_internal.maxBitrate == 0) { |
| 161 | // Max is one bit per pixel. |
| 162 | video_codec_internal.maxBitrate = (video_codec_internal.width * |
| 163 | video_codec_internal.height * |
| 164 | video_codec_internal.maxFramerate) |
| 165 | / 1000; |
| 166 | if (video_codec_internal.startBitrate > video_codec_internal.maxBitrate) { |
| 167 | // Don't limit the set start bitrate. |
| 168 | video_codec_internal.maxBitrate = video_codec_internal.startBitrate; |
| 169 | } |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 170 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, |
| 171 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 172 | "%s: New max bitrate set to %d kbps", __FUNCTION__, |
| 173 | video_codec_internal.maxBitrate); |
| 174 | } |
| 175 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 176 | VideoCodec encoder; |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 177 | vie_encoder->GetEncoder(&encoder); |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 178 | |
mflodman@webrtc.org | 9c0aedc | 2012-01-03 13:46:49 +0000 | [diff] [blame] | 179 | // Make sure to generate a new SSRC if the codec type and/or resolution has |
| 180 | // changed. This won't have any effect if the user has set an SSRC. |
| 181 | bool new_rtp_stream = false; |
stefan@webrtc.org | 4e8eaba | 2012-08-20 14:29:52 +0000 | [diff] [blame] | 182 | if (encoder.codecType != video_codec_internal.codecType) { |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 183 | new_rtp_stream = true; |
| 184 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 185 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 186 | ViEInputManagerScoped is(*(shared_data_->input_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 187 | ViEFrameProviderBase* frame_provider = NULL; |
| 188 | |
| 189 | // Stop the media flow while reconfiguring. |
| 190 | vie_encoder->Pause(); |
| 191 | |
| 192 | // Check if we have a frame provider that is a camera and can provide this |
| 193 | // codec for us. |
| 194 | bool use_capture_device_as_encoder = false; |
| 195 | frame_provider = is.FrameProvider(vie_encoder); |
| 196 | if (frame_provider) { |
| 197 | if (frame_provider->Id() >= kViECaptureIdBase && |
| 198 | frame_provider->Id() <= kViECaptureIdMax) { |
| 199 | ViECapturer* vie_capture = static_cast<ViECapturer*>(frame_provider); |
| 200 | // Try to get preencoded. Nothing to do if it is not supported. |
| 201 | if (vie_capture && vie_capture->PreEncodeToViEEncoder( |
| 202 | video_codec_internal, |
| 203 | *vie_encoder, |
| 204 | video_channel) == 0) { |
| 205 | use_capture_device_as_encoder = true; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // Update the encoder settings if we are not using a capture device capable |
| 211 | // of this codec. |
| 212 | if (!use_capture_device_as_encoder && |
| 213 | vie_encoder->SetEncoder(video_codec_internal) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 214 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 215 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 216 | "%s: Could not change encoder for channel %d", __FUNCTION__, |
| 217 | video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 218 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 219 | return -1; |
| 220 | } |
| 221 | |
mflodman@webrtc.org | 9c0aedc | 2012-01-03 13:46:49 +0000 | [diff] [blame] | 222 | // Give the channel(s) the new information. |
| 223 | ChannelList channels; |
| 224 | cs.ChannelsUsingViEEncoder(video_channel, &channels); |
| 225 | for (ChannelList::iterator it = channels.begin(); it != channels.end(); |
| 226 | ++it) { |
| 227 | bool ret = true; |
| 228 | if ((*it)->SetSendCodec(video_codec_internal, new_rtp_stream) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 229 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 230 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | 9c0aedc | 2012-01-03 13:46:49 +0000 | [diff] [blame] | 231 | "%s: Could not set send codec for channel %d", __FUNCTION__, |
| 232 | video_channel); |
| 233 | ret = false; |
| 234 | } |
| 235 | if (!ret) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 236 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | 9c0aedc | 2012-01-03 13:46:49 +0000 | [diff] [blame] | 237 | return -1; |
| 238 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | // Update the protection mode, we might be switching NACK/FEC. |
| 242 | vie_encoder->UpdateProtectionMethod(); |
| 243 | |
| 244 | // Get new best format for frame provider. |
| 245 | if (frame_provider) { |
| 246 | frame_provider->FrameCallbackChanged(); |
| 247 | } |
| 248 | // Restart the media flow |
| 249 | if (new_rtp_stream) { |
| 250 | // Stream settings changed, make sure we get a key frame. |
| 251 | vie_encoder->SendKeyFrame(); |
| 252 | } |
| 253 | vie_encoder->Restart(); |
| 254 | return 0; |
stefan@webrtc.org | 791eec7 | 2011-10-11 07:53:43 +0000 | [diff] [blame] | 255 | } |
| 256 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 257 | int ViECodecImpl::GetSendCodec(const int video_channel, |
| 258 | VideoCodec& video_codec) const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 259 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 260 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 261 | "%s(video_channel: %d)", __FUNCTION__, video_channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 262 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 263 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 264 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 265 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 266 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 267 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 268 | "%s: No encoder for channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 269 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 270 | return -1; |
| 271 | } |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 272 | return vie_encoder->GetEncoder(&video_codec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 273 | } |
| 274 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 275 | int ViECodecImpl::SetReceiveCodec(const int video_channel, |
| 276 | const VideoCodec& video_codec) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 277 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 278 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 279 | "%s(video_channel: %d, codec_type: %d)", __FUNCTION__, |
| 280 | video_channel, video_codec.codecType); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 281 | WEBRTC_TRACE(kTraceInfo, kTraceVideo, |
| 282 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 283 | "%s: codec: %d, pl_type: %d, width: %d, height: %d, bitrate: %d," |
| 284 | "maxBr: %d, min_br: %d, frame_rate: %d", __FUNCTION__, |
| 285 | video_codec.codecType, video_codec.plType, video_codec.width, |
| 286 | video_codec.height, video_codec.startBitrate, |
| 287 | video_codec.maxBitrate, video_codec.minBitrate, |
| 288 | video_codec.maxFramerate); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 289 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 290 | if (CodecValid(video_codec) == false) { |
| 291 | // Error logged. |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 292 | shared_data_->SetLastError(kViECodecInvalidCodec); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 293 | return -1; |
| 294 | } |
| 295 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 296 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 297 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 298 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 299 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 300 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 301 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 302 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 303 | return -1; |
| 304 | } |
| 305 | |
| 306 | if (vie_channel->SetReceiveCodec(video_codec) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 307 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 308 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 309 | "%s: Could not set receive codec for channel %d", |
| 310 | __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 311 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 312 | return -1; |
| 313 | } |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | int ViECodecImpl::GetReceiveCodec(const int video_channel, |
| 318 | VideoCodec& video_codec) const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 319 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 320 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 321 | "%s(video_channel: %d, codec_type: %d)", __FUNCTION__, |
| 322 | video_channel, video_codec.codecType); |
| 323 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 324 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 325 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 326 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 327 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 328 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 329 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 330 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 331 | return -1; |
| 332 | } |
| 333 | |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 334 | if (vie_channel->GetReceiveCodec(&video_codec) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 335 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 336 | return -1; |
| 337 | } |
| 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | int ViECodecImpl::GetCodecConfigParameters( |
| 342 | const int video_channel, |
| 343 | unsigned char config_parameters[kConfigParameterSize], |
| 344 | unsigned char& config_parameters_size) const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 345 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 346 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 347 | "%s(video_channel: %d)", __FUNCTION__, video_channel); |
| 348 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 349 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 350 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 351 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 352 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 353 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 354 | "%s: No encoder for channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 355 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 356 | return -1; |
| 357 | } |
| 358 | |
| 359 | if (vie_encoder->GetCodecConfigParameters(config_parameters, |
| 360 | config_parameters_size) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 361 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 362 | return -1; |
| 363 | } |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | int ViECodecImpl::SetImageScaleStatus(const int video_channel, |
| 368 | const bool enable) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 369 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 370 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 371 | "%s(video_channel: %d, enable: %d)", __FUNCTION__, video_channel, |
| 372 | enable); |
| 373 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 374 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 375 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 376 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 377 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 378 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 379 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 380 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 381 | return -1; |
| 382 | } |
| 383 | |
| 384 | if (vie_encoder->ScaleInputImage(enable) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 385 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 386 | return -1; |
| 387 | } |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | int ViECodecImpl::GetSendCodecStastistics(const int video_channel, |
| 392 | unsigned int& key_frames, |
| 393 | unsigned int& delta_frames) const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 394 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 395 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 396 | "%s(video_channel %d)", __FUNCTION__, video_channel); |
| 397 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 398 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 399 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 400 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 401 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 402 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 403 | "%s: No send codec for channel %d", __FUNCTION__, |
| 404 | video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 405 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 406 | return -1; |
| 407 | } |
| 408 | |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 409 | if (vie_encoder->SendCodecStatistics(&key_frames, &delta_frames) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 410 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 411 | return -1; |
| 412 | } |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | int ViECodecImpl::GetReceiveCodecStastistics(const int video_channel, |
| 417 | unsigned int& key_frames, |
| 418 | unsigned int& delta_frames) const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 419 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 420 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 421 | "%s(video_channel: %d, codec_type: %d)", __FUNCTION__, |
| 422 | video_channel); |
| 423 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 424 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 425 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 426 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 427 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 428 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 429 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 430 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 431 | return -1; |
| 432 | } |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 433 | if (vie_channel->ReceiveCodecStatistics(&key_frames, &delta_frames) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 434 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 435 | return -1; |
| 436 | } |
| 437 | return 0; |
| 438 | } |
| 439 | |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 440 | int ViECodecImpl::GetCodecTargetBitrate(const int video_channel, |
| 441 | unsigned int* bitrate) const { |
| 442 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 443 | ViEId(shared_data_->instance_id(), video_channel), |
| 444 | "%s(video_channel: %d, codec_type: %d)", __FUNCTION__, |
| 445 | video_channel); |
| 446 | |
| 447 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 448 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 449 | if (!vie_encoder) { |
| 450 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 451 | ViEId(shared_data_->instance_id(), video_channel), |
| 452 | "%s: No send codec for channel %d", __FUNCTION__, |
| 453 | video_channel); |
| 454 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
| 455 | return -1; |
| 456 | } |
| 457 | return vie_encoder->CodecTargetBitrate(static_cast<WebRtc_UWord32*>(bitrate)); |
| 458 | } |
| 459 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 460 | unsigned int ViECodecImpl::GetDiscardedPackets(const int video_channel) const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 461 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 462 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 463 | "%s(video_channel: %d, codec_type: %d)", __FUNCTION__, |
| 464 | video_channel); |
| 465 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 466 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 467 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 468 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 469 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 470 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 471 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 472 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 473 | return -1; |
| 474 | } |
| 475 | return vie_channel->DiscardedPackets(); |
| 476 | } |
| 477 | |
| 478 | int ViECodecImpl::SetKeyFrameRequestCallbackStatus(const int video_channel, |
| 479 | const bool enable) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 480 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 481 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 482 | "%s(video_channel: %d)", __FUNCTION__, video_channel); |
| 483 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 484 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 485 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 486 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 487 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 488 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 489 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 490 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 491 | return -1; |
| 492 | } |
| 493 | if (vie_channel->EnableKeyFrameRequestCallback(enable) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 494 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 495 | return -1; |
| 496 | } |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | int ViECodecImpl::SetSignalKeyPacketLossStatus(const int video_channel, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 501 | const bool enable, |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 502 | const bool only_key_frames) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 503 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 504 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 505 | "%s(video_channel: %d, enable: %d, only_key_frames: %d)", |
| 506 | __FUNCTION__, video_channel, enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 507 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 508 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 509 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 510 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 511 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 512 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 513 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 514 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 515 | return -1; |
| 516 | } |
| 517 | if (vie_channel->SetSignalPacketLossStatus(enable, only_key_frames) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 518 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 519 | return -1; |
| 520 | } |
| 521 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 522 | } |
| 523 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 524 | int ViECodecImpl::RegisterEncoderObserver(const int video_channel, |
| 525 | ViEEncoderObserver& observer) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 526 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 527 | "%s", __FUNCTION__); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 528 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 529 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 530 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 531 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 532 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 533 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 534 | "%s: No encoder for channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 535 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 536 | return -1; |
| 537 | } |
| 538 | if (vie_encoder->RegisterCodecObserver(&observer) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 539 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 540 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 541 | "%s: Could not register codec observer at channel", |
| 542 | __FUNCTION__); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 543 | shared_data_->SetLastError(kViECodecObserverAlreadyRegistered); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 544 | return -1; |
| 545 | } |
| 546 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 547 | } |
| 548 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 549 | int ViECodecImpl::DeregisterEncoderObserver(const int video_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 550 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 551 | "%s", __FUNCTION__); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 552 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 553 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 554 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 555 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 556 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 557 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 558 | "%s: No encoder for channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 559 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 560 | return -1; |
| 561 | } |
| 562 | if (vie_encoder->RegisterCodecObserver(NULL) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 563 | shared_data_->SetLastError(kViECodecObserverNotRegistered); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 564 | return -1; |
| 565 | } |
| 566 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 567 | } |
| 568 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 569 | int ViECodecImpl::RegisterDecoderObserver(const int video_channel, |
| 570 | ViEDecoderObserver& observer) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 571 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
| 572 | "%s", __FUNCTION__); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 573 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 574 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 575 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 576 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 577 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 578 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 579 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 580 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 581 | return -1; |
| 582 | } |
| 583 | if (vie_channel->RegisterCodecObserver(&observer) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 584 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 585 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 586 | "%s: Could not register codec observer at channel", |
| 587 | __FUNCTION__); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 588 | shared_data_->SetLastError(kViECodecObserverAlreadyRegistered); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 589 | return -1; |
| 590 | } |
| 591 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 592 | } |
| 593 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 594 | int ViECodecImpl::DeregisterDecoderObserver(const int video_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 595 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 596 | ViEId(shared_data_->instance_id()), "%s", |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 597 | __FUNCTION__); |
| 598 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 599 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 600 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 601 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 602 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 603 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 604 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 605 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 606 | return -1; |
| 607 | } |
| 608 | if (vie_channel->RegisterCodecObserver(NULL) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 609 | shared_data_->SetLastError(kViECodecObserverNotRegistered); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 610 | return -1; |
| 611 | } |
| 612 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 613 | } |
| 614 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 615 | int ViECodecImpl::SendKeyFrame(const int video_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 616 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, ViEId(shared_data_->instance_id()), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 617 | "%s(video_channel: %d)", __FUNCTION__, video_channel); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 618 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 619 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 620 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 621 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 622 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 623 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 624 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 625 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 626 | return -1; |
| 627 | } |
| 628 | if (vie_encoder->SendKeyFrame() != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 629 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 630 | return -1; |
| 631 | } |
| 632 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 633 | } |
| 634 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 635 | int ViECodecImpl::WaitForFirstKeyFrame(const int video_channel, |
| 636 | const bool wait) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 637 | WEBRTC_TRACE(kTraceApiCall, kTraceVideo, |
| 638 | ViEId(shared_data_->instance_id()), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 639 | "%s(video_channel: %d, wait: %d)", __FUNCTION__, video_channel, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 640 | wait); |
| 641 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 642 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 643 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 644 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 645 | WEBRTC_TRACE(kTraceError, kTraceVideo, |
| 646 | ViEId(shared_data_->instance_id(), video_channel), |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 647 | "%s: No channel %d", __FUNCTION__, video_channel); |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 648 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 649 | return -1; |
| 650 | } |
| 651 | if (vie_channel->WaitForKeyFrame(wait) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 652 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 653 | return -1; |
| 654 | } |
| 655 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 656 | } |
| 657 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 658 | bool ViECodecImpl::CodecValid(const VideoCodec& video_codec) { |
| 659 | // Check pl_name matches codec_type. |
| 660 | if (video_codec.codecType == kVideoCodecRED) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 661 | #if defined(WIN32) |
mflodman@webrtc.org | 1fe2ada | 2011-12-21 12:23:15 +0000 | [diff] [blame] | 662 | if (_strnicmp(video_codec.plName, "red", 3) == 0) { |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 663 | #else |
| 664 | if (strncasecmp(video_codec.plName, "red", 3) == 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 665 | #endif |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 666 | // We only care about the type and name for red. |
| 667 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 668 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 669 | WEBRTC_TRACE(kTraceError, kTraceVideo, -1, |
| 670 | "Codec type doesn't match pl_name", video_codec.plType); |
| 671 | return false; |
| 672 | } else if (video_codec.codecType == kVideoCodecULPFEC) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 673 | #if defined(WIN32) |
mflodman@webrtc.org | 1fe2ada | 2011-12-21 12:23:15 +0000 | [diff] [blame] | 674 | if (_strnicmp(video_codec.plName, "ULPFEC", 6) == 0) { |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 675 | #else |
| 676 | if (strncasecmp(video_codec.plName, "ULPFEC", 6) == 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 677 | #endif |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 678 | // We only care about the type and name for ULPFEC. |
| 679 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 680 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 681 | WEBRTC_TRACE(kTraceError, kTraceVideo, -1, |
| 682 | "Codec type doesn't match pl_name", video_codec.plType); |
| 683 | return false; |
pwestin@webrtc.org | 5621057 | 2012-01-17 12:45:47 +0000 | [diff] [blame] | 684 | } else if ((video_codec.codecType == kVideoCodecVP8 && |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 685 | strncmp(video_codec.plName, "VP8", 4) == 0) || |
| 686 | (video_codec.codecType == kVideoCodecI420 && |
pwestin@webrtc.org | 5621057 | 2012-01-17 12:45:47 +0000 | [diff] [blame] | 687 | strncmp(video_codec.plName, "I420", 4) == 0)) { |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 688 | // OK. |
| 689 | } else { |
| 690 | WEBRTC_TRACE(kTraceError, kTraceVideo, -1, |
| 691 | "Codec type doesn't match pl_name", video_codec.plType); |
| 692 | return false; |
| 693 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 694 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 695 | if (video_codec.plType == 0 && video_codec.plType > 127) { |
| 696 | WEBRTC_TRACE(kTraceError, kTraceVideo, -1, |
| 697 | "Invalid codec payload type: %d", video_codec.plType); |
| 698 | return false; |
| 699 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 700 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 701 | if (video_codec.width > kViEMaxCodecWidth || |
| 702 | video_codec.height > kViEMaxCodecHeight) { |
| 703 | WEBRTC_TRACE(kTraceError, kTraceVideo, -1, "Invalid codec size: %u x %u", |
| 704 | video_codec.width, video_codec.height); |
| 705 | return false; |
| 706 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 707 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 708 | if (video_codec.startBitrate < kViEMinCodecBitrate) { |
| 709 | WEBRTC_TRACE(kTraceError, kTraceVideo, -1, "Invalid start_bitrate: %u", |
| 710 | video_codec.startBitrate); |
| 711 | return false; |
| 712 | } |
| 713 | if (video_codec.minBitrate < kViEMinCodecBitrate) { |
| 714 | WEBRTC_TRACE(kTraceError, kTraceVideo, -1, "Invalid min_bitrate: %u", |
| 715 | video_codec.minBitrate); |
| 716 | return false; |
| 717 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 718 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 719 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 720 | |
| 721 | } // namespace webrtc |