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 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 #include "libavutil/atomic.h"
33 
34 #include "avcodec.h"
35 #include "h264_parse.h"
36 #include "hevc_parse.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 {
56 
57  ff_mediacodec_dec_close(avctx, s->ctx);
58  s->ctx = NULL;
59 
60  av_fifo_free(s->fifo);
61 
62  av_bsf_free(&s->bsf);
64 
65  return 0;
66 }
67 
68 #if CONFIG_H264_MEDIACODEC_DECODER || CONFIG_HEVC_MEDIACODEC_DECODER
69 static int h2645_ps_to_nalu(const uint8_t *src, int src_size, uint8_t **out, int *out_size)
70 {
71  int i;
72  int ret = 0;
73  uint8_t *p = NULL;
74  static const uint8_t nalu_header[] = { 0x00, 0x00, 0x00, 0x01 };
75 
76  if (!out || !out_size) {
77  return AVERROR(EINVAL);
78  }
79 
80  p = av_malloc(sizeof(nalu_header) + src_size);
81  if (!p) {
82  return AVERROR(ENOMEM);
83  }
84 
85  *out = p;
86  *out_size = sizeof(nalu_header) + src_size;
87 
88  memcpy(p, nalu_header, sizeof(nalu_header));
89  memcpy(p + sizeof(nalu_header), src, src_size);
90 
91  /* Escape 0x00, 0x00, 0x0{0-3} pattern */
92  for (i = 4; i < *out_size; i++) {
93  if (i < *out_size - 3 &&
94  p[i + 0] == 0 &&
95  p[i + 1] == 0 &&
96  p[i + 2] <= 3) {
97  uint8_t *new;
98 
99  *out_size += 1;
100  new = av_realloc(*out, *out_size);
101  if (!new) {
102  ret = AVERROR(ENOMEM);
103  goto done;
104  }
105  *out = p = new;
106 
107  i = i + 2;
108  memmove(p + i + 1, p + i, *out_size - (i + 1));
109  p[i] = 0x03;
110  }
111  }
112 done:
113  if (ret < 0) {
114  av_freep(out);
115  *out_size = 0;
116  }
117 
118  return ret;
119 }
120 #endif
121 
122 #if CONFIG_H264_MEDIACODEC_DECODER
123 static int h264_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
124 {
125  int i;
126  int ret;
127 
128  H264ParamSets ps;
129  const PPS *pps = NULL;
130  const SPS *sps = NULL;
131  int is_avc = 0;
132  int nal_length_size = 0;
133 
134  memset(&ps, 0, sizeof(ps));
135 
137  &ps, &is_avc, &nal_length_size, 0, avctx);
138  if (ret < 0) {
139  goto done;
140  }
141 
142  for (i = 0; i < MAX_PPS_COUNT; i++) {
143  if (ps.pps_list[i]) {
144  pps = (const PPS*)ps.pps_list[i]->data;
145  break;
146  }
147  }
148 
149  if (pps) {
150  if (ps.sps_list[pps->sps_id]) {
151  sps = (const SPS*)ps.sps_list[pps->sps_id]->data;
152  }
153  }
154 
155  if (pps && sps) {
156  uint8_t *data = NULL;
157  int data_size = 0;
158 
159  if ((ret = h2645_ps_to_nalu(sps->data, sps->data_size, &data, &data_size)) < 0) {
160  goto done;
161  }
162  ff_AMediaFormat_setBuffer(format, "csd-0", (void*)data, data_size);
163  av_freep(&data);
164 
165  if ((ret = h2645_ps_to_nalu(pps->data, pps->data_size, &data, &data_size)) < 0) {
166  goto done;
167  }
168  ff_AMediaFormat_setBuffer(format, "csd-1", (void*)data, data_size);
169  av_freep(&data);
170  } else {
171  av_log(avctx, AV_LOG_ERROR, "Could not extract PPS/SPS from extradata");
172  ret = AVERROR_INVALIDDATA;
173  }
174 
175 done:
176  ff_h264_ps_uninit(&ps);
177 
178  return ret;
179 }
180 #endif
181 
182 #if CONFIG_HEVC_MEDIACODEC_DECODER
183 static int hevc_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
184 {
185  int i;
186  int ret;
187 
188  HEVCParamSets ps;
189 
190  const HEVCVPS *vps = NULL;
191  const HEVCPPS *pps = NULL;
192  const HEVCSPS *sps = NULL;
193  int is_nalff = 0;
194  int nal_length_size = 0;
195 
196  uint8_t *vps_data = NULL;
197  uint8_t *sps_data = NULL;
198  uint8_t *pps_data = NULL;
199  int vps_data_size = 0;
200  int sps_data_size = 0;
201  int pps_data_size = 0;
202 
203  memset(&ps, 0, sizeof(ps));
204 
206  &ps, &is_nalff, &nal_length_size, 0, avctx);
207  if (ret < 0) {
208  goto done;
209  }
210 
211  for (i = 0; i < MAX_VPS_COUNT; i++) {
212  if (ps.vps_list[i]) {
213  vps = (const HEVCVPS*)ps.vps_list[i]->data;
214  break;
215  }
216  }
217 
218  for (i = 0; i < MAX_PPS_COUNT; i++) {
219  if (ps.pps_list[i]) {
220  pps = (const HEVCPPS*)ps.pps_list[i]->data;
221  break;
222  }
223  }
224 
225  if (pps) {
226  if (ps.sps_list[pps->sps_id]) {
227  sps = (const HEVCSPS*)ps.sps_list[pps->sps_id]->data;
228  }
229  }
230 
231  if (vps && pps && sps) {
232  uint8_t *data;
233  int data_size;
234 
235  if ((ret = h2645_ps_to_nalu(vps->data, vps->data_size, &vps_data, &vps_data_size)) < 0 ||
236  (ret = h2645_ps_to_nalu(sps->data, sps->data_size, &sps_data, &sps_data_size)) < 0 ||
237  (ret = h2645_ps_to_nalu(pps->data, pps->data_size, &pps_data, &pps_data_size)) < 0) {
238  goto done;
239  }
240 
241  data_size = vps_data_size + sps_data_size + pps_data_size;
242  data = av_mallocz(data_size);
243  if (!data) {
244  ret = AVERROR(ENOMEM);
245  goto done;
246  }
247 
248  memcpy(data , vps_data, vps_data_size);
249  memcpy(data + vps_data_size , sps_data, sps_data_size);
250  memcpy(data + vps_data_size + sps_data_size, pps_data, pps_data_size);
251 
252  ff_AMediaFormat_setBuffer(format, "csd-0", data, data_size);
253 
254  av_freep(&data);
255  } else {
256  av_log(avctx, AV_LOG_ERROR, "Could not extract VPS/PPS/SPS from extradata");
257  ret = AVERROR_INVALIDDATA;
258  }
259 
260 done:
261  av_freep(&vps_data);
262  av_freep(&sps_data);
263  av_freep(&pps_data);
264 
265  return ret;
266 }
267 #endif
268 
269 #if CONFIG_MPEG4_MEDIACODEC_DECODER
270 static int mpeg4_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
271 {
272  int ret = 0;
273 
274  if (avctx->extradata) {
275  ff_AMediaFormat_setBuffer(format, "csd-0", avctx->extradata, avctx->extradata_size);
276  }
277 
278  return ret;
279 }
280 #endif
281 
282 #if CONFIG_VP8_MEDIACODEC_DECODER || CONFIG_VP9_MEDIACODEC_DECODER
283 static int vpx_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
284 {
285  int ret = 0;
286 
287  if (avctx->extradata) {
288  ff_AMediaFormat_setBuffer(format, "csd-0", avctx->extradata, avctx->extradata_size);
289  }
290 
291  return ret;
292 }
293 #endif
294 
296 {
297  int ret;
298 
299  const char *codec_mime = NULL;
300 
301  const char *bsf_name = NULL;
302  const AVBitStreamFilter *bsf = NULL;
303 
304  FFAMediaFormat *format = NULL;
306 
307  format = ff_AMediaFormat_new();
308  if (!format) {
309  av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
310  ret = AVERROR_EXTERNAL;
311  goto done;
312  }
313 
314  switch (avctx->codec_id) {
315 #if CONFIG_H264_MEDIACODEC_DECODER
316  case AV_CODEC_ID_H264:
317  codec_mime = "video/avc";
318  bsf_name = "h264_mp4toannexb";
319 
320  ret = h264_set_extradata(avctx, format);
321  if (ret < 0)
322  goto done;
323  break;
324 #endif
325 #if CONFIG_HEVC_MEDIACODEC_DECODER
326  case AV_CODEC_ID_HEVC:
327  codec_mime = "video/hevc";
328  bsf_name = "hevc_mp4toannexb";
329 
330  ret = hevc_set_extradata(avctx, format);
331  if (ret < 0)
332  goto done;
333  break;
334 #endif
335 #if CONFIG_MPEG4_MEDIACODEC_DECODER
336  case AV_CODEC_ID_MPEG4:
337  codec_mime = "video/mp4v-es",
338 
339  ret = mpeg4_set_extradata(avctx, format);
340  if (ret < 0)
341  goto done;
342  break;
343 #endif
344 #if CONFIG_VP8_MEDIACODEC_DECODER
345  case AV_CODEC_ID_VP8:
346  codec_mime = "video/x-vnd.on2.vp8";
347 
348  ret = vpx_set_extradata(avctx, format);
349  if (ret < 0)
350  goto done;
351  break;
352 #endif
353 #if CONFIG_VP9_MEDIACODEC_DECODER
354  case AV_CODEC_ID_VP9:
355  codec_mime = "video/x-vnd.on2.vp9";
356 
357  ret = vpx_set_extradata(avctx, format);
358  if (ret < 0)
359  goto done;
360  break;
361 #endif
362  default:
363  av_assert0(0);
364  }
365 
366  ff_AMediaFormat_setString(format, "mime", codec_mime);
367  ff_AMediaFormat_setInt32(format, "width", avctx->width);
368  ff_AMediaFormat_setInt32(format, "height", avctx->height);
369 
370  s->ctx = av_mallocz(sizeof(*s->ctx));
371  if (!s->ctx) {
372  av_log(avctx, AV_LOG_ERROR, "Failed to allocate MediaCodecDecContext\n");
373  ret = AVERROR(ENOMEM);
374  goto done;
375  }
376 
377  if ((ret = ff_mediacodec_dec_init(avctx, s->ctx, codec_mime, format)) < 0) {
378  s->ctx = NULL;
379  goto done;
380  }
381 
382  av_log(avctx, AV_LOG_INFO, "MediaCodec started successfully, ret = %d\n", ret);
383 
384  s->fifo = av_fifo_alloc(sizeof(AVPacket));
385  if (!s->fifo) {
386  ret = AVERROR(ENOMEM);
387  goto done;
388  }
389 
390  if (bsf_name) {
391  bsf = av_bsf_get_by_name(bsf_name);
392  if(!bsf) {
393  ret = AVERROR_BSF_NOT_FOUND;
394  goto done;
395  }
396 
397  if ((ret = av_bsf_alloc(bsf, &s->bsf))) {
398  goto done;
399  }
400 
401  if (((ret = avcodec_parameters_from_context(s->bsf->par_in, avctx)) < 0) ||
402  ((ret = av_bsf_init(s->bsf)) < 0)) {
403  goto done;
404  }
405  }
406 
408 
409 done:
410  if (format) {
411  ff_AMediaFormat_delete(format);
412  }
413 
414  if (ret < 0) {
416  }
417 
418  return ret;
419 }
420 
421 
423  int *got_frame, AVPacket *pkt)
424 {
426 
427  return ff_mediacodec_dec_decode(avctx, s->ctx, frame, got_frame, pkt);
428 }
429 
430 static int mediacodec_decode_frame(AVCodecContext *avctx, void *data,
431  int *got_frame, AVPacket *avpkt)
432 {
434  AVFrame *frame = data;
435  int ret;
436 
437  /* buffer the input packet */
438  if (avpkt->size) {
439  AVPacket input_pkt = { 0 };
440 
441  if (av_fifo_space(s->fifo) < sizeof(input_pkt)) {
442  ret = av_fifo_realloc2(s->fifo,
443  av_fifo_size(s->fifo) + sizeof(input_pkt));
444  if (ret < 0)
445  return ret;
446  }
447 
448  ret = av_packet_ref(&input_pkt, avpkt);
449  if (ret < 0)
450  return ret;
451  av_fifo_generic_write(s->fifo, &input_pkt, sizeof(input_pkt), NULL);
452  }
453 
454  /*
455  * MediaCodec.flush() discards both input and output buffers, thus we
456  * need to delay the call to this function until the user has released or
457  * renderered the frames he retains.
458  *
459  * After we have buffered an input packet, check if the codec is in the
460  * flushing state. If it is, we need to call ff_mediacodec_dec_flush.
461  *
462  * ff_mediacodec_dec_flush returns 0 if the flush cannot be performed on
463  * the codec (because the user retains frames). The codec stays in the
464  * flushing state.
465  *
466  * ff_mediacodec_dec_flush returns 1 if the flush can actually be
467  * performed on the codec. The codec leaves the flushing state and can
468  * process again packets.
469  *
470  * ff_mediacodec_dec_flush returns a negative value if an error has
471  * occurred.
472  *
473  */
474  if (ff_mediacodec_dec_is_flushing(avctx, s->ctx)) {
475  if (!ff_mediacodec_dec_flush(avctx, s->ctx)) {
476  return avpkt->size;
477  }
478  }
479 
480  /* process buffered data */
481  while (!*got_frame) {
482  /* prepare the input data -- convert to Annex B if needed */
483  if (s->filtered_pkt.size <= 0) {
484  AVPacket input_pkt = { 0 };
485 
487 
488  /* no more data */
489  if (av_fifo_size(s->fifo) < sizeof(AVPacket)) {
490  return avpkt->size ? avpkt->size :
491  ff_mediacodec_dec_decode(avctx, s->ctx, frame, got_frame, avpkt);
492  }
493 
494  av_fifo_generic_read(s->fifo, &input_pkt, sizeof(input_pkt), NULL);
495 
496  if (s->bsf) {
497  ret = av_bsf_send_packet(s->bsf, &input_pkt);
498  if (ret < 0) {
499  return ret;
500  }
501 
502  ret = av_bsf_receive_packet(s->bsf, &s->filtered_pkt);
503  if (ret == AVERROR(EAGAIN)) {
504  goto done;
505  }
506  } else {
507  av_packet_move_ref(&s->filtered_pkt, &input_pkt);
508  }
509 
510  /* {h264,hevc}_mp4toannexb are used here and do not require flushing */
511  av_assert0(ret != AVERROR_EOF);
512 
513  if (ret < 0) {
514  return ret;
515  }
516  }
517 
518  ret = mediacodec_process_data(avctx, frame, got_frame, &s->filtered_pkt);
519  if (ret < 0)
520  return ret;
521 
522  s->filtered_pkt.size -= ret;
523  s->filtered_pkt.data += ret;
524  }
525 done:
526  return avpkt->size;
527 }
528 
530 {
532 
533  while (av_fifo_size(s->fifo)) {
534  AVPacket pkt;
535  av_fifo_generic_read(s->fifo, &pkt, sizeof(pkt), NULL);
536  av_packet_unref(&pkt);
537  }
538  av_fifo_reset(s->fifo);
539 
541 
542  ff_mediacodec_dec_flush(avctx, s->ctx);
543 }
544 
545 #if CONFIG_H264_MEDIACODEC_DECODER
546 AVCodec ff_h264_mediacodec_decoder = {
547  .name = "h264_mediacodec",
548  .long_name = NULL_IF_CONFIG_SMALL("H.264 Android MediaCodec decoder"),
549  .type = AVMEDIA_TYPE_VIDEO,
550  .id = AV_CODEC_ID_H264,
551  .priv_data_size = sizeof(MediaCodecH264DecContext),
555  .close = mediacodec_decode_close,
556  .capabilities = CODEC_CAP_DELAY,
557  .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
558 };
559 #endif
560 
561 #if CONFIG_HEVC_MEDIACODEC_DECODER
562 AVCodec ff_hevc_mediacodec_decoder = {
563  .name = "hevc_mediacodec",
564  .long_name = NULL_IF_CONFIG_SMALL("H.265 Android MediaCodec decoder"),
565  .type = AVMEDIA_TYPE_VIDEO,
566  .id = AV_CODEC_ID_HEVC,
567  .priv_data_size = sizeof(MediaCodecH264DecContext),
571  .close = mediacodec_decode_close,
572  .capabilities = CODEC_CAP_DELAY,
573  .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
574 };
575 #endif
576 
577 #if CONFIG_MPEG4_MEDIACODEC_DECODER
578 AVCodec ff_mpeg4_mediacodec_decoder = {
579  .name = "mpeg4_mediacodec",
580  .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Android MediaCodec decoder"),
581  .type = AVMEDIA_TYPE_VIDEO,
582  .id = AV_CODEC_ID_MPEG4,
583  .priv_data_size = sizeof(MediaCodecH264DecContext),
587  .close = mediacodec_decode_close,
588  .capabilities = CODEC_CAP_DELAY,
589  .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
590 };
591 #endif
592 
593 #if CONFIG_VP8_MEDIACODEC_DECODER
594 AVCodec ff_vp8_mediacodec_decoder = {
595  .name = "vp8_mediacodec",
596  .long_name = NULL_IF_CONFIG_SMALL("VP8 Android MediaCodec decoder"),
597  .type = AVMEDIA_TYPE_VIDEO,
598  .id = AV_CODEC_ID_VP8,
599  .priv_data_size = sizeof(MediaCodecH264DecContext),
603  .close = mediacodec_decode_close,
604  .capabilities = CODEC_CAP_DELAY,
605  .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
606 };
607 #endif
608 
609 #if CONFIG_VP9_MEDIACODEC_DECODER
610 AVCodec ff_vp9_mediacodec_decoder = {
611  .name = "vp9_mediacodec",
612  .long_name = NULL_IF_CONFIG_SMALL("VP9 Android MediaCodec decoder"),
613  .type = AVMEDIA_TYPE_VIDEO,
614  .id = AV_CODEC_ID_VP9,
615  .priv_data_size = sizeof(MediaCodecH264DecContext),
619  .close = mediacodec_decode_close,
620  .capabilities = CODEC_CAP_DELAY,
621  .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
622 };
623 #endif
void av_bsf_free(AVBSFContext **ctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:36
#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:184
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:145
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:137
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
The bitstream filter state.
Definition: avcodec.h:5731
int size
Definition: avcodec.h:1602
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:53
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
Picture parameter set.
Definition: h264_ps.h:107
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:252
static AVPacket pkt
static av_cold int mediacodec_decode_init(AVCodecContext *avctx)
int ff_mediacodec_dec_close(AVCodecContext *avctx, MediaCodecDecContext *s)
AVBufferRef * vps_list[MAX_VPS_COUNT]
Definition: hevc.h:572
AVCodec.
Definition: avcodec.h:3600
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition: bsf.c:135
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)
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **ctx)
Allocate a context for a given bitstream filter.
Definition: bsf.c:82
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:199
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)
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:1791
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:422
#define MAX_PPS_COUNT
Definition: h264_ps.h:38
uint8_t * data
Definition: avcodec.h:1601
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:622
#define AVERROR_EOF
End of file.
Definition: error.h:55
void av_fifo_free(AVFifoBuffer *f)
Free an AVFifoBuffer.
Definition: fifo.c:55
#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:576
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define 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:1176
#define AVERROR(e)
Definition: error.h:43
int data_size
Definition: hevc.h:568
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:176
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:3607
int ff_hevc_decode_extradata(const uint8_t *data, int size, HEVCParamSets *ps, int *is_nalff, int *nal_length_size, int err_recognition, void *logctx)
Definition: hevc_parse.c:72
size_t data_size
Definition: h264_ps.h:101
uint8_t data[4096]
Definition: h264_ps.h:127
void ff_AMediaFormat_setInt32(FFAMediaFormat *format, const char *name, int32_t value)
int width
picture width / height.
Definition: avcodec.h:1863
AVBufferRef * pps_list[MAX_PPS_COUNT]
Definition: hevc.h:574
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:176
#define AVERROR_BSF_NOT_FOUND
Bitstream filter not found.
Definition: error.h:49
int data_size
Definition: hevc.h:392
#define src
Definition: vp9dsp.c:530
void ff_AMediaFormat_setString(FFAMediaFormat *format, const char *name, const char *value)
Definition: hevc.h:402
Definition: hevc.h:372
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
Definition: hevc.h:494
Libavcodec external API header.
AVBufferRef * pps_list[MAX_PPS_COUNT]
Definition: h264_ps.h:138
enum AVCodecID codec_id
Definition: avcodec.h:1693
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.h:495
#define MAX_VPS_COUNT
Definition: hevc.h:50
main external API structure.
Definition: avcodec.h:1676
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:567
uint8_t * data
The data buffer.
Definition: buffer.h:89
a very simple circular buffer FIFO implementation
int extradata_size
Definition: avcodec.h:1792
static const char * format
Definition: movenc.c:47
static int mediacodec_process_data(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: utils.c:4166
unsigned int sps_id
Definition: h264_ps.h:108
int ff_AMediaFormat_delete(FFAMediaFormat *format)
static void mediacodec_decode_flush(AVCodecContext *avctx)
#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.h:491
common internal api header.
common internal and external API header
uint8_t data[4096]
Definition: h264_ps.h:100
size_t data_size
Definition: h264_ps.h:128
uint8_t data[4096]
Definition: hevc.h:391
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:33
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
Definition: h264_ps.c:307
int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, const char *mime, FFAMediaFormat *format)
void * priv_data
Definition: avcodec.h:1718
pixel format definitions
uint8_t data[4096]
Definition: hevc.h:490
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
Definition: fifo.c:43
FILE * out
Definition: movenc.c:54
#define av_freep(p)
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: ffmpeg.c:2035
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:1578
AVCodecParameters * par_in
Parameters of the input stream.
Definition: avcodec.h:5757
AVBufferRef * sps_list[MAX_SPS_COUNT]
Definition: hevc.h:573
uint8_t data[4096]
Definition: hevc.h:567