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

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

Issue 2398963003: Move usage of QualityScaler to ViEEncoder. (Closed)
Patch Set: fix videotoolbox overridden QP thresholds 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..79ce5bf4df9ae41ba8ba3e3484890960e7dff33e 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,6 @@ 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;
- }
// We can only set average bitrate on the HW encoder.
target_bitrate_bps_ = codec_settings->startBitrate;
bitrate_adjuster_.SetTargetBitrateBps(target_bitrate_bps_);
@@ -273,18 +261,6 @@ int H264VideoToolboxEncoder::Encode(
#endif
bool is_keyframe_required = false;
- quality_scaler_.OnEncodeFrame(frame.width(), frame.height());
- 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,16 +302,6 @@ 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,
- pixel_buffer)) {
- LOG(LS_ERROR) << "Failed to copy frame data.";
- CVBufferRelease(pixel_buffer);
- return WEBRTC_VIDEO_CODEC_ERROR;
- }
}
// Check if we need a keyframe.
@@ -386,11 +352,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 +363,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 +535,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;
}
@@ -620,13 +575,6 @@ void H264VideoToolboxEncoder::OnEncodedFrame(
frame._timeStamp = timestamp;
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);
- }
-
int result = callback_->Encoded(frame, &codec_specific_info, header.get());
if (result != 0) {
LOG(LS_ERROR) << "Encode callback failed: " << result;
@@ -635,6 +583,12 @@ void H264VideoToolboxEncoder::OnEncodedFrame(
bitrate_adjuster_.Update(frame._size);
}
+rtc::Optional<QPThresholds>
+H264VideoToolboxEncoder::GetQPThresholds() {
+ return rtc::Optional<QPThresholds>(QPThresholds(
+ internal::kLowH264QpThreshold,
+ internal::kHighH264QpThreshold));
+}
} // namespace webrtc
#endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED)

Powered by Google App Engine
This is Rietveld 408576698