John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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. |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 10 | */ |
| 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> |
Vignesh Venkatasubramanian | 4fd6317 | 2014-04-14 14:19:50 -0700 | [diff] [blame] | 18 | #include "../tools_common.h" |
| 19 | #include "../webmdec.h" |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 20 | #include "test/video_source.h" |
| 21 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 22 | namespace libaom_test { |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 23 | |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 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) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 29 | : file_name_(file_name), aom_ctx_(new AvxInputContext()), |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 30 | webm_ctx_(new WebmInputContext()), buf_(NULL), buf_sz_(0), frame_(0), |
| 31 | end_of_file_(false) {} |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 32 | |
| 33 | virtual ~WebMVideoSource() { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 34 | if (aom_ctx_->file != NULL) fclose(aom_ctx_->file); |
James Zern | 96f8895 | 2014-04-19 09:29:26 -0700 | [diff] [blame] | 35 | webm_free(webm_ctx_); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 36 | delete aom_ctx_; |
Vignesh Venkatasubramanian | 4fd6317 | 2014-04-14 14:19:50 -0700 | [diff] [blame] | 37 | delete webm_ctx_; |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 38 | } |
| 39 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 40 | virtual void Init() {} |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 41 | |
| 42 | virtual void Begin() { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 43 | aom_ctx_->file = OpenTestDataFile(file_name_); |
| 44 | ASSERT_TRUE(aom_ctx_->file != NULL) << "Input file open failed. Filename: " |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 45 | << file_name_; |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 46 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 47 | ASSERT_EQ(file_is_webm(webm_ctx_, aom_ctx_), 1) << "file is not WebM"; |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 48 | |
| 49 | FillFrame(); |
| 50 | } |
| 51 | |
| 52 | virtual void Next() { |
| 53 | ++frame_; |
| 54 | FillFrame(); |
| 55 | } |
| 56 | |
| 57 | void FillFrame() { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 58 | ASSERT_TRUE(aom_ctx_->file != NULL); |
Vignesh Venkatasubramanian | fa99c37 | 2016-04-25 13:46:42 -0700 | [diff] [blame] | 59 | const int status = webm_read_frame(webm_ctx_, &buf_, &buf_sz_); |
Vignesh Venkatasubramanian | 4fd6317 | 2014-04-14 14:19:50 -0700 | [diff] [blame] | 60 | ASSERT_GE(status, 0) << "webm_read_frame failed"; |
| 61 | if (status == 1) { |
| 62 | end_of_file_ = true; |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 63 | } |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 64 | } |
| 65 | |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 66 | void SeekToNextKeyFrame() { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 67 | ASSERT_TRUE(aom_ctx_->file != NULL); |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 68 | do { |
Vignesh Venkatasubramanian | fa99c37 | 2016-04-25 13:46:42 -0700 | [diff] [blame] | 69 | const int status = webm_read_frame(webm_ctx_, &buf_, &buf_sz_); |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 70 | ASSERT_GE(status, 0) << "webm_read_frame failed"; |
| 71 | ++frame_; |
| 72 | if (status == 1) { |
| 73 | end_of_file_ = true; |
| 74 | } |
| 75 | } while (!webm_ctx_->is_key_frame && !end_of_file_); |
| 76 | } |
| 77 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 78 | virtual const uint8_t *cxdata() const { return end_of_file_ ? NULL : buf_; } |
Tom Finegan | eb2325e | 2014-02-19 14:17:55 -0800 | [diff] [blame] | 79 | virtual size_t frame_size() const { return buf_sz_; } |
| 80 | virtual unsigned int frame_number() const { return frame_; } |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 81 | |
| 82 | protected: |
| 83 | std::string file_name_; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 84 | AvxInputContext *aom_ctx_; |
Vignesh Venkatasubramanian | 4fd6317 | 2014-04-14 14:19:50 -0700 | [diff] [blame] | 85 | WebmInputContext *webm_ctx_; |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 86 | uint8_t *buf_; |
| 87 | size_t buf_sz_; |
| 88 | unsigned int frame_; |
| 89 | bool end_of_file_; |
| 90 | }; |
| 91 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 92 | } // namespace libaom_test |
John Koleszar | 119c981 | 2013-06-13 12:42:05 -0700 | [diff] [blame] | 93 | |
| 94 | #endif // TEST_WEBM_VIDEO_SOURCE_H_ |