FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 /**
30  * The following API around MediaCodec and MediaFormat is based on the
31  * NDK one provided by Google since Android 5.0.
32  *
33  * Differences from the NDK API:
34  *
35  * Buffers returned by ff_AMediaFormat_toString and ff_AMediaFormat_getString
36  * are newly allocated buffer and must be freed by the user after use.
37  *
38  * The MediaCrypto API is not implemented.
39  *
40  * ff_AMediaCodec_infoTryAgainLater, ff_AMediaCodec_infoOutputBuffersChanged,
41  * ff_AMediaCodec_infoOutputFormatChanged, ff_AMediaCodec_cleanOutputBuffers
42  * ff_AMediaCodec_getName and ff_AMediaCodec_getBufferFlagEndOfStream are not
43  * part of the original NDK API and are convenience functions to hide JNI
44  * implementation.
45  *
46  * The API around MediaCodecList is not part of the NDK (and is lacking as
47  * we still need to retreive the codec name to work around faulty decoders
48  * and encoders).
49  *
50  * For documentation, please refers to NdkMediaCodec.h NdkMediaFormat.h and
51  * http://developer.android.com/reference/android/media/MediaCodec.html.
52  *
53  */
54 
56 
57 char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx);
58 
59 struct FFAMediaFormat;
60 typedef struct FFAMediaFormat FFAMediaFormat;
61 
64 
66 
68 int ff_AMediaFormat_getInt64(FFAMediaFormat* format, const char *name, int64_t *out);
69 int ff_AMediaFormat_getFloat(FFAMediaFormat* format, const char *name, float *out);
70 int ff_AMediaFormat_getBuffer(FFAMediaFormat* format, const char *name, void** data, size_t *size);
71 int ff_AMediaFormat_getString(FFAMediaFormat* format, const char *name, const char **out);
72 
74 void ff_AMediaFormat_setInt64(FFAMediaFormat* format, const char* name, int64_t value);
75 void ff_AMediaFormat_setFloat(FFAMediaFormat* format, const char* name, float value);
76 void ff_AMediaFormat_setString(FFAMediaFormat* format, const char* name, const char* value);
77 void ff_AMediaFormat_setBuffer(FFAMediaFormat* format, const char* name, void* data, size_t size);
78 
79 struct FFAMediaCodec;
80 typedef struct FFAMediaCodec FFAMediaCodec;
82 
87  uint32_t flags;
88 };
90 
92 
96 
97 int ff_AMediaCodec_configure(FFAMediaCodec* codec, const FFAMediaFormat* format, void* surface, void *crypto, uint32_t flags);
102 
103 uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size);
104 uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size);
105 
106 ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec* codec, int64_t timeoutUs);
107 int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec* codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
108 
109 ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec* codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs);
111 
112 int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec* codec, size_t idx, int render);
113 int ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, int64_t timestampNs);
114 
115 int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx);
117 int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t indx);
118 
122 
124 
126 
127 #endif /* AVCODEC_MEDIACODEC_WRAPPER_H */
ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec *codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
int ff_AMediaFormat_getString(FFAMediaFormat *format, const char *name, const char **out)
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
void ff_AMediaFormat_setBuffer(FFAMediaFormat *format, const char *name, void *data, size_t size)
FFAMediaFormat * ff_AMediaFormat_new(void)
int ff_AMediaFormat_getInt32(FFAMediaFormat *format, const char *name, int32_t *out)
char * ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx)
int ff_AMediaCodec_start(FFAMediaCodec *codec)
struct FFAMediaCodecCryptoInfo FFAMediaCodecCryptoInfo
int out_size
Definition: movenc.c:55
int ff_AMediaCodec_flush(FFAMediaCodec *codec)
int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec *codec, size_t idx, int render)
uint8_t
int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
int ff_AMediaFormat_delete(FFAMediaFormat *format)
FFAMediaCodec * ff_AMediaCodec_createDecoderByType(const char *mime_type)
ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec *codec, int64_t timeoutUs)
int ff_AMediaCodec_cleanOutputBuffers(FFAMediaCodec *codec)
ptrdiff_t size
Definition: opengl_enc.c:101
int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
int ff_AMediaFormat_getInt64(FFAMediaFormat *format, const char *name, int64_t *out)
char * ff_AMediaCodec_getName(FFAMediaCodec *codec)
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
char * ff_AMediaFormat_toString(FFAMediaFormat *format)
int ff_AMediaCodec_getBufferFlagKeyFrame(FFAMediaCodec *codec)
int ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, int64_t timestampNs)
int ff_AMediaCodec_delete(FFAMediaCodec *codec)
int ff_AMediaFormat_getFloat(FFAMediaFormat *format, const char *name, float *out)
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
int ff_AMediaFormat_getBuffer(FFAMediaFormat *format, const char *name, void **data, size_t *size)
int32_t
int ff_AMediaCodec_getBufferFlagCodecConfig(FFAMediaCodec *codec)
FFAMediaCodec * ff_AMediaCodec_createCodecByName(const char *name)
int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec *codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
uint8_t * ff_AMediaCodec_getOutputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
void ff_AMediaFormat_setInt32(FFAMediaFormat *format, const char *name, int32_t value)
main external API structure.
Definition: avcodec.h:1649
void ff_AMediaFormat_setInt64(FFAMediaFormat *format, const char *name, int64_t value)
void ff_AMediaFormat_setFloat(FFAMediaFormat *format, const char *name, float value)
static const char * format
Definition: movenc.c:47
void ff_AMediaFormat_setString(FFAMediaFormat *format, const char *name, const char *value)
int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t indx)
mfxU16 profile
Definition: qsvenc.c:42
static int flags
Definition: cpu.c:47
int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
The following API around MediaCodec and MediaFormat is based on the NDK one provided by Google since ...
int ff_AMediaCodec_getConfigureFlagEncode(FFAMediaCodec *codec)
FFAMediaFormat * ff_AMediaCodec_getOutputFormat(FFAMediaCodec *codec)
int ff_AMediaCodec_stop(FFAMediaCodec *codec)
uint8_t * ff_AMediaCodec_getInputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
FILE * out
Definition: movenc.c:54
int ff_AMediaCodec_configure(FFAMediaCodec *codec, const FFAMediaFormat *format, void *surface, void *crypto, uint32_t flags)
int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
FFAMediaCodec * ff_AMediaCodec_createEncoderByType(const char *mime_type)
const char * name
Definition: opengl_enc.c:103