blob: 7d1638035523131d667912159f2233c5f8caefb6 [file] [log] [blame]
Tom Finegan2abe2d42013-11-18 14:39:51 -08001/*
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10#ifndef WEBMDEC_H_
11#define WEBMDEC_H_
12
13#include "./tools_common.h"
14
James Zern25cfd8e2014-01-18 12:16:11 -080015#ifdef __cplusplus
16extern "C" {
17#endif
18
Tom Finegan2abe2d42013-11-18 14:39:51 -080019struct VpxInputContext;
20
21struct WebmInputContext {
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070022 void *reader;
23 void *segment;
24 uint8_t *buffer;
25 const void *cluster;
26 const void *block_entry;
27 const void *block;
28 int block_frame_index;
29 int video_track_index;
30 uint64_t timestamp_ns;
hkuangbe6aead2015-01-27 12:26:28 -080031 int is_key_frame;
Vignesh Venkatasubramanian1f05b192015-03-30 12:58:26 -070032 int reached_eos;
Tom Finegan2abe2d42013-11-18 14:39:51 -080033};
34
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070035// Checks if the input is a WebM file. If so, initializes WebMInputContext so
36// that webm_read_frame can be called to retrieve a video frame.
37// Returns 1 on success and 0 on failure or input is not WebM file.
38// TODO(vigneshv): Refactor this function into two smaller functions specific
39// to their task.
Tom Finegan2abe2d42013-11-18 14:39:51 -080040int file_is_webm(struct WebmInputContext *webm_ctx,
41 struct VpxInputContext *vpx_ctx);
42
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070043// Reads a WebM Video Frame. Memory for the buffer is created, owned and managed
44// by this function. For the first call, |buffer| should be NULL and
45// |*bytes_in_buffer| should be 0. Once all the frames are read and used,
46// webm_free() should be called, otherwise there will be a leak.
47// Parameters:
48// webm_ctx - WebmInputContext object
49// buffer - pointer where the frame data will be filled.
50// bytes_in_buffer - pointer to buffer size.
51// buffer_size - unused TODO(vigneshv): remove this
52// Return values:
53// 0 - Success
54// 1 - End of Stream
55// -1 - Error
56// TODO(vigneshv): Make the return values consistent across all functions in
57// this file.
Tom Finegan2abe2d42013-11-18 14:39:51 -080058int webm_read_frame(struct WebmInputContext *webm_ctx,
59 uint8_t **buffer,
60 size_t *bytes_in_buffer,
61 size_t *buffer_size);
62
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070063// Guesses the frame rate of the input file based on the container timestamps.
Tom Finegan2abe2d42013-11-18 14:39:51 -080064int webm_guess_framerate(struct WebmInputContext *webm_ctx,
65 struct VpxInputContext *vpx_ctx);
66
Vignesh Venkatasubramaniandbd24712014-04-03 00:41:14 -070067// Resets the WebMInputContext.
Tom Finegan2abe2d42013-11-18 14:39:51 -080068void webm_free(struct WebmInputContext *webm_ctx);
69
James Zern25cfd8e2014-01-18 12:16:11 -080070#ifdef __cplusplus
71} // extern "C"
72#endif
73
Tom Finegan2abe2d42013-11-18 14:39:51 -080074#endif // WEBMDEC_H_