Chromium Code Reviews| Index: webrtc/video/vie_encoder.cc |
| diff --git a/webrtc/video/vie_encoder.cc b/webrtc/video/vie_encoder.cc |
| index 73b29f319e03484081c37e59448f3fde8d2ea431..558426fc994b2d60582223c7ae7b35dc56ac3f12 100644 |
| --- a/webrtc/video/vie_encoder.cc |
| +++ b/webrtc/video/vie_encoder.cc |
| @@ -28,13 +28,11 @@ |
| namespace webrtc { |
| -static const float kStopPaddingThresholdMs = 2000; |
| - |
| ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
| ProcessThread* module_process_thread, |
| SendStatisticsProxy* stats_proxy, |
| OveruseFrameDetector* overuse_detector, |
| - EncodedImageCallback* sink) |
| + VideoEncoderSink* sink) |
| : number_of_cores_(number_of_cores), |
| sink_(sink), |
| vp_(VideoProcessing::Create()), |
| @@ -43,10 +41,10 @@ ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
| overuse_detector_(overuse_detector), |
| time_of_last_frame_activity_ms_(0), |
| encoder_config_(), |
| - min_transmit_bitrate_bps_(0), |
| last_observed_bitrate_bps_(0), |
| encoder_paused_(true), |
| encoder_paused_and_dropped_frame_(false), |
| + reported_timeout_(false), |
| module_process_thread_(module_process_thread), |
| has_received_sli_(false), |
| picture_id_sli_(0), |
| @@ -88,7 +86,6 @@ int32_t ViEEncoder::DeRegisterExternalEncoder(uint8_t pl_type) { |
| } |
| void ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec, |
| - int min_transmit_bitrate_bps, |
| size_t max_data_payload_length) { |
| // Setting target width and height for VPM. |
| RTC_CHECK_EQ(VPM_OK, |
| @@ -100,7 +97,6 @@ void ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec, |
| { |
| rtc::CritScope lock(&data_cs_); |
| encoder_config_ = video_codec; |
| - min_transmit_bitrate_bps_ = min_transmit_bitrate_bps; |
| } |
| bool success = video_sender_.RegisterSendCodec( |
| @@ -129,63 +125,6 @@ void ViEEncoder::SetEncoder(const webrtc::VideoCodec& video_codec, |
| } |
| } |
| -int ViEEncoder::GetPaddingNeededBps() const { |
| - int64_t time_of_last_frame_activity_ms; |
| - int min_transmit_bitrate_bps; |
| - int bitrate_bps; |
| - VideoCodec send_codec; |
| - { |
| - rtc::CritScope lock(&data_cs_); |
| - bool send_padding = encoder_config_.numberOfSimulcastStreams > 1 || |
| - video_suspended_ || min_transmit_bitrate_bps_ > 0; |
| - if (!send_padding) |
| - return 0; |
| - time_of_last_frame_activity_ms = time_of_last_frame_activity_ms_; |
| - min_transmit_bitrate_bps = min_transmit_bitrate_bps_; |
| - bitrate_bps = last_observed_bitrate_bps_; |
| - send_codec = encoder_config_; |
| - } |
| - |
| - bool video_is_suspended = video_sender_.VideoSuspended(); |
| - |
| - // Find the max amount of padding we can allow ourselves to send at this |
| - // point, based on which streams are currently active and what our current |
| - // available bandwidth is. |
| - int pad_up_to_bitrate_bps = 0; |
| - if (send_codec.numberOfSimulcastStreams == 0) { |
| - pad_up_to_bitrate_bps = send_codec.minBitrate * 1000; |
| - } else { |
| - SimulcastStream* stream_configs = send_codec.simulcastStream; |
| - pad_up_to_bitrate_bps = |
| - stream_configs[send_codec.numberOfSimulcastStreams - 1].minBitrate * |
| - 1000; |
| - for (int i = 0; i < send_codec.numberOfSimulcastStreams - 1; ++i) { |
| - pad_up_to_bitrate_bps += stream_configs[i].targetBitrate * 1000; |
| - } |
| - } |
| - |
| - // Disable padding if only sending one stream and video isn't suspended and |
| - // min-transmit bitrate isn't used (applied later). |
| - if (!video_is_suspended && send_codec.numberOfSimulcastStreams <= 1) |
| - pad_up_to_bitrate_bps = 0; |
| - |
| - // The amount of padding should decay to zero if no frames are being |
| - // captured/encoded unless a min-transmit bitrate is used. |
| - int64_t now_ms = rtc::TimeMillis(); |
| - if (now_ms - time_of_last_frame_activity_ms > kStopPaddingThresholdMs) |
| - pad_up_to_bitrate_bps = 0; |
| - |
| - // Pad up to min bitrate. |
| - if (pad_up_to_bitrate_bps < min_transmit_bitrate_bps) |
| - pad_up_to_bitrate_bps = min_transmit_bitrate_bps; |
| - |
| - // Padding may never exceed bitrate estimate. |
| - if (pad_up_to_bitrate_bps > bitrate_bps) |
| - pad_up_to_bitrate_bps = bitrate_bps; |
| - |
| - return pad_up_to_bitrate_bps; |
| -} |
| - |
| bool ViEEncoder::EncoderPaused() const { |
| // Pause video if paused by caller or as long as the network is down or the |
| // pacer queue has grown too large in buffered mode. |
| @@ -213,6 +152,7 @@ void ViEEncoder::TraceFrameDropEnd() { |
| void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame) { |
| VideoCodecType codec_type; |
| + bool do_report_active = false; |
| { |
| rtc::CritScope lock(&data_cs_); |
| time_of_last_frame_activity_ms_ = rtc::TimeMillis(); |
| @@ -221,9 +161,18 @@ void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame) { |
| return; |
| } |
| TraceFrameDropEnd(); |
| + do_report_active = reported_timeout_; |
| + reported_timeout_ = false; |
| codec_type = encoder_config_.codecType; |
| } |
| + if (do_report_active) { |
| + // We have previously reported that the encoder is inactive and we need to |
| + // report the state change. |
| + LOG(LS_INFO) << "ViEncoder is active."; |
| + sink_->OnEncoderActivityChanged(true); |
| + } |
| + |
| TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), |
| "Encode"); |
| const VideoFrame* frame_to_send = &video_frame; |
| @@ -264,6 +213,29 @@ void ViEEncoder::SendKeyFrame() { |
| video_sender_.IntraFrameRequest(0); |
| } |
| +void ViEEncoder::CheckForActivity() { |
| + bool do_report_timeout = false; |
| + { |
| + rtc::CritScope lock(&data_cs_); |
| + // TODO(perkj): Refactor this monitoring once we use TaskQueues and use a |
| + // timer instead. |
| + // This monitoring was previously achieved by that |
| + // VieEncoder::GetPaddingBitrate was by Call for each OnBitrateUpdated. |
|
stefan-webrtc
2016/06/08 09:25:13
This comment needs to be rewritten
perkj_webrtc
2016/06/08 15:35:27
Acknowledged.
|
| + int64_t now_ms = rtc::TimeMillis(); |
| + if (!reported_timeout_ && !EncoderPaused() && |
| + (now_ms - time_of_last_frame_activity_ms_ > |
| + VideoEncoderSink::TimeOutMs)) { |
| + do_report_timeout = true; |
| + reported_timeout_ = true; |
| + } |
| + } |
| + |
| + if (do_report_timeout) { |
| + LOG(LS_INFO) << "ViEncoder timed out."; |
|
stefan-webrtc
2016/06/08 09:25:13
ViEEncoder
perkj_webrtc
2016/06/08 15:35:27
Acknowledged.
|
| + sink_->OnEncoderActivityChanged(false); |
| + } |
| +} |
| + |
| void ViEEncoder::OnSetRates(uint32_t bitrate_bps, int framerate) { |
| if (stats_proxy_) |
| stats_proxy_->OnSetRates(bitrate_bps, framerate); |
| @@ -321,6 +293,7 @@ void ViEEncoder::OnBitrateUpdated(uint32_t bitrate_bps, |
| video_sender_.SetChannelParameters(bitrate_bps, fraction_lost, |
| round_trip_time_ms); |
| bool video_is_suspended = video_sender_.VideoSuspended(); |
| + |
| bool video_suspension_changed; |
| { |
| rtc::CritScope lock(&data_cs_); |