2012-05-17 00:27:00 +02:00
|
|
|
/*
|
|
|
|
* 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_
|
2012-07-23 23:55:32 +02:00
|
|
|
|
2012-10-04 21:59:36 +02:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
2012-07-23 23:55:32 +02:00
|
|
|
#include "test/acm_random.h"
|
2012-05-17 00:27:00 +02:00
|
|
|
#include "vpx/vpx_encoder.h"
|
|
|
|
|
|
|
|
namespace libvpx_test {
|
|
|
|
|
2012-10-04 21:59:36 +02:00
|
|
|
static FILE *OpenTestDataFile(const std::string& file_name) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fopen(path_to_source.c_str(), "rb");
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:27:00 +02:00
|
|
|
// 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;
|
2012-10-27 04:49:44 +02:00
|
|
|
|
|
|
|
// Get the current file limit.
|
|
|
|
virtual unsigned int limit() const = 0;
|
2012-05-17 00:27:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class DummyVideoSource : public VideoSource {
|
|
|
|
public:
|
2012-05-23 21:55:27 +02:00
|
|
|
DummyVideoSource() : img_(NULL), limit_(100), width_(0), height_(0) {
|
|
|
|
SetSize(80, 64);
|
|
|
|
}
|
2012-05-17 00:27:00 +02:00
|
|
|
|
|
|
|
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_; }
|
|
|
|
|
2012-10-27 04:49:44 +02:00
|
|
|
virtual unsigned int limit() const { return limit_; }
|
|
|
|
|
2012-05-17 00:27:00 +02:00
|
|
|
void SetSize(unsigned int width, unsigned int height) {
|
2012-05-23 21:55:27 +02:00
|
|
|
if (width != width_ || height != height_) {
|
|
|
|
vpx_img_free(img_);
|
|
|
|
raw_sz_ = ((width + 31)&~31) * height * 3 / 2;
|
2013-05-09 05:42:58 +02:00
|
|
|
img_ = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, width, height, 32);
|
2012-05-23 21:55:27 +02:00
|
|
|
width_ = width;
|
|
|
|
height_ = height;
|
|
|
|
}
|
2012-05-17 00:27:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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_;
|
2012-05-23 21:55:27 +02:00
|
|
|
unsigned int width_;
|
|
|
|
unsigned int height_;
|
2012-05-17 00:27:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RandomVideoSource : public DummyVideoSource {
|
2012-07-23 23:55:32 +02:00
|
|
|
public:
|
2012-07-24 00:06:12 +02:00
|
|
|
RandomVideoSource(int seed = ACMRandom::DeterministicSeed())
|
|
|
|
: rnd_(seed),
|
|
|
|
seed_(seed) { }
|
2012-07-23 23:55:32 +02:00
|
|
|
|
2012-05-17 00:27:00 +02:00
|
|
|
protected:
|
2012-07-23 23:55:32 +02:00
|
|
|
// Reset the RNG to get a matching stream for the second pass
|
|
|
|
virtual void Begin() {
|
|
|
|
frame_ = 0;
|
2012-07-24 00:06:12 +02:00
|
|
|
rnd_.Reset(seed_);
|
2012-07-23 23:55:32 +02:00
|
|
|
FillFrame();
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:27:00 +02:00
|
|
|
// 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)
|
2012-07-23 23:55:32 +02:00
|
|
|
img_->img_data[i] = rnd_.Rand8();
|
2012-05-17 00:27:00 +02:00
|
|
|
else
|
|
|
|
memset(img_->img_data, 0, raw_sz_);
|
|
|
|
}
|
2012-07-23 23:55:32 +02:00
|
|
|
|
|
|
|
ACMRandom rnd_;
|
2012-07-24 00:06:12 +02:00
|
|
|
int seed_;
|
2012-05-17 00:27:00 +02:00
|
|
|
};
|
|
|
|
|
2012-10-04 21:59:36 +02:00
|
|
|
// Abstract base class for test video sources, which provide a stream of
|
|
|
|
// decompressed images to the decoder.
|
|
|
|
class CompressedVideoSource {
|
|
|
|
public:
|
|
|
|
virtual ~CompressedVideoSource() {}
|
|
|
|
|
|
|
|
virtual void Init() = 0;
|
|
|
|
|
|
|
|
// Prepare the stream for reading, rewind/open as necessary.
|
|
|
|
virtual void Begin() = 0;
|
|
|
|
|
|
|
|
// Advance the cursor to the next frame
|
|
|
|
virtual void Next() = 0;
|
|
|
|
|
|
|
|
virtual const uint8_t *cxdata() const = 0;
|
|
|
|
|
|
|
|
virtual const unsigned int frame_size() const = 0;
|
|
|
|
|
|
|
|
virtual const unsigned int frame_number() const = 0;
|
|
|
|
};
|
|
|
|
|
2012-05-17 00:27:00 +02:00
|
|
|
} // namespace libvpx_test
|
|
|
|
|
|
|
|
#endif // TEST_VIDEO_SOURCE_H_
|