diff --git a/modules/video_coding/codecs/test/packet_manipulator.cc b/modules/video_coding/codecs/test/packet_manipulator.cc index 42e6ab539e..779faf68c4 100644 --- a/modules/video_coding/codecs/test/packet_manipulator.cc +++ b/modules/video_coding/codecs/test/packet_manipulator.cc @@ -10,9 +10,9 @@ #include "modules/video_coding/codecs/test/packet_manipulator.h" -#include #include +#include "rtc_base/checks.h" #include "rtc_base/format_macros.h" namespace webrtc { @@ -23,10 +23,10 @@ PacketManipulatorImpl::PacketManipulatorImpl(PacketReader* packet_reader, bool verbose) : packet_reader_(packet_reader), config_(config), + verbose_(verbose), active_burst_packets_(0), - random_seed_(1), - verbose_(verbose) { - assert(packet_reader); + random_seed_(1) { + RTC_DCHECK(packet_reader); } int PacketManipulatorImpl::ManipulatePackets( @@ -41,7 +41,7 @@ int PacketManipulatorImpl::ManipulatePackets( packet_reader_->InitializeReading(encoded_image->_buffer, encoded_image->_length, config_.packet_size_in_bytes); - uint8_t* packet = NULL; + uint8_t* packet = nullptr; int nbr_bytes_to_read; // keep track of if we've lost any packets, since then we shall loose // the remains of the current frame: @@ -91,17 +91,5 @@ inline double PacketManipulatorImpl::RandomUniform() { return (random_seed_ + 1.0) / (RAND_MAX + 1.0); } -const char* PacketLossModeToStr(PacketLossMode e) { - switch (e) { - case kUniform: - return "Uniform"; - case kBurst: - return "Burst"; - default: - assert(false); - return "Unknown"; - } -} - } // namespace test } // namespace webrtc diff --git a/modules/video_coding/codecs/test/packet_manipulator.h b/modules/video_coding/codecs/test/packet_manipulator.h index be00b236f2..5a2c9cc56a 100644 --- a/modules/video_coding/codecs/test/packet_manipulator.h +++ b/modules/video_coding/codecs/test/packet_manipulator.h @@ -24,13 +24,10 @@ namespace test { enum PacketLossMode { // Drops packets with a configured probability independently for each packet kUniform, - // Drops packets similar to uniform but when a packet is being dropped, - // the number of lost packets in a row is equal to the configured burst - // length. + // Drops packets similar to uniform but when a packet is being dropped, the + // number of lost packets in a row is equal to the configured burst length. kBurst }; -// Returns a string representation of the enum value. -const char* PacketLossModeToStr(PacketLossMode e); // Contains configurations related to networking and simulation of // scenarios caused by network interference. @@ -100,13 +97,13 @@ class PacketManipulatorImpl : public PacketManipulator { virtual double RandomUniform(); private: - PacketReader* packet_reader_; + PacketReader* const packet_reader_; const NetworkingConfig& config_; + const bool verbose_; // Used to simulate a burst over several frames. int active_burst_packets_; rtc::CriticalSection critsect_; unsigned int random_seed_; - bool verbose_; }; } // namespace test diff --git a/modules/video_coding/codecs/test/test_config.cc b/modules/video_coding/codecs/test/test_config.cc index 3905b03f0b..d0d46de69b 100644 --- a/modules/video_coding/codecs/test/test_config.cc +++ b/modules/video_coding/codecs/test/test_config.cc @@ -153,6 +153,13 @@ int TestConfig::TemporalLayerForFrame(int frame_idx) const { return tl; } +std::vector TestConfig::FrameTypeForFrame(int frame_idx) const { + if (keyframe_interval > 0 && (frame_idx % keyframe_interval == 0)) { + return {kVideoFrameKey}; + } + return {kVideoFrameDelta}; +} + std::string TestConfig::ToString() const { std::stringstream ss; ss << "Video config:"; diff --git a/modules/video_coding/codecs/test/test_config.h b/modules/video_coding/codecs/test/test_config.h index a6fcd5c308..9c1ef1b68c 100644 --- a/modules/video_coding/codecs/test/test_config.h +++ b/modules/video_coding/codecs/test/test_config.h @@ -12,6 +12,7 @@ #define MODULES_VIDEO_CODING_CODECS_TEST_TEST_CONFIG_H_ #include +#include #include "common_types.h" // NOLINT(build/include) #include "modules/video_coding/codecs/h264/include/h264_globals.h" @@ -53,6 +54,7 @@ struct TestConfig { int NumberOfCores() const; int NumberOfTemporalLayers() const; int TemporalLayerForFrame(int frame_idx) const; + std::vector FrameTypeForFrame(int frame_idx) const; std::string ToString() const; // Plain name of YUV file to process without file extension. diff --git a/modules/video_coding/codecs/test/test_config_unittest.cc b/modules/video_coding/codecs/test/test_config_unittest.cc index 30b7f22258..c2253a2fd3 100644 --- a/modules/video_coding/codecs/test/test_config_unittest.cc +++ b/modules/video_coding/codecs/test/test_config_unittest.cc @@ -9,9 +9,12 @@ */ #include "modules/video_coding/codecs/test/test_config.h" +#include "test/gmock.h" #include "test/gtest.h" #include "test/video_codec_settings.h" +using ::testing::ElementsAre; + namespace webrtc { namespace test { @@ -84,6 +87,25 @@ TEST(TestConfig, TemporalLayersForFrame_ThreeLayers) { EXPECT_EQ(2, config.TemporalLayerForFrame(7)); } +TEST(TestConfig, ForcedKeyFrameIntervalOff) { + TestConfig config; + config.keyframe_interval = 0; + EXPECT_THAT(config.FrameTypeForFrame(0), ElementsAre(kVideoFrameDelta)); + EXPECT_THAT(config.FrameTypeForFrame(1), ElementsAre(kVideoFrameDelta)); + EXPECT_THAT(config.FrameTypeForFrame(2), ElementsAre(kVideoFrameDelta)); +} + +TEST(TestConfig, ForcedKeyFrameIntervalOn) { + TestConfig config; + config.keyframe_interval = 3; + EXPECT_THAT(config.FrameTypeForFrame(0), ElementsAre(kVideoFrameKey)); + EXPECT_THAT(config.FrameTypeForFrame(1), ElementsAre(kVideoFrameDelta)); + EXPECT_THAT(config.FrameTypeForFrame(2), ElementsAre(kVideoFrameDelta)); + EXPECT_THAT(config.FrameTypeForFrame(3), ElementsAre(kVideoFrameKey)); + EXPECT_THAT(config.FrameTypeForFrame(4), ElementsAre(kVideoFrameDelta)); + EXPECT_THAT(config.FrameTypeForFrame(5), ElementsAre(kVideoFrameDelta)); +} + TEST(TestConfig, ToString_Vp8) { TestConfig config; config.filename = "yuvfile"; diff --git a/modules/video_coding/codecs/test/videoprocessor.cc b/modules/video_coding/codecs/test/videoprocessor.cc index 0ed380cc86..fb79308054 100644 --- a/modules/video_coding/codecs/test/videoprocessor.cc +++ b/modules/video_coding/codecs/test/videoprocessor.cc @@ -30,6 +30,7 @@ namespace test { namespace { const int kRtpClockRateHz = 90000; +const int64_t kNoRenderTime = 0; std::unique_ptr CreateBitrateAllocator( TestConfig* config) { @@ -170,16 +171,11 @@ void VideoProcessor::ProcessFrame() { kRtpClockRateHz / config_.codec_settings.maxFramerate; rtp_timestamp_to_frame_num_[rtp_timestamp] = last_inputed_frame_num_; - const int64_t kNoRenderTime = 0; VideoFrame source_frame(buffer, rtp_timestamp, kNoRenderTime, webrtc::kVideoRotation_0); - // Decide if we are going to force a keyframe. - std::vector frame_types(1, kVideoFrameDelta); - if (config_.keyframe_interval > 0 && - last_inputed_frame_num_ % config_.keyframe_interval == 0) { - frame_types[0] = kVideoFrameKey; - } + std::vector frame_types = + config_.FrameTypeForFrame(last_inputed_frame_num_); // Create frame statistics object used for aggregation at end of test run. FrameStatistic* frame_stat = stats_->AddFrame(); @@ -321,10 +317,8 @@ void VideoProcessor::FrameDecoded(const VideoFrame& image) { RTC_CHECK_GE(last_decoded_frame_num_, 0); const FrameStatistic* last_decoded_frame_stat = stats_->GetFrame(last_decoded_frame_num_); - if (static_cast(image.width()) != - last_decoded_frame_stat->decoded_width || - static_cast(image.height()) != - last_decoded_frame_stat->decoded_height) { + if (image.width() != last_decoded_frame_stat->decoded_width || + image.height() != last_decoded_frame_stat->decoded_height) { RTC_CHECK_GE(rate_update_index_, 0); ++num_spatial_resizes_[rate_update_index_]; }