]> granicus.if.org Git - libvpx/blob - test/y4m_video_source.h
Merge "Cleaning up vp9_refining_search_8p_c() function."
[libvpx] / test / y4m_video_source.h
1 /*
2  *  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3  *
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.
9  */
10 #ifndef TEST_Y4M_VIDEO_SOURCE_H_
11 #define TEST_Y4M_VIDEO_SOURCE_H_
12 #include <string>
13
14 #include "test/video_source.h"
15 extern "C" {
16 #include "./y4minput.h"
17 }
18
19 namespace libvpx_test {
20
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,
26                   unsigned int start, int limit)
27       : file_name_(file_name),
28         input_file_(NULL),
29         img_(new vpx_image_t()),
30         start_(start),
31         limit_(limit),
32         frame_(0),
33         framerate_numerator_(0),
34         framerate_denominator_(0),
35         y4m_() {
36   }
37
38   virtual ~Y4mVideoSource() {
39     vpx_img_free(img_.get());
40     y4m_input_close(&y4m_);
41     if (input_file_)
42       fclose(input_file_);
43   }
44
45   virtual void Begin() {
46     if (input_file_)
47       fclose(input_file_);
48     input_file_ = OpenTestDataFile(file_name_);
49     ASSERT_TRUE(input_file_ != NULL) << "Input file open failed. Filename: "
50         << file_name_;
51
52     y4m_input_open(&y4m_, input_file_, NULL, 0, 0);
53     framerate_numerator_ = y4m_.fps_n;
54     framerate_denominator_ = y4m_.fps_d;
55
56     frame_ = 0;
57     for (unsigned int i = 0; i < start_; i++) {
58         Next();
59     }
60
61     FillFrame();
62   }
63
64   virtual void Next() {
65     ++frame_;
66     FillFrame();
67   }
68
69   virtual vpx_image_t *img() const {
70     return (frame_ < limit_) ? img_.get() : NULL;
71   }
72
73   // Models a stream where Timebase = 1/FPS, so pts == frame.
74   virtual vpx_codec_pts_t pts() const { return frame_; }
75
76   virtual unsigned long duration() const { return 1; }
77
78   virtual vpx_rational_t timebase() const {
79     const vpx_rational_t t = { framerate_denominator_, framerate_numerator_ };
80     return t;
81   }
82
83   virtual unsigned int frame() const { return frame_; }
84
85   virtual unsigned int limit() const { return limit_; }
86
87   virtual void FillFrame() {
88     ASSERT_TRUE(input_file_ != NULL);
89     // Read a frame from input_file.
90     y4m_input_fetch_frame(&y4m_, input_file_, img_.get());
91   }
92
93  protected:
94   std::string file_name_;
95   FILE *input_file_;
96   testing::internal::scoped_ptr<vpx_image_t> img_;
97   unsigned int start_;
98   unsigned int limit_;
99   unsigned int frame_;
100   int framerate_numerator_;
101   int framerate_denominator_;
102   y4m_input y4m_;
103 };
104
105 }  // namespace libvpx_test
106
107 #endif  // TEST_Y4M_VIDEO_SOURCE_H_