Go to the documentation of this file.
23 #include "config_components.h"
74 #if CONFIG_H264_MEDIACODEC_DECODER || CONFIG_HEVC_MEDIACODEC_DECODER
75 static int h2645_ps_to_nalu(
const uint8_t *
src,
int src_size, uint8_t **
out,
int *
out_size)
80 static const uint8_t nalu_header[] = { 0x00, 0x00, 0x00, 0x01 };
86 p =
av_malloc(
sizeof(nalu_header) + src_size);
92 *
out_size =
sizeof(nalu_header) + src_size;
94 memcpy(p, nalu_header,
sizeof(nalu_header));
95 memcpy(p +
sizeof(nalu_header),
src, src_size);
128 #if CONFIG_H264_MEDIACODEC_DECODER
138 int nal_length_size = 0;
140 memset(&ps, 0,
sizeof(ps));
143 &ps, &is_avc, &nal_length_size, 0, avctx);
168 if ((
ret = h2645_ps_to_nalu(
sps->data,
sps->data_size, &
data, &data_size)) < 0) {
174 if ((
ret = h2645_ps_to_nalu(
pps->data,
pps->data_size, &
data, &data_size)) < 0) {
180 const int warn = is_avc && (avctx->
codec_tag ==
MKTAG(
'a',
'v',
'c',
'1') ||
183 "Could not extract PPS/SPS from extradata\n");
194 #if CONFIG_HEVC_MEDIACODEC_DECODER
207 int nal_length_size = 0;
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;
216 memset(&ps, 0,
sizeof(ps));
217 memset(&
sei, 0,
sizeof(
sei));
220 &ps, &
sei, &is_nalff, &nal_length_size, 0, 1, avctx);
249 avctx->
profile =
sps->ptl.general_ptl.profile_idc;
250 avctx->
level =
sps->ptl.general_ptl.level_idc;
252 if ((
ret = h2645_ps_to_nalu(
vps->data,
vps->data_size, &vps_data, &vps_data_size)) < 0 ||
253 (
ret = h2645_ps_to_nalu(
sps->data,
sps->data_size, &sps_data, &sps_data_size)) < 0 ||
254 (
ret = h2645_ps_to_nalu(
pps->data,
pps->data_size, &pps_data, &pps_data_size)) < 0) {
258 data_size = vps_data_size + sps_data_size + pps_data_size;
265 memcpy(
data , vps_data, vps_data_size);
266 memcpy(
data + vps_data_size , sps_data, sps_data_size);
267 memcpy(
data + vps_data_size + sps_data_size, pps_data, pps_data_size);
273 const int warn = is_nalff && avctx->
codec_tag ==
MKTAG(
'h',
'v',
'c',
'1');
275 "Could not extract VPS/PPS/SPS from extradata\n");
290 #if CONFIG_MPEG2_MEDIACODEC_DECODER || \
291 CONFIG_MPEG4_MEDIACODEC_DECODER || \
292 CONFIG_VP8_MEDIACODEC_DECODER || \
293 CONFIG_VP9_MEDIACODEC_DECODER || \
294 CONFIG_AV1_MEDIACODEC_DECODER || \
295 CONFIG_AAC_MEDIACODEC_DECODER || \
296 CONFIG_AMRNB_MEDIACODEC_DECODER || \
297 CONFIG_AMRWB_MEDIACODEC_DECODER || \
298 CONFIG_MP3_MEDIACODEC_DECODER
316 const char *codec_mime =
NULL;
321 if (
s->use_ndk_codec < 0)
332 #if CONFIG_AV1_MEDIACODEC_DECODER
334 codec_mime =
"video/av01";
336 ret = common_set_extradata(avctx,
format);
341 #if CONFIG_H264_MEDIACODEC_DECODER
343 codec_mime =
"video/avc";
350 #if CONFIG_HEVC_MEDIACODEC_DECODER
352 codec_mime =
"video/hevc";
359 #if CONFIG_MPEG2_MEDIACODEC_DECODER
361 codec_mime =
"video/mpeg2";
363 ret = common_set_extradata(avctx,
format);
368 #if CONFIG_MPEG4_MEDIACODEC_DECODER
370 codec_mime =
"video/mp4v-es",
372 ret = common_set_extradata(avctx,
format);
377 #if CONFIG_VP8_MEDIACODEC_DECODER
379 codec_mime =
"video/x-vnd.on2.vp8";
381 ret = common_set_extradata(avctx,
format);
386 #if CONFIG_VP9_MEDIACODEC_DECODER
388 codec_mime =
"video/x-vnd.on2.vp9";
390 ret = common_set_extradata(avctx,
format);
395 #if CONFIG_AAC_MEDIACODEC_DECODER
397 codec_mime =
"audio/mp4a-latm";
399 ret = common_set_extradata(avctx,
format);
404 #if CONFIG_AMRNB_MEDIACODEC_DECODER
406 codec_mime =
"audio/3gpp";
408 ret = common_set_extradata(avctx,
format);
413 #if CONFIG_AMRWB_MEDIACODEC_DECODER
415 codec_mime =
"audio/amr-wb";
417 ret = common_set_extradata(avctx,
format);
422 #if CONFIG_MP3_MEDIACODEC_DECODER
424 codec_mime =
"audio/mpeg";
426 ret = common_set_extradata(avctx,
format);
452 s->ctx->delay_flush =
s->delay_flush;
453 s->ctx->use_ndk_codec =
s->use_ndk_codec;
461 "MediaCodec started successfully: codec = %s, ret = %d\n",
462 s->ctx->codec_name,
ret);
471 if (sdk_int > 0 && sdk_int <= 23 &&
472 strcmp(
s->ctx->codec_name,
"OMX.amlogic.mpeg2.decoder.awesome") == 0) {
474 s->ctx->codec_name, sdk_int);
475 s->amlogic_mpeg2_api23_workaround = 1;
511 if (
s->ctx->current_input_buffer < 0 && !
s->ctx->draining) {
527 s->ctx->current_input_buffer =
index;
531 if (
s->buffered_pkt.size > 0) {
534 s->buffered_pkt.size -=
ret;
535 s->buffered_pkt.data +=
ret;
536 if (
s->buffered_pkt.size <= 0) {
540 "could not send entire packet in single input buffer (%d < %d)\n",
541 ret,
s->buffered_pkt.size+
ret);
547 if (
s->amlogic_mpeg2_api23_workaround &&
s->buffered_pkt.size <= 0) {
563 }
else if (
ret ==
AVERROR(EAGAIN) &&
s->ctx->current_input_buffer < 0) {
565 }
else if (
ret < 0) {
595 #define OFFSET(x) offsetof(MediaCodecH264DecContext, x)
596 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
598 {
"delay_flush",
"Delay flush until hw output buffers are returned to the decoder",
600 {
"ndk_codec",
"Use MediaCodec from NDK",
605 #define DECLARE_MEDIACODEC_VCLASS(short_name) \
606 static const AVClass ff_##short_name##_mediacodec_dec_class = { \
607 .class_name = #short_name "_mediacodec", \
608 .item_name = av_default_item_name, \
609 .option = ff_mediacodec_vdec_options, \
610 .version = LIBAVUTIL_VERSION_INT, \
613 #define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf) \
614 DECLARE_MEDIACODEC_VCLASS(short_name) \
615 const FFCodec ff_ ## short_name ## _mediacodec_decoder = { \
616 .p.name = #short_name "_mediacodec", \
617 CODEC_LONG_NAME(full_name " Android MediaCodec decoder"), \
618 .p.type = AVMEDIA_TYPE_VIDEO, \
620 .p.priv_class = &ff_##short_name##_mediacodec_dec_class, \
621 .priv_data_size = sizeof(MediaCodecH264DecContext), \
622 .init = mediacodec_decode_init, \
623 FF_CODEC_RECEIVE_FRAME_CB(mediacodec_receive_frame), \
624 .flush = mediacodec_decode_flush, \
625 .close = mediacodec_decode_close, \
626 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, \
627 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \
629 .hw_configs = mediacodec_hw_configs, \
630 .p.wrapper_name = "mediacodec", \
633 #if CONFIG_H264_MEDIACODEC_DECODER
637 #if CONFIG_HEVC_MEDIACODEC_DECODER
641 #if CONFIG_MPEG2_MEDIACODEC_DECODER
645 #if CONFIG_MPEG4_MEDIACODEC_DECODER
649 #if CONFIG_VP8_MEDIACODEC_DECODER
653 #if CONFIG_VP9_MEDIACODEC_DECODER
657 #if CONFIG_AV1_MEDIACODEC_DECODER
661 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
663 {
"ndk_codec",
"Use MediaCodec from NDK",
668 #define DECLARE_MEDIACODEC_ACLASS(short_name) \
669 static const AVClass ff_##short_name##_mediacodec_dec_class = { \
670 .class_name = #short_name "_mediacodec", \
671 .item_name = av_default_item_name, \
672 .option = ff_mediacodec_adec_options, \
673 .version = LIBAVUTIL_VERSION_INT, \
676 #define DECLARE_MEDIACODEC_ADEC(short_name, full_name, codec_id, bsf) \
677 DECLARE_MEDIACODEC_VCLASS(short_name) \
678 const FFCodec ff_ ## short_name ## _mediacodec_decoder = { \
679 .p.name = #short_name "_mediacodec", \
680 CODEC_LONG_NAME(full_name " Android MediaCodec decoder"), \
681 .p.type = AVMEDIA_TYPE_AUDIO, \
683 .p.priv_class = &ff_##short_name##_mediacodec_dec_class, \
684 .priv_data_size = sizeof(MediaCodecH264DecContext), \
685 .init = mediacodec_decode_init, \
686 FF_CODEC_RECEIVE_FRAME_CB(mediacodec_receive_frame), \
687 .flush = mediacodec_decode_flush, \
688 .close = mediacodec_decode_close, \
689 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE, \
690 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE, \
692 .p.wrapper_name = "mediacodec", \
695 #if CONFIG_AAC_MEDIACODEC_DECODER
699 #if CONFIG_AMRNB_MEDIACODEC_DECODER
703 #if CONFIG_AMRWB_MEDIACODEC_DECODER
707 #if CONFIG_MP3_MEDIACODEC_DECODER
const SPS * sps_list[MAX_SPS_COUNT]
RefStruct references.
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)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
#define AV_LOG_WARNING
Something somehow does not look correct.
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
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
int sample_rate
samples per second
const HEVCPPS * pps_list[HEVC_MAX_PPS_COUNT]
RefStruct references.
#define AVERROR_EOF
End of file.
const PPS * pps_list[MAX_PPS_COUNT]
RefStruct references.
This structure describes decoded (raw) audio or video data.
@ AV_HWDEVICE_TYPE_MEDIACODEC
int nb_channels
Number of channels in this layout.
AVChannelLayout ch_layout
Audio channel layout.
int amlogic_mpeg2_api23_workaround
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
const HEVCSPS * sps_list[HEVC_MAX_SPS_COUNT]
RefStruct references.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
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
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)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
enum AVPixelFormat pix_fmt
For decoders, a hardware pixel format which that decoder may be able to decode to if suitable hardwar...
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Describe the class of an AVClass context structure.
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
int level
Encoding level descriptor.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AV_LOG_INFO
Standard information.
void ff_hevc_ps_uninit(HEVCParamSets *ps)
#define i(width, name, range_min, range_max)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_jni_get_java_vm(void *log_ctx)
int ff_h264_get_profile(const SPS *sps)
Compute profile from profile_idc and constraint_set?_flags.
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
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
main external API structure.
MediaCodecDecContext * ctx
enum AVMediaType codec_type
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
const HEVCVPS * vps_list[HEVC_MAX_VPS_COUNT]
RefStruct references.
int width
picture width / height.
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
#define MKTAG(a, b, c, d)
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.