Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -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. |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 10 | */ |
| 11 | #ifndef WEBMDEC_H_ |
| 12 | #define WEBMDEC_H_ |
| 13 | |
| 14 | #include "./tools_common.h" |
| 15 | |
James Zern | 25cfd8e | 2014-01-18 12:16:11 -0800 | [diff] [blame] | 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 20 | struct AvxInputContext; |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 21 | |
| 22 | struct WebmInputContext { |
Vignesh Venkatasubramanian | dbd2471 | 2014-04-03 00:41:14 -0700 | [diff] [blame] | 23 | void *reader; |
| 24 | void *segment; |
| 25 | uint8_t *buffer; |
| 26 | const void *cluster; |
| 27 | const void *block_entry; |
| 28 | const void *block; |
| 29 | int block_frame_index; |
| 30 | int video_track_index; |
| 31 | uint64_t timestamp_ns; |
hkuang | be6aead | 2015-01-27 12:26:28 -0800 | [diff] [blame] | 32 | int is_key_frame; |
Vignesh Venkatasubramanian | 1f05b19 | 2015-03-30 12:58:26 -0700 | [diff] [blame] | 33 | int reached_eos; |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 34 | }; |
| 35 | |
Vignesh Venkatasubramanian | dbd2471 | 2014-04-03 00:41:14 -0700 | [diff] [blame] | 36 | // Checks if the input is a WebM file. If so, initializes WebMInputContext so |
| 37 | // that webm_read_frame can be called to retrieve a video frame. |
| 38 | // Returns 1 on success and 0 on failure or input is not WebM file. |
| 39 | // TODO(vigneshv): Refactor this function into two smaller functions specific |
| 40 | // to their task. |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 41 | int file_is_webm(struct WebmInputContext *webm_ctx, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 42 | struct AvxInputContext *aom_ctx); |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 43 | |
Vignesh Venkatasubramanian | dbd2471 | 2014-04-03 00:41:14 -0700 | [diff] [blame] | 44 | // Reads a WebM Video Frame. Memory for the buffer is created, owned and managed |
| 45 | // by this function. For the first call, |buffer| should be NULL and |
Vignesh Venkatasubramanian | fa99c37 | 2016-04-25 13:46:42 -0700 | [diff] [blame] | 46 | // |*buffer_size| should be 0. Once all the frames are read and used, |
Vignesh Venkatasubramanian | dbd2471 | 2014-04-03 00:41:14 -0700 | [diff] [blame] | 47 | // webm_free() should be called, otherwise there will be a leak. |
| 48 | // Parameters: |
| 49 | // webm_ctx - WebmInputContext object |
| 50 | // buffer - pointer where the frame data will be filled. |
Vignesh Venkatasubramanian | fa99c37 | 2016-04-25 13:46:42 -0700 | [diff] [blame] | 51 | // buffer_size - pointer to buffer size. |
Vignesh Venkatasubramanian | dbd2471 | 2014-04-03 00:41:14 -0700 | [diff] [blame] | 52 | // Return values: |
| 53 | // 0 - Success |
| 54 | // 1 - End of Stream |
| 55 | // -1 - Error |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 56 | int webm_read_frame(struct WebmInputContext *webm_ctx, uint8_t **buffer, |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 57 | size_t *buffer_size); |
| 58 | |
Vignesh Venkatasubramanian | dbd2471 | 2014-04-03 00:41:14 -0700 | [diff] [blame] | 59 | // Guesses the frame rate of the input file based on the container timestamps. |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 60 | int webm_guess_framerate(struct WebmInputContext *webm_ctx, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 61 | struct AvxInputContext *aom_ctx); |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 62 | |
Vignesh Venkatasubramanian | dbd2471 | 2014-04-03 00:41:14 -0700 | [diff] [blame] | 63 | // Resets the WebMInputContext. |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 64 | void webm_free(struct WebmInputContext *webm_ctx); |
| 65 | |
James Zern | 25cfd8e | 2014-01-18 12:16:11 -0800 | [diff] [blame] | 66 | #ifdef __cplusplus |
| 67 | } // extern "C" |
| 68 | #endif |
| 69 | |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 70 | #endif // WEBMDEC_H_ |