Disable encoder scaling on iPhone4S.

Scaling causes us to work the CPU too much, which very quickly degrades quality. This causes us to at least behave better on good networks.

NOTRY=True
BUG=

Review-Url: https://codereview.webrtc.org/2205763002
Cr-Commit-Position: refs/heads/master@{#13630}
This commit is contained in:
tkchin
2016-08-03 12:57:09 -07:00
committed by Commit bot
parent 9dfa249796
commit 6ce738da31
5 changed files with 21 additions and 6 deletions

View File

@ -179,8 +179,8 @@ if (is_ios) {
sources = [
"codecs/h264/h264_video_toolbox_decoder.cc",
"codecs/h264/h264_video_toolbox_decoder.h",
"codecs/h264/h264_video_toolbox_encoder.cc",
"codecs/h264/h264_video_toolbox_encoder.h",
"codecs/h264/h264_video_toolbox_encoder.mm",
"codecs/h264/h264_video_toolbox_nalu.cc",
"codecs/h264/h264_video_toolbox_nalu.h",
]

View File

@ -79,8 +79,8 @@
'sources': [
'h264_video_toolbox_decoder.cc',
'h264_video_toolbox_decoder.h',
'h264_video_toolbox_encoder.cc',
'h264_video_toolbox_encoder.h',
'h264_video_toolbox_encoder.mm',
'h264_video_toolbox_nalu.cc',
'h264_video_toolbox_nalu.h',
],

View File

@ -88,6 +88,7 @@ class H264VideoToolboxEncoder : public H264Encoder {
rtc::CriticalSection quality_scaler_crit_;
QualityScaler quality_scaler_ GUARDED_BY(quality_scaler_crit_);
H264BitstreamParser h264_bitstream_parser_;
bool enable_scaling_;
}; // H264VideoToolboxEncoder
} // namespace webrtc

View File

@ -18,6 +18,7 @@
#include <vector>
#if defined(WEBRTC_IOS)
#import "WebRTC/UIDevice+RTCDevice.h"
#include "RTCUIApplication.h"
#endif
#include "libyuv/convert_from.h"
@ -217,7 +218,14 @@ namespace webrtc {
H264VideoToolboxEncoder::H264VideoToolboxEncoder()
: callback_(nullptr),
compression_session_(nullptr),
bitrate_adjuster_(Clock::GetRealTimeClock(), .5, .95) {}
bitrate_adjuster_(Clock::GetRealTimeClock(), .5, .95),
enable_scaling_(true) {
#if defined(WEBRTC_IOS)
if ([UIDevice deviceType] == RTCDeviceTypeIPhone4S) {
enable_scaling_ = false;
}
#endif
}
H264VideoToolboxEncoder::~H264VideoToolboxEncoder() {
DestroyCompressionSession();
@ -228,6 +236,8 @@ int H264VideoToolboxEncoder::InitEncode(const VideoCodec* codec_settings,
size_t max_payload_size) {
RTC_DCHECK(codec_settings);
RTC_DCHECK_EQ(codec_settings->codecType, kVideoCodecH264);
width_ = codec_settings->width;
height_ = codec_settings->height;
{
rtc::CritScope lock(&quality_scaler_crit_);
quality_scaler_.Init(QualityScaler::kLowH264QpThreshold,
@ -237,8 +247,10 @@ int H264VideoToolboxEncoder::InitEncode(const VideoCodec* codec_settings,
QualityScaler::Resolution res = quality_scaler_.GetScaledResolution();
// TODO(tkchin): We may need to enforce width/height dimension restrictions
// to match what the encoder supports.
width_ = res.width;
height_ = res.height;
if (enable_scaling_) {
width_ = res.width;
height_ = res.height;
}
}
// We can only set average bitrate on the HW encoder.
target_bitrate_bps_ = codec_settings->startBitrate;
@ -260,7 +272,8 @@ H264VideoToolboxEncoder::GetScaledBufferOnEncode(
// Handle native (CVImageRef) scaling.
const QualityScaler::Resolution res = quality_scaler_.GetScaledResolution();
if (res.width == frame->width() && res.height == frame->height())
if (!enable_scaling_ ||
(res.width == frame->width() && res.height == frame->height()))
return frame;
// TODO(magjed): Implement efficient CVImageRef -> CVImageRef scaling instead
// of doing it via I420.

View File

@ -582,6 +582,7 @@ AVFoundationVideoCapturer::AVFoundationVideoCapturer()
#if TARGET_OS_IPHONE
if ([UIDevice deviceType] == RTCDeviceTypeIPhone4S) {
supported_formats.push_back(cricket::VideoFormat(kIPhone4SFormat));
set_enable_video_adapter(false);
} else {
supported_formats.push_back(cricket::VideoFormat(kDefaultFormat));
}