2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
11 #ifndef TEST_YUV_VIDEO_SOURCE_H_
12 #define TEST_YUV_VIDEO_SOURCE_H_
18 #include "test/video_source.h"
19 #include "aom/aom_image.h"
21 namespace libaom_test
{
23 // This class extends VideoSource to allow parsing of raw YUV
24 // formats of various color sampling and bit-depths so that we can
25 // do actual file encodes.
26 class YUVVideoSource
: public VideoSource
{
28 YUVVideoSource(const std::string
&file_name
, aom_img_fmt format
,
29 unsigned int width
, unsigned int height
, int rate_numerator
,
30 int rate_denominator
, unsigned int start
, int limit
)
31 : file_name_(file_name
), input_file_(NULL
), img_(NULL
), start_(start
),
32 limit_(limit
), frame_(0), width_(0), height_(0),
33 format_(AOM_IMG_FMT_NONE
), framerate_numerator_(rate_numerator
),
34 framerate_denominator_(rate_denominator
) {
35 // This initializes format_, raw_size_, width_, height_ and allocates img.
36 SetSize(width
, height
, format
);
39 virtual ~YUVVideoSource() {
41 if (input_file_
) fclose(input_file_
);
44 virtual void Begin() {
45 if (input_file_
) fclose(input_file_
);
46 input_file_
= OpenTestDataFile(file_name_
);
47 ASSERT_TRUE(input_file_
!= NULL
)
48 << "Input file open failed. Filename: " << file_name_
;
50 fseek(input_file_
, static_cast<unsigned>(raw_size_
) * start_
, SEEK_SET
);
61 virtual aom_image_t
*img() const { return (frame_
< limit_
) ? img_
: NULL
; }
63 // Models a stream where Timebase = 1/FPS, so pts == frame.
64 virtual aom_codec_pts_t
pts() const { return frame_
; }
66 virtual unsigned long duration() const { return 1; }
68 virtual aom_rational_t
timebase() const {
69 const aom_rational_t t
= { framerate_denominator_
, framerate_numerator_
};
73 virtual unsigned int frame() const { return frame_
; }
75 virtual unsigned int limit() const { return limit_
; }
77 virtual void SetSize(unsigned int width
, unsigned int height
,
79 if (width
!= width_
|| height
!= height_
|| format
!= format_
) {
81 img_
= aom_img_alloc(NULL
, format
, width
, height
, 1);
82 ASSERT_TRUE(img_
!= NULL
);
87 case AOM_IMG_FMT_I420
: raw_size_
= width
* height
* 3 / 2; break;
88 case AOM_IMG_FMT_I422
: raw_size_
= width
* height
* 2; break;
89 case AOM_IMG_FMT_I440
: raw_size_
= width
* height
* 2; break;
90 case AOM_IMG_FMT_I444
: raw_size_
= width
* height
* 3; break;
91 case AOM_IMG_FMT_I42016
: raw_size_
= width
* height
* 3; break;
92 case AOM_IMG_FMT_I42216
: raw_size_
= width
* height
* 4; break;
93 case AOM_IMG_FMT_I44016
: raw_size_
= width
* height
* 4; break;
94 case AOM_IMG_FMT_I44416
: raw_size_
= width
* height
* 6; break;
95 default: ASSERT_TRUE(0);
100 virtual void FillFrame() {
101 ASSERT_TRUE(input_file_
!= NULL
);
102 // Read a frame from input_file.
103 if (fread(img_
->img_data
, raw_size_
, 1, input_file_
) == 0) {
109 std::string file_name_
;
117 unsigned int height_
;
119 int framerate_numerator_
;
120 int framerate_denominator_
;
123 } // namespace libaom_test
125 #endif // TEST_YUV_VIDEO_SOURCE_H_