1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Android MediaCodec public API
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * Copyright (c) 2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
5cabdff1aSopenharmony_ci *
6cabdff1aSopenharmony_ci * This file is part of FFmpeg.
7cabdff1aSopenharmony_ci *
8cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
9cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
10cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
11cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
12cabdff1aSopenharmony_ci *
13cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
14cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
15cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16cabdff1aSopenharmony_ci * Lesser General Public License for more details.
17cabdff1aSopenharmony_ci *
18cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
19cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
20cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21cabdff1aSopenharmony_ci */
22cabdff1aSopenharmony_ci
23cabdff1aSopenharmony_ci#ifndef AVCODEC_MEDIACODEC_H
24cabdff1aSopenharmony_ci#define AVCODEC_MEDIACODEC_H
25cabdff1aSopenharmony_ci
26cabdff1aSopenharmony_ci#include "libavcodec/avcodec.h"
27cabdff1aSopenharmony_ci
28cabdff1aSopenharmony_ci/**
29cabdff1aSopenharmony_ci * This structure holds a reference to a android/view/Surface object that will
30cabdff1aSopenharmony_ci * be used as output by the decoder.
31cabdff1aSopenharmony_ci *
32cabdff1aSopenharmony_ci */
33cabdff1aSopenharmony_citypedef struct AVMediaCodecContext {
34cabdff1aSopenharmony_ci
35cabdff1aSopenharmony_ci    /**
36cabdff1aSopenharmony_ci     * android/view/Surface object reference.
37cabdff1aSopenharmony_ci     */
38cabdff1aSopenharmony_ci    void *surface;
39cabdff1aSopenharmony_ci
40cabdff1aSopenharmony_ci} AVMediaCodecContext;
41cabdff1aSopenharmony_ci
42cabdff1aSopenharmony_ci/**
43cabdff1aSopenharmony_ci * Allocate and initialize a MediaCodec context.
44cabdff1aSopenharmony_ci *
45cabdff1aSopenharmony_ci * When decoding with MediaCodec is finished, the caller must free the
46cabdff1aSopenharmony_ci * MediaCodec context with av_mediacodec_default_free.
47cabdff1aSopenharmony_ci *
48cabdff1aSopenharmony_ci * @return a pointer to a newly allocated AVMediaCodecContext on success, NULL otherwise
49cabdff1aSopenharmony_ci */
50cabdff1aSopenharmony_ciAVMediaCodecContext *av_mediacodec_alloc_context(void);
51cabdff1aSopenharmony_ci
52cabdff1aSopenharmony_ci/**
53cabdff1aSopenharmony_ci * Convenience function that sets up the MediaCodec context.
54cabdff1aSopenharmony_ci *
55cabdff1aSopenharmony_ci * @param avctx codec context
56cabdff1aSopenharmony_ci * @param ctx MediaCodec context to initialize
57cabdff1aSopenharmony_ci * @param surface reference to an android/view/Surface
58cabdff1aSopenharmony_ci * @return 0 on success, < 0 otherwise
59cabdff1aSopenharmony_ci */
60cabdff1aSopenharmony_ciint av_mediacodec_default_init(AVCodecContext *avctx, AVMediaCodecContext *ctx, void *surface);
61cabdff1aSopenharmony_ci
62cabdff1aSopenharmony_ci/**
63cabdff1aSopenharmony_ci * This function must be called to free the MediaCodec context initialized with
64cabdff1aSopenharmony_ci * av_mediacodec_default_init().
65cabdff1aSopenharmony_ci *
66cabdff1aSopenharmony_ci * @param avctx codec context
67cabdff1aSopenharmony_ci */
68cabdff1aSopenharmony_civoid av_mediacodec_default_free(AVCodecContext *avctx);
69cabdff1aSopenharmony_ci
70cabdff1aSopenharmony_ci/**
71cabdff1aSopenharmony_ci * Opaque structure representing a MediaCodec buffer to render.
72cabdff1aSopenharmony_ci */
73cabdff1aSopenharmony_citypedef struct MediaCodecBuffer AVMediaCodecBuffer;
74cabdff1aSopenharmony_ci
75cabdff1aSopenharmony_ci/**
76cabdff1aSopenharmony_ci * Release a MediaCodec buffer and render it to the surface that is associated
77cabdff1aSopenharmony_ci * with the decoder. This function should only be called once on a given
78cabdff1aSopenharmony_ci * buffer, once released the underlying buffer returns to the codec, thus
79cabdff1aSopenharmony_ci * subsequent calls to this function will have no effect.
80cabdff1aSopenharmony_ci *
81cabdff1aSopenharmony_ci * @param buffer the buffer to render
82cabdff1aSopenharmony_ci * @param render 1 to release and render the buffer to the surface or 0 to
83cabdff1aSopenharmony_ci * discard the buffer
84cabdff1aSopenharmony_ci * @return 0 on success, < 0 otherwise
85cabdff1aSopenharmony_ci */
86cabdff1aSopenharmony_ciint av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render);
87cabdff1aSopenharmony_ci
88cabdff1aSopenharmony_ci/**
89cabdff1aSopenharmony_ci * Release a MediaCodec buffer and render it at the given time to the surface
90cabdff1aSopenharmony_ci * that is associated with the decoder. The timestamp must be within one second
91cabdff1aSopenharmony_ci * of the current java/lang/System#nanoTime() (which is implemented using
92cabdff1aSopenharmony_ci * CLOCK_MONOTONIC on Android). See the Android MediaCodec documentation
93cabdff1aSopenharmony_ci * of android/media/MediaCodec#releaseOutputBuffer(int,long) for more details.
94cabdff1aSopenharmony_ci *
95cabdff1aSopenharmony_ci * @param buffer the buffer to render
96cabdff1aSopenharmony_ci * @param time timestamp in nanoseconds of when to render the buffer
97cabdff1aSopenharmony_ci * @return 0 on success, < 0 otherwise
98cabdff1aSopenharmony_ci */
99cabdff1aSopenharmony_ciint av_mediacodec_render_buffer_at_time(AVMediaCodecBuffer *buffer, int64_t time);
100cabdff1aSopenharmony_ci
101cabdff1aSopenharmony_ci#endif /* AVCODEC_MEDIACODEC_H */
102