FFmpeg
mediacodecdec_common.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"
28 #include "libavutil/mem.h"
29 #include "libavutil/log.h"
30 #include "libavutil/pixfmt.h"
31 #include "libavutil/time.h"
32 #include "libavutil/timestamp.h"
33 
34 #include "avcodec.h"
35 #include "internal.h"
36 
37 #include "mediacodec.h"
38 #include "mediacodec_surface.h"
39 #include "mediacodec_sw_buffer.h"
40 #include "mediacodec_wrapper.h"
41 #include "mediacodecdec_common.h"
42 
43 /**
44  * OMX.k3.video.decoder.avc, OMX.NVIDIA.* OMX.SEC.avc.dec and OMX.google
45  * codec workarounds used in various place are taken from the Gstreamer
46  * project.
47  *
48  * Gstreamer references:
49  * https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/sys/androidmedia/
50  *
51  * Gstreamer copyright notice:
52  *
53  * Copyright (C) 2012, Collabora Ltd.
54  * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
55  *
56  * Copyright (C) 2012, Rafaël Carré <funman@videolanorg>
57  *
58  * Copyright (C) 2015, Sebastian Dröge <sebastian@centricular.com>
59  *
60  * Copyright (C) 2014-2015, Collabora Ltd.
61  * Author: Matthieu Bouron <matthieu.bouron@gcollabora.com>
62  *
63  * Copyright (C) 2015, Edward Hervey
64  * Author: Edward Hervey <bilboed@gmail.com>
65  *
66  * Copyright (C) 2015, Matthew Waters <matthew@centricular.com>
67  *
68  * This library is free software; you can redistribute it and/or
69  * modify it under the terms of the GNU Lesser General Public
70  * License as published by the Free Software Foundation
71  * version 2.1 of the License.
72  *
73  * This library is distributed in the hope that it will be useful,
74  * but WITHOUT ANY WARRANTY; without even the implied warranty of
75  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
76  * Lesser General Public License for more details.
77  *
78  * You should have received a copy of the GNU Lesser General Public
79  * License along with this library; if not, write to the Free Software
80  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
81  *
82  */
83 
84 #define INPUT_DEQUEUE_TIMEOUT_US 8000
85 #define OUTPUT_DEQUEUE_TIMEOUT_US 8000
86 #define OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US 1000000
87 
88 enum {
91 };
92 
94 {
95  switch (color_range) {
96  case COLOR_RANGE_FULL:
97  return AVCOL_RANGE_JPEG;
99  return AVCOL_RANGE_MPEG;
100  default:
102  }
103 }
104 
105 enum {
110 };
111 
112 static enum AVColorSpace mcdec_get_color_space(int color_standard)
113 {
114  switch (color_standard) {
116  return AVCOL_SPC_BT709;
118  return AVCOL_SPC_BT470BG;
120  return AVCOL_SPC_SMPTE170M;
122  return AVCOL_SPC_BT2020_NCL;
123  default:
124  return AVCOL_SPC_UNSPECIFIED;
125  }
126 }
127 
128 static enum AVColorPrimaries mcdec_get_color_pri(int color_standard)
129 {
130  switch (color_standard) {
132  return AVCOL_PRI_BT709;
134  return AVCOL_PRI_BT470BG;
136  return AVCOL_PRI_SMPTE170M;
138  return AVCOL_PRI_BT2020;
139  default:
140  return AVCOL_PRI_UNSPECIFIED;
141  }
142 }
143 
144 enum {
149 };
150 
151 static enum AVColorTransferCharacteristic mcdec_get_color_trc(int color_transfer)
152 {
153  switch (color_transfer) {
155  return AVCOL_TRC_LINEAR;
157  return AVCOL_TRC_SMPTE170M;
159  return AVCOL_TRC_SMPTEST2084;
160  case COLOR_TRANSFER_HLG:
161  return AVCOL_TRC_ARIB_STD_B67;
162  default:
163  return AVCOL_TRC_UNSPECIFIED;
164  }
165 }
166 
167 enum {
177 };
178 
179 static const struct {
180 
183 
184 } color_formats[] = {
185 
193  { 0 }
194 };
195 
198  int color_format)
199 {
200  int i;
202 
203  if (s->surface) {
204  return AV_PIX_FMT_MEDIACODEC;
205  }
206 
207  if (!strcmp(s->codec_name, "OMX.k3.video.decoder.avc") && color_format == COLOR_FormatYCbYCr) {
209  }
210 
211  for (i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) {
213  return color_formats[i].pix_fmt;
214  }
215  }
216 
217  av_log(avctx, AV_LOG_ERROR, "Output color format 0x%x (value=%d) is not supported\n",
219 
220  return ret;
221 }
222 
224 {
225  atomic_fetch_add(&s->refcount, 1);
226 }
227 
229 {
230  if (!s)
231  return;
232 
233  if (atomic_fetch_sub(&s->refcount, 1) == 1) {
234  if (s->codec) {
235  ff_AMediaCodec_delete(s->codec);
236  s->codec = NULL;
237  }
238 
239  if (s->format) {
240  ff_AMediaFormat_delete(s->format);
241  s->format = NULL;
242  }
243 
244  if (s->surface) {
246  s->surface = NULL;
247  }
248 
249  av_freep(&s->codec_name);
250  av_freep(&s);
251  }
252 }
253 
254 static void mediacodec_buffer_release(void *opaque, uint8_t *data)
255 {
256  AVMediaCodecBuffer *buffer = opaque;
258  int released = atomic_load(&buffer->released);
259 
260  if (!released && (ctx->delay_flush || buffer->serial == atomic_load(&ctx->serial))) {
261  atomic_fetch_sub(&ctx->hw_buffer_count, 1);
262  av_log(ctx->avctx, AV_LOG_DEBUG,
263  "Releasing output buffer %zd (%p) ts=%"PRId64" on free() [%d pending]\n",
264  buffer->index, buffer, buffer->pts, atomic_load(&ctx->hw_buffer_count));
265  ff_AMediaCodec_releaseOutputBuffer(ctx->codec, buffer->index, 0);
266  }
267 
268  if (ctx->delay_flush)
270  av_freep(&buffer);
271 }
272 
275  ssize_t index,
277  AVFrame *frame)
278 {
279  int ret = 0;
280  int status = 0;
281  AVMediaCodecBuffer *buffer = NULL;
282 
283  frame->buf[0] = NULL;
284  frame->width = avctx->width;
285  frame->height = avctx->height;
286  frame->format = avctx->pix_fmt;
287  frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
288 
289  if (avctx->pkt_timebase.num && avctx->pkt_timebase.den) {
290  frame->pts = av_rescale_q(info->presentationTimeUs,
292  avctx->pkt_timebase);
293  } else {
294  frame->pts = info->presentationTimeUs;
295  }
296  frame->pkt_dts = AV_NOPTS_VALUE;
297  frame->color_range = avctx->color_range;
298  frame->color_primaries = avctx->color_primaries;
299  frame->color_trc = avctx->color_trc;
300  frame->colorspace = avctx->colorspace;
301 
302  buffer = av_mallocz(sizeof(AVMediaCodecBuffer));
303  if (!buffer) {
304  ret = AVERROR(ENOMEM);
305  goto fail;
306  }
307 
308  atomic_init(&buffer->released, 0);
309 
310  frame->buf[0] = av_buffer_create(NULL,
311  0,
313  buffer,
315 
316  if (!frame->buf[0]) {
317  ret = AVERROR(ENOMEM);
318  goto fail;
319 
320  }
321 
322  buffer->ctx = s;
323  buffer->serial = atomic_load(&s->serial);
324  if (s->delay_flush)
326 
327  buffer->index = index;
328  buffer->pts = info->presentationTimeUs;
329 
330  frame->data[3] = (uint8_t *)buffer;
331 
332  atomic_fetch_add(&s->hw_buffer_count, 1);
333  av_log(avctx, AV_LOG_DEBUG,
334  "Wrapping output buffer %zd (%p) ts=%"PRId64" [%d pending]\n",
335  buffer->index, buffer, buffer->pts, atomic_load(&s->hw_buffer_count));
336 
337  return 0;
338 fail:
339  av_freep(buffer);
340  av_buffer_unref(&frame->buf[0]);
342  if (status < 0) {
343  av_log(avctx, AV_LOG_ERROR, "Failed to release output buffer\n");
345  }
346 
347  return ret;
348 }
349 
352  uint8_t *data,
353  size_t size,
354  ssize_t index,
356  AVFrame *frame)
357 {
358  int ret = 0;
359  int status = 0;
360 
361  frame->width = avctx->width;
362  frame->height = avctx->height;
363  frame->format = avctx->pix_fmt;
364 
365  /* MediaCodec buffers needs to be copied to our own refcounted buffers
366  * because the flush command invalidates all input and output buffers.
367  */
368  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
369  av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer\n");
370  goto done;
371  }
372 
373  /* Override frame->pkt_pts as ff_get_buffer will override its value based
374  * on the last avpacket received which is not in sync with the frame:
375  * * N avpackets can be pushed before 1 frame is actually returned
376  * * 0-sized avpackets are pushed to flush remaining frames at EOS */
377  if (avctx->pkt_timebase.num && avctx->pkt_timebase.den) {
378  frame->pts = av_rescale_q(info->presentationTimeUs,
380  avctx->pkt_timebase);
381  } else {
382  frame->pts = info->presentationTimeUs;
383  }
384  frame->pkt_dts = AV_NOPTS_VALUE;
385 
386  av_log(avctx, AV_LOG_TRACE,
387  "Frame: width=%d stride=%d height=%d slice-height=%d "
388  "crop-top=%d crop-bottom=%d crop-left=%d crop-right=%d encoder=%s "
389  "destination linesizes=%d,%d,%d\n" ,
390  avctx->width, s->stride, avctx->height, s->slice_height,
391  s->crop_top, s->crop_bottom, s->crop_left, s->crop_right, s->codec_name,
392  frame->linesize[0], frame->linesize[1], frame->linesize[2]);
393 
394  switch (s->color_format) {
397  break;
402  break;
406  break;
409  break;
410  default:
411  av_log(avctx, AV_LOG_ERROR, "Unsupported color format 0x%x (value=%d)\n",
412  s->color_format, s->color_format);
413  ret = AVERROR(EINVAL);
414  goto done;
415  }
416 
417  ret = 0;
418 done:
420  if (status < 0) {
421  av_log(avctx, AV_LOG_ERROR, "Failed to release output buffer\n");
423  }
424 
425  return ret;
426 }
427 
428 #define AMEDIAFORMAT_GET_INT32(name, key, mandatory) do { \
429  int32_t value = 0; \
430  if (ff_AMediaFormat_getInt32(s->format, key, &value)) { \
431  (name) = value; \
432  } else if (mandatory) { \
433  av_log(avctx, AV_LOG_ERROR, "Could not get %s from format %s\n", key, format); \
434  ret = AVERROR_EXTERNAL; \
435  goto fail; \
436  } \
437 } while (0) \
438 
440 {
441  int ret = 0;
442  int width = 0;
443  int height = 0;
444  int color_range = 0;
445  int color_standard = 0;
446  int color_transfer = 0;
447  char *format = NULL;
448 
449  if (!s->format) {
450  av_log(avctx, AV_LOG_ERROR, "Output MediaFormat is not set\n");
451  return AVERROR(EINVAL);
452  }
453 
454  format = ff_AMediaFormat_toString(s->format);
455  if (!format) {
456  return AVERROR_EXTERNAL;
457  }
458  av_log(avctx, AV_LOG_DEBUG, "Parsing MediaFormat %s\n", format);
459 
460  /* Mandatory fields */
461  AMEDIAFORMAT_GET_INT32(s->width, "width", 1);
462  AMEDIAFORMAT_GET_INT32(s->height, "height", 1);
463 
464  AMEDIAFORMAT_GET_INT32(s->stride, "stride", 0);
465  s->stride = s->stride > 0 ? s->stride : s->width;
466 
467  AMEDIAFORMAT_GET_INT32(s->slice_height, "slice-height", 0);
468 
469  if (strstr(s->codec_name, "OMX.Nvidia.") && s->slice_height == 0) {
470  s->slice_height = FFALIGN(s->height, 16);
471  } else if (strstr(s->codec_name, "OMX.SEC.avc.dec")) {
472  s->slice_height = avctx->height;
473  s->stride = avctx->width;
474  } else if (s->slice_height == 0) {
475  s->slice_height = s->height;
476  }
477 
478  AMEDIAFORMAT_GET_INT32(s->color_format, "color-format", 1);
479  avctx->pix_fmt = mcdec_map_color_format(avctx, s, s->color_format);
480  if (avctx->pix_fmt == AV_PIX_FMT_NONE) {
481  av_log(avctx, AV_LOG_ERROR, "Output color format is not supported\n");
482  ret = AVERROR(EINVAL);
483  goto fail;
484  }
485 
486  /* Optional fields */
487  AMEDIAFORMAT_GET_INT32(s->crop_top, "crop-top", 0);
488  AMEDIAFORMAT_GET_INT32(s->crop_bottom, "crop-bottom", 0);
489  AMEDIAFORMAT_GET_INT32(s->crop_left, "crop-left", 0);
490  AMEDIAFORMAT_GET_INT32(s->crop_right, "crop-right", 0);
491 
492  width = s->crop_right + 1 - s->crop_left;
493  height = s->crop_bottom + 1 - s->crop_top;
494 
495  AMEDIAFORMAT_GET_INT32(s->display_width, "display-width", 0);
496  AMEDIAFORMAT_GET_INT32(s->display_height, "display-height", 0);
497 
498  if (s->display_width && s->display_height) {
499  AVRational sar = av_div_q(
500  (AVRational){ s->display_width, s->display_height },
501  (AVRational){ width, height });
502  ff_set_sar(avctx, sar);
503  }
504 
505  AMEDIAFORMAT_GET_INT32(color_range, "color-range", 0);
506  if (color_range)
508 
509  AMEDIAFORMAT_GET_INT32(color_standard, "color-standard", 0);
510  if (color_standard) {
511  avctx->colorspace = mcdec_get_color_space(color_standard);
512  avctx->color_primaries = mcdec_get_color_pri(color_standard);
513  }
514 
515  AMEDIAFORMAT_GET_INT32(color_transfer, "color-transfer", 0);
516  if (color_transfer)
517  avctx->color_trc = mcdec_get_color_trc(color_transfer);
518 
519  av_log(avctx, AV_LOG_INFO,
520  "Output crop parameters top=%d bottom=%d left=%d right=%d, "
521  "resulting dimensions width=%d height=%d\n",
522  s->crop_top, s->crop_bottom, s->crop_left, s->crop_right,
523  width, height);
524 
525  av_freep(&format);
526  return ff_set_dimensions(avctx, width, height);
527 fail:
528  av_freep(&format);
529  return ret;
530 }
531 
533 {
534  FFAMediaCodec *codec = s->codec;
535  int status;
536 
537  s->output_buffer_count = 0;
538 
539  s->draining = 0;
540  s->flushing = 0;
541  s->eos = 0;
542  atomic_fetch_add(&s->serial, 1);
543  atomic_init(&s->hw_buffer_count, 0);
544  s->current_input_buffer = -1;
545 
546  status = ff_AMediaCodec_flush(codec);
547  if (status < 0) {
548  av_log(avctx, AV_LOG_ERROR, "Failed to flush codec\n");
549  return AVERROR_EXTERNAL;
550  }
551 
552  return 0;
553 }
554 
556  const char *mime, FFAMediaFormat *format)
557 {
558  int ret = 0;
559  int status;
560  int profile;
561 
562  enum AVPixelFormat pix_fmt;
563  static const enum AVPixelFormat pix_fmts[] = {
566  };
567 
568  s->avctx = avctx;
569  atomic_init(&s->refcount, 1);
570  atomic_init(&s->hw_buffer_count, 0);
571  atomic_init(&s->serial, 1);
572  s->current_input_buffer = -1;
573 
574  pix_fmt = ff_get_format(avctx, pix_fmts);
576  AVMediaCodecContext *user_ctx = avctx->hwaccel_context;
577 
578  if (avctx->hw_device_ctx) {
579  AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)(avctx->hw_device_ctx->data);
580  if (device_ctx->type == AV_HWDEVICE_TYPE_MEDIACODEC) {
581  if (device_ctx->hwctx) {
582  AVMediaCodecDeviceContext *mediacodec_ctx = (AVMediaCodecDeviceContext *)device_ctx->hwctx;
583  s->surface = ff_mediacodec_surface_ref(mediacodec_ctx->surface, avctx);
584  av_log(avctx, AV_LOG_INFO, "Using surface %p\n", s->surface);
585  }
586  }
587  }
588 
589  if (!s->surface && user_ctx && user_ctx->surface) {
590  s->surface = ff_mediacodec_surface_ref(user_ctx->surface, avctx);
591  av_log(avctx, AV_LOG_INFO, "Using surface %p\n", s->surface);
592  }
593  }
594 
596  if (profile < 0) {
597  av_log(avctx, AV_LOG_WARNING, "Unsupported or unknown profile\n");
598  }
599 
600  s->codec_name = ff_AMediaCodecList_getCodecNameByType(mime, profile, 0, avctx);
601  if (!s->codec_name) {
603  goto fail;
604  }
605 
606  av_log(avctx, AV_LOG_DEBUG, "Found decoder %s\n", s->codec_name);
607  s->codec = ff_AMediaCodec_createCodecByName(s->codec_name);
608  if (!s->codec) {
609  av_log(avctx, AV_LOG_ERROR, "Failed to create media decoder for type %s and name %s\n", mime, s->codec_name);
611  goto fail;
612  }
613 
614  status = ff_AMediaCodec_configure(s->codec, format, s->surface, NULL, 0);
615  if (status < 0) {
617  av_log(avctx, AV_LOG_ERROR,
618  "Failed to configure codec %s (status = %d) with format %s\n",
619  s->codec_name, status, desc);
620  av_freep(&desc);
621 
623  goto fail;
624  }
625 
626  status = ff_AMediaCodec_start(s->codec);
627  if (status < 0) {
629  av_log(avctx, AV_LOG_ERROR,
630  "Failed to start codec %s (status = %d) with format %s\n",
631  s->codec_name, status, desc);
632  av_freep(&desc);
634  goto fail;
635  }
636 
637  s->format = ff_AMediaCodec_getOutputFormat(s->codec);
638  if (s->format) {
639  if ((ret = mediacodec_dec_parse_format(avctx, s)) < 0) {
640  av_log(avctx, AV_LOG_ERROR,
641  "Failed to configure context\n");
642  goto fail;
643  }
644  }
645 
646  av_log(avctx, AV_LOG_DEBUG, "MediaCodec %p started successfully\n", s->codec);
647 
648  return 0;
649 
650 fail:
651  av_log(avctx, AV_LOG_ERROR, "MediaCodec %p failed to start\n", s->codec);
652  ff_mediacodec_dec_close(avctx, s);
653  return ret;
654 }
655 
657  AVPacket *pkt, bool wait)
658 {
659  int offset = 0;
660  int need_draining = 0;
661  uint8_t *data;
662  size_t size;
663  FFAMediaCodec *codec = s->codec;
664  int status;
665  int64_t input_dequeue_timeout_us = wait ? INPUT_DEQUEUE_TIMEOUT_US : 0;
666  int64_t pts;
667 
668  if (s->flushing) {
669  av_log(avctx, AV_LOG_ERROR, "Decoder is flushing and cannot accept new buffer "
670  "until all output buffers have been released\n");
671  return AVERROR_EXTERNAL;
672  }
673 
674  if (pkt->size == 0) {
675  need_draining = 1;
676  }
677 
678  if (s->draining && s->eos) {
679  return AVERROR_EOF;
680  }
681 
682  while (offset < pkt->size || (need_draining && !s->draining)) {
683  ssize_t index = s->current_input_buffer;
684  if (index < 0) {
685  index = ff_AMediaCodec_dequeueInputBuffer(codec, input_dequeue_timeout_us);
687  av_log(avctx, AV_LOG_TRACE, "No input buffer available, try again later\n");
688  break;
689  }
690 
691  if (index < 0) {
692  av_log(avctx, AV_LOG_ERROR, "Failed to dequeue input buffer (status=%zd)\n", index);
693  return AVERROR_EXTERNAL;
694  }
695  }
696  s->current_input_buffer = -1;
697 
699  if (!data) {
700  av_log(avctx, AV_LOG_ERROR, "Failed to get input buffer\n");
701  return AVERROR_EXTERNAL;
702  }
703 
704  pts = pkt->pts;
705  if (pts == AV_NOPTS_VALUE) {
706  av_log(avctx, AV_LOG_WARNING, "Input packet is missing PTS\n");
707  pts = 0;
708  }
709  if (pts && avctx->pkt_timebase.num && avctx->pkt_timebase.den) {
711  }
712 
713  if (need_draining) {
715 
716  av_log(avctx, AV_LOG_DEBUG, "Sending End Of Stream signal\n");
717 
719  if (status < 0) {
720  av_log(avctx, AV_LOG_ERROR, "Failed to queue input empty buffer (status = %d)\n", status);
721  return AVERROR_EXTERNAL;
722  }
723 
724  av_log(avctx, AV_LOG_TRACE,
725  "Queued empty EOS input buffer %zd with flags=%d\n", index, flags);
726 
727  s->draining = 1;
728  return 0;
729  }
730 
731  size = FFMIN(pkt->size - offset, size);
732  memcpy(data, pkt->data + offset, size);
733  offset += size;
734 
736  if (status < 0) {
737  av_log(avctx, AV_LOG_ERROR, "Failed to queue input buffer (status = %d)\n", status);
738  return AVERROR_EXTERNAL;
739  }
740 
741  av_log(avctx, AV_LOG_TRACE,
742  "Queued input buffer %zd size=%zd ts=%"PRIi64"\n", index, size, pts);
743  }
744 
745  if (offset == 0)
746  return AVERROR(EAGAIN);
747  return offset;
748 }
749 
751  AVFrame *frame, bool wait)
752 {
753  int ret;
754  uint8_t *data;
755  ssize_t index;
756  size_t size;
757  FFAMediaCodec *codec = s->codec;
759  int status;
760  int64_t output_dequeue_timeout_us = OUTPUT_DEQUEUE_TIMEOUT_US;
761 
762  if (s->draining && s->eos) {
763  return AVERROR_EOF;
764  }
765 
766  if (s->draining) {
767  /* If the codec is flushing or need to be flushed, block for a fair
768  * amount of time to ensure we got a frame */
769  output_dequeue_timeout_us = OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US;
770  } else if (s->output_buffer_count == 0 || !wait) {
771  /* If the codec hasn't produced any frames, do not block so we
772  * can push data to it as fast as possible, and get the first
773  * frame */
774  output_dequeue_timeout_us = 0;
775  }
776 
777  index = ff_AMediaCodec_dequeueOutputBuffer(codec, &info, output_dequeue_timeout_us);
778  if (index >= 0) {
779  av_log(avctx, AV_LOG_TRACE, "Got output buffer %zd"
780  " offset=%" PRIi32 " size=%" PRIi32 " ts=%" PRIi64
781  " flags=%" PRIu32 "\n", index, info.offset, info.size,
782  info.presentationTimeUs, info.flags);
783 
784  if (info.flags & ff_AMediaCodec_getBufferFlagEndOfStream(codec)) {
785  s->eos = 1;
786  }
787 
788  if (info.size) {
789  if (s->surface) {
790  if ((ret = mediacodec_wrap_hw_buffer(avctx, s, index, &info, frame)) < 0) {
791  av_log(avctx, AV_LOG_ERROR, "Failed to wrap MediaCodec buffer\n");
792  return ret;
793  }
794  } else {
796  if (!data) {
797  av_log(avctx, AV_LOG_ERROR, "Failed to get output buffer\n");
798  return AVERROR_EXTERNAL;
799  }
800 
801  if ((ret = mediacodec_wrap_sw_buffer(avctx, s, data, size, index, &info, frame)) < 0) {
802  av_log(avctx, AV_LOG_ERROR, "Failed to wrap MediaCodec buffer\n");
803  return ret;
804  }
805  }
806 
807  s->output_buffer_count++;
808  return 0;
809  } else {
811  if (status < 0) {
812  av_log(avctx, AV_LOG_ERROR, "Failed to release output buffer\n");
813  }
814  }
815 
816  } else if (ff_AMediaCodec_infoOutputFormatChanged(codec, index)) {
817  char *format = NULL;
818 
819  if (s->format) {
820  status = ff_AMediaFormat_delete(s->format);
821  if (status < 0) {
822  av_log(avctx, AV_LOG_ERROR, "Failed to delete MediaFormat %p\n", s->format);
823  }
824  }
825 
826  s->format = ff_AMediaCodec_getOutputFormat(codec);
827  if (!s->format) {
828  av_log(avctx, AV_LOG_ERROR, "Failed to get output format\n");
829  return AVERROR_EXTERNAL;
830  }
831 
832  format = ff_AMediaFormat_toString(s->format);
833  if (!format) {
834  return AVERROR_EXTERNAL;
835  }
836  av_log(avctx, AV_LOG_INFO, "Output MediaFormat changed to %s\n", format);
837  av_freep(&format);
838 
839  if ((ret = mediacodec_dec_parse_format(avctx, s)) < 0) {
840  return ret;
841  }
842 
843  } else if (ff_AMediaCodec_infoOutputBuffersChanged(codec, index)) {
845  } else if (ff_AMediaCodec_infoTryAgainLater(codec, index)) {
846  if (s->draining) {
847  av_log(avctx, AV_LOG_ERROR, "Failed to dequeue output buffer within %" PRIi64 "ms "
848  "while draining remaining frames, output will probably lack frames\n",
849  output_dequeue_timeout_us / 1000);
850  } else {
851  av_log(avctx, AV_LOG_TRACE, "No output buffer available, try again later\n");
852  }
853  } else {
854  av_log(avctx, AV_LOG_ERROR, "Failed to dequeue output buffer (status=%zd)\n", index);
855  return AVERROR_EXTERNAL;
856  }
857 
858  return AVERROR(EAGAIN);
859 }
860 
861 /*
862 * ff_mediacodec_dec_flush returns 0 if the flush cannot be performed on
863 * the codec (because the user retains frames). The codec stays in the
864 * flushing state.
865 *
866 * ff_mediacodec_dec_flush returns 1 if the flush can actually be
867 * performed on the codec. The codec leaves the flushing state and can
868 * process again packets.
869 *
870 * ff_mediacodec_dec_flush returns a negative value if an error has
871 * occurred.
872 */
874 {
875  if (!s->surface || atomic_load(&s->refcount) == 1) {
876  int ret;
877 
878  /* No frames (holding a reference to the codec) are retained by the
879  * user, thus we can flush the codec and returns accordingly */
880  if ((ret = mediacodec_dec_flush_codec(avctx, s)) < 0) {
881  return ret;
882  }
883 
884  return 1;
885  }
886 
887  s->flushing = 1;
888  return 0;
889 }
890 
892 {
894 
895  return 0;
896 }
897 
899 {
900  return s->flushing;
901 }
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:92
AVCodecContext::hwaccel_context
void * hwaccel_context
Hardware accelerator context.
Definition: avcodec.h:1370
ff_AMediaCodecList_getCodecNameByType
char * ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx)
Definition: mediacodec_wrapper.c:384
MediaCodecDecContext
Definition: mediacodecdec_common.h:37
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
status
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
AVERROR
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 they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:960
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:494
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1089
COLOR_QCOM_FormatYUV420SemiPlanar
@ COLOR_QCOM_FormatYUV420SemiPlanar
Definition: mediacodecdec_common.c:172
mediacodec_surface.h
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:503
av_div_q
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
AVMediaCodecDeviceContext::surface
void * surface
android/view/Surface handle, to be filled by the user.
Definition: hwcontext_mediacodec.h:33
OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US
#define OUTPUT_DEQUEUE_BLOCK_TIMEOUT_US
Definition: mediacodecdec_common.c:86
ff_mediacodec_dec_close
int ff_mediacodec_dec_close(AVCodecContext *avctx, MediaCodecDecContext *s)
Definition: mediacodecdec_common.c:891
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:424
index
fg index
Definition: ffmpeg_filter.c:167
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:953
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:597
ff_mediacodec_dec_receive
int ff_mediacodec_dec_receive(AVCodecContext *avctx, MediaCodecDecContext *s, AVFrame *frame, bool wait)
Definition: mediacodecdec_common.c:750
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:373
OUTPUT_DEQUEUE_TIMEOUT_US
#define OUTPUT_DEQUEUE_TIMEOUT_US
Definition: mediacodecdec_common.c:85
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:497
data
const char data[16]
Definition: mxf.c:143
COLOR_TRANSFER_HLG
@ COLOR_TRANSFER_HLG
Definition: mediacodecdec_common.c:148
AV_HWDEVICE_TYPE_MEDIACODEC
@ AV_HWDEVICE_TYPE_MEDIACODEC
Definition: hwcontext.h:38
COLOR_TRANSFER_LINEAR
@ COLOR_TRANSFER_LINEAR
Definition: mediacodecdec_common.c:145
ff_mediacodec_dec_is_flushing
int ff_mediacodec_dec_is_flushing(AVCodecContext *avctx, MediaCodecDecContext *s)
Definition: mediacodecdec_common.c:898
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:469
ff_AMediaCodec_releaseOutputBuffer
int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec *codec, size_t idx, int render)
Definition: mediacodec_wrapper.c:1430
hwcontext_mediacodec.h
AVCOL_SPC_BT470BG
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition: pixfmt.h:529
ff_mediacodec_sw_buffer_copy_yuv420_packed_semi_planar_64x32Tile2m8ka
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)
Definition: mediacodec_sw_buffer.c:272
COLOR_FormatYCbYCr
@ COLOR_FormatYCbYCr
Definition: mediacodecdec_common.c:170
color_formats
static const struct @96 color_formats[]
fail
#define fail()
Definition: checkasm.h:127
ff_AMediaCodec_infoOutputFormatChanged
int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.c:1662
ff_AMediaFormat_toString
char * ff_AMediaFormat_toString(FFAMediaFormat *format)
Definition: mediacodec_wrapper.c:728
ff_AMediaCodec_flush
int ff_AMediaCodec_flush(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1413
ff_mediacodec_dec_flush
int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s)
Definition: mediacodecdec_common.c:873
pts
static int64_t pts
Definition: transcode_aac.c:653
COLOR_TI_FormatYUV420PackedSemiPlanar
@ COLOR_TI_FormatYUV420PackedSemiPlanar
Definition: mediacodecdec_common.c:175
atomic_fetch_sub
#define atomic_fetch_sub(object, operand)
Definition: stdatomic.h:137
AVRational::num
int num
Numerator.
Definition: rational.h:59
mediacodecdec_common.h
INPUT_DEQUEUE_TIMEOUT_US
#define INPUT_DEQUEUE_TIMEOUT_US
OMX.k3.video.decoder.avc, OMX.NVIDIA.
Definition: mediacodecdec_common.c:84
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:61
ff_AMediaCodec_infoOutputBuffersChanged
int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.c:1657
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:946
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
COLOR_STANDARD_BT601_PAL
@ COLOR_STANDARD_BT601_PAL
Definition: mediacodecdec_common.c:107
ff_mediacodec_surface_ref
FFANativeWindow * ff_mediacodec_surface_ref(void *surface, void *log_ctx)
Definition: mediacodec_surface.c:28
mcdec_map_color_format
static enum AVPixelFormat mcdec_map_color_format(AVCodecContext *avctx, MediaCodecDecContext *s, int color_format)
Definition: mediacodecdec_common.c:196
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:257
COLOR_TRANSFER_SDR_VIDEO
@ COLOR_TRANSFER_SDR_VIDEO
Definition: mediacodecdec_common.c:146
AV_BUFFER_FLAG_READONLY
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
Definition: buffer.h:114
AVCOL_SPC_SMPTE170M
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition: pixfmt.h:530
info
MIPS optimizations info
Definition: mips.txt:2
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:296
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
COLOR_QCOM_FormatYUV420PackedSemiPlanar64x32Tile2m8ka
@ COLOR_QCOM_FormatYUV420PackedSemiPlanar64x32Tile2m8ka
Definition: mediacodecdec_common.c:174
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:141
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
ff_mediacodec_sw_buffer_copy_yuv420_packed_semi_planar
void ff_mediacodec_sw_buffer_copy_yuv420_packed_semi_planar(AVCodecContext *avctx, MediaCodecDecContext *s, uint8_t *data, size_t size, FFAMediaCodecBufferInfo *info, AVFrame *frame)
Definition: mediacodec_sw_buffer.c:181
color_range
color_range
Definition: vf_selectivecolor.c:44
atomic_load
#define atomic_load(object)
Definition: stdatomic.h:93
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:472
AVCOL_PRI_BT470BG
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:476
mcdec_get_color_range
static enum AVColorRange mcdec_get_color_range(int color_range)
Definition: mediacodecdec_common.c:93
AV_PIX_FMT_MEDIACODEC
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition: pixfmt.h:283
AVCOL_PRI_SMPTE170M
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:477
ff_AMediaCodec_queueInputBuffer
int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec *codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
Definition: mediacodec_wrapper.c:1481
ff_AMediaCodec_getInputBuffer
uint8_t * ff_AMediaCodec_getInputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:1533
NULL
#define NULL
Definition: coverity.c:32
FFAMediaCodecBufferInfo
Definition: mediacodec_wrapper.h:85
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:967
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
AVMediaCodecContext
This structure holds a reference to a android/view/Surface object that will be used as output by the ...
Definition: mediacodec.h:33
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:471
mediacodec_sw_buffer.h
ff_mediacodec_surface_unref
int ff_mediacodec_surface_unref(FFANativeWindow *window, void *log_ctx)
Definition: mediacodec_surface.c:40
COLOR_TI_FormatYUV420PackedSemiPlanarInterlaced
@ COLOR_TI_FormatYUV420PackedSemiPlanarInterlaced
Definition: mediacodecdec_common.c:176
time.h
ff_mediacodec_dec_ref
static void ff_mediacodec_dec_ref(MediaCodecDecContext *s)
Definition: mediacodecdec_common.c:223
ff_AMediaCodec_getBufferFlagEndOfStream
int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1672
COLOR_FormatYUV420SemiPlanar
@ COLOR_FormatYUV420SemiPlanar
Definition: mediacodecdec_common.c:169
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:563
AVMediaCodecDeviceContext
MediaCodec details.
Definition: hwcontext_mediacodec.h:27
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
COLOR_STANDARD_BT709
@ COLOR_STANDARD_BT709
Definition: mediacodecdec_common.c:106
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:480
ff_AMediaCodec_dequeueOutputBuffer
ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec *codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:1498
AMEDIAFORMAT_GET_INT32
#define AMEDIAFORMAT_GET_INT32(name, key, mandatory)
Definition: mediacodecdec_common.c:428
ff_mediacodec_sw_buffer_copy_yuv420_semi_planar
void ff_mediacodec_sw_buffer_copy_yuv420_semi_planar(AVCodecContext *avctx, MediaCodecDecContext *s, uint8_t *data, size_t size, FFAMediaCodecBufferInfo *info, AVFrame *frame)
Definition: mediacodec_sw_buffer.c:131
mediacodec_dec_parse_format
static int mediacodec_dec_parse_format(AVCodecContext *avctx, MediaCodecDecContext *s)
Definition: mediacodecdec_common.c:439
ff_mediacodec_sw_buffer_copy_yuv420_planar
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.
Definition: mediacodec_sw_buffer.c:76
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1652
AVPacket::size
int size
Definition: packet.h:374
ff_AMediaCodec_createCodecByName
FFAMediaCodec * ff_AMediaCodec_createCodecByName(const char *name)
AVCOL_TRC_SMPTEST2084
@ AVCOL_TRC_SMPTEST2084
Definition: pixfmt.h:512
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
Definition: avcodec.h:1724
size
int size
Definition: twinvq_data.h:10344
ff_AMediaCodec_start
int ff_AMediaCodec_start(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1379
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
ff_AMediaCodec_delete
int ff_AMediaCodec_delete(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1303
format
ofilter format
Definition: ffmpeg_filter.c:172
COLOR_RANGE_FULL
@ COLOR_RANGE_FULL
Definition: mediacodecdec_common.c:89
pix_fmt
enum AVPixelFormat pix_fmt
Definition: mediacodecdec_common.c:182
height
#define height
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
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:315
mediacodec_dec_flush_codec
static int mediacodec_dec_flush_codec(AVCodecContext *avctx, MediaCodecDecContext *s)
Definition: mediacodecdec_common.c:532
mediacodec_buffer_release
static void mediacodec_buffer_release(void *opaque, uint8_t *data)
Definition: mediacodecdec_common.c:254
ff_AMediaCodec_dequeueInputBuffer
ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec *codec, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:1464
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
COLOR_QCOM_FormatYUV420SemiPlanar32m
@ COLOR_QCOM_FormatYUV420SemiPlanar32m
Definition: mediacodecdec_common.c:173
mediacodec_wrap_sw_buffer
static int mediacodec_wrap_sw_buffer(AVCodecContext *avctx, MediaCodecDecContext *s, uint8_t *data, size_t size, ssize_t index, FFAMediaCodecBufferInfo *info, AVFrame *frame)
Definition: mediacodecdec_common.c:350
ff_mediacodec_dec_unref
static void ff_mediacodec_dec_unref(MediaCodecDecContext *s)
Definition: mediacodecdec_common.c:228
ff_AMediaCodec_infoTryAgainLater
int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.c:1652
mcdec_get_color_space
static enum AVColorSpace mcdec_get_color_space(int color_standard)
Definition: mediacodecdec_common.c:112
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
mediacodec_wrapper.h
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:366
ff_AMediaCodec_cleanOutputBuffers
int ff_AMediaCodec_cleanOutputBuffers(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1687
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:534
FFAMediaCodec
Definition: mediacodec_wrapper.c:276
ff_AMediaCodec_getOutputBuffer
uint8_t * ff_AMediaCodec_getOutputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:1581
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:523
mcdec_get_color_trc
static enum AVColorTransferCharacteristic mcdec_get_color_trc(int color_transfer)
Definition: mediacodecdec_common.c:151
COLOR_STANDARD_BT2020
@ COLOR_STANDARD_BT2020
Definition: mediacodecdec_common.c:109
common.h
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:263
AVCodecContext::hw_device_ctx
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:1908
AVMediaCodecContext::surface
void * surface
android/view/Surface object reference.
Definition: mediacodec.h:38
profile
int profile
Definition: mxfenc.c:2003
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:526
AVCodecContext::height
int height
Definition: avcodec.h:556
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:593
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:580
avcodec.h
mcdec_get_color_pri
static enum AVColorPrimaries mcdec_get_color_pri(int color_standard)
Definition: mediacodecdec_common.c:128
ff_AMediaCodec_configure
int ff_AMediaCodec_configure(FFAMediaCodec *codec, const FFAMediaFormat *format, void *surface, void *crypto, uint32_t flags)
Definition: mediacodec_wrapper.c:1362
ret
ret
Definition: filter_design.txt:187
AVHWDeviceContext::type
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition: hwcontext.h:79
pixfmt.h
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
ff_set_sar
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition: utils.c:101
AVCodecContext
main external API structure.
Definition: avcodec.h:383
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:515
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
atomic_fetch_add
#define atomic_fetch_add(object, operand)
Definition: stdatomic.h:131
ff_AMediaFormat_delete
int ff_AMediaFormat_delete(FFAMediaFormat *format)
Definition: mediacodec_wrapper.c:706
ff_AMediaCodec_getOutputFormat
FFAMediaFormat * ff_AMediaCodec_getOutputFormat(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.c:1629
AVCOL_TRC_SMPTE170M
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition: pixfmt.h:501
COLOR_STANDARD_BT601_NTSC
@ COLOR_STANDARD_BT601_NTSC
Definition: mediacodecdec_common.c:108
color_format
int color_format
Definition: mediacodecdec_common.c:181
COLOR_RANGE_LIMITED
@ COLOR_RANGE_LIMITED
Definition: mediacodecdec_common.c:90
desc
const char * desc
Definition: libsvtav1.c:79
COLOR_FormatYUV420Planar
@ COLOR_FormatYUV420Planar
Definition: mediacodecdec_common.c:168
mem.h
ff_set_dimensions
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:86
mediacodec_wrap_hw_buffer
static int mediacodec_wrap_hw_buffer(AVCodecContext *avctx, MediaCodecDecContext *s, ssize_t index, FFAMediaCodecBufferInfo *info, AVFrame *frame)
Definition: mediacodecdec_common.c:273
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:350
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
COLOR_TRANSFER_ST2084
@ COLOR_TRANSFER_ST2084
Definition: mediacodecdec_common.c:147
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:556
ff_mediacodec_dec_send
int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, AVPacket *pkt, bool wait)
Definition: mediacodecdec_common.c:656
timestamp.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
COLOR_FormatAndroidOpaque
@ COLOR_FormatAndroidOpaque
Definition: mediacodecdec_common.c:171
atomic_init
#define atomic_init(obj, value)
Definition: stdatomic.h:33
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:525
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:562
FFAMediaFormat
Definition: mediacodec_wrapper.c:164
AVCodecContext::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition: avcodec.h:753
mediacodec.h
ff_mediacodec_dec_init
int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, const char *mime, FFAMediaFormat *format)
Definition: mediacodecdec_common.c:555