2013-06-13 23:42:05 +04:00
|
|
|
/*
|
2016-09-02 22:04:54 +03:00
|
|
|
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
2013-06-13 23:42:05 +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.
|
2013-06-13 23:42:05 +04:00
|
|
|
*/
|
|
|
|
#ifndef TEST_WEBM_VIDEO_SOURCE_H_
|
|
|
|
#define TEST_WEBM_VIDEO_SOURCE_H_
|
|
|
|
#include <cstdarg>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <new>
|
|
|
|
#include <string>
|
2014-04-15 01:19:50 +04:00
|
|
|
#include "../tools_common.h"
|
|
|
|
#include "../webmdec.h"
|
2013-06-13 23:42:05 +04:00
|
|
|
#include "test/video_source.h"
|
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
namespace libaom_test {
|
2013-06-13 23:42:05 +04:00
|
|
|
|
|
|
|
// This class extends VideoSource to allow parsing of WebM files,
|
|
|
|
// so that we can do actual file decodes.
|
|
|
|
class WebMVideoSource : public CompressedVideoSource {
|
|
|
|
public:
|
|
|
|
explicit WebMVideoSource(const std::string &file_name)
|
2016-08-31 00:01:10 +03:00
|
|
|
: file_name_(file_name), aom_ctx_(new AvxInputContext()),
|
2016-08-12 03:46:05 +03:00
|
|
|
webm_ctx_(new WebmInputContext()), buf_(NULL), buf_sz_(0), frame_(0),
|
|
|
|
end_of_file_(false) {}
|
2013-06-13 23:42:05 +04:00
|
|
|
|
|
|
|
virtual ~WebMVideoSource() {
|
2016-08-31 00:01:10 +03:00
|
|
|
if (aom_ctx_->file != NULL) fclose(aom_ctx_->file);
|
2014-04-19 20:29:26 +04:00
|
|
|
webm_free(webm_ctx_);
|
2016-08-31 00:01:10 +03:00
|
|
|
delete aom_ctx_;
|
2014-04-15 01:19:50 +04:00
|
|
|
delete webm_ctx_;
|
2013-06-13 23:42:05 +04:00
|
|
|
}
|
|
|
|
|
2016-08-12 03:46:05 +03:00
|
|
|
virtual void Init() {}
|
2013-06-13 23:42:05 +04:00
|
|
|
|
|
|
|
virtual void Begin() {
|
2016-08-31 00:01:10 +03:00
|
|
|
aom_ctx_->file = OpenTestDataFile(file_name_);
|
|
|
|
ASSERT_TRUE(aom_ctx_->file != NULL) << "Input file open failed. Filename: "
|
2016-08-12 03:46:05 +03:00
|
|
|
<< file_name_;
|
2013-06-13 23:42:05 +04:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
ASSERT_EQ(file_is_webm(webm_ctx_, aom_ctx_), 1) << "file is not WebM";
|
2013-06-13 23:42:05 +04:00
|
|
|
|
|
|
|
FillFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Next() {
|
|
|
|
++frame_;
|
|
|
|
FillFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FillFrame() {
|
2016-08-31 00:01:10 +03:00
|
|
|
ASSERT_TRUE(aom_ctx_->file != NULL);
|
2016-04-25 23:46:42 +03:00
|
|
|
const int status = webm_read_frame(webm_ctx_, &buf_, &buf_sz_);
|
2014-04-15 01:19:50 +04:00
|
|
|
ASSERT_GE(status, 0) << "webm_read_frame failed";
|
|
|
|
if (status == 1) {
|
|
|
|
end_of_file_ = true;
|
2013-06-13 23:42:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 23:26:28 +03:00
|
|
|
void SeekToNextKeyFrame() {
|
2016-08-31 00:01:10 +03:00
|
|
|
ASSERT_TRUE(aom_ctx_->file != NULL);
|
2015-01-27 23:26:28 +03:00
|
|
|
do {
|
2016-04-25 23:46:42 +03:00
|
|
|
const int status = webm_read_frame(webm_ctx_, &buf_, &buf_sz_);
|
2015-01-27 23:26:28 +03:00
|
|
|
ASSERT_GE(status, 0) << "webm_read_frame failed";
|
|
|
|
++frame_;
|
|
|
|
if (status == 1) {
|
|
|
|
end_of_file_ = true;
|
|
|
|
}
|
|
|
|
} while (!webm_ctx_->is_key_frame && !end_of_file_);
|
|
|
|
}
|
|
|
|
|
2016-08-12 03:46:05 +03:00
|
|
|
virtual const uint8_t *cxdata() const { return end_of_file_ ? NULL : buf_; }
|
2014-02-20 02:17:55 +04:00
|
|
|
virtual size_t frame_size() const { return buf_sz_; }
|
|
|
|
virtual unsigned int frame_number() const { return frame_; }
|
2013-06-13 23:42:05 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string file_name_;
|
2016-08-31 00:01:10 +03:00
|
|
|
AvxInputContext *aom_ctx_;
|
2014-04-15 01:19:50 +04:00
|
|
|
WebmInputContext *webm_ctx_;
|
2013-06-13 23:42:05 +04:00
|
|
|
uint8_t *buf_;
|
|
|
|
size_t buf_sz_;
|
|
|
|
unsigned int frame_;
|
|
|
|
bool end_of_file_;
|
|
|
|
};
|
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
} // namespace libaom_test
|
2013-06-13 23:42:05 +04:00
|
|
|
|
|
|
|
#endif // TEST_WEBM_VIDEO_SOURCE_H_
|