| 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/common_video/libyuv/include/webrtc_libyuv.h" | 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 20 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" | 20 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" |
| 21 #include "webrtc/modules/video_coding/codecs/test/stats.h" | 21 #include "webrtc/modules/video_coding/codecs/test/stats.h" |
| 22 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 22 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 23 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" | 23 #include "webrtc/modules/video_coding/utility/ivf_file_writer.h" |
| 24 #include "webrtc/modules/video_coding/utility/vp8_header_parser.h" | 24 #include "webrtc/modules/video_coding/utility/vp8_header_parser.h" |
| 25 #include "webrtc/modules/video_coding/utility/vp9_uncompressed_header_parser.h" | 25 #include "webrtc/modules/video_coding/utility/vp9_uncompressed_header_parser.h" |
| 26 #include "webrtc/rtc_base/buffer.h" | 26 #include "webrtc/rtc_base/buffer.h" |
| 27 #include "webrtc/rtc_base/checks.h" | 27 #include "webrtc/rtc_base/checks.h" |
| 28 #include "webrtc/rtc_base/constructormagic.h" |
| 28 #include "webrtc/test/testsupport/frame_reader.h" | 29 #include "webrtc/test/testsupport/frame_reader.h" |
| 29 #include "webrtc/test/testsupport/frame_writer.h" | 30 #include "webrtc/test/testsupport/frame_writer.h" |
| 30 | 31 |
| 31 namespace webrtc { | 32 namespace webrtc { |
| 32 | 33 |
| 33 class VideoBitrateAllocator; | 34 class VideoBitrateAllocator; |
| 34 | 35 |
| 35 namespace test { | 36 namespace test { |
| 36 | 37 |
| 37 // Defines which frame types shall be excluded from packet loss and when. | 38 // Defines which frame types shall be excluded from packet loss and when. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 IvfFileWriter* encoded_frame_writer, | 149 IvfFileWriter* encoded_frame_writer, |
| 149 FrameWriter* decoded_frame_writer); | 150 FrameWriter* decoded_frame_writer); |
| 150 ~VideoProcessor(); | 151 ~VideoProcessor(); |
| 151 | 152 |
| 152 // Sets up callbacks and initializes the encoder and decoder. | 153 // Sets up callbacks and initializes the encoder and decoder. |
| 153 void Init(); | 154 void Init(); |
| 154 | 155 |
| 155 // Tears down callbacks and releases the encoder and decoder. | 156 // Tears down callbacks and releases the encoder and decoder. |
| 156 void Release(); | 157 void Release(); |
| 157 | 158 |
| 158 // Processes a single frame. Returns true as long as there's more frames | 159 // Processes a single frame. The frames must be processed in order, and the |
| 159 // available in the source clip. | 160 // VideoProcessor must be initialized first. |
| 160 // |frame_number| must be an integer >= 0. | 161 void ProcessFrame(int frame_number); |
| 161 bool ProcessFrame(int frame_number); | |
| 162 | 162 |
| 163 // Updates the encoder with the target |bit_rate| and the |frame_rate|. | 163 // Updates the encoder with target rates. Must be called at least once. |
| 164 void SetRates(int bit_rate, int frame_rate); | 164 void SetRates(int bitrate_kbps, int framerate_fps); |
| 165 | 165 |
| 166 // Return the size of the encoded frame in bytes. Dropped frames by the | |
| 167 // encoder are regarded as zero size. | |
| 168 size_t EncodedFrameSize(int frame_number); | |
| 169 | 166 |
| 170 // Return the encoded frame type (key or delta). | 167 // TODO(brandtr): Get rid of these functions by moving the corresponding QP |
| 171 FrameType EncodedFrameType(int frame_number); | 168 // fields to the Stats object. |
| 169 int GetQpFromEncoder(int frame_number) const; |
| 170 int GetQpFromBitstream(int frame_number) const; |
| 172 | 171 |
| 173 // Return the qp used by encoder. | |
| 174 int GetQpFromEncoder(int frame_number); | |
| 175 | |
| 176 // Return the qp from the qp parser. | |
| 177 int GetQpFromBitstream(int frame_number); | |
| 178 | 172 |
| 179 // Return the number of dropped frames. | 173 // Return the number of dropped frames. |
| 180 int NumberDroppedFrames(); | 174 int NumberDroppedFrames(); |
| 181 | 175 |
| 182 // Return the number of spatial resizes. | 176 // Return the number of spatial resizes. |
| 183 int NumberSpatialResizes(); | 177 int NumberSpatialResizes(); |
| 184 | 178 |
| 185 private: | 179 private: |
| 186 // Container that holds per-frame information that needs to be stored between | 180 // Container that holds per-frame information that needs to be stored between |
| 187 // calls to Encode and Decode, as well as the corresponding callbacks. It is | 181 // calls to Encode and Decode, as well as the corresponding callbacks. It is |
| 188 // not directly used for statistics -- for that, test::FrameStatistic is used. | 182 // not directly used for statistics -- for that, test::FrameStatistic is used. |
| 183 // TODO(brandtr): Get rid of this struct and use the Stats class instead. |
| 189 struct FrameInfo { | 184 struct FrameInfo { |
| 190 FrameInfo() | 185 int64_t encode_start_ns = 0; |
| 191 : timestamp(0), | 186 int64_t decode_start_ns = 0; |
| 192 encode_start_ns(0), | 187 int qp_encoder = 0; |
| 193 decode_start_ns(0), | 188 int qp_bitstream = 0; |
| 194 encoded_frame_size(0), | 189 int decoded_width = 0; |
| 195 encoded_frame_type(kVideoFrameDelta), | 190 int decoded_height = 0; |
| 196 decoded_width(0), | 191 size_t manipulated_length = 0; |
| 197 decoded_height(0), | |
| 198 manipulated_length(0), | |
| 199 qp_encoder(0), | |
| 200 qp_bitstream(0) {} | |
| 201 | |
| 202 uint32_t timestamp; | |
| 203 int64_t encode_start_ns; | |
| 204 int64_t decode_start_ns; | |
| 205 size_t encoded_frame_size; | |
| 206 FrameType encoded_frame_type; | |
| 207 int decoded_width; | |
| 208 int decoded_height; | |
| 209 size_t manipulated_length; | |
| 210 int qp_encoder; | |
| 211 int qp_bitstream; | |
| 212 }; | 192 }; |
| 213 | 193 |
| 214 // Callback class required to implement according to the VideoEncoder API. | |
| 215 class VideoProcessorEncodeCompleteCallback | 194 class VideoProcessorEncodeCompleteCallback |
| 216 : public webrtc::EncodedImageCallback { | 195 : public webrtc::EncodedImageCallback { |
| 217 public: | 196 public: |
| 218 explicit VideoProcessorEncodeCompleteCallback( | 197 explicit VideoProcessorEncodeCompleteCallback( |
| 219 VideoProcessor* video_processor) | 198 VideoProcessor* video_processor) |
| 220 : video_processor_(video_processor) {} | 199 : video_processor_(video_processor) {} |
| 221 Result OnEncodedImage( | 200 Result OnEncodedImage( |
| 222 const webrtc::EncodedImage& encoded_image, | 201 const webrtc::EncodedImage& encoded_image, |
| 223 const webrtc::CodecSpecificInfo* codec_specific_info, | 202 const webrtc::CodecSpecificInfo* codec_specific_info, |
| 224 const webrtc::RTPFragmentationHeader* fragmentation) override { | 203 const webrtc::RTPFragmentationHeader* fragmentation) override { |
| 225 // Forward to parent class. | 204 // Forward to parent class. |
| 226 RTC_CHECK(codec_specific_info); | 205 RTC_CHECK(codec_specific_info); |
| 227 video_processor_->FrameEncoded(codec_specific_info->codecType, | 206 video_processor_->FrameEncoded(codec_specific_info->codecType, |
| 228 encoded_image, fragmentation); | 207 encoded_image, fragmentation); |
| 229 return Result(Result::OK, 0); | 208 return Result(Result::OK, 0); |
| 230 } | 209 } |
| 231 | 210 |
| 232 private: | 211 private: |
| 233 VideoProcessor* const video_processor_; | 212 VideoProcessor* const video_processor_; |
| 234 }; | 213 }; |
| 235 | 214 |
| 236 // Callback class required to implement according to the VideoDecoder API. | |
| 237 class VideoProcessorDecodeCompleteCallback | 215 class VideoProcessorDecodeCompleteCallback |
| 238 : public webrtc::DecodedImageCallback { | 216 : public webrtc::DecodedImageCallback { |
| 239 public: | 217 public: |
| 240 explicit VideoProcessorDecodeCompleteCallback( | 218 explicit VideoProcessorDecodeCompleteCallback( |
| 241 VideoProcessor* video_processor) | 219 VideoProcessor* video_processor) |
| 242 : video_processor_(video_processor) {} | 220 : video_processor_(video_processor) {} |
| 243 int32_t Decoded(webrtc::VideoFrame& image) override { | 221 int32_t Decoded(webrtc::VideoFrame& image) override { |
| 244 // Forward to parent class. | 222 // Forward to parent class. |
| 245 video_processor_->FrameDecoded(image); | 223 video_processor_->FrameDecoded(image); |
| 246 return 0; | 224 return 0; |
| 247 } | 225 } |
| 248 int32_t Decoded(webrtc::VideoFrame& image, | 226 int32_t Decoded(webrtc::VideoFrame& image, |
| 249 int64_t decode_time_ms) override { | 227 int64_t decode_time_ms) override { |
| 250 return Decoded(image); | 228 return Decoded(image); |
| 251 } | 229 } |
| 252 void Decoded(webrtc::VideoFrame& image, | 230 void Decoded(webrtc::VideoFrame& image, |
| 253 rtc::Optional<int32_t> decode_time_ms, | 231 rtc::Optional<int32_t> decode_time_ms, |
| 254 rtc::Optional<uint8_t> qp) override { | 232 rtc::Optional<uint8_t> qp) override { |
| 255 Decoded(image); | 233 Decoded(image); |
| 256 } | 234 } |
| 257 | 235 |
| 258 private: | 236 private: |
| 259 VideoProcessor* const video_processor_; | 237 VideoProcessor* const video_processor_; |
| 260 }; | 238 }; |
| 261 | 239 |
| 262 // Invoked by the callback when a frame has completed encoding. | 240 // Invoked by the callback adapter when a frame has completed encoding. |
| 263 void FrameEncoded(webrtc::VideoCodecType codec, | 241 void FrameEncoded(webrtc::VideoCodecType codec, |
| 264 const webrtc::EncodedImage& encodedImage, | 242 const webrtc::EncodedImage& encodedImage, |
| 265 const webrtc::RTPFragmentationHeader* fragmentation); | 243 const webrtc::RTPFragmentationHeader* fragmentation); |
| 266 | 244 |
| 267 // Invoked by the callback when a frame has completed decoding. | 245 // Invoked by the callback adapter when a frame has completed decoding. |
| 268 void FrameDecoded(const webrtc::VideoFrame& image); | 246 void FrameDecoded(const webrtc::VideoFrame& image); |
| 269 | 247 |
| 270 // Use the frame number as the basis for timestamp to identify frames. Let the | 248 // Use the frame number as the basis for timestamp to identify frames. Let the |
| 271 // first timestamp be non-zero, to not make the IvfFileWriter believe that we | 249 // first timestamp be non-zero, to not make the IvfFileWriter believe that we |
| 272 // want to use capture timestamps in the IVF files. | 250 // want to use capture timestamps in the IVF files. |
| 273 uint32_t FrameNumberToTimestamp(int frame_number); | 251 uint32_t FrameNumberToTimestamp(int frame_number) const; |
| 274 int TimestampToFrameNumber(uint32_t timestamp); | 252 int TimestampToFrameNumber(uint32_t timestamp) const; |
| 275 | 253 |
| 276 TestConfig config_; | 254 TestConfig config_; |
| 277 | 255 |
| 278 webrtc::VideoEncoder* const encoder_; | 256 webrtc::VideoEncoder* const encoder_; |
| 279 webrtc::VideoDecoder* const decoder_; | 257 webrtc::VideoDecoder* const decoder_; |
| 280 const std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_; | 258 const std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_; |
| 281 | 259 |
| 282 // Adapters for the codec callbacks. | 260 // Adapters for the codec callbacks. |
| 283 const std::unique_ptr<EncodedImageCallback> encode_callback_; | 261 VideoProcessorEncodeCompleteCallback encode_callback_; |
| 284 const std::unique_ptr<DecodedImageCallback> decode_callback_; | 262 VideoProcessorDecodeCompleteCallback decode_callback_; |
| 285 | 263 |
| 286 // Fake network. | 264 // Fake network. |
| 287 PacketManipulator* const packet_manipulator_; | 265 PacketManipulator* const packet_manipulator_; |
| 288 | 266 |
| 289 // These (mandatory) file manipulators are used for, e.g., objective PSNR and | 267 // These (mandatory) file manipulators are used for, e.g., objective PSNR and |
| 290 // SSIM calculations at the end of a test run. | 268 // SSIM calculations at the end of a test run. |
| 291 FrameReader* const analysis_frame_reader_; | 269 FrameReader* const analysis_frame_reader_; |
| 292 FrameWriter* const analysis_frame_writer_; | 270 FrameWriter* const analysis_frame_writer_; |
| 293 | 271 |
| 294 // These (optional) file writers are used to persistently store the encoded | 272 // These (optional) file writers are used to persistently store the encoded |
| (...skipping 16 matching lines...) Expand all Loading... |
| 311 bool first_key_frame_has_been_excluded_; | 289 bool first_key_frame_has_been_excluded_; |
| 312 | 290 |
| 313 // Keep track of the last successfully decoded frame, since we write that | 291 // Keep track of the last successfully decoded frame, since we write that |
| 314 // frame to disk when decoding fails. | 292 // frame to disk when decoding fails. |
| 315 rtc::Buffer last_decoded_frame_buffer_; | 293 rtc::Buffer last_decoded_frame_buffer_; |
| 316 | 294 |
| 317 // Statistics. | 295 // Statistics. |
| 318 Stats* stats_; | 296 Stats* stats_; |
| 319 int num_dropped_frames_; | 297 int num_dropped_frames_; |
| 320 int num_spatial_resizes_; | 298 int num_spatial_resizes_; |
| 299 |
| 300 RTC_DISALLOW_COPY_AND_ASSIGN(VideoProcessor); |
| 321 }; | 301 }; |
| 322 | 302 |
| 323 } // namespace test | 303 } // namespace test |
| 324 } // namespace webrtc | 304 } // namespace webrtc |
| 325 | 305 |
| 326 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ | 306 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ |
| OLD | NEW |