2014-10-16 03:40:12 +04:00
|
|
|
/*
|
2016-09-02 22:04:54 +03:00
|
|
|
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
2014-10-16 03:40:12 +04:00
|
|
|
*
|
2016-09-02 22:04:54 +03:00
|
|
|
* This source code is subject to the terms of the BSD 2 Clause License and
|
|
|
|
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
|
|
|
|
* was not distributed with this source code in the LICENSE file, you can
|
|
|
|
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
|
|
|
|
* Media Patent License 1.0 was not distributed with this source code in the
|
|
|
|
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
2014-10-16 03:40:12 +04:00
|
|
|
*/
|
|
|
|
#ifndef TEST_YUV_VIDEO_SOURCE_H_
|
|
|
|
#define TEST_YUV_VIDEO_SOURCE_H_
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "test/video_source.h"
|
2016-08-31 00:01:10 +03:00
|
|
|
#include "aom/aom_image.h"
|
2014-10-16 03:40:12 +04:00
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
namespace libaom_test {
|
2014-10-16 03:40:12 +04:00
|
|
|
|
|
|
|
// This class extends VideoSource to allow parsing of raw YUV
|
|
|
|
// formats of various color sampling and bit-depths so that we can
|
|
|
|
// do actual file encodes.
|
|
|
|
class YUVVideoSource : public VideoSource {
|
|
|
|
public:
|
2016-08-31 00:01:10 +03:00
|
|
|
YUVVideoSource(const std::string &file_name, aom_img_fmt format,
|
2016-08-12 03:46:05 +03:00
|
|
|
unsigned int width, unsigned int height, int rate_numerator,
|
|
|
|
int rate_denominator, unsigned int start, int limit)
|
|
|
|
: file_name_(file_name), input_file_(NULL), img_(NULL), start_(start),
|
|
|
|
limit_(limit), frame_(0), width_(0), height_(0),
|
2016-08-31 00:01:10 +03:00
|
|
|
format_(AOM_IMG_FMT_NONE), framerate_numerator_(rate_numerator),
|
2014-10-16 03:40:12 +04:00
|
|
|
framerate_denominator_(rate_denominator) {
|
|
|
|
// This initializes format_, raw_size_, width_, height_ and allocates img.
|
|
|
|
SetSize(width, height, format);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~YUVVideoSource() {
|
2016-08-31 00:01:10 +03:00
|
|
|
aom_img_free(img_);
|
2016-08-12 03:46:05 +03:00
|
|
|
if (input_file_) fclose(input_file_);
|
2014-10-16 03:40:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Begin() {
|
2016-08-12 03:46:05 +03:00
|
|
|
if (input_file_) fclose(input_file_);
|
2014-10-16 03:40:12 +04:00
|
|
|
input_file_ = OpenTestDataFile(file_name_);
|
|
|
|
ASSERT_TRUE(input_file_ != NULL) << "Input file open failed. Filename: "
|
|
|
|
<< file_name_;
|
|
|
|
if (start_)
|
|
|
|
fseek(input_file_, static_cast<unsigned>(raw_size_) * start_, SEEK_SET);
|
|
|
|
|
|
|
|
frame_ = start_;
|
|
|
|
FillFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Next() {
|
|
|
|
++frame_;
|
|
|
|
FillFrame();
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
virtual aom_image_t *img() const { return (frame_ < limit_) ? img_ : NULL; }
|
2014-10-16 03:40:12 +04:00
|
|
|
|
|
|
|
// Models a stream where Timebase = 1/FPS, so pts == frame.
|
2016-08-31 00:01:10 +03:00
|
|
|
virtual aom_codec_pts_t pts() const { return frame_; }
|
2014-10-16 03:40:12 +04:00
|
|
|
|
|
|
|
virtual unsigned long duration() const { return 1; }
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
virtual aom_rational_t timebase() const {
|
|
|
|
const aom_rational_t t = { framerate_denominator_, framerate_numerator_ };
|
2014-10-16 03:40:12 +04:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual unsigned int frame() const { return frame_; }
|
|
|
|
|
|
|
|
virtual unsigned int limit() const { return limit_; }
|
|
|
|
|
|
|
|
virtual void SetSize(unsigned int width, unsigned int height,
|
2016-08-31 00:01:10 +03:00
|
|
|
aom_img_fmt format) {
|
2014-10-16 03:40:12 +04:00
|
|
|
if (width != width_ || height != height_ || format != format_) {
|
2016-08-31 00:01:10 +03:00
|
|
|
aom_img_free(img_);
|
|
|
|
img_ = aom_img_alloc(NULL, format, width, height, 1);
|
2014-10-16 03:40:12 +04:00
|
|
|
ASSERT_TRUE(img_ != NULL);
|
|
|
|
width_ = width;
|
|
|
|
height_ = height;
|
|
|
|
format_ = format;
|
|
|
|
switch (format) {
|
2016-08-31 00:01:10 +03:00
|
|
|
case AOM_IMG_FMT_I420: raw_size_ = width * height * 3 / 2; break;
|
|
|
|
case AOM_IMG_FMT_I422: raw_size_ = width * height * 2; break;
|
|
|
|
case AOM_IMG_FMT_I440: raw_size_ = width * height * 2; break;
|
|
|
|
case AOM_IMG_FMT_I444: raw_size_ = width * height * 3; break;
|
|
|
|
case AOM_IMG_FMT_I42016: raw_size_ = width * height * 3; break;
|
|
|
|
case AOM_IMG_FMT_I42216: raw_size_ = width * height * 4; break;
|
|
|
|
case AOM_IMG_FMT_I44016: raw_size_ = width * height * 4; break;
|
|
|
|
case AOM_IMG_FMT_I44416: raw_size_ = width * height * 6; break;
|
2016-08-12 03:46:05 +03:00
|
|
|
default: ASSERT_TRUE(0);
|
2014-10-16 03:40:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void FillFrame() {
|
|
|
|
ASSERT_TRUE(input_file_ != NULL);
|
|
|
|
// Read a frame from input_file.
|
|
|
|
if (fread(img_->img_data, raw_size_, 1, input_file_) == 0) {
|
|
|
|
limit_ = frame_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string file_name_;
|
|
|
|
FILE *input_file_;
|
2016-08-31 00:01:10 +03:00
|
|
|
aom_image_t *img_;
|
2014-10-16 03:40:12 +04:00
|
|
|
size_t raw_size_;
|
|
|
|
unsigned int start_;
|
|
|
|
unsigned int limit_;
|
|
|
|
unsigned int frame_;
|
|
|
|
unsigned int width_;
|
|
|
|
unsigned int height_;
|
2016-08-31 00:01:10 +03:00
|
|
|
aom_img_fmt format_;
|
2014-10-16 03:40:12 +04:00
|
|
|
int framerate_numerator_;
|
|
|
|
int framerate_denominator_;
|
|
|
|
};
|
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
} // namespace libaom_test
|
2014-10-16 03:40:12 +04:00
|
|
|
|
|
|
|
#endif // TEST_YUV_VIDEO_SOURCE_H_
|