2012-06-23 22:20:41 +04: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_I420_VIDEO_SOURCE_H_
|
|
|
|
#define TEST_I420_VIDEO_SOURCE_H_
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
2013-09-05 19:45:56 +04:00
|
|
|
#include <string>
|
2012-06-23 22:20:41 +04:00
|
|
|
|
|
|
|
#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),
|
2012-10-27 06:49:44 +04:00
|
|
|
input_file_(NULL),
|
2012-06-23 22:20:41 +04:00
|
|
|
img_(NULL),
|
|
|
|
start_(start),
|
|
|
|
limit_(limit),
|
2012-07-10 04:36:01 +04:00
|
|
|
frame_(0),
|
|
|
|
width_(0),
|
|
|
|
height_(0),
|
2012-06-23 22:20:41 +04:00
|
|
|
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() {
|
2012-10-27 06:49:44 +04:00
|
|
|
if (input_file_)
|
|
|
|
fclose(input_file_);
|
2012-10-04 23:59:36 +04:00
|
|
|
input_file_ = OpenTestDataFile(file_name_);
|
2013-06-26 04:55:28 +04:00
|
|
|
ASSERT_TRUE(input_file_ != NULL) << "Input file open failed. Filename: "
|
2012-10-04 23:59:36 +04:00
|
|
|
<< file_name_;
|
2012-06-23 22:20:41 +04:00
|
|
|
if (start_) {
|
2013-12-19 05:00:40 +04:00
|
|
|
fseek(input_file_, static_cast<unsigned>(raw_sz_) * start_, SEEK_SET);
|
2012-06-23 22:20:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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_; }
|
|
|
|
|
2012-10-27 06:49:44 +04:00
|
|
|
virtual unsigned int limit() const { return limit_; }
|
|
|
|
|
2012-06-23 22:20:41 +04:00
|
|
|
void SetSize(unsigned int width, unsigned int height) {
|
|
|
|
if (width != width_ || height != height_) {
|
|
|
|
vpx_img_free(img_);
|
2013-05-09 07:42:58 +04:00
|
|
|
img_ = vpx_img_alloc(NULL, VPX_IMG_FMT_I420, width, height, 1);
|
2012-06-23 22:20:41 +04:00
|
|
|
ASSERT_TRUE(img_ != NULL);
|
|
|
|
width_ = width;
|
|
|
|
height_ = height;
|
|
|
|
raw_sz_ = width * height * 3 / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void FillFrame() {
|
2013-06-26 04:55:28 +04:00
|
|
|
ASSERT_TRUE(input_file_ != NULL);
|
2012-06-23 22:20:41 +04:00
|
|
|
// 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_;
|
2013-06-22 06:34:51 +04:00
|
|
|
int framerate_numerator_;
|
|
|
|
int framerate_denominator_;
|
2012-06-23 22:20:41 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace libvpx_test
|
|
|
|
|
|
|
|
#endif // TEST_I420_VIDEO_SOURCE_H_
|