diff --git a/video/receive_statistics_proxy.cc b/video/receive_statistics_proxy.cc index fff3e8e1ce..ccd2c20f65 100644 --- a/video/receive_statistics_proxy.cc +++ b/video/receive_statistics_proxy.cc @@ -839,18 +839,13 @@ void ReceiveStatisticsProxy::OnDiscardedPacketsUpdated(int discarded_packets) { stats_.discarded_packets = discarded_packets; } -void ReceiveStatisticsProxy::OnPreDecode( - const EncodedImage& encoded_image, - const CodecSpecificInfo* codec_specific_info) { +void ReceiveStatisticsProxy::OnPreDecode(VideoCodecType codec_type, int qp) { RTC_DCHECK_RUN_ON(&decode_thread_); - if (!codec_specific_info || encoded_image.qp_ == -1) { - return; - } rtc::CritScope lock(&crit_); - last_codec_type_ = codec_specific_info->codecType; - if (last_codec_type_ == kVideoCodecVP8) { - qp_counters_.vp8.Add(encoded_image.qp_); - qp_sample_.Add(encoded_image.qp_); + last_codec_type_ = codec_type; + if (last_codec_type_ == kVideoCodecVP8 && qp != -1) { + qp_counters_.vp8.Add(qp); + qp_sample_.Add(qp); } } diff --git a/video/receive_statistics_proxy.h b/video/receive_statistics_proxy.h index f8afe45cff..4daefe047d 100644 --- a/video/receive_statistics_proxy.h +++ b/video/receive_statistics_proxy.h @@ -62,8 +62,7 @@ class ReceiveStatisticsProxy : public VCMReceiveStatisticsCallback, void OnDecoderImplementationName(const char* implementation_name); void OnIncomingRate(unsigned int framerate, unsigned int bitrate_bps); - void OnPreDecode(const EncodedImage& encoded_image, - const CodecSpecificInfo* codec_specific_info); + void OnPreDecode(VideoCodecType codec_type, int qp); void OnUniqueFramesCounted(int num_unique_frames); diff --git a/video/receive_statistics_proxy_unittest.cc b/video/receive_statistics_proxy_unittest.cc index d8903e84b7..e419c93b21 100644 --- a/video/receive_statistics_proxy_unittest.cc +++ b/video/receive_statistics_proxy_unittest.cc @@ -578,13 +578,9 @@ TEST_F(ReceiveStatisticsProxyTest, RtpToNtpFrequencyOffsetHistogramIsUpdated) { TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsUpdated) { const int kQp = 22; - EncodedImage encoded_image; - encoded_image.qp_ = kQp; - CodecSpecificInfo codec_info; - codec_info.codecType = kVideoCodecVP8; for (int i = 0; i < kMinRequiredSamples; ++i) - statistics_proxy_->OnPreDecode(encoded_image, &codec_info); + statistics_proxy_->OnPreDecode(kVideoCodecVP8, kQp); statistics_proxy_.reset(); EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp")); @@ -592,25 +588,18 @@ TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsUpdated) { } TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsNotUpdatedForTooFewSamples) { - EncodedImage encoded_image; - encoded_image.qp_ = 22; - CodecSpecificInfo codec_info; - codec_info.codecType = kVideoCodecVP8; + const int kQp = 22; for (int i = 0; i < kMinRequiredSamples - 1; ++i) - statistics_proxy_->OnPreDecode(encoded_image, &codec_info); + statistics_proxy_->OnPreDecode(kVideoCodecVP8, kQp); statistics_proxy_.reset(); EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp")); } TEST_F(ReceiveStatisticsProxyTest, Vp8QpHistogramIsNotUpdatedIfNoQpValue) { - EncodedImage encoded_image; - CodecSpecificInfo codec_info; - codec_info.codecType = kVideoCodecVP8; - for (int i = 0; i < kMinRequiredSamples; ++i) - statistics_proxy_->OnPreDecode(encoded_image, &codec_info); + statistics_proxy_->OnPreDecode(kVideoCodecVP8, -1); statistics_proxy_.reset(); EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.Decoded.Vp8.Qp")); diff --git a/video/video_receive_stream.cc b/video/video_receive_stream.cc index 186ce4beb5..0ff9716b5d 100644 --- a/video/video_receive_stream.cc +++ b/video/video_receive_stream.cc @@ -32,6 +32,7 @@ #include "modules/video_coding/jitter_estimator.h" #include "modules/video_coding/timing.h" #include "modules/video_coding/utility/ivf_file_writer.h" +#include "modules/video_coding/utility/vp8_header_parser.h" #include "rtc_base/checks.h" #include "rtc_base/location.h" #include "rtc_base/logging.h" @@ -366,7 +367,6 @@ EncodedImageCallback::Result VideoReceiveStream::OnEncodedImage( const EncodedImage& encoded_image, const CodecSpecificInfo* codec_specific_info, const RTPFragmentationHeader* fragmentation) { - stats_proxy_.OnPreDecode(encoded_image, codec_specific_info); { rtc::CritScope lock(&ivf_writer_lock_); if (ivf_writer_.get()) { @@ -458,6 +458,16 @@ bool VideoReceiveStream::Decode() { if (frame) { int64_t now_ms = clock_->TimeInMilliseconds(); RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kFrameFound); + + // Current OnPreDecode only cares about QP for VP8. + int qp = -1; + if (frame->CodecSpecific()->codecType == kVideoCodecVP8) { + if (!vp8::GetQp(frame->Buffer(), frame->Length(), &qp)) { + RTC_LOG(LS_WARNING) << "Failed to extract QP from VP8 video frame"; + } + } + stats_proxy_.OnPreDecode(frame->CodecSpecific()->codecType, qp); + int decode_result = video_receiver_.Decode(frame.get()); if (decode_result == WEBRTC_VIDEO_CODEC_OK || decode_result == WEBRTC_VIDEO_CODEC_OK_REQUEST_KEYFRAME) {