 Chromium Code Reviews
 Chromium Code Reviews Issue 3009423002:
  VideoProcessorIntegrationTest: Group member variables into two structs containing target/actual rate  (Closed)
    
  
    Issue 3009423002:
  VideoProcessorIntegrationTest: Group member variables into two structs containing target/actual rate  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 
| 3 * | 3 * | 
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license | 
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source | 
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found | 
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may | 
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. | 
| 9 */ | 9 */ | 
| 10 | 10 | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "modules/video_coding/utility/ivf_file_writer.h" | 24 #include "modules/video_coding/utility/ivf_file_writer.h" | 
| 25 #include "test/gtest.h" | 25 #include "test/gtest.h" | 
| 26 #include "test/testsupport/frame_reader.h" | 26 #include "test/testsupport/frame_reader.h" | 
| 27 #include "test/testsupport/frame_writer.h" | 27 #include "test/testsupport/frame_writer.h" | 
| 28 #include "test/testsupport/packet_reader.h" | 28 #include "test/testsupport/packet_reader.h" | 
| 29 | 29 | 
| 30 namespace webrtc { | 30 namespace webrtc { | 
| 31 namespace test { | 31 namespace test { | 
| 32 | 32 | 
| 33 // The sequence of bit rate and frame rate changes for the encoder, the frame | 33 // The sequence of bit rate and frame rate changes for the encoder, the frame | 
| 34 // number where the changes are made, and the total number of frames for the | 34 // number where the changes are made, and the total number of frames to process. | 
| 35 // test. | |
| 36 struct RateProfile { | 35 struct RateProfile { | 
| 37 static const int kMaxNumRateUpdates = 3; | 36 static const int kMaxNumRateUpdates = 3; | 
| 38 | 37 | 
| 39 int target_bit_rate[kMaxNumRateUpdates]; | 38 int target_bit_rate[kMaxNumRateUpdates]; | 
| 40 int input_frame_rate[kMaxNumRateUpdates]; | 39 int input_frame_rate[kMaxNumRateUpdates]; | 
| 41 int frame_index_rate_update[kMaxNumRateUpdates + 1]; | 40 int frame_index_rate_update[kMaxNumRateUpdates + 1]; | 
| 42 int num_frames; | 41 int num_frames; | 
| 43 }; | 42 }; | 
| 44 | 43 | 
| 45 // Thresholds for the rate control metrics. The rate mismatch thresholds are | 44 // Thresholds for the rate control metrics. The thresholds are defined for each | 
| 46 // defined as percentages. |max_time_hit_target| is defined as number of frames, | 45 // rate update sequence. |max_num_frames_to_hit_target| is defined as number of | 
| 47 // after a rate update is made to the encoder, for the encoder to reach within | 46 // frames, after a rate update is made to the encoder, for the encoder to reach | 
| 48 // |kPercTargetvsActualMismatch| of new target rate. The thresholds are defined | 47 // |kMaxBitrateMismatchPercent| of new target rate. | 
| 49 // for each rate update sequence. | |
| 50 struct RateControlThresholds { | 48 struct RateControlThresholds { | 
| 51 int max_num_dropped_frames; | 49 int max_num_dropped_frames; | 
| 52 int max_key_frame_size_mismatch; | 50 int max_key_framesize_mismatch_percent; | 
| 53 int max_delta_frame_size_mismatch; | 51 int max_delta_framesize_mismatch_percent; | 
| 54 int max_encoding_rate_mismatch; | 52 int max_bitrate_mismatch_percent; | 
| 55 int max_time_hit_target; | 53 int max_num_frames_to_hit_target; | 
| 56 int num_spatial_resizes; | 54 int num_spatial_resizes; | 
| 57 int num_key_frames; | 55 int num_key_frames; | 
| 58 }; | 56 }; | 
| 59 | 57 | 
| 60 // Thresholds for the quality metrics. | 58 // Thresholds for the quality metrics. | 
| 61 struct QualityThresholds { | 59 struct QualityThresholds { | 
| 62 QualityThresholds(double min_avg_psnr, | 60 QualityThresholds(double min_avg_psnr, | 
| 63 double min_min_psnr, | 61 double min_min_psnr, | 
| 64 double min_avg_ssim, | 62 double min_avg_ssim, | 
| 65 double min_min_ssim) | 63 double min_min_ssim) | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 int height); | 103 int height); | 
| 106 | 104 | 
| 107 static void SetRateProfile(RateProfile* rate_profile, | 105 static void SetRateProfile(RateProfile* rate_profile, | 
| 108 int rate_update_index, | 106 int rate_update_index, | 
| 109 int bitrate_kbps, | 107 int bitrate_kbps, | 
| 110 int framerate_fps, | 108 int framerate_fps, | 
| 111 int frame_index_rate_update); | 109 int frame_index_rate_update); | 
| 112 | 110 | 
| 113 static void AddRateControlThresholds( | 111 static void AddRateControlThresholds( | 
| 114 int max_num_dropped_frames, | 112 int max_num_dropped_frames, | 
| 115 int max_key_frame_size_mismatch, | 113 int max_key_framesize_mismatch_percent, | 
| 116 int max_delta_frame_size_mismatch, | 114 int max_delta_framesize_mismatch_percent, | 
| 117 int max_encoding_rate_mismatch, | 115 int max_bitrate_mismatch_percent, | 
| 118 int max_time_hit_target, | 116 int max_num_frames_to_hit_target, | 
| 119 int num_spatial_resizes, | 117 int num_spatial_resizes, | 
| 120 int num_key_frames, | 118 int num_key_frames, | 
| 121 std::vector<RateControlThresholds>* rc_thresholds); | 119 std::vector<RateControlThresholds>* rc_thresholds); | 
| 122 | 120 | 
| 123 void ProcessFramesAndMaybeVerify( | 121 void ProcessFramesAndMaybeVerify( | 
| 124 const RateProfile& rate_profile, | 122 const RateProfile& rate_profile, | 
| 125 const std::vector<RateControlThresholds>* rc_thresholds, | 123 const std::vector<RateControlThresholds>* rc_thresholds, | 
| 126 const QualityThresholds* quality_thresholds, | 124 const QualityThresholds* quality_thresholds, | 
| 127 const VisualizationParams* visualization_params); | 125 const VisualizationParams* visualization_params); | 
| 128 | 126 | 
| 129 // Config. | 127 // Config. | 
| 130 TestConfig config_; | 128 TestConfig config_; | 
| 131 | 129 | 
| 132 private: | 130 private: | 
| 133 static const int kMaxNumTemporalLayers = 3; | 131 static const int kMaxNumTemporalLayers = 3; | 
| 134 | 132 | 
| 135 void CreateEncoderAndDecoder(); | 133 void CreateEncoderAndDecoder(); | 
| 136 void DestroyEncoderAndDecoder(); | 134 void DestroyEncoderAndDecoder(); | 
| 137 void SetUpAndInitObjects(rtc::TaskQueue* task_queue, | 135 void SetUpAndInitObjects(rtc::TaskQueue* task_queue, | 
| 138 const int initial_bitrate_kbps, | 136 const int initial_bitrate_kbps, | 
| 139 const int initial_framerate_fps, | 137 const int initial_framerate_fps, | 
| 140 const VisualizationParams* visualization_params); | 138 const VisualizationParams* visualization_params); | 
| 141 void ReleaseAndCloseObjects(rtc::TaskQueue* task_queue); | 139 void ReleaseAndCloseObjects(rtc::TaskQueue* task_queue); | 
| 140 int TemporalLayerIndexForFrame(int frame_number) const; | |
| 141 | |
| 142 // Rate control metrics. | |
| 143 void ResetRateControlMetrics(int rate_update_index, | |
| 144 const RateProfile& rate_profile); | |
| 142 void UpdateRateControlMetrics(int frame_number); | 145 void UpdateRateControlMetrics(int frame_number); | 
| 143 void PrintAndMaybeVerifyRateControlMetrics( | 146 void PrintAndMaybeVerifyRateControlMetrics( | 
| 144 int rate_update_index, | 147 int rate_update_index, | 
| 145 const std::vector<RateControlThresholds>* rc_thresholds, | 148 const std::vector<RateControlThresholds>* rc_thresholds, | 
| 146 const std::vector<int>& num_dropped_frames, | 149 const std::vector<int>& num_dropped_frames, | 
| 147 const std::vector<int>& num_resize_actions); | 150 const std::vector<int>& num_spatial_resizes) const; | 
| 148 int TemporalLayerIndexForFrame(int frame_number) const; | 151 void PrintRateControlMetrics( | 
| 
brandtr
2017/09/21 08:40:10
Declare above PrintAndMaybeVerifyRateControlMetric
 
åsapersson
2017/09/22 08:06:50
Done.
 | |
| 149 void ResetRateControlMetrics(int rate_update_index, | 152 int rate_update_index, | 
| 150 const RateProfile& rate_profile); | 153 const std::vector<int>& num_dropped_frames, | 
| 154 const std::vector<int>& num_spatial_resizes) const; | |
| 151 | 155 | 
| 152 // Codecs. | 156 // Codecs. | 
| 153 std::unique_ptr<VideoEncoder> encoder_; | 157 std::unique_ptr<VideoEncoder> encoder_; | 
| 154 std::unique_ptr<cricket::WebRtcVideoDecoderFactory> decoder_factory_; | 158 std::unique_ptr<cricket::WebRtcVideoDecoderFactory> decoder_factory_; | 
| 155 VideoDecoder* decoder_; | 159 VideoDecoder* decoder_; | 
| 156 | 160 | 
| 157 // Helper objects. | 161 // Helper objects. | 
| 158 std::unique_ptr<FrameReader> analysis_frame_reader_; | 162 std::unique_ptr<FrameReader> analysis_frame_reader_; | 
| 159 std::unique_ptr<FrameWriter> analysis_frame_writer_; | 163 std::unique_ptr<FrameWriter> analysis_frame_writer_; | 
| 160 std::unique_ptr<IvfFileWriter> encoded_frame_writer_; | 164 std::unique_ptr<IvfFileWriter> encoded_frame_writer_; | 
| 161 std::unique_ptr<FrameWriter> decoded_frame_writer_; | 165 std::unique_ptr<FrameWriter> decoded_frame_writer_; | 
| 162 PacketReader packet_reader_; | 166 PacketReader packet_reader_; | 
| 163 std::unique_ptr<PacketManipulator> packet_manipulator_; | 167 std::unique_ptr<PacketManipulator> packet_manipulator_; | 
| 164 Stats stats_; | 168 Stats stats_; | 
| 165 std::unique_ptr<VideoProcessor> processor_; | 169 std::unique_ptr<VideoProcessor> processor_; | 
| 166 | 170 | 
| 167 // Quantities defined/updated for every encoder rate update. | 171 // Quantities updated for every encoded frame. | 
| 168 int num_frames_per_update_[kMaxNumTemporalLayers]; | 172 struct TestResults { | 
| 
brandtr
2017/09/21 08:40:10
Move definition to the top of the private: section
 
åsapersson
2017/09/22 08:06:50
Done.
 | |
| 169 float sum_frame_size_mismatch_[kMaxNumTemporalLayers]; | 173 int KeyFrameSizeMismatchPercent() const { | 
| 170 float sum_encoded_frame_size_[kMaxNumTemporalLayers]; | 174 if (num_key_frames == 0) { | 
| 171 float encoding_bitrate_[kMaxNumTemporalLayers]; | 175 return -1; | 
| 172 float per_frame_bandwidth_[kMaxNumTemporalLayers]; | 176 } | 
| 173 float bitrate_layer_[kMaxNumTemporalLayers]; | 177 return 100 * sum_key_framesize_mismatch / num_key_frames; | 
| 174 float framerate_layer_[kMaxNumTemporalLayers]; | 178 } | 
| 175 int num_frames_total_; | 179 int DeltaFrameSizeMismatchPercent(int i) const { | 
| 
brandtr
2017/09/21 08:40:10
In a followup CL, it would be nice to output the p
 
åsapersson
2017/09/22 08:06:50
Acknowledged.
 | |
| 176 float sum_encoded_frame_size_total_; | 180 return 100 * sum_delta_framesize_mismatch_layer[i] / num_frames_layer[i]; | 
| 177 float encoding_bitrate_total_; | 181 } | 
| 178 float perc_encoding_rate_mismatch_; | 182 int BitrateMismatchPercent(float target_kbps) const { | 
| 179 int num_frames_to_hit_target_; | 183 return 100 * fabs(kbps - target_kbps) / target_kbps; | 
| 180 bool encoding_rate_within_target_; | 184 } | 
| 181 int bitrate_kbps_; | 185 int BitrateMismatchPercent(int i, float target_kbps_layer) const { | 
| 182 int framerate_; | 186 return 100 * fabs(kbps_layer[i] - target_kbps_layer) / target_kbps_layer; | 
| 183 float target_size_key_frame_initial_; | 187 } | 
| 184 float target_size_key_frame_; | 188 int num_frames = 0; | 
| 185 float sum_key_frame_size_mismatch_; | 189 int num_frames_layer[kMaxNumTemporalLayers] = {0}; | 
| 186 int num_key_frames_; | 190 int num_key_frames = 0; | 
| 191 int num_frames_to_hit_target = 0; | |
| 192 float sum_framesize_kbits = 0.0f; | |
| 193 float sum_framesize_kbits_layer[kMaxNumTemporalLayers] = {0}; | |
| 194 float kbps = 0.0f; | |
| 195 float kbps_layer[kMaxNumTemporalLayers] = {0}; | |
| 196 float sum_key_framesize_mismatch = 0.0f; | |
| 197 float sum_delta_framesize_mismatch_layer[kMaxNumTemporalLayers] = {0}; | |
| 198 }; | |
| 199 TestResults actual_; | |
| 
brandtr
2017/09/21 08:40:10
What do you think about getting rid of |actual_| a
 
åsapersson
2017/09/22 08:06:50
Sounds good.
 | |
| 200 | |
| 201 // Rates set for every encoder rate update. | |
| 202 struct TargetRates { | |
| 203 int kbps; | |
| 204 int fps; | |
| 205 float kbps_layer[kMaxNumTemporalLayers]; | |
| 206 float fps_layer[kMaxNumTemporalLayers]; | |
| 207 float framesize_kbits_layer[kMaxNumTemporalLayers]; | |
| 208 float key_framesize_kbits_initial; | |
| 209 float key_framesize_kbits; | |
| 210 }; | |
| 211 void SetRatesPerTemporalLayer(); | |
| 212 TargetRates target_; | |
| 187 }; | 213 }; | 
| 188 | 214 | 
| 189 } // namespace test | 215 } // namespace test | 
| 190 } // namespace webrtc | 216 } // namespace webrtc | 
| 191 | 217 | 
| 192 #endif // MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTEST_H_ | 218 #endif // MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_INTEGRATIONTEST_H_ | 
| OLD | NEW |