kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | db2de5b | 2012-03-05 19:53:24 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 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 | */ |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 10 | |
pbos@webrtc.org | a440732 | 2013-07-16 12:32:05 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/video_coding/codecs/test/stats.h" |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 +0000 | [diff] [blame] | 13 | #include <assert.h> |
| 14 | #include <stdio.h> |
| 15 | |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 16 | #include <algorithm> // min_element, max_element |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 17 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 18 | #include "webrtc/base/format_macros.h" |
| 19 | |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 20 | namespace webrtc { |
| 21 | namespace test { |
| 22 | |
pbos@webrtc.org | 7f7162a | 2013-07-30 15:18:31 +0000 | [diff] [blame] | 23 | FrameStatistic::FrameStatistic() |
| 24 | : encoding_successful(false), |
| 25 | decoding_successful(false), |
| 26 | encode_return_code(0), |
| 27 | decode_return_code(0), |
| 28 | encode_time_in_us(0), |
| 29 | decode_time_in_us(0), |
| 30 | frame_number(0), |
| 31 | packets_dropped(0), |
| 32 | total_packets(0), |
| 33 | bit_rate_in_kbps(0), |
| 34 | encoded_frame_length_in_bytes(0), |
Peter Boström | 49e196a | 2015-10-23 15:58:18 +0200 | [diff] [blame^] | 35 | frame_type(kVideoFrameDelta) {} |
pbos@webrtc.org | 7f7162a | 2013-07-30 15:18:31 +0000 | [diff] [blame] | 36 | |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 37 | Stats::Stats() {} |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 38 | |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 39 | Stats::~Stats() {} |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 40 | |
| 41 | bool LessForEncodeTime(const FrameStatistic& s1, const FrameStatistic& s2) { |
| 42 | return s1.encode_time_in_us < s2.encode_time_in_us; |
| 43 | } |
| 44 | |
| 45 | bool LessForDecodeTime(const FrameStatistic& s1, const FrameStatistic& s2) { |
| 46 | return s1.decode_time_in_us < s2.decode_time_in_us; |
| 47 | } |
| 48 | |
| 49 | bool LessForEncodedSize(const FrameStatistic& s1, const FrameStatistic& s2) { |
| 50 | return s1.encoded_frame_length_in_bytes < s2.encoded_frame_length_in_bytes; |
| 51 | } |
| 52 | |
| 53 | bool LessForBitRate(const FrameStatistic& s1, const FrameStatistic& s2) { |
| 54 | return s1.bit_rate_in_kbps < s2.bit_rate_in_kbps; |
| 55 | } |
| 56 | |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 57 | FrameStatistic& Stats::NewFrame(int frame_number) { |
| 58 | assert(frame_number >= 0); |
| 59 | FrameStatistic stat; |
| 60 | stat.frame_number = frame_number; |
| 61 | stats_.push_back(stat); |
| 62 | return stats_[frame_number]; |
| 63 | } |
| 64 | |
| 65 | void Stats::PrintSummary() { |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 66 | printf("Processing summary:\n"); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 67 | if (stats_.size() == 0) { |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 68 | printf("No frame statistics have been logged yet.\n"); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 69 | return; |
| 70 | } |
| 71 | |
| 72 | // Calculate min, max, average and total encoding time |
| 73 | int total_encoding_time_in_us = 0; |
| 74 | int total_decoding_time_in_us = 0; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 75 | size_t total_encoded_frames_lengths = 0; |
| 76 | size_t total_encoded_key_frames_lengths = 0; |
| 77 | size_t total_encoded_nonkey_frames_lengths = 0; |
| 78 | size_t nbr_keyframes = 0; |
| 79 | size_t nbr_nonkeyframes = 0; |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 80 | |
| 81 | for (FrameStatisticsIterator it = stats_.begin(); |
| 82 | it != stats_.end(); ++it) { |
| 83 | total_encoding_time_in_us += it->encode_time_in_us; |
| 84 | total_decoding_time_in_us += it->decode_time_in_us; |
| 85 | total_encoded_frames_lengths += it->encoded_frame_length_in_bytes; |
Peter Boström | 49e196a | 2015-10-23 15:58:18 +0200 | [diff] [blame^] | 86 | if (it->frame_type == webrtc::kVideoFrameKey) { |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 87 | total_encoded_key_frames_lengths += it->encoded_frame_length_in_bytes; |
| 88 | nbr_keyframes++; |
| 89 | } else { |
| 90 | total_encoded_nonkey_frames_lengths += it->encoded_frame_length_in_bytes; |
| 91 | nbr_nonkeyframes++; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | FrameStatisticsIterator frame; |
| 96 | |
| 97 | // ENCODING |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 98 | printf("Encoding time:\n"); |
leozwang@webrtc.org | db2de5b | 2012-03-05 19:53:24 +0000 | [diff] [blame] | 99 | frame = std::min_element(stats_.begin(), |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 100 | stats_.end(), LessForEncodeTime); |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 101 | printf(" Min : %7d us (frame %d)\n", |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 102 | frame->encode_time_in_us, frame->frame_number); |
| 103 | |
leozwang@webrtc.org | db2de5b | 2012-03-05 19:53:24 +0000 | [diff] [blame] | 104 | frame = std::max_element(stats_.begin(), |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 105 | stats_.end(), LessForEncodeTime); |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 106 | printf(" Max : %7d us (frame %d)\n", |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 107 | frame->encode_time_in_us, frame->frame_number); |
| 108 | |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 109 | printf(" Average : %7d us\n", |
kjellander@webrtc.org | 7de6e10 | 2011-12-08 08:39:13 +0000 | [diff] [blame] | 110 | static_cast<int>(total_encoding_time_in_us / stats_.size())); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 111 | |
| 112 | // DECODING |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 113 | printf("Decoding time:\n"); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 114 | // only consider frames that were successfully decoded (packet loss may cause |
| 115 | // failures) |
| 116 | std::vector<FrameStatistic> decoded_frames; |
| 117 | for (std::vector<FrameStatistic>::iterator it = stats_.begin(); |
| 118 | it != stats_.end(); ++it) { |
| 119 | if (it->decoding_successful) { |
| 120 | decoded_frames.push_back(*it); |
| 121 | } |
| 122 | } |
| 123 | if (decoded_frames.size() == 0) { |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 124 | printf("No successfully decoded frames exist in this statistics.\n"); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 125 | } else { |
leozwang@webrtc.org | db2de5b | 2012-03-05 19:53:24 +0000 | [diff] [blame] | 126 | frame = std::min_element(decoded_frames.begin(), |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 127 | decoded_frames.end(), LessForDecodeTime); |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 128 | printf(" Min : %7d us (frame %d)\n", |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 129 | frame->decode_time_in_us, frame->frame_number); |
| 130 | |
leozwang@webrtc.org | db2de5b | 2012-03-05 19:53:24 +0000 | [diff] [blame] | 131 | frame = std::max_element(decoded_frames.begin(), |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 132 | decoded_frames.end(), LessForDecodeTime); |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 133 | printf(" Max : %7d us (frame %d)\n", |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 134 | frame->decode_time_in_us, frame->frame_number); |
| 135 | |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 136 | printf(" Average : %7d us\n", |
kjellander@webrtc.org | 7de6e10 | 2011-12-08 08:39:13 +0000 | [diff] [blame] | 137 | static_cast<int>(total_decoding_time_in_us / decoded_frames.size())); |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 138 | printf(" Failures: %d frames failed to decode.\n", |
kjellander@webrtc.org | 7de6e10 | 2011-12-08 08:39:13 +0000 | [diff] [blame] | 139 | static_cast<int>(stats_.size() - decoded_frames.size())); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | // SIZE |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 143 | printf("Frame sizes:\n"); |
leozwang@webrtc.org | db2de5b | 2012-03-05 19:53:24 +0000 | [diff] [blame] | 144 | frame = std::min_element(stats_.begin(), |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 145 | stats_.end(), LessForEncodedSize); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 146 | printf(" Min : %7" PRIuS " bytes (frame %d)\n", |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 147 | frame->encoded_frame_length_in_bytes, frame->frame_number); |
| 148 | |
leozwang@webrtc.org | db2de5b | 2012-03-05 19:53:24 +0000 | [diff] [blame] | 149 | frame = std::max_element(stats_.begin(), |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 150 | stats_.end(), LessForEncodedSize); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 151 | printf(" Max : %7" PRIuS " bytes (frame %d)\n", |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 152 | frame->encoded_frame_length_in_bytes, frame->frame_number); |
| 153 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 154 | printf(" Average : %7" PRIuS " bytes\n", |
| 155 | total_encoded_frames_lengths / stats_.size()); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 156 | if (nbr_keyframes > 0) { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 157 | printf(" Average key frame size : %7" PRIuS " bytes (%" PRIuS |
| 158 | " keyframes)\n", |
| 159 | total_encoded_key_frames_lengths / nbr_keyframes, nbr_keyframes); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 160 | } |
| 161 | if (nbr_nonkeyframes > 0) { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 162 | printf(" Average non-key frame size: %7" PRIuS " bytes (%" PRIuS |
| 163 | " frames)\n", |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 164 | total_encoded_nonkey_frames_lengths / nbr_nonkeyframes, |
| 165 | nbr_nonkeyframes); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | // BIT RATE |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 169 | printf("Bit rates:\n"); |
leozwang@webrtc.org | db2de5b | 2012-03-05 19:53:24 +0000 | [diff] [blame] | 170 | frame = std::min_element(stats_.begin(), |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 171 | stats_.end(), LessForBitRate); |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 172 | printf(" Min bit rate: %7d kbps (frame %d)\n", |
| 173 | frame->bit_rate_in_kbps, frame->frame_number); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 174 | |
leozwang@webrtc.org | db2de5b | 2012-03-05 19:53:24 +0000 | [diff] [blame] | 175 | frame = std::max_element(stats_.begin(), |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 176 | stats_.end(), LessForBitRate); |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 177 | printf(" Max bit rate: %7d kbps (frame %d)\n", |
| 178 | frame->bit_rate_in_kbps, frame->frame_number); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 179 | |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 180 | printf("\n"); |
| 181 | printf("Total encoding time : %7d ms.\n", |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 182 | total_encoding_time_in_us / 1000); |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 183 | printf("Total decoding time : %7d ms.\n", |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 184 | total_decoding_time_in_us / 1000); |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 185 | printf("Total processing time: %7d ms.\n", |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 186 | (total_encoding_time_in_us + total_decoding_time_in_us) / 1000); |
| 187 | } |
| 188 | |
| 189 | } // namespace test |
| 190 | } // namespace webrtc |