Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 1 | /* |
James Zern | b7c05bd | 2024-06-11 19:15:10 -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 | */ |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 11 | #ifndef AOM_COMMON_WEBMDEC_H_ |
| 12 | #define AOM_COMMON_WEBMDEC_H_ |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 13 | |
Tom Finegan | dd3e2a5 | 2018-05-23 14:33:09 -0700 | [diff] [blame] | 14 | #include "common/tools_common.h" |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 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; |
James Zern | 151b52f | 2022-08-18 16:18:08 -0700 | [diff] [blame] | 31 | int64_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. |
Tom Finegan | 707b575 | 2018-03-29 15:41:08 -0700 | [diff] [blame] | 51 | // bytes_read - pointer to bytes read. |
Vignesh Venkatasubramanian | fa99c37 | 2016-04-25 13:46:42 -0700 | [diff] [blame] | 52 | // buffer_size - pointer to buffer size. |
Vignesh Venkatasubramanian | dbd2471 | 2014-04-03 00:41:14 -0700 | [diff] [blame] | 53 | // Return values: |
| 54 | // 0 - Success |
| 55 | // 1 - End of Stream |
| 56 | // -1 - Error |
clang-format | 6c4d83e | 2016-08-08 19:03:30 -0700 | [diff] [blame] | 57 | int webm_read_frame(struct WebmInputContext *webm_ctx, uint8_t **buffer, |
Tom Finegan | 707b575 | 2018-03-29 15:41:08 -0700 | [diff] [blame] | 58 | size_t *bytes_read, size_t *buffer_size); |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 59 | |
Vignesh Venkatasubramanian | dbd2471 | 2014-04-03 00:41:14 -0700 | [diff] [blame] | 60 | // 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] | 61 | int webm_guess_framerate(struct WebmInputContext *webm_ctx, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 62 | struct AvxInputContext *aom_ctx); |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 63 | |
Vignesh Venkatasubramanian | dbd2471 | 2014-04-03 00:41:14 -0700 | [diff] [blame] | 64 | // Resets the WebMInputContext. |
Tom Finegan | 2abe2d4 | 2013-11-18 14:39:51 -0800 | [diff] [blame] | 65 | void webm_free(struct WebmInputContext *webm_ctx); |
| 66 | |
James Zern | 25cfd8e | 2014-01-18 12:16:11 -0800 | [diff] [blame] | 67 | #ifdef __cplusplus |
| 68 | } // extern "C" |
| 69 | #endif |
| 70 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 71 | #endif // AOM_COMMON_WEBMDEC_H_ |