/*
- * Android MediaCodec H.264 / H.265 / MPEG-4 / VP8 / VP9 decoders
+ * Android MediaCodec MPEG-2 / H.264 / H.265 / MPEG-4 / VP8 / VP9 decoders
*
* Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
*
MediaCodecDecContext *ctx;
- AVBSFContext *bsf;
-
AVFifoBuffer *fifo;
- AVPacket filtered_pkt;
+ AVPacket buffered_pkt;
} MediaCodecH264DecContext;
av_fifo_free(s->fifo);
- av_bsf_free(&s->bsf);
- av_packet_unref(&s->filtered_pkt);
+ av_packet_unref(&s->buffered_pkt);
return 0;
}
int ret;
HEVCParamSets ps;
+ HEVCSEIContext sei;
const HEVCVPS *vps = NULL;
const HEVCPPS *pps = NULL;
int pps_data_size = 0;
memset(&ps, 0, sizeof(ps));
+ memset(&sei, 0, sizeof(sei));
ret = ff_hevc_decode_extradata(avctx->extradata, avctx->extradata_size,
- &ps, &is_nalff, &nal_length_size, 0, 1, avctx);
+ &ps, &sei, &is_nalff, &nal_length_size, 0, 1, avctx);
if (ret < 0) {
goto done;
}
}
#endif
+#if CONFIG_MPEG2_MEDIACODEC_DECODER
+static int mpeg2_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
+{
+ int ret = 0;
+
+ if (avctx->extradata) {
+ ff_AMediaFormat_setBuffer(format, "csd-0", avctx->extradata, avctx->extradata_size);
+ }
+
+ return ret;
+}
+#endif
+
#if CONFIG_MPEG4_MEDIACODEC_DECODER
static int mpeg4_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format)
{
const char *codec_mime = NULL;
- const char *bsf_name = NULL;
- const AVBitStreamFilter *bsf = NULL;
-
FFAMediaFormat *format = NULL;
MediaCodecH264DecContext *s = avctx->priv_data;
#if CONFIG_H264_MEDIACODEC_DECODER
case AV_CODEC_ID_H264:
codec_mime = "video/avc";
- bsf_name = "h264_mp4toannexb";
ret = h264_set_extradata(avctx, format);
if (ret < 0)
#if CONFIG_HEVC_MEDIACODEC_DECODER
case AV_CODEC_ID_HEVC:
codec_mime = "video/hevc";
- bsf_name = "hevc_mp4toannexb";
ret = hevc_set_extradata(avctx, format);
if (ret < 0)
goto done;
break;
#endif
+#if CONFIG_MPEG2_MEDIACODEC_DECODER
+ case AV_CODEC_ID_MPEG2VIDEO:
+ codec_mime = "video/mpeg2";
+
+ ret = mpeg2_set_extradata(avctx, format);
+ if (ret < 0)
+ goto done;
+ break;
+#endif
#if CONFIG_MPEG4_MEDIACODEC_DECODER
case AV_CODEC_ID_MPEG4:
codec_mime = "video/mp4v-es",
goto done;
}
- if (bsf_name) {
- bsf = av_bsf_get_by_name(bsf_name);
- if(!bsf) {
- ret = AVERROR_BSF_NOT_FOUND;
- goto done;
- }
-
- if ((ret = av_bsf_alloc(bsf, &s->bsf))) {
- goto done;
- }
-
- if (((ret = avcodec_parameters_from_context(s->bsf->par_in, avctx)) < 0) ||
- ((ret = av_bsf_init(s->bsf)) < 0)) {
- goto done;
- }
- }
-
- av_init_packet(&s->filtered_pkt);
-
done:
if (format) {
ff_AMediaFormat_delete(format);
/* process buffered data */
while (!*got_frame) {
- /* prepare the input data -- convert to Annex B if needed */
- if (s->filtered_pkt.size <= 0) {
- AVPacket input_pkt = { 0 };
-
- av_packet_unref(&s->filtered_pkt);
+ /* prepare the input data */
+ if (s->buffered_pkt.size <= 0) {
+ av_packet_unref(&s->buffered_pkt);
/* no more data */
if (av_fifo_size(s->fifo) < sizeof(AVPacket)) {
ff_mediacodec_dec_decode(avctx, s->ctx, frame, got_frame, avpkt);
}
- av_fifo_generic_read(s->fifo, &input_pkt, sizeof(input_pkt), NULL);
-
- if (s->bsf) {
- ret = av_bsf_send_packet(s->bsf, &input_pkt);
- if (ret < 0) {
- return ret;
- }
-
- ret = av_bsf_receive_packet(s->bsf, &s->filtered_pkt);
- if (ret == AVERROR(EAGAIN)) {
- goto done;
- }
- } else {
- av_packet_move_ref(&s->filtered_pkt, &input_pkt);
- }
-
- /* {h264,hevc}_mp4toannexb are used here and do not require flushing */
- av_assert0(ret != AVERROR_EOF);
-
- if (ret < 0) {
- return ret;
- }
+ av_fifo_generic_read(s->fifo, &s->buffered_pkt, sizeof(s->buffered_pkt), NULL);
}
- ret = mediacodec_process_data(avctx, frame, got_frame, &s->filtered_pkt);
+ ret = mediacodec_process_data(avctx, frame, got_frame, &s->buffered_pkt);
if (ret < 0)
return ret;
- s->filtered_pkt.size -= ret;
- s->filtered_pkt.data += ret;
+ s->buffered_pkt.size -= ret;
+ s->buffered_pkt.data += ret;
}
-done:
+
return avpkt->size;
}
}
av_fifo_reset(s->fifo);
- av_packet_unref(&s->filtered_pkt);
+ av_packet_unref(&s->buffered_pkt);
ff_mediacodec_dec_flush(avctx, s->ctx);
}
.close = mediacodec_decode_close,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING,
.caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
+ .bsfs = "h264_mp4toannexb",
};
#endif
.close = mediacodec_decode_close,
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING,
.caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
+ .bsfs = "hevc_mp4toannexb",
+};
+#endif
+
+#if CONFIG_MPEG2_MEDIACODEC_DECODER
+AVCodec ff_mpeg2_mediacodec_decoder = {
+ .name = "mpeg2_mediacodec",
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 Android MediaCodec decoder"),
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_MPEG2VIDEO,
+ .priv_data_size = sizeof(MediaCodecH264DecContext),
+ .init = mediacodec_decode_init,
+ .decode = mediacodec_decode_frame,
+ .flush = mediacodec_decode_flush,
+ .close = mediacodec_decode_close,
+ .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING,
+ .caps_internal = FF_CODEC_CAP_SETS_PKT_DTS,
};
#endif