Improved aom_smooth_predictor_16x 32,16,8
[aom.git] / test / webm_video_source.h
blobb6c99804212f28ba94b689592d502b7b79041601
1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
11 #ifndef TEST_WEBM_VIDEO_SOURCE_H_
12 #define TEST_WEBM_VIDEO_SOURCE_H_
13 #include <cstdarg>
14 #include <cstdio>
15 #include <cstdlib>
16 #include <new>
17 #include <string>
18 #include "../tools_common.h"
19 #include "../webmdec.h"
20 #include "test/video_source.h"
22 namespace libaom_test {
24 // This class extends VideoSource to allow parsing of WebM files,
25 // so that we can do actual file decodes.
26 class WebMVideoSource : public CompressedVideoSource {
27 public:
28 explicit WebMVideoSource(const std::string &file_name)
29 : file_name_(file_name), aom_ctx_(new AvxInputContext()),
30 webm_ctx_(new WebmInputContext()), buf_(NULL), buf_sz_(0), frame_(0),
31 end_of_file_(false) {}
33 virtual ~WebMVideoSource() {
34 if (aom_ctx_->file != NULL) fclose(aom_ctx_->file);
35 webm_free(webm_ctx_);
36 delete aom_ctx_;
37 delete webm_ctx_;
40 virtual void Init() {}
42 virtual void Begin() {
43 aom_ctx_->file = OpenTestDataFile(file_name_);
44 ASSERT_TRUE(aom_ctx_->file != NULL)
45 << "Input file open failed. Filename: " << file_name_;
47 ASSERT_EQ(file_is_webm(webm_ctx_, aom_ctx_), 1) << "file is not WebM";
49 FillFrame();
52 virtual void Next() {
53 ++frame_;
54 FillFrame();
57 void FillFrame() {
58 ASSERT_TRUE(aom_ctx_->file != NULL);
59 const int status = webm_read_frame(webm_ctx_, &buf_, &buf_sz_);
60 ASSERT_GE(status, 0) << "webm_read_frame failed";
61 if (status == 1) {
62 end_of_file_ = true;
66 void SeekToNextKeyFrame() {
67 ASSERT_TRUE(aom_ctx_->file != NULL);
68 do {
69 const int status = webm_read_frame(webm_ctx_, &buf_, &buf_sz_);
70 ASSERT_GE(status, 0) << "webm_read_frame failed";
71 ++frame_;
72 if (status == 1) {
73 end_of_file_ = true;
75 } while (!webm_ctx_->is_key_frame && !end_of_file_);
78 virtual const uint8_t *cxdata() const { return end_of_file_ ? NULL : buf_; }
79 virtual size_t frame_size() const { return buf_sz_; }
80 virtual unsigned int frame_number() const { return frame_; }
82 protected:
83 std::string file_name_;
84 AvxInputContext *aom_ctx_;
85 WebmInputContext *webm_ctx_;
86 uint8_t *buf_;
87 size_t buf_sz_;
88 unsigned int frame_;
89 bool end_of_file_;
92 } // namespace libaom_test
94 #endif // TEST_WEBM_VIDEO_SOURCE_H_