diff --git a/api/test/videocodec_test_fixture.h b/api/test/videocodec_test_fixture.h index 0a2c758164..16177de5b0 100644 --- a/api/test/videocodec_test_fixture.h +++ b/api/test/videocodec_test_fixture.h @@ -25,7 +25,7 @@ namespace test { // Rates for the encoder and the frame number when to apply profile. struct RateProfile { size_t target_kbps; - size_t input_fps; + double input_fps; size_t frame_num; }; diff --git a/api/test/videocodec_test_stats.cc b/api/test/videocodec_test_stats.cc index 91af574497..b2f88a4661 100644 --- a/api/test/videocodec_test_stats.cc +++ b/api/test/videocodec_test_stats.cc @@ -43,6 +43,7 @@ std::string VideoCodecTestStats::FrameStatistics::ToString() const { ss << " decode_time_us " << decode_time_us; ss << " rtp_timestamp " << rtp_timestamp; ss << " target_bitrate_kbps " << target_bitrate_kbps; + ss << " target_framerate_fps " << target_framerate_fps; return ss.Release(); } diff --git a/api/test/videocodec_test_stats.h b/api/test/videocodec_test_stats.h index 5249c7a573..63e15768dc 100644 --- a/api/test/videocodec_test_stats.h +++ b/api/test/videocodec_test_stats.h @@ -42,6 +42,7 @@ class VideoCodecTestStats { bool encoding_successful = false; size_t encode_time_us = 0; size_t target_bitrate_kbps = 0; + double target_framerate_fps = 0.0; size_t length_bytes = 0; VideoFrameType frame_type = VideoFrameType::kVideoFrameDelta; diff --git a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc index 8586ee8a56..46612722d6 100644 --- a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc +++ b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc @@ -405,9 +405,8 @@ void VideoCodecTestFixtureImpl::RunTest( // codecs on a task queue. TaskQueueForTest task_queue("VidProc TQ"); - SetUpAndInitObjects(&task_queue, - static_cast(rate_profiles[0].target_kbps), - static_cast(rate_profiles[0].input_fps)); + SetUpAndInitObjects(&task_queue, rate_profiles[0].target_kbps, + rate_profiles[0].input_fps); PrintSettings(&task_queue); ProcessAllFrames(&task_queue, rate_profiles); ReleaseAndCloseObjects(&task_queue); @@ -442,9 +441,9 @@ void VideoCodecTestFixtureImpl::ProcessAllFrames( if (RunEncodeInRealTime(config_)) { // Roughly pace the frames. - const size_t frame_duration_ms = - rtc::kNumMillisecsPerSec / rate_profile->input_fps; - SleepMs(static_cast(frame_duration_ms)); + const int frame_duration_ms = + std::ceil(rtc::kNumMillisecsPerSec / rate_profile->input_fps); + SleepMs(frame_duration_ms); } } @@ -552,7 +551,7 @@ void VideoCodecTestFixtureImpl::VerifyVideoStatistic( const QualityThresholds* quality_thresholds, const BitstreamThresholds* bs_thresholds, size_t target_bitrate_kbps, - float input_framerate_fps) { + double input_framerate_fps) { if (rc_thresholds) { const float bitrate_mismatch_percent = 100 * std::fabs(1.0f * video_stat.bitrate_kbps - target_bitrate_kbps) / @@ -638,11 +637,11 @@ VideoCodecTestStats& VideoCodecTestFixtureImpl::GetStats() { void VideoCodecTestFixtureImpl::SetUpAndInitObjects( TaskQueueForTest* task_queue, - int initial_bitrate_kbps, - int initial_framerate_fps) { + size_t initial_bitrate_kbps, + double initial_framerate_fps) { config_.codec_settings.minBitrate = 0; - config_.codec_settings.startBitrate = initial_bitrate_kbps; - config_.codec_settings.maxFramerate = initial_framerate_fps; + config_.codec_settings.startBitrate = static_cast(initial_bitrate_kbps); + config_.codec_settings.maxFramerate = std::ceil(initial_framerate_fps); // Create file objects for quality analysis. source_frame_reader_.reset( @@ -679,7 +678,7 @@ void VideoCodecTestFixtureImpl::SetUpAndInitObjects( if (config_.visualization_params.save_decoded_y4m) { FrameWriter* decoded_frame_writer = new Y4mFrameWriterImpl( output_filename_base + ".y4m", config_.codec_settings.width, - config_.codec_settings.height, initial_framerate_fps); + config_.codec_settings.height, config_.codec_settings.maxFramerate); EXPECT_TRUE(decoded_frame_writer->Init()); decoded_frame_writers_.push_back( std::unique_ptr(decoded_frame_writer)); diff --git a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.h b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.h index 8caebebca7..3bbe50ecc3 100644 --- a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.h +++ b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.h @@ -62,8 +62,8 @@ class VideoCodecTestFixtureImpl : public VideoCodecTestFixture { void CreateEncoderAndDecoder(); void DestroyEncoderAndDecoder(); void SetUpAndInitObjects(TaskQueueForTest* task_queue, - int initial_bitrate_kbps, - int initial_framerate_fps); + size_t initial_bitrate_kbps, + double initial_framerate_fps); void ReleaseAndCloseObjects(TaskQueueForTest* task_queue); void ProcessAllFrames(TaskQueueForTest* task_queue, @@ -80,7 +80,7 @@ class VideoCodecTestFixtureImpl : public VideoCodecTestFixture { const QualityThresholds* quality_thresholds, const BitstreamThresholds* bs_thresholds, size_t target_bitrate_kbps, - float input_framerate_fps); + double input_framerate_fps); void PrintSettings(TaskQueueForTest* task_queue) const; diff --git a/modules/video_coding/codecs/test/videoprocessor.cc b/modules/video_coding/codecs/test/videoprocessor.cc index 42081a0f1f..9b0903b334 100644 --- a/modules/video_coding/codecs/test/videoprocessor.cc +++ b/modules/video_coding/codecs/test/videoprocessor.cc @@ -256,7 +256,8 @@ void VideoProcessor::ProcessFrame() { input_frame_reader_->ReadFrame(); RTC_CHECK(buffer) << "Tried to read too many frames from the file."; const size_t timestamp = - last_inputed_timestamp_ + kVideoPayloadTypeFrequency / framerate_fps_; + last_inputed_timestamp_ + + static_cast(kVideoPayloadTypeFrequency / framerate_fps_); VideoFrame input_frame = VideoFrame::Builder() .set_video_frame_buffer(buffer) @@ -301,13 +302,13 @@ void VideoProcessor::ProcessFrame() { } } -void VideoProcessor::SetRates(size_t bitrate_kbps, size_t framerate_fps) { +void VideoProcessor::SetRates(size_t bitrate_kbps, double framerate_fps) { RTC_DCHECK_RUN_ON(&sequence_checker_); - framerate_fps_ = static_cast(framerate_fps); + framerate_fps_ = framerate_fps; bitrate_allocation_ = bitrate_allocator_->GetAllocation( static_cast(bitrate_kbps * 1000), framerate_fps_); - encoder_->SetRates(VideoEncoder::RateControlParameters( - bitrate_allocation_, static_cast(framerate_fps_))); + encoder_->SetRates( + VideoEncoder::RateControlParameters(bitrate_allocation_, framerate_fps_)); } int32_t VideoProcessor::VideoProcessorDecodeCompleteCallback::Decoded( @@ -381,6 +382,7 @@ void VideoProcessor::FrameEncoded( frame_stat->encode_start_ns, encode_stop_ns - post_encode_time_ns_); frame_stat->target_bitrate_kbps = bitrate_allocation_.GetTemporalLayerSum(spatial_idx, temporal_idx) / 1000; + frame_stat->target_framerate_fps = framerate_fps_; frame_stat->length_bytes = encoded_image.size(); frame_stat->frame_type = encoded_image._frameType; frame_stat->temporal_idx = temporal_idx; diff --git a/modules/video_coding/codecs/test/videoprocessor.h b/modules/video_coding/codecs/test/videoprocessor.h index 6ac0d656f7..fe0211de7d 100644 --- a/modules/video_coding/codecs/test/videoprocessor.h +++ b/modules/video_coding/codecs/test/videoprocessor.h @@ -76,7 +76,7 @@ class VideoProcessor { void ProcessFrame(); // Updates the encoder with target rates. Must be called at least once. - void SetRates(size_t bitrate_kbps, size_t framerate_fps); + void SetRates(size_t bitrate_kbps, double framerate_fps); private: class VideoProcessorEncodeCompleteCallback @@ -194,7 +194,7 @@ class VideoProcessor { VideoDecoderList* const decoders_; const std::unique_ptr bitrate_allocator_; VideoBitrateAllocation bitrate_allocation_ RTC_GUARDED_BY(sequence_checker_); - uint32_t framerate_fps_ RTC_GUARDED_BY(sequence_checker_); + double framerate_fps_ RTC_GUARDED_BY(sequence_checker_); // Adapters for the codec callbacks. VideoProcessorEncodeCompleteCallback encode_callback_;