67 #if CONFIG_H264_MEDIACODEC_DECODER || CONFIG_HEVC_MEDIACODEC_DECODER
73 static const uint8_t nalu_header[] = { 0x00, 0x00, 0x00, 0x01 };
79 p =
av_malloc(
sizeof(nalu_header) + src_size);
85 *
out_size =
sizeof(nalu_header) + src_size;
87 memcpy(p, nalu_header,
sizeof(nalu_header));
88 memcpy(p +
sizeof(nalu_header),
src, src_size);
121 #if CONFIG_H264_MEDIACODEC_DECODER
131 int nal_length_size = 0;
133 memset(&ps, 0,
sizeof(ps));
136 &ps, &is_avc, &nal_length_size, 0, avctx);
158 if ((ret = h2645_ps_to_nalu(
sps->data,
sps->data_size, &
data, &data_size)) < 0) {
164 if ((ret = h2645_ps_to_nalu(
pps->data,
pps->data_size, &
data, &data_size)) < 0) {
170 const int warn = is_avc && (avctx->
codec_tag ==
MKTAG(
'a',
'v',
'c',
'1') ||
173 "Could not extract PPS/SPS from extradata\n");
184 #if CONFIG_HEVC_MEDIACODEC_DECODER
197 int nal_length_size = 0;
202 int vps_data_size = 0;
203 int sps_data_size = 0;
204 int pps_data_size = 0;
206 memset(&ps, 0,
sizeof(ps));
207 memset(&
sei, 0,
sizeof(
sei));
210 &ps, &
sei, &is_nalff, &nal_length_size, 0, 1, avctx);
239 if ((ret = h2645_ps_to_nalu(
vps->data,
vps->data_size, &vps_data, &vps_data_size)) < 0 ||
240 (ret = h2645_ps_to_nalu(
sps->data,
sps->data_size, &sps_data, &sps_data_size)) < 0 ||
241 (ret = h2645_ps_to_nalu(
pps->data,
pps->data_size, &pps_data, &pps_data_size)) < 0) {
245 data_size = vps_data_size + sps_data_size + pps_data_size;
252 memcpy(
data , vps_data, vps_data_size);
253 memcpy(
data + vps_data_size , sps_data, sps_data_size);
254 memcpy(
data + vps_data_size + sps_data_size, pps_data, pps_data_size);
260 const int warn = is_nalff && avctx->
codec_tag ==
MKTAG(
'h',
'v',
'c',
'1');
262 "Could not extract VPS/PPS/SPS from extradata\n");
277 #if CONFIG_MPEG2_MEDIACODEC_DECODER || \
278 CONFIG_MPEG4_MEDIACODEC_DECODER || \
279 CONFIG_VP8_MEDIACODEC_DECODER || \
280 CONFIG_VP9_MEDIACODEC_DECODER
298 const char *codec_mime =
NULL;
311 #if CONFIG_H264_MEDIACODEC_DECODER
313 codec_mime =
"video/avc";
315 ret = h264_set_extradata(avctx,
format);
320 #if CONFIG_HEVC_MEDIACODEC_DECODER
322 codec_mime =
"video/hevc";
324 ret = hevc_set_extradata(avctx,
format);
329 #if CONFIG_MPEG2_MEDIACODEC_DECODER
331 codec_mime =
"video/mpeg2";
333 ret = common_set_extradata(avctx,
format);
338 #if CONFIG_MPEG4_MEDIACODEC_DECODER
340 codec_mime =
"video/mp4v-es",
342 ret = common_set_extradata(avctx,
format);
347 #if CONFIG_VP8_MEDIACODEC_DECODER
349 codec_mime =
"video/x-vnd.on2.vp8";
351 ret = common_set_extradata(avctx,
format);
356 #if CONFIG_VP9_MEDIACODEC_DECODER
358 codec_mime =
"video/x-vnd.on2.vp9";
360 ret = common_set_extradata(avctx,
format);
380 s->ctx->delay_flush =
s->delay_flush;
388 "MediaCodec started successfully: codec = %s, ret = %d\n",
389 s->ctx->codec_name, ret);
393 strcmp(
s->ctx->codec_name,
"OMX.amlogic.mpeg2.decoder.awesome") == 0) {
395 s->ctx->codec_name, sdk_int);
396 s->amlogic_mpeg2_api23_workaround = 1;
432 if (
s->ctx->current_input_buffer < 0) {
439 s->ctx->current_input_buffer =
index;
443 if (
s->buffered_pkt.size > 0) {
446 s->buffered_pkt.size -= ret;
447 s->buffered_pkt.data += ret;
448 if (
s->buffered_pkt.size <= 0) {
452 "could not send entire packet in single input buffer (%d < %d)\n",
453 ret,
s->buffered_pkt.size+ret);
455 }
else if (ret < 0 && ret !=
AVERROR(EAGAIN)) {
459 if (
s->amlogic_mpeg2_api23_workaround &&
s->buffered_pkt.size <= 0) {
475 }
else if (ret ==
AVERROR(EAGAIN) &&
s->ctx->current_input_buffer < 0) {
477 }
else if (ret < 0) {
507 #define OFFSET(x) offsetof(MediaCodecH264DecContext, x)
508 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
510 {
"delay_flush",
"Delay flush until hw output buffers are returned to the decoder",
515 #define DECLARE_MEDIACODEC_VCLASS(short_name) \
516 static const AVClass ff_##short_name##_mediacodec_dec_class = { \
517 .class_name = #short_name "_mediacodec", \
518 .item_name = av_default_item_name, \
519 .option = ff_mediacodec_vdec_options, \
520 .version = LIBAVUTIL_VERSION_INT, \
523 #define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf) \
524 DECLARE_MEDIACODEC_VCLASS(short_name) \
525 AVCodec ff_##short_name##_mediacodec_decoder = { \
526 .name = #short_name "_mediacodec", \
527 .long_name = NULL_IF_CONFIG_SMALL(full_name " Android MediaCodec decoder"), \
528 .type = AVMEDIA_TYPE_VIDEO, \
530 .priv_class = &ff_##short_name##_mediacodec_dec_class, \
531 .priv_data_size = sizeof(MediaCodecH264DecContext), \
532 .init = mediacodec_decode_init, \
533 .receive_frame = mediacodec_receive_frame, \
534 .flush = mediacodec_decode_flush, \
535 .close = mediacodec_decode_close, \
536 .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, \
537 .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS, \
539 .hw_configs = mediacodec_hw_configs, \
540 .wrapper_name = "mediacodec", \
543 #if CONFIG_H264_MEDIACODEC_DECODER
547 #if CONFIG_HEVC_MEDIACODEC_DECODER
551 #if CONFIG_MPEG2_MEDIACODEC_DECODER
555 #if CONFIG_MPEG4_MEDIACODEC_DECODER
559 #if CONFIG_VP8_MEDIACODEC_DECODER
563 #if CONFIG_VP9_MEDIACODEC_DECODER
static const char *const format[]
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
common internal and external API header
#define MKTAG(a, b, c, d)
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_EOF
End of file.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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)
H.264 decoder/parser shared code.
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
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 ff_hevc_ps_uninit(HEVCParamSets *ps)
@ AV_HWDEVICE_TYPE_MEDIACODEC
common internal API header
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
uint8_t * data
The data buffer.
Describe the class of an AVClass context structure.
main external API structure.
int width
picture width / height.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
enum AVPixelFormat pix_fmt
For decoders, a hardware pixel format which that decoder may be able to decode to if suitable hardwar...
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
AVBufferRef * sps_list[MAX_SPS_COUNT]
AVBufferRef * pps_list[MAX_PPS_COUNT]
AVBufferRef * pps_list[HEVC_MAX_PPS_COUNT]
AVBufferRef * vps_list[HEVC_MAX_VPS_COUNT]
AVBufferRef * sps_list[HEVC_MAX_SPS_COUNT]
int amlogic_mpeg2_api23_workaround
MediaCodecDecContext * ctx