summaryrefslogtreecommitdiff
path: root/test/i420_video_source.h
diff options
context:
space:
mode:
authorJim Bankoski <jimbankoski@google.com>2012-06-23 11:20:41 -0700
committerJim Bankoski <jimbankoski@google.com>2012-06-23 11:20:41 -0700
commit96b6b6bbf046c944b44a2ca96d4c6adb851fecf7 (patch)
tree25625440ce08d1ce32e73e2c74d9193802cace33 /test/i420_video_source.h
parent007486329fe79280f6b062a85fad9ba8720aaaea (diff)
downloadlibvpx-96b6b6bbf046c944b44a2ca96d4c6adb851fecf7.tar
libvpx-96b6b6bbf046c944b44a2ca96d4c6adb851fecf7.tar.gz
libvpx-96b6b6bbf046c944b44a2ca96d4c6adb851fecf7.tar.bz2
libvpx-96b6b6bbf046c944b44a2ca96d4c6adb851fecf7.zip
add auto keyframe unit test
To do so we add a framework for encoding a yv12 file.. Change-Id: I94a061eb916beaf6cde920cf1aaadb6eed10a717
Diffstat (limited to 'test/i420_video_source.h')
-rw-r--r--test/i420_video_source.h117
1 files changed, 117 insertions, 0 deletions
diff --git a/test/i420_video_source.h b/test/i420_video_source.h
new file mode 100644
index 000000000..f4717647b
--- /dev/null
+++ b/test/i420_video_source.h
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef TEST_I420_VIDEO_SOURCE_H_
+#define TEST_I420_VIDEO_SOURCE_H_
+#include <cstdio>
+#include <cstdlib>
+
+#include "test/video_source.h"
+
+namespace libvpx_test {
+
+// This class extends VideoSource to allow parsing of raw yv12
+// so that we can do actual file encodes.
+class I420VideoSource : public VideoSource {
+ public:
+ I420VideoSource(const std::string &file_name,
+ unsigned int width, unsigned int height,
+ int rate_numerator, int rate_denominator,
+ unsigned int start, int limit)
+ : file_name_(file_name),
+ img_(NULL),
+ start_(start),
+ limit_(limit),
+ framerate_numerator_(rate_numerator),
+ framerate_denominator_(rate_denominator) {
+
+ // This initializes raw_sz_, width_, height_ and allocates an img.
+ SetSize(width, height);
+ }
+
+ virtual ~I420VideoSource() {
+ vpx_img_free(img_);
+ if (input_file_)
+ fclose(input_file_);
+ }
+
+ virtual void Begin() {
+ std::string path_to_source = file_name_;
+ const char *kDataPath = getenv("LIBVPX_TEST_DATA_PATH");
+ if (kDataPath) {
+ path_to_source = kDataPath;
+ path_to_source += "/";
+ path_to_source += file_name_;
+ }
+
+ input_file_ = fopen(path_to_source.c_str(), "rb");
+ ASSERT_TRUE(input_file_) << "File open failed.";
+
+ if (start_) {
+ fseek(input_file_, raw_sz_ * start_, SEEK_SET);
+ }
+
+ frame_ = start_;
+ FillFrame();
+ }
+
+ virtual void Next() {
+ ++frame_;
+ FillFrame();
+ }
+
+ virtual vpx_image_t *img() const { return (frame_ < limit_) ? img_ : NULL; }
+
+ // Models a stream where Timebase = 1/FPS, so pts == frame.
+ virtual vpx_codec_pts_t pts() const { return frame_; }
+
+ virtual unsigned long duration() const { return 1; }
+
+ virtual vpx_rational_t timebase() const {
+ const vpx_rational_t t = { framerate_denominator_, framerate_numerator_ };
+ return t;
+ }
+
+ virtual unsigned int frame() const { return frame_; }
+
+ void SetSize(unsigned int width, unsigned int height) {
+ if (width != width_ || height != height_) {
+ vpx_img_free(img_);
+ img_ = vpx_img_alloc(NULL, VPX_IMG_FMT_VPXI420, width, height, 1);
+ ASSERT_TRUE(img_ != NULL);
+ width_ = width;
+ height_ = height;
+ raw_sz_ = width * height * 3 / 2;
+ }
+ }
+
+ virtual void FillFrame() {
+ // Read a frame from input_file.
+ if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
+ limit_ = frame_;
+ }
+ }
+
+ protected:
+ std::string file_name_;
+ FILE *input_file_;
+ vpx_image_t *img_;
+ size_t raw_sz_;
+ unsigned int start_;
+ unsigned int limit_;
+ unsigned int frame_;
+ unsigned int width_;
+ unsigned int height_;
+ unsigned int framerate_numerator_;
+ unsigned int framerate_denominator_;
+};
+
+} // namespace libvpx_test
+
+#endif // TEST_I420_VIDEO_SOURCE_H_