From patchwork Tue Jun 12 21:37:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 9383 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp5967764jad; Tue, 12 Jun 2018 14:45:48 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLQgCRocdp95w0Jsk2+z+MzP3522U+u6XBtK7qb0xBRaZTfz377fC/tOlCdDgmkKL6rPkcU X-Received: by 2002:adf:a20a:: with SMTP id p10-v6mr2013424wra.196.1528839948024; Tue, 12 Jun 2018 14:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528839947; cv=none; d=google.com; s=arc-20160816; b=ELJ7L8DuBFykT7pQHyvBg5sFiKGlRD1Gh+W643c4P/CJySRKQrS1W2/JxSY1BvUkTK epMegbOWyE01ftUfvLBgOaK11y//jpH+vyZmL7jzoI7Ble3Y4QwCTYvpwsyjCPxVS2d8 /1tGyfTPzFTkyXVRUmE5Ub/7029xJLrP+qUYgSDuqVI8bIbWSHytjKLpfwhDwqbJsGP+ xUT/QupkCNRJcJ93q3kY/lAd3CmyeNQwvVUokLd+iWDf9Fm6M/iN5h6wISLsGzAogtXr UHPYTj2nGLEodCHoZXiCYaSZbTHy1NR0M4tIm6Cs8IEX9ujXQUgnGnWZQDVmQbF4SW9G hx4w== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=RIucaimOc4ZAzpp1ZRFDtB5nYba6v5eg2MbD6devkCE=; b=S2/x96TbUA7R5REKCsiz1I7UmKUUceSsq7kWMekNnGqZWjt1Zp9REfbT/3YyGuzhtB L9BgSOnXEKdD7vFopCT4yjfuJYb7nuHgKi0TQNAo3EEaNg/KJ0LwffmxASDxM4zC0PcH U2ZSKmMypR0vh1ll5MquVqdyESsReDAo4Qin6AQi4Qwl1X8t1PFY7L/mc96E0sb8KUsc p3yOvyX7a595BgU5oHMj53khrAIM9xKrD4uKN2rZwLm8s8pjoMYzMGjF43ePVfCTewDT vxa3YbJgYKUjoXUhjtcYBCB1ofkdAr6HRW5f8Z+yg6F5i/b7IMAdf6aibtf7qLiDel1P pw4g== 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=hsewvKjx; 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 d12-v6si823466wrs.93.2018.06.12.14.45.47; Tue, 12 Jun 2018 14:45:47 -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=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=hsewvKjx; 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 E92EE68AFEC; Wed, 13 Jun 2018 00:44:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f194.google.com (mail-pf0-f194.google.com [209.85.192.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8B60168AF0D for ; Wed, 13 Jun 2018 00:44:48 +0300 (EEST) Received: by mail-pf0-f194.google.com with SMTP id z24-v6so216631pfe.7 for ; Tue, 12 Jun 2018 14:45:38 -0700 (PDT) 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:in-reply-to:references; bh=8DCGK6sgwWx4No1CInviNmnk9rHz5SaL/mOS+X4jnmw=; b=hsewvKjxe3pZNX/lQSpmlIRD+3MjpBvBADjb+zDaJyCAlbvegLxpxn2nwgSfdnF4Mm S9QB7Wow0Cmm8tVMCETUI0YOmGZym+h0K71g8s60OWrkMhYq2JMBxw9JIZ8qhbFk2X5T P6YFZ7kVZCP5yC7vUbakvJhrvmyhK9KJT3Y7BWgtG/ZmIhXKsdSFtWLW96vLISwAysq1 hCG5jVgx1ABb0mNnN+Hk7zcH0N+ATlpFhJKyqCdewYFP7O+He9nDpNfbAqqLiJOqgVjE mdAdTQGLHDNp75v9zDU+6E3+P75pQdMs7nCbYn0pmq+qooQWlUZTn+kuqate956ocPeU 5xMg== 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 :in-reply-to:references; bh=8DCGK6sgwWx4No1CInviNmnk9rHz5SaL/mOS+X4jnmw=; b=ixPjjno5lgn1FW5MNn4jYPC51f9I9YrIcXpoLClhW4X4PXGmX26YJbKgr+g6o9VtQd ZRqPRX/jKltuQqVUvO6ZW5p/o7YyMw5kVOjL0BMOWO38GjmZ6WQDuCmYIEiRQmBhTmJO esR2lZxuTFHfaadO1mpA79IJ/Ej8hwBLxyViDFFH06nwGw++UB95rQpiPzr81ffwKlT4 qISU14IpKrgqbCDVHJKi6/aHSSz8523dxLNh1BCjqyMcb8J6qOxLDp3lk7pFS2e97TmX CUHhwtoZ54/G3DqkmqeQbCzqu6faZLTIKmrj+pe418FDUtfZOOFjEO98zCb511vlKDJ3 1Y9g== X-Gm-Message-State: APt69E3MRn+5Ya01cbkLkfn+aQrEcqn5/uI0aryekwRM6CVy+xuadL7W /TcfzeFgMEdhPiWWbc9i7G3Qfk0c X-Received: by 2002:a62:4e07:: with SMTP id c7-v6mr2091254pfb.149.1528839473517; Tue, 12 Jun 2018 14:37:53 -0700 (PDT) Received: from localhost.localdomain (c-69-181-54-242.hsd1.ca.comcast.net. [69.181.54.242]) by smtp.gmail.com with ESMTPSA id o72-v6sm1616808pfk.76.2018.06.12.14.37.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Jun 2018 14:37:52 -0700 (PDT) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Jun 2018 14:37:46 -0700 Message-Id: <20180612213746.17225-1-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180322181450.1152-1-ffmpeg@tmm1.net> References: <20180322181450.1152-1-ffmpeg@tmm1.net> Subject: [FFmpeg-devel] [PATCH v2] avcodec/mediacodecdec: work around for decoding h264 with coded fields 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: Aman Gupta MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Gupta This is a hacky work-around for #7092, where the lavc h264 parser splits coded fields into separate video packets, only one of which has a PTS set. The MediaCodec#queueInputBuffer API expects a PTS along with incoming video packets, and breaks badly when the PTS is missing or incorrect (previously it would be passed in as AV_NOPTS_VALUE, but the same breakage happens if you pass in 0 instead). Since it seems there's no easy fix for #7092, this patch stores the previous PTS in the decoder context and re-uses it for the second packet. This emulates the behavior of other Android video players that don't split the coded fields, and pass them as a single buffer with the same timestamp. Signed-off-by: Aman Gupta --- libavcodec/mediacodecdec_common.c | 9 +++++++++ libavcodec/mediacodecdec_common.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c index 40a2ee6778..80cbb7afbd 100644 --- a/libavcodec/mediacodecdec_common.c +++ b/libavcodec/mediacodecdec_common.c @@ -448,6 +448,7 @@ static int mediacodec_dec_flush_codec(AVCodecContext *avctx, MediaCodecDecContex s->eos = 0; atomic_fetch_add(&s->serial, 1); atomic_init(&s->hw_buffer_count, 0); + s->last_pts = AV_NOPTS_VALUE; s->current_input_buffer = -1; status = ff_AMediaCodec_flush(codec); @@ -476,6 +477,7 @@ int ff_mediacodec_dec_init(AVCodecContext *avctx, MediaCodecDecContext *s, atomic_init(&s->refcount, 1); atomic_init(&s->hw_buffer_count, 0); atomic_init(&s->serial, 1); + s->last_pts = AV_NOPTS_VALUE; s->current_input_buffer = -1; pix_fmt = ff_get_format(avctx, pix_fmts); @@ -609,6 +611,13 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s, } pts = pkt->pts; + if (pts == AV_NOPTS_VALUE && s->last_pts != AV_NOPTS_VALUE) { + pts = s->last_pts; + } else if (pts == AV_NOPTS_VALUE) { + av_log(avctx, AV_LOG_WARNING, "Packet is missing PTS!\n"); + pts = 0; + } + s->last_pts = pkt->pts; if (pts != AV_NOPTS_VALUE && avctx->pkt_timebase.num && avctx->pkt_timebase.den) { pts = av_rescale_q(pts, avctx->pkt_timebase, AV_TIME_BASE_Q); } diff --git a/libavcodec/mediacodecdec_common.h b/libavcodec/mediacodecdec_common.h index d280236b8e..9f22006e12 100644 --- a/libavcodec/mediacodecdec_common.h +++ b/libavcodec/mediacodecdec_common.h @@ -69,6 +69,8 @@ typedef struct MediaCodecDecContext { bool delay_flush; atomic_int serial; + int64_t last_pts; + } MediaCodecDecContext; int ff_mediacodec_dec_init(AVCodecContext *avctx,