From patchwork Fri Jun 9 23:38:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Bouron X-Patchwork-Id: 3895 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.195 with SMTP id 186csp203801vsk; Fri, 9 Jun 2017 16:37:19 -0700 (PDT) X-Received: by 10.28.178.198 with SMTP id b189mr1434598wmf.8.1497051439299; Fri, 09 Jun 2017 16:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497051439; cv=none; d=google.com; s=arc-20160816; b=N9+HpNKbsUXKcQTnVZIg90pnjHBtOfK4dYkZ1k1VRcT9RwFHY/DnRxLNSqL1a2evHu uWcKsj13dt7EmDePOz9K2UDh1Olw1hW5aZfEAC4Eu8fkwTeJGuZyZ7W0OWJGNuDeBGWS tc5MgC+xx9R9BKXqalSpC0q3JPVP3+hpSoBVzuVCpdMgmRkZBEsvKW7LB0UNRlFtf3Sp 8RMOV9sMsuStHMU+C+7cd4nuIxGAyfatYmn5sgsZCROy9FNknQCxsADAvl9QNcHnKHXL n2tsnL8Nkm3cVBsSn4Bds3T3h2Z0Yet5Dsvfn/CRJmArjDA1bkjuShz5d30U3r8VcZyv 6V2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:user-agent :in-reply-to:content-disposition:mime-version:references:message-id :to:from:date:dkim-signature:delivered-to:arc-authentication-results; bh=K1JQR4JYHQ0DAGN8tUWNdbF3XXnUOxI+N7P8jZTzbh8=; b=QTyMfXoPABQIc3C8LNtBdNtisAZzvOhTXH4fSEUPFK4CT1AHVk4VBfGBQ9NeqJrRIb NFpDJG2bjr1kXiZzd9v/Lkziqq6PwGO1Z5oPMNUuh3AAOyUXDWfcyOfBiYbzkcv5SVvv HClr57KPr3bckk74efCSHTAKaXCp7AmK4oSbehTPTrUC7VbLZMu95x7sjjxFbMdI+4kI vqbtVbDbtdrIiEwF3yAeaRuwfdnUXR0FEY4wK7Wu6PCaibYB64vAV/kLV6W3CKO6r/ec 7cBLySZsaZpgBRP5vdlfB234/Ei5tpz3K4daaDeIJnPUTfum82MjLizmWm0n8dfHp9YL N2XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m70si961025wmc.121.2017.06.09.16.37.18; Fri, 09 Jun 2017 16:37:19 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2349A689EA8; Sat, 10 Jun 2017 02:37:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E3E51689D87 for ; Sat, 10 Jun 2017 02:37:07 +0300 (EEST) Received: by mail-wr0-f194.google.com with SMTP id u101so9650962wrc.1 for ; Fri, 09 Jun 2017 16:37:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=n7f9wguFmSoiW2w5pXwZAtVPCun8fNE4uZJbpmtni8w=; b=XTOjfA1KgvF0FT0mSrFhAfWQjaj2X/fMVkOr+IQ3RC+4XV3GtGKRgq08BAt9sd/9AZ yo28f+CNHi3nV6Xudqd6Ovu9ZRNVisx4x8ArxEkYTt51H+wxqqCC+ELXfDLRl3DGVA9M lQbu8DJILIkNmRxmMRJWfQOFn6GgEdReKePohBz/faFg4mpxmRSe74vQQjsfMcHSRbyH OWXLcgHnO0HnT5H5dc3r5Bzgfhb0XjHTytsjeiJErza1YIjyEu++E+kpQDSTSZ/QagOi qTUqGDun+QujgTvNeUpHGwcmpLkjwXxY6VuvaZfENKLGzkjSdooWlHAvXOC9R5y881cQ jTag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=n7f9wguFmSoiW2w5pXwZAtVPCun8fNE4uZJbpmtni8w=; b=evOFSXoaHyLve2eBPe1XjZCoybMwDfRWGjYtqbRhwWQMlI3DTJs4tVe5++fCEK7wcL L3QLcY0CoGbvhtv+T3a0l6wfSvm4mD5p37XQdpeXVAQ/rxZH+gLcI2e92b5SEmwGumD6 BsN85jXWXGeg4ATTKsjg77vyssOBAWktuPkhOaMRSUd2c86We3Zq01kN/jMX7vMNKQZF Dl7MeteJfl/nTicHljvDY6lvGBwRiZvfzRezsIydEHgS/ELK40MmA6bvYlYcQIqRn6eB N6YiVp2lm3llIway1E72xo006sihoDBiCQry3tXHaqjxyfAFAuYbZln8gC+0Kv/3Tgq6 QVWg== X-Gm-Message-State: AODbwcBJXBQ4UUVlrGYj465wegPtGKDqLLnjrDITVWdX8Kt6TXEgIsIT 0+SA6eZxJUEw7gPm X-Received: by 10.223.133.208 with SMTP id 16mr502720wru.199.1497051427996; Fri, 09 Jun 2017 16:37:07 -0700 (PDT) Received: from tsuri.lan (AMontsouris-653-1-246-123.w92-128.abo.wanadoo.fr. [92.128.117.123]) by smtp.gmail.com with ESMTPSA id 94sm2824362wrp.63.2017.06.09.16.37.06 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 09 Jun 2017 16:37:07 -0700 (PDT) Date: Sat, 10 Jun 2017 01:38:20 +0200 From: Matthieu Bouron To: FFmpeg development discussions and patches Message-ID: <20170609233820.GD12885@tsuri.lan> References: <20170609225330.24536-1-matthieu.bouron@gmail.com> <94cddea3-fb8c-82f7-850b-8ccb7877aff7@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <94cddea3-fb8c-82f7-850b-8ccb7877aff7@gmail.com> User-Agent: Mutt/1.8.2 (2017-04-18) Subject: Re: [FFmpeg-devel] [PATCH] lavc/mediacodecdec: switch to the new generic filtering mechanism X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On Fri, Jun 09, 2017 at 08:18:25PM -0300, James Almer wrote: > On 6/9/2017 7:53 PM, Matthieu Bouron wrote: > > --- > > libavcodec/mediacodecdec.c | 70 ++++++++-------------------------------------- > > 1 file changed, 12 insertions(+), 58 deletions(-) > > > > diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c > > index 5bdeb6c1d7..0c77a78aa9 100644 > > --- a/libavcodec/mediacodecdec.c > > +++ b/libavcodec/mediacodecdec.c > > @@ -41,11 +41,9 @@ typedef struct MediaCodecH264DecContext { > > > > MediaCodecDecContext *ctx; > > > > - AVBSFContext *bsf; > > - > > AVFifoBuffer *fifo; > > > > - AVPacket filtered_pkt; > > + AVPacket buffered_pkt; > > > > } MediaCodecH264DecContext; > > > > @@ -58,8 +56,7 @@ static av_cold int mediacodec_decode_close(AVCodecContext *avctx) > > > > av_fifo_free(s->fifo); > > > > - av_bsf_free(&s->bsf); > > - av_packet_unref(&s->filtered_pkt); > > + av_packet_unref(&s->buffered_pkt); > > > > return 0; > > } > > @@ -312,9 +309,6 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx) > > > > const char *codec_mime = NULL; > > > > - const char *bsf_name = NULL; > > - const AVBitStreamFilter *bsf = NULL; > > - > > FFAMediaFormat *format = NULL; > > MediaCodecH264DecContext *s = avctx->priv_data; > > > > @@ -329,7 +323,6 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx) > > #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) > > @@ -339,7 +332,6 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx) > > #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) > > @@ -410,25 +402,6 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx) > > 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); > > @@ -503,10 +476,10 @@ static int mediacodec_decode_frame(AVCodecContext *avctx, void *data, > > /* process buffered data */ > > while (!*got_frame) { > > /* prepare the input data -- convert to Annex B if needed */ > > The second part of this comment can be removed. Fixed. > > > - if (s->filtered_pkt.size <= 0) { > > - AVPacket input_pkt = { 0 }; > > + if (s->buffered_pkt.size <= 0) { > > + AVPacket input_pkt; > > > > - av_packet_unref(&s->filtered_pkt); > > + av_packet_unref(&s->buffered_pkt); > > > > /* no more data */ > > if (av_fifo_size(s->fifo) < sizeof(AVPacket)) { > > @@ -514,36 +487,15 @@ static int mediacodec_decode_frame(AVCodecContext *avctx, void *data, > > 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(input_pkt), NULL); > > input_pkt is unused aside from this, so why not just do > sizeof(s->buffered_pkt) instead and remove input_pkt altogether? Fixed. I removed input_pkt as it was a left-over of the previous code. > > > } > > > > - 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: I also removed the above done label, which is now unused. > > return avpkt->size; > > @@ -560,7 +512,7 @@ static void mediacodec_decode_flush(AVCodecContext *avctx) > > } > > av_fifo_reset(s->fifo); > > > > - av_packet_unref(&s->filtered_pkt); > > + av_packet_unref(&s->buffered_pkt); > > > > ff_mediacodec_dec_flush(avctx, s->ctx); > > } > > @@ -578,6 +530,7 @@ AVCodec ff_h264_mediacodec_decoder = { > > .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 > > > > @@ -594,6 +547,7 @@ AVCodec ff_hevc_mediacodec_decoder = { > > .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 > > LGTM otherwise if it works (Can't test). Thanks for the review. I've done some basic testing and it works but I'll wait a day or two before pushing it. The updated patch is attached. [...] From 04c46b119891fa4c2f0fe41eb72703cffbbf1ae5 Mon Sep 17 00:00:00 2001 From: Matthieu Bouron Date: Sat, 10 Jun 2017 00:41:07 +0200 Subject: [PATCH] lavc/mediacodecdec: switch to the new generic filtering mechanism --- libavcodec/mediacodecdec.c | 74 ++++++++-------------------------------------- 1 file changed, 13 insertions(+), 61 deletions(-) diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c index 5bdeb6c1d7..6962ce2474 100644 --- a/libavcodec/mediacodecdec.c +++ b/libavcodec/mediacodecdec.c @@ -41,11 +41,9 @@ typedef struct MediaCodecH264DecContext { MediaCodecDecContext *ctx; - AVBSFContext *bsf; - AVFifoBuffer *fifo; - AVPacket filtered_pkt; + AVPacket buffered_pkt; } MediaCodecH264DecContext; @@ -58,8 +56,7 @@ static av_cold int mediacodec_decode_close(AVCodecContext *avctx) av_fifo_free(s->fifo); - av_bsf_free(&s->bsf); - av_packet_unref(&s->filtered_pkt); + av_packet_unref(&s->buffered_pkt); return 0; } @@ -312,9 +309,6 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx) const char *codec_mime = NULL; - const char *bsf_name = NULL; - const AVBitStreamFilter *bsf = NULL; - FFAMediaFormat *format = NULL; MediaCodecH264DecContext *s = avctx->priv_data; @@ -329,7 +323,6 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx) #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) @@ -339,7 +332,6 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx) #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) @@ -410,25 +402,6 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx) 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); @@ -502,11 +475,9 @@ static int mediacodec_decode_frame(AVCodecContext *avctx, void *data, /* 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)) { @@ -514,38 +485,17 @@ static int mediacodec_decode_frame(AVCodecContext *avctx, void *data, 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; } @@ -560,7 +510,7 @@ static void mediacodec_decode_flush(AVCodecContext *avctx) } av_fifo_reset(s->fifo); - av_packet_unref(&s->filtered_pkt); + av_packet_unref(&s->buffered_pkt); ff_mediacodec_dec_flush(avctx, s->ctx); } @@ -578,6 +528,7 @@ AVCodec ff_h264_mediacodec_decoder = { .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 @@ -594,6 +545,7 @@ AVCodec ff_hevc_mediacodec_decoder = { .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 -- 2.13.1