FFmpeg
mediacodec_wrapper.h
Go to the documentation of this file.
1 /*
2  * Android MediaCodec Wrapper
3  *
4  * Copyright (c) 2015-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_WRAPPER_H
24 #define AVCODEC_MEDIACODEC_WRAPPER_H
25 
26 #include <stdint.h>
27 #include <sys/types.h>
28 
29 #include "avcodec.h"
30 
31 /**
32  * The following API around MediaCodec and MediaFormat is based on the
33  * NDK one provided by Google since Android 5.0.
34  *
35  * Differences from the NDK API:
36  *
37  * Buffers returned by ff_AMediaFormat_toString and ff_AMediaFormat_getString
38  * are newly allocated buffer and must be freed by the user after use.
39  *
40  * The MediaCrypto API is not implemented.
41  *
42  * ff_AMediaCodec_infoTryAgainLater, ff_AMediaCodec_infoOutputBuffersChanged,
43  * ff_AMediaCodec_infoOutputFormatChanged, ff_AMediaCodec_cleanOutputBuffers
44  * ff_AMediaCodec_getName and ff_AMediaCodec_getBufferFlagEndOfStream are not
45  * part of the original NDK API and are convenience functions to hide JNI
46  * implementation.
47  *
48  * The API around MediaCodecList is not part of the NDK (and is lacking as
49  * we still need to retrieve the codec name to work around faulty decoders
50  * and encoders).
51  *
52  * For documentation, please refers to NdkMediaCodec.h NdkMediaFormat.h and
53  * http://developer.android.com/reference/android/media/MediaCodec.html.
54  *
55  */
56 
58 
59 char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx);
60 
61 struct FFAMediaFormat;
62 typedef struct FFAMediaFormat FFAMediaFormat;
63 
66 
68 
70 int ff_AMediaFormat_getInt64(FFAMediaFormat* format, const char *name, int64_t *out);
71 int ff_AMediaFormat_getFloat(FFAMediaFormat* format, const char *name, float *out);
72 int ff_AMediaFormat_getBuffer(FFAMediaFormat* format, const char *name, void** data, size_t *size);
73 int ff_AMediaFormat_getString(FFAMediaFormat* format, const char *name, const char **out);
74 
76 void ff_AMediaFormat_setInt64(FFAMediaFormat* format, const char* name, int64_t value);
77 void ff_AMediaFormat_setFloat(FFAMediaFormat* format, const char* name, float value);
78 void ff_AMediaFormat_setString(FFAMediaFormat* format, const char* name, const char* value);
79 void ff_AMediaFormat_setBuffer(FFAMediaFormat* format, const char* name, void* data, size_t size);
80 
81 struct FFAMediaCodec;
82 typedef struct FFAMediaCodec FFAMediaCodec;
84 
89  uint32_t flags;
90 };
92 
94 
98 
99 int ff_AMediaCodec_configure(FFAMediaCodec* codec, const FFAMediaFormat* format, void* surface, void *crypto, uint32_t flags);
104 
105 uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size);
106 uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size);
107 
108 ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec* codec, int64_t timeoutUs);
109 int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec* codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
110 
113 
114 int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec* codec, size_t idx, int render);
115 int ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, int64_t timestampNs);
116 
117 int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx);
119 int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t indx);
120 
124 
126 
128 
129 int ff_Build_SDK_INT(AVCodecContext *avctx);
130 
131 #endif /* AVCODEC_MEDIACODEC_WRAPPER_H */
ff_AMediaCodec_createEncoderByType
FFAMediaCodec * ff_AMediaCodec_createEncoderByType(const char *mime_type)
ff_Build_SDK_INT
int ff_Build_SDK_INT(AVCodecContext *avctx)
Definition: mediacodec_wrapper.c:1696
ff_AMediaCodec_dequeueOutputBuffer
ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec *codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:1484
out
FILE * out
Definition: movenc.c:54
FFAMediaCodecBufferInfo::offset
int32_t offset
Definition: mediacodec_wrapper.h:86
ff_AMediaFormat_getString
int ff_AMediaFormat_getString(FFAMediaFormat *format, const char *name, const char **out)
Definition: mediacodec_wrapper.c:914
ff_AMediaCodecList_getCodecNameByType
char * ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx)
Definition: mediacodec_wrapper.c:382
ff_AMediaFormat_new
FFAMediaFormat * ff_AMediaFormat_new(void)
Definition: mediacodec_wrapper.c:612
ff_AMediaCodec_start
int ff_AMediaCodec_start(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1365
out_size
int out_size
Definition: movenc.c:55
profile
mfxU16 profile
Definition: qsvenc.c:44
name
const char * name
Definition: avisynth_c.h:867
ff_AMediaFormat_setBuffer
void ff_AMediaFormat_setBuffer(FFAMediaFormat *format, const char *name, void *data, size_t size)
Definition: mediacodec_wrapper.c:1074
ff_AMediaCodec_releaseOutputBuffer
int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec *codec, size_t idx, int render)
Definition: mediacodec_wrapper.c:1416
data
const char data[16]
Definition: mxf.c:91
ff_AMediaFormat_getInt32
int ff_AMediaFormat_getInt32(FFAMediaFormat *format, const char *name, int32_t *out)
Definition: mediacodec_wrapper.c:739
FFAMediaCodecCryptoInfo
struct FFAMediaCodecCryptoInfo FFAMediaCodecCryptoInfo
Definition: mediacodec_wrapper.h:83
ff_AMediaCodec_infoTryAgainLater
int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.c:1638
ff_AMediaCodec_flush
int ff_AMediaCodec_flush(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1399
ff_AMediaCodec_createDecoderByType
FFAMediaCodec * ff_AMediaCodec_createDecoderByType(const char *mime_type)
ff_AMediaFormat_delete
int ff_AMediaFormat_delete(FFAMediaFormat *format)
Definition: mediacodec_wrapper.c:692
ff_AMediaCodec_dequeueInputBuffer
ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec *codec, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:1450
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
info
MIPS optimizations info
Definition: mips.txt:2
ff_AMediaCodec_cleanOutputBuffers
int ff_AMediaCodec_cleanOutputBuffers(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1673
ff_AMediaCodec_getBufferFlagEndOfStream
int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1658
ff_AMediaCodec_getName
char * ff_AMediaCodec_getName(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1325
ff_AMediaFormat_toString
char * ff_AMediaFormat_toString(FFAMediaFormat *format)
Definition: mediacodec_wrapper.c:714
ff_AMediaCodec_getBufferFlagKeyFrame
int ff_AMediaCodec_getBufferFlagKeyFrame(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1663
ff_AMediaCodec_releaseOutputBufferAtTime
int ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, int64_t timestampNs)
Definition: mediacodec_wrapper.c:1433
int32_t
int32_t
Definition: audio_convert.c:194
FFAMediaCodecBufferInfo
Definition: mediacodec_wrapper.h:85
FFAMediaCodecBufferInfo::size
int32_t size
Definition: mediacodec_wrapper.h:87
ff_AMediaFormat_getInt64
int ff_AMediaFormat_getInt64(FFAMediaFormat *format, const char *name, int64_t *out)
Definition: mediacodec_wrapper.c:778
ff_AMediaCodec_delete
int ff_AMediaCodec_delete(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1289
ff_AMediaCodec_queueInputBuffer
int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec *codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
Definition: mediacodec_wrapper.c:1467
ff_AMediaFormat_getFloat
int ff_AMediaFormat_getFloat(FFAMediaFormat *format, const char *name, float *out)
Definition: mediacodec_wrapper.c:817
ff_AMediaCodec_getOutputBuffer
uint8_t * ff_AMediaCodec_getOutputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:1567
ff_AMediaCodec_createCodecByName
FFAMediaCodec * ff_AMediaCodec_createCodecByName(const char *name)
size
int size
Definition: twinvq_data.h:11134
ff_AMediaFormat_getBuffer
int ff_AMediaFormat_getBuffer(FFAMediaFormat *format, const char *name, void **data, size_t *size)
Definition: mediacodec_wrapper.c:856
ff_AMediaFormat_setInt64
void ff_AMediaFormat_setInt64(FFAMediaFormat *format, const char *name, int64_t value)
Definition: mediacodec_wrapper.c:989
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
ff_AMediaFormat_setFloat
void ff_AMediaFormat_setFloat(FFAMediaFormat *format, const char *name, float value)
Definition: mediacodec_wrapper.c:1014
ff_AMediaCodec_getBufferFlagCodecConfig
int ff_AMediaCodec_getBufferFlagCodecConfig(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1653
ff_AMediaCodec_infoOutputFormatChanged
int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t indx)
Definition: mediacodec_wrapper.c:1648
FFAMediaCodec
Definition: mediacodec_wrapper.c:274
ff_AMediaFormat_setInt32
void ff_AMediaFormat_setInt32(FFAMediaFormat *format, const char *name, int32_t value)
Definition: mediacodec_wrapper.c:964
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
uint8_t
uint8_t
Definition: audio_convert.c:194
FFAMediaCodecBufferInfo::flags
uint32_t flags
Definition: mediacodec_wrapper.h:89
FFAMediaCodecBufferInfo::presentationTimeUs
int64_t presentationTimeUs
Definition: mediacodec_wrapper.h:88
avcodec.h
ff_AMediaCodecProfile_getProfileFromAVCodecContext
int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
The following API around MediaCodec and MediaFormat is based on the NDK one provided by Google since ...
Definition: mediacodec_wrapper.c:313
ff_AMediaFormat_setString
void ff_AMediaFormat_setString(FFAMediaFormat *format, const char *name, const char *value)
Definition: mediacodec_wrapper.c:1039
ff_AMediaCodec_getOutputFormat
FFAMediaFormat * ff_AMediaCodec_getOutputFormat(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1615
AVCodecContext
main external API structure.
Definition: avcodec.h:1565
ff_AMediaCodec_getConfigureFlagEncode
int ff_AMediaCodec_getConfigureFlagEncode(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1668
ff_AMediaCodec_configure
int ff_AMediaCodec_configure(FFAMediaCodec *codec, const FFAMediaFormat *format, void *surface, void *crypto, uint32_t flags)
Definition: mediacodec_wrapper.c:1348
ff_AMediaCodec_stop
int ff_AMediaCodec_stop(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1382
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
ff_AMediaCodec_getInputBuffer
uint8_t * ff_AMediaCodec_getInputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:1519
FFAMediaFormat
Definition: mediacodec_wrapper.c:162
ff_AMediaCodec_infoOutputBuffersChanged
int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.c:1643