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_Y4M_VIDEO_SOURCE_H_
11 #define TEST_Y4M_VIDEO_SOURCE_H_
15 #include "test/video_source.h"
16 #include "./y4minput.h"
18 namespace libvpx_test
{
20 // This class extends VideoSource to allow parsing of raw yv12
21 // so that we can do actual file encodes.
22 class Y4mVideoSource
: public VideoSource
{
24 Y4mVideoSource(const std::string
&file_name
,
25 unsigned int start
, int limit
)
26 : file_name_(file_name
),
28 img_(new vpx_image_t()),
32 framerate_numerator_(0),
33 framerate_denominator_(0),
37 virtual ~Y4mVideoSource() {
38 vpx_img_free(img_
.get());
42 virtual void OpenSource() {
44 input_file_
= OpenTestDataFile(file_name_
);
45 ASSERT_TRUE(input_file_
!= NULL
) << "Input file open failed. Filename: "
49 virtual void ReadSourceToStart() {
50 ASSERT_TRUE(input_file_
!= NULL
);
51 ASSERT_FALSE(y4m_input_open(&y4m_
, input_file_
, NULL
, 0, 0));
52 framerate_numerator_
= y4m_
.fps_n
;
53 framerate_denominator_
= y4m_
.fps_d
;
55 for (unsigned int i
= 0; i
< start_
; i
++) {
61 virtual void Begin() {
71 virtual vpx_image_t
*img() const {
72 return (frame_
< limit_
) ? img_
.get() : NULL
;
75 // Models a stream where Timebase = 1/FPS, so pts == frame.
76 virtual vpx_codec_pts_t
pts() const { return frame_
; }
78 virtual unsigned long duration() const { return 1; }
80 virtual vpx_rational_t
timebase() const {
81 const vpx_rational_t t
= { framerate_denominator_
, framerate_numerator_
};
85 virtual unsigned int frame() const { return frame_
; }
87 virtual unsigned int limit() const { return limit_
; }
89 virtual void FillFrame() {
90 ASSERT_TRUE(input_file_
!= NULL
);
91 // Read a frame from input_file.
92 y4m_input_fetch_frame(&y4m_
, input_file_
, img_
.get());
95 // Swap buffers with another y4m source. This allows reading a new frame
96 // while keeping the old frame around. A whole Y4mSource is required and
97 // not just a vpx_image_t because of how the y4m reader manipulates
98 // vpx_image_t internals,
99 void SwapBuffers(Y4mVideoSource
*other
) {
100 std::swap(other
->y4m_
.dst_buf
, y4m_
.dst_buf
);
102 tmp
= other
->img_
.release();
103 other
->img_
.reset(img_
.release());
109 y4m_input_close(&y4m_
);
111 if (input_file_
!= NULL
) {
117 std::string file_name_
;
119 testing::internal::scoped_ptr
<vpx_image_t
> img_
;
123 int framerate_numerator_
;
124 int framerate_denominator_
;
128 } // namespace libvpx_test
130 #endif // TEST_Y4M_VIDEO_SOURCE_H_