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.
10 #ifndef TEST_VIDEO_SOURCE_H_
11 #define TEST_VIDEO_SOURCE_H_
12 #include "vpx/vpx_encoder.h"
14 namespace libvpx_test {
16 // Abstract base class for test video sources, which provide a stream of
17 // vpx_image_t images with associated timestamps and duration.
20 virtual ~VideoSource() {}
22 // Prepare the stream for reading, rewind/open as necessary.
23 virtual void Begin() = 0;
25 // Advance the cursor to the next frame
26 virtual void Next() = 0;
28 // Get the current video frame, or NULL on End-Of-Stream.
29 virtual vpx_image_t *img() const = 0;
31 // Get the presentation timestamp of the current frame.
32 virtual vpx_codec_pts_t pts() const = 0;
34 // Get the current frame's duration
35 virtual unsigned long duration() const = 0;
37 // Get the timebase for the stream
38 virtual vpx_rational_t timebase() const = 0;
40 // Get the current frame counter, starting at 0.
41 virtual unsigned int frame() const = 0;
45 class DummyVideoSource : public VideoSource {
48 : img_(NULL), limit_(100) { SetSize(80, 64); }
50 virtual ~DummyVideoSource() { vpx_img_free(img_); }
52 virtual void Begin() {
62 virtual vpx_image_t *img() const {
63 return (frame_ < limit_) ? img_ : NULL;
66 // Models a stream where Timebase = 1/FPS, so pts == frame.
67 virtual vpx_codec_pts_t pts() const { return frame_; }
69 virtual unsigned long duration() const { return 1; }
71 virtual vpx_rational_t timebase() const {
72 const vpx_rational_t t = {1, 30};
76 virtual unsigned int frame() const { return frame_; }
78 void SetSize(unsigned int width, unsigned int height) {
80 raw_sz_ = ((width + 31)&~31) * height * 3 / 2;
81 img_ = vpx_img_alloc(NULL, VPX_IMG_FMT_VPXI420, width, height, 32);
85 virtual void FillFrame() { memset(img_->img_data, 0, raw_sz_); }
94 class RandomVideoSource : public DummyVideoSource {
96 // 15 frames of noise, followed by 15 static frames. Reset to 0 rather
97 // than holding previous frames to encourage keyframes to be thrown.
98 virtual void FillFrame() {
100 for (size_t i = 0; i < raw_sz_; ++i)
101 img_->img_data[i] = rand();
103 memset(img_->img_data, 0, raw_sz_);
107 } // namespace libvpx_test
109 #endif // TEST_VIDEO_SOURCE_H_