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;
182  const AVClass *class;
183 
184  char *(*getName)(FFAMediaCodec *codec);
185 
186  FFAMediaCodec* (*createCodecByName)(const char *name);
187  FFAMediaCodec* (*createDecoderByType)(const char *mime_type);
188  FFAMediaCodec* (*createEncoderByType)(const char *mime_type);
189  int (*delete)(FFAMediaCodec* codec);
190 
191  int (*configure)(FFAMediaCodec* codec, const FFAMediaFormat* format, FFANativeWindow* surface, void *crypto, uint32_t flags);
192  int (*start)(FFAMediaCodec* codec);
193  int (*stop)(FFAMediaCodec* codec);
194  int (*flush)(FFAMediaCodec* codec);
195 
196  uint8_t* (*getInputBuffer)(FFAMediaCodec* codec, size_t idx, size_t *out_size);
197  uint8_t* (*getOutputBuffer)(FFAMediaCodec* codec, size_t idx, size_t *out_size);
198 
199  ssize_t (*dequeueInputBuffer)(FFAMediaCodec* codec, int64_t timeoutUs);
200  int (*queueInputBuffer)(FFAMediaCodec* codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags);
201 
203  FFAMediaFormat* (*getOutputFormat)(FFAMediaCodec* codec);
204 
205  int (*releaseOutputBuffer)(FFAMediaCodec* codec, size_t idx, int render);
206  int (*releaseOutputBufferAtTime)(FFAMediaCodec *codec, size_t idx, int64_t timestampNs);
207 
208  int (*infoTryAgainLater)(FFAMediaCodec *codec, ssize_t idx);
209  int (*infoOutputBuffersChanged)(FFAMediaCodec *codec, ssize_t idx);
210  int (*infoOutputFormatChanged)(FFAMediaCodec *codec, ssize_t indx);
211 
215 
217 
219 
220  // For encoder with FFANativeWindow as input.
222 };
223 
224 static inline char *ff_AMediaCodec_getName(FFAMediaCodec *codec)
225 {
226  return codec->getName(codec);
227 }
228 
230 FFAMediaCodec* ff_AMediaCodec_createDecoderByType(const char *mime_type, int ndk);
231 FFAMediaCodec* ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk);
232 
233 static inline int ff_AMediaCodec_configure(FFAMediaCodec *codec,
234  const FFAMediaFormat *format,
235  FFANativeWindow *surface,
236  void *crypto, uint32_t flags)
237 {
238  return codec->configure(codec, format, surface, crypto, flags);
239 }
240 
241 static inline int ff_AMediaCodec_start(FFAMediaCodec* codec)
242 {
243  return codec->start(codec);
244 }
245 
246 static inline int ff_AMediaCodec_stop(FFAMediaCodec* codec)
247 {
248  return codec->stop(codec);
249 }
250 
251 static inline int ff_AMediaCodec_flush(FFAMediaCodec* codec)
252 {
253  return codec->flush(codec);
254 }
255 
256 static inline int ff_AMediaCodec_delete(FFAMediaCodec* codec)
257 {
258  return codec->delete(codec);
259 }
260 
261 static inline uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size)
262 {
263  return codec->getInputBuffer(codec, idx, out_size);
264 }
265 
266 static inline uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t *out_size)
267 {
268  return codec->getOutputBuffer(codec, idx, out_size);
269 }
270 
271 static inline ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec* codec, int64_t timeoutUs)
272 {
273  return codec->dequeueInputBuffer(codec, timeoutUs);
274 }
275 
276 static inline int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec *codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
277 {
278  return codec->queueInputBuffer(codec, idx, offset, size, time, flags);
279 }
280 
282 {
283  return codec->dequeueOutputBuffer(codec, info, timeoutUs);
284 }
285 
287 {
288  return codec->getOutputFormat(codec);
289 }
290 
291 static inline int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec* codec, size_t idx, int render)
292 {
293  return codec->releaseOutputBuffer(codec, idx, render);
294 }
295 
296 static inline int ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, int64_t timestampNs)
297 {
298  return codec->releaseOutputBufferAtTime(codec, idx, timestampNs);
299 }
300 
301 static inline int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
302 {
303  return codec->infoTryAgainLater(codec, idx);
304 }
305 
306 static inline int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
307 {
308  return codec->infoOutputBuffersChanged(codec, idx);
309 }
310 
311 static inline int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t idx)
312 {
313  return codec->infoOutputFormatChanged(codec, idx);
314 }
315 
317 {
318  return codec->getBufferFlagCodecConfig(codec);
319 }
320 
322 {
323  return codec->getBufferFlagEndOfStream(codec);
324 }
325 
327 {
328  return codec->getBufferFlagKeyFrame(codec);
329 }
330 
332 {
333  return codec->getConfigureFlagEncode(codec);
334 }
335 
337 {
338  return codec->cleanOutputBuffers(codec);
339 }
340 
342 {
343  return codec->signalEndOfInputStream(codec);
344 }
345 
346 int ff_Build_SDK_INT(AVCodecContext *avctx);
347 
352 };
353 
360 };
361 
368 };
369 
370 /**
371  * Map MediaFormat color range to AVColorRange.
372  *
373  * return AVCOL_RANGE_UNSPECIFIED when failed.
374  */
376 
377 /**
378  * Map AVColorRange to MediaFormat color range.
379  *
380  * return COLOR_RANGE_UNSPECIFIED when failed.
381  */
383 
384 /**
385  * Map MediaFormat color standard to AVColorSpace.
386  *
387  * return AVCOL_SPC_UNSPECIFIED when failed.
388  */
390 
391 /**
392  * Map AVColorSpace to MediaFormat color standard.
393  *
394  * return COLOR_STANDARD_UNSPECIFIED when failed.
395  */
397 
398 /**
399  * Map MediaFormat color standard to AVColorPrimaries.
400  *
401  * return AVCOL_PRI_UNSPECIFIED when failed.
402  */
404 
405 /**
406  * Map MediaFormat color transfer to AVColorTransferCharacteristic.
407  *
408  * return AVCOL_TRC_UNSPECIFIED when failed.
409  */
412 
413 /**
414  * Map AVColorTransferCharacteristic to MediaFormat color transfer.
415  *
416  * return COLOR_TRANSFER_UNSPECIFIED when failed.
417  */
419  enum AVColorTransferCharacteristic color_transfer);
420 
421 #endif /* AVCODEC_MEDIACODEC_WRAPPER_H */
ff_AMediaCodec_getInputBuffer
static uint8_t * ff_AMediaCodec_getInputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:261
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:214
ff_Build_SDK_INT
int ff_Build_SDK_INT(AVCodecContext *avctx)
Definition: mediacodec_wrapper.c:2429
ff_AMediaCodec_delete
static int ff_AMediaCodec_delete(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:256
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:590
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:241
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:2535
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:208
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:2554
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:341
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:311
ff_AMediaFormatColorRange_from_AVColorRange
int ff_AMediaFormatColorRange_from_AVColorRange(enum AVColorRange color_range)
Map AVColorRange to MediaFormat color range.
Definition: mediacodec_wrapper.c:2509
ff_AMediaCodec_infoOutputBuffersChanged
static int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:306
ff_AMediaCodec_releaseOutputBufferAtTime
static int ff_AMediaCodec_releaseOutputBufferAtTime(FFAMediaCodec *codec, size_t idx, int64_t timestampNs)
Definition: mediacodec_wrapper.h:296
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:196
FFAMediaCodec::getName
char *(* getName)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:184
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:276
COLOR_TRANSFER_LINEAR
@ COLOR_TRANSFER_LINEAR
Definition: mediacodec_wrapper.h:364
FFAMediaCodecCryptoInfo
struct FFAMediaCodecCryptoInfo FFAMediaCodecCryptoInfo
Definition: mediacodec_wrapper.h:170
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:565
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:233
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:2500
COLOR_RANGE_UNSPECIFIED
@ COLOR_RANGE_UNSPECIFIED
Definition: mediacodec_wrapper.h:349
FFAMediaCodec::getOutputFormat
FFAMediaFormat *(* getOutputFormat)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:203
FFAMediaCodec::signalEndOfInputStream
int(* signalEndOfInputStream)(FFAMediaCodec *)
Definition: mediacodec_wrapper.h:221
COLOR_TRANSFER_HLG
@ COLOR_TRANSFER_HLG
Definition: mediacodec_wrapper.h:367
FFAMediaCodec::dequeueInputBuffer
ssize_t(* dequeueInputBuffer)(FFAMediaCodec *codec, int64_t timeoutUs)
Definition: mediacodec_wrapper.h:199
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:224
ff_AMediaCodec_getBufferFlagEndOfStream
static int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:321
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:210
FFAMediaCodec::infoOutputBuffersChanged
int(* infoOutputBuffersChanged)(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:209
FFAMediaFormat::setBuffer
void(* setBuffer)(FFAMediaFormat *format, const char *name, void *data, size_t size)
Definition: mediacodec_wrapper.h:84
ff_AMediaCodec_createCodecByName
FFAMediaCodec * ff_AMediaCodec_createCodecByName(const char *name, int ndk)
Definition: mediacodec_wrapper.c:2408
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:2401
COLOR_RANGE_LIMITED
@ COLOR_RANGE_LIMITED
Definition: mediacodec_wrapper.h:351
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:286
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:251
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:202
ff_AMediaCodec_stop
static int ff_AMediaCodec_stop(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:246
COLOR_STANDARD_BT709
@ COLOR_STANDARD_BT709
Definition: mediacodec_wrapper.h:356
ff_AMediaCodec_getBufferFlagKeyFrame
static int ff_AMediaCodec_getBufferFlagKeyFrame(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:326
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
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:2422
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:218
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:193
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:365
COLOR_TRANSFER_UNSPECIFIED
@ COLOR_TRANSFER_UNSPECIFIED
Definition: mediacodec_wrapper.h:363
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:2415
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:350
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:189
COLOR_TRANSFER_ST2084
@ COLOR_TRANSFER_ST2084
Definition: mediacodec_wrapper.h:366
ff_AMediaCodec_getConfigureFlagEncode
static int ff_AMediaCodec_getConfigureFlagEncode(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:331
COLOR_STANDARD_BT2020
@ COLOR_STANDARD_BT2020
Definition: mediacodec_wrapper.h:359
FFANativeWindow
Definition: mediacodec_surface.h:28
COLOR_STANDARD_UNSPECIFIED
@ COLOR_STANDARD_UNSPECIFIED
Definition: mediacodec_wrapper.h:355
FFAMediaCodec::releaseOutputBufferAtTime
int(* releaseOutputBufferAtTime)(FFAMediaCodec *codec, size_t idx, int64_t timestampNs)
Definition: mediacodec_wrapper.h:206
FFAMediaCodec
Definition: mediacodec_wrapper.h:181
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:619
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:216
FFAMediaCodecBufferInfo::flags
uint32_t flags
Definition: mediacodec_wrapper.h:176
profile
int profile
Definition: mxfenc.c:2228
FFAMediaCodec::configure
int(* configure)(FFAMediaCodec *codec, const FFAMediaFormat *format, FFANativeWindow *surface, void *crypto, uint32_t flags)
Definition: mediacodec_wrapper.h:191
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:357
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:271
avcodec.h
FFAMediaFormatColorStandard
FFAMediaFormatColorStandard
Definition: mediacodec_wrapper.h:354
ff_AMediaFormatColorStandard_to_AVColorSpace
enum AVColorSpace ff_AMediaFormatColorStandard_to_AVColorSpace(int color_standard)
Map MediaFormat color standard to AVColorSpace.
Definition: mediacodec_wrapper.c:2517
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:200
FFAMediaFormatColorRange
FFAMediaFormatColorRange
Definition: mediacodec_wrapper.h:348
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:205
FFAMediaFormatColorTransfer
FFAMediaFormatColorTransfer
Definition: mediacodec_wrapper.h:362
FFAMediaCodec::getBufferFlagCodecConfig
int(* getBufferFlagCodecConfig)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:212
FFAMediaCodec::getBufferFlagEndOfStream
int(* getBufferFlagEndOfStream)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:213
FFAMediaCodec::getOutputBuffer
uint8_t *(* getOutputBuffer)(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:197
ff_AMediaCodec_getBufferFlagCodecConfig
static int ff_AMediaCodec_getBufferFlagCodecConfig(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:316
COLOR_STANDARD_BT601_NTSC
@ COLOR_STANDARD_BT601_NTSC
Definition: mediacodec_wrapper.h:358
ff_AMediaCodec_getOutputBuffer
static uint8_t * ff_AMediaCodec_getOutputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:266
ff_AMediaCodec_cleanOutputBuffers
static int ff_AMediaCodec_cleanOutputBuffers(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:336
ff_AMediaCodec_infoTryAgainLater
static int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:301
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:291
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:2526
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:661
FFAMediaFormat
Definition: mediacodec_wrapper.h:63
FFAMediaCodec::flush
int(* flush)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:194
ff_AMediaCodec_dequeueOutputBuffer
static ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec *codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.h:281
FFAMediaCodec::start
int(* start)(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:192
ff_AMediaFormatColorTransfer_to_AVColorTransfer
enum AVColorTransferCharacteristic ff_AMediaFormatColorTransfer_to_AVColorTransfer(int color_transfer)
Map MediaFormat color transfer to AVColorTransferCharacteristic.
Definition: mediacodec_wrapper.c:2545