diff --git a/webrtc/modules/video_coding/BUILD.gn b/webrtc/modules/video_coding/BUILD.gn index d7143fd6d2..8cd7570046 100644 --- a/webrtc/modules/video_coding/BUILD.gn +++ b/webrtc/modules/video_coding/BUILD.gn @@ -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", ] diff --git a/webrtc/modules/video_coding/codecs/h264/h264.gypi b/webrtc/modules/video_coding/codecs/h264/h264.gypi index 92489c3966..5d9282371f 100644 --- a/webrtc/modules/video_coding/codecs/h264/h264.gypi +++ b/webrtc/modules/video_coding/codecs/h264/h264.gypi @@ -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', ], diff --git a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h b/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h index 08cb537a58..cb7ca34e61 100644 --- a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h +++ b/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.h @@ -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 diff --git a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.cc b/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm similarity index 97% rename from webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.cc rename to webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm index 4cbe2cd0bf..5a1fe845f7 100644 --- a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.cc +++ b/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm @@ -18,6 +18,7 @@ #include #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. diff --git a/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm b/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm index a9cf89f8d4..331db6d955 100644 --- a/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm +++ b/webrtc/sdk/objc/Framework/Classes/avfoundationvideocapturer.mm @@ -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)); }