From patchwork Fri Dec 29 00:36:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 7004 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.79.195 with SMTP id r64csp9889227jad; Thu, 28 Dec 2017 16:44:21 -0800 (PST) X-Google-Smtp-Source: ACJfBovP1WsSIShL4xTiwFh/8X5c4aQAbyMar3i1tDe6jZyCxxej1ALPvElcXcWjI5MKOlqpx5MK X-Received: by 10.223.196.211 with SMTP id o19mr36426494wrf.240.1514508261243; Thu, 28 Dec 2017 16:44:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514508261; cv=none; d=google.com; s=arc-20160816; b=zodl0iCVN3jnRipKgMNPMPAKm24y1Hwy9A8DR24rWQ/4XC4URRmrqaQSCwbhxqheiQ xNBSAlEYSdqDqvVawPzWjvI0xG2vtBQX3xSXaxJIHAnnS697Az3hfYqnPZEZQa6v24eV CdTG3SUXGVSlmNCX2TLuHqq8MfD+JBSD0HRCtJsmVx+mv3YAQ5QHrrVx1nOLlXxvVha9 Rc1fm4/MkO3E7hyTODxbBuzSGlAuXEHCUEiUAgJDO2JXIcwq1kOgvR7AjLc6X0D2/DQ9 9UDtptxlvuRfybNEH/9B77QGvfBUlJwu5JM+5PnXuBBTBTSOk5f9axvH7xwAjIL+bn9F +epQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=I5YK+se2HdiXJo619CWV/e+M8FcnNlErJdVWHU5QkTg=; b=UNGu8FvcEddk8JV37hw3zc/A7M/D3dT/5H+lPcyXgbcPTzY4YHqFxjI1wkZcyPR3nb 3DMBPy51bklZ9u7TNVbVG5hWF2+pdD5kpemEuXCFEhJlYu6IHF8xU2Q66+ylG41Ok0EL qubQdOOU/ScdAWk2SruA7MmxN5lHK08dL9W1pFKVVc7aUnSLJgL31Hde3omvZHOYFkxz tTPTfFE5k/mjCZJwVpG9QT++tTqWJw66+jNtNLv0DI3e0Uq5pi5pYBIFxf5RALmgXSbj AaBP+MXPNBc5xJtXCBpWWwcKnZAtWsPGXQUE2ELJx8T+eXjkCfSZeqnJRKRvEbH3SEP8 0RHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=yXg9shKh; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w42si4443221wrb.38.2017.12.28.16.44.20; Thu, 28 Dec 2017 16:44:21 -0800 (PST) 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=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=yXg9shKh; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D481D6883E1; Fri, 29 Dec 2017 02:44:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0FDD368834E for ; Fri, 29 Dec 2017 02:43:58 +0200 (EET) Received: by mail-pl0-f68.google.com with SMTP id g2so22057616pli.8 for ; Thu, 28 Dec 2017 16:44:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tmm1-net.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id; bh=/pJjJPsBY1Zgu9oKUOmgaSAZOtip78XW1KtF1O7ZE08=; b=yXg9shKhztlbVSEG9whUFy41G7SVyb6m0LP5Zv46Do980KI/b475OycYK9hyXcknr3 cwXKbBeXiwt8tAAEvOM54paVkC+jlTevcNAYHx58DzBtABaVf8nIioqxR0eOTrLwVW7I KOnWsK6HvqXpk4NoHkYzwXCNuWd9zHI6sLSwhMglBe94h+X0k1jhcMF4gW9PVvrdEx5t 1notERoBrQjEdwY9YXPVQkf4wD2QOX81n8TVB2Nhowpc3us7uY44TRnmNRr7cgkTkpop apqfUg4miAwFjIUs1QOUgVrfC7xwfBtKfW98luh5l0TaDUKH4CEfj1VkhnWEUgBWsAtB ZWvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=/pJjJPsBY1Zgu9oKUOmgaSAZOtip78XW1KtF1O7ZE08=; b=mUr5aTrpo6L/yvvSwCi1CGpoC62LpSW58I9qnooTJklQs2BGgJF1VVp44MSKhfnx6e VnnO4PYTjAKQSeswSOvgqOimEzLoaweIwPf51YdgLDRUIPgfo8dHOhfcKATdFZAoetdW tIJQ0tGLNAqsLEPeUmia2kJQdBLu8IWx1DdPBeE4MG/HDF6os1jEH1MqenjFbHBpTG3+ YxUwm7jWMD/w8ueKk3WPtvLCGRtkC4PcL40QDxODH058PJAhK+lfyiuBFiCDwkkoowww GsxwRMZ243Z+fh/WBwbZdItQZyoZ37XDC5dp0iHNDmJgOUOl+OUrc5E7nfXfV2mD7fsp D+OA== X-Gm-Message-State: AKGB3mJqcJ4ySRWQfHvkZgIdm7NeJR89PQMCFK6TwhhdqOsx8U7ahNSF P6zlFCDZWLaKlX5t/J1xpY6NF7Dv X-Received: by 10.84.235.68 with SMTP id g4mr33212087plt.155.1514507816570; Thu, 28 Dec 2017 16:36:56 -0800 (PST) Received: from localhost.localdomain (c-69-181-54-242.hsd1.ca.comcast.net. [69.181.54.242]) by smtp.gmail.com with ESMTPSA id w10sm33094766pgc.28.2017.12.28.16.36.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Dec 2017 16:36:55 -0800 (PST) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Dec 2017 16:36:53 -0800 Message-Id: <20171229003653.66604-1-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.14.2 Subject: [FFmpeg-devel] [PATCH] libavcodec/mediacodecdec: update to use new decoding api 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 Cc: matthieu.bouron@gmail.com, Aman Gupta MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Gupta --- libavcodec/mediacodecdec.c | 75 ++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 32 deletions(-) diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c index b698ceaef9..29f1076bb0 100644 --- a/libavcodec/mediacodecdec.c +++ b/libavcodec/mediacodecdec.c @@ -31,6 +31,7 @@ #include "libavutil/pixfmt.h" #include "avcodec.h" +#include "decode.h" #include "h264_parse.h" #include "hevc_parse.h" #include "hwaccel.h" @@ -424,29 +425,12 @@ static int mediacodec_process_data(AVCodecContext *avctx, AVFrame *frame, return ff_mediacodec_dec_decode(avctx, s->ctx, frame, got_frame, pkt); } -static int mediacodec_decode_frame(AVCodecContext *avctx, void *data, - int *got_frame, AVPacket *avpkt) +static int mediacodec_receive_frame(AVCodecContext *avctx, AVFrame *frame) { MediaCodecH264DecContext *s = avctx->priv_data; - AVFrame *frame = data; int ret; - - /* buffer the input packet */ - if (avpkt->size) { - AVPacket input_pkt = { 0 }; - - if (av_fifo_space(s->fifo) < sizeof(input_pkt)) { - ret = av_fifo_realloc2(s->fifo, - av_fifo_size(s->fifo) + sizeof(input_pkt)); - if (ret < 0) - return ret; - } - - ret = av_packet_ref(&input_pkt, avpkt); - if (ret < 0) - return ret; - av_fifo_generic_write(s->fifo, &input_pkt, sizeof(input_pkt), NULL); - } + int got_frame = 0, pkt_size = 0; + AVPacket pkt = {0}, *avpkt = &pkt; /* * MediaCodec.flush() discards both input and output buffers, thus we @@ -470,26 +454,50 @@ static int mediacodec_decode_frame(AVCodecContext *avctx, void *data, */ if (ff_mediacodec_dec_is_flushing(avctx, s->ctx)) { if (!ff_mediacodec_dec_flush(avctx, s->ctx)) { - return avpkt->size; + return 0; + } + return AVERROR(EAGAIN); + } + + ret = ff_decode_get_packet(avctx, avpkt); + if (ret < 0 && ret != AVERROR_EOF) + return ret; + pkt_size = avpkt->size; + + /* buffer the input packet */ + if (avpkt->size) { + AVPacket input_pkt = { 0 }; + + if (av_fifo_space(s->fifo) < sizeof(input_pkt)) { + ret = av_fifo_realloc2(s->fifo, + av_fifo_size(s->fifo) + sizeof(input_pkt)); + if (ret < 0) + return ret; } + + ret = av_packet_ref(&input_pkt, avpkt); + if (ret < 0) + return ret; + av_fifo_generic_write(s->fifo, &input_pkt, sizeof(input_pkt), NULL); } + av_packet_unref(avpkt); /* process buffered data */ - while (!*got_frame) { + while (!got_frame) { /* 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)) { - return avpkt->size ? avpkt->size : - ff_mediacodec_dec_decode(avctx, s->ctx, frame, got_frame, avpkt); + return pkt_size ? AVERROR(EAGAIN) : + ff_mediacodec_dec_decode(avctx, s->ctx, frame, &got_frame, avpkt); } av_fifo_generic_read(s->fifo, &s->buffered_pkt, sizeof(s->buffered_pkt), NULL); } - ret = mediacodec_process_data(avctx, frame, got_frame, &s->buffered_pkt); + ret = mediacodec_process_data(avctx, frame, &got_frame, &s->buffered_pkt); if (ret < 0) return ret; @@ -497,7 +505,10 @@ static int mediacodec_decode_frame(AVCodecContext *avctx, void *data, s->buffered_pkt.data += ret; } - return avpkt->size; + if (got_frame) + return 0; + + return AVERROR(EAGAIN); } static void mediacodec_decode_flush(AVCodecContext *avctx) @@ -537,7 +548,7 @@ AVCodec ff_h264_mediacodec_decoder = { .id = AV_CODEC_ID_H264, .priv_data_size = sizeof(MediaCodecH264DecContext), .init = mediacodec_decode_init, - .decode = mediacodec_decode_frame, + .receive_frame = mediacodec_receive_frame, .flush = mediacodec_decode_flush, .close = mediacodec_decode_close, .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, @@ -556,7 +567,7 @@ AVCodec ff_hevc_mediacodec_decoder = { .id = AV_CODEC_ID_HEVC, .priv_data_size = sizeof(MediaCodecH264DecContext), .init = mediacodec_decode_init, - .decode = mediacodec_decode_frame, + .receive_frame = mediacodec_receive_frame, .flush = mediacodec_decode_flush, .close = mediacodec_decode_close, .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, @@ -575,7 +586,7 @@ AVCodec ff_mpeg2_mediacodec_decoder = { .id = AV_CODEC_ID_MPEG2VIDEO, .priv_data_size = sizeof(MediaCodecH264DecContext), .init = mediacodec_decode_init, - .decode = mediacodec_decode_frame, + .receive_frame = mediacodec_receive_frame, .flush = mediacodec_decode_flush, .close = mediacodec_decode_close, .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, @@ -593,7 +604,7 @@ AVCodec ff_mpeg4_mediacodec_decoder = { .id = AV_CODEC_ID_MPEG4, .priv_data_size = sizeof(MediaCodecH264DecContext), .init = mediacodec_decode_init, - .decode = mediacodec_decode_frame, + .receive_frame = mediacodec_receive_frame, .flush = mediacodec_decode_flush, .close = mediacodec_decode_close, .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, @@ -611,7 +622,7 @@ AVCodec ff_vp8_mediacodec_decoder = { .id = AV_CODEC_ID_VP8, .priv_data_size = sizeof(MediaCodecH264DecContext), .init = mediacodec_decode_init, - .decode = mediacodec_decode_frame, + .receive_frame = mediacodec_receive_frame, .flush = mediacodec_decode_flush, .close = mediacodec_decode_close, .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, @@ -629,7 +640,7 @@ AVCodec ff_vp9_mediacodec_decoder = { .id = AV_CODEC_ID_VP9, .priv_data_size = sizeof(MediaCodecH264DecContext), .init = mediacodec_decode_init, - .decode = mediacodec_decode_frame, + .receive_frame = mediacodec_receive_frame, .flush = mediacodec_decode_flush, .close = mediacodec_decode_close, .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE,