Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Unified Diff: talk/app/webrtc/java/jni/androidmediaencoder_jni.cc

Issue 1592883004: Use high QP threshold for HW VP8 encoder frame downscaling. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: talk/app/webrtc/java/jni/androidmediaencoder_jni.cc
diff --git a/talk/app/webrtc/java/jni/androidmediaencoder_jni.cc b/talk/app/webrtc/java/jni/androidmediaencoder_jni.cc
index 7f558c0551b07e657d2163df58167a4734ecf06d..d63b7d1d60212b56a08efae43ae7bcbee0268290 100644
--- a/talk/app/webrtc/java/jni/androidmediaencoder_jni.cc
+++ b/talk/app/webrtc/java/jni/androidmediaencoder_jni.cc
@@ -77,7 +77,9 @@ namespace webrtc_jni {
#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
+// this threshold means that encoder probably got stuck and need to be reset.
+#define MAX_DROPPED_FRAMES 60
pbos-webrtc 2016/01/18 10:33:07 ENCODER_STALL_FRAMEDROP_THRESHOLD maybe, something
jackychen_ 2016/01/19 02:21:01 In the comment, "reset the encoder when it drops m
AlexG 2016/01/19 22:13:41 Done.
AlexG 2016/01/19 22:13:41 Done.
// Logging macros.
#define TAG_ENCODER "MediaCodecVideoEncoder"
@@ -221,6 +223,7 @@ class MediaCodecVideoEncoder : public webrtc::VideoEncoder,
int frames_received_; // Number of frames received by encoder.
int frames_encoded_; // Number of frames encoded by encoder.
int frames_dropped_; // Number of frames dropped by encoder.
+ int frames_dropped_q_full_; // Number of dropped frames caused by full queue.
pbos-webrtc 2016/01/18 10:33:07 consecutive_full_queue_frame_drops_
AlexG 2016/01/19 22:13:41 Done.
int frames_in_queue_; // Number of frames in encoder queue.
int64_t start_time_ms_; // Start time for statistics.
int current_frames_; // Number of frames in the current statistics interval.
@@ -370,18 +373,15 @@ int32_t MediaCodecVideoEncoder::InitEncode(
// always = 127. Note that in SW, QP is that of the user-level range [0,
// 63].
const int kMaxQp = 127;
- // TODO(pbos): Investigate whether high-QP thresholds make sense for VP8.
- // This effectively disables high QP as VP8 QP can't go above this
- // threshold.
- const int kDisabledBadQpThreshold = kMaxQp + 1;
- quality_scaler_.Init(kMaxQp / kLowQpThresholdDenominator,
- kDisabledBadQpThreshold, true);
+ const int kBadQpThreshold = kMaxQp - kMaxQp / 4;
pbos-webrtc 2016/01/18 10:33:07 I think this should just be hard-coded as another
AlexG 2016/01/19 22:13:41 Done.
+ quality_scaler_.Init(
+ kMaxQp / kLowQpThresholdDenominator, kBadQpThreshold, false);
} else if (codecType_ == kVideoCodecH264) {
// H264 QP is in the range [0, 51].
const int kMaxQp = 51;
const int kBadQpThreshold = 40;
- quality_scaler_.Init(kMaxQp / kLowQpThresholdDenominator, kBadQpThreshold,
- false);
+ quality_scaler_.Init(
+ kMaxQp / kLowQpThresholdDenominator, kBadQpThreshold, false);
} else {
// When adding codec support to additional hardware codecs, also configure
// their QP thresholds for scaling.
@@ -429,9 +429,6 @@ int32_t MediaCodecVideoEncoder::SetChannelParameters(uint32_t /* packet_loss */,
int32_t MediaCodecVideoEncoder::SetRates(uint32_t new_bit_rate,
uint32_t frame_rate) {
- if (scale_)
- quality_scaler_.ReportFramerate(frame_rate);
-
return codec_thread_->Invoke<int32_t>(
Bind(&MediaCodecVideoEncoder::SetRatesOnCodecThread,
this,
@@ -498,6 +495,7 @@ int32_t MediaCodecVideoEncoder::InitEncodeOnCodecThread(
frames_received_ = 0;
frames_encoded_ = 0;
frames_dropped_ = 0;
+ frames_dropped_q_full_ = 0;
frames_in_queue_ = 0;
current_timestamp_us_ = 0;
start_time_ms_ = GetCurrentTimeMs();
@@ -614,12 +612,20 @@ int32_t MediaCodecVideoEncoder::EncodeOnCodecThread(
if (frames_in_queue_ > MAX_ENCODER_Q_SIZE ||
encoder_latency_ms > MAX_ENCODER_LATENCY_MS) {
ALOGD << "Drop frame - encoder is behind by " << encoder_latency_ms <<
- " ms. Q size: " << frames_in_queue_;
+ " ms. Q size: " << frames_in_queue_ << ". Consecutive drops: " <<
+ frames_dropped_q_full_;
current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_;
+ frames_dropped_q_full_++;
+ if (frames_dropped_q_full_ >= MAX_DROPPED_FRAMES) {
+ ALOGE << "Encoder got stuck. Reset.";
+ ResetCodecOnCodecThread();
+ return WEBRTC_VIDEO_CODEC_ERROR;
+ }
OnDroppedFrame();
return WEBRTC_VIDEO_CODEC_OK;
}
}
+ frames_dropped_q_full_ = 0;
VideoFrame input_frame = frame;
if (scale_) {
@@ -662,6 +668,7 @@ int32_t MediaCodecVideoEncoder::EncodeOnCodecThread(
ALOGW << "Encoder drop frame - no input buffers available";
current_timestamp_us_ += rtc::kNumMicrosecsPerSec / last_set_fps_;
frame_rtc_times_ms_.erase(frame_rtc_times_ms_.begin());
+ OnDroppedFrame();
return WEBRTC_VIDEO_CODEC_OK; // TODO(fischman): see webrtc bug 2887.
}
if (j_input_buffer_index == -2) {
@@ -815,6 +822,9 @@ int32_t MediaCodecVideoEncoder::SetRatesOnCodecThread(uint32_t new_bit_rate,
last_set_fps_ == frame_rate) {
return WEBRTC_VIDEO_CODEC_OK;
}
+ if (scale_) {
+ quality_scaler_.ReportFramerate(frame_rate);
+ }
JNIEnv* jni = AttachCurrentThreadIfNeeded();
ScopedLocalRefFrame local_ref_frame(jni);
if (new_bit_rate > 0) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698