summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorVignesh Venkatasubramanian <vigneshv@google.com>2014-04-14 14:19:50 -0700
committerVignesh Venkatasubramanian <vigneshv@google.com>2014-04-18 00:32:30 -0700
commit4fd631754563c229fd0cb33f9ad5905a872f8ec7 (patch)
tree1654fe1a196dd6da44032ba806594c9af21d2c7f /test
parentd6fe868d87c52012abb62729adea3207f786d0be (diff)
downloadlibvpx-4fd631754563c229fd0cb33f9ad5905a872f8ec7.tar
libvpx-4fd631754563c229fd0cb33f9ad5905a872f8ec7.tar.gz
libvpx-4fd631754563c229fd0cb33f9ad5905a872f8ec7.tar.bz2
libvpx-4fd631754563c229fd0cb33f9ad5905a872f8ec7.zip
Remove duplicate code in test/webm_video_source.h
Remove duplicate WebM parsing code in test/webm_video_source.h and linking it against webmdec.c which does the exact same thing. Change-Id: Ib7152eecde890fca58be42028cab18c9cb54221c
Diffstat (limited to 'test')
-rw-r--r--test/test.mk3
-rw-r--r--test/webm_video_source.h138
2 files changed, 21 insertions, 120 deletions
diff --git a/test/test.mk b/test/test.mk
index 92664e225..f1a8ed9a0 100644
--- a/test/test.mk
+++ b/test/test.mk
@@ -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/src/nestegg.c
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) += test_vector_test.cc
diff --git a/test/webm_video_source.h b/test/webm_video_source.h
index 9d88ae360..dc76bb007 100644
--- a/test/webm_video_source.h
+++ b/test/webm_video_source.h
@@ -14,73 +14,20 @@
#include <cstdlib>
#include <new>
#include <string>
-#include "third_party/nestegg/include/nestegg/nestegg.h"
+#include "../tools_common.h"
+#include "../webmdec.h"
#include "test/video_source.h"
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,
// so that we can do actual file decodes.
class WebMVideoSource : public CompressedVideoSource {
public:
explicit WebMVideoSource(const std::string &file_name)
: file_name_(file_name),
- input_file_(NULL),
- nestegg_ctx_(NULL),
- pkt_(NULL),
- video_track_(0),
- chunk_(0),
- chunks_(0),
+ vpx_ctx_(new VpxInputContext()),
+ webm_ctx_(new WebmInputContext()),
buf_(NULL),
buf_sz_(0),
frame_(0),
@@ -88,42 +35,21 @@ class WebMVideoSource : public CompressedVideoSource {
}
virtual ~WebMVideoSource() {
- if (input_file_)
- fclose(input_file_);
- if (nestegg_ctx_ != NULL) {
- if (pkt_ != NULL) {
- nestegg_free_packet(pkt_);
- }
- nestegg_destroy(nestegg_ctx_);
- }
+ if (vpx_ctx_->file != NULL)
+ fclose(vpx_ctx_->file);
+ delete vpx_ctx_;
+ delete webm_ctx_;
}
virtual void Init() {
}
virtual void Begin() {
- input_file_ = OpenTestDataFile(file_name_);
- ASSERT_TRUE(input_file_ != NULL) << "Input file open failed. Filename: "
+ vpx_ctx_->file = OpenTestDataFile(file_name_);
+ ASSERT_TRUE(vpx_ctx_->file != NULL) << "Input file open failed. Filename: "
<< file_name_;
- nestegg_io io = {nestegg_read_cb, nestegg_seek_cb, nestegg_tell_cb,
- 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;
- }
- }
+ ASSERT_EQ(file_is_webm(webm_ctx_, vpx_ctx_), 1) << "file is not WebM";
FillFrame();
}
@@ -134,36 +60,12 @@ class WebMVideoSource : public CompressedVideoSource {
}
void FillFrame() {
- ASSERT_TRUE(input_file_ != NULL);
- if (chunk_ >= chunks_) {
- unsigned int track;
-
- do {
- /* 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_TRUE(vpx_ctx_->file != NULL);
+ const int status = webm_read_frame(webm_ctx_, &buf_, &buf_sz_, &buf_sz_);
+ ASSERT_GE(status, 0) << "webm_read_frame failed";
+ if (status == 1) {
+ end_of_file_ = true;
}
-
- ASSERT_FALSE(nestegg_packet_data(pkt_, chunk_, &buf_, &buf_sz_))
- << "nestegg_packet_data failed";
- chunk_++;
}
virtual const uint8_t *cxdata() const {
@@ -174,12 +76,8 @@ class WebMVideoSource : public CompressedVideoSource {
protected:
std::string file_name_;
- FILE *input_file_;
- nestegg *nestegg_ctx_;
- nestegg_packet *pkt_;
- unsigned int video_track_;
- unsigned int chunk_;
- unsigned int chunks_;
+ VpxInputContext *vpx_ctx_;
+ WebmInputContext *webm_ctx_;
uint8_t *buf_;
size_t buf_sz_;
unsigned int frame_;