| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 const uint32_t height); | 50 const uint32_t height); |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 VideoProcessing* vp_; | 53 VideoProcessing* vp_; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 56 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
| 57 const std::vector<uint32_t>& ssrcs, | 57 const std::vector<uint32_t>& ssrcs, |
| 58 ProcessThread* module_process_thread, | 58 ProcessThread* module_process_thread, |
| 59 SendStatisticsProxy* stats_proxy, | 59 SendStatisticsProxy* stats_proxy, |
| 60 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 60 OveruseFrameDetector* overuse_detector) |
| 61 OveruseFrameDetector* overuse_detector, | |
| 62 PacedSender* pacer) | |
| 63 : number_of_cores_(number_of_cores), | 61 : number_of_cores_(number_of_cores), |
| 64 ssrcs_(ssrcs), | 62 ssrcs_(ssrcs), |
| 65 vp_(VideoProcessing::Create()), | 63 vp_(VideoProcessing::Create()), |
| 66 qm_callback_(new QMVideoSettingsCallback(vp_.get())), | 64 qm_callback_(new QMVideoSettingsCallback(vp_.get())), |
| 67 video_sender_(Clock::GetRealTimeClock(), this, this, qm_callback_.get()), | 65 video_sender_(Clock::GetRealTimeClock(), this, this, qm_callback_.get()), |
| 68 stats_proxy_(stats_proxy), | 66 stats_proxy_(stats_proxy), |
| 69 pre_encode_callback_(pre_encode_callback), | |
| 70 overuse_detector_(overuse_detector), | 67 overuse_detector_(overuse_detector), |
| 71 pacer_(pacer), | |
| 72 time_of_last_frame_activity_ms_(0), | 68 time_of_last_frame_activity_ms_(0), |
| 73 encoder_config_(), | 69 encoder_config_(), |
| 74 min_transmit_bitrate_bps_(0), | 70 min_transmit_bitrate_bps_(0), |
| 75 last_observed_bitrate_bps_(0), | 71 last_observed_bitrate_bps_(0), |
| 76 network_is_transmitting_(true), | 72 network_is_transmitting_(true), |
| 77 encoder_paused_(true), | 73 encoder_paused_(true), |
| 78 encoder_paused_and_dropped_frame_(false), | 74 encoder_paused_and_dropped_frame_(false), |
| 79 time_last_intra_request_ms_(ssrcs.size(), -1), | 75 time_last_intra_request_ms_(ssrcs.size(), -1), |
| 80 module_process_thread_(module_process_thread), | 76 module_process_thread_(module_process_thread), |
| 81 has_received_sli_(false), | 77 has_received_sli_(false), |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 243 |
| 248 return pad_up_to_bitrate_bps; | 244 return pad_up_to_bitrate_bps; |
| 249 } | 245 } |
| 250 | 246 |
| 251 bool ViEEncoder::EncoderPaused() const { | 247 bool ViEEncoder::EncoderPaused() const { |
| 252 // Pause video if paused by caller or as long as the network is down or the | 248 // Pause video if paused by caller or as long as the network is down or the |
| 253 // pacer queue has grown too large in buffered mode. | 249 // pacer queue has grown too large in buffered mode. |
| 254 if (encoder_paused_) { | 250 if (encoder_paused_) { |
| 255 return true; | 251 return true; |
| 256 } | 252 } |
| 257 if (pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs) { | 253 if (video_suspended_ || last_observed_bitrate_bps_ == 0) { |
| 258 // Too much data in pacer queue, drop frame. | |
| 259 return true; | 254 return true; |
| 260 } | 255 } |
| 261 return !network_is_transmitting_; | 256 return !network_is_transmitting_; |
| 262 } | 257 } |
| 263 | 258 |
| 264 void ViEEncoder::TraceFrameDropStart() { | 259 void ViEEncoder::TraceFrameDropStart() { |
| 265 // Start trace event only on the first frame after encoder is paused. | 260 // Start trace event only on the first frame after encoder is paused. |
| 266 if (!encoder_paused_and_dropped_frame_) { | 261 if (!encoder_paused_and_dropped_frame_) { |
| 267 TRACE_EVENT_ASYNC_BEGIN0("webrtc", "EncoderPaused", this); | 262 TRACE_EVENT_ASYNC_BEGIN0("webrtc", "EncoderPaused", this); |
| 268 } | 263 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 297 // TODO(wuchengli): support texture frames. | 292 // TODO(wuchengli): support texture frames. |
| 298 if (!video_frame.video_frame_buffer()->native_handle()) { | 293 if (!video_frame.video_frame_buffer()->native_handle()) { |
| 299 // Pass frame via preprocessor. | 294 // Pass frame via preprocessor. |
| 300 frame_to_send = vp_->PreprocessFrame(video_frame); | 295 frame_to_send = vp_->PreprocessFrame(video_frame); |
| 301 if (!frame_to_send) { | 296 if (!frame_to_send) { |
| 302 // Drop this frame, or there was an error processing it. | 297 // Drop this frame, or there was an error processing it. |
| 303 return; | 298 return; |
| 304 } | 299 } |
| 305 } | 300 } |
| 306 | 301 |
| 307 if (pre_encode_callback_) { | |
| 308 pre_encode_callback_->OnFrame(*frame_to_send); | |
| 309 } | |
| 310 | |
| 311 if (codec_type == webrtc::kVideoCodecVP8) { | 302 if (codec_type == webrtc::kVideoCodecVP8) { |
| 312 webrtc::CodecSpecificInfo codec_specific_info; | 303 webrtc::CodecSpecificInfo codec_specific_info; |
| 313 codec_specific_info.codecType = webrtc::kVideoCodecVP8; | 304 codec_specific_info.codecType = webrtc::kVideoCodecVP8; |
| 314 { | 305 { |
| 315 rtc::CritScope lock(&data_cs_); | 306 rtc::CritScope lock(&data_cs_); |
| 316 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = | 307 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = |
| 317 has_received_rpsi_; | 308 has_received_rpsi_; |
| 318 codec_specific_info.codecSpecific.VP8.hasReceivedSLI = | 309 codec_specific_info.codecSpecific.VP8.hasReceivedSLI = |
| 319 has_received_sli_; | 310 has_received_sli_; |
| 320 codec_specific_info.codecSpecific.VP8.pictureIdRPSI = | 311 codec_specific_info.codecSpecific.VP8.pictureIdRPSI = |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 } | 433 } |
| 443 video_sender_.IntraFrameRequest(static_cast<int>(i)); | 434 video_sender_.IntraFrameRequest(static_cast<int>(i)); |
| 444 return; | 435 return; |
| 445 } | 436 } |
| 446 RTC_NOTREACHED() << "Should not receive keyframe requests on unknown SSRCs."; | 437 RTC_NOTREACHED() << "Should not receive keyframe requests on unknown SSRCs."; |
| 447 } | 438 } |
| 448 | 439 |
| 449 void ViEEncoder::OnBitrateUpdated(uint32_t bitrate_bps, | 440 void ViEEncoder::OnBitrateUpdated(uint32_t bitrate_bps, |
| 450 uint8_t fraction_lost, | 441 uint8_t fraction_lost, |
| 451 int64_t round_trip_time_ms) { | 442 int64_t round_trip_time_ms) { |
| 452 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate" << bitrate_bps | 443 LOG(LS_VERBOSE) << "OnBitrateUpdated, bitrate " << bitrate_bps |
| 453 << " packet loss " << static_cast<int>(fraction_lost) | 444 << " packet loss " << static_cast<int>(fraction_lost) |
| 454 << " rtt " << round_trip_time_ms; | 445 << " rtt " << round_trip_time_ms; |
| 455 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, | 446 video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, |
| 456 round_trip_time_ms); | 447 round_trip_time_ms); |
| 457 bool video_is_suspended = video_sender_.VideoSuspended(); | 448 bool video_is_suspended = video_sender_.VideoSuspended(); |
| 458 bool video_suspension_changed; | 449 bool video_suspension_changed; |
| 459 { | 450 { |
| 460 rtc::CritScope lock(&data_cs_); | 451 rtc::CritScope lock(&data_cs_); |
| 461 last_observed_bitrate_bps_ = bitrate_bps; | 452 last_observed_bitrate_bps_ = bitrate_bps; |
| 462 video_suspension_changed = video_suspended_ != video_is_suspended; | 453 video_suspension_changed = video_suspended_ != video_is_suspended; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 480 } | 471 } |
| 481 | 472 |
| 482 int32_t QMVideoSettingsCallback::SetVideoQMSettings( | 473 int32_t QMVideoSettingsCallback::SetVideoQMSettings( |
| 483 const uint32_t frame_rate, | 474 const uint32_t frame_rate, |
| 484 const uint32_t width, | 475 const uint32_t width, |
| 485 const uint32_t height) { | 476 const uint32_t height) { |
| 486 return vp_->SetTargetResolution(width, height, frame_rate); | 477 return vp_->SetTargetResolution(width, height, frame_rate); |
| 487 } | 478 } |
| 488 | 479 |
| 489 } // namespace webrtc | 480 } // namespace webrtc |
| OLD | NEW |