| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 } | 99 } |
| 100 private: | 100 private: |
| 101 ViEEncoder* owner_; | 101 ViEEncoder* owner_; |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 ViEEncoder::ViEEncoder(int32_t channel_id, | 104 ViEEncoder::ViEEncoder(int32_t channel_id, |
| 105 uint32_t number_of_cores, | 105 uint32_t number_of_cores, |
| 106 ProcessThread& module_process_thread, | 106 ProcessThread& module_process_thread, |
| 107 PacedSender* pacer, | 107 PacedSender* pacer, |
| 108 BitrateAllocator* bitrate_allocator, | 108 BitrateAllocator* bitrate_allocator, |
| 109 BitrateController* bitrate_controller, | 109 BitrateController* bitrate_controller) |
| 110 bool disable_default_encoder) | |
| 111 : channel_id_(channel_id), | 110 : channel_id_(channel_id), |
| 112 number_of_cores_(number_of_cores), | 111 number_of_cores_(number_of_cores), |
| 113 disable_default_encoder_(disable_default_encoder), | |
| 114 vpm_(VideoProcessingModule::Create(ViEModuleId(-1, channel_id))), | 112 vpm_(VideoProcessingModule::Create(ViEModuleId(-1, channel_id))), |
| 115 qm_callback_(new QMVideoSettingsCallback(vpm_.get())), | 113 qm_callback_(new QMVideoSettingsCallback(vpm_.get())), |
| 116 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), | 114 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), |
| 117 this, | 115 this, |
| 118 qm_callback_.get())), | 116 qm_callback_.get())), |
| 119 send_payload_router_(NULL), | 117 send_payload_router_(NULL), |
| 120 callback_cs_(CriticalSectionWrapper::CreateCriticalSection()), | 118 callback_cs_(CriticalSectionWrapper::CreateCriticalSection()), |
| 121 data_cs_(CriticalSectionWrapper::CreateCriticalSection()), | 119 data_cs_(CriticalSectionWrapper::CreateCriticalSection()), |
| 122 pacer_(pacer), | 120 pacer_(pacer), |
| 123 bitrate_allocator_(bitrate_allocator), | 121 bitrate_allocator_(bitrate_allocator), |
| 124 bitrate_controller_(bitrate_controller), | 122 bitrate_controller_(bitrate_controller), |
| 125 time_of_last_frame_activity_ms_(0), | 123 time_of_last_frame_activity_ms_(0), |
| 126 send_padding_(false), | 124 simulcast_enabled_(false), |
| 127 min_transmit_bitrate_kbps_(0), | 125 min_transmit_bitrate_kbps_(0), |
| 128 last_observed_bitrate_bps_(0), | 126 last_observed_bitrate_bps_(0), |
| 129 target_delay_ms_(0), | 127 target_delay_ms_(0), |
| 130 network_is_transmitting_(true), | 128 network_is_transmitting_(true), |
| 131 encoder_paused_(false), | 129 encoder_paused_(false), |
| 132 encoder_paused_and_dropped_frame_(false), | 130 encoder_paused_and_dropped_frame_(false), |
| 133 fec_enabled_(false), | 131 fec_enabled_(false), |
| 134 nack_enabled_(false), | 132 nack_enabled_(false), |
| 135 codec_observer_(NULL), | 133 codec_observer_(NULL), |
| 136 module_process_thread_(module_process_thread), | 134 module_process_thread_(module_process_thread), |
| 137 has_received_sli_(false), | 135 has_received_sli_(false), |
| 138 picture_id_sli_(0), | 136 picture_id_sli_(0), |
| 139 has_received_rpsi_(false), | 137 has_received_rpsi_(false), |
| 140 picture_id_rpsi_(0), | 138 picture_id_rpsi_(0), |
| 141 video_suspended_(false), | 139 video_suspended_(false), |
| 142 pre_encode_callback_(NULL), | 140 pre_encode_callback_(NULL), |
| 143 start_ms_(Clock::GetRealTimeClock()->TimeInMilliseconds()), | 141 start_ms_(Clock::GetRealTimeClock()->TimeInMilliseconds()), |
| 144 send_statistics_proxy_(NULL) { | 142 send_statistics_proxy_(NULL) { |
| 145 bitrate_observer_.reset(new ViEBitrateObserver(this)); | 143 bitrate_observer_.reset(new ViEBitrateObserver(this)); |
| 146 } | 144 } |
| 147 | 145 |
| 148 bool ViEEncoder::Init() { | 146 bool ViEEncoder::Init() { |
| 149 vpm_->EnableTemporalDecimation(true); | 147 vpm_->EnableTemporalDecimation(true); |
| 150 | 148 |
| 151 // Enable/disable content analysis: off by default for now. | 149 // Enable/disable content analysis: off by default for now. |
| 152 vpm_->EnableContentAnalysis(false); | 150 vpm_->EnableContentAnalysis(false); |
| 153 | 151 |
| 154 if (!disable_default_encoder_) { | |
| 155 #ifdef VIDEOCODEC_VP8 | |
| 156 VideoCodecType codec_type = webrtc::kVideoCodecVP8; | |
| 157 #else | |
| 158 VideoCodecType codec_type = webrtc::kVideoCodecI420; | |
| 159 #endif | |
| 160 VideoCodec video_codec; | |
| 161 if (vcm_->Codec(codec_type, &video_codec) != VCM_OK) { | |
| 162 return false; | |
| 163 } | |
| 164 { | |
| 165 CriticalSectionScoped cs(data_cs_.get()); | |
| 166 send_padding_ = video_codec.numberOfSimulcastStreams > 1; | |
| 167 } | |
| 168 if (vcm_->RegisterSendCodec( | |
| 169 &video_codec, number_of_cores_, | |
| 170 static_cast<uint32_t>(PayloadRouter::DefaultMaxPayloadLength())) != | |
| 171 0) { | |
| 172 return false; | |
| 173 } | |
| 174 } | |
| 175 if (vcm_->RegisterTransportCallback(this) != 0) { | 152 if (vcm_->RegisterTransportCallback(this) != 0) { |
| 176 return false; | 153 return false; |
| 177 } | 154 } |
| 178 if (vcm_->RegisterSendStatisticsCallback(this) != 0) { | 155 if (vcm_->RegisterSendStatisticsCallback(this) != 0) { |
| 179 return false; | 156 return false; |
| 180 } | 157 } |
| 181 return true; | 158 return true; |
| 182 } | 159 } |
| 183 | 160 |
| 184 void ViEEncoder::StartThreadsAndSetSharedMembers( | 161 void ViEEncoder::StartThreadsAndSetSharedMembers( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 return -1; | 241 return -1; |
| 265 | 242 |
| 266 if (vcm_->RegisterExternalEncoder(encoder, pl_type, internal_source) != | 243 if (vcm_->RegisterExternalEncoder(encoder, pl_type, internal_source) != |
| 267 VCM_OK) { | 244 VCM_OK) { |
| 268 return -1; | 245 return -1; |
| 269 } | 246 } |
| 270 return 0; | 247 return 0; |
| 271 } | 248 } |
| 272 | 249 |
| 273 int32_t ViEEncoder::DeRegisterExternalEncoder(uint8_t pl_type) { | 250 int32_t ViEEncoder::DeRegisterExternalEncoder(uint8_t pl_type) { |
| 274 DCHECK(send_payload_router_ != NULL); | |
| 275 webrtc::VideoCodec current_send_codec; | |
| 276 if (vcm_->SendCodec(¤t_send_codec) == VCM_OK) { | |
| 277 uint32_t current_bitrate_bps = 0; | |
| 278 if (vcm_->Bitrate(¤t_bitrate_bps) != 0) { | |
| 279 LOG(LS_WARNING) << "Failed to get the current encoder target bitrate."; | |
| 280 } | |
| 281 current_send_codec.startBitrate = (current_bitrate_bps + 500) / 1000; | |
| 282 } | |
| 283 | |
| 284 if (vcm_->RegisterExternalEncoder(NULL, pl_type) != VCM_OK) { | 251 if (vcm_->RegisterExternalEncoder(NULL, pl_type) != VCM_OK) { |
| 285 return -1; | 252 return -1; |
| 286 } | 253 } |
| 287 | |
| 288 if (disable_default_encoder_) | |
| 289 return 0; | |
| 290 | |
| 291 // If the external encoder is the current send codec, use vcm internal | |
| 292 // encoder. | |
| 293 if (current_send_codec.plType == pl_type) { | |
| 294 { | |
| 295 CriticalSectionScoped cs(data_cs_.get()); | |
| 296 send_padding_ = current_send_codec.numberOfSimulcastStreams > 1; | |
| 297 } | |
| 298 // TODO(mflodman): Unfortunately the VideoCodec that VCM has cached a | |
| 299 // raw pointer to an |extra_options| that's long gone. Clearing it here is | |
| 300 // a hack to prevent the following code from crashing. This should be fixed | |
| 301 // for realz. https://code.google.com/p/chromium/issues/detail?id=348222 | |
| 302 current_send_codec.extra_options = NULL; | |
| 303 size_t max_data_payload_length = send_payload_router_->MaxPayloadLength(); | |
| 304 if (vcm_->RegisterSendCodec( | |
| 305 ¤t_send_codec, number_of_cores_, | |
| 306 static_cast<uint32_t>(max_data_payload_length)) != VCM_OK) { | |
| 307 LOG(LS_INFO) << "De-registered the currently used external encoder (" | |
| 308 << static_cast<int>(pl_type) << ") and therefore tried to " | |
| 309 << "register the corresponding internal encoder, but none " | |
| 310 << "was supported."; | |
| 311 } | |
| 312 } | |
| 313 return 0; | 254 return 0; |
| 314 } | 255 } |
| 315 | 256 |
| 316 int32_t ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec) { | 257 int32_t ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec) { |
| 317 DCHECK(send_payload_router_ != NULL); | 258 DCHECK(send_payload_router_ != NULL); |
| 318 // Setting target width and height for VPM. | 259 // Setting target width and height for VPM. |
| 319 if (vpm_->SetTargetResolution(video_codec.width, video_codec.height, | 260 if (vpm_->SetTargetResolution(video_codec.width, video_codec.height, |
| 320 video_codec.maxFramerate) != VPM_OK) { | 261 video_codec.maxFramerate) != VPM_OK) { |
| 321 return -1; | 262 return -1; |
| 322 } | 263 } |
| 323 | 264 |
| 324 { | 265 { |
| 325 CriticalSectionScoped cs(data_cs_.get()); | 266 CriticalSectionScoped cs(data_cs_.get()); |
| 326 send_padding_ = video_codec.numberOfSimulcastStreams > 1; | 267 simulcast_enabled_ = video_codec.numberOfSimulcastStreams > 1; |
| 327 } | 268 } |
| 328 | 269 |
| 329 // Add a bitrate observer to the allocator and update the start, max and | 270 // Add a bitrate observer to the allocator and update the start, max and |
| 330 // min bitrates of the bitrate controller as needed. | 271 // min bitrates of the bitrate controller as needed. |
| 331 int allocated_bitrate_bps; | 272 int allocated_bitrate_bps; |
| 332 int new_bwe_candidate_bps = bitrate_allocator_->AddBitrateObserver( | 273 int new_bwe_candidate_bps = bitrate_allocator_->AddBitrateObserver( |
| 333 bitrate_observer_.get(), video_codec.startBitrate * 1000, | 274 bitrate_observer_.get(), video_codec.startBitrate * 1000, |
| 334 video_codec.minBitrate * 1000, video_codec.maxBitrate * 1000, | 275 video_codec.minBitrate * 1000, video_codec.maxBitrate * 1000, |
| 335 &allocated_bitrate_bps); | 276 &allocated_bitrate_bps); |
| 336 | 277 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 336 |
| 396 return 0; | 337 return 0; |
| 397 } | 338 } |
| 398 | 339 |
| 399 int ViEEncoder::GetPaddingNeededBps() const { | 340 int ViEEncoder::GetPaddingNeededBps() const { |
| 400 int64_t time_of_last_frame_activity_ms; | 341 int64_t time_of_last_frame_activity_ms; |
| 401 int min_transmit_bitrate_bps; | 342 int min_transmit_bitrate_bps; |
| 402 int bitrate_bps; | 343 int bitrate_bps; |
| 403 { | 344 { |
| 404 CriticalSectionScoped cs(data_cs_.get()); | 345 CriticalSectionScoped cs(data_cs_.get()); |
| 405 bool send_padding = | 346 bool send_padding = simulcast_enabled_ || video_suspended_ || |
| 406 send_padding_ || video_suspended_ || min_transmit_bitrate_kbps_ > 0; | 347 min_transmit_bitrate_kbps_ > 0; |
| 407 if (!send_padding) | 348 if (!send_padding) |
| 408 return 0; | 349 return 0; |
| 409 time_of_last_frame_activity_ms = time_of_last_frame_activity_ms_; | 350 time_of_last_frame_activity_ms = time_of_last_frame_activity_ms_; |
| 410 min_transmit_bitrate_bps = 1000 * min_transmit_bitrate_kbps_; | 351 min_transmit_bitrate_bps = 1000 * min_transmit_bitrate_kbps_; |
| 411 bitrate_bps = last_observed_bitrate_bps_; | 352 bitrate_bps = last_observed_bitrate_bps_; |
| 412 } | 353 } |
| 413 | 354 |
| 414 VideoCodec send_codec; | 355 VideoCodec send_codec; |
| 415 if (vcm_->SendCodec(&send_codec) != 0) | 356 if (vcm_->SendCodec(&send_codec) != 0) |
| 416 return 0; | 357 return 0; |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 const uint32_t width, | 809 const uint32_t width, |
| 869 const uint32_t height) { | 810 const uint32_t height) { |
| 870 return vpm_->SetTargetResolution(width, height, frame_rate); | 811 return vpm_->SetTargetResolution(width, height, frame_rate); |
| 871 } | 812 } |
| 872 | 813 |
| 873 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { | 814 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { |
| 874 vpm_->SetTargetFramerate(frame_rate); | 815 vpm_->SetTargetFramerate(frame_rate); |
| 875 } | 816 } |
| 876 | 817 |
| 877 } // namespace webrtc | 818 } // namespace webrtc |
| OLD | NEW |