Merge "Remove duplicate code in test/webm_video_source.h"
This commit is contained in:
commit
6b47f84578
@ -49,6 +49,9 @@ NESTEGG_SRCS += ../third_party/nestegg/halloc/src/hlis
|
|||||||
NESTEGG_SRCS += ../third_party/nestegg/include/nestegg/nestegg.h
|
NESTEGG_SRCS += ../third_party/nestegg/include/nestegg/nestegg.h
|
||||||
NESTEGG_SRCS += ../third_party/nestegg/src/nestegg.c
|
NESTEGG_SRCS += ../third_party/nestegg/src/nestegg.c
|
||||||
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += $(NESTEGG_SRCS)
|
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += $(NESTEGG_SRCS)
|
||||||
|
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += ../tools_common.h
|
||||||
|
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += ../webmdec.c
|
||||||
|
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += ../webmdec.h
|
||||||
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += webm_video_source.h
|
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += webm_video_source.h
|
||||||
|
|
||||||
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += test_vector_test.cc
|
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += test_vector_test.cc
|
||||||
|
@ -14,73 +14,20 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "third_party/nestegg/include/nestegg/nestegg.h"
|
#include "../tools_common.h"
|
||||||
|
#include "../webmdec.h"
|
||||||
#include "test/video_source.h"
|
#include "test/video_source.h"
|
||||||
|
|
||||||
namespace libvpx_test {
|
namespace libvpx_test {
|
||||||
|
|
||||||
static int
|
|
||||||
nestegg_read_cb(void *buffer, size_t length, void *userdata) {
|
|
||||||
FILE *f = reinterpret_cast<FILE *>(userdata);
|
|
||||||
|
|
||||||
if (fread(buffer, 1, length, f) < length) {
|
|
||||||
if (ferror(f))
|
|
||||||
return -1;
|
|
||||||
if (feof(f))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
nestegg_seek_cb(int64_t offset, int whence, void *userdata) {
|
|
||||||
FILE *f = reinterpret_cast<FILE *>(userdata);
|
|
||||||
switch (whence) {
|
|
||||||
case NESTEGG_SEEK_SET:
|
|
||||||
whence = SEEK_SET;
|
|
||||||
break;
|
|
||||||
case NESTEGG_SEEK_CUR:
|
|
||||||
whence = SEEK_CUR;
|
|
||||||
break;
|
|
||||||
case NESTEGG_SEEK_END:
|
|
||||||
whence = SEEK_END;
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
return fseek(f, (long)offset, whence) ? -1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int64_t
|
|
||||||
nestegg_tell_cb(void *userdata) {
|
|
||||||
FILE *f = reinterpret_cast<FILE *>(userdata);
|
|
||||||
return ftell(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
nestegg_log_cb(nestegg *context, unsigned int severity, char const *format,
|
|
||||||
...) {
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, format);
|
|
||||||
vfprintf(stderr, format, ap);
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This class extends VideoSource to allow parsing of WebM files,
|
// This class extends VideoSource to allow parsing of WebM files,
|
||||||
// so that we can do actual file decodes.
|
// so that we can do actual file decodes.
|
||||||
class WebMVideoSource : public CompressedVideoSource {
|
class WebMVideoSource : public CompressedVideoSource {
|
||||||
public:
|
public:
|
||||||
explicit WebMVideoSource(const std::string &file_name)
|
explicit WebMVideoSource(const std::string &file_name)
|
||||||
: file_name_(file_name),
|
: file_name_(file_name),
|
||||||
input_file_(NULL),
|
vpx_ctx_(new VpxInputContext()),
|
||||||
nestegg_ctx_(NULL),
|
webm_ctx_(new WebmInputContext()),
|
||||||
pkt_(NULL),
|
|
||||||
video_track_(0),
|
|
||||||
chunk_(0),
|
|
||||||
chunks_(0),
|
|
||||||
buf_(NULL),
|
buf_(NULL),
|
||||||
buf_sz_(0),
|
buf_sz_(0),
|
||||||
frame_(0),
|
frame_(0),
|
||||||
@ -88,42 +35,21 @@ class WebMVideoSource : public CompressedVideoSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual ~WebMVideoSource() {
|
virtual ~WebMVideoSource() {
|
||||||
if (input_file_)
|
if (vpx_ctx_->file != NULL)
|
||||||
fclose(input_file_);
|
fclose(vpx_ctx_->file);
|
||||||
if (nestegg_ctx_ != NULL) {
|
delete vpx_ctx_;
|
||||||
if (pkt_ != NULL) {
|
delete webm_ctx_;
|
||||||
nestegg_free_packet(pkt_);
|
|
||||||
}
|
|
||||||
nestegg_destroy(nestegg_ctx_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Init() {
|
virtual void Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Begin() {
|
virtual void Begin() {
|
||||||
input_file_ = OpenTestDataFile(file_name_);
|
vpx_ctx_->file = OpenTestDataFile(file_name_);
|
||||||
ASSERT_TRUE(input_file_ != NULL) << "Input file open failed. Filename: "
|
ASSERT_TRUE(vpx_ctx_->file != NULL) << "Input file open failed. Filename: "
|
||||||
<< file_name_;
|
<< file_name_;
|
||||||
|
|
||||||
nestegg_io io = {nestegg_read_cb, nestegg_seek_cb, nestegg_tell_cb,
|
ASSERT_EQ(file_is_webm(webm_ctx_, vpx_ctx_), 1) << "file is not WebM";
|
||||||
input_file_};
|
|
||||||
ASSERT_FALSE(nestegg_init(&nestegg_ctx_, io, NULL, -1))
|
|
||||||
<< "nestegg_init failed";
|
|
||||||
|
|
||||||
unsigned int n;
|
|
||||||
ASSERT_FALSE(nestegg_track_count(nestegg_ctx_, &n))
|
|
||||||
<< "failed to get track count";
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < n; i++) {
|
|
||||||
int track_type = nestegg_track_type(nestegg_ctx_, i);
|
|
||||||
ASSERT_GE(track_type, 0) << "failed to get track type";
|
|
||||||
|
|
||||||
if (track_type == NESTEGG_TRACK_VIDEO) {
|
|
||||||
video_track_ = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FillFrame();
|
FillFrame();
|
||||||
}
|
}
|
||||||
@ -134,36 +60,12 @@ class WebMVideoSource : public CompressedVideoSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FillFrame() {
|
void FillFrame() {
|
||||||
ASSERT_TRUE(input_file_ != NULL);
|
ASSERT_TRUE(vpx_ctx_->file != NULL);
|
||||||
if (chunk_ >= chunks_) {
|
const int status = webm_read_frame(webm_ctx_, &buf_, &buf_sz_, &buf_sz_);
|
||||||
unsigned int track;
|
ASSERT_GE(status, 0) << "webm_read_frame failed";
|
||||||
|
if (status == 1) {
|
||||||
do {
|
end_of_file_ = true;
|
||||||
/* End of this packet, get another. */
|
|
||||||
if (pkt_ != NULL) {
|
|
||||||
nestegg_free_packet(pkt_);
|
|
||||||
pkt_ = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int again = nestegg_read_packet(nestegg_ctx_, &pkt_);
|
|
||||||
ASSERT_GE(again, 0) << "nestegg_read_packet failed";
|
|
||||||
if (!again) {
|
|
||||||
end_of_file_ = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT_FALSE(nestegg_packet_track(pkt_, &track))
|
|
||||||
<< "nestegg_packet_track failed";
|
|
||||||
} while (track != video_track_);
|
|
||||||
|
|
||||||
ASSERT_FALSE(nestegg_packet_count(pkt_, &chunks_))
|
|
||||||
<< "nestegg_packet_count failed";
|
|
||||||
chunk_ = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_FALSE(nestegg_packet_data(pkt_, chunk_, &buf_, &buf_sz_))
|
|
||||||
<< "nestegg_packet_data failed";
|
|
||||||
chunk_++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const uint8_t *cxdata() const {
|
virtual const uint8_t *cxdata() const {
|
||||||
@ -174,12 +76,8 @@ class WebMVideoSource : public CompressedVideoSource {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string file_name_;
|
std::string file_name_;
|
||||||
FILE *input_file_;
|
VpxInputContext *vpx_ctx_;
|
||||||
nestegg *nestegg_ctx_;
|
WebmInputContext *webm_ctx_;
|
||||||
nestegg_packet *pkt_;
|
|
||||||
unsigned int video_track_;
|
|
||||||
unsigned int chunk_;
|
|
||||||
unsigned int chunks_;
|
|
||||||
uint8_t *buf_;
|
uint8_t *buf_;
|
||||||
size_t buf_sz_;
|
size_t buf_sz_;
|
||||||
unsigned int frame_;
|
unsigned int frame_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user