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