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 MPEG-2 / H.264 / H.265 / MPEG-4 / VP8 / VP9 decoders
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 <stdint.h>
24 #include <string.h>
25 
26 #include "libavutil/avassert.h"
27 #include "libavutil/common.h"
28 #include "libavutil/fifo.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/pixfmt.h"
32 
33 #include "avcodec.h"
34 #include "h264_parse.h"
35 #include "hevc_parse.h"
36 #include "hwaccel.h"
37 #include "internal.h"
38 #include "mediacodec_wrapper.h"
39 #include "mediacodecdec_common.h"
40 
41 typedef struct MediaCodecH264DecContext {
42 
44 
46 
48 
50 
52 {
54 
55  ff_mediacodec_dec_close(avctx, s->ctx);
56  s->ctx = NULL;
57 
58  av_fifo_free(s->fifo);
59 
61 
62  return 0;
63 }
64 
65 #if CONFIG_H264_MEDIACODEC_DECODER || CONFIG_HEVC_MEDIACODEC_DECODER
66 static int h2645_ps_to_nalu(const uint8_t *src, int src_size, uint8_t **out, int *out_size)
67 {
68  int i;
69  int ret = 0;
70  uint8_t *p = NULL;
71  static const uint8_t nalu_header[] = { 0x00, 0x00, 0x00, 0x01 };
72 
73  if (!out || !out_size) {
74  return AVERROR(EINVAL);
75  }
76 
77  p = av_malloc(sizeof(nalu_header) + src_size);
78  if (!p) {
79  return AVERROR(ENOMEM);
80  }
81 
82  *out = p;
83  *out_size = sizeof(nalu_header) + src_size;
84 
85  memcpy(p, nalu_header, sizeof(nalu_header));
86  memcpy(p + sizeof(nalu_header), src, src_size);
87 
88  /* Escape 0x00, 0x00, 0x0{0-3} pattern */
89  for (i = 4; i < *out_size; i++) {
90  if (i < *out_size - 3 &&
91  p[i + 0] == 0 &&
92  p[i + 1] == 0 &&
93  p[i + 2] <= 3) {
94  uint8_t *new;
95 
96  *out_size += 1;
97  new = av_realloc(*out, *out_size);
98  if (!new) {
99  ret = AVERROR(ENOMEM);
100  goto done;
101  }
102  *out = p = new;
103 
104  i = i + 2;
105  memmove(p + i + 1, p + i, *out_size - (i + 1));
106  p[i] = 0x03;
107  }
108  }
109 done:
110  if (ret < 0) {
111  av_freep(out);
112  *out_size = 0;
113  }
114 
115  return ret;
116 }
117 #endif
118 
119 #if CONFIG_H264_MEDIACODEC_DECODER
120 static int h264_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
121 {
122  int i;
123  int ret;
124 
125  H264ParamSets ps;
126  const PPS *pps = NULL;
127  const SPS *sps = NULL;
128  int is_avc = 0;
129  int nal_length_size = 0;
130 
131  memset(&ps, 0, sizeof(ps));
132 
134  &ps, &is_avc, &nal_length_size, 0, avctx);
135  if (ret < 0) {
136  goto done;
137  }
138 
139  for (i = 0; i < MAX_PPS_COUNT; i++) {
140  if (ps.pps_list[i]) {
141  pps = (const PPS*)ps.pps_list[i]->data;
142  break;
143  }
144  }
145 
146  if (pps) {
147  if (ps.sps_list[pps->sps_id]) {
148  sps = (const SPS*)ps.sps_list[pps->sps_id]->data;
149  }
150  }
151 
152  if (pps && sps) {
153  uint8_t *data = NULL;
154  int data_size = 0;
155 
156  if ((ret = h2645_ps_to_nalu(sps->data, sps->data_size, &data, &data_size)) < 0) {
157  goto done;
158  }
159  ff_AMediaFormat_setBuffer(format, "csd-0", (void*)data, data_size);
160  av_freep(&data);
161 
162  if ((ret = h2645_ps_to_nalu(pps->data, pps->data_size, &data, &data_size)) < 0) {
163  goto done;
164  }
165  ff_AMediaFormat_setBuffer(format, "csd-1", (void*)data, data_size);
166  av_freep(&data);
167  } else {
168  av_log(avctx, AV_LOG_ERROR, "Could not extract PPS/SPS from extradata");
169  ret = AVERROR_INVALIDDATA;
170  }
171 
172 done:
173  ff_h264_ps_uninit(&ps);
174 
175  return ret;
176 }
177 #endif
178 
179 #if CONFIG_HEVC_MEDIACODEC_DECODER
180 static int hevc_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
181 {
182  int i;
183  int ret;
184 
185  HEVCParamSets ps;
186  HEVCSEI sei;
187 
188  const HEVCVPS *vps = NULL;
189  const HEVCPPS *pps = NULL;
190  const HEVCSPS *sps = NULL;
191  int is_nalff = 0;
192  int nal_length_size = 0;
193 
194  uint8_t *vps_data = NULL;
195  uint8_t *sps_data = NULL;
196  uint8_t *pps_data = NULL;
197  int vps_data_size = 0;
198  int sps_data_size = 0;
199  int pps_data_size = 0;
200 
201  memset(&ps, 0, sizeof(ps));
202  memset(&sei, 0, sizeof(sei));
203 
205  &ps, &sei, &is_nalff, &nal_length_size, 0, 1, avctx);
206  if (ret < 0) {
207  goto done;
208  }
209 
210  for (i = 0; i < HEVC_MAX_VPS_COUNT; i++) {
211  if (ps.vps_list[i]) {
212  vps = (const HEVCVPS*)ps.vps_list[i]->data;
213  break;
214  }
215  }
216 
217  for (i = 0; i < HEVC_MAX_PPS_COUNT; i++) {
218  if (ps.pps_list[i]) {
219  pps = (const HEVCPPS*)ps.pps_list[i]->data;
220  break;
221  }
222  }
223 
224  if (pps) {
225  if (ps.sps_list[pps->sps_id]) {
226  sps = (const HEVCSPS*)ps.sps_list[pps->sps_id]->data;
227  }
228  }
229 
230  if (vps && pps && sps) {
231  uint8_t *data;
232  int data_size;
233 
234  if ((ret = h2645_ps_to_nalu(vps->data, vps->data_size, &vps_data, &vps_data_size)) < 0 ||
235  (ret = h2645_ps_to_nalu(sps->data, sps->data_size, &sps_data, &sps_data_size)) < 0 ||
236  (ret = h2645_ps_to_nalu(pps->data, pps->data_size, &pps_data, &pps_data_size)) < 0) {
237  goto done;
238  }
239 
240  data_size = vps_data_size + sps_data_size + pps_data_size;
241  data = av_mallocz(data_size);
242  if (!data) {
243  ret = AVERROR(ENOMEM);
244  goto done;
245  }
246 
247  memcpy(data , vps_data, vps_data_size);
248  memcpy(data + vps_data_size , sps_data, sps_data_size);
249  memcpy(data + vps_data_size + sps_data_size, pps_data, pps_data_size);
250 
251  ff_AMediaFormat_setBuffer(format, "csd-0", data, data_size);
252 
253  av_freep(&data);
254  } else {
255  av_log(avctx, AV_LOG_ERROR, "Could not extract VPS/PPS/SPS from extradata");
256  ret = AVERROR_INVALIDDATA;
257  }
258 
259 done:
260  av_freep(&vps_data);
261  av_freep(&sps_data);
262  av_freep(&pps_data);
263 
264  return ret;
265 }
266 #endif
267 
268 #if CONFIG_MPEG2_MEDIACODEC_DECODER
269 static int mpeg2_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
270 {
271  int ret = 0;
272 
273  if (avctx->extradata) {
274  ff_AMediaFormat_setBuffer(format, "csd-0", avctx->extradata, avctx->extradata_size);
275  }
276 
277  return ret;
278 }
279 #endif
280 
281 #if CONFIG_MPEG4_MEDIACODEC_DECODER
282 static int mpeg4_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
283 {
284  int ret = 0;
285 
286  if (avctx->extradata) {
287  ff_AMediaFormat_setBuffer(format, "csd-0", avctx->extradata, avctx->extradata_size);
288  }
289 
290  return ret;
291 }
292 #endif
293 
294 #if CONFIG_VP8_MEDIACODEC_DECODER || CONFIG_VP9_MEDIACODEC_DECODER
295 static int vpx_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
296 {
297  int ret = 0;
298 
299  if (avctx->extradata) {
300  ff_AMediaFormat_setBuffer(format, "csd-0", avctx->extradata, avctx->extradata_size);
301  }
302 
303  return ret;
304 }
305 #endif
306 
308 {
309  int ret;
310 
311  const char *codec_mime = NULL;
312 
313  FFAMediaFormat *format = NULL;
315 
316  format = ff_AMediaFormat_new();
317  if (!format) {
318  av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
319  ret = AVERROR_EXTERNAL;
320  goto done;
321  }
322 
323  switch (avctx->codec_id) {
324 #if CONFIG_H264_MEDIACODEC_DECODER
325  case AV_CODEC_ID_H264:
326  codec_mime = "video/avc";
327 
328  ret = h264_set_extradata(avctx, format);
329  if (ret < 0)
330  goto done;
331  break;
332 #endif
333 #if CONFIG_HEVC_MEDIACODEC_DECODER
334  case AV_CODEC_ID_HEVC:
335  codec_mime = "video/hevc";
336 
337  ret = hevc_set_extradata(avctx, format);
338  if (ret < 0)
339  goto done;
340  break;
341 #endif
342 #if CONFIG_MPEG2_MEDIACODEC_DECODER
344  codec_mime = "video/mpeg2";
345 
346  ret = mpeg2_set_extradata(avctx, format);
347  if (ret < 0)
348  goto done;
349  break;
350 #endif
351 #if CONFIG_MPEG4_MEDIACODEC_DECODER
352  case AV_CODEC_ID_MPEG4:
353  codec_mime = "video/mp4v-es",
354 
355  ret = mpeg4_set_extradata(avctx, format);
356  if (ret < 0)
357  goto done;
358  break;
359 #endif
360 #if CONFIG_VP8_MEDIACODEC_DECODER
361  case AV_CODEC_ID_VP8:
362  codec_mime = "video/x-vnd.on2.vp8";
363 
364  ret = vpx_set_extradata(avctx, format);
365  if (ret < 0)
366  goto done;
367  break;
368 #endif
369 #if CONFIG_VP9_MEDIACODEC_DECODER
370  case AV_CODEC_ID_VP9:
371  codec_mime = "video/x-vnd.on2.vp9";
372 
373  ret = vpx_set_extradata(avctx, format);
374  if (ret < 0)
375  goto done;
376  break;
377 #endif
378  default:
379  av_assert0(0);
380  }
381 
382  ff_AMediaFormat_setString(format, "mime", codec_mime);
383  ff_AMediaFormat_setInt32(format, "width", avctx->width);
384  ff_AMediaFormat_setInt32(format, "height", avctx->height);
385 
386  s->ctx = av_mallocz(sizeof(*s->ctx));
387  if (!s->ctx) {
388  av_log(avctx, AV_LOG_ERROR, "Failed to allocate MediaCodecDecContext\n");
389  ret = AVERROR(ENOMEM);
390  goto done;
391  }
392 
393  if ((ret = ff_mediacodec_dec_init(avctx, s->ctx, codec_mime, format)) < 0) {
394  s->ctx = NULL;
395  goto done;
396  }
397 
398  av_log(avctx, AV_LOG_INFO, "MediaCodec started successfully, ret = %d\n", ret);
399 
400  s->fifo = av_fifo_alloc(sizeof(AVPacket));
401  if (!s->fifo) {
402  ret = AVERROR(ENOMEM);
403  goto done;
404  }
405 
406 done:
407  if (format) {
408  ff_AMediaFormat_delete(format);
409  }
410 
411  if (ret < 0) {
413  }
414 
415  return ret;
416 }
417 
418 
420  int *got_frame, AVPacket *pkt)
421 {
423 
424  return ff_mediacodec_dec_decode(avctx, s->ctx, frame, got_frame, pkt);
425 }
426 
427 static int mediacodec_decode_frame(AVCodecContext *avctx, void *data,
428  int *got_frame, AVPacket *avpkt)
429 {
431  AVFrame *frame = data;
432  int ret;
433 
434  /* buffer the input packet */
435  if (avpkt->size) {
436  AVPacket input_pkt = { 0 };
437 
438  if (av_fifo_space(s->fifo) < sizeof(input_pkt)) {
439  ret = av_fifo_realloc2(s->fifo,
440  av_fifo_size(s->fifo) + sizeof(input_pkt));
441  if (ret < 0)
442  return ret;
443  }
444 
445  ret = av_packet_ref(&input_pkt, avpkt);
446  if (ret < 0)
447  return ret;
448  av_fifo_generic_write(s->fifo, &input_pkt, sizeof(input_pkt), NULL);
449  }
450 
451  /*
452  * MediaCodec.flush() discards both input and output buffers, thus we
453  * need to delay the call to this function until the user has released or
454  * renderered the frames he retains.
455  *
456  * After we have buffered an input packet, check if the codec is in the
457  * flushing state. If it is, we need to call ff_mediacodec_dec_flush.
458  *
459  * ff_mediacodec_dec_flush returns 0 if the flush cannot be performed on
460  * the codec (because the user retains frames). The codec stays in the
461  * flushing state.
462  *
463  * ff_mediacodec_dec_flush returns 1 if the flush can actually be
464  * performed on the codec. The codec leaves the flushing state and can
465  * process again packets.
466  *
467  * ff_mediacodec_dec_flush returns a negative value if an error has
468  * occurred.
469  *
470  */
471  if (ff_mediacodec_dec_is_flushing(avctx, s->ctx)) {
472  if (!ff_mediacodec_dec_flush(avctx, s->ctx)) {
473  return avpkt->size;
474  }
475  }
476 
477  /* process buffered data */
478  while (!*got_frame) {
479  /* prepare the input data */
480  if (s->buffered_pkt.size <= 0) {
482 
483  /* no more data */
484  if (av_fifo_size(s->fifo) < sizeof(AVPacket)) {
485  return avpkt->size ? avpkt->size :
486  ff_mediacodec_dec_decode(avctx, s->ctx, frame, got_frame, avpkt);
487  }
488 
490  }
491 
492  ret = mediacodec_process_data(avctx, frame, got_frame, &s->buffered_pkt);
493  if (ret < 0)
494  return ret;
495 
496  s->buffered_pkt.size -= ret;
497  s->buffered_pkt.data += ret;
498  }
499 
500  return avpkt->size;
501 }
502 
504 {
506 
507  while (av_fifo_size(s->fifo)) {
508  AVPacket pkt;
509  av_fifo_generic_read(s->fifo, &pkt, sizeof(pkt), NULL);
510  av_packet_unref(&pkt);
511  }
512  av_fifo_reset(s->fifo);
513 
515 
516  ff_mediacodec_dec_flush(avctx, s->ctx);
517 }
518 
520  &(const AVCodecHWConfigInternal) {
521  .public = {
524  .device_type = AV_HWDEVICE_TYPE_NONE,
525  },
526  .hwaccel = NULL,
527  },
528  NULL
529 };
530 
531 #if CONFIG_H264_MEDIACODEC_DECODER
532 AVCodec ff_h264_mediacodec_decoder = {
533  .name = "h264_mediacodec",
534  .long_name = NULL_IF_CONFIG_SMALL("H.264 Android MediaCodec decoder"),
535  .type = AVMEDIA_TYPE_VIDEO,
536  .id = AV_CODEC_ID_H264,
537  .priv_data_size = sizeof(MediaCodecH264DecContext),
541  .close = mediacodec_decode_close,
543  .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
544  .bsfs = "h264_mp4toannexb",
545  .hw_configs = mediacodec_hw_configs,
546 };
547 #endif
548 
549 #if CONFIG_HEVC_MEDIACODEC_DECODER
550 AVCodec ff_hevc_mediacodec_decoder = {
551  .name = "hevc_mediacodec",
552  .long_name = NULL_IF_CONFIG_SMALL("H.265 Android MediaCodec decoder"),
553  .type = AVMEDIA_TYPE_VIDEO,
554  .id = AV_CODEC_ID_HEVC,
555  .priv_data_size = sizeof(MediaCodecH264DecContext),
559  .close = mediacodec_decode_close,
561  .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
562  .bsfs = "hevc_mp4toannexb",
563  .hw_configs = mediacodec_hw_configs,
564 };
565 #endif
566 
567 #if CONFIG_MPEG2_MEDIACODEC_DECODER
568 AVCodec ff_mpeg2_mediacodec_decoder = {
569  .name = "mpeg2_mediacodec",
570  .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 Android MediaCodec decoder"),
571  .type = AVMEDIA_TYPE_VIDEO,
573  .priv_data_size = sizeof(MediaCodecH264DecContext),
577  .close = mediacodec_decode_close,
579  .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
580  .hw_configs = mediacodec_hw_configs,
581 };
582 #endif
583 
584 #if CONFIG_MPEG4_MEDIACODEC_DECODER
585 AVCodec ff_mpeg4_mediacodec_decoder = {
586  .name = "mpeg4_mediacodec",
587  .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Android MediaCodec decoder"),
588  .type = AVMEDIA_TYPE_VIDEO,
589  .id = AV_CODEC_ID_MPEG4,
590  .priv_data_size = sizeof(MediaCodecH264DecContext),
594  .close = mediacodec_decode_close,
596  .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
597  .hw_configs = mediacodec_hw_configs,
598 };
599 #endif
600 
601 #if CONFIG_VP8_MEDIACODEC_DECODER
602 AVCodec ff_vp8_mediacodec_decoder = {
603  .name = "vp8_mediacodec",
604  .long_name = NULL_IF_CONFIG_SMALL("VP8 Android MediaCodec decoder"),
605  .type = AVMEDIA_TYPE_VIDEO,
606  .id = AV_CODEC_ID_VP8,
607  .priv_data_size = sizeof(MediaCodecH264DecContext),
611  .close = mediacodec_decode_close,
613  .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
614  .hw_configs = mediacodec_hw_configs,
615 };
616 #endif
617 
618 #if CONFIG_VP9_MEDIACODEC_DECODER
619 AVCodec ff_vp9_mediacodec_decoder = {
620  .name = "vp9_mediacodec",
621  .long_name = NULL_IF_CONFIG_SMALL("VP9 Android MediaCodec decoder"),
622  .type = AVMEDIA_TYPE_VIDEO,
623  .id = AV_CODEC_ID_VP9,
624  .priv_data_size = sizeof(MediaCodecH264DecContext),
628  .close = mediacodec_decode_close,
630  .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
631  .hw_configs = mediacodec_hw_configs,
632 };
633 #endif
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition: hwaccel.h:34
#define NULL
Definition: coverity.c:32
int ff_mediacodec_dec_decode(AVCodecContext *avctx, MediaCodecDecContext *s, AVFrame *frame, int *got_frame, AVPacket *pkt)
const char * s
Definition: avisynth_c.h:768
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
static const AVCodecHWConfigInternal * mediacodec_hw_configs[]
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:135
AVBufferRef * vps_list[HEVC_MAX_VPS_COUNT]
Definition: hevc_ps.h:395
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static void flush(AVCodecContext *avctx)
AVBufferRef * sps_list[MAX_SPS_COUNT]
Definition: h264_ps.h:138
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
MediaCodecDecContext * ctx
Definition: mediacodecdec.c:43
Sequence parameter set.
Definition: h264_ps.h:43
int size
Definition: avcodec.h:1401
void ff_AMediaFormat_setBuffer(FFAMediaFormat *format, const char *name, void *data, size_t size)
static av_cold int mediacodec_decode_close(AVCodecContext *avctx)
Definition: mediacodecdec.c:51
Picture parameter set.
Definition: h264_ps.h:108
int out_size
Definition: movenc.c:55
H.265 parser code.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
int ff_hevc_decode_extradata(const uint8_t *data, int size, HEVCParamSets *ps, HEVCSEI *sei, int *is_nalff, int *nal_length_size, int err_recognition, int apply_defdispwin, void *logctx)
Definition: hevc_parse.c:77
static AVPacket pkt
static av_cold int mediacodec_decode_init(AVCodecContext *avctx)
#define src
Definition: vp8dsp.c:254
int ff_mediacodec_dec_close(AVCodecContext *avctx, MediaCodecDecContext *s)
AVCodec.
Definition: avcodec.h:3351
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
Definition: fifo.c:122
int ff_mediacodec_dec_is_flushing(AVCodecContext *avctx, MediaCodecDecContext *s)
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:981
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVBufferRef * sps_list[HEVC_MAX_SPS_COUNT]
Definition: hevc_ps.h:396
uint8_t
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
AVOptions.
FFAMediaFormat * ff_AMediaFormat_new(void)
static int mediacodec_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
enum AVPixelFormat pix_fmt
A hardware pixel format which the codec can use.
Definition: avcodec.h:3329
int av_fifo_space(const AVFifoBuffer *f)
Return the amount of space in bytes in the AVFifoBuffer, that is the amount of data you can write int...
Definition: fifo.c:82
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1588
static AVFrame * frame
int ff_h264_decode_extradata(const uint8_t *data, int size, H264ParamSets *ps, int *is_avc, int *nal_length_size, int err_recognition, void *logctx)
Definition: h264_parse.c:436
#define MAX_PPS_COUNT
Definition: h264_ps.h:38
uint8_t * data
Definition: avcodec.h:1400
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
Definition: fifo.c:55
AVBufferRef * pps_list[HEVC_MAX_PPS_COUNT]
Definition: hevc_ps.h:397
#define av_log(a,...)
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:599
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AVERROR(e)
Definition: error.h:43
int data_size
Definition: hevc_ps.h:391
int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
Definition: fifo.c:213
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Definition: avcodec.h:3358
size_t data_size
Definition: h264_ps.h:102
uint8_t data[4096]
Definition: h264_ps.h:128
void ff_AMediaFormat_setInt32(FFAMediaFormat *format, const char *name, int32_t value)
int width
picture width / height.
Definition: avcodec.h:1660
int data_size
Definition: hevc_ps.h:215
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:220
void ff_AMediaFormat_setString(FFAMediaFormat *format, const char *name, const char *value)
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
Libavcodec external API header.
AVBufferRef * pps_list[MAX_PPS_COUNT]
Definition: h264_ps.h:139
enum AVCodecID codec_id
Definition: avcodec.h:1498
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
Definition: fifo.c:77
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
Resize an AVFifoBuffer.
Definition: fifo.c:87
unsigned int sps_id
seq_parameter_set_id
Definition: hevc_ps.h:318
main external API structure.
Definition: avcodec.h:1488
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:590
uint8_t * data
The data buffer.
Definition: buffer.h:89
a very simple circular buffer FIFO implementation
int extradata_size
Definition: avcodec.h:1589
static const char * format
Definition: movenc.c:47
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
static int mediacodec_process_data(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
unsigned int sps_id
Definition: h264_ps.h:109
int ff_AMediaFormat_delete(FFAMediaFormat *format)
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
static void mediacodec_decode_flush(AVCodecContext *avctx)
hardware decoding through MediaCodec
Definition: pixfmt.h:289
#define FF_CODEC_CAP_SETS_PKT_DTS
Decoders marked with FF_CODEC_CAP_SETS_PKT_DTS want to set AVFrame.pkt_dts manually.
Definition: internal.h:55
int data_size
Definition: hevc_ps.h:314
common internal api header.
common internal and external API header
uint8_t data[4096]
Definition: h264_ps.h:101
size_t data_size
Definition: h264_ps.h:129
uint8_t data[4096]
Definition: hevc_ps.h:214
The codec supports this format by some ad-hoc method.
Definition: avcodec.h:3322
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
Definition: h264_ps.c:317
int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, const char *mime, FFAMediaFormat *format)
void * priv_data
Definition: avcodec.h:1515
pixel format definitions
uint8_t data[4096]
Definition: hevc_ps.h:313
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
Definition: fifo.c:43
#define AV_CODEC_CAP_AVOID_PROBING
Decoder is not a preferred choice for probing.
Definition: avcodec.h:1038
FILE * out
Definition: movenc.c:54
#define av_freep(p)
void av_fifo_reset(AVFifoBuffer *f)
Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied...
Definition: fifo.c:71
H.264 decoder/parser shared code.
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:57
This structure stores compressed data.
Definition: avcodec.h:1377
uint8_t data[4096]
Definition: hevc_ps.h:390