Add dr prediction test
[aom.git] / test / y4m_video_source.h
blob277ded9eb536f41a4de7562e8e7f09e7902520d7
1 /*
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_Y4M_VIDEO_SOURCE_H_
12 #define TEST_Y4M_VIDEO_SOURCE_H_
13 #include <algorithm>
14 #include <string>
16 #include "common/y4minput.h"
17 #include "test/video_source.h"
19 namespace libaom_test {
21 // This class extends VideoSource to allow parsing of raw yv12
22 // so that we can do actual file encodes.
23 class Y4mVideoSource : public VideoSource {
24 public:
25 Y4mVideoSource(const std::string &file_name, unsigned int start, int limit)
26 : file_name_(file_name), input_file_(NULL), img_(new aom_image_t()),
27 start_(start), limit_(limit), frame_(0), framerate_numerator_(0),
28 framerate_denominator_(0), y4m_() {}
30 virtual ~Y4mVideoSource() {
31 aom_img_free(img_.get());
32 CloseSource();
35 virtual void OpenSource() {
36 CloseSource();
37 input_file_ = OpenTestDataFile(file_name_);
38 ASSERT_TRUE(input_file_ != NULL)
39 << "Input file open failed. Filename: " << file_name_;
42 virtual void ReadSourceToStart() {
43 ASSERT_TRUE(input_file_ != NULL);
44 ASSERT_FALSE(y4m_input_open(&y4m_, input_file_, NULL, 0, 0));
45 framerate_numerator_ = y4m_.fps_n;
46 framerate_denominator_ = y4m_.fps_d;
47 frame_ = 0;
48 for (unsigned int i = 0; i < start_; i++) {
49 Next();
51 FillFrame();
54 virtual void Begin() {
55 OpenSource();
56 ReadSourceToStart();
59 virtual void Next() {
60 ++frame_;
61 FillFrame();
64 virtual aom_image_t *img() const {
65 return (frame_ < limit_) ? img_.get() : NULL;
68 // Models a stream where Timebase = 1/FPS, so pts == frame.
69 virtual aom_codec_pts_t pts() const { return frame_; }
71 virtual unsigned long duration() const { return 1; }
73 virtual aom_rational_t timebase() const {
74 const aom_rational_t t = { framerate_denominator_, framerate_numerator_ };
75 return t;
78 virtual unsigned int frame() const { return frame_; }
80 virtual unsigned int limit() const { return limit_; }
82 virtual void FillFrame() {
83 ASSERT_TRUE(input_file_ != NULL);
84 // Read a frame from input_file.
85 y4m_input_fetch_frame(&y4m_, input_file_, img_.get());
88 // Swap buffers with another y4m source. This allows reading a new frame
89 // while keeping the old frame around. A whole Y4mSource is required and
90 // not just a aom_image_t because of how the y4m reader manipulates
91 // aom_image_t internals,
92 void SwapBuffers(Y4mVideoSource *other) {
93 std::swap(other->y4m_.dst_buf, y4m_.dst_buf);
94 aom_image_t *tmp;
95 tmp = other->img_.release();
96 other->img_.reset(img_.release());
97 img_.reset(tmp);
100 protected:
101 void CloseSource() {
102 y4m_input_close(&y4m_);
103 y4m_ = y4m_input();
104 if (input_file_ != NULL) {
105 fclose(input_file_);
106 input_file_ = NULL;
110 std::string file_name_;
111 FILE *input_file_;
112 testing::internal::scoped_ptr<aom_image_t> img_;
113 unsigned int start_;
114 unsigned int limit_;
115 unsigned int frame_;
116 int framerate_numerator_;
117 int framerate_denominator_;
118 y4m_input y4m_;
121 } // namespace libaom_test
123 #endif // TEST_Y4M_VIDEO_SOURCE_H_