summaryrefslogtreecommitdiff
path: root/test/video_source.h
diff options
context:
space:
mode:
authorJohn Koleszar <jkoleszar@google.com>2012-05-16 15:27:00 -0700
committerJohn Koleszar <jkoleszar@google.com>2012-05-22 15:08:11 -0700
commitb9180fc0499a7c1480a47e17328e7a35bb788086 (patch)
tree82ac0eddbc0eb8ecbfb068cc53f1be12bc0c0ae6 /test/video_source.h
parent2d225689d36128e7c7fa1351e5c725ba4830f6b2 (diff)
downloadlibvpx-b9180fc0499a7c1480a47e17328e7a35bb788086.tar
libvpx-b9180fc0499a7c1480a47e17328e7a35bb788086.tar.gz
libvpx-b9180fc0499a7c1480a47e17328e7a35bb788086.tar.bz2
libvpx-b9180fc0499a7c1480a47e17328e7a35bb788086.zip
Add initial keyframe tests
Implements a couple simple tests of the encoder API using the gtest framework: TestDisableKeyframes TestForceKeyframe TestKeyframeMaxDistance Change-Id: I38e93fe242fbeb30bb11b23ac12de8ddc291a28d
Diffstat (limited to 'test/video_source.h')
-rw-r--r--test/video_source.h109
1 files changed, 109 insertions, 0 deletions
diff --git a/test/video_source.h b/test/video_source.h
new file mode 100644
index 000000000..86c6caa83
--- /dev/null
+++ b/test/video_source.h
@@ -0,0 +1,109 @@
+/*
+ * 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_VIDEO_SOURCE_H_
+#define TEST_VIDEO_SOURCE_H_
+#include "vpx/vpx_encoder.h"
+
+namespace libvpx_test {
+
+// Abstract base class for test video sources, which provide a stream of
+// vpx_image_t images with associated timestamps and duration.
+class VideoSource {
+ public:
+ virtual ~VideoSource() {}
+
+ // Prepare the stream for reading, rewind/open as necessary.
+ virtual void Begin() = 0;
+
+ // Advance the cursor to the next frame
+ virtual void Next() = 0;
+
+ // Get the current video frame, or NULL on End-Of-Stream.
+ virtual vpx_image_t *img() const = 0;
+
+ // Get the presentation timestamp of the current frame.
+ virtual vpx_codec_pts_t pts() const = 0;
+
+ // Get the current frame's duration
+ virtual unsigned long duration() const = 0;
+
+ // Get the timebase for the stream
+ virtual vpx_rational_t timebase() const = 0;
+
+ // Get the current frame counter, starting at 0.
+ virtual unsigned int frame() const = 0;
+};
+
+
+class DummyVideoSource : public VideoSource {
+ public:
+ DummyVideoSource()
+ : img_(NULL), limit_(100) { SetSize(80, 64); }
+
+ virtual ~DummyVideoSource() { vpx_img_free(img_); }
+
+ virtual void Begin() {
+ frame_ = 0;
+ 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 = {1, 30};
+ return t;
+ }
+
+ virtual unsigned int frame() const { return frame_; }
+
+ void SetSize(unsigned int width, unsigned int height) {
+ vpx_img_free(img_);
+ raw_sz_ = ((width + 31)&~31) * height * 3 / 2;
+ img_ = vpx_img_alloc(NULL, VPX_IMG_FMT_VPXI420, width, height, 32);
+ }
+
+ protected:
+ virtual void FillFrame() { memset(img_->img_data, 0, raw_sz_); }
+
+ vpx_image_t *img_;
+ size_t raw_sz_;
+ unsigned int limit_;
+ unsigned int frame_;
+};
+
+
+class RandomVideoSource : public DummyVideoSource {
+ protected:
+ // 15 frames of noise, followed by 15 static frames. Reset to 0 rather
+ // than holding previous frames to encourage keyframes to be thrown.
+ virtual void FillFrame() {
+ if (frame_ % 30 < 15)
+ for (size_t i = 0; i < raw_sz_; ++i)
+ img_->img_data[i] = rand();
+ else
+ memset(img_->img_data, 0, raw_sz_);
+ }
+};
+
+} // namespace libvpx_test
+
+#endif // TEST_VIDEO_SOURCE_H_