Remove latency-based frame dropping on Android.
This logic currently prevents loopback calls on Nexus 5X when it's slightly overloaded to maintain input framerate since encoding at ~25fps with one framedrop results in >70ms between frames naturally. With this change applied Nexus 5X can maintain ~25fps both in and out without building excessive latency (>2 frames) (this is now covered by CPU adaptation outside the codec wrapper). BUG= R=glaznev@webrtc.org Review URL: https://codereview.webrtc.org/1854413004 . Cr-Commit-Position: refs/heads/master@{#12317}
This commit is contained in:
@ -62,8 +62,6 @@ namespace webrtc_jni {
|
|||||||
#define MAX_ALLOWED_VIDEO_FPS 60
|
#define MAX_ALLOWED_VIDEO_FPS 60
|
||||||
// Maximum allowed frames in encoder input queue.
|
// Maximum allowed frames in encoder input queue.
|
||||||
#define MAX_ENCODER_Q_SIZE 2
|
#define MAX_ENCODER_Q_SIZE 2
|
||||||
// Maximum allowed latency in ms.
|
|
||||||
#define MAX_ENCODER_LATENCY_MS 70
|
|
||||||
// Maximum amount of dropped frames caused by full encoder queue - exceeding
|
// Maximum amount of dropped frames caused by full encoder queue - exceeding
|
||||||
// this threshold means that encoder probably got stuck and need to be reset.
|
// this threshold means that encoder probably got stuck and need to be reset.
|
||||||
#define ENCODER_STALL_FRAMEDROP_THRESHOLD 60
|
#define ENCODER_STALL_FRAMEDROP_THRESHOLD 60
|
||||||
@ -642,29 +640,24 @@ int32_t MediaCodecVideoEncoder::EncodeOnCodecThread(
|
|||||||
|
|
||||||
RTC_CHECK(frame_types->size() == 1) << "Unexpected stream count";
|
RTC_CHECK(frame_types->size() == 1) << "Unexpected stream count";
|
||||||
|
|
||||||
// Check if we accumulated too many frames in encoder input buffers
|
// Check if we accumulated too many frames in encoder input buffers and drop
|
||||||
// or the encoder latency exceeds 70 ms and drop frame if so.
|
// frame if so.
|
||||||
if (frames_in_queue_ > 0 && last_input_timestamp_ms_ >= 0) {
|
if (frames_in_queue_ > MAX_ENCODER_Q_SIZE) {
|
||||||
int encoder_latency_ms = last_input_timestamp_ms_ -
|
ALOGD << "Already " << frames_in_queue_ << " frames in the queue, dropping"
|
||||||
last_output_timestamp_ms_;
|
<< ". TS: " << (int)(current_timestamp_us_ / 1000)
|
||||||
if (frames_in_queue_ > MAX_ENCODER_Q_SIZE ||
|
<< ". Fps: " << last_set_fps_
|
||||||
encoder_latency_ms > MAX_ENCODER_LATENCY_MS) {
|
<< ". Consecutive drops: " << consecutive_full_queue_frame_drops_;
|
||||||
ALOGD << "Drop frame - encoder is behind by " << encoder_latency_ms <<
|
current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_;
|
||||||
" ms. Q size: " << frames_in_queue_ << ". TS: " <<
|
consecutive_full_queue_frame_drops_++;
|
||||||
(int)(current_timestamp_us_ / 1000) << ". Fps: " << last_set_fps_ <<
|
if (consecutive_full_queue_frame_drops_ >=
|
||||||
". Consecutive drops: " << consecutive_full_queue_frame_drops_ ;
|
ENCODER_STALL_FRAMEDROP_THRESHOLD) {
|
||||||
current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_;
|
ALOGE << "Encoder got stuck. Reset.";
|
||||||
consecutive_full_queue_frame_drops_++;
|
ResetCodecOnCodecThread();
|
||||||
if (consecutive_full_queue_frame_drops_ >=
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||||
ENCODER_STALL_FRAMEDROP_THRESHOLD) {
|
|
||||||
ALOGE << "Encoder got stuck. Reset.";
|
|
||||||
ResetCodecOnCodecThread();
|
|
||||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
|
||||||
}
|
|
||||||
frames_dropped_media_encoder_++;
|
|
||||||
OnDroppedFrame();
|
|
||||||
return WEBRTC_VIDEO_CODEC_OK;
|
|
||||||
}
|
}
|
||||||
|
frames_dropped_media_encoder_++;
|
||||||
|
OnDroppedFrame();
|
||||||
|
return WEBRTC_VIDEO_CODEC_OK;
|
||||||
}
|
}
|
||||||
consecutive_full_queue_frame_drops_ = 0;
|
consecutive_full_queue_frame_drops_ = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user