Move the QP scaling thresholds to the relevant encoders.

Also provide a new set of thresholds for the VideoToolbox encoder. The new thresholds were experimentally determined to work well on the iPhone 6S, and also adequately on the iPhone 5S.

BUG=webrtc:5678

Review-Url: https://codereview.webrtc.org/2309743002
Cr-Commit-Position: refs/heads/master@{#14420}
This commit is contained in:
kthelgason
2016-09-28 08:17:43 -07:00
committed by Commit bot
parent e75f204b06
commit 478681e1e6
6 changed files with 52 additions and 46 deletions

View File

@ -14,6 +14,8 @@
#include <algorithm>
#include "webrtc/base/checks.h"
// TODO(kthelgason): Some versions of Android have issues with log2.
// See https://code.google.com/p/android/issues/detail?id=212634 for details
#if defined(WEBRTC_ANDROID)
@ -38,42 +40,54 @@ static const int kVgaBitrateThresholdKbps = 500;
static const int kVgaNumPixels = 700 * 500; // 640x480
static const int kQvgaBitrateThresholdKbps = 250;
static const int kQvgaNumPixels = 400 * 300; // 320x240
// QP scaling threshold defaults:
static const int kLowH264QpThreshold = 24;
static const int kHighH264QpThreshold = 37;
// QP is obtained from VP8-bitstream for HW, so the QP corresponds to the
// bitstream range of [0, 127] and not the user-level range of [0,63].
static const int kLowVp8QpThreshold = 29;
static const int kHighVp8QpThreshold = 95;
} // namespace
// QP thresholds are chosen to be high enough to be hit in practice when quality
// is good, but also low enough to not cause a flip-flop behavior (e.g. going up
// in resolution shouldn't give so bad quality that we should go back down).
const int QualityScaler::kLowVp8QpThreshold = 29;
const int QualityScaler::kBadVp8QpThreshold = 95;
#if defined(WEBRTC_IOS)
const int QualityScaler::kLowH264QpThreshold = 32;
const int QualityScaler::kBadH264QpThreshold = 42;
#else
const int QualityScaler::kLowH264QpThreshold = 24;
const int QualityScaler::kBadH264QpThreshold = 37;
#endif
// Default values. Should immediately get set to something more sensible.
QualityScaler::QualityScaler()
: average_qp_(kMeasureSecondsUpscale * 30),
framedrop_percent_(kMeasureSecondsUpscale * 30),
low_qp_threshold_(-1) {}
void QualityScaler::Init(VideoCodecType codec_type,
int initial_bitrate_kbps,
int width,
int height,
int fps) {
int low = -1, high = -1;
switch (codec_type) {
case kVideoCodecH264:
low = kLowH264QpThreshold;
high = kHighH264QpThreshold;
break;
case kVideoCodecVP8:
low = kLowVp8QpThreshold;
high = kHighVp8QpThreshold;
break;
default:
RTC_NOTREACHED() << "Invalid codec type for QualityScaler.";
}
Init(low, high, initial_bitrate_kbps, width, height, fps);
}
void QualityScaler::Init(int low_qp_threshold,
int high_qp_threshold,
int initial_bitrate_kbps,
int width,
int height,
int fps) {
ClearSamples();
low_qp_threshold_ = low_qp_threshold;
high_qp_threshold_ = high_qp_threshold;
downscale_shift_ = 0;
fast_rampup_ = true;
ClearSamples();
ReportFramerate(fps);
const int init_width = width;

View File

@ -11,6 +11,7 @@
#ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_
#define WEBRTC_MODULES_VIDEO_CODING_UTILITY_QUALITY_SCALER_H_
#include "webrtc/common_types.h"
#include "webrtc/common_video/include/i420_buffer_pool.h"
#include "webrtc/modules/video_coding/utility/moving_average.h"
@ -23,6 +24,11 @@ class QualityScaler {
};
QualityScaler();
void Init(VideoCodecType codec_type,
int initial_bitrate_kbps,
int width,
int height,
int fps);
void Init(int low_qp_threshold,
int high_qp_threshold,
int initial_bitrate_kbps,
@ -38,15 +44,6 @@ class QualityScaler {
const rtc::scoped_refptr<VideoFrameBuffer>& frame);
int downscale_shift() const { return downscale_shift_; }
// QP is obtained from VP8-bitstream for HW, so the QP corresponds to the
// bitstream range of [0, 127] and not the user-level range of [0,63].
static const int kLowVp8QpThreshold;
static const int kBadVp8QpThreshold;
// H264 QP is in the range [0, 51].
static const int kLowH264QpThreshold;
static const int kBadH264QpThreshold;
private:
void ClearSamples();
void ScaleUp();