blob: 329908eebf4e9dcb617594b345425dcc30273d7b [file] [log] [blame]
Tom Finegan2abe2d42013-11-18 14:39:51 -08001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -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 */
11#ifndef WEBMDEC_H_
12#define WEBMDEC_H_
13
14#include "./tools_common.h"
15
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;
31 uint64_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.
Vignesh Venkatasubramanianfa99c372016-04-25 13:46:42 -070051// buffer_size - pointer to buffer size.
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070052// Return values:
53// 0 - Success
54// 1 - End of Stream
55// -1 - Error
clang-format6c4d83e2016-08-08 19:03:30 -070056int webm_read_frame(struct WebmInputContext *webm_ctx, uint8_t **buffer,
Tom Finegan2abe2d42013-11-18 14:39:51 -080057 size_t *buffer_size);
58
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070059// Guesses the frame rate of the input file based on the container timestamps.
Tom Finegan2abe2d42013-11-18 14:39:51 -080060int webm_guess_framerate(struct WebmInputContext *webm_ctx,
Yaowu Xuf883b422016-08-30 14:01:10 -070061 struct AvxInputContext *aom_ctx);
Tom Finegan2abe2d42013-11-18 14:39:51 -080062
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070063// Resets the WebMInputContext.
Tom Finegan2abe2d42013-11-18 14:39:51 -080064void webm_free(struct WebmInputContext *webm_ctx);
65
James Zern25cfd8e2014-01-18 12:16:11 -080066#ifdef __cplusplus
67} // extern "C"
68#endif
69
Tom Finegan2abe2d42013-11-18 14:39:51 -080070#endif // WEBMDEC_H_