FFmpeg
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 "config_components.h"
24 
25 #include <stdint.h>
26 #include <string.h>
27 
28 #include "libavutil/avassert.h"
29 #include "libavutil/common.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavutil/pixfmt.h"
33 #include "libavutil/internal.h"
34 
35 #include "avcodec.h"
36 #include "codec_internal.h"
37 #include "decode.h"
38 #include "h264_parse.h"
39 #include "h264_ps.h"
40 #include "hevc_parse.h"
41 #include "hwconfig.h"
42 #include "internal.h"
43 #include "jni.h"
44 #include "mediacodec_wrapper.h"
45 #include "mediacodecdec_common.h"
46 
47 typedef struct MediaCodecH264DecContext {
48 
50 
52 
54 
57 
60 
62 {
64 
65  ff_mediacodec_dec_close(avctx, s->ctx);
66  s->ctx = NULL;
67 
68  av_packet_unref(&s->buffered_pkt);
69 
70  return 0;
71 }
72 
73 #if CONFIG_H264_MEDIACODEC_DECODER || CONFIG_HEVC_MEDIACODEC_DECODER
74 static int h2645_ps_to_nalu(const uint8_t *src, int src_size, uint8_t **out, int *out_size)
75 {
76  int i;
77  int ret = 0;
78  uint8_t *p = NULL;
79  static const uint8_t nalu_header[] = { 0x00, 0x00, 0x00, 0x01 };
80 
81  if (!out || !out_size) {
82  return AVERROR(EINVAL);
83  }
84 
85  p = av_malloc(sizeof(nalu_header) + src_size);
86  if (!p) {
87  return AVERROR(ENOMEM);
88  }
89 
90  *out = p;
91  *out_size = sizeof(nalu_header) + src_size;
92 
93  memcpy(p, nalu_header, sizeof(nalu_header));
94  memcpy(p + sizeof(nalu_header), src, src_size);
95 
96  /* Escape 0x00, 0x00, 0x0{0-3} pattern */
97  for (i = 4; i < *out_size; i++) {
98  if (i < *out_size - 3 &&
99  p[i + 0] == 0 &&
100  p[i + 1] == 0 &&
101  p[i + 2] <= 3) {
102  uint8_t *new;
103 
104  *out_size += 1;
105  new = av_realloc(*out, *out_size);
106  if (!new) {
107  ret = AVERROR(ENOMEM);
108  goto done;
109  }
110  *out = p = new;
111 
112  i = i + 2;
113  memmove(p + i + 1, p + i, *out_size - (i + 1));
114  p[i] = 0x03;
115  }
116  }
117 done:
118  if (ret < 0) {
119  av_freep(out);
120  *out_size = 0;
121  }
122 
123  return ret;
124 }
125 #endif
126 
127 #if CONFIG_H264_MEDIACODEC_DECODER
128 static int h264_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
129 {
130  int i;
131  int ret;
132 
133  H264ParamSets ps;
134  const PPS *pps = NULL;
135  const SPS *sps = NULL;
136  int is_avc = 0;
137  int nal_length_size = 0;
138 
139  memset(&ps, 0, sizeof(ps));
140 
142  &ps, &is_avc, &nal_length_size, 0, avctx);
143  if (ret < 0) {
144  goto done;
145  }
146 
147  for (i = 0; i < MAX_PPS_COUNT; i++) {
148  if (ps.pps_list[i]) {
149  pps = (const PPS*)ps.pps_list[i]->data;
150  break;
151  }
152  }
153 
154  if (pps) {
155  if (ps.sps_list[pps->sps_id]) {
156  sps = (const SPS*)ps.sps_list[pps->sps_id]->data;
157  }
158  }
159 
160  if (pps && sps) {
161  uint8_t *data = NULL;
162  int data_size = 0;
163 
164  avctx->profile = ff_h264_get_profile(sps);
165  avctx->level = sps->level_idc;
166 
167  if ((ret = h2645_ps_to_nalu(sps->data, sps->data_size, &data, &data_size)) < 0) {
168  goto done;
169  }
170  ff_AMediaFormat_setBuffer(format, "csd-0", (void*)data, data_size);
171  av_freep(&data);
172 
173  if ((ret = h2645_ps_to_nalu(pps->data, pps->data_size, &data, &data_size)) < 0) {
174  goto done;
175  }
176  ff_AMediaFormat_setBuffer(format, "csd-1", (void*)data, data_size);
177  av_freep(&data);
178  } else {
179  const int warn = is_avc && (avctx->codec_tag == MKTAG('a','v','c','1') ||
180  avctx->codec_tag == MKTAG('a','v','c','2'));
181  av_log(avctx, warn ? AV_LOG_WARNING : AV_LOG_DEBUG,
182  "Could not extract PPS/SPS from extradata\n");
183  ret = 0;
184  }
185 
186 done:
187  ff_h264_ps_uninit(&ps);
188 
189  return ret;
190 }
191 #endif
192 
193 #if CONFIG_HEVC_MEDIACODEC_DECODER
194 static int hevc_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
195 {
196  int i;
197  int ret;
198 
199  HEVCParamSets ps;
200  HEVCSEI sei;
201 
202  const HEVCVPS *vps = NULL;
203  const HEVCPPS *pps = NULL;
204  const HEVCSPS *sps = NULL;
205  int is_nalff = 0;
206  int nal_length_size = 0;
207 
208  uint8_t *vps_data = NULL;
209  uint8_t *sps_data = NULL;
210  uint8_t *pps_data = NULL;
211  int vps_data_size = 0;
212  int sps_data_size = 0;
213  int pps_data_size = 0;
214 
215  memset(&ps, 0, sizeof(ps));
216  memset(&sei, 0, sizeof(sei));
217 
219  &ps, &sei, &is_nalff, &nal_length_size, 0, 1, avctx);
220  if (ret < 0) {
221  goto done;
222  }
223 
224  for (i = 0; i < HEVC_MAX_VPS_COUNT; i++) {
225  if (ps.vps_list[i]) {
226  vps = (const HEVCVPS*)ps.vps_list[i]->data;
227  break;
228  }
229  }
230 
231  for (i = 0; i < HEVC_MAX_PPS_COUNT; i++) {
232  if (ps.pps_list[i]) {
233  pps = (const HEVCPPS*)ps.pps_list[i]->data;
234  break;
235  }
236  }
237 
238  if (pps) {
239  if (ps.sps_list[pps->sps_id]) {
240  sps = (const HEVCSPS*)ps.sps_list[pps->sps_id]->data;
241  }
242  }
243 
244  if (vps && pps && sps) {
245  uint8_t *data;
246  int data_size;
247 
248  avctx->profile = sps->ptl.general_ptl.profile_idc;
249  avctx->level = sps->ptl.general_ptl.level_idc;
250 
251  if ((ret = h2645_ps_to_nalu(vps->data, vps->data_size, &vps_data, &vps_data_size)) < 0 ||
252  (ret = h2645_ps_to_nalu(sps->data, sps->data_size, &sps_data, &sps_data_size)) < 0 ||
253  (ret = h2645_ps_to_nalu(pps->data, pps->data_size, &pps_data, &pps_data_size)) < 0) {
254  goto done;
255  }
256 
257  data_size = vps_data_size + sps_data_size + pps_data_size;
258  data = av_mallocz(data_size);
259  if (!data) {
260  ret = AVERROR(ENOMEM);
261  goto done;
262  }
263 
264  memcpy(data , vps_data, vps_data_size);
265  memcpy(data + vps_data_size , sps_data, sps_data_size);
266  memcpy(data + vps_data_size + sps_data_size, pps_data, pps_data_size);
267 
268  ff_AMediaFormat_setBuffer(format, "csd-0", data, data_size);
269 
270  av_freep(&data);
271  } else {
272  const int warn = is_nalff && avctx->codec_tag == MKTAG('h','v','c','1');
273  av_log(avctx, warn ? AV_LOG_WARNING : AV_LOG_DEBUG,
274  "Could not extract VPS/PPS/SPS from extradata\n");
275  ret = 0;
276  }
277 
278 done:
279  ff_hevc_ps_uninit(&ps);
280 
281  av_freep(&vps_data);
282  av_freep(&sps_data);
283  av_freep(&pps_data);
284 
285  return ret;
286 }
287 #endif
288 
289 #if CONFIG_MPEG2_MEDIACODEC_DECODER || \
290  CONFIG_MPEG4_MEDIACODEC_DECODER || \
291  CONFIG_VP8_MEDIACODEC_DECODER || \
292  CONFIG_VP9_MEDIACODEC_DECODER
293 static int common_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
294 {
295  int ret = 0;
296 
297  if (avctx->extradata) {
298  ff_AMediaFormat_setBuffer(format, "csd-0", avctx->extradata, avctx->extradata_size);
299  }
300 
301  return ret;
302 }
303 #endif
304 
306 {
307  int ret;
308  int sdk_int;
309 
310  const char *codec_mime = NULL;
311 
314 
315  if (s->use_ndk_codec < 0)
316  s->use_ndk_codec = !av_jni_get_java_vm(avctx);
317 
318  format = ff_AMediaFormat_new(s->use_ndk_codec);
319  if (!format) {
320  av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
322  goto done;
323  }
324 
325  switch (avctx->codec_id) {
326 #if CONFIG_H264_MEDIACODEC_DECODER
327  case AV_CODEC_ID_H264:
328  codec_mime = "video/avc";
329 
330  ret = h264_set_extradata(avctx, format);
331  if (ret < 0)
332  goto done;
333  break;
334 #endif
335 #if CONFIG_HEVC_MEDIACODEC_DECODER
336  case AV_CODEC_ID_HEVC:
337  codec_mime = "video/hevc";
338 
339  ret = hevc_set_extradata(avctx, format);
340  if (ret < 0)
341  goto done;
342  break;
343 #endif
344 #if CONFIG_MPEG2_MEDIACODEC_DECODER
346  codec_mime = "video/mpeg2";
347 
348  ret = common_set_extradata(avctx, format);
349  if (ret < 0)
350  goto done;
351  break;
352 #endif
353 #if CONFIG_MPEG4_MEDIACODEC_DECODER
354  case AV_CODEC_ID_MPEG4:
355  codec_mime = "video/mp4v-es",
356 
357  ret = common_set_extradata(avctx, format);
358  if (ret < 0)
359  goto done;
360  break;
361 #endif
362 #if CONFIG_VP8_MEDIACODEC_DECODER
363  case AV_CODEC_ID_VP8:
364  codec_mime = "video/x-vnd.on2.vp8";
365 
366  ret = common_set_extradata(avctx, format);
367  if (ret < 0)
368  goto done;
369  break;
370 #endif
371 #if CONFIG_VP9_MEDIACODEC_DECODER
372  case AV_CODEC_ID_VP9:
373  codec_mime = "video/x-vnd.on2.vp9";
374 
375  ret = common_set_extradata(avctx, format);
376  if (ret < 0)
377  goto done;
378  break;
379 #endif
380  default:
381  av_assert0(0);
382  }
383 
384  ff_AMediaFormat_setString(format, "mime", codec_mime);
385  ff_AMediaFormat_setInt32(format, "width", avctx->width);
386  ff_AMediaFormat_setInt32(format, "height", avctx->height);
387 
388  s->ctx = av_mallocz(sizeof(*s->ctx));
389  if (!s->ctx) {
390  av_log(avctx, AV_LOG_ERROR, "Failed to allocate MediaCodecDecContext\n");
391  ret = AVERROR(ENOMEM);
392  goto done;
393  }
394 
395  s->ctx->delay_flush = s->delay_flush;
396  s->ctx->use_ndk_codec = s->use_ndk_codec;
397 
398  if ((ret = ff_mediacodec_dec_init(avctx, s->ctx, codec_mime, format)) < 0) {
399  s->ctx = NULL;
400  goto done;
401  }
402 
403  av_log(avctx, AV_LOG_INFO,
404  "MediaCodec started successfully: codec = %s, ret = %d\n",
405  s->ctx->codec_name, ret);
406 
407  sdk_int = ff_Build_SDK_INT(avctx);
408  if (sdk_int <= 23 &&
409  strcmp(s->ctx->codec_name, "OMX.amlogic.mpeg2.decoder.awesome") == 0) {
410  av_log(avctx, AV_LOG_INFO, "Enabling workaround for %s on API=%d\n",
411  s->ctx->codec_name, sdk_int);
412  s->amlogic_mpeg2_api23_workaround = 1;
413  }
414 
415 done:
416  if (format) {
418  }
419 
420  if (ret < 0) {
422  }
423 
424  return ret;
425 }
426 
428 {
430  int ret;
431  ssize_t index;
432 
433  /* In delay_flush mode, wait until the user has released or rendered
434  all retained frames. */
435  if (s->delay_flush && ff_mediacodec_dec_is_flushing(avctx, s->ctx)) {
436  if (!ff_mediacodec_dec_flush(avctx, s->ctx)) {
437  return AVERROR(EAGAIN);
438  }
439  }
440 
441  /* poll for new frame */
442  ret = ff_mediacodec_dec_receive(avctx, s->ctx, frame, false);
443  if (ret != AVERROR(EAGAIN))
444  return ret;
445 
446  /* feed decoder */
447  while (1) {
448  if (s->ctx->current_input_buffer < 0) {
449  /* poll for input space */
450  index = ff_AMediaCodec_dequeueInputBuffer(s->ctx->codec, 0);
451  if (index < 0) {
452  /* no space, block for an output frame to appear */
453  ret = ff_mediacodec_dec_receive(avctx, s->ctx, frame, true);
454  /* Try again if both input port and output port return EAGAIN.
455  * If no data is consumed and no frame in output, it can make
456  * both avcodec_send_packet() and avcodec_receive_frame()
457  * return EAGAIN, which violate the design.
458  */
459  if (ff_AMediaCodec_infoTryAgainLater(s->ctx->codec, index) &&
460  ret == AVERROR(EAGAIN))
461  continue;
462  return ret;
463  }
464  s->ctx->current_input_buffer = index;
465  }
466 
467  /* try to flush any buffered packet data */
468  if (s->buffered_pkt.size > 0) {
469  ret = ff_mediacodec_dec_send(avctx, s->ctx, &s->buffered_pkt, false);
470  if (ret >= 0) {
471  s->buffered_pkt.size -= ret;
472  s->buffered_pkt.data += ret;
473  if (s->buffered_pkt.size <= 0) {
474  av_packet_unref(&s->buffered_pkt);
475  } else {
476  av_log(avctx, AV_LOG_WARNING,
477  "could not send entire packet in single input buffer (%d < %d)\n",
478  ret, s->buffered_pkt.size+ret);
479  }
480  } else if (ret < 0 && ret != AVERROR(EAGAIN)) {
481  return ret;
482  }
483 
484  if (s->amlogic_mpeg2_api23_workaround && s->buffered_pkt.size <= 0) {
485  /* fallthrough to fetch next packet regardless of input buffer space */
486  } else {
487  /* poll for space again */
488  continue;
489  }
490  }
491 
492  /* fetch new packet or eof */
493  ret = ff_decode_get_packet(avctx, &s->buffered_pkt);
494  if (ret == AVERROR_EOF) {
495  AVPacket null_pkt = { 0 };
496  ret = ff_mediacodec_dec_send(avctx, s->ctx, &null_pkt, true);
497  if (ret < 0)
498  return ret;
499  return ff_mediacodec_dec_receive(avctx, s->ctx, frame, true);
500  } else if (ret == AVERROR(EAGAIN) && s->ctx->current_input_buffer < 0) {
501  return ff_mediacodec_dec_receive(avctx, s->ctx, frame, true);
502  } else if (ret < 0) {
503  return ret;
504  }
505  }
506 
507  return AVERROR(EAGAIN);
508 }
509 
511 {
513 
514  av_packet_unref(&s->buffered_pkt);
515 
516  ff_mediacodec_dec_flush(avctx, s->ctx);
517 }
518 
520  &(const AVCodecHWConfigInternal) {
521  .public = {
525  .device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
526  },
527  .hwaccel = NULL,
528  },
529  NULL
530 };
531 
532 #define OFFSET(x) offsetof(MediaCodecH264DecContext, x)
533 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
535  { "delay_flush", "Delay flush until hw output buffers are returned to the decoder",
536  OFFSET(delay_flush), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VD },
537  { "ndk_codec", "Use MediaCodec from NDK",
538  OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VD },
539  { NULL }
540 };
541 
542 #define DECLARE_MEDIACODEC_VCLASS(short_name) \
543 static const AVClass ff_##short_name##_mediacodec_dec_class = { \
544  .class_name = #short_name "_mediacodec", \
545  .item_name = av_default_item_name, \
546  .option = ff_mediacodec_vdec_options, \
547  .version = LIBAVUTIL_VERSION_INT, \
548 };
549 
550 #define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf) \
551 DECLARE_MEDIACODEC_VCLASS(short_name) \
552 const FFCodec ff_ ## short_name ## _mediacodec_decoder = { \
553  .p.name = #short_name "_mediacodec", \
554  CODEC_LONG_NAME(full_name " Android MediaCodec decoder"), \
555  .p.type = AVMEDIA_TYPE_VIDEO, \
556  .p.id = codec_id, \
557  .p.priv_class = &ff_##short_name##_mediacodec_dec_class, \
558  .priv_data_size = sizeof(MediaCodecH264DecContext), \
559  .init = mediacodec_decode_init, \
560  FF_CODEC_RECEIVE_FRAME_CB(mediacodec_receive_frame), \
561  .flush = mediacodec_decode_flush, \
562  .close = mediacodec_decode_close, \
563  .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, \
564  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE | \
565  FF_CODEC_CAP_SETS_PKT_DTS, \
566  .bsfs = bsf, \
567  .hw_configs = mediacodec_hw_configs, \
568  .p.wrapper_name = "mediacodec", \
569 }; \
570 
571 #if CONFIG_H264_MEDIACODEC_DECODER
572 DECLARE_MEDIACODEC_VDEC(h264, "H.264", AV_CODEC_ID_H264, "h264_mp4toannexb")
573 #endif
574 
575 #if CONFIG_HEVC_MEDIACODEC_DECODER
576 DECLARE_MEDIACODEC_VDEC(hevc, "H.265", AV_CODEC_ID_HEVC, "hevc_mp4toannexb")
577 #endif
578 
579 #if CONFIG_MPEG2_MEDIACODEC_DECODER
581 #endif
582 
583 #if CONFIG_MPEG4_MEDIACODEC_DECODER
585 #endif
586 
587 #if CONFIG_VP8_MEDIACODEC_DECODER
589 #endif
590 
591 #if CONFIG_VP9_MEDIACODEC_DECODER
593 #endif
hwconfig.h
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:422
ff_AMediaFormat_delete
static int ff_AMediaFormat_delete(FFAMediaFormat *format)
Definition: mediacodec_wrapper.h:86
MediaCodecDecContext
Definition: mediacodecdec_common.h:37
ff_decode_get_packet
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
Definition: decode.c:205
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
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
opt.h
ff_h264_ps_uninit
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
Definition: h264_ps.c:264
mediacodec_receive_frame
static int mediacodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: mediacodecdec.c:427
out
FILE * out
Definition: movenc.c:54
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
mediacodec_decode_init
static av_cold int mediacodec_decode_init(AVCodecContext *avctx)
Definition: mediacodecdec.c:305
ff_mediacodec_dec_close
int ff_mediacodec_dec_close(AVCodecContext *avctx, MediaCodecDecContext *s)
Definition: mediacodecdec_common.c:915
out_size
int out_size
Definition: movenc.c:55
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
MediaCodecH264DecContext::buffered_pkt
AVPacket buffered_pkt
Definition: mediacodecdec.c:53
h264_parse.h
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
ff_mediacodec_dec_receive
int ff_mediacodec_dec_receive(AVCodecContext *avctx, MediaCodecDecContext *s, AVFrame *frame, bool wait)
Definition: mediacodecdec_common.c:774
HEVC_MAX_PPS_COUNT
@ HEVC_MAX_PPS_COUNT
Definition: hevc.h:114
internal.h
ff_AMediaFormat_setString
static void ff_AMediaFormat_setString(FFAMediaFormat *format, const char *name, const char *value)
Definition: mediacodec_wrapper.h:136
AVOption
AVOption.
Definition: opt.h:251
data
const char data[16]
Definition: mxf.c:146
AV_HWDEVICE_TYPE_MEDIACODEC
@ AV_HWDEVICE_TYPE_MEDIACODEC
Definition: hwcontext.h:38
ff_mediacodec_dec_is_flushing
int ff_mediacodec_dec_is_flushing(AVCodecContext *avctx, MediaCodecDecContext *s)
Definition: mediacodecdec_common.c:922
ff_AMediaFormat_setInt32
static void ff_AMediaFormat_setInt32(FFAMediaFormat *format, const char *name, int32_t value)
Definition: mediacodec_wrapper.h:121
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
MediaCodecH264DecContext::amlogic_mpeg2_api23_workaround
int amlogic_mpeg2_api23_workaround
Definition: mediacodecdec.c:56
ff_mediacodec_dec_flush
int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s)
Definition: mediacodecdec_common.c:897
ff_AMediaFormat_new
FFAMediaFormat * ff_AMediaFormat_new(int ndk)
Definition: mediacodec_wrapper.c:2484
mediacodecdec_common.h
hevc_parse.h
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:500
ff_Build_SDK_INT
int ff_Build_SDK_INT(AVCodecContext *avctx)
Definition: mediacodec_wrapper.c:2512
ff_AMediaFormat_setBuffer
static void ff_AMediaFormat_setBuffer(FFAMediaFormat *format, const char *name, void *data, size_t size)
Definition: mediacodec_wrapper.h:141
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:256
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
ff_h264_decode_extradata
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:464
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:220
HEVCSEI
Definition: hevc_sei.h:95
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
decode.h
AVCodecHWConfig::pix_fmt
enum AVPixelFormat pix_fmt
For decoders, a hardware pixel format which that decoder may be able to decode to if suitable hardwar...
Definition: codec.h:367
H264ParamSets::sps_list
AVBufferRef * sps_list[MAX_SPS_COUNT]
Definition: h264_ps.h:138
OFFSET
#define OFFSET(x)
Definition: mediacodecdec.c:532
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:408
AV_PIX_FMT_MEDIACODEC
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition: pixfmt.h:313
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:153
ff_hevc_ps_uninit
void ff_hevc_ps_uninit(HEVCParamSets *ps)
Definition: hevc_ps.c:1687
SPS
Sequence parameter set.
Definition: h264_ps.h:45
PPS
Picture parameter set.
Definition: h264_ps.h:105
MAX_PPS_COUNT
#define MAX_PPS_COUNT
Definition: h264_ps.h:39
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
Definition: cbs_h265_syntax_template.c:423
ff_hevc_decode_extradata
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:80
sei
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
Definition: cbs_h264_syntax_template.c:825
AVCodecContext::level
int level
level
Definition: avcodec.h:1676
h264_ps.h
index
int index
Definition: gxfenc.c:89
MediaCodecH264DecContext::use_ndk_codec
int use_ndk_codec
Definition: mediacodecdec.c:58
pps
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Definition: cbs_h264_syntax_template.c:404
codec_internal.h
VD
#define VD
Definition: mediacodecdec.c:533
MediaCodecH264DecContext
Definition: mediacodecdec.c:47
AVCodecHWConfigInternal
Definition: hwconfig.h:29
HEVCParamSets::pps_list
AVBufferRef * pps_list[HEVC_MAX_PPS_COUNT]
Definition: hevc_ps.h:317
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
mediacodec_decode_flush
static void mediacodec_decode_flush(AVCodecContext *avctx)
Definition: mediacodecdec.c:510
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
mediacodec_wrapper.h
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:499
internal.h
common.h
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:226
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:264
AVCodecContext::height
int height
Definition: avcodec.h:571
av_jni_get_java_vm
void * av_jni_get_java_vm(void *log_ctx)
Definition: jni.c:74
MediaCodecH264DecContext::avclass
AVClass * avclass
Definition: mediacodecdec.c:49
ff_AMediaCodec_dequeueInputBuffer
static ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec *codec, int64_t timeoutUs)
Definition: mediacodec_wrapper.h:247
avcodec.h
ret
ret
Definition: filter_design.txt:187
pixfmt.h
ff_h264_get_profile
int ff_h264_get_profile(const SPS *sps)
Compute profile from profile_idc and constraint_set?_flags.
Definition: h264_parse.c:531
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
AV_CODEC_HW_CONFIG_METHOD_AD_HOC
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition: codec.h:355
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
MediaCodecH264DecContext::delay_flush
int delay_flush
Definition: mediacodecdec.c:55
HEVC_MAX_VPS_COUNT
@ HEVC_MAX_VPS_COUNT
Definition: hevc.h:110
DECLARE_MEDIACODEC_VDEC
#define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf)
Definition: mediacodecdec.c:550
AVCodecContext
main external API structure.
Definition: avcodec.h:398
H264ParamSets::pps_list
AVBufferRef * pps_list[MAX_PPS_COUNT]
Definition: h264_ps.h:139
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1550
H264ParamSets
Definition: h264_ps.h:137
HEVCParamSets::sps_list
AVBufferRef * sps_list[HEVC_MAX_SPS_COUNT]
Definition: hevc_ps.h:316
ff_mediacodec_vdec_options
static const AVOption ff_mediacodec_vdec_options[]
Definition: mediacodecdec.c:534
MediaCodecH264DecContext::ctx
MediaCodecDecContext * ctx
Definition: mediacodecdec.c:51
HEVCVPS
Definition: hevc_ps.h:110
HEVCSPS
Definition: hevc_ps.h:140
HEVCPPS
Definition: hevc_ps.h:236
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:423
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:425
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
ff_AMediaCodec_infoTryAgainLater
static int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:277
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:571
ff_mediacodec_dec_send
int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, AVPacket *pkt, bool wait)
Definition: mediacodecdec_common.c:680
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition: codec.h:326
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
mediacodec_hw_configs
static const AVCodecHWConfigInternal *const mediacodec_hw_configs[]
Definition: mediacodecdec.c:519
jni.h
AVCodecHWConfigInternal::public
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition: hwconfig.h:34
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:54
FFAMediaFormat
Definition: mediacodec_wrapper.h:63
mediacodec_decode_close
static av_cold int mediacodec_decode_close(AVCodecContext *avctx)
Definition: mediacodecdec.c:61
HEVCParamSets::vps_list
AVBufferRef * vps_list[HEVC_MAX_VPS_COUNT]
Definition: hevc_ps.h:315
ff_mediacodec_dec_init
int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, const char *mime, FFAMediaFormat *format)
Definition: mediacodecdec_common.c:564
HEVCParamSets
Definition: hevc_ps.h:314