2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
10 #ifndef TEST_YUV_VIDEO_SOURCE_H_
11 #define TEST_YUV_VIDEO_SOURCE_H_
17 #include "test/video_source.h"
18 #include "vpx/vpx_image.h"
20 namespace libvpx_test
{
22 // This class extends VideoSource to allow parsing of raw YUV
23 // formats of various color sampling and bit-depths so that we can
24 // do actual file encodes.
25 class YUVVideoSource
: public VideoSource
{
27 YUVVideoSource(const std::string
&file_name
, vpx_img_fmt format
,
28 unsigned int width
, unsigned int height
,
29 int rate_numerator
, int rate_denominator
,
30 unsigned int start
, int limit
)
31 : file_name_(file_name
),
39 format_(VPX_IMG_FMT_NONE
),
40 framerate_numerator_(rate_numerator
),
41 framerate_denominator_(rate_denominator
) {
42 // This initializes format_, raw_size_, width_, height_ and allocates img.
43 SetSize(width
, height
, format
);
46 virtual ~YUVVideoSource() {
52 virtual void Begin() {
55 input_file_
= OpenTestDataFile(file_name_
);
56 ASSERT_TRUE(input_file_
!= NULL
) << "Input file open failed. Filename: "
59 fseek(input_file_
, static_cast<unsigned>(raw_size_
) * start_
, SEEK_SET
);
70 virtual vpx_image_t
*img() const { return (frame_
< limit_
) ? img_
: NULL
; }
72 // Models a stream where Timebase = 1/FPS, so pts == frame.
73 virtual vpx_codec_pts_t
pts() const { return frame_
; }
75 virtual unsigned long duration() const { return 1; }
77 virtual vpx_rational_t
timebase() const {
78 const vpx_rational_t t
= { framerate_denominator_
, framerate_numerator_
};
82 virtual unsigned int frame() const { return frame_
; }
84 virtual unsigned int limit() const { return limit_
; }
86 virtual void SetSize(unsigned int width
, unsigned int height
,
88 if (width
!= width_
|| height
!= height_
|| format
!= format_
) {
90 img_
= vpx_img_alloc(NULL
, format
, width
, height
, 1);
91 ASSERT_TRUE(img_
!= NULL
);
96 case VPX_IMG_FMT_I420
:
97 raw_size_
= width
* height
* 3 / 2;
99 case VPX_IMG_FMT_I422
:
100 raw_size_
= width
* height
* 2;
102 case VPX_IMG_FMT_I440
:
103 raw_size_
= width
* height
* 2;
105 case VPX_IMG_FMT_I444
:
106 raw_size_
= width
* height
* 3;
108 case VPX_IMG_FMT_I42016
:
109 raw_size_
= width
* height
* 3;
111 case VPX_IMG_FMT_I42216
:
112 raw_size_
= width
* height
* 4;
114 case VPX_IMG_FMT_I44016
:
115 raw_size_
= width
* height
* 4;
117 case VPX_IMG_FMT_I44416
:
118 raw_size_
= width
* height
* 6;
126 virtual void FillFrame() {
127 ASSERT_TRUE(input_file_
!= NULL
);
128 // Read a frame from input_file.
129 if (fread(img_
->img_data
, raw_size_
, 1, input_file_
) == 0) {
135 std::string file_name_
;
143 unsigned int height_
;
145 int framerate_numerator_
;
146 int framerate_denominator_
;
149 } // namespace libvpx_test
151 #endif // TEST_YUV_VIDEO_SOURCE_H_