diff options
author | Hendrik Leppkes <h.leppkes@gmail.com> | 2015-09-26 11:07:33 +0200 |
---|---|---|
committer | Hendrik Leppkes <h.leppkes@gmail.com> | 2015-09-26 11:07:33 +0200 |
commit | c5a312dd6afb9aded1f8f763be71ef70d69c7e17 (patch) | |
tree | b79f438a9761c9a210d8142487ea4a2de4723e2b /libavcodec | |
parent | 0f98fd30e2d3c7254a1c56ce42a9a8bf0f6dc0eb (diff) | |
parent | f290e48d86e10f34b5ddc519127636bcebec7c43 (diff) | |
download | ffmpeg-c5a312dd6afb9aded1f8f763be71ef70d69c7e17.tar.gz |
Merge commit 'f290e48d86e10f34b5ddc519127636bcebec7c43'
* commit 'f290e48d86e10f34b5ddc519127636bcebec7c43':
mmal: drop the h264 BSF
Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/mmaldec.c | 64 |
1 files changed, 28 insertions, 36 deletions
diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c index a41a1b67be..1253ca6023 100644 --- a/libavcodec/mmaldec.c +++ b/libavcodec/mmaldec.c @@ -67,8 +67,6 @@ typedef struct MMALDecodeContext { AVClass *av_class; int extra_buffers; - AVBitStreamFilterContext *bsfc; - MMAL_COMPONENT_T *decoder; MMAL_QUEUE_T *queue_decoded_frames; MMAL_POOL_T *pool_in; @@ -86,6 +84,7 @@ typedef struct MMALDecodeContext { int64_t frames_output; int eos_received; int eos_sent; + int extradata_sent; } MMALDecodeContext; // Assume decoder is guaranteed to produce output after at least this many @@ -165,7 +164,7 @@ static void ffmmal_stop_decoder(AVCodecContext *avctx) } ctx->waiting_buffers_tail = NULL; - ctx->frames_output = ctx->eos_received = ctx->eos_sent = ctx->packets_sent = 0; + ctx->frames_output = ctx->eos_received = ctx->eos_sent = ctx->packets_sent = ctx->extradata_sent = 0; } static av_cold int ffmmal_close_decoder(AVCodecContext *avctx) @@ -181,9 +180,6 @@ static av_cold int ffmmal_close_decoder(AVCodecContext *avctx) mmal_pool_destroy(ctx->pool_in); ffmmal_poolref_unref(ctx->pool_out); - if (ctx->bsfc) - av_bitstream_filter_close(ctx->bsfc); - mmal_vc_deinit(); return 0; @@ -356,17 +352,7 @@ static av_cold int ffmmal_init_decoder(AVCodecContext *avctx) format_in->es->video.par.den = avctx->sample_aspect_ratio.den; format_in->flags = MMAL_ES_FORMAT_FLAG_FRAMED; - if (avctx->codec->id == AV_CODEC_ID_H264 && avctx->extradata && avctx->extradata[0] == 1) { - uint8_t *dummy_p; - int dummy_int; - ctx->bsfc = av_bitstream_filter_init("h264_mp4toannexb"); - if (!ctx->bsfc) { - av_log(avctx, AV_LOG_ERROR, "Cannot open the h264_mp4toannexb BSF!\n"); - ret = AVERROR(ENOSYS); - goto fail; - } - av_bitstream_filter_filter(ctx->bsfc, avctx, "private_spspps_buf", &dummy_p, &dummy_int, NULL, 0, 0); - } else if (avctx->extradata_size) { + if (avctx->extradata_size) { if ((status = mmal_format_extradata_alloc(format_in, avctx->extradata_size))) goto fail; format_in->extradata_size = avctx->extradata_size; @@ -440,7 +426,9 @@ fail: // (due to us not reading/returning enough output buffers) and won't accept // new input. (This wouldn't be an issue if MMAL input buffers always were // complete frames - then the input buffer just would have to be big enough.) -static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt) +// If is_extradata is set, send it as MMAL_BUFFER_HEADER_FLAG_CONFIG. +static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt, + int is_extradata) { MMALDecodeContext *ctx = avctx->priv_data; AVBufferRef *buf = NULL; @@ -450,23 +438,12 @@ static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt) int ret = 0; if (avpkt->size) { - if (ctx->bsfc) { - uint8_t *tmp_data; - int tmp_size; - if ((ret = av_bitstream_filter_filter(ctx->bsfc, avctx, "private_spspps_buf", - &tmp_data, &tmp_size, - avpkt->data, avpkt->size, - avpkt->flags & AV_PKT_FLAG_KEY)) < 0) - goto done; - buf = av_buffer_create(tmp_data, tmp_size, NULL, NULL, 0); + if (avpkt->buf) { + buf = av_buffer_ref(avpkt->buf); } else { - if (avpkt->buf) { - buf = av_buffer_ref(avpkt->buf); - } else { - buf = av_buffer_alloc(avpkt->size); - if (buf) - memcpy(buf->data, avpkt->data, avpkt->size); - } + buf = av_buffer_alloc(avpkt->size); + if (buf) + memcpy(buf->data, avpkt->data, avpkt->size); } if (!buf) { ret = AVERROR(ENOMEM); @@ -474,7 +451,8 @@ static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt) } size = buf->size; data = buf->data; - ctx->packets_sent++; + if (!is_extradata) + ctx->packets_sent++; } else { if (!ctx->packets_sent) { // Short-cut the flush logic to avoid upsetting MMAL. @@ -496,6 +474,9 @@ static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt) buffer->data = data; buffer->length = FFMIN(size, ctx->decoder->input[0]->buffer_size); + if (is_extradata) + buffer->flags |= MMAL_BUFFER_HEADER_FLAG_CONFIG; + if (data == start) buffer->flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_START; @@ -731,10 +712,21 @@ done: static int ffmmal_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { + MMALDecodeContext *ctx = avctx->priv_data; AVFrame *frame = data; int ret = 0; - if ((ret = ffmmal_add_packet(avctx, avpkt)) < 0) + if (avctx->extradata_size && !ctx->extradata_sent) { + AVPacket pkt = {0}; + av_init_packet(&pkt); + pkt.data = avctx->extradata; + pkt.size = avctx->extradata_size; + ctx->extradata_sent = 1; + if ((ret = ffmmal_add_packet(avctx, &pkt, 1)) < 0) + return ret; + } + + if ((ret = ffmmal_add_packet(avctx, avpkt, 0)) < 0) return ret; if ((ret = ffmmal_fill_input_port(avctx)) < 0) |