From patchwork Tue Aug 31 20:45:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Linn X-Patchwork-Id: 29932 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp5267161iov; Tue, 31 Aug 2021 13:46:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe2tUWBbKdEw+JFe7Dw2YqCvxv1oYdoNGxQEWVSbCeeyiTGv3S6nF2ViAfHEh9xCtHQNUN X-Received: by 2002:a17:906:314e:: with SMTP id e14mr33362494eje.165.1630442790185; Tue, 31 Aug 2021 13:46:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630442790; cv=none; d=google.com; s=arc-20160816; b=N/woSf3wONGDnbZMQnWCpIPqBr8E9ghU5DIj6kFiXqgZilInnwY+VIuF9nUyjSYk4d waMU8X97Mtaho/d/10a+OeEu+tF7AFnR5bkHmdHdm7pInAsnvqrkdQNS1IzBJuJiIVme PhIPETqN9+4hiDIsgkB4MM++j7QFjfAvzsYqIpAPDgGPQE2WwmgvfJ0kcTyWepEhgrGj D/xyoMZwCfeaM6EfKmAJ32KXdOaaXyGZN8GKeMZG+Ru/2pXGIr2jWOWiCvNCFbHevLUJ acgz2ObllckAP9dQp41MhPlAo9Wq8rFrY+StsgjpJzvTVMAjDsLw12IlTvSPL1rqYx0K RzEw== 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:message-id:date:to :dkim-signature:from:delivered-to; bh=Wsqii9BA3AnW/c5MXo/zm9OdBcCXze1zJJBLL7auYGU=; b=UhZbp9gwmFCE5McBl528ve8yuYOP2JWBK6XFQQ2TbN4gFgKIIQrvgh7+/83/twxyGq o6s6AVLE/KkTakKFZ7cXfwGXDDluXqh3m4OAgc9jGBIKyi9kRyJa7LtoaCAeWPxj03Q6 00KwkOPmb+3mHp+cCm3D/Ros6wr0sqxsLsObD8Yy6ov8NV3XKvDQxqlws3FUHaEP2S2M qAYxkeU9dx6xPceVJvtrBT1r+dLLnWt/Mz2Ae6Ow1KHK5ir1sWBvsTy2MfEFcfyN7OnT bkr79OSTM8EY4dDf0kGu162pV8miwQ/ootAQfD+pjW9tvbungvAWk5I50WdO4D+ISbfe 6fSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@conductive.de header.s=key1 header.b="KJPYS/si"; 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 j17si4485419ejm.446.2021.08.31.13.46.20; Tue, 31 Aug 2021 13:46:30 -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="KJPYS/si"; 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 69759689F3A; Tue, 31 Aug 2021 23:46:16 +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 774316808FC for ; Tue, 31 Aug 2021 23:46:09 +0300 (EEST) From: Joel Linn DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=conductive.de; s=key1; t=1630442768; bh=A+4QFPQv7gnoxLDpqgGratEXeEFtVM4IIpAo2+/0TFE=; h=From:To:Cc:Subject:Date; b=KJPYS/siEOCD3l2Eoq3cn2b4XihoglULt3es1oNa7IKNTca/rXpJXfj1Q7BdlYY33 ulyE2E2wkTzjADH3bfkOkW4pyJhda6yR/h1OkBaHColoiA6oc1QbWxXii2IjVC0Eyn 2tu0d1419N8y3BgjfmIKn626WS9WkpIlTXWnlU5giXGwK3mA/d3398KAVjLLfgTBWh exWshHwlZf69AXMj0NGzOr3ASw96GqLfDJprTnzRvqn9FRxVi+xOp30zdLLuempxBs wZLBsiHVacRrvBhD2QkqbQ1NXQspn0zN5IggSnrvudBKNGkRXVynefnfqDhE28akOr Jz80+oSRKM3lg== To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Aug 2021 22:45:47 +0200 Message-Id: <20210831204547.25082-1-jl@conductive.de> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] 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: U6OGXIZLGdPN Support decoding only a selection of the encoded XMA streams. Previously, the decoder assumed it was decoding all available streams. --- libavcodec/wmaprodec.c | 64 ++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c index 66271c4037..95e039c14e 100644 --- a/libavcodec/wmaprodec.c +++ b/libavcodec/wmaprodec.c @@ -1814,7 +1814,43 @@ 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, offset, skip_current_packet = 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 +1882,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]);