Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(428)

Side by Side Diff: source/libvpx/test/i420_video_source.h

Issue 668403002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/test/frame_size_tests.cc ('k') | source/libvpx/test/lpf_8_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 #ifndef TEST_I420_VIDEO_SOURCE_H_ 10 #ifndef TEST_I420_VIDEO_SOURCE_H_
11 #define TEST_I420_VIDEO_SOURCE_H_ 11 #define TEST_I420_VIDEO_SOURCE_H_
12 #include <cstdio> 12 #include <cstdio>
13 #include <cstdlib> 13 #include <cstdlib>
14 #include <string> 14 #include <string>
15 15
16 #include "test/video_source.h" 16 #include "test/yuv_video_source.h"
17 17
18 namespace libvpx_test { 18 namespace libvpx_test {
19 19
20 // This class extends VideoSource to allow parsing of raw yv12 20 // This class extends VideoSource to allow parsing of raw yv12
21 // so that we can do actual file encodes. 21 // so that we can do actual file encodes.
22 class I420VideoSource : public VideoSource { 22 class I420VideoSource : public YUVVideoSource {
23 public: 23 public:
24 I420VideoSource(const std::string &file_name, 24 I420VideoSource(const std::string &file_name,
25 unsigned int width, unsigned int height, 25 unsigned int width, unsigned int height,
26 int rate_numerator, int rate_denominator, 26 int rate_numerator, int rate_denominator,
27 unsigned int start, int limit) 27 unsigned int start, int limit)
28 : file_name_(file_name), 28 : YUVVideoSource(file_name, VPX_IMG_FMT_I420,
29 input_file_(NULL), 29 width, height,
30 img_(NULL), 30 rate_numerator, rate_denominator,
31 start_(start), 31 start, limit) {}
32 limit_(limit),
33 frame_(0),
34 width_(0),
35 height_(0),
36 framerate_numerator_(rate_numerator),
37 framerate_denominator_(rate_denominator) {
38 // This initializes raw_sz_, width_, height_ and allocates an img.
39 SetSize(width, height);
40 }
41
42 virtual ~I420VideoSource() {
43 vpx_img_free(img_);
44 if (input_file_)
45 fclose(input_file_);
46 }
47
48 virtual void Begin() {
49 if (input_file_)
50 fclose(input_file_);
51 input_file_ = OpenTestDataFile(file_name_);
52 ASSERT_TRUE(input_file_ != NULL) << "Input file open failed. Filename: "
53 << file_name_;
54 if (start_) {
55 fseek(input_file_, static_cast<unsigned>(raw_sz_) * start_, SEEK_SET);
56 }
57
58 frame_ = start_;
59 FillFrame();
60 }
61
62 virtual void Next() {
63 ++frame_;
64 FillFrame();
65 }
66
67 virtual vpx_image_t *img() const { return (frame_ < limit_) ? img_ : NULL; }
68
69 // Models a stream where Timebase = 1/FPS, so pts == frame.
70 virtual vpx_codec_pts_t pts() const { return frame_; }
71
72 virtual unsigned long duration() const { return 1; }
73
74 virtual vpx_rational_t timebase() const {
75 const vpx_rational_t t = { framerate_denominator_, framerate_numerator_ };
76 return t;
77 }
78
79 virtual unsigned int frame() const { return frame_; }
80
81 virtual unsigned int limit() const { return limit_; }
82
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_I420, width, height, 1);
87 ASSERT_TRUE(img_ != NULL);
88 width_ = width;
89 height_ = height;
90 raw_sz_ = width * height * 3 / 2;
91 }
92 }
93
94 virtual void FillFrame() {
95 ASSERT_TRUE(input_file_ != NULL);
96 // Read a frame from input_file.
97 if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
98 limit_ = frame_;
99 }
100 }
101
102 protected:
103 std::string file_name_;
104 FILE *input_file_;
105 vpx_image_t *img_;
106 size_t raw_sz_;
107 unsigned int start_;
108 unsigned int limit_;
109 unsigned int frame_;
110 unsigned int width_;
111 unsigned int height_;
112 int framerate_numerator_;
113 int framerate_denominator_;
114 }; 32 };
115 33
116 } // namespace libvpx_test 34 } // namespace libvpx_test
117 35
118 #endif // TEST_I420_VIDEO_SOURCE_H_ 36 #endif // TEST_I420_VIDEO_SOURCE_H_
OLDNEW
« no previous file with comments | « source/libvpx/test/frame_size_tests.cc ('k') | source/libvpx/test/lpf_8_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698