From patchwork Wed Sep 1 08:44:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Linn X-Patchwork-Id: 29936 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp351137iov; Wed, 1 Sep 2021 01:45:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK5m9JxpaDhZly0TI7aF+GTiC66s4xGxQX6oWM/71sz4p+g1MDPQyynAHpVeTiWlzKECmc X-Received: by 2002:a17:906:2bd0:: with SMTP id n16mr35900118ejg.132.1630485948412; Wed, 01 Sep 2021 01:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630485948; cv=none; d=google.com; s=arc-20160816; b=RymvCVG7gjA160alIEU3XdUxDOsiSKtXY6ZGjmes9IFdL5GqsNoCdWdoEalAtzemWc lCpqvPJ59UJ8KmjClKs8RjVZeDCD1COXyVfdFQ+JEK9KVMcrbgIeT84q7wgqvM0zDjJ+ teF08RIoCpToQWJDxEM9qiB+Nj9NLN8DAs/wnDqCqRkW5Xy0tGFB6+7Jd4gan1EaAStM xSO54XEclnwv/FGL2ckPsNLSpJMnlhbkYCsbwJoA03evJeRBMWHduLw5jLD9D28tplGY zPnJUDdKfGIutQ9KN1RxTSjUIDPdTQCLbYmPdKDQX9DXK9xWPrbEv1PMjdGhguncTvyC hqKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:dkim-signature:from:delivered-to; bh=SuLpDNV2BUfZ3c4Oo3/yRgThbY554tPOBEgPz8//sbs=; b=eS+C+rVcsSxOdh6ksiOqudObWhrWXizpeUiyDCqydphWUfj/TDYXJjNRxqMeNSq9ej MRG/eF/zPX3c3MT4MDNWMbvlrIy0w2cNw/UXPXuDol8JPPzf1TY15o/w2w8u0RwWQg6D wiWjibBb65jXVvrPVPpNf9626zJUp2ACSRM7NLCNStzLq+MNLgfAbgjr8tFSqMPrX12b yEVWVaiTfSqqBdte3hxoAYurDh1M6qjo4/5kFL1TI8/EcRG55EbAFfihv57F+5WgAWMr dZTAI+Sq4nheOWfB/2Xg5R0bIs6baMDeIeJh3may/s5EgFRcWnIohBcPjm9sLgfNZs3M Ydsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@conductive.de header.s=key1 header.b=dLmFqyqE; 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=conductive.de Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e21si20507199edj.249.2021.09.01.01.45.37; Wed, 01 Sep 2021 01:45:48 -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=@conductive.de header.s=key1 header.b=dLmFqyqE; 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=conductive.de Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9507368A36E; Wed, 1 Sep 2021 11:45:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.leuchtkanone.de (mail.leuchtkanone.de [5.189.166.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 619A468A0EA for ; Wed, 1 Sep 2021 11:45:27 +0300 (EEST) From: Joel Linn DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=conductive.de; s=key1; t=1630485926; bh=KW5fDQfAuqe5IpLQ22F1ngdxabseWG1Pc+io60l7SYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dLmFqyqECZDgRksOI8C0dTkiTPMsqeKgy8dzlitVgZ25HE5e1zP3/U3+PUgJ+JMbY 8VNFEgEpPhyhnszoclfppO2CuUakOqSoJ6Ykk2FmyuvG+v7dif4dEgJ2o/jBvcd//i L4Zb0igBukOUJpFaveB9EatvCKGFItIZgxKq+lNC0oI4FqAQHjTYE9ri46bbxnM2ML D+sd5KHA69cM8oYb9uQBHSe0ZH6OZAlpbhopFsGqn6CBlDRAN0r2zSrA0PiB1nPsZA +/G+l8WfX+vMq+ebGEaTzPbayQhKokpdNVgNHHAqFKVI58KdZ+C98CA07UwJDAelK2 Ww8LuBYjU1g4w== To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Sep 2021 10:44:43 +0200 Message-Id: <20210901084443.56245-1-jl@conductive.de> In-Reply-To: <20210831204547.25082-1-jl@conductive.de> References: <20210831204547.25082-1-jl@conductive.de> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avcodec/wmaprodec: skip foreign XMA packets X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Joel Linn Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: TSzIDqhRWbd+ Support decoding only a selection of the encoded XMA streams. Previously, the decoder assumed it was decoding all available streams. --- libavcodec/wmaprodec.c | 65 ++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c index 66271c4037..b957b1d1ea 100644 --- a/libavcodec/wmaprodec.c +++ b/libavcodec/wmaprodec.c @@ -1814,7 +1814,44 @@ static int xma_decode_packet(AVCodecContext *avctx, void *data, XMADecodeCtx *s = avctx->priv_data; int got_stream_frame_ptr = 0; AVFrame *frame = data; - int i, ret, offset = INT_MAX; + int i, ret, skip_current_packet; + int offset = INT_MAX; + + /* find the owner stream of the new XMA packet that belongs to on of our streams + * XMA streams find their packets following packet_skips + * there may be other packets in between if we are not responsible for all streams + * (at start there is one packet per stream, then interleave non-linearly). */ + if (s->xma[s->current_stream].packet_done || + s->xma[s->current_stream].packet_loss) { + /* select stream with lowest skip_packets (= uses next packet) */ + if (s->xma[s->current_stream].skip_packets != 0) { + int min[2]; + + min[0] = s->xma[0].skip_packets; + min[1] = i = 0; + + for (i = 1; i < s->num_streams; i++) { + if (s->xma[i].skip_packets < min[0]) { + min[0] = s->xma[i].skip_packets; + min[1] = i; + } + } + + s->current_stream = min[1]; + } + + skip_current_packet = !!s->xma[s->current_stream].skip_packets; + + /* advance all stream packet skip counts */ + for (i = 0; i < s->num_streams; i++) { + s->xma[i].skip_packets = FFMAX(0, s->xma[i].skip_packets - 1); + } + + /* if we are not responsible for every stream, make sure we ignore + * XMA packets not belonging to one of our streams */ + if (skip_current_packet) + return avctx->block_align; + } if (!s->frames[s->current_stream]->data[0]) { s->frames[s->current_stream]->nb_samples = 512; @@ -1846,34 +1883,8 @@ static int xma_decode_packet(AVCodecContext *avctx, void *data, return ret; } - /* find next XMA packet's owner stream, and update. - * XMA streams find their packets following packet_skips - * (at start there is one packet per stream, then interleave non-linearly). */ if (s->xma[s->current_stream].packet_done || s->xma[s->current_stream].packet_loss) { - - /* select stream with 0 skip_packets (= uses next packet) */ - if (s->xma[s->current_stream].skip_packets != 0) { - int min[2]; - - min[0] = s->xma[0].skip_packets; - min[1] = i = 0; - - for (i = 1; i < s->num_streams; i++) { - if (s->xma[i].skip_packets < min[0]) { - min[0] = s->xma[i].skip_packets; - min[1] = i; - } - } - - s->current_stream = min[1]; - } - - /* all other streams skip next packet */ - for (i = 0; i < s->num_streams; i++) { - s->xma[i].skip_packets = FFMAX(0, s->xma[i].skip_packets - 1); - } - /* copy samples from buffer to output if possible */ for (i = 0; i < s->num_streams; i++) { offset = FFMIN(offset, s->offset[i]);