diff --git a/modules/video_coding/generic_decoder.cc b/modules/video_coding/generic_decoder.cc index 166ce1d9f1..23199f7a34 100644 --- a/modules/video_coding/generic_decoder.cc +++ b/modules/video_coding/generic_decoder.cc @@ -134,14 +134,13 @@ void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage, return; } - // TODO: bugs.webrtc.org/358039777 - Use the score. - std::optional score; + std::optional corruption_score; if (corruption_score_calculator_ && frame_info->frame_instrumentation_data.has_value()) { if (const FrameInstrumentationData* data = absl::get_if( &*frame_info->frame_instrumentation_data)) { - score = corruption_score_calculator_->CalculateCorruptionScore( + corruption_score = corruption_score_calculator_->CalculateCorruptionScore( decodedImage, *data); } } @@ -242,7 +241,8 @@ void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage, .qp = qp, .decode_time = decode_time, .content_type = frame_info->content_type, - .frame_type = frame_info->frame_type}); + .frame_type = frame_info->frame_type, + .corruption_score = corruption_score}); } void VCMDecodedFrameCallback::OnDecoderInfoChanged( diff --git a/modules/video_coding/generic_decoder_unittest.cc b/modules/video_coding/generic_decoder_unittest.cc index 9f362e45c6..8300292146 100644 --- a/modules/video_coding/generic_decoder_unittest.cc +++ b/modules/video_coding/generic_decoder_unittest.cc @@ -37,6 +37,8 @@ #include "test/scoped_key_value_config.h" #include "test/time_controller/simulated_time_controller.h" +using ::testing::Return; + namespace webrtc { namespace video_coding { @@ -65,6 +67,7 @@ class ReceiveCallback : public VCMReceiveCallback { int32_t OnFrameToRender(const struct FrameToRender& arguments) override { frames_.push_back(arguments.video_frame); + last_corruption_score_ = arguments.corruption_score; return 0; } @@ -84,9 +87,14 @@ class ReceiveCallback : public VCMReceiveCallback { uint32_t frames_dropped() const { return frames_dropped_; } + std::optional last_corruption_score() const { + return last_corruption_score_; + } + private: std::vector frames_; uint32_t frames_dropped_ = 0; + std::optional last_corruption_score_; }; class GenericDecoderTest : public ::testing::Test { @@ -220,22 +228,27 @@ TEST_F(GenericDecoderTest, IsLowLatencyStreamActivatedByPlayoutDelay) { } TEST_F(GenericDecoderTest, CallCalculateCorruptionScoreInDecoded) { - EXPECT_CALL(corruption_score_calculator_, CalculateCorruptionScore); + constexpr double kCorruptionScore = 0.76; - uint32_t rtp_timestamp = 1; + EXPECT_CALL(corruption_score_calculator_, CalculateCorruptionScore) + .WillOnce(Return(kCorruptionScore)); + + constexpr uint32_t kRtpTimestamp = 1; FrameInfo frame_info; frame_info.frame_instrumentation_data = FrameInstrumentationData{}; - frame_info.rtp_timestamp = rtp_timestamp; + frame_info.rtp_timestamp = kRtpTimestamp; frame_info.decode_start = Timestamp::Zero(); frame_info.content_type = VideoContentType::UNSPECIFIED; frame_info.frame_type = VideoFrameType::kVideoFrameDelta; VideoFrame video_frame = VideoFrame::Builder() .set_video_frame_buffer(I420Buffer::Create(5, 5)) - .set_rtp_timestamp(rtp_timestamp) + .set_rtp_timestamp(kRtpTimestamp) .build(); vcm_callback_.Map(std::move(frame_info)); vcm_callback_.Decoded(video_frame); + + EXPECT_EQ(user_callback_.last_corruption_score(), kCorruptionScore); } } // namespace video_coding diff --git a/modules/video_coding/include/video_coding_defines.h b/modules/video_coding/include/video_coding_defines.h index 1347431087..c5d8e7597c 100644 --- a/modules/video_coding/include/video_coding_defines.h +++ b/modules/video_coding/include/video_coding_defines.h @@ -59,6 +59,7 @@ class VCMReceiveCallback { TimeDelta decode_time; VideoContentType content_type; VideoFrameType frame_type; + std::optional corruption_score; }; // TODO: bugs.webrtc.org/358039777 - Delete this function. diff --git a/video/video_stream_decoder2.cc b/video/video_stream_decoder2.cc index c8bec277f0..30ea4c38ea 100644 --- a/video/video_stream_decoder2.cc +++ b/video/video_stream_decoder2.cc @@ -66,6 +66,10 @@ int32_t VideoStreamDecoder::OnFrameToRender( receive_stats_callback_->OnDecodedFrame( arguments.video_frame, arguments.qp, arguments.decode_time, arguments.content_type, arguments.frame_type); + if (arguments.corruption_score.has_value()) { + receive_stats_callback_->OnCorruptionScore(*arguments.corruption_score, + arguments.content_type); + } incoming_video_stream_->OnFrame(arguments.video_frame); return 0; }