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