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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // Tears down callbacks and releases the encoder and decoder. | 153 // Tears down callbacks and releases the encoder and decoder. |
153 void Release(); | 154 void Release(); |
154 | 155 |
155 // 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 |
156 // VideoProcessor must be initialized first. | 157 // VideoProcessor must be initialized first. |
157 void ProcessFrame(int frame_number); | 158 void ProcessFrame(int frame_number); |
158 | 159 |
159 // 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. |
160 void SetRates(int bitrate_kbps, int framerate_fps); | 161 void SetRates(int bitrate_kbps, int framerate_fps); |
161 | 162 |
162 // Return the number of dropped frames. | 163 // Returns the number of dropped frames. |
163 int NumberDroppedFrames(); | 164 std::vector<int> NumberDroppedFramesPerRateUpdate() const; |
164 | 165 |
165 // Return the number of spatial resizes. | 166 // Returns the number of spatial resizes. |
166 int NumberSpatialResizes(); | 167 std::vector<int> NumberSpatialResizesPerRateUpdate() const; |
167 | 168 |
168 private: | 169 private: |
169 // Container that holds per-frame information that needs to be stored between | 170 // Container that holds per-frame information that needs to be stored between |
170 // calls to Encode and Decode, as well as the corresponding callbacks. It is | 171 // calls to Encode and Decode, as well as the corresponding callbacks. It is |
171 // not directly used for statistics -- for that, test::FrameStatistic is used. | 172 // not directly used for statistics -- for that, test::FrameStatistic is used. |
172 // TODO(brandtr): Get rid of this struct and use the Stats class instead. | 173 // TODO(brandtr): Get rid of this struct and use the Stats class instead. |
173 struct FrameInfo { | 174 struct FrameInfo { |
174 int64_t encode_start_ns = 0; | 175 int64_t encode_start_ns = 0; |
175 int64_t decode_start_ns = 0; | 176 int64_t decode_start_ns = 0; |
176 int decoded_width = 0; | 177 int decoded_width = 0; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 rtc::TaskQueue* const task_queue_; | 269 rtc::TaskQueue* const task_queue_; |
269 }; | 270 }; |
270 | 271 |
271 // Invoked by the callback adapter when a frame has completed encoding. | 272 // Invoked by the callback adapter when a frame has completed encoding. |
272 void FrameEncoded(webrtc::VideoCodecType codec, | 273 void FrameEncoded(webrtc::VideoCodecType codec, |
273 const webrtc::EncodedImage& encodedImage); | 274 const webrtc::EncodedImage& encodedImage); |
274 | 275 |
275 // Invoked by the callback adapter when a frame has completed decoding. | 276 // Invoked by the callback adapter when a frame has completed decoding. |
276 void FrameDecoded(const webrtc::VideoFrame& image); | 277 void FrameDecoded(const webrtc::VideoFrame& image); |
277 | 278 |
278 // Use the frame number as the basis for timestamp to identify frames. Let the | |
279 // first timestamp be non-zero, to not make the IvfFileWriter believe that we | |
280 // want to use capture timestamps in the IVF files. | |
281 uint32_t FrameNumberToTimestamp(int frame_number) const; | |
282 int TimestampToFrameNumber(uint32_t timestamp) const; | |
283 | |
284 bool initialized_ GUARDED_BY(sequence_checker_); | 279 bool initialized_ GUARDED_BY(sequence_checker_); |
285 | |
286 TestConfig config_ GUARDED_BY(sequence_checker_); | 280 TestConfig config_ GUARDED_BY(sequence_checker_); |
287 | 281 |
288 webrtc::VideoEncoder* const encoder_; | 282 webrtc::VideoEncoder* const encoder_; |
289 webrtc::VideoDecoder* const decoder_; | 283 webrtc::VideoDecoder* const decoder_; |
290 const std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_; | 284 const std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_; |
291 | 285 |
292 // Adapters for the codec callbacks. | 286 // Adapters for the codec callbacks. |
293 VideoProcessorEncodeCompleteCallback encode_callback_; | 287 VideoProcessorEncodeCompleteCallback encode_callback_; |
294 VideoProcessorDecodeCompleteCallback decode_callback_; | 288 VideoProcessorDecodeCompleteCallback decode_callback_; |
295 | 289 |
(...skipping 12 matching lines...) Expand all Loading... |
308 IvfFileWriter* const encoded_frame_writer_; | 302 IvfFileWriter* const encoded_frame_writer_; |
309 FrameWriter* const decoded_frame_writer_; | 303 FrameWriter* const decoded_frame_writer_; |
310 | 304 |
311 // Frame metadata for all frames that have been added through a call to | 305 // Frame metadata for all frames that have been added through a call to |
312 // ProcessFrames(). We need to store this metadata over the course of the | 306 // ProcessFrames(). We need to store this metadata over the course of the |
313 // test run, to support pipelining HW codecs. | 307 // test run, to support pipelining HW codecs. |
314 std::vector<FrameInfo> frame_infos_ GUARDED_BY(sequence_checker_); | 308 std::vector<FrameInfo> frame_infos_ GUARDED_BY(sequence_checker_); |
315 int last_encoded_frame_num_ GUARDED_BY(sequence_checker_); | 309 int last_encoded_frame_num_ GUARDED_BY(sequence_checker_); |
316 int last_decoded_frame_num_ GUARDED_BY(sequence_checker_); | 310 int last_decoded_frame_num_ GUARDED_BY(sequence_checker_); |
317 | 311 |
| 312 // Store an RTP timestamp -> frame number map, since the timestamps are |
| 313 // based off of the frame rate, which can change mid-test. |
| 314 std::map<uint32_t, int> rtp_timestamp_to_frame_num_ |
| 315 GUARDED_BY(sequence_checker_); |
| 316 |
318 // Keep track of if we have excluded the first key frame from packet loss. | 317 // Keep track of if we have excluded the first key frame from packet loss. |
319 bool first_key_frame_has_been_excluded_ GUARDED_BY(sequence_checker_); | 318 bool first_key_frame_has_been_excluded_ GUARDED_BY(sequence_checker_); |
320 | 319 |
321 // Keep track of the last successfully decoded frame, since we write that | 320 // Keep track of the last successfully decoded frame, since we write that |
322 // frame to disk when decoding fails. | 321 // frame to disk when decoding fails. |
323 rtc::Buffer last_decoded_frame_buffer_ GUARDED_BY(sequence_checker_); | 322 rtc::Buffer last_decoded_frame_buffer_ GUARDED_BY(sequence_checker_); |
324 | 323 |
325 // Statistics. | 324 // Statistics. |
326 Stats* stats_; | 325 Stats* stats_; |
327 int num_dropped_frames_ GUARDED_BY(sequence_checker_); | 326 std::vector<int> num_dropped_frames_ GUARDED_BY(sequence_checker_); |
328 int num_spatial_resizes_ GUARDED_BY(sequence_checker_); | 327 std::vector<int> num_spatial_resizes_ GUARDED_BY(sequence_checker_); |
| 328 int rate_update_index_ GUARDED_BY(sequence_checker_); |
329 | 329 |
330 rtc::SequencedTaskChecker sequence_checker_; | 330 rtc::SequencedTaskChecker sequence_checker_; |
331 | 331 |
332 RTC_DISALLOW_COPY_AND_ASSIGN(VideoProcessor); | 332 RTC_DISALLOW_COPY_AND_ASSIGN(VideoProcessor); |
333 }; | 333 }; |
334 | 334 |
335 } // namespace test | 335 } // namespace test |
336 } // namespace webrtc | 336 } // namespace webrtc |
337 | 337 |
338 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ | 338 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ |
OLD | NEW |