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 | |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 11 | #include "webrtc/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 | |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 15 | #include "webrtc/engine_configurations.h" |
| 16 | #include "webrtc/modules/video_coding/main/interface/video_coding.h" |
| 17 | #include "webrtc/system_wrappers/interface/logging.h" |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 18 | #include "webrtc/video_engine/include/vie_errors.h" |
| 19 | #include "webrtc/video_engine/vie_capturer.h" |
| 20 | #include "webrtc/video_engine/vie_channel.h" |
| 21 | #include "webrtc/video_engine/vie_channel_manager.h" |
| 22 | #include "webrtc/video_engine/vie_defines.h" |
| 23 | #include "webrtc/video_engine/vie_encoder.h" |
| 24 | #include "webrtc/video_engine/vie_impl.h" |
| 25 | #include "webrtc/video_engine/vie_input_manager.h" |
| 26 | #include "webrtc/video_engine/vie_shared_data.h" |
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 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 30 | static void LogCodec(const VideoCodec& codec) { |
| 31 | LOG(LS_INFO) << "CodecType " << codec.codecType |
| 32 | << ", pl_type " << codec.plType |
| 33 | << ", resolution " << codec.width |
| 34 | << " x " << codec.height |
| 35 | << ", start br " << codec.startBitrate |
| 36 | << ", min br " << codec.minBitrate |
| 37 | << ", max br " << codec.maxBitrate |
| 38 | << ", max fpr " << codec.maxFramerate |
| 39 | << ", max qp " << codec.qpMax |
| 40 | << ", number of streams " |
| 41 | << codec.numberOfSimulcastStreams; |
| 42 | if (codec.codecType == kVideoCodecVP8) { |
| 43 | LOG(LS_INFO) << "VP8 specific settings"; |
| 44 | LOG(LS_INFO) << "pivtureLossIndicationOn " |
| 45 | << codec.codecSpecific.VP8.pictureLossIndicationOn |
| 46 | << ", feedbackModeOn " |
| 47 | << codec.codecSpecific.VP8.feedbackModeOn |
| 48 | << ", complexity " |
| 49 | << codec.codecSpecific.VP8.complexity |
| 50 | << ", resilience " |
| 51 | << codec.codecSpecific.VP8.resilience |
| 52 | << ", numberOfTeporalLayers " |
| 53 | << codec.codecSpecific.VP8.numberOfTemporalLayers |
| 54 | << ", keyFrameinterval " |
| 55 | << codec.codecSpecific.VP8.keyFrameInterval; |
| 56 | for (int idx = 0; idx < codec.numberOfSimulcastStreams; ++idx) { |
| 57 | LOG(LS_INFO) << "Stream " << codec.simulcastStream[idx].width |
| 58 | << " x " << codec.simulcastStream[idx].height; |
| 59 | LOG(LS_INFO) << "Temporal layers " |
| 60 | << codec.simulcastStream[idx].numberOfTemporalLayers |
| 61 | << ", min br " |
| 62 | << codec.simulcastStream[idx].minBitrate |
| 63 | << ", target br " |
| 64 | << codec.simulcastStream[idx].targetBitrate |
| 65 | << ", max br " |
| 66 | << codec.simulcastStream[idx].maxBitrate |
| 67 | << ", qp max " |
| 68 | << codec.simulcastStream[idx].qpMax; |
| 69 | |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 75 | ViECodec* ViECodec::GetInterface(VideoEngine* video_engine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | #ifdef WEBRTC_VIDEO_ENGINE_CODEC_API |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 77 | if (!video_engine) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | return NULL; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 79 | } |
andrew@webrtc.org | d72262d | 2013-05-09 02:12:07 +0000 | [diff] [blame] | 80 | VideoEngineImpl* vie_impl = static_cast<VideoEngineImpl*>(video_engine); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 81 | ViECodecImpl* vie_codec_impl = vie_impl; |
| 82 | // Increase ref count. |
| 83 | (*vie_codec_impl)++; |
| 84 | return vie_codec_impl; |
| 85 | #else |
| 86 | return NULL; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | #endif |
| 88 | } |
| 89 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 90 | int ViECodecImpl::Release() { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 91 | LOG(LS_INFO) << "ViECodec::Release."; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 92 | // Decrease ref count. |
| 93 | (*this)--; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 95 | int32_t ref_count = GetCount(); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 96 | if (ref_count < 0) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 97 | LOG(LS_WARNING) << "ViECodec released too many times."; |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 98 | shared_data_->SetLastError(kViEAPIDoesNotExist); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 99 | return -1; |
| 100 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 101 | return ref_count; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | } |
| 103 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 104 | ViECodecImpl::ViECodecImpl(ViESharedData* shared_data) |
| 105 | : shared_data_(shared_data) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | } |
| 107 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 108 | ViECodecImpl::~ViECodecImpl() { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | } |
| 110 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 111 | int ViECodecImpl::NumberOfCodecs() const { |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 112 | // +2 because of FEC(RED and ULPFEC) |
| 113 | return static_cast<int>((VideoCodingModule::NumberOfCodecs() + 2)); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | } |
| 115 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 116 | int ViECodecImpl::GetCodec(const unsigned char list_number, |
| 117 | VideoCodec& video_codec) const { |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 118 | if (list_number == VideoCodingModule::NumberOfCodecs()) { |
| 119 | memset(&video_codec, 0, sizeof(VideoCodec)); |
mflodman@webrtc.org | aeff4f3 | 2013-04-22 12:41:57 +0000 | [diff] [blame] | 120 | strcpy(video_codec.plName, "red"); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 121 | video_codec.codecType = kVideoCodecRED; |
| 122 | video_codec.plType = VCM_RED_PAYLOAD_TYPE; |
| 123 | } else if (list_number == VideoCodingModule::NumberOfCodecs() + 1) { |
| 124 | memset(&video_codec, 0, sizeof(VideoCodec)); |
mflodman@webrtc.org | aeff4f3 | 2013-04-22 12:41:57 +0000 | [diff] [blame] | 125 | strcpy(video_codec.plName, "ulpfec"); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 126 | video_codec.codecType = kVideoCodecULPFEC; |
| 127 | video_codec.plType = VCM_ULPFEC_PAYLOAD_TYPE; |
| 128 | } else if (VideoCodingModule::Codec(list_number, &video_codec) != VCM_OK) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 129 | shared_data_->SetLastError(kViECodecInvalidArgument); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 130 | return -1; |
| 131 | } |
| 132 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 133 | } |
| 134 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 135 | int ViECodecImpl::SetSendCodec(const int video_channel, |
| 136 | const VideoCodec& video_codec) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 137 | LOG(LS_INFO) << "SetSendCodec for channel " << video_channel; |
| 138 | LogCodec(video_codec); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 139 | if (!CodecValid(video_codec)) { |
| 140 | // Error logged. |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 141 | shared_data_->SetLastError(kViECodecInvalidCodec); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 142 | return -1; |
| 143 | } |
stefan@webrtc.org | 791eec7 | 2011-10-11 07:53:43 +0000 | [diff] [blame] | 144 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 145 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 146 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 147 | if (!vie_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) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 155 | LOG_F(LS_ERROR) << "Receive only channel."; |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 156 | shared_data_->SetLastError(kViECodecReceiveOnlyChannel); |
| 157 | return -1; |
| 158 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 159 | // Set a max_bitrate if the user hasn't set one. |
| 160 | VideoCodec video_codec_internal; |
| 161 | memcpy(&video_codec_internal, &video_codec, sizeof(VideoCodec)); |
| 162 | if (video_codec_internal.maxBitrate == 0) { |
| 163 | // Max is one bit per pixel. |
| 164 | video_codec_internal.maxBitrate = (video_codec_internal.width * |
| 165 | video_codec_internal.height * |
| 166 | video_codec_internal.maxFramerate) |
| 167 | / 1000; |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 168 | LOG(LS_INFO) << "New max bitrate set " << video_codec_internal.maxBitrate; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 169 | } |
| 170 | |
mflodman@webrtc.org | 6031001 | 2013-12-20 15:07:12 +0000 | [diff] [blame] | 171 | if (video_codec_internal.startBitrate > video_codec_internal.maxBitrate) { |
| 172 | video_codec_internal.startBitrate = video_codec_internal.maxBitrate; |
| 173 | } |
| 174 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 175 | VideoCodec encoder; |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 176 | vie_encoder->GetEncoder(&encoder); |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 177 | |
mflodman@webrtc.org | 9c0aedc | 2012-01-03 13:46:49 +0000 | [diff] [blame] | 178 | // Make sure to generate a new SSRC if the codec type and/or resolution has |
| 179 | // changed. This won't have any effect if the user has set an SSRC. |
| 180 | bool new_rtp_stream = false; |
stefan@webrtc.org | 4e8eaba | 2012-08-20 14:29:52 +0000 | [diff] [blame] | 181 | if (encoder.codecType != video_codec_internal.codecType) { |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 182 | new_rtp_stream = true; |
| 183 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 184 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 185 | ViEInputManagerScoped is(*(shared_data_->input_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 186 | |
| 187 | // Stop the media flow while reconfiguring. |
| 188 | vie_encoder->Pause(); |
| 189 | |
mflodman@webrtc.org | 3ba883f | 2013-06-07 13:57:57 +0000 | [diff] [blame] | 190 | if (vie_encoder->SetEncoder(video_codec_internal) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 191 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 192 | return -1; |
| 193 | } |
| 194 | |
mflodman@webrtc.org | 9c0aedc | 2012-01-03 13:46:49 +0000 | [diff] [blame] | 195 | // Give the channel(s) the new information. |
| 196 | ChannelList channels; |
| 197 | cs.ChannelsUsingViEEncoder(video_channel, &channels); |
| 198 | for (ChannelList::iterator it = channels.begin(); it != channels.end(); |
| 199 | ++it) { |
| 200 | bool ret = true; |
| 201 | if ((*it)->SetSendCodec(video_codec_internal, new_rtp_stream) != 0) { |
mflodman@webrtc.org | 9c0aedc | 2012-01-03 13:46:49 +0000 | [diff] [blame] | 202 | ret = false; |
| 203 | } |
| 204 | if (!ret) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 205 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | 9c0aedc | 2012-01-03 13:46:49 +0000 | [diff] [blame] | 206 | return -1; |
| 207 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 208 | } |
| 209 | |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 210 | // TODO(mflodman) Break out this part in GetLocalSsrcList(). |
| 211 | // Update all SSRCs to ViEEncoder. |
| 212 | std::list<unsigned int> ssrcs; |
| 213 | if (video_codec_internal.numberOfSimulcastStreams == 0) { |
| 214 | unsigned int ssrc = 0; |
| 215 | if (vie_channel->GetLocalSSRC(0, &ssrc) != 0) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 216 | LOG_F(LS_ERROR) << "Could not get ssrc."; |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 217 | } |
| 218 | ssrcs.push_back(ssrc); |
| 219 | } else { |
| 220 | for (int idx = 0; idx < video_codec_internal.numberOfSimulcastStreams; |
| 221 | ++idx) { |
| 222 | unsigned int ssrc = 0; |
| 223 | if (vie_channel->GetLocalSSRC(idx, &ssrc) != 0) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 224 | LOG_F(LS_ERROR) << "Could not get ssrc for stream " << idx; |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 +0000 | [diff] [blame] | 225 | } |
| 226 | ssrcs.push_back(ssrc); |
| 227 | } |
| 228 | } |
| 229 | vie_encoder->SetSsrcs(ssrcs); |
| 230 | shared_data_->channel_manager()->UpdateSsrcs(video_channel, ssrcs); |
| 231 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 232 | // Update the protection mode, we might be switching NACK/FEC. |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 233 | vie_encoder->UpdateProtectionMethod(vie_encoder->nack_enabled()); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 234 | |
| 235 | // Get new best format for frame provider. |
pbos@webrtc.org | 735a7c8 | 2013-08-05 09:03:03 +0000 | [diff] [blame] | 236 | ViEFrameProviderBase* frame_provider = is.FrameProvider(vie_encoder); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 237 | if (frame_provider) { |
| 238 | frame_provider->FrameCallbackChanged(); |
| 239 | } |
| 240 | // Restart the media flow |
| 241 | if (new_rtp_stream) { |
| 242 | // Stream settings changed, make sure we get a key frame. |
| 243 | vie_encoder->SendKeyFrame(); |
| 244 | } |
| 245 | vie_encoder->Restart(); |
| 246 | return 0; |
stefan@webrtc.org | 791eec7 | 2011-10-11 07:53:43 +0000 | [diff] [blame] | 247 | } |
| 248 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 249 | int ViECodecImpl::GetSendCodec(const int video_channel, |
| 250 | VideoCodec& video_codec) const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 251 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 252 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 253 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 254 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 255 | return -1; |
| 256 | } |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 257 | return vie_encoder->GetEncoder(&video_codec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 258 | } |
| 259 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 260 | int ViECodecImpl::SetReceiveCodec(const int video_channel, |
| 261 | const VideoCodec& video_codec) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 262 | LOG(LS_INFO) << "SetReceiveCodec for channel " << video_channel; |
| 263 | LOG(LS_INFO) << "Codec type " << video_codec.codecType |
| 264 | << ", payload type " << video_codec.plType; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 265 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 266 | if (CodecValid(video_codec) == false) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 267 | shared_data_->SetLastError(kViECodecInvalidCodec); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 268 | return -1; |
| 269 | } |
| 270 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 271 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 272 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 273 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 274 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 275 | return -1; |
| 276 | } |
| 277 | |
| 278 | if (vie_channel->SetReceiveCodec(video_codec) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 279 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 280 | return -1; |
| 281 | } |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | int ViECodecImpl::GetReceiveCodec(const int video_channel, |
| 286 | VideoCodec& video_codec) const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 287 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 288 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 289 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 290 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 291 | return -1; |
| 292 | } |
| 293 | |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 294 | if (vie_channel->GetReceiveCodec(&video_codec) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 295 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 296 | return -1; |
| 297 | } |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | int ViECodecImpl::GetCodecConfigParameters( |
| 302 | const int video_channel, |
| 303 | unsigned char config_parameters[kConfigParameterSize], |
| 304 | unsigned char& config_parameters_size) const { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 305 | LOG(LS_INFO) << "GetCodecConfigParameters " << video_channel; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 306 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 307 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 308 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 309 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 310 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 311 | return -1; |
| 312 | } |
| 313 | |
| 314 | if (vie_encoder->GetCodecConfigParameters(config_parameters, |
| 315 | config_parameters_size) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 316 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 317 | return -1; |
| 318 | } |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | int ViECodecImpl::SetImageScaleStatus(const int video_channel, |
| 323 | const bool enable) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 324 | LOG(LS_INFO) << "SetImageScaleStates for channel " << video_channel |
| 325 | << ", enable: " << enable; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 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 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 329 | if (!vie_encoder) { |
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 | |
| 334 | if (vie_encoder->ScaleInputImage(enable) != 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::GetSendCodecStastistics(const int video_channel, |
| 342 | unsigned int& key_frames, |
| 343 | unsigned int& delta_frames) const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 344 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 345 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 346 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 347 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 348 | return -1; |
| 349 | } |
| 350 | |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 351 | if (vie_encoder->SendCodecStatistics(&key_frames, &delta_frames) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 352 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 353 | return -1; |
| 354 | } |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | int ViECodecImpl::GetReceiveCodecStastistics(const int video_channel, |
| 359 | unsigned int& key_frames, |
| 360 | unsigned int& delta_frames) const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 361 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 362 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 363 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 364 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 365 | return -1; |
| 366 | } |
mflodman@webrtc.org | f5e99db | 2012-06-27 09:49:37 +0000 | [diff] [blame] | 367 | if (vie_channel->ReceiveCodecStatistics(&key_frames, &delta_frames) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 368 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 369 | return -1; |
| 370 | } |
| 371 | return 0; |
| 372 | } |
| 373 | |
mflodman@webrtc.org | 4aee6b6 | 2012-12-14 14:02:10 +0000 | [diff] [blame] | 374 | int ViECodecImpl::GetReceiveSideDelay(const int video_channel, |
| 375 | int* delay_ms) const { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 376 | assert(delay_ms != NULL); |
mflodman@webrtc.org | 4aee6b6 | 2012-12-14 14:02:10 +0000 | [diff] [blame] | 377 | |
| 378 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 379 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 380 | if (!vie_channel) { |
mflodman@webrtc.org | 4aee6b6 | 2012-12-14 14:02:10 +0000 | [diff] [blame] | 381 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
| 382 | return -1; |
| 383 | } |
| 384 | *delay_ms = vie_channel->ReceiveDelay(); |
| 385 | if (*delay_ms < 0) { |
| 386 | return -1; |
| 387 | } |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 392 | int ViECodecImpl::GetCodecTargetBitrate(const int video_channel, |
| 393 | unsigned int* bitrate) const { |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 394 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 395 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 396 | if (!vie_encoder) { |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 397 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
| 398 | return -1; |
| 399 | } |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 400 | return vie_encoder->CodecTargetBitrate(static_cast<uint32_t*>(bitrate)); |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 401 | } |
| 402 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 403 | unsigned int ViECodecImpl::GetDiscardedPackets(const int video_channel) const { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 404 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 405 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 406 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 407 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 408 | return -1; |
| 409 | } |
| 410 | return vie_channel->DiscardedPackets(); |
| 411 | } |
| 412 | |
| 413 | int ViECodecImpl::SetKeyFrameRequestCallbackStatus(const int video_channel, |
| 414 | const bool enable) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 415 | LOG(LS_INFO) << "SetKeyFrameRequestCallbackStatus for " << video_channel |
| 416 | << ", enacle " << enable; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 417 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 418 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 419 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 420 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 421 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 422 | return -1; |
| 423 | } |
| 424 | if (vie_channel->EnableKeyFrameRequestCallback(enable) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 425 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 426 | return -1; |
| 427 | } |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | int ViECodecImpl::SetSignalKeyPacketLossStatus(const int video_channel, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 432 | const bool enable, |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 433 | const bool only_key_frames) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 434 | LOG(LS_INFO) << "SetSignalKeyPacketLossStatus for " << video_channel |
| 435 | << "enable, " << enable |
| 436 | << ", only key frames " << only_key_frames; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 437 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 438 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 439 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 440 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 441 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 442 | return -1; |
| 443 | } |
| 444 | if (vie_channel->SetSignalPacketLossStatus(enable, only_key_frames) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 445 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 446 | return -1; |
| 447 | } |
| 448 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 449 | } |
| 450 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 451 | int ViECodecImpl::RegisterEncoderObserver(const int video_channel, |
| 452 | ViEEncoderObserver& observer) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 453 | LOG(LS_INFO) << "RegisterEncoderObserver for channel " << video_channel; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 457 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 458 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 459 | return -1; |
| 460 | } |
| 461 | if (vie_encoder->RegisterCodecObserver(&observer) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 462 | shared_data_->SetLastError(kViECodecObserverAlreadyRegistered); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 463 | return -1; |
| 464 | } |
| 465 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 466 | } |
| 467 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 468 | int ViECodecImpl::DeregisterEncoderObserver(const int video_channel) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 469 | LOG(LS_INFO) << "DeregisterEncoderObserver for channel " << video_channel; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 470 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 471 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 472 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 473 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 474 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 475 | return -1; |
| 476 | } |
| 477 | if (vie_encoder->RegisterCodecObserver(NULL) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 478 | shared_data_->SetLastError(kViECodecObserverNotRegistered); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 479 | return -1; |
| 480 | } |
| 481 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 482 | } |
| 483 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 484 | int ViECodecImpl::RegisterDecoderObserver(const int video_channel, |
| 485 | ViEDecoderObserver& observer) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 486 | LOG(LS_INFO) << "RegisterDecoderObserver for channel " << video_channel; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 487 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 488 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 489 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 490 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 491 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 492 | return -1; |
| 493 | } |
| 494 | if (vie_channel->RegisterCodecObserver(&observer) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 495 | shared_data_->SetLastError(kViECodecObserverAlreadyRegistered); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 496 | return -1; |
| 497 | } |
| 498 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 499 | } |
| 500 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 501 | int ViECodecImpl::DeregisterDecoderObserver(const int video_channel) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 502 | LOG(LS_INFO) << "DeregisterDecodeObserver for channel " << video_channel; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 503 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 504 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 505 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 506 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 507 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 508 | return -1; |
| 509 | } |
| 510 | if (vie_channel->RegisterCodecObserver(NULL) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 511 | shared_data_->SetLastError(kViECodecObserverNotRegistered); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 512 | return -1; |
| 513 | } |
| 514 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 515 | } |
| 516 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 517 | int ViECodecImpl::SendKeyFrame(const int video_channel) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 518 | LOG(LS_INFO) << "SendKeyFrame on channel " << video_channel; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 519 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 520 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 521 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 522 | if (!vie_encoder) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 523 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 524 | return -1; |
| 525 | } |
| 526 | if (vie_encoder->SendKeyFrame() != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 527 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 528 | return -1; |
| 529 | } |
| 530 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 531 | } |
| 532 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 533 | int ViECodecImpl::WaitForFirstKeyFrame(const int video_channel, |
| 534 | const bool wait) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 535 | LOG(LS_INFO) << "WaitForFirstKeyFrame for channel " << video_channel |
| 536 | << ", wait " << wait; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 537 | |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 538 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 539 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 540 | if (!vie_channel) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 541 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 542 | return -1; |
| 543 | } |
| 544 | if (vie_channel->WaitForKeyFrame(wait) != 0) { |
mflodman@webrtc.org | b11424b | 2012-01-25 13:42:03 +0000 | [diff] [blame] | 545 | shared_data_->SetLastError(kViECodecUnknownError); |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 546 | return -1; |
| 547 | } |
| 548 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 549 | } |
| 550 | |
mflodman@webrtc.org | 1c986e7 | 2013-06-26 09:12:49 +0000 | [diff] [blame] | 551 | int ViECodecImpl::StartDebugRecording(int video_channel, |
| 552 | const char* file_name_utf8) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 553 | LOG(LS_INFO) << "StartDebugRecording for channel " << video_channel; |
mflodman@webrtc.org | 1c986e7 | 2013-06-26 09:12:49 +0000 | [diff] [blame] | 554 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 555 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 556 | if (!vie_encoder) { |
mflodman@webrtc.org | 1c986e7 | 2013-06-26 09:12:49 +0000 | [diff] [blame] | 557 | return -1; |
| 558 | } |
| 559 | return vie_encoder->StartDebugRecording(file_name_utf8); |
| 560 | } |
| 561 | |
| 562 | int ViECodecImpl::StopDebugRecording(int video_channel) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 563 | LOG(LS_INFO) << "StopDebugRecording for channel " << video_channel; |
mflodman@webrtc.org | 1c986e7 | 2013-06-26 09:12:49 +0000 | [diff] [blame] | 564 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 565 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 566 | if (!vie_encoder) { |
mflodman@webrtc.org | 1c986e7 | 2013-06-26 09:12:49 +0000 | [diff] [blame] | 567 | return -1; |
| 568 | } |
| 569 | return vie_encoder->StopDebugRecording(); |
| 570 | } |
| 571 | |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 572 | void ViECodecImpl::SuspendBelowMinBitrate(int video_channel) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 573 | LOG(LS_INFO) << "SuspendBelowMinBitrate for channel " << video_channel; |
henrik.lundin@webrtc.org | 7ea4f24 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 574 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 575 | ViEEncoder* vie_encoder = cs.Encoder(video_channel); |
| 576 | if (!vie_encoder) { |
henrik.lundin@webrtc.org | 7ea4f24 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 577 | return; |
| 578 | } |
henrik.lundin@webrtc.org | 331d440 | 2013-11-21 14:05:40 +0000 | [diff] [blame] | 579 | vie_encoder->SuspendBelowMinBitrate(); |
| 580 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 581 | if (!vie_channel) { |
henrik.lundin@webrtc.org | 331d440 | 2013-11-21 14:05:40 +0000 | [diff] [blame] | 582 | return; |
| 583 | } |
| 584 | // Must enable pacing when enabling SuspendBelowMinBitrate. Otherwise, no |
| 585 | // padding will be sent when the video is suspended so the video will be |
| 586 | // unable to recover. |
| 587 | vie_channel->SetTransmissionSmoothingStatus(true); |
henrik.lundin@webrtc.org | 7ea4f24 | 2013-10-02 13:34:26 +0000 | [diff] [blame] | 588 | } |
| 589 | |
stefan@webrtc.org | 0a3c147 | 2013-12-05 14:05:07 +0000 | [diff] [blame] | 590 | bool ViECodecImpl::GetSendSideDelay(int video_channel, int* avg_delay_ms, |
| 591 | int* max_delay_ms) const { |
| 592 | ViEChannelManagerScoped cs(*(shared_data_->channel_manager())); |
| 593 | ViEChannel* vie_channel = cs.Channel(video_channel); |
| 594 | if (!vie_channel) { |
stefan@webrtc.org | 0a3c147 | 2013-12-05 14:05:07 +0000 | [diff] [blame] | 595 | shared_data_->SetLastError(kViECodecInvalidChannelId); |
| 596 | return false; |
| 597 | } |
| 598 | return vie_channel->GetSendSideDelay(avg_delay_ms, max_delay_ms); |
| 599 | } |
| 600 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 601 | bool ViECodecImpl::CodecValid(const VideoCodec& video_codec) { |
| 602 | // Check pl_name matches codec_type. |
| 603 | if (video_codec.codecType == kVideoCodecRED) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 604 | #if defined(WIN32) |
mflodman@webrtc.org | 1fe2ada | 2011-12-21 12:23:15 +0000 | [diff] [blame] | 605 | if (_strnicmp(video_codec.plName, "red", 3) == 0) { |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 606 | #else |
| 607 | if (strncasecmp(video_codec.plName, "red", 3) == 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 608 | #endif |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 609 | // We only care about the type and name for red. |
| 610 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 611 | } |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 612 | LOG_F(LS_ERROR) << "Invalid RED configuration."; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 613 | return false; |
| 614 | } else if (video_codec.codecType == kVideoCodecULPFEC) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 615 | #if defined(WIN32) |
mflodman@webrtc.org | 1fe2ada | 2011-12-21 12:23:15 +0000 | [diff] [blame] | 616 | if (_strnicmp(video_codec.plName, "ULPFEC", 6) == 0) { |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 617 | #else |
| 618 | if (strncasecmp(video_codec.plName, "ULPFEC", 6) == 0) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 619 | #endif |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 620 | // We only care about the type and name for ULPFEC. |
| 621 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 622 | } |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 623 | LOG_F(LS_ERROR) << "Invalid ULPFEC configuration."; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 624 | return false; |
pwestin@webrtc.org | 5621057 | 2012-01-17 12:45:47 +0000 | [diff] [blame] | 625 | } else if ((video_codec.codecType == kVideoCodecVP8 && |
pbos@webrtc.org | 8911ce4 | 2013-03-18 16:39:03 +0000 | [diff] [blame] | 626 | strncmp(video_codec.plName, "VP8", 4) == 0) || |
| 627 | (video_codec.codecType == kVideoCodecI420 && |
pbos@webrtc.org | b5bf54c | 2013-04-05 13:27:38 +0000 | [diff] [blame] | 628 | strncmp(video_codec.plName, "I420", 4) == 0)) { |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 629 | // OK. |
pbos@webrtc.org | b5bf54c | 2013-04-05 13:27:38 +0000 | [diff] [blame] | 630 | } else if (video_codec.codecType != kVideoCodecGeneric) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 631 | LOG(LS_ERROR) << "Codec type and name mismatch."; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 632 | return false; |
| 633 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 634 | |
braveyao@webrtc.org | 49273ff | 2013-01-14 01:52:26 +0000 | [diff] [blame] | 635 | if (video_codec.plType == 0 || video_codec.plType > 127) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 636 | LOG(LS_ERROR) << "Invalif payload type: " << video_codec.plType; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 637 | return false; |
| 638 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 639 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 640 | if (video_codec.width > kViEMaxCodecWidth || |
| 641 | video_codec.height > kViEMaxCodecHeight) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 642 | LOG(LS_ERROR) << "Invalid codec resolution " << video_codec.width |
| 643 | << " x " << video_codec.height; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 644 | return false; |
| 645 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 646 | |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 647 | if (video_codec.startBitrate < kViEMinCodecBitrate) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 648 | LOG(LS_ERROR) << "Invalid start bitrate."; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 649 | return false; |
| 650 | } |
| 651 | if (video_codec.minBitrate < kViEMinCodecBitrate) { |
mflodman@webrtc.org | 5574dac | 2014-04-07 10:56:31 +0000 | [diff] [blame] | 652 | LOG(LS_ERROR) << "Invalid min bitrate."; |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 653 | return false; |
| 654 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 655 | return true; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 656 | } |
mflodman@webrtc.org | c12686c | 2011-12-21 09:29:28 +0000 | [diff] [blame] | 657 | |
| 658 | } // namespace webrtc |