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

Unified Diff: webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm

Issue 2398963003: Move usage of QualityScaler to ViEEncoder. (Closed)
Patch Set: Stats now properly reflect scaling status Created 4 years, 2 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
Index: webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm
diff --git a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm b/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm
index 88687136ed31fbdcdf75af27522f5ce0abe219c9..ae0761d1c06a76698fa4d34eb9790a1644aa1e9f 100644
--- a/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm
+++ b/webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_encoder.mm
@@ -234,18 +234,9 @@ int H264VideoToolboxEncoder::InitEncode(const VideoCodec* codec_settings,
size_t max_payload_size) {
RTC_DCHECK(codec_settings);
RTC_DCHECK_EQ(codec_settings->codecType, kVideoCodecH264);
- {
- rtc::CritScope lock(&quality_scaler_crit_);
- quality_scaler_.Init(internal::kLowH264QpThreshold,
- internal::kHighH264QpThreshold,
- codec_settings->startBitrate, codec_settings->width,
- codec_settings->height, codec_settings->maxFramerate);
- 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;
- }
+
+ width_ = codec_settings->width;
+ height_ = codec_settings->height;
// We can only set average bitrate on the HW encoder.
target_bitrate_bps_ = codec_settings->startBitrate;
bitrate_adjuster_.SetTargetBitrateBps(target_bitrate_bps_);
@@ -273,18 +264,6 @@ int H264VideoToolboxEncoder::Encode(
#endif
bool is_keyframe_required = false;
- quality_scaler_.OnEncodeFrame(frame.width(), frame.height());
magjed_webrtc 2016/10/26 14:28:36 ditto: Please add: RTC_DCHECK_EQ(frame.width(), wi
kthelgason 2016/10/26 19:02:49 Done.
- const QualityScaler::Resolution scaled_res =
- quality_scaler_.GetScaledResolution();
-
- if (scaled_res.width != width_ || scaled_res.height != height_) {
- width_ = scaled_res.width;
- height_ = scaled_res.height;
- int ret = ResetCompressionSession();
- if (ret < 0)
- return ret;
- }
-
// Get a pixel buffer from the pool and copy frame data over.
CVPixelBufferPoolRef pixel_buffer_pool =
VTCompressionSessionGetPixelBufferPool(compression_session_);
@@ -326,11 +305,7 @@ int H264VideoToolboxEncoder::Encode(
return WEBRTC_VIDEO_CODEC_ERROR;
}
RTC_DCHECK(pixel_buffer);
- // TODO(magjed): Optimize by merging scaling and NV12 pixel buffer
- // conversion once libyuv::MergeUVPlanes is available.
- rtc::scoped_refptr<VideoFrameBuffer> scaled_i420_buffer =
- quality_scaler_.GetScaledBuffer(frame.video_frame_buffer());
- if (!internal::CopyVideoFrameToPixelBuffer(scaled_i420_buffer,
+ if (!internal::CopyVideoFrameToPixelBuffer(frame.video_frame_buffer(),
pixel_buffer)) {
LOG(LS_ERROR) << "Failed to copy frame data.";
CVBufferRelease(pixel_buffer);
@@ -386,11 +361,6 @@ int H264VideoToolboxEncoder::RegisterEncodeCompleteCallback(
return WEBRTC_VIDEO_CODEC_OK;
}
-void H264VideoToolboxEncoder::OnDroppedFrame() {
- rtc::CritScope lock(&quality_scaler_crit_);
- quality_scaler_.ReportDroppedFrame();
-}
-
int H264VideoToolboxEncoder::SetChannelParameters(uint32_t packet_loss,
int64_t rtt) {
// Encoder doesn't know anything about packet loss or rtt so just return.
@@ -402,10 +372,6 @@ int H264VideoToolboxEncoder::SetRates(uint32_t new_bitrate_kbit,
target_bitrate_bps_ = 1000 * new_bitrate_kbit;
bitrate_adjuster_.SetTargetBitrateBps(target_bitrate_bps_);
SetBitrateBps(bitrate_adjuster_.GetAdjustedBitrateBps());
-
- rtc::CritScope lock(&quality_scaler_crit_);
- quality_scaler_.ReportFramerate(frame_rate);
-
return WEBRTC_VIDEO_CODEC_OK;
}
@@ -578,8 +544,6 @@ void H264VideoToolboxEncoder::OnEncodedFrame(
}
if (info_flags & kVTEncodeInfo_FrameDropped) {
LOG(LS_INFO) << "H264 encode dropped frame.";
- rtc::CritScope lock(&quality_scaler_crit_);
- quality_scaler_.ReportDroppedFrame();
return;
}
@@ -621,11 +585,7 @@ void H264VideoToolboxEncoder::OnEncodedFrame(
frame.rotation_ = rotation;
h264_bitstream_parser_.ParseBitstream(buffer->data(), buffer->size());
- int qp;
- if (h264_bitstream_parser_.GetLastSliceQp(&qp)) {
- rtc::CritScope lock(&quality_scaler_crit_);
- quality_scaler_.ReportQP(qp);
- }
+ h264_bitstream_parser_.GetLastSliceQp(&frame.qp_);
int result = callback_->Encoded(frame, &codec_specific_info, header.get());
if (result != 0) {
@@ -635,6 +595,10 @@ void H264VideoToolboxEncoder::OnEncodedFrame(
bitrate_adjuster_.Update(frame._size);
}
+QualityScaler::Settings H264VideoToolboxEncoder::GetQPThresholds() const {
+ return QualityScaler::Settings(true, internal::kLowH264QpThreshold,
+ internal::kHighH264QpThreshold);
+}
} // namespace webrtc
#endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)

Powered by Google App Engine
This is Rietveld 408576698