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