blob: 76e2a48529a2df9ddc05e8f973c597ed1e5e6af8 [file] [log] [blame]
Tom Finegan2abe2d42013-11-18 14:39:51 -08001/*
James Zernb7c05bd2024-06-11 19:15:10 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
Tom Finegan2abe2d42013-11-18 14:39:51 -08003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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 Finegan2abe2d42013-11-18 14:39:51 -080010 */
James Zerne1cbb132018-08-22 14:10:36 -070011#ifndef AOM_COMMON_WEBMDEC_H_
12#define AOM_COMMON_WEBMDEC_H_
Tom Finegan2abe2d42013-11-18 14:39:51 -080013
Tom Finegandd3e2a52018-05-23 14:33:09 -070014#include "common/tools_common.h"
Tom Finegan2abe2d42013-11-18 14:39:51 -080015
James Zern25cfd8e2014-01-18 12:16:11 -080016#ifdef __cplusplus
17extern "C" {
18#endif
19
Yaowu Xuf883b422016-08-30 14:01:10 -070020struct AvxInputContext;
Tom Finegan2abe2d42013-11-18 14:39:51 -080021
22struct WebmInputContext {
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070023 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 Zern151b52f2022-08-18 16:18:08 -070031 int64_t timestamp_ns;
hkuangbe6aead2015-01-27 12:26:28 -080032 int is_key_frame;
Vignesh Venkatasubramanian1f05b192015-03-30 12:58:26 -070033 int reached_eos;
Tom Finegan2abe2d42013-11-18 14:39:51 -080034};
35
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070036// 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 Finegan2abe2d42013-11-18 14:39:51 -080041int file_is_webm(struct WebmInputContext *webm_ctx,
Yaowu Xuf883b422016-08-30 14:01:10 -070042 struct AvxInputContext *aom_ctx);
Tom Finegan2abe2d42013-11-18 14:39:51 -080043
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070044// 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 Venkatasubramanianfa99c372016-04-25 13:46:42 -070046// |*buffer_size| should be 0. Once all the frames are read and used,
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070047// 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 Finegan707b5752018-03-29 15:41:08 -070051// bytes_read - pointer to bytes read.
Vignesh Venkatasubramanianfa99c372016-04-25 13:46:42 -070052// buffer_size - pointer to buffer size.
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070053// Return values:
54// 0 - Success
55// 1 - End of Stream
56// -1 - Error
clang-format6c4d83e2016-08-08 19:03:30 -070057int webm_read_frame(struct WebmInputContext *webm_ctx, uint8_t **buffer,
Tom Finegan707b5752018-03-29 15:41:08 -070058 size_t *bytes_read, size_t *buffer_size);
Tom Finegan2abe2d42013-11-18 14:39:51 -080059
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070060// Guesses the frame rate of the input file based on the container timestamps.
Tom Finegan2abe2d42013-11-18 14:39:51 -080061int webm_guess_framerate(struct WebmInputContext *webm_ctx,
Yaowu Xuf883b422016-08-30 14:01:10 -070062 struct AvxInputContext *aom_ctx);
Tom Finegan2abe2d42013-11-18 14:39:51 -080063
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070064// Resets the WebMInputContext.
Tom Finegan2abe2d42013-11-18 14:39:51 -080065void webm_free(struct WebmInputContext *webm_ctx);
66
James Zern25cfd8e2014-01-18 12:16:11 -080067#ifdef __cplusplus
68} // extern "C"
69#endif
70
James Zerne1cbb132018-08-22 14:10:36 -070071#endif // AOM_COMMON_WEBMDEC_H_