2 * Copyright (c) 2012 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_I420_VIDEO_SOURCE_H_
11 #define TEST_I420_VIDEO_SOURCE_H_
15 #include "test/video_source.h"
17 namespace libvpx_test
{
19 // This class extends VideoSource to allow parsing of raw yv12
20 // so that we can do actual file encodes.
21 class I420VideoSource
: public VideoSource
{
23 I420VideoSource(const std::string
&file_name
,
24 unsigned int width
, unsigned int height
,
25 int rate_numerator
, int rate_denominator
,
26 unsigned int start
, int limit
)
27 : file_name_(file_name
),
35 framerate_numerator_(rate_numerator
),
36 framerate_denominator_(rate_denominator
) {
38 // This initializes raw_sz_, width_, height_ and allocates an img.
39 SetSize(width
, height
);
42 virtual ~I420VideoSource() {
48 virtual void Begin() {
51 input_file_
= OpenTestDataFile(file_name_
);
52 ASSERT_TRUE(input_file_
) << "Input file open failed. Filename: "
55 fseek(input_file_
, raw_sz_
* start_
, SEEK_SET
);
67 virtual vpx_image_t
*img() const { return (frame_
< limit_
) ? img_
: NULL
; }
69 // Models a stream where Timebase = 1/FPS, so pts == frame.
70 virtual vpx_codec_pts_t
pts() const { return frame_
; }
72 virtual unsigned long duration() const { return 1; }
74 virtual vpx_rational_t
timebase() const {
75 const vpx_rational_t t
= { framerate_denominator_
, framerate_numerator_
};
79 virtual unsigned int frame() const { return frame_
; }
81 virtual unsigned int limit() const { return limit_
; }
83 void SetSize(unsigned int width
, unsigned int height
) {
84 if (width
!= width_
|| height
!= height_
) {
86 img_
= vpx_img_alloc(NULL
, VPX_IMG_FMT_VPXI420
, width
, height
, 1);
87 ASSERT_TRUE(img_
!= NULL
);
90 raw_sz_
= width
* height
* 3 / 2;
94 virtual void FillFrame() {
95 // Read a frame from input_file.
96 if (fread(img_
->img_data
, raw_sz_
, 1, input_file_
) == 0) {
102 std::string file_name_
;
110 unsigned int height_
;
111 unsigned int framerate_numerator_
;
112 unsigned int framerate_denominator_
;
115 } // namespace libvpx_test
117 #endif // TEST_I420_VIDEO_SOURCE_H_