Removed shadow warnings : postproc.c decodframe.c threading.c
[aom.git] / test / i420_video_source.h
blob219bd3393c864567b3ce58fbbd55cec45edfdc3f
1 /*
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.
9 */
10 #ifndef TEST_I420_VIDEO_SOURCE_H_
11 #define TEST_I420_VIDEO_SOURCE_H_
12 #include <cstdio>
13 #include <cstdlib>
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 {
22 public:
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),
28 input_file_(NULL),
29 img_(NULL),
30 start_(start),
31 limit_(limit),
32 frame_(0),
33 width_(0),
34 height_(0),
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() {
43 vpx_img_free(img_);
44 if (input_file_)
45 fclose(input_file_);
48 virtual void Begin() {
49 if (input_file_)
50 fclose(input_file_);
51 input_file_ = OpenTestDataFile(file_name_);
52 ASSERT_TRUE(input_file_) << "Input file open failed. Filename: "
53 << file_name_;
54 if (start_) {
55 fseek(input_file_, raw_sz_ * start_, SEEK_SET);
58 frame_ = start_;
59 FillFrame();
62 virtual void Next() {
63 ++frame_;
64 FillFrame();
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_ };
76 return t;
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_) {
85 vpx_img_free(img_);
86 img_ = vpx_img_alloc(NULL, VPX_IMG_FMT_VPXI420, width, height, 1);
87 ASSERT_TRUE(img_ != NULL);
88 width_ = width;
89 height_ = height;
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) {
97 limit_ = frame_;
101 protected:
102 std::string file_name_;
103 FILE *input_file_;
104 vpx_image_t *img_;
105 size_t raw_sz_;
106 unsigned int start_;
107 unsigned int limit_;
108 unsigned int frame_;
109 unsigned int width_;
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_