FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mediacodecdec.c
Go to the documentation of this file.
1 /*
2  * Android MediaCodec decoder
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 #include <string.h>
24 #include <sys/types.h>
25 
26 #include "libavutil/common.h"
27 #include "libavutil/mem.h"
28 #include "libavutil/log.h"
29 #include "libavutil/pixfmt.h"
30 #include "libavutil/time.h"
31 #include "libavutil/timestamp.h"
32 
33 #include "avcodec.h"
34 #include "internal.h"
35 
36 #include "mediacodec_sw_buffer.h"
37 #include "mediacodec_wrapper.h"
38 #include "mediacodecdec.h"
39 
40 /**
41  * OMX.k3.video.decoder.avc, OMX.NVIDIA.* OMX.SEC.avc.dec and OMX.google
42  * codec workarounds used in various place are taken from the Gstreamer
43  * project.
44  *
45  * Gstreamer references:
46  * https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/sys/androidmedia/
47  *
48  * Gstreamer copyright notice:
49  *
50  * Copyright (C) 2012, Collabora Ltd.
51  * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
52  *
53  * Copyright (C) 2012, Rafaël Carré <funman@videolanorg>
54  *
55  * Copyright (C) 2015, Sebastian Dröge <sebastian@centricular.com>
56  *
57  * Copyright (C) 2014-2015, Collabora Ltd.
58  * Author: Matthieu Bouron <matthieu.bouron@gcollabora.com>
59  *
60  * Copyright (C) 2015, Edward Hervey
61  * Author: Edward Hervey <bilboed@gmail.com>
62  *
63  * Copyright (C) 2015, Matthew Waters <matthew@centricular.com>
64  *
65  * This library is free software; you can redistribute it and/or
66  * modify it under the terms of the GNU Lesser General Public
67  * License as published by the Free Software Foundation
68  * version 2.1 of the License.
69  *
70  * This library is distributed in the hope that it will be useful,
71  * but WITHOUT ANY WARRANTY; without even the implied warranty of
72  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
73  * Lesser General Public License for more details.
74  *
75  * You should have received a copy of the GNU Lesser General Public
76  * License along with this library; if not, write to the Free Software
77  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
78  *
79  */
80 
81 #define INPUT_DEQUEUE_TIMEOUT_US 8000
82 #define OUTPUT_DEQUEUE_TIMEOUT_US 8000
83 #define OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US 1000000
84 
85 enum {
95 };
96 
97 static const struct {
98 
101 
102 } color_formats[] = {
103 
111  { 0 }
112 };
113 
116  int color_format)
117 {
118  int i;
119  enum AVPixelFormat ret = AV_PIX_FMT_NONE;
120 
121  if (!strcmp(s->codec_name, "OMX.k3.video.decoder.avc") && color_format == COLOR_FormatYCbYCr) {
123  }
124 
125  for (i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) {
126  if (color_formats[i].color_format == color_format) {
127  return color_formats[i].pix_fmt;
128  }
129  }
130 
131  av_log(avctx, AV_LOG_ERROR, "Output color format 0x%x (value=%d) is not supported\n",
132  color_format, color_format);
133 
134  return ret;
135 }
136 
139  uint8_t *data,
140  size_t size,
141  ssize_t index,
143  AVFrame *frame)
144 {
145  int ret = 0;
146  int status = 0;
147 
148  frame->width = avctx->width;
149  frame->height = avctx->height;
150  frame->format = avctx->pix_fmt;
151 
152  /* MediaCodec buffers needs to be copied to our own refcounted buffers
153  * because the flush command invalidates all input and output buffers.
154  */
155  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
156  av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer\n");
157  goto done;
158  }
159 
160  /* Override frame->pkt_pts as ff_get_buffer will override its value based
161  * on the last avpacket received which is not in sync with the frame:
162  * * N avpackets can be pushed before 1 frame is actually returned
163  * * 0-sized avpackets are pushed to flush remaining frames at EOS */
164  frame->pkt_pts = info->presentationTimeUs;
165  frame->pkt_dts = AV_NOPTS_VALUE;
166 
167  av_log(avctx, AV_LOG_DEBUG,
168  "Frame: width=%d stride=%d height=%d slice-height=%d "
169  "crop-top=%d crop-bottom=%d crop-left=%d crop-right=%d encoder=%s\n"
170  "destination linesizes=%d,%d,%d\n" ,
171  avctx->width, s->stride, avctx->height, s->slice_height,
173  frame->linesize[0], frame->linesize[1], frame->linesize[2]);
174 
175  switch (s->color_format) {
177  ff_mediacodec_sw_buffer_copy_yuv420_planar(avctx, s, data, size, info, frame);
178  break;
182  ff_mediacodec_sw_buffer_copy_yuv420_semi_planar(avctx, s, data, size, info, frame);
183  break;
186  ff_mediacodec_sw_buffer_copy_yuv420_packed_semi_planar(avctx, s, data, size, info, frame);
187  break;
190  break;
191  default:
192  av_log(avctx, AV_LOG_ERROR, "Unsupported color format 0x%x (value=%d)\n",
193  s->color_format, s->color_format);
194  ret = AVERROR(EINVAL);
195  goto done;
196  }
197 
198  ret = 0;
199 done:
200  status = ff_AMediaCodec_releaseOutputBuffer(s->codec, index, 0);
201  if (status < 0) {
202  av_log(avctx, AV_LOG_ERROR, "Failed to release output buffer\n");
203  ret = AVERROR_EXTERNAL;
204  }
205 
206  return ret;
207 }
208 
210 {
211  int width = 0;
212  int height = 0;
213  int32_t value = 0;
214  char *format = NULL;
215 
216  if (!s->format) {
217  av_log(avctx, AV_LOG_ERROR, "Output MediaFormat is not set\n");
218  return AVERROR(EINVAL);
219  }
220 
221  format = ff_AMediaFormat_toString(s->format);
222  if (!format) {
223  return AVERROR_EXTERNAL;
224  }
225  av_log(avctx, AV_LOG_DEBUG, "Parsing MediaFormat %s\n", format);
226  av_freep(&format);
227 
228  /* Mandatory fields */
229  if (!ff_AMediaFormat_getInt32(s->format, "width", &value)) {
230  format = ff_AMediaFormat_toString(s->format);
231  av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", "width", format);
232  av_freep(&format);
233  return AVERROR_EXTERNAL;
234  }
235  s->width = value;
236 
237  if (!ff_AMediaFormat_getInt32(s->format, "height", &value)) {
238  format = ff_AMediaFormat_toString(s->format);
239  av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", "height", format);
240  av_freep(&format);
241  return AVERROR_EXTERNAL;
242  }
243  s->height = value;
244 
245  if (!ff_AMediaFormat_getInt32(s->format, "stride", &value)) {
246  format = ff_AMediaFormat_toString(s->format);
247  av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", "stride", format);
248  av_freep(&format);
249  return AVERROR_EXTERNAL;
250  }
251  s->stride = value > 0 ? value : s->width;
252 
253  if (!ff_AMediaFormat_getInt32(s->format, "slice-height", &value)) {
254  format = ff_AMediaFormat_toString(s->format);
255  av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", "slice-height", format);
256  av_freep(&format);
257  return AVERROR_EXTERNAL;
258  }
259  s->slice_height = value > 0 ? value : s->height;
260 
261  if (strstr(s->codec_name, "OMX.Nvidia.")) {
262  s->slice_height = FFALIGN(s->height, 16);
263  } else if (strstr(s->codec_name, "OMX.SEC.avc.dec")) {
264  s->slice_height = avctx->height;
265  s->stride = avctx->width;
266  }
267 
268  if (!ff_AMediaFormat_getInt32(s->format, "color-format", &value)) {
269  format = ff_AMediaFormat_toString(s->format);
270  av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", "color-format", format);
271  av_freep(&format);
272  return AVERROR_EXTERNAL;
273  }
274  s->color_format = value;
275 
276  s->pix_fmt = avctx->pix_fmt = mcdec_map_color_format(avctx, s, value);
277  if (avctx->pix_fmt == AV_PIX_FMT_NONE) {
278  av_log(avctx, AV_LOG_ERROR, "Output color format is not supported\n");
279  return AVERROR(EINVAL);
280  }
281 
282  /* Optional fields */
283  if (ff_AMediaFormat_getInt32(s->format, "crop-top", &value))
284  s->crop_top = value;
285 
286  if (ff_AMediaFormat_getInt32(s->format, "crop-bottom", &value))
287  s->crop_bottom = value;
288 
289  if (ff_AMediaFormat_getInt32(s->format, "crop-left", &value))
290  s->crop_left = value;
291 
292  if (ff_AMediaFormat_getInt32(s->format, "crop-right", &value))
293  s->crop_right = value;
294 
295  width = s->crop_right + 1 - s->crop_left;
296  height = s->crop_bottom + 1 - s->crop_top;
297 
298  av_log(avctx, AV_LOG_INFO,
299  "Output crop parameters top=%d bottom=%d left=%d right=%d, "
300  "resulting dimensions width=%d height=%d\n",
301  s->crop_top, s->crop_bottom, s->crop_left, s->crop_right,
302  width, height);
303 
304  return ff_set_dimensions(avctx, width, height);
305 }
306 
308  const char *mime, FFAMediaFormat *format)
309 {
310  int ret = 0;
311  int status;
312  int profile;
313 
315 
317  if (profile < 0) {
318  av_log(avctx, AV_LOG_WARNING, "Unsupported or unknown profile");
319  }
320 
321  s->codec_name = ff_AMediaCodecList_getCodecNameByType(mime, profile, 0, avctx);
322  if (!s->codec_name) {
323  ret = AVERROR_EXTERNAL;
324  goto fail;
325  }
326 
327  av_log(avctx, AV_LOG_DEBUG, "Found decoder %s\n", s->codec_name);
329  if (!s->codec) {
330  av_log(avctx, AV_LOG_ERROR, "Failed to create media decoder for type %s and name %s\n", mime, s->codec_name);
331  ret = AVERROR_EXTERNAL;
332  goto fail;
333  }
334 
335  status = ff_AMediaCodec_configure(s->codec, format, NULL, NULL, 0);
336  if (status < 0) {
337  char *desc = ff_AMediaFormat_toString(format);
338  av_log(avctx, AV_LOG_ERROR,
339  "Failed to configure codec (status = %d) with format %s\n",
340  status, desc);
341  av_freep(&desc);
342 
343  ret = AVERROR_EXTERNAL;
344  goto fail;
345  }
346 
347  status = ff_AMediaCodec_start(s->codec);
348  if (status < 0) {
349  char *desc = ff_AMediaFormat_toString(format);
350  av_log(avctx, AV_LOG_ERROR,
351  "Failed to start codec (status = %d) with format %s\n",
352  status, desc);
353  av_freep(&desc);
354  ret = AVERROR_EXTERNAL;
355  goto fail;
356  }
357 
359  if (s->format) {
360  if ((ret = mediacodec_dec_parse_format(avctx, s)) < 0) {
361  av_log(avctx, AV_LOG_ERROR,
362  "Failed to configure context\n");
363  goto fail;
364  }
365  }
366 
367  av_log(avctx, AV_LOG_DEBUG, "MediaCodec %p started successfully\n", s->codec);
368 
369  return 0;
370 
371 fail:
372  av_log(avctx, AV_LOG_ERROR, "MediaCodec %p failed to start\n", s->codec);
373  ff_mediacodec_dec_close(avctx, s);
374  return ret;
375 }
376 
378  AVFrame *frame, int *got_frame,
379  AVPacket *pkt)
380 {
381  int ret;
382  int offset = 0;
383  int need_flushing = 0;
384  uint8_t *data;
385  ssize_t index;
386  size_t size;
387  FFAMediaCodec *codec = s->codec;
388  FFAMediaCodecBufferInfo info = { 0 };
389 
390  int status;
391 
392  int64_t input_dequeue_timeout_us = INPUT_DEQUEUE_TIMEOUT_US;
393  int64_t output_dequeue_timeout_us = OUTPUT_DEQUEUE_TIMEOUT_US;
394 
395  if (pkt->size == 0) {
396  need_flushing = 1;
397  }
398 
399  if (s->flushing && s->eos) {
400  return 0;
401  }
402 
403  while (offset < pkt->size || (need_flushing && !s->flushing)) {
404  int size;
405 
406  index = ff_AMediaCodec_dequeueInputBuffer(codec, input_dequeue_timeout_us);
407  if (ff_AMediaCodec_infoTryAgainLater(codec, index)) {
408  break;
409  }
410 
411  if (index < 0) {
412  av_log(avctx, AV_LOG_ERROR, "Failed to dequeue input buffer (status=%zd)\n", index);
413  return AVERROR_EXTERNAL;
414  }
415 
416  data = ff_AMediaCodec_getInputBuffer(codec, index, &size);
417  if (!data) {
418  av_log(avctx, AV_LOG_ERROR, "Failed to get input buffer\n");
419  return AVERROR_EXTERNAL;
420  }
421 
422  if (need_flushing) {
424 
425  av_log(avctx, AV_LOG_DEBUG, "Sending End Of Stream signal\n");
426 
427  status = ff_AMediaCodec_queueInputBuffer(codec, index, 0, 0, pkt->pts, flags);
428  if (status < 0) {
429  av_log(avctx, AV_LOG_ERROR, "Failed to queue input empty buffer (status = %d)\n", status);
430  return AVERROR_EXTERNAL;
431  }
432 
433  s->flushing = 1;
434  break;
435  } else {
436  size = FFMIN(pkt->size - offset, size);
437 
438  memcpy(data, pkt->data + offset, size);
439  offset += size;
440 
441  status = ff_AMediaCodec_queueInputBuffer(codec, index, 0, size, pkt->pts, 0);
442  if (status < 0) {
443  av_log(avctx, AV_LOG_ERROR, "Failed to queue input buffer (status = %d)\n", status);
444  return AVERROR_EXTERNAL;
445  }
446  }
447  }
448 
449  if (need_flushing || s->flushing) {
450  /* If the codec is flushing or need to be flushed, block for a fair
451  * amount of time to ensure we got a frame */
452  output_dequeue_timeout_us = OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US;
453  } else if (s->dequeued_buffer_nb == 0) {
454  /* If the codec hasn't produced any frames, do not block so we
455  * can push data to it as fast as possible, and get the first
456  * frame */
457  output_dequeue_timeout_us = 0;
458  }
459 
460  index = ff_AMediaCodec_dequeueOutputBuffer(codec, &info, output_dequeue_timeout_us);
461  if (index >= 0) {
462  int ret;
463 
464  if (!s->first_buffer++) {
465  av_log(avctx, AV_LOG_DEBUG, "Got first buffer after %fms\n", (av_gettime() - s->first_buffer_at) / 1000);
466  }
467 
468  av_log(avctx, AV_LOG_DEBUG, "Got output buffer %zd"
469  " offset=%" PRIi32 " size=%" PRIi32 " ts=%" PRIi64
470  " flags=%" PRIu32 "\n", index, info.offset, info.size,
471  info.presentationTimeUs, info.flags);
472 
474  s->eos = 1;
475  }
476 
477  if (info.size) {
478  data = ff_AMediaCodec_getOutputBuffer(codec, index, &size);
479  if (!data) {
480  av_log(avctx, AV_LOG_ERROR, "Failed to get output buffer\n");
481  return AVERROR_EXTERNAL;
482  }
483 
484  if ((ret = mediacodec_wrap_buffer(avctx, s, data, size, index, &info, frame)) < 0) {
485  av_log(avctx, AV_LOG_ERROR, "Failed to wrap MediaCodec buffer\n");
486  return ret;
487  }
488 
489  *got_frame = 1;
490  s->dequeued_buffer_nb++;
491  } else {
492  status = ff_AMediaCodec_releaseOutputBuffer(codec, index, 0);
493  if (status < 0) {
494  av_log(avctx, AV_LOG_ERROR, "Failed to release output buffer\n");
495  }
496  }
497 
498  } else if (ff_AMediaCodec_infoOutputFormatChanged(codec, index)) {
499  char *format = NULL;
500 
501  if (s->format) {
502  status = ff_AMediaFormat_delete(s->format);
503  if (status < 0) {
504  av_log(avctx, AV_LOG_ERROR, "Failed to delete MediaFormat %p\n", s->format);
505  }
506  }
507 
509  if (!s->format) {
510  av_log(avctx, AV_LOG_ERROR, "Failed to get output format\n");
511  return AVERROR_EXTERNAL;
512  }
513 
514  format = ff_AMediaFormat_toString(s->format);
515  if (!format) {
516  return AVERROR_EXTERNAL;
517  }
518  av_log(avctx, AV_LOG_INFO, "Output MediaFormat changed to %s\n", format);
519  av_freep(&format);
520 
521  if ((ret = mediacodec_dec_parse_format(avctx, s)) < 0) {
522  return ret;
523  }
524 
525  } else if (ff_AMediaCodec_infoOutputBuffersChanged(codec, index)) {
527  } else if (ff_AMediaCodec_infoTryAgainLater(codec, index)) {
528  if (s->flushing) {
529  av_log(avctx, AV_LOG_ERROR, "Failed to dequeue output buffer within %" PRIi64 "ms "
530  "while flushing remaining frames, output will probably lack frames\n",
531  output_dequeue_timeout_us / 1000);
532  } else {
533  av_log(avctx, AV_LOG_DEBUG, "No output buffer available, try again later\n");
534  }
535  } else {
536  av_log(avctx, AV_LOG_ERROR, "Failed to dequeue output buffer (status=%zd)\n", index);
537  return AVERROR_EXTERNAL;
538  }
539 
540  return offset;
541 }
542 
544 {
545  FFAMediaCodec *codec = s->codec;
546  int status;
547 
548  s->dequeued_buffer_nb = 0;
549 
550  s->flushing = 0;
551  s->eos = 0;
552 
553  status = ff_AMediaCodec_flush(codec);
554  if (status < 0) {
555  av_log(avctx, AV_LOG_ERROR, "Failed to flush codec\n");
556  return AVERROR_EXTERNAL;
557  }
558 
559  s->first_buffer = 0;
561 
562  return 0;
563 }
564 
566 {
567  if (s->codec) {
569  s->codec = NULL;
570  }
571 
572  if (s->format) {
574  s->format = NULL;
575  }
576 
577  av_freep(&s->codec_name);
578 
579  return 0;
580 }
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
char * ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx)
memory handling functions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:210
const char * desc
Definition: nvenc.c:89
FFAMediaCodec * ff_AMediaCodec_createCodecByName(const char *name)
int size
Definition: avcodec.h:1581
static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecContext *s)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1877
void ff_mediacodec_sw_buffer_copy_yuv420_semi_planar(AVCodecContext *avctx, MediaCodecDecContext *s, uint8_t *data, size_t size, FFAMediaCodecBufferInfo *info, AVFrame *frame)
static AVPacket pkt
void ff_mediacodec_sw_buffer_copy_yuv420_planar(AVCodecContext *avctx, MediaCodecDecContext *s, uint8_t *data, size_t size, FFAMediaCodecBufferInfo *info, AVFrame *frame)
The code handling the various YUV color formats is taken from the GStreamer project.
enum AVPixelFormat pix_fmt
int ff_AMediaCodec_flush(FFAMediaCodec *codec)
int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec *codec, size_t idx, int render)
uint8_t
timestamp utils, mostly useful for debugging/logging purposes
int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
#define OUTPUT_DEQUEUE_TIMEOUT_US
Definition: mediacodecdec.c:82
static AVFrame * frame
#define height
int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t idx)
uint8_t * data
Definition: avcodec.h:1580
static const struct @78 color_formats[]
char * ff_AMediaFormat_toString(FFAMediaFormat *format)
ptrdiff_t size
Definition: opengl_enc.c:101
static int mediacodec_wrap_buffer(AVCodecContext *avctx, MediaCodecDecContext *s, uint8_t *data, size_t size, ssize_t index, FFAMediaCodecBufferInfo *info, AVFrame *frame)
#define FFALIGN(x, a)
Definition: macros.h:48
#define av_log(a,...)
enum AVPixelFormat pix_fmt
Definition: mediacodecdec.h:51
int width
width and height of the video frame
Definition: frame.h:236
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
uint8_t * ff_AMediaCodec_getInputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:90
int ff_mediacodec_dec_decode(AVCodecContext *avctx, MediaCodecDecContext *s, AVFrame *frame, int *got_frame, AVPacket *pkt)
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
#define fail()
Definition: checkasm.h:81
void ff_mediacodec_sw_buffer_copy_yuv420_packed_semi_planar(AVCodecContext *avctx, MediaCodecDecContext *s, uint8_t *data, size_t size, FFAMediaCodecBufferInfo *info, AVFrame *frame)
int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec *codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
#define FFMIN(a, b)
Definition: common.h:96
ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec *codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
#define width
int width
picture width / height.
Definition: avcodec.h:1836
void ff_mediacodec_sw_buffer_copy_yuv420_packed_semi_planar_64x32Tile2m8ka(AVCodecContext *avctx, MediaCodecDecContext *s, uint8_t *data, size_t size, FFAMediaCodecBufferInfo *info, AVFrame *frame)
int ff_AMediaCodec_delete(FFAMediaCodec *codec)
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
int32_t
int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
int ff_mediacodec_dec_close(AVCodecContext *avctx, MediaCodecDecContext *s)
#define FF_ARRAY_ELEMS(a)
#define OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US
Definition: mediacodecdec.c:83
ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec *codec, int64_t timeoutUs)
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:248
int ff_AMediaFormat_getInt32(FFAMediaFormat *format, const char *name, int32_t *out)
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
int ff_AMediaCodec_cleanOutputBuffers(FFAMediaCodec *codec)
int ff_AMediaCodec_start(FFAMediaCodec *codec)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:215
main external API structure.
Definition: avcodec.h:1649
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_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:928
static const char * format
Definition: movenc.c:47
int index
Definition: gxfenc.c:89
static enum AVPixelFormat mcdec_map_color_format(AVCodecContext *avctx, MediaCodecDecContext *s, int color_format)
FFAMediaCodec * codec
Definition: mediacodecdec.h:39
int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
int ff_AMediaFormat_delete(FFAMediaFormat *format)
mfxU16 profile
Definition: qsvenc.c:42
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:273
static int flags
Definition: cpu.c:47
FFAMediaFormat * format
Definition: mediacodecdec.h:40
uint8_t * ff_AMediaCodec_getOutputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:280
int ff_AMediaCodec_configure(FFAMediaCodec *codec, const FFAMediaFormat *format, void *surface, void *crypto, uint32_t flags)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
common internal api header.
common internal and external API header
pixel format definitions
int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s)
#define INPUT_DEQUEUE_TIMEOUT_US
OMX.k3.video.decoder.avc, OMX.NVIDIA.
Definition: mediacodecdec.c:81
FFAMediaFormat * ff_AMediaCodec_getOutputFormat(FFAMediaCodec *codec)
uint64_t dequeued_buffer_nb
Definition: mediacodecdec.h:57
int height
Definition: frame.h:236
#define av_freep(p)
int color_format
Definition: mediacodecdec.c:99
int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, const char *mime, FFAMediaFormat *format)
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:57
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
This structure stores compressed data.
Definition: avcodec.h:1557
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1573
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:240