From patchwork Fri Sep 6 13:57:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Bouron X-Patchwork-Id: 14956 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id E2D73447858 for ; Fri, 6 Sep 2019 16:58:17 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C3D8C68803B; Fri, 6 Sep 2019 16:58:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F261687FBD for ; Fri, 6 Sep 2019 16:58:12 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id t9so7214260wmi.5 for ; Fri, 06 Sep 2019 06:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bZkY5g5lOx9kEI1jSbzf3UG+yGALVP/I5CApkCjCRFg=; b=ArZyBWHaG6lNywuoS73EC8RuTCj3B3uRsL/hcnnTKp+9sM2AFTa02T/CIl6ihoTQjr Z58JeLd8aNE1UCRpKRc3r8UbW87J9T8eeBWWPA8WbFNMn8Iszp7NPUJHwSq7VNrQTq5D 94Zl70BJSlVaDvchEEbfZ2Ni0GeutvYI4cWlOhEDQGkX/Rpj53tiToKKdilnNwIYtEFN oSjviA/M/GEVx341EYAb2KAVm83ySRl9Tafq+kr/j2BQARtQuJOclYWXBd5hWEzSocaH /OUgP2YbaqXtB79ikqBrat/y399CnLXnDqj3QDb3oF/dNxZ4b2Qt14GJI6MyNX1SkR0M fAsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bZkY5g5lOx9kEI1jSbzf3UG+yGALVP/I5CApkCjCRFg=; b=BB0CzQInYqWBTssYtrdXkw15XTh9Sl57Tmmnb2My4ygV1vhFeE9x/qiwxLXVH/ZUyF icrVqMKDs/2austqK2QBJVa1y6G4KdHuGebdxtKECWJySui3Lnt9JCbl93wMBfy/lA7r jiP9/Hi9zoM2oxSdhRYap9KXGTxUxGWY010M2yRUMWrjyYaDwHGu+LHmoamNpuxxlfl9 mzNjUm5Nrnv/BYy7yxTmsTVF4uvUg697KWLPwofXOa+MhAUcvpJ5XCeE2jSjHW6lon3O MxZAVEoF7osWCPBHNvz6Z2JdiImAg8dnAHCaxwIkOV8Pmp+4vuQEoJOrLuLr5y7OeuLu ONJA== X-Gm-Message-State: APjAAAWlYOuIU+zdta+bdILrUTauLRQgAIZH8CCCvNI6OMAZuVyt09j6 guBrnCstuDl4PAxDCOVfFiRtyN2v X-Google-Smtp-Source: APXvYqwZoXkLOMgw/ysFyBog8PfQGY6L0cETQ3HxJ92qiQoHw24NxbOMk3p93hcb6RqcwHFoWYmD7w== X-Received: by 2002:a05:600c:2056:: with SMTP id p22mr7200941wmg.155.1567778291467; Fri, 06 Sep 2019 06:58:11 -0700 (PDT) Received: from boken.gopro.lcl (73.136-14-84.ripe.coltfrance.com. [84.14.136.73]) by smtp.gmail.com with ESMTPSA id w1sm5899585wrm.38.2019.09.06.06.58.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2019 06:58:10 -0700 (PDT) From: Matthieu Bouron To: ffmpeg-devel@ffmpeg.org Date: Fri, 6 Sep 2019 15:57:58 +0200 Message-Id: <20190906135758.14768-2-matthieu.bouron@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190906135758.14768-1-matthieu.bouron@gmail.com> References: <20190906135758.14768-1-matthieu.bouron@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/mediacodecdec_common: do not split input packets into multiple buffers in ff_mediacodec_dec_send() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" MediaCodec expects exactly one incoming buffer with a given PTS, it is not valid to split data for a given PTS across multiple input buffers. See https://developer.android.com/reference/android/media/MediaCodec#data-processing > Do not submit multiple input buffers with the same timestamp --- libavcodec/mediacodecdec_common.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c index 6c0a1212c1..74fa29cc7d 100644 --- a/libavcodec/mediacodecdec_common.c +++ b/libavcodec/mediacodecdec_common.c @@ -566,7 +566,6 @@ fail: int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, AVPacket *pkt, bool wait) { - int offset = 0; int need_draining = pkt->size == 0; uint8_t *data; ssize_t index = s->current_input_buffer; @@ -586,12 +585,15 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, return AVERROR_EOF; } - while (offset < pkt->size || (need_draining && !s->draining)) { + if (s->draining) { + return 0; + } + if (index < 0) { index = ff_AMediaCodec_dequeueInputBuffer(codec, input_dequeue_timeout_us); if (ff_AMediaCodec_infoTryAgainLater(codec, index)) { av_log(avctx, AV_LOG_TRACE, "No input buffer available, try again later\n"); - break; + return AVERROR(EAGAIN); } if (index < 0) { @@ -630,9 +632,8 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, return 0; } - size = FFMIN(pkt->size - offset, size); - memcpy(data, pkt->data + offset, size); - offset += size; + size = FFMIN(pkt->size, size); + memcpy(data, pkt->data, size); status = ff_AMediaCodec_queueInputBuffer(codec, index, 0, size, pts, 0); if (status < 0) { @@ -642,11 +643,8 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, av_log(avctx, AV_LOG_TRACE, "Queued input buffer %zd size=%zd ts=%"PRIi64"\n", index, size, pts); - } - if (offset == 0) - return AVERROR(EAGAIN); - return offset; + return size; } int ff_mediacodec_dec_receive(AVCodecContext *avctx, MediaCodecDecContext *s,