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 "hevc/sei.h"
43#include "hwconfig.h"
44#include "internal.h"
45#include "jni.h"
46#include "mediacodec_wrapper.h"
48
64
66{
68
69 ff_mediacodec_dec_close(avctx, s->ctx);
70 s->ctx = NULL;
71
72 av_packet_unref(&s->buffered_pkt);
73
74 return 0;
75}
76
77#if CONFIG_H264_MEDIACODEC_DECODER || CONFIG_HEVC_MEDIACODEC_DECODER
78static int h2645_ps_to_nalu(const uint8_t *src, int src_size, uint8_t **out, int *out_size)
79{
80 int i;
81 int ret = 0;
82 uint8_t *p = NULL;
83 static const uint8_t nalu_header[] = { 0x00, 0x00, 0x00, 0x01 };
84
85 if (!out || !out_size) {
86 return AVERROR(EINVAL);
87 }
88
89 p = av_malloc(sizeof(nalu_header) + src_size);
90 if (!p) {
91 return AVERROR(ENOMEM);
92 }
93
94 *out = p;
95 *out_size = sizeof(nalu_header) + src_size;
96
97 memcpy(p, nalu_header, sizeof(nalu_header));
98 memcpy(p + sizeof(nalu_header), src, src_size);
99
100 /* Escape 0x00, 0x00, 0x0{0-3} pattern */
101 for (i = 4; i < *out_size; i++) {
102 if (i < *out_size - 3 &&
103 p[i + 0] == 0 &&
104 p[i + 1] == 0 &&
105 p[i + 2] <= 3) {
106 uint8_t *new;
107
108 *out_size += 1;
109 new = av_realloc(*out, *out_size);
110 if (!new) {
111 ret = AVERROR(ENOMEM);
112 goto done;
113 }
114 *out = p = new;
115
116 i = i + 2;
117 memmove(p + i + 1, p + i, *out_size - (i + 1));
118 p[i] = 0x03;
119 }
120 }
121done:
122 if (ret < 0) {
123 av_freep(out);
124 *out_size = 0;
125 }
126
127 return ret;
128}
129#endif
130
131#if CONFIG_H264_MEDIACODEC_DECODER
132static int h264_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
133{
134 int i;
135 int ret;
136
137 H264ParamSets ps = {0};
138 const PPS *pps = NULL;
139 const SPS *sps = NULL;
140 int is_avc = 0;
141 int nal_length_size = 0;
142
144 &ps, &is_avc, &nal_length_size, 0, avctx);
145 if (ret < 0) {
146 goto done;
147 }
148
149 for (i = 0; i < MAX_PPS_COUNT; i++) {
150 if (ps.pps_list[i]) {
151 pps = ps.pps_list[i];
152 break;
153 }
154 }
155
156 if (pps) {
157 if (ps.sps_list[pps->sps_id]) {
158 sps = ps.sps_list[pps->sps_id];
159 }
160 }
161
162 if (pps && sps) {
163 uint8_t *data = NULL;
164 int data_size = 0;
165
167 avctx->level = sps->level_idc;
168
169 if ((ret = h2645_ps_to_nalu(sps->data, sps->data_size, &data, &data_size)) < 0) {
170 goto done;
171 }
172 ff_AMediaFormat_setBuffer(format, "csd-0", (void*)data, data_size);
173 av_freep(&data);
174
175 if ((ret = h2645_ps_to_nalu(pps->data, pps->data_size, &data, &data_size)) < 0) {
176 goto done;
177 }
178 ff_AMediaFormat_setBuffer(format, "csd-1", (void*)data, data_size);
179 av_freep(&data);
180 } else {
181 const int warn = is_avc && (avctx->codec_tag == MKTAG('a','v','c','1') ||
182 avctx->codec_tag == MKTAG('a','v','c','2'));
183 av_log(avctx, warn ? AV_LOG_WARNING : AV_LOG_DEBUG,
184 "Could not extract PPS/SPS from extradata\n");
185 ret = 0;
186 }
187
188done:
190
191 return ret;
192}
193#endif
194
195#if CONFIG_HEVC_MEDIACODEC_DECODER
196static int hevc_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
197{
198 int i;
199 int ret;
200
201 HEVCParamSets ps = {0};
202 HEVCSEI sei = {0};
203
204 const HEVCVPS *vps = NULL;
205 const HEVCPPS *pps = NULL;
206 const HEVCSPS *sps = NULL;
207 int is_nalff = 0;
208 int nal_length_size = 0;
209
210 uint8_t *vps_data = NULL;
211 uint8_t *sps_data = NULL;
212 uint8_t *pps_data = NULL;
213 int vps_data_size = 0;
214 int sps_data_size = 0;
215 int pps_data_size = 0;
216
218 &ps, &sei, &is_nalff, &nal_length_size, 0, 1, avctx);
219 if (ret < 0) {
220 goto done;
221 }
222
223 for (i = 0; i < HEVC_MAX_VPS_COUNT; i++) {
224 if (ps.vps_list[i]) {
225 vps = ps.vps_list[i];
226 break;
227 }
228 }
229
230 for (i = 0; i < HEVC_MAX_PPS_COUNT; i++) {
231 if (ps.pps_list[i]) {
232 pps = ps.pps_list[i];
233 break;
234 }
235 }
236
237 if (pps) {
238 if (ps.sps_list[pps->sps_id]) {
239 sps = ps.sps_list[pps->sps_id];
240 }
241 }
242
243 if (vps && pps && sps) {
244 uint8_t *data;
245 int data_size;
246
247 avctx->profile = sps->ptl.general_ptl.profile_idc;
248 avctx->level = sps->ptl.general_ptl.level_idc;
249
250 if ((ret = h2645_ps_to_nalu(vps->data, vps->data_size, &vps_data, &vps_data_size)) < 0 ||
251 (ret = h2645_ps_to_nalu(sps->data, sps->data_size, &sps_data, &sps_data_size)) < 0 ||
252 (ret = h2645_ps_to_nalu(pps->data, pps->data_size, &pps_data, &pps_data_size)) < 0) {
253 goto done;
254 }
255
256 data_size = vps_data_size + sps_data_size + pps_data_size;
257 data = av_mallocz(data_size);
258 if (!data) {
259 ret = AVERROR(ENOMEM);
260 goto done;
261 }
262
263 memcpy(data , vps_data, vps_data_size);
264 memcpy(data + vps_data_size , sps_data, sps_data_size);
265 memcpy(data + vps_data_size + sps_data_size, pps_data, pps_data_size);
266
267 ff_AMediaFormat_setBuffer(format, "csd-0", data, data_size);
268
269 av_freep(&data);
270 } else {
271 const int warn = is_nalff && avctx->codec_tag == MKTAG('h','v','c','1');
272 av_log(avctx, warn ? AV_LOG_WARNING : AV_LOG_DEBUG,
273 "Could not extract VPS/PPS/SPS from extradata\n");
274 ret = 0;
275 }
276
277done:
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 CONFIG_AV1_MEDIACODEC_DECODER || \
294 CONFIG_AAC_MEDIACODEC_DECODER || \
295 CONFIG_AMRNB_MEDIACODEC_DECODER || \
296 CONFIG_AMRWB_MEDIACODEC_DECODER || \
297 CONFIG_MP3_MEDIACODEC_DECODER
298static int common_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
299{
300 int ret = 0;
301
302 if (avctx->extradata) {
304 }
305
306 return ret;
307}
308#endif
309
311{
312 int ret;
313 int sdk_int;
314
315 const char *codec_mime = NULL;
316
318 MediaCodecContext *s = avctx->priv_data;
319
320 if (s->use_ndk_codec < 0)
321 s->use_ndk_codec = !av_jni_get_java_vm(avctx);
322
323 format = ff_AMediaFormat_new(s->use_ndk_codec);
324 if (!format) {
325 av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
326 ret = AVERROR_EXTERNAL;
327 goto done;
328 }
329
330 switch (avctx->codec_id) {
331#if CONFIG_AV1_MEDIACODEC_DECODER
332 case AV_CODEC_ID_AV1:
333 codec_mime = "video/av01";
334
335 ret = common_set_extradata(avctx, format);
336 if (ret < 0)
337 goto done;
338 break;
339#endif
340#if CONFIG_H264_MEDIACODEC_DECODER
341 case AV_CODEC_ID_H264:
342 codec_mime = "video/avc";
343
344 ret = h264_set_extradata(avctx, format);
345 if (ret < 0)
346 goto done;
347 break;
348#endif
349#if CONFIG_HEVC_MEDIACODEC_DECODER
350 case AV_CODEC_ID_HEVC:
351 codec_mime = "video/hevc";
352
353 ret = hevc_set_extradata(avctx, format);
354 if (ret < 0)
355 goto done;
356 break;
357#endif
358#if CONFIG_MPEG2_MEDIACODEC_DECODER
360 codec_mime = "video/mpeg2";
361
362 ret = common_set_extradata(avctx, format);
363 if (ret < 0)
364 goto done;
365 break;
366#endif
367#if CONFIG_MPEG4_MEDIACODEC_DECODER
369 codec_mime = "video/mp4v-es",
370
371 ret = common_set_extradata(avctx, format);
372 if (ret < 0)
373 goto done;
374 break;
375#endif
376#if CONFIG_VP8_MEDIACODEC_DECODER
377 case AV_CODEC_ID_VP8:
378 codec_mime = "video/x-vnd.on2.vp8";
379
380 ret = common_set_extradata(avctx, format);
381 if (ret < 0)
382 goto done;
383 break;
384#endif
385#if CONFIG_VP9_MEDIACODEC_DECODER
386 case AV_CODEC_ID_VP9:
387 codec_mime = "video/x-vnd.on2.vp9";
388
389 ret = common_set_extradata(avctx, format);
390 if (ret < 0)
391 goto done;
392 break;
393#endif
394#if CONFIG_AAC_MEDIACODEC_DECODER
395 case AV_CODEC_ID_AAC:
396 codec_mime = "audio/mp4a-latm";
397
398 ret = common_set_extradata(avctx, format);
399 if (ret < 0)
400 goto done;
401 break;
402#endif
403#if CONFIG_AMRNB_MEDIACODEC_DECODER
405 codec_mime = "audio/3gpp";
406
407 ret = common_set_extradata(avctx, format);
408 if (ret < 0)
409 goto done;
410 break;
411#endif
412#if CONFIG_AMRWB_MEDIACODEC_DECODER
414 codec_mime = "audio/amr-wb";
415
416 ret = common_set_extradata(avctx, format);
417 if (ret < 0)
418 goto done;
419 break;
420#endif
421#if CONFIG_MP3_MEDIACODEC_DECODER
422 case AV_CODEC_ID_MP3:
423 codec_mime = "audio/mpeg";
424
425 ret = common_set_extradata(avctx, format);
426 if (ret < 0)
427 goto done;
428 break;
429#endif
430 default:
431 av_assert0(0);
432 }
433
434 ff_AMediaFormat_setString(format, "mime", codec_mime);
435
436 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
437 ff_AMediaFormat_setInt32(format, "width", avctx->width);
438 ff_AMediaFormat_setInt32(format, "height", avctx->height);
439 } else {
440 ff_AMediaFormat_setInt32(format, "channel-count", avctx->ch_layout.nb_channels);
441 ff_AMediaFormat_setInt32(format, "sample-rate", avctx->sample_rate);
442 }
443 if (s->operating_rate > 0)
444 ff_AMediaFormat_setInt32(format, "operating-rate", s->operating_rate);
445
446 s->ctx = av_mallocz(sizeof(*s->ctx));
447 if (!s->ctx) {
448 av_log(avctx, AV_LOG_ERROR, "Failed to allocate MediaCodecDecContext\n");
449 ret = AVERROR(ENOMEM);
450 goto done;
451 }
452
453 s->ctx->delay_flush = s->delay_flush;
454 s->ctx->use_ndk_codec = s->use_ndk_codec;
455
456 if ((ret = ff_mediacodec_dec_init(avctx, s->ctx, codec_mime, format)) < 0) {
457 s->ctx = NULL;
458 goto done;
459 }
460
461 av_log(avctx, AV_LOG_INFO,
462 "MediaCodec started successfully: codec = %s, ret = %d\n",
463 s->ctx->codec_name, ret);
464
465 sdk_int = ff_Build_SDK_INT(avctx);
466 /* ff_Build_SDK_INT can fail when target API < 24 and JVM isn't available.
467 * If we don't check sdk_int > 0, the workaround might be enabled by
468 * mistake.
469 * JVM is required to make the workaround works reliably. On the other hand,
470 * missing a workaround should not be a serious issue, we do as best we can.
471 */
472 if (sdk_int > 0 && sdk_int <= 23 &&
473 strcmp(s->ctx->codec_name, "OMX.amlogic.mpeg2.decoder.awesome") == 0) {
474 av_log(avctx, AV_LOG_INFO, "Enabling workaround for %s on API=%d\n",
475 s->ctx->codec_name, sdk_int);
476 s->amlogic_mpeg2_api23_workaround = 1;
477 }
478
479done:
480 if (format) {
482 }
483
484 if (ret < 0) {
486 }
487
488 return ret;
489}
490
492{
493 MediaCodecContext *s = avctx->priv_data;
494 int ret;
495 ssize_t index;
496
497 /* In delay_flush mode, wait until the user has released or rendered
498 all retained frames. */
499 if (s->delay_flush && ff_mediacodec_dec_is_flushing(avctx, s->ctx)) {
500 if (!ff_mediacodec_dec_flush(avctx, s->ctx)) {
501 return AVERROR(EAGAIN);
502 }
503 }
504
505 /* poll for new frame */
506 ret = ff_mediacodec_dec_receive(avctx, s->ctx, frame, false);
507 if (ret != AVERROR(EAGAIN))
508 return ret;
509
510 /* feed decoder */
511 while (1) {
512 if (s->ctx->current_input_buffer < 0 && !s->ctx->draining) {
513 /* poll for input space */
514 index = ff_AMediaCodec_dequeueInputBuffer(s->ctx->codec, 0);
515 if (index < 0) {
516 /* no space, block for an output frame to appear */
517 ret = ff_mediacodec_dec_receive(avctx, s->ctx, frame, true);
518 /* Try again if both input port and output port return EAGAIN.
519 * If no data is consumed and no frame in output, it can make
520 * both avcodec_send_packet() and avcodec_receive_frame()
521 * return EAGAIN, which violate the design.
522 */
523 if (ff_AMediaCodec_infoTryAgainLater(s->ctx->codec, index) &&
524 ret == AVERROR(EAGAIN))
525 continue;
526 return ret;
527 }
528 s->ctx->current_input_buffer = index;
529 }
530
531 /* try to flush any buffered packet data */
532 if (s->buffered_pkt.size > 0) {
533 ret = ff_mediacodec_dec_send(avctx, s->ctx, &s->buffered_pkt, false);
534 if (ret >= 0) {
535 s->buffered_pkt.size -= ret;
536 s->buffered_pkt.data += ret;
537 if (s->buffered_pkt.size <= 0) {
538 av_packet_unref(&s->buffered_pkt);
539 } else {
540 av_log(avctx, AV_LOG_WARNING,
541 "could not send entire packet in single input buffer (%d < %d)\n",
542 ret, s->buffered_pkt.size+ret);
543 }
544 } else if (ret < 0 && ret != AVERROR(EAGAIN)) {
545 return ret;
546 }
547
548 if (s->amlogic_mpeg2_api23_workaround && s->buffered_pkt.size <= 0) {
549 /* fallthrough to fetch next packet regardless of input buffer space */
550 } else {
551 /* poll for space again */
552 continue;
553 }
554 }
555
556 /* fetch new packet or eof */
557 ret = ff_decode_get_packet(avctx, &s->buffered_pkt);
558 if (ret == AVERROR_EOF) {
559 AVPacket null_pkt = { 0 };
560 ret = ff_mediacodec_dec_send(avctx, s->ctx, &null_pkt, true);
561 if (ret < 0)
562 return ret;
563 return ff_mediacodec_dec_receive(avctx, s->ctx, frame, true);
564 } else if (ret == AVERROR(EAGAIN) && s->ctx->current_input_buffer < 0) {
565 return ff_mediacodec_dec_receive(avctx, s->ctx, frame, true);
566 } else if (ret < 0) {
567 return ret;
568 }
569 }
570
571 return AVERROR(EAGAIN);
572}
573
575{
576 MediaCodecContext *s = avctx->priv_data;
577
578 av_packet_unref(&s->buffered_pkt);
579
580 ff_mediacodec_dec_flush(avctx, s->ctx);
581}
582
584 &(const AVCodecHWConfigInternal) {
585 .public = {
586 .pix_fmt = AV_PIX_FMT_MEDIACODEC,
589 .device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
590 },
591 .hwaccel = NULL,
592 },
593 NULL
594};
595
596#define OFFSET(x) offsetof(MediaCodecContext, x)
597#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
599 { "delay_flush", "Delay flush until hw output buffers are returned to the decoder",
600 OFFSET(delay_flush), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VD },
601 { "ndk_codec", "Use MediaCodec from NDK",
602 OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VD },
603 { "operating_rate", "The desired operating rate that the codec will need to operate at, zero for unspecified",
604 OFFSET(operating_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VD },
605 { NULL }
606};
607
608#define DECLARE_MEDIACODEC_VCLASS(short_name) \
609static const AVClass ff_##short_name##_mediacodec_dec_class = { \
610 .class_name = #short_name "_mediacodec", \
611 .item_name = av_default_item_name, \
612 .option = ff_mediacodec_vdec_options, \
613 .version = LIBAVUTIL_VERSION_INT, \
614};
615
616#define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf) \
617DECLARE_MEDIACODEC_VCLASS(short_name) \
618const FFCodec ff_ ## short_name ## _mediacodec_decoder = { \
619 .p.name = #short_name "_mediacodec", \
620 CODEC_LONG_NAME(full_name " Android MediaCodec decoder"), \
621 .p.type = AVMEDIA_TYPE_VIDEO, \
622 .p.id = codec_id, \
623 .p.priv_class = &ff_##short_name##_mediacodec_dec_class, \
624 .priv_data_size = sizeof(MediaCodecContext), \
625 .init = mediacodec_decode_init, \
626 FF_CODEC_RECEIVE_FRAME_CB(mediacodec_receive_frame), \
627 .flush = mediacodec_decode_flush, \
628 .close = mediacodec_decode_close, \
629 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, \
630 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \
631 .bsfs = bsf, \
632 .hw_configs = mediacodec_hw_configs, \
633 .p.wrapper_name = "mediacodec", \
634}; \
635
636#if CONFIG_H264_MEDIACODEC_DECODER
637DECLARE_MEDIACODEC_VDEC(h264, "H.264", AV_CODEC_ID_H264, "h264_mp4toannexb")
638#endif
639
640#if CONFIG_HEVC_MEDIACODEC_DECODER
641DECLARE_MEDIACODEC_VDEC(hevc, "H.265", AV_CODEC_ID_HEVC, "hevc_mp4toannexb")
642#endif
643
644#if CONFIG_MPEG2_MEDIACODEC_DECODER
646#endif
647
648#if CONFIG_MPEG4_MEDIACODEC_DECODER
650#endif
651
652#if CONFIG_VP8_MEDIACODEC_DECODER
654#endif
655
656#if CONFIG_VP9_MEDIACODEC_DECODER
658#endif
659
660#if CONFIG_AV1_MEDIACODEC_DECODER
662#endif
663
664#define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
666 { "ndk_codec", "Use MediaCodec from NDK",
667 OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, AD },
668 { "operating_rate", "The desired operating rate that the codec will need to operate at, zero for unspecified",
669 OFFSET(operating_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AD },
670 { NULL }
671};
672
673#define DECLARE_MEDIACODEC_ACLASS(short_name) \
674static const AVClass ff_##short_name##_mediacodec_dec_class = { \
675 .class_name = #short_name "_mediacodec", \
676 .item_name = av_default_item_name, \
677 .option = ff_mediacodec_adec_options, \
678 .version = LIBAVUTIL_VERSION_INT, \
679};
680
681#define DECLARE_MEDIACODEC_ADEC(short_name, full_name, codec_id, bsf) \
682DECLARE_MEDIACODEC_ACLASS(short_name) \
683const FFCodec ff_ ## short_name ## _mediacodec_decoder = { \
684 .p.name = #short_name "_mediacodec", \
685 CODEC_LONG_NAME(full_name " Android MediaCodec decoder"), \
686 .p.type = AVMEDIA_TYPE_AUDIO, \
687 .p.id = codec_id, \
688 .p.priv_class = &ff_##short_name##_mediacodec_dec_class, \
689 .priv_data_size = sizeof(MediaCodecContext), \
690 .init = mediacodec_decode_init, \
691 FF_CODEC_RECEIVE_FRAME_CB(mediacodec_receive_frame), \
692 .flush = mediacodec_decode_flush, \
693 .close = mediacodec_decode_close, \
694 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE, \
695 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \
696 .bsfs = bsf, \
697 .p.wrapper_name = "mediacodec", \
698}; \
699
700#if CONFIG_AAC_MEDIACODEC_DECODER
701DECLARE_MEDIACODEC_ADEC(aac, "AAC", AV_CODEC_ID_AAC, "aac_adtstoasc")
702#endif
703
704#if CONFIG_AMRNB_MEDIACODEC_DECODER
706#endif
707
708#if CONFIG_AMRWB_MEDIACODEC_DECODER
710#endif
711
712#if CONFIG_MP3_MEDIACODEC_DECODER
714#endif
static const char *const format[]
Definition af_aiir.c:445
#define VD
Definition amfdec.c:787
static FILE * out
static int out_size
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
static void ff_hevc_reset_sei(HEVCSEI *sei)
Reset SEI values that are stored on the Context.
Definition sei.h:128
@ 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:1647
int profile
profile
Definition avcodec.h:1637
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