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