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 <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/api/video/video_frame.h" | 18 #include "webrtc/api/video/video_frame.h" |
19 #include "webrtc/base/buffer.h" | 19 #include "webrtc/base/buffer.h" |
20 #include "webrtc/base/checks.h" | 20 #include "webrtc/base/checks.h" |
| 21 #include "webrtc/base/sequenced_task_checker.h" |
21 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.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/codecs/test/packet_manipulator.h" | 24 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" |
24 #include "webrtc/modules/video_coding/codecs/test/stats.h" | 25 #include "webrtc/modules/video_coding/codecs/test/stats.h" |
25 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 26 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
26 #include "webrtc/test/testsupport/frame_reader.h" | 27 #include "webrtc/test/testsupport/frame_reader.h" |
27 #include "webrtc/test/testsupport/frame_writer.h" | 28 #include "webrtc/test/testsupport/frame_writer.h" |
28 | 29 |
29 namespace webrtc { | 30 namespace webrtc { |
30 | 31 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // Regarding packet loss: Note that keyframes are excluded (first or all | 122 // Regarding packet loss: Note that keyframes are excluded (first or all |
122 // depending on the ExcludeFrameTypes setting). This is because if key frames | 123 // depending on the ExcludeFrameTypes setting). This is because if key frames |
123 // would be altered, all the following delta frames would be pretty much | 124 // would be altered, all the following delta frames would be pretty much |
124 // worthless. VP8 has an error-resilience feature that makes it able to handle | 125 // worthless. VP8 has an error-resilience feature that makes it able to handle |
125 // packet loss in key non-first keyframes, which is why only the first is | 126 // packet loss in key non-first keyframes, which is why only the first is |
126 // excluded by default. | 127 // excluded by default. |
127 // Packet loss in such important frames is handled on a higher level in the | 128 // Packet loss in such important frames is handled on a higher level in the |
128 // Video Engine, where signaling would request a retransmit of the lost packets, | 129 // Video Engine, where signaling would request a retransmit of the lost packets, |
129 // since they're so important. | 130 // since they're so important. |
130 // | 131 // |
131 // Note this class is not thread safe in any way and is meant for simple testing | 132 // This class should be run on a single thread, or a single task queue. |
132 // purposes. | |
133 class VideoProcessor { | 133 class VideoProcessor { |
134 public: | 134 public: |
135 virtual ~VideoProcessor() {} | 135 virtual ~VideoProcessor() = default; |
136 | 136 |
137 // Performs initial calculations about frame size, sets up callbacks etc. | 137 // Performs initial calculations about frame size, sets up callbacks etc. |
138 // Returns false if an error has occurred, in addition to printing to stderr. | 138 // Returns false if an error has occurred, in addition to printing to stderr. |
139 virtual bool Init() = 0; | 139 virtual bool Init() = 0; |
140 | 140 |
| 141 virtual void DeregisterCallbacks() = 0; |
| 142 |
141 // Processes a single frame. Returns true as long as there's more frames | 143 // Processes a single frame. Returns true as long as there's more frames |
142 // available in the source clip. | 144 // available in the source clip. |
143 // Frame number must be an integer >= 0. | 145 // Frame number must be an integer >= 0. |
144 virtual bool ProcessFrame(int frame_number) = 0; | 146 virtual bool ProcessFrame(int frame_number) = 0; |
145 | 147 |
146 // Updates the encoder with the target bit rate and the frame rate. | 148 // Updates the encoder with the target bit rate and the frame rate. |
147 virtual void SetRates(int bit_rate, int frame_rate) = 0; | 149 virtual void SetRates(int bit_rate, int frame_rate) = 0; |
148 | 150 |
149 // Return the size of the encoded frame in bytes. Dropped frames by the | 151 // Return the size of the encoded frame in bytes. Dropped frames by the |
150 // encoder are regarded as zero size. | 152 // encoder are regarded as zero size. |
(...skipping 14 matching lines...) Expand all Loading... |
165 VideoProcessorImpl(webrtc::VideoEncoder* encoder, | 167 VideoProcessorImpl(webrtc::VideoEncoder* encoder, |
166 webrtc::VideoDecoder* decoder, | 168 webrtc::VideoDecoder* decoder, |
167 FrameReader* analysis_frame_reader, | 169 FrameReader* analysis_frame_reader, |
168 FrameWriter* analysis_frame_writer, | 170 FrameWriter* analysis_frame_writer, |
169 PacketManipulator* packet_manipulator, | 171 PacketManipulator* packet_manipulator, |
170 const TestConfig& config, | 172 const TestConfig& config, |
171 Stats* stats, | 173 Stats* stats, |
172 FrameWriter* source_frame_writer, | 174 FrameWriter* source_frame_writer, |
173 IvfFileWriter* encoded_frame_writer, | 175 IvfFileWriter* encoded_frame_writer, |
174 FrameWriter* decoded_frame_writer); | 176 FrameWriter* decoded_frame_writer); |
175 virtual ~VideoProcessorImpl(); | 177 ~VideoProcessorImpl() override; |
176 bool Init() override; | 178 bool Init() override; |
| 179 void DeregisterCallbacks() override; |
177 bool ProcessFrame(int frame_number) override; | 180 bool ProcessFrame(int frame_number) override; |
178 | 181 |
179 private: | 182 private: |
180 // Container that holds per-frame information that needs to be stored between | 183 // Container that holds per-frame information that needs to be stored between |
181 // calls to Encode and Decode, as well as the corresponding callbacks. It is | 184 // calls to Encode and Decode, as well as the corresponding callbacks. It is |
182 // not directly used for statistics -- for that, test::FrameStatistic is used. | 185 // not directly used for statistics -- for that, test::FrameStatistic is used. |
183 struct FrameInfo { | 186 struct FrameInfo { |
184 FrameInfo() | 187 FrameInfo() |
185 : timestamp(0), | 188 : timestamp(0), |
186 encode_start_ns(0), | 189 encode_start_ns(0), |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 267 |
265 // Return the encoded frame type (key or delta). | 268 // Return the encoded frame type (key or delta). |
266 FrameType EncodedFrameType(int frame_number) override; | 269 FrameType EncodedFrameType(int frame_number) override; |
267 | 270 |
268 // Return the number of dropped frames. | 271 // Return the number of dropped frames. |
269 int NumberDroppedFrames() override; | 272 int NumberDroppedFrames() override; |
270 | 273 |
271 // Return the number of spatial resizes. | 274 // Return the number of spatial resizes. |
272 int NumberSpatialResizes() override; | 275 int NumberSpatialResizes() override; |
273 | 276 |
274 webrtc::VideoEncoder* const encoder_; | 277 webrtc::VideoEncoder* const encoder_ PT_GUARDED_BY(task_checker_); |
275 webrtc::VideoDecoder* const decoder_; | 278 webrtc::VideoDecoder* const decoder_ PT_GUARDED_BY(task_checker_); |
276 const std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_; | 279 const std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_ |
| 280 PT_GUARDED_BY(task_checker_); |
277 | 281 |
278 // Adapters for the codec callbacks. | 282 // Adapters for the codec callbacks. |
279 const std::unique_ptr<EncodedImageCallback> encode_callback_; | 283 const std::unique_ptr<EncodedImageCallback> encode_callback_; |
280 const std::unique_ptr<DecodedImageCallback> decode_callback_; | 284 const std::unique_ptr<DecodedImageCallback> decode_callback_; |
281 | 285 |
282 PacketManipulator* const packet_manipulator_; | 286 PacketManipulator* const packet_manipulator_ PT_GUARDED_BY(task_checker_); |
283 const TestConfig& config_; | 287 const TestConfig& config_; |
284 | 288 |
285 // These (mandatory) file manipulators are used for, e.g., objective PSNR and | 289 // These (mandatory) file manipulators are used for, e.g., objective PSNR and |
286 // SSIM calculations at the end of a test run. | 290 // SSIM calculations at the end of a test run. |
287 FrameReader* const analysis_frame_reader_; | 291 FrameReader* const analysis_frame_reader_ PT_GUARDED_BY(task_checker_); |
288 FrameWriter* const analysis_frame_writer_; | 292 FrameWriter* const analysis_frame_writer_ PT_GUARDED_BY(task_checker_); |
289 const int num_frames_; | 293 const int num_frames_; |
290 | 294 |
291 // These (optional) file writers are used for persistently storing the output | 295 // These (optional) file writers are used for persistently storing the output |
292 // of the coding pipeline at different stages: pre encode (source), post | 296 // of the coding pipeline at different stages: pre encode (source), post |
293 // encode (encoded), and post decode (decoded). The purpose is to give the | 297 // encode (encoded), and post decode (decoded). The purpose is to give the |
294 // experimenter an option to subjectively evaluate the quality of the | 298 // experimenter an option to subjectively evaluate the quality of the |
295 // encoding, given the test settings. Each frame writer is enabled by being | 299 // encoding, given the test settings. Each frame writer is enabled by being |
296 // non-null. | 300 // non-null. |
297 FrameWriter* const source_frame_writer_; | 301 FrameWriter* const source_frame_writer_ PT_GUARDED_BY(task_checker_); |
298 IvfFileWriter* const encoded_frame_writer_; | 302 IvfFileWriter* const encoded_frame_writer_ PT_GUARDED_BY(task_checker_); |
299 FrameWriter* const decoded_frame_writer_; | 303 FrameWriter* const decoded_frame_writer_ PT_GUARDED_BY(task_checker_); |
300 | 304 |
301 bool initialized_; | 305 bool initialized_ GUARDED_BY(task_checker_); |
302 | 306 |
303 // Frame metadata for all frames that have been added through a call to | 307 // Frame metadata for all frames that have been added through a call to |
304 // ProcessFrames(). We need to store this metadata over the course of the | 308 // ProcessFrames(). We need to store this metadata over the course of the |
305 // test run, to support pipelining HW codecs. | 309 // test run, to support pipelining HW codecs. |
306 std::vector<FrameInfo> frame_infos_; | 310 std::vector<FrameInfo> frame_infos_ GUARDED_BY(task_checker_); |
307 int last_encoded_frame_num_; | 311 int last_encoded_frame_num_ GUARDED_BY(task_checker_); |
308 int last_decoded_frame_num_; | 312 int last_decoded_frame_num_ GUARDED_BY(task_checker_); |
309 | 313 |
310 // Keep track of if we have excluded the first key frame from packet loss. | 314 // Keep track of if we have excluded the first key frame from packet loss. |
311 bool first_key_frame_has_been_excluded_; | 315 bool first_key_frame_has_been_excluded_ GUARDED_BY(task_checker_); |
312 | 316 |
313 // Keep track of the last successfully decoded frame, since we write that | 317 // Keep track of the last successfully decoded frame, since we write that |
314 // frame to disk when decoding fails. | 318 // frame to disk when decoding fails. |
315 rtc::Buffer last_decoded_frame_buffer_; | 319 rtc::Buffer last_decoded_frame_buffer_ GUARDED_BY(task_checker_); |
316 | 320 |
317 // Statistics. | 321 // Statistics. |
318 Stats* stats_; | 322 Stats* stats_ PT_GUARDED_BY(task_checker_); |
319 int num_dropped_frames_; | 323 int num_dropped_frames_ GUARDED_BY(task_checker_); |
320 int num_spatial_resizes_; | 324 int num_spatial_resizes_ GUARDED_BY(task_checker_); |
321 double bit_rate_factor_; // Multiply frame length with this to get bit rate. | 325 // Multiply frame length with this to get bit rate. |
| 326 double bit_rate_factor_ GUARDED_BY(task_checker_); |
| 327 |
| 328 rtc::SequencedTaskChecker task_checker_; |
322 }; | 329 }; |
323 | 330 |
324 } // namespace test | 331 } // namespace test |
325 } // namespace webrtc | 332 } // namespace webrtc |
326 | 333 |
327 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ | 334 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ |
OLD | NEW |