1 /* 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_VIDEO_CODING_CODECS_TEST_VIDEOCODEC_TEST_STATS_IMPL_H_ 12 #define MODULES_VIDEO_CODING_CODECS_TEST_VIDEOCODEC_TEST_STATS_IMPL_H_ 13 14 #include <stddef.h> 15 16 #include <map> 17 #include <string> 18 #include <vector> 19 20 #include "api/test/videocodec_test_stats.h" // NOLINT(build/include) 21 22 namespace webrtc { 23 namespace test { 24 25 // Statistics for a sequence of processed frames. This class is not thread safe. 26 class VideoCodecTestStatsImpl : public VideoCodecTestStats { 27 public: 28 VideoCodecTestStatsImpl(); 29 ~VideoCodecTestStatsImpl() override; 30 31 // Creates a FrameStatistics for the next frame to be processed. 32 void AddFrame(const FrameStatistics& frame_stat); 33 34 // Returns the FrameStatistics corresponding to |frame_number| or |timestamp|. 35 FrameStatistics* GetFrame(size_t frame_number, size_t spatial_idx); 36 FrameStatistics* GetFrameWithTimestamp(size_t timestamp, size_t spatial_idx); 37 38 // Implements VideoCodecTestStats. 39 std::vector<FrameStatistics> GetFrameStatistics() override; 40 std::vector<VideoStatistics> SliceAndCalcLayerVideoStatistic( 41 size_t first_frame_num, 42 size_t last_frame_num) override; 43 44 VideoStatistics SliceAndCalcAggregatedVideoStatistic(size_t first_frame_num, 45 size_t last_frame_num); 46 47 size_t Size(size_t spatial_idx); 48 49 void Clear(); 50 51 private: 52 VideoCodecTestStats::FrameStatistics AggregateFrameStatistic( 53 size_t frame_num, 54 size_t spatial_idx, 55 bool aggregate_independent_layers); 56 57 size_t CalcLayerTargetBitrateKbps(size_t first_frame_num, 58 size_t last_frame_num, 59 size_t spatial_idx, 60 size_t temporal_idx, 61 bool aggregate_independent_layers); 62 63 VideoCodecTestStats::VideoStatistics SliceAndCalcVideoStatistic( 64 size_t first_frame_num, 65 size_t last_frame_num, 66 size_t spatial_idx, 67 size_t temporal_idx, 68 bool aggregate_independent_layers); 69 70 void GetNumberOfEncodedLayers(size_t first_frame_num, 71 size_t last_frame_num, 72 size_t* num_encoded_spatial_layers, 73 size_t* num_encoded_temporal_layers); 74 75 // layer_idx -> stats. 76 std::map<size_t, std::vector<FrameStatistics>> layer_stats_; 77 // layer_idx -> rtp_timestamp -> frame_num. 78 std::map<size_t, std::map<size_t, size_t>> rtp_timestamp_to_frame_num_; 79 }; 80 81 } // namespace test 82 } // namespace webrtc 83 84 #endif // MODULES_VIDEO_CODING_CODECS_TEST_VIDEOCODEC_TEST_STATS_IMPL_H_ 85