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 #include "mediacodec_surface.h"
31 
32 /**
33  * The following API around MediaCodec and MediaFormat is based on the
34  * NDK one provided by Google since Android 5.0.
35  *
36  * Differences from the NDK API:
37  *
38  * Buffers returned by ff_AMediaFormat_toString and ff_AMediaFormat_getString
39  * are newly allocated buffer and must be freed by the user after use.
40  *
41  * The MediaCrypto API is not implemented.
42  *
43  * ff_AMediaCodec_infoTryAgainLater, ff_AMediaCodec_infoOutputBuffersChanged,
44  * ff_AMediaCodec_infoOutputFormatChanged, ff_AMediaCodec_cleanOutputBuffers
45  * ff_AMediaCodec_getName and ff_AMediaCodec_getBufferFlagEndOfStream are not
46  * part of the original NDK API and are convenience functions to hide JNI
47  * implementation.
48  *
49  * The API around MediaCodecList is not part of the NDK (and is lacking as
50  * we still need to retrieve the codec name to work around faulty decoders
51  * and encoders).
52  *
53  * For documentation, please refers to NdkMediaCodec.h NdkMediaFormat.h and
54  * http://developer.android.com/reference/android/media/MediaCodec.html.
55  *
56  */
57 
59 
60 char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx);
61 
62 typedef struct FFAMediaFormat FFAMediaFormat;
64  const AVClass *class;
65 
66  FFAMediaFormat *(*create)(void);
67  int (*delete)(FFAMediaFormat *);
68 
69  char* (*toString)(FFAMediaFormat* format);
70 
71  int (*getInt32)(FFAMediaFormat* format, const char *name, int32_t *out);
72  int (*getInt64)(FFAMediaFormat* format, const char *name, int64_t *out);
73  int (*getFloat)(FFAMediaFormat* format, const char *name, float *out);
74  int (*getBuffer)(FFAMediaFormat* format, const char *name, void** data, size_t *size);
75  int (*getString)(FFAMediaFormat* format, const char *name, const char **out);
76  // NDK only, introduced in API level 28
77  int (*getRect)(FFAMediaFormat *, const char *name,
78  int32_t *left, int32_t *top, int32_t *right, int32_t *bottom);
79 
80  void (*setInt32)(FFAMediaFormat* format, const char* name, int32_t value);
81  void (*setInt64)(FFAMediaFormat* format, const char* name, int64_t value);
82  void (*setFloat)(FFAMediaFormat* format, const char* name, float value);
83  void (*setString)(FFAMediaFormat* format, const char* name, const char* value);
84  void (*setBuffer)(FFAMediaFormat* format, const char* name, void* data, size_t size);
85  // NDK only, introduced in API level 28
86  void (*setRect)(FFAMediaFormat*, const char* name,
87  int32_t left, int32_t top, int32_t right, int32_t bottom);
88 };
89 
91 
93 {
94  return format->delete(format);
95 }
96 
98 {
99  return format->toString(format);
100 }
101 
102 static inline int ff_AMediaFormat_getInt32(FFAMediaFormat* format, const char *name, int32_t *out)
103 {
104  return format->getInt32(format, name, out);
105 }
106 
107 static inline int ff_AMediaFormat_getInt64(FFAMediaFormat* format, const char *name, int64_t *out)
108 {
109  return format->getInt64(format, name, out);
110 }
111 
112 static inline int ff_AMediaFormat_getFloat(FFAMediaFormat* format, const char *name, float *out)
113 {
114  return format->getFloat(format, name, out);
115 }
116 
117 static inline int ff_AMediaFormat_getBuffer(FFAMediaFormat* format, const char *name, void** data, size_t *size)
118 {
119  return format->getBuffer(format, name, data, size);
120 }
121 
122 static inline int ff_AMediaFormat_getString(FFAMediaFormat* format, const char *name, const char **out)
123 {
124  return format->getString(format, name, out);
125 }
126 
127 static inline int ff_AMediaFormat_getRect(FFAMediaFormat *format, const char *name,
128  int32_t *left, int32_t *top, int32_t *right, int32_t *bottom)
129 {
130  if (!format->getRect)
131  return AVERROR_EXTERNAL;
132  return format->getRect(format, name, left, top, right, bottom);
133 }
134 
136 {
137  format->setInt32(format, name, value);
138 }
139 
141 {
142  format->setInt64(format, name, value);
143 }
144 
145 static inline void ff_AMediaFormat_setFloat(FFAMediaFormat* format, const char* name, float value)
146 {
147  format->setFloat(format, name, value);
148 }
149 
150 static inline void ff_AMediaFormat_setString(FFAMediaFormat* format, const char* name, const char* value)
151 {
152  format->setString(format, name, value);
153 }
154 
155 static inline void ff_AMediaFormat_setBuffer(FFAMediaFormat* format, const char* name, void* data, size_t size)
156 {
157  format->setBuffer(format, name, data, size);
158 }
159 
160 static inline void ff_AMediaFormat_setRect(FFAMediaFormat* format, const char* name,
161  int32_t left, int32_t top, int32_t right, int32_t bottom)
162 {
163  if (!format->setRect) {
164  av_log(format, AV_LOG_WARNING, "Doesn't support setRect\n");
165  return;
166  }
167  format->setRect(format, name, left, top, right, bottom);
168 }
169 
171 
176  uint32_t flags;
177 };
179 
180 typedef struct FFAMediaCodec FFAMediaCodec;
181 
183  void (*onAsyncInputAvailable)(FFAMediaCodec *codec, void *userdata,
184  int32_t index);
185 
186  void (*onAsyncOutputAvailable)(FFAMediaCodec *codec, void *userdata,
187  int32_t index,
188  FFAMediaCodecBufferInfo *buffer_info);
189 
190  void (*onAsyncFormatChanged)(FFAMediaCodec *codec, void *userdata,
192 
193  void (*onAsyncError)(FFAMediaCodec *codec, void *userdata, int error,
194  const char *detail);
196 
198  const AVClass *class;
199 
200  char *(*getName)(FFAMediaCodec *codec);
201 
202  FFAMediaCodec* (*createCodecByName)(const char *name);
203  FFAMediaCodec* (*createDecoderByType)(const char *mime_type);
204  FFAMediaCodec* (*createEncoderByType)(const char *mime_type);
205  int (*delete)(FFAMediaCodec* codec);
206 
207  int (*configure)(FFAMediaCodec* codec, const FFAMediaFormat* format, FFANativeWindow* surface, void *crypto, uint32_t flags);
208  int (*start)(FFAMediaCodec* codec);
209  int (*stop)(FFAMediaCodec* codec);
210  int (*flush)(FFAMediaCodec* codec);
211 
212  uint8_t* (*getInputBuffer)(FFAMediaCodec* codec, size_t idx, size_t *out_size);
213  uint8_t* (*getOutputBuffer)(FFAMediaCodec* codec, size_t idx, size_t *out_size);
214 
215  ssize_t (*dequeueInputBuffer)(FFAMediaCodec* codec, int64_t timeoutUs);
216  int (*queueInputBuffer)(FFAMediaCodec* codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
217 
219  FFAMediaFormat* (*getOutputFormat)(FFAMediaCodec* codec);
220 
221  int (*releaseOutputBuffer)(FFAMediaCodec* codec, size_t idx, int render);
222  int (*releaseOutputBufferAtTime)(FFAMediaCodec *codec, size_t idx, int64_t timestampNs);
223 
224  int (*infoTryAgainLater)(FFAMediaCodec *codec, ssize_t idx);
225  int (*infoOutputBuffersChanged)(FFAMediaCodec *codec, ssize_t idx);
226  int (*infoOutputFormatChanged)(FFAMediaCodec *codec, ssize_t indx);
227 
231 
233 
235 
236  // For encoder with FFANativeWindow as input.
238 
239  // Introduced in Android API 28
242  void *userdata);
243 };
244 
245 static inline char *ff_AMediaCodec_getName(FFAMediaCodec *codec)
246 {
247  return codec->getName(codec);
248 }
249 
251 FFAMediaCodec* ff_AMediaCodec_createDecoderByType(const char *mime_type, int ndk);
252 FFAMediaCodec* ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk);
253 
254 static inline int ff_AMediaCodec_configure(FFAMediaCodec *codec,
255  const FFAMediaFormat *format,
256  FFANativeWindow *surface,
257  void *crypto, uint32_t flags)
258 {
259  return codec->configure(codec, format, surface, crypto, flags);
260 }
261 
262 static inline int ff_AMediaCodec_start(FFAMediaCodec* codec)
263 {
264  return codec->start(codec);
265 }
266 
267 static inline int ff_AMediaCodec_stop(FFAMediaCodec* codec)
268 {
269  return codec->stop(codec);
270 }
271 
272 static inline int ff_AMediaCodec_flush(FFAMediaCodec* codec)
273 {
274  return codec->flush(codec);
275 }
276 
277 static inline int ff_AMediaCodec_delete(FFAMediaCodec* codec)
278 {
279  return codec->delete(codec);
280 }
281 
282 static inline uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size)
283 {
284  return codec->getInputBuffer(codec, idx, out_size);
285 }
286 
287 static inline uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size)
288 {
289  return codec->getOutputBuffer(codec, idx, out_size);
290 }
291 
292 static inline ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec* codec, int64_t timeoutUs)
293 {
294  return codec->dequeueInputBuffer(codec, timeoutUs);
295 }
296 
297 static inline int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec *codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
298 {
299  return codec->queueInputBuffer(codec, idx, offset, size, time, flags);
300 }
301 
303 {
304  return codec->dequeueOutputBuffer(codec, info, timeoutUs);
305 }
306 
308 {
309  return codec->getOutputFormat(codec);
310 }
311 
312 static inline int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec* codec, size_t idx, int render)
313 {
314  return codec->releaseOutputBuffer(codec, idx, render);
315 }
316 
317 static inline int ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, int64_t timestampNs)
318 {
319  return codec->releaseOutputBufferAtTime(codec, idx, timestampNs);
320 }
321 
322 static inline int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
323 {
324  return codec->infoTryAgainLater(codec, idx);
325 }
326 
327 static inline int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
328 {
329  return codec->infoOutputBuffersChanged(codec, idx);
330 }
331 
332 static inline int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t idx)
333 {
334  return codec->infoOutputFormatChanged(codec, idx);
335 }
336 
338 {
339  return codec->getBufferFlagCodecConfig(codec);
340 }
341 
343 {
344  return codec->getBufferFlagEndOfStream(codec);
345 }
346 
348 {
349  return codec->getBufferFlagKeyFrame(codec);
350 }
351 
353 {
354  return codec->getConfigureFlagEncode(codec);
355 }
356 
358 {
359  return codec->cleanOutputBuffers(codec);
360 }
361 
363 {
364  return codec->signalEndOfInputStream(codec);
365 }
366 
369  void *userdata)
370 {
371  return codec->setAsyncNotifyCallback(codec, callback, userdata);
372 }
373 
374 int ff_Build_SDK_INT(AVCodecContext *avctx);
375 
380 };
381 
388 };
389 
396 };
397 
398 /**
399  * Map MediaFormat color range to AVColorRange.
400  *
401  * return AVCOL_RANGE_UNSPECIFIED when failed.
402  */
404 
405 /**
406  * Map AVColorRange to MediaFormat color range.
407  *
408  * return COLOR_RANGE_UNSPECIFIED when failed.
409  */
411 
412 /**
413  * Map MediaFormat color standard to AVColorSpace.
414  *
415  * return AVCOL_SPC_UNSPECIFIED when failed.
416  */
418 
419 /**
420  * Map AVColorSpace to MediaFormat color standard.
421  *
422  * return COLOR_STANDARD_UNSPECIFIED when failed.
423  */
425 
426 /**
427  * Map MediaFormat color standard to AVColorPrimaries.
428  *
429  * return AVCOL_PRI_UNSPECIFIED when failed.
430  */
432 
433 /**
434  * Map MediaFormat color transfer to AVColorTransferCharacteristic.
435  *
436  * return AVCOL_TRC_UNSPECIFIED when failed.
437  */
440 
441 /**
442  * Map AVColorTransferCharacteristic to MediaFormat color transfer.
443  *
444  * return COLOR_TRANSFER_UNSPECIFIED when failed.
445  */
447  enum AVColorTransferCharacteristic color_transfer);
448 
449 #endif /* AVCODEC_MEDIACODEC_WRAPPER_H */
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
ff_AMediaCodec_getInputBuffer
static uint8_t * ff_AMediaCodec_getInputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:282
ff_AMediaFormat_setRect
static void ff_AMediaFormat_setRect(FFAMediaFormat *format, const char *name, int32_t left, int32_t top, int32_t right, int32_t bottom)
Definition: mediacodec_wrapper.h:160
ff_AMediaFormat_delete
static int ff_AMediaFormat_delete(FFAMediaFormat *format)
Definition: mediacodec_wrapper.h:92
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
FFAMediaCodec::getBufferFlagKeyFrame
int(* getBufferFlagKeyFrame)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:230
ff_Build_SDK_INT
int ff_Build_SDK_INT(AVCodecContext *avctx)
Definition: mediacodec_wrapper.c:2559
ff_AMediaCodec_delete
static int ff_AMediaCodec_delete(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:277
name
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 minimum maximum flags name is the option name
Definition: writing_filters.txt:88
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:627
out
FILE * out
Definition: movenc.c:55
FFAMediaFormat::getInt64
int(* getInt64)(FFAMediaFormat *format, const char *name, int64_t *out)
Definition: mediacodec_wrapper.h:72
ff_AMediaCodec_start
static int ff_AMediaCodec_start(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:262
FFAMediaCodecBufferInfo::offset
int32_t offset
Definition: mediacodec_wrapper.h:173
ff_AMediaFormatColorStandard_to_AVColorPrimaries
enum AVColorPrimaries ff_AMediaFormatColorStandard_to_AVColorPrimaries(int color_standard)
Map MediaFormat color standard to AVColorPrimaries.
Definition: mediacodec_wrapper.c:2665
ff_AMediaCodecList_getCodecNameByType
char * ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx)
Definition: mediacodec_wrapper.c:470
mediacodec_surface.h
FFAMediaCodec::infoTryAgainLater
int(* infoTryAgainLater)(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:224
int64_t
long long int64_t
Definition: coverity.c:34
ff_AMediaFormatColorTransfer_from_AVColorTransfer
int ff_AMediaFormatColorTransfer_from_AVColorTransfer(enum AVColorTransferCharacteristic color_transfer)
Map AVColorTransferCharacteristic to MediaFormat color transfer.
Definition: mediacodec_wrapper.c:2684
out_size
int out_size
Definition: movenc.c:56
ff_AMediaFormat_getRect
static int ff_AMediaFormat_getRect(FFAMediaFormat *format, const char *name, int32_t *left, int32_t *top, int32_t *right, int32_t *bottom)
Definition: mediacodec_wrapper.h:127
ff_AMediaCodec_signalEndOfInputStream
static int ff_AMediaCodec_signalEndOfInputStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:362
ff_AMediaFormat_setString
static void ff_AMediaFormat_setString(FFAMediaFormat *format, const char *name, const char *value)
Definition: mediacodec_wrapper.h:150
ff_AMediaCodec_infoOutputFormatChanged
static int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:332
ff_AMediaFormatColorRange_from_AVColorRange
int ff_AMediaFormatColorRange_from_AVColorRange(enum AVColorRange color_range)
Map AVColorRange to MediaFormat color range.
Definition: mediacodec_wrapper.c:2639
ff_AMediaCodec_infoOutputBuffersChanged
static int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:327
ff_AMediaCodec_releaseOutputBufferAtTime
static int ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, int64_t timestampNs)
Definition: mediacodec_wrapper.h:317
data
const char data[16]
Definition: mxf.c:149
FFAMediaCodec::getInputBuffer
uint8_t *(* getInputBuffer)(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:212
FFAMediaCodec::getName
char *(* getName)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:200
ff_AMediaCodec_queueInputBuffer
static int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec *codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
Definition: mediacodec_wrapper.h:297
COLOR_TRANSFER_LINEAR
@ COLOR_TRANSFER_LINEAR
Definition: mediacodec_wrapper.h:392
FFAMediaCodecCryptoInfo
struct FFAMediaCodecCryptoInfo FFAMediaCodecCryptoInfo
Definition: mediacodec_wrapper.h:170
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:602
FFAMediaFormat::getFloat
int(* getFloat)(FFAMediaFormat *format, const char *name, float *out)
Definition: mediacodec_wrapper.h:73
ff_AMediaFormat_setInt32
static void ff_AMediaFormat_setInt32(FFAMediaFormat *format, const char *name, int32_t value)
Definition: mediacodec_wrapper.h:135
ff_AMediaCodec_configure
static int ff_AMediaCodec_configure(FFAMediaCodec *codec, const FFAMediaFormat *format, FFANativeWindow *surface, void *crypto, uint32_t flags)
Definition: mediacodec_wrapper.h:254
FFAMediaFormat::getBuffer
int(* getBuffer)(FFAMediaFormat *format, const char *name, void **data, size_t *size)
Definition: mediacodec_wrapper.h:74
ff_AMediaFormat_getBuffer
static int ff_AMediaFormat_getBuffer(FFAMediaFormat *format, const char *name, void **data, size_t *size)
Definition: mediacodec_wrapper.h:117
ff_AMediaFormatColorRange_to_AVColorRange
enum AVColorRange ff_AMediaFormatColorRange_to_AVColorRange(int color_range)
Map MediaFormat color range to AVColorRange.
Definition: mediacodec_wrapper.c:2630
COLOR_RANGE_UNSPECIFIED
@ COLOR_RANGE_UNSPECIFIED
Definition: mediacodec_wrapper.h:377
FFAMediaCodec::getOutputFormat
FFAMediaFormat *(* getOutputFormat)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:219
FFAMediaCodec::signalEndOfInputStream
int(* signalEndOfInputStream)(FFAMediaCodec *)
Definition: mediacodec_wrapper.h:237
COLOR_TRANSFER_HLG
@ COLOR_TRANSFER_HLG
Definition: mediacodec_wrapper.h:395
FFAMediaCodec::dequeueInputBuffer
ssize_t(* dequeueInputBuffer)(FFAMediaCodec *codec, int64_t timeoutUs)
Definition: mediacodec_wrapper.h:215
FFAMediaFormat::getRect
int(* getRect)(FFAMediaFormat *, const char *name, int32_t *left, int32_t *top, int32_t *right, int32_t *bottom)
Definition: mediacodec_wrapper.h:77
FFAMediaFormat::getInt32
int(* getInt32)(FFAMediaFormat *format, const char *name, int32_t *out)
Definition: mediacodec_wrapper.h:71
ff_AMediaCodec_getName
static char * ff_AMediaCodec_getName(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:245
ff_AMediaCodec_getBufferFlagEndOfStream
static int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:342
ff_AMediaFormat_setBuffer
static void ff_AMediaFormat_setBuffer(FFAMediaFormat *format, const char *name, void *data, size_t size)
Definition: mediacodec_wrapper.h:155
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
FFAMediaCodec::infoOutputFormatChanged
int(* infoOutputFormatChanged)(FFAMediaCodec *codec, ssize_t indx)
Definition: mediacodec_wrapper.h:226
FFAMediaCodec::infoOutputBuffersChanged
int(* infoOutputBuffersChanged)(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:225
FFAMediaFormat::setBuffer
void(* setBuffer)(FFAMediaFormat *format, const char *name, void *data, size_t size)
Definition: mediacodec_wrapper.h:84
FFAMediaCodecOnAsyncNotifyCallback
Definition: mediacodec_wrapper.h:182
ff_AMediaCodec_createCodecByName
FFAMediaCodec * ff_AMediaCodec_createCodecByName(const char *name, int ndk)
Definition: mediacodec_wrapper.c:2538
color_range
color_range
Definition: vf_selectivecolor.c:43
ff_AMediaFormat_getInt64
static int ff_AMediaFormat_getInt64(FFAMediaFormat *format, const char *name, int64_t *out)
Definition: mediacodec_wrapper.h:107
ff_AMediaFormat_new
FFAMediaFormat * ff_AMediaFormat_new(int ndk)
Definition: mediacodec_wrapper.c:2531
callback
static void callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, enum dshowDeviceType devtype)
Definition: dshow.c:342
COLOR_RANGE_LIMITED
@ COLOR_RANGE_LIMITED
Definition: mediacodec_wrapper.h:379
ff_AMediaFormat_setFloat
static void ff_AMediaFormat_setFloat(FFAMediaFormat *format, const char *name, float value)
Definition: mediacodec_wrapper.h:145
ff_AMediaCodec_getOutputFormat
static FFAMediaFormat * ff_AMediaCodec_getOutputFormat(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:307
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
ff_AMediaCodec_flush
static int ff_AMediaCodec_flush(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:272
FFAMediaCodecBufferInfo
Definition: mediacodec_wrapper.h:172
FFAMediaFormat::setRect
void(* setRect)(FFAMediaFormat *, const char *name, int32_t left, int32_t top, int32_t right, int32_t bottom)
Definition: mediacodec_wrapper.h:86
FFAMediaFormat::getString
int(* getString)(FFAMediaFormat *format, const char *name, const char **out)
Definition: mediacodec_wrapper.h:75
FFAMediaCodecBufferInfo::size
int32_t size
Definition: mediacodec_wrapper.h:174
FFAMediaCodec::dequeueOutputBuffer
ssize_t(* dequeueOutputBuffer)(FFAMediaCodec *codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.h:218
FFAMediaCodecOnAsyncNotifyCallback::onAsyncOutputAvailable
void(* onAsyncOutputAvailable)(FFAMediaCodec *codec, void *userdata, int32_t index, FFAMediaCodecBufferInfo *buffer_info)
Definition: mediacodec_wrapper.h:186
ff_AMediaCodec_setAsyncNotifyCallback
static int ff_AMediaCodec_setAsyncNotifyCallback(FFAMediaCodec *codec, const FFAMediaCodecOnAsyncNotifyCallback *callback, void *userdata)
Definition: mediacodec_wrapper.h:367
ff_AMediaCodec_stop
static int ff_AMediaCodec_stop(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:267
COLOR_STANDARD_BT709
@ COLOR_STANDARD_BT709
Definition: mediacodec_wrapper.h:384
FFAMediaCodecOnAsyncNotifyCallback::onAsyncFormatChanged
void(* onAsyncFormatChanged)(FFAMediaCodec *codec, void *userdata, FFAMediaFormat *format)
Definition: mediacodec_wrapper.h:190
ff_AMediaCodec_getBufferFlagKeyFrame
static int ff_AMediaCodec_getBufferFlagKeyFrame(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:347
FFAMediaFormat::setFloat
void(* setFloat)(FFAMediaFormat *format, const char *name, float value)
Definition: mediacodec_wrapper.h:82
FFAMediaFormat::setInt64
void(* setInt64)(FFAMediaFormat *format, const char *name, int64_t value)
Definition: mediacodec_wrapper.h:81
index
int index
Definition: gxfenc.c:90
ff_AMediaFormat_toString
static char * ff_AMediaFormat_toString(FFAMediaFormat *format)
Definition: mediacodec_wrapper.h:97
ff_AMediaCodec_createEncoderByType
FFAMediaCodec * ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk)
Definition: mediacodec_wrapper.c:2552
ff_AMediaFormat_getFloat
static int ff_AMediaFormat_getFloat(FFAMediaFormat *format, const char *name, float *out)
Definition: mediacodec_wrapper.h:112
FFAMediaCodec::cleanOutputBuffers
int(* cleanOutputBuffers)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:234
FFAMediaFormat::setInt32
void(* setInt32)(FFAMediaFormat *format, const char *name, int32_t value)
Definition: mediacodec_wrapper.h:80
FFAMediaCodec::stop
int(* stop)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:209
FFAMediaFormat::setString
void(* setString)(FFAMediaFormat *format, const char *name, const char *value)
Definition: mediacodec_wrapper.h:83
COLOR_TRANSFER_SDR_VIDEO
@ COLOR_TRANSFER_SDR_VIDEO
Definition: mediacodec_wrapper.h:393
COLOR_TRANSFER_UNSPECIFIED
@ COLOR_TRANSFER_UNSPECIFIED
Definition: mediacodec_wrapper.h:391
FFAMediaCodecOnAsyncNotifyCallback::onAsyncError
void(* onAsyncError)(FFAMediaCodec *codec, void *userdata, int error, const char *detail)
Definition: mediacodec_wrapper.h:193
size
int size
Definition: twinvq_data.h:10344
ff_AMediaCodec_createDecoderByType
FFAMediaCodec * ff_AMediaCodec_createDecoderByType(const char *mime_type, int ndk)
Definition: mediacodec_wrapper.c:2545
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
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
COLOR_RANGE_FULL
@ COLOR_RANGE_FULL
Definition: mediacodec_wrapper.h:378
ff_AMediaFormat_getInt32
static int ff_AMediaFormat_getInt32(FFAMediaFormat *format, const char *name, int32_t *out)
Definition: mediacodec_wrapper.h:102
FFAMediaCodec::delete
int(* delete)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:205
COLOR_TRANSFER_ST2084
@ COLOR_TRANSFER_ST2084
Definition: mediacodec_wrapper.h:394
ff_AMediaCodec_getConfigureFlagEncode
static int ff_AMediaCodec_getConfigureFlagEncode(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:352
COLOR_STANDARD_BT2020
@ COLOR_STANDARD_BT2020
Definition: mediacodec_wrapper.h:387
FFANativeWindow
Definition: mediacodec_surface.h:28
COLOR_STANDARD_UNSPECIFIED
@ COLOR_STANDARD_UNSPECIFIED
Definition: mediacodec_wrapper.h:383
FFAMediaCodec::releaseOutputBufferAtTime
int(* releaseOutputBufferAtTime)(FFAMediaCodec *codec, size_t idx, int64_t timestampNs)
Definition: mediacodec_wrapper.h:222
FFAMediaCodec
Definition: mediacodec_wrapper.h:197
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:656
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
FFAMediaCodec::getConfigureFlagEncode
int(* getConfigureFlagEncode)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:232
FFAMediaCodecBufferInfo::flags
uint32_t flags
Definition: mediacodec_wrapper.h:176
profile
int profile
Definition: mxfenc.c:2249
FFAMediaCodec::configure
int(* configure)(FFAMediaCodec *codec, const FFAMediaFormat *format, FFANativeWindow *surface, void *crypto, uint32_t flags)
Definition: mediacodec_wrapper.h:207
ff_AMediaFormat_getString
static int ff_AMediaFormat_getString(FFAMediaFormat *format, const char *name, const char **out)
Definition: mediacodec_wrapper.h:122
COLOR_STANDARD_BT601_PAL
@ COLOR_STANDARD_BT601_PAL
Definition: mediacodec_wrapper.h:385
FFAMediaCodecBufferInfo::presentationTimeUs
int64_t presentationTimeUs
Definition: mediacodec_wrapper.h:175
ff_AMediaCodec_dequeueInputBuffer
static ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec *codec, int64_t timeoutUs)
Definition: mediacodec_wrapper.h:292
avcodec.h
FFAMediaFormatColorStandard
FFAMediaFormatColorStandard
Definition: mediacodec_wrapper.h:382
ff_AMediaFormatColorStandard_to_AVColorSpace
enum AVColorSpace ff_AMediaFormatColorStandard_to_AVColorSpace(int color_standard)
Map MediaFormat color standard to AVColorSpace.
Definition: mediacodec_wrapper.c:2647
FFAMediaCodec::setAsyncNotifyCallback
int(* setAsyncNotifyCallback)(FFAMediaCodec *codec, const FFAMediaCodecOnAsyncNotifyCallback *callback, void *userdata)
Definition: mediacodec_wrapper.h:240
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:309
FFAMediaCodec::queueInputBuffer
int(* queueInputBuffer)(FFAMediaCodec *codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
Definition: mediacodec_wrapper.h:216
FFAMediaFormatColorRange
FFAMediaFormatColorRange
Definition: mediacodec_wrapper.h:376
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
AVCodecContext
main external API structure.
Definition: avcodec.h:451
FFAMediaCodec::releaseOutputBuffer
int(* releaseOutputBuffer)(FFAMediaCodec *codec, size_t idx, int render)
Definition: mediacodec_wrapper.h:221
FFAMediaFormatColorTransfer
FFAMediaFormatColorTransfer
Definition: mediacodec_wrapper.h:390
FFAMediaCodec::getBufferFlagCodecConfig
int(* getBufferFlagCodecConfig)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:228
FFAMediaCodec::getBufferFlagEndOfStream
int(* getBufferFlagEndOfStream)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:229
FFAMediaCodec::getOutputBuffer
uint8_t *(* getOutputBuffer)(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:213
ff_AMediaCodec_getBufferFlagCodecConfig
static int ff_AMediaCodec_getBufferFlagCodecConfig(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:337
COLOR_STANDARD_BT601_NTSC
@ COLOR_STANDARD_BT601_NTSC
Definition: mediacodec_wrapper.h:386
ff_AMediaCodec_getOutputBuffer
static uint8_t * ff_AMediaCodec_getOutputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:287
ff_AMediaCodec_cleanOutputBuffers
static int ff_AMediaCodec_cleanOutputBuffers(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:357
ff_AMediaCodec_infoTryAgainLater
static int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:322
int32_t
int32_t
Definition: audioconvert.c:56
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
ff_AMediaCodec_releaseOutputBuffer
static int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec *codec, size_t idx, int render)
Definition: mediacodec_wrapper.h:312
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_AMediaFormatColorStandard_from_AVColorSpace
int ff_AMediaFormatColorStandard_from_AVColorSpace(enum AVColorSpace color_space)
Map AVColorSpace to MediaFormat color standard.
Definition: mediacodec_wrapper.c:2656
FFAMediaCodecOnAsyncNotifyCallback::onAsyncInputAvailable
void(* onAsyncInputAvailable)(FFAMediaCodec *codec, void *userdata, int32_t index)
Definition: mediacodec_wrapper.h:183
ff_AMediaFormat_setInt64
static void ff_AMediaFormat_setInt64(FFAMediaFormat *format, const char *name, int64_t value)
Definition: mediacodec_wrapper.h:140
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:698
FFAMediaFormat
Definition: mediacodec_wrapper.h:63
FFAMediaCodec::flush
int(* flush)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:210
ff_AMediaCodec_dequeueOutputBuffer
static ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec *codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.h:302
FFAMediaCodec::start
int(* start)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:208
ff_AMediaFormatColorTransfer_to_AVColorTransfer
enum AVColorTransferCharacteristic ff_AMediaFormatColorTransfer_to_AVColorTransfer(int color_transfer)
Map MediaFormat color transfer to AVColorTransferCharacteristic.
Definition: mediacodec_wrapper.c:2675