FFmpeg
Loading...
Searching...
No Matches
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/mem.h"
31#include "libavutil/opt.h"
33#include "libavutil/pixfmt.h"
34#include "libavutil/internal.h"
35
36#include "avcodec.h"
37#include "codec_internal.h"
38#include "decode.h"
39#include "h264_parse.h"
40#include "h264_ps.h"
41#include "hevc/parse.h"
42#include "hwconfig.h"
43#include "internal.h"
44#include "jni.h"
45#include "mediacodec_wrapper.h"
47
63
65{
67
68 ff_mediacodec_dec_close(avctx, s->ctx);
69 s->ctx = NULL;
70
71 av_packet_unref(&s->buffered_pkt);
72
73 return 0;
74}
75
76#if CONFIG_H264_MEDIACODEC_DECODER || CONFIG_HEVC_MEDIACODEC_DECODER
77static int h2645_ps_to_nalu(const uint8_t *src, int src_size, uint8_t **out, int *out_size)
78{
79 int i;
80 int ret = 0;
81 uint8_t *p = NULL;
82 static const uint8_t nalu_header[] = { 0x00, 0x00, 0x00, 0x01 };
83
84 if (!out || !out_size) {
85 return AVERROR(EINVAL);
86 }
87
88 p = av_malloc(sizeof(nalu_header) + src_size);
89 if (!p) {
90 return AVERROR(ENOMEM);
91 }
92
93 *out = p;
94 *out_size = sizeof(nalu_header) + src_size;
95
96 memcpy(p, nalu_header, sizeof(nalu_header));
97 memcpy(p + sizeof(nalu_header), src, src_size);
98
99 /* Escape 0x00, 0x00, 0x0{0-3} pattern */
100 for (i = 4; i < *out_size; i++) {
101 if (i < *out_size - 3 &&
102 p[i + 0] == 0 &&
103 p[i + 1] == 0 &&
104 p[i + 2] <= 3) {
105 uint8_t *new;
106
107 *out_size += 1;
108 new = av_realloc(*out, *out_size);
109 if (!new) {
110 ret = AVERROR(ENOMEM);
111 goto done;
112 }
113 *out = p = new;
114
115 i = i + 2;
116 memmove(p + i + 1, p + i, *out_size - (i + 1));
117 p[i] = 0x03;
118 }
119 }
120done:
121 if (ret < 0) {
122 av_freep(out);
123 *out_size = 0;
124 }
125
126 return ret;
127}
128#endif
129
130#if CONFIG_H264_MEDIACODEC_DECODER
131static int h264_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
132{
133 int i;
134 int ret;
135
136 H264ParamSets ps = {0};
137 const PPS *pps = NULL;
138 const SPS *sps = NULL;
139 int is_avc = 0;
140 int nal_length_size = 0;
141
143 &ps, &is_avc, &nal_length_size, 0, avctx);
144 if (ret < 0) {
145 goto done;
146 }
147
148 for (i = 0; i < MAX_PPS_COUNT; i++) {
149 if (ps.pps_list[i]) {
150 pps = ps.pps_list[i];
151 break;
152 }
153 }
154
155 if (pps) {
156 if (ps.sps_list[pps->sps_id]) {
157 sps = ps.sps_list[pps->sps_id];
158 }
159 }
160
161 if (pps && sps) {
162 uint8_t *data = NULL;
163 int data_size = 0;
164
166 avctx->level = sps->level_idc;
167
168 if ((ret = h2645_ps_to_nalu(sps->data, sps->data_size, &data, &data_size)) < 0) {
169 goto done;
170 }
171 ff_AMediaFormat_setBuffer(format, "csd-0", (void*)data, data_size);
172 av_freep(&data);
173
174 if ((ret = h2645_ps_to_nalu(pps->data, pps->data_size, &data, &data_size)) < 0) {
175 goto done;
176 }
177 ff_AMediaFormat_setBuffer(format, "csd-1", (void*)data, data_size);
178 av_freep(&data);
179 } else {
180 const int warn = is_avc && (avctx->codec_tag == MKTAG('a','v','c','1') ||
181 avctx->codec_tag == MKTAG('a','v','c','2'));
182 av_log(avctx, warn ? AV_LOG_WARNING : AV_LOG_DEBUG,
183 "Could not extract PPS/SPS from extradata\n");
184 ret = 0;
185 }
186
187done:
189
190 return ret;
191}
192#endif
193
194#if CONFIG_HEVC_MEDIACODEC_DECODER
195static int hevc_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
196{
197 int i;
198 int ret;
199
200 HEVCParamSets ps = {0};
201 HEVCSEI sei = {0};
202
203 const HEVCVPS *vps = NULL;
204 const HEVCPPS *pps = NULL;
205 const HEVCSPS *sps = NULL;
206 int is_nalff = 0;
207 int nal_length_size = 0;
208
209 uint8_t *vps_data = NULL;
210 uint8_t *sps_data = NULL;
211 uint8_t *pps_data = NULL;
212 int vps_data_size = 0;
213 int sps_data_size = 0;
214 int pps_data_size = 0;
215
217 &ps, &sei, &is_nalff, &nal_length_size, 0, 1, avctx);
218 if (ret < 0) {
219 goto done;
220 }
221
222 for (i = 0; i < HEVC_MAX_VPS_COUNT; i++) {
223 if (ps.vps_list[i]) {
224 vps = ps.vps_list[i];
225 break;
226 }
227 }
228
229 for (i = 0; i < HEVC_MAX_PPS_COUNT; i++) {
230 if (ps.pps_list[i]) {
231 pps = ps.pps_list[i];
232 break;
233 }
234 }
235
236 if (pps) {
237 if (ps.sps_list[pps->sps_id]) {
238 sps = ps.sps_list[pps->sps_id];
239 }
240 }
241
242 if (vps && pps && sps) {
243 uint8_t *data;
244 int data_size;
245
246 avctx->profile = sps->ptl.general_ptl.profile_idc;
247 avctx->level = sps->ptl.general_ptl.level_idc;
248
249 if ((ret = h2645_ps_to_nalu(vps->data, vps->data_size, &vps_data, &vps_data_size)) < 0 ||
250 (ret = h2645_ps_to_nalu(sps->data, sps->data_size, &sps_data, &sps_data_size)) < 0 ||
251 (ret = h2645_ps_to_nalu(pps->data, pps->data_size, &pps_data, &pps_data_size)) < 0) {
252 goto done;
253 }
254
255 data_size = vps_data_size + sps_data_size + pps_data_size;
256 data = av_mallocz(data_size);
257 if (!data) {
258 ret = AVERROR(ENOMEM);
259 goto done;
260 }
261
262 memcpy(data , vps_data, vps_data_size);
263 memcpy(data + vps_data_size , sps_data, sps_data_size);
264 memcpy(data + vps_data_size + sps_data_size, pps_data, pps_data_size);
265
266 ff_AMediaFormat_setBuffer(format, "csd-0", data, data_size);
267
268 av_freep(&data);
269 } else {
270 const int warn = is_nalff && avctx->codec_tag == MKTAG('h','v','c','1');
271 av_log(avctx, warn ? AV_LOG_WARNING : AV_LOG_DEBUG,
272 "Could not extract VPS/PPS/SPS from extradata\n");
273 ret = 0;
274 }
275
276done:
278
279 av_freep(&vps_data);
280 av_freep(&sps_data);
281 av_freep(&pps_data);
282
283 return ret;
284}
285#endif
286
287#if CONFIG_MPEG2_MEDIACODEC_DECODER || \
288 CONFIG_MPEG4_MEDIACODEC_DECODER || \
289 CONFIG_VP8_MEDIACODEC_DECODER || \
290 CONFIG_VP9_MEDIACODEC_DECODER || \
291 CONFIG_AV1_MEDIACODEC_DECODER || \
292 CONFIG_AAC_MEDIACODEC_DECODER || \
293 CONFIG_AMRNB_MEDIACODEC_DECODER || \
294 CONFIG_AMRWB_MEDIACODEC_DECODER || \
295 CONFIG_MP3_MEDIACODEC_DECODER
296static int common_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
297{
298 int ret = 0;
299
300 if (avctx->extradata) {
302 }
303
304 return ret;
305}
306#endif
307
309{
310 int ret;
311 int sdk_int;
312
313 const char *codec_mime = NULL;
314
316 MediaCodecContext *s = avctx->priv_data;
317
318 if (s->use_ndk_codec < 0)
319 s->use_ndk_codec = !av_jni_get_java_vm(avctx);
320
321 format = ff_AMediaFormat_new(s->use_ndk_codec);
322 if (!format) {
323 av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
324 ret = AVERROR_EXTERNAL;
325 goto done;
326 }
327
328 switch (avctx->codec_id) {
329#if CONFIG_AV1_MEDIACODEC_DECODER
330 case AV_CODEC_ID_AV1:
331 codec_mime = "video/av01";
332
333 ret = common_set_extradata(avctx, format);
334 if (ret < 0)
335 goto done;
336 break;
337#endif
338#if CONFIG_H264_MEDIACODEC_DECODER
339 case AV_CODEC_ID_H264:
340 codec_mime = "video/avc";
341
342 ret = h264_set_extradata(avctx, format);
343 if (ret < 0)
344 goto done;
345 break;
346#endif
347#if CONFIG_HEVC_MEDIACODEC_DECODER
348 case AV_CODEC_ID_HEVC:
349 codec_mime = "video/hevc";
350
351 ret = hevc_set_extradata(avctx, format);
352 if (ret < 0)
353 goto done;
354 break;
355#endif
356#if CONFIG_MPEG2_MEDIACODEC_DECODER
358 codec_mime = "video/mpeg2";
359
360 ret = common_set_extradata(avctx, format);
361 if (ret < 0)
362 goto done;
363 break;
364#endif
365#if CONFIG_MPEG4_MEDIACODEC_DECODER
367 codec_mime = "video/mp4v-es",
368
369 ret = common_set_extradata(avctx, format);
370 if (ret < 0)
371 goto done;
372 break;
373#endif
374#if CONFIG_VP8_MEDIACODEC_DECODER
375 case AV_CODEC_ID_VP8:
376 codec_mime = "video/x-vnd.on2.vp8";
377
378 ret = common_set_extradata(avctx, format);
379 if (ret < 0)
380 goto done;
381 break;
382#endif
383#if CONFIG_VP9_MEDIACODEC_DECODER
384 case AV_CODEC_ID_VP9:
385 codec_mime = "video/x-vnd.on2.vp9";
386
387 ret = common_set_extradata(avctx, format);
388 if (ret < 0)
389 goto done;
390 break;
391#endif
392#if CONFIG_AAC_MEDIACODEC_DECODER
393 case AV_CODEC_ID_AAC:
394 codec_mime = "audio/mp4a-latm";
395
396 ret = common_set_extradata(avctx, format);
397 if (ret < 0)
398 goto done;
399 break;
400#endif
401#if CONFIG_AMRNB_MEDIACODEC_DECODER
403 codec_mime = "audio/3gpp";
404
405 ret = common_set_extradata(avctx, format);
406 if (ret < 0)
407 goto done;
408 break;
409#endif
410#if CONFIG_AMRWB_MEDIACODEC_DECODER
412 codec_mime = "audio/amr-wb";
413
414 ret = common_set_extradata(avctx, format);
415 if (ret < 0)
416 goto done;
417 break;
418#endif
419#if CONFIG_MP3_MEDIACODEC_DECODER
420 case AV_CODEC_ID_MP3:
421 codec_mime = "audio/mpeg";
422
423 ret = common_set_extradata(avctx, format);
424 if (ret < 0)
425 goto done;
426 break;
427#endif
428 default:
429 av_assert0(0);
430 }
431
432 ff_AMediaFormat_setString(format, "mime", codec_mime);
433
434 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
435 ff_AMediaFormat_setInt32(format, "width", avctx->width);
436 ff_AMediaFormat_setInt32(format, "height", avctx->height);
437 } else {
438 ff_AMediaFormat_setInt32(format, "channel-count", avctx->ch_layout.nb_channels);
439 ff_AMediaFormat_setInt32(format, "sample-rate", avctx->sample_rate);
440 }
441 if (s->operating_rate > 0)
442 ff_AMediaFormat_setInt32(format, "operating-rate", s->operating_rate);
443
444 s->ctx = av_mallocz(sizeof(*s->ctx));
445 if (!s->ctx) {
446 av_log(avctx, AV_LOG_ERROR, "Failed to allocate MediaCodecDecContext\n");
447 ret = AVERROR(ENOMEM);
448 goto done;
449 }
450
451 s->ctx->delay_flush = s->delay_flush;
452 s->ctx->use_ndk_codec = s->use_ndk_codec;
453
454 if ((ret = ff_mediacodec_dec_init(avctx, s->ctx, codec_mime, format)) < 0) {
455 s->ctx = NULL;
456 goto done;
457 }
458
459 av_log(avctx, AV_LOG_INFO,
460 "MediaCodec started successfully: codec = %s, ret = %d\n",
461 s->ctx->codec_name, ret);
462
463 sdk_int = ff_Build_SDK_INT(avctx);
464 /* ff_Build_SDK_INT can fail when target API < 24 and JVM isn't available.
465 * If we don't check sdk_int > 0, the workaround might be enabled by
466 * mistake.
467 * JVM is required to make the workaround works reliably. On the other hand,
468 * missing a workaround should not be a serious issue, we do as best we can.
469 */
470 if (sdk_int > 0 && sdk_int <= 23 &&
471 strcmp(s->ctx->codec_name, "OMX.amlogic.mpeg2.decoder.awesome") == 0) {
472 av_log(avctx, AV_LOG_INFO, "Enabling workaround for %s on API=%d\n",
473 s->ctx->codec_name, sdk_int);
474 s->amlogic_mpeg2_api23_workaround = 1;
475 }
476
477done:
478 if (format) {
480 }
481
482 if (ret < 0) {
484 }
485
486 return ret;
487}
488
490{
491 MediaCodecContext *s = avctx->priv_data;
492 int ret;
493 ssize_t index;
494
495 /* In delay_flush mode, wait until the user has released or rendered
496 all retained frames. */
497 if (s->delay_flush && ff_mediacodec_dec_is_flushing(avctx, s->ctx)) {
498 if (!ff_mediacodec_dec_flush(avctx, s->ctx)) {
499 return AVERROR(EAGAIN);
500 }
501 }
502
503 /* poll for new frame */
504 ret = ff_mediacodec_dec_receive(avctx, s->ctx, frame, false);
505 if (ret != AVERROR(EAGAIN))
506 return ret;
507
508 /* feed decoder */
509 while (1) {
510 if (s->ctx->current_input_buffer < 0 && !s->ctx->draining) {
511 /* poll for input space */
512 index = ff_AMediaCodec_dequeueInputBuffer(s->ctx->codec, 0);
513 if (index < 0) {
514 /* no space, block for an output frame to appear */
515 ret = ff_mediacodec_dec_receive(avctx, s->ctx, frame, true);
516 /* Try again if both input port and output port return EAGAIN.
517 * If no data is consumed and no frame in output, it can make
518 * both avcodec_send_packet() and avcodec_receive_frame()
519 * return EAGAIN, which violate the design.
520 */
521 if (ff_AMediaCodec_infoTryAgainLater(s->ctx->codec, index) &&
522 ret == AVERROR(EAGAIN))
523 continue;
524 return ret;
525 }
526 s->ctx->current_input_buffer = index;
527 }
528
529 /* try to flush any buffered packet data */
530 if (s->buffered_pkt.size > 0) {
531 ret = ff_mediacodec_dec_send(avctx, s->ctx, &s->buffered_pkt, false);
532 if (ret >= 0) {
533 s->buffered_pkt.size -= ret;
534 s->buffered_pkt.data += ret;
535 if (s->buffered_pkt.size <= 0) {
536 av_packet_unref(&s->buffered_pkt);
537 } else {
538 av_log(avctx, AV_LOG_WARNING,
539 "could not send entire packet in single input buffer (%d < %d)\n",
540 ret, s->buffered_pkt.size+ret);
541 }
542 } else if (ret < 0 && ret != AVERROR(EAGAIN)) {
543 return ret;
544 }
545
546 if (s->amlogic_mpeg2_api23_workaround && s->buffered_pkt.size <= 0) {
547 /* fallthrough to fetch next packet regardless of input buffer space */
548 } else {
549 /* poll for space again */
550 continue;
551 }
552 }
553
554 /* fetch new packet or eof */
555 ret = ff_decode_get_packet(avctx, &s->buffered_pkt);
556 if (ret == AVERROR_EOF) {
557 AVPacket null_pkt = { 0 };
558 ret = ff_mediacodec_dec_send(avctx, s->ctx, &null_pkt, true);
559 if (ret < 0)
560 return ret;
561 return ff_mediacodec_dec_receive(avctx, s->ctx, frame, true);
562 } else if (ret == AVERROR(EAGAIN) && s->ctx->current_input_buffer < 0) {
563 return ff_mediacodec_dec_receive(avctx, s->ctx, frame, true);
564 } else if (ret < 0) {
565 return ret;
566 }
567 }
568
569 return AVERROR(EAGAIN);
570}
571
573{
574 MediaCodecContext *s = avctx->priv_data;
575
576 av_packet_unref(&s->buffered_pkt);
577
578 ff_mediacodec_dec_flush(avctx, s->ctx);
579}
580
582 &(const AVCodecHWConfigInternal) {
583 .public = {
584 .pix_fmt = AV_PIX_FMT_MEDIACODEC,
587 .device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
588 },
589 .hwaccel = NULL,
590 },
591 NULL
592};
593
594#define OFFSET(x) offsetof(MediaCodecContext, x)
595#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
597 { "delay_flush", "Delay flush until hw output buffers are returned to the decoder",
598 OFFSET(delay_flush), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VD },
599 { "ndk_codec", "Use MediaCodec from NDK",
600 OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VD },
601 { "operating_rate", "The desired operating rate that the codec will need to operate at, zero for unspecified",
602 OFFSET(operating_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VD },
603 { NULL }
604};
605
606#define DECLARE_MEDIACODEC_VCLASS(short_name) \
607static const AVClass ff_##short_name##_mediacodec_dec_class = { \
608 .class_name = #short_name "_mediacodec", \
609 .item_name = av_default_item_name, \
610 .option = ff_mediacodec_vdec_options, \
611 .version = LIBAVUTIL_VERSION_INT, \
612};
613
614#define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf) \
615DECLARE_MEDIACODEC_VCLASS(short_name) \
616const FFCodec ff_ ## short_name ## _mediacodec_decoder = { \
617 .p.name = #short_name "_mediacodec", \
618 CODEC_LONG_NAME(full_name " Android MediaCodec decoder"), \
619 .p.type = AVMEDIA_TYPE_VIDEO, \
620 .p.id = codec_id, \
621 .p.priv_class = &ff_##short_name##_mediacodec_dec_class, \
622 .priv_data_size = sizeof(MediaCodecContext), \
623 .init = mediacodec_decode_init, \
624 FF_CODEC_RECEIVE_FRAME_CB(mediacodec_receive_frame), \
625 .flush = mediacodec_decode_flush, \
626 .close = mediacodec_decode_close, \
627 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, \
628 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \
629 .bsfs = bsf, \
630 .hw_configs = mediacodec_hw_configs, \
631 .p.wrapper_name = "mediacodec", \
632}; \
633
634#if CONFIG_H264_MEDIACODEC_DECODER
635DECLARE_MEDIACODEC_VDEC(h264, "H.264", AV_CODEC_ID_H264, "h264_mp4toannexb")
636#endif
637
638#if CONFIG_HEVC_MEDIACODEC_DECODER
639DECLARE_MEDIACODEC_VDEC(hevc, "H.265", AV_CODEC_ID_HEVC, "hevc_mp4toannexb")
640#endif
641
642#if CONFIG_MPEG2_MEDIACODEC_DECODER
644#endif
645
646#if CONFIG_MPEG4_MEDIACODEC_DECODER
648#endif
649
650#if CONFIG_VP8_MEDIACODEC_DECODER
652#endif
653
654#if CONFIG_VP9_MEDIACODEC_DECODER
656#endif
657
658#if CONFIG_AV1_MEDIACODEC_DECODER
660#endif
661
662#define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
664 { "ndk_codec", "Use MediaCodec from NDK",
665 OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, AD },
666 { "operating_rate", "The desired operating rate that the codec will need to operate at, zero for unspecified",
667 OFFSET(operating_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AD },
668 { NULL }
669};
670
671#define DECLARE_MEDIACODEC_ACLASS(short_name) \
672static const AVClass ff_##short_name##_mediacodec_dec_class = { \
673 .class_name = #short_name "_mediacodec", \
674 .item_name = av_default_item_name, \
675 .option = ff_mediacodec_adec_options, \
676 .version = LIBAVUTIL_VERSION_INT, \
677};
678
679#define DECLARE_MEDIACODEC_ADEC(short_name, full_name, codec_id, bsf) \
680DECLARE_MEDIACODEC_ACLASS(short_name) \
681const FFCodec ff_ ## short_name ## _mediacodec_decoder = { \
682 .p.name = #short_name "_mediacodec", \
683 CODEC_LONG_NAME(full_name " Android MediaCodec decoder"), \
684 .p.type = AVMEDIA_TYPE_AUDIO, \
685 .p.id = codec_id, \
686 .p.priv_class = &ff_##short_name##_mediacodec_dec_class, \
687 .priv_data_size = sizeof(MediaCodecContext), \
688 .init = mediacodec_decode_init, \
689 FF_CODEC_RECEIVE_FRAME_CB(mediacodec_receive_frame), \
690 .flush = mediacodec_decode_flush, \
691 .close = mediacodec_decode_close, \
692 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE, \
693 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \
694 .bsfs = bsf, \
695 .p.wrapper_name = "mediacodec", \
696}; \
697
698#if CONFIG_AAC_MEDIACODEC_DECODER
699DECLARE_MEDIACODEC_ADEC(aac, "AAC", AV_CODEC_ID_AAC, "aac_adtstoasc")
700#endif
701
702#if CONFIG_AMRNB_MEDIACODEC_DECODER
704#endif
705
706#if CONFIG_AMRWB_MEDIACODEC_DECODER
708#endif
709
710#if CONFIG_MP3_MEDIACODEC_DECODER
712#endif
static const char *const format[]
Definition af_aiir.c:444
#define VD
Definition amfdec.c:787
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static int FUNC sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
#define s(width, name)
Definition cbs_vp9.c:198
common internal and external API header
#define NULL
Definition coverity.c:32
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
Definition decode.c:254
static AVFrame * frame
uint64_t pps
Definition dovi_rpuenc.c:36
#define AD
Definition evrcdec.c:920
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition codec.h:311
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition codec.h:282
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_AV1
Definition codec_id.h:275
@ AV_CODEC_ID_VP8
Definition codec_id.h:190
@ AV_CODEC_ID_AMR_NB
Definition codec_id.h:434
@ AV_CODEC_ID_HEVC
Definition codec_id.h:223
@ AV_CODEC_ID_AAC
Definition codec_id.h:455
@ AV_CODEC_ID_AMR_WB
Definition codec_id.h:435
@ AV_CODEC_ID_MPEG4
Definition codec_id.h:62
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition codec_id.h:454
@ AV_CODEC_ID_VP9
Definition codec_id.h:217
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition codec_id.h:52
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:434
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition error.h:59
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
int index
Definition gxfenc.c:90
int ff_h264_get_profile(const SPS *sps)
Compute profile from profile_idc and constraint_set?_flags.
Definition h264_parse.c:533
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:466
H.264 decoder/parser shared code.
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
Definition h264_ps.c:270
H.264 parameter set handling.
#define MAX_PPS_COUNT
Definition h264_ps.h:38
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 parse.c:79
H.265 parser code.
void ff_hevc_ps_uninit(HEVCParamSets *ps)
Definition ps.c:2473
@ AV_HWDEVICE_TYPE_MEDIACODEC
Definition hwcontext.h:38
void * av_jni_get_java_vm(void *log_ctx)
Definition jni.c:75
@ HEVC_MAX_PPS_COUNT
Definition hevc.h:117
@ HEVC_MAX_VPS_COUNT
Definition hevc.h:113
common internal api header.
#define av_cold
Definition attributes.h:117
common internal API header
#define MKTAG(a, b, c, d)
Definition macros.h:55
FFAMediaFormat * ff_AMediaFormat_new(int ndk)
int ff_Build_SDK_INT(AVCodecContext *avctx)
static void ff_AMediaFormat_setBuffer(FFAMediaFormat *format, const char *name, void *data, size_t size)
static void ff_AMediaFormat_setString(FFAMediaFormat *format, const char *name, const char *value)
static void ff_AMediaFormat_setInt32(FFAMediaFormat *format, const char *name, int32_t value)
static int ff_AMediaFormat_delete(FFAMediaFormat *format)
static ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec *codec, int64_t timeoutUs)
static int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
static const AVCodecHWConfigInternal *const mediacodec_hw_configs[]
static const AVOption ff_mediacodec_vdec_options[]
static av_cold int mediacodec_decode_close(AVCodecContext *avctx)
static const AVOption ff_mediacodec_adec_options[]
static av_cold int mediacodec_decode_init(AVCodecContext *avctx)
#define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf)
#define DECLARE_MEDIACODEC_ADEC(short_name, full_name, codec_id, bsf)
static void mediacodec_decode_flush(AVCodecContext *avctx)
static int mediacodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
#define OFFSET(x)
int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, AVPacket *pkt, bool wait)
int ff_mediacodec_dec_flush(AVCodecContext *avctx, MediaCodecDecContext *s)
int ff_mediacodec_dec_receive(AVCodecContext *avctx, MediaCodecDecContext *s, AVFrame *frame, bool wait)
int ff_mediacodec_dec_close(AVCodecContext *avctx, MediaCodecDecContext *s)
int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, const char *mime, FFAMediaFormat *format)
int ff_mediacodec_dec_is_flushing(AVCodecContext *avctx, MediaCodecDecContext *s)
Memory handling functions.
const char data[16]
Definition mxf.c:149
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
#define av_realloc(p, s)
Definition ops_static.c:54
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
pixel format definitions
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition pixfmt.h:316
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
int width
picture width / height.
Definition avcodec.h:604
AVChannelLayout ch_layout
Audio channel layout.
Definition avcodec.h:1055
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition avcodec.h:468
enum AVMediaType codec_type
Definition avcodec.h:451
int level
Encoding level descriptor.
Definition avcodec.h:1646
int profile
profile
Definition avcodec.h:1636
int sample_rate
samples per second
Definition avcodec.h:1040
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
enum AVCodecID codec_id
Definition avcodec.h:453
int extradata_size
Definition avcodec.h:527
void * priv_data
Definition avcodec.h:470
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
const PPS * pps_list[MAX_PPS_COUNT]
RefStruct references.
Definition h264_ps.h:146
const SPS * sps_list[MAX_SPS_COUNT]
RefStruct references.
Definition h264_ps.h:145
Definition ps.h:371
const HEVCVPS * vps_list[HEVC_MAX_VPS_COUNT]
RefStruct references.
Definition ps.h:509
const HEVCPPS * pps_list[HEVC_MAX_PPS_COUNT]
RefStruct references.
Definition ps.h:511
const HEVCSPS * sps_list[HEVC_MAX_SPS_COUNT]
RefStruct references.
Definition ps.h:510
Definition sei.h:106
Definition ps.h:252
Definition ps.h:168
MediaCodecDecContext * ctx
int amlogic_mpeg2_api23_workaround
Picture parameter set.
Definition h264_ps.h:110
Sequence parameter set.
Definition h264_ps.h:44
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
static FILE * out
Definition movenc.c:55
static int out_size
Definition movenc.c:56