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 |
11 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ |
12 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ |
13 | 13 |
| 14 #include <map> |
14 #include <memory> | 15 #include <memory> |
15 #include <string> | 16 #include <string> |
16 #include <vector> | 17 #include <vector> |
17 | 18 |
18 #include "webrtc/api/video/video_frame.h" | 19 #include "webrtc/api/video/video_frame.h" |
19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 20 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
20 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" | 21 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" |
21 #include "webrtc/modules/video_coding/codecs/test/stats.h" | 22 #include "webrtc/modules/video_coding/codecs/test/stats.h" |
22 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 23 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
23 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 24 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // The codec settings to use for the test (target bitrate, video size, | 107 // The codec settings to use for the test (target bitrate, video size, |
107 // framerate and so on). This struct should be filled in using the | 108 // framerate and so on). This struct should be filled in using the |
108 // VideoCodingModule::Codec() method. | 109 // VideoCodingModule::Codec() method. |
109 webrtc::VideoCodec codec_settings; | 110 webrtc::VideoCodec codec_settings; |
110 | 111 |
111 // If printing of information to stdout shall be performed during processing. | 112 // If printing of information to stdout shall be performed during processing. |
112 bool verbose = true; | 113 bool verbose = true; |
113 | 114 |
114 // If HW or SW codec should be used. | 115 // If HW or SW codec should be used. |
115 bool hw_codec = false; | 116 bool hw_codec = false; |
116 | |
117 // In batch mode, the VideoProcessor is fed all the frames for processing | |
118 // before any metrics are calculated. This is useful for pipelining HW codecs, | |
119 // for which some calculated metrics otherwise would be incorrect. The | |
120 // downside with batch mode is that mid-test rate allocation is not supported. | |
121 bool batch_mode = false; | |
122 }; | 117 }; |
123 | 118 |
124 // Handles encoding/decoding of video using the VideoEncoder/VideoDecoder | 119 // Handles encoding/decoding of video using the VideoEncoder/VideoDecoder |
125 // interfaces. This is done in a sequential manner in order to be able to | 120 // interfaces. This is done in a sequential manner in order to be able to |
126 // measure times properly. | 121 // measure times properly. |
127 // The class processes a frame at the time for the configured input file. | 122 // The class processes a frame at the time for the configured input file. |
128 // It maintains state of where in the source input file the processing is at. | 123 // It maintains state of where in the source input file the processing is at. |
129 // | 124 // |
130 // Regarding packet loss: Note that keyframes are excluded (first or all | 125 // Regarding packet loss: Note that keyframes are excluded (first or all |
131 // depending on the ExcludeFrameTypes setting). This is because if key frames | 126 // depending on the ExcludeFrameTypes setting). This is because if key frames |
(...skipping 26 matching lines...) Expand all Loading... |
158 // Tears down callbacks and releases the encoder and decoder. | 153 // Tears down callbacks and releases the encoder and decoder. |
159 void Release(); | 154 void Release(); |
160 | 155 |
161 // Processes a single frame. The frames must be processed in order, and the | 156 // Processes a single frame. The frames must be processed in order, and the |
162 // VideoProcessor must be initialized first. | 157 // VideoProcessor must be initialized first. |
163 void ProcessFrame(int frame_number); | 158 void ProcessFrame(int frame_number); |
164 | 159 |
165 // Updates the encoder with target rates. Must be called at least once. | 160 // Updates the encoder with target rates. Must be called at least once. |
166 void SetRates(int bitrate_kbps, int framerate_fps); | 161 void SetRates(int bitrate_kbps, int framerate_fps); |
167 | 162 |
168 | |
169 // TODO(brandtr): Get rid of these functions by moving the corresponding QP | 163 // TODO(brandtr): Get rid of these functions by moving the corresponding QP |
170 // fields to the Stats object. | 164 // fields to the Stats object. |
171 int GetQpFromEncoder(int frame_number) const; | 165 int GetQpFromEncoder(int frame_number) const; |
172 int GetQpFromBitstream(int frame_number) const; | 166 int GetQpFromBitstream(int frame_number) const; |
173 | 167 |
| 168 // Returns the number of dropped frames. |
| 169 std::vector<int> NumberDroppedFramesPerRateUpdate() const; |
174 | 170 |
175 // Return the number of dropped frames. | 171 // Returns the number of spatial resizes. |
176 int NumberDroppedFrames(); | 172 std::vector<int> NumberSpatialResizesPerRateUpdate() const; |
177 | 173 |
178 // Return the number of spatial resizes. | 174 int LastDecodedFrameNumber() const; |
179 int NumberSpatialResizes(); | |
180 | 175 |
181 private: | 176 private: |
182 // Container that holds per-frame information that needs to be stored between | 177 // Container that holds per-frame information that needs to be stored between |
183 // calls to Encode and Decode, as well as the corresponding callbacks. It is | 178 // calls to Encode and Decode, as well as the corresponding callbacks. It is |
184 // not directly used for statistics -- for that, test::FrameStatistic is used. | 179 // not directly used for statistics -- for that, test::FrameStatistic is used. |
185 // TODO(brandtr): Get rid of this struct and use the Stats class instead. | 180 // TODO(brandtr): Get rid of this struct and use the Stats class instead. |
186 struct FrameInfo { | 181 struct FrameInfo { |
187 int64_t encode_start_ns = 0; | 182 int64_t encode_start_ns = 0; |
188 int64_t decode_start_ns = 0; | 183 int64_t decode_start_ns = 0; |
189 int qp_encoder = 0; | 184 int qp_encoder = 0; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 }; | 284 }; |
290 | 285 |
291 // Invoked by the callback adapter when a frame has completed encoding. | 286 // Invoked by the callback adapter when a frame has completed encoding. |
292 void FrameEncoded(webrtc::VideoCodecType codec, | 287 void FrameEncoded(webrtc::VideoCodecType codec, |
293 const webrtc::EncodedImage& encodedImage, | 288 const webrtc::EncodedImage& encodedImage, |
294 const webrtc::RTPFragmentationHeader* fragmentation); | 289 const webrtc::RTPFragmentationHeader* fragmentation); |
295 | 290 |
296 // Invoked by the callback adapter when a frame has completed decoding. | 291 // Invoked by the callback adapter when a frame has completed decoding. |
297 void FrameDecoded(const webrtc::VideoFrame& image); | 292 void FrameDecoded(const webrtc::VideoFrame& image); |
298 | 293 |
299 // Use the frame number as the basis for timestamp to identify frames. Let the | |
300 // first timestamp be non-zero, to not make the IvfFileWriter believe that we | |
301 // want to use capture timestamps in the IVF files. | |
302 uint32_t FrameNumberToTimestamp(int frame_number) const; | |
303 int TimestampToFrameNumber(uint32_t timestamp) const; | |
304 | |
305 bool initialized_ GUARDED_BY(sequence_checker_); | 294 bool initialized_ GUARDED_BY(sequence_checker_); |
306 | |
307 TestConfig config_ GUARDED_BY(sequence_checker_); | 295 TestConfig config_ GUARDED_BY(sequence_checker_); |
308 | 296 |
309 webrtc::VideoEncoder* const encoder_; | 297 webrtc::VideoEncoder* const encoder_; |
310 webrtc::VideoDecoder* const decoder_; | 298 webrtc::VideoDecoder* const decoder_; |
311 const std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_; | 299 const std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_; |
312 | 300 |
313 // Adapters for the codec callbacks. | 301 // Adapters for the codec callbacks. |
314 VideoProcessorEncodeCompleteCallback encode_callback_; | 302 VideoProcessorEncodeCompleteCallback encode_callback_; |
315 VideoProcessorDecodeCompleteCallback decode_callback_; | 303 VideoProcessorDecodeCompleteCallback decode_callback_; |
316 | 304 |
(...skipping 12 matching lines...) Expand all Loading... |
329 IvfFileWriter* const encoded_frame_writer_; | 317 IvfFileWriter* const encoded_frame_writer_; |
330 FrameWriter* const decoded_frame_writer_; | 318 FrameWriter* const decoded_frame_writer_; |
331 | 319 |
332 // Frame metadata for all frames that have been added through a call to | 320 // Frame metadata for all frames that have been added through a call to |
333 // ProcessFrames(). We need to store this metadata over the course of the | 321 // ProcessFrames(). We need to store this metadata over the course of the |
334 // test run, to support pipelining HW codecs. | 322 // test run, to support pipelining HW codecs. |
335 std::vector<FrameInfo> frame_infos_ GUARDED_BY(sequence_checker_); | 323 std::vector<FrameInfo> frame_infos_ GUARDED_BY(sequence_checker_); |
336 int last_encoded_frame_num_ GUARDED_BY(sequence_checker_); | 324 int last_encoded_frame_num_ GUARDED_BY(sequence_checker_); |
337 int last_decoded_frame_num_ GUARDED_BY(sequence_checker_); | 325 int last_decoded_frame_num_ GUARDED_BY(sequence_checker_); |
338 | 326 |
| 327 // Store an RTP timestamp -> frame number map, since the timestamps are |
| 328 // based off of the frame rate, which can change mid-test. |
| 329 std::map<uint32_t, int> rtp_timestamp_to_frame_num_ |
| 330 GUARDED_BY(sequence_checker_); |
| 331 |
339 // Keep track of if we have excluded the first key frame from packet loss. | 332 // Keep track of if we have excluded the first key frame from packet loss. |
340 bool first_key_frame_has_been_excluded_ GUARDED_BY(sequence_checker_); | 333 bool first_key_frame_has_been_excluded_ GUARDED_BY(sequence_checker_); |
341 | 334 |
342 // Keep track of the last successfully decoded frame, since we write that | 335 // Keep track of the last successfully decoded frame, since we write that |
343 // frame to disk when decoding fails. | 336 // frame to disk when decoding fails. |
344 rtc::Buffer last_decoded_frame_buffer_ GUARDED_BY(sequence_checker_); | 337 rtc::Buffer last_decoded_frame_buffer_ GUARDED_BY(sequence_checker_); |
345 | 338 |
346 // Statistics. | 339 // Statistics. |
347 Stats* stats_; | 340 Stats* stats_; |
348 int num_dropped_frames_ GUARDED_BY(sequence_checker_); | 341 std::vector<int> num_dropped_frames_ GUARDED_BY(sequence_checker_); |
349 int num_spatial_resizes_ GUARDED_BY(sequence_checker_); | 342 std::vector<int> num_spatial_resizes_ GUARDED_BY(sequence_checker_); |
| 343 int rate_update_index_ GUARDED_BY(sequence_checker_); |
350 | 344 |
351 rtc::SequencedTaskChecker sequence_checker_; | 345 rtc::SequencedTaskChecker sequence_checker_; |
352 | 346 |
353 RTC_DISALLOW_COPY_AND_ASSIGN(VideoProcessor); | 347 RTC_DISALLOW_COPY_AND_ASSIGN(VideoProcessor); |
354 }; | 348 }; |
355 | 349 |
356 } // namespace test | 350 } // namespace test |
357 } // namespace webrtc | 351 } // namespace webrtc |
358 | 352 |
359 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ | 353 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ |
OLD | NEW |