From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 8ABB64BB9C for ; Wed, 21 May 2025 22:06:32 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 1F1F368DD52; Thu, 22 May 2025 01:05:56 +0300 (EEST) Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 91D9468DD29 for ; Thu, 22 May 2025 01:05:47 +0300 (EEST) Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-2dfe2913a4bso1605173fac.1 for ; Wed, 21 May 2025 15:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747865146; x=1748469946; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2L24h5QY+p/8ysJQIed4rxUqTvS/nddfP6BzrceCCb4=; b=STA3UIR0ifDrEvu973eMyRRDMSy2XxN38Tje0WtAsrWLAHaGmbNibHgG7dKh9P8h9b Apmnw2TwRTTsWvlSKU34XXyQ89W7VnpIpaApyKRMuLdqKJulA0wvCD7Zj3xaI24JWLNh FOsJzfoQ9DAu3d4pISNmO4AV+4Cc7H6KHYl10uizTIYhhzUjR5Vhm+xW8FJrMjJ0EvZB DI/ujjpEgZQ7Fx/GX0YnNa9v4hQXLTEtB5jDeQzdRXeDtmc/lvUqQTBa2JHq5SHZvuGb wtfXya/Lb4RwGycS3UFz7DzLNENgdoTcpAZgo8YDU/wERQ+J3ICQk0mbDFM4qd3R6tQo SEtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747865146; x=1748469946; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2L24h5QY+p/8ysJQIed4rxUqTvS/nddfP6BzrceCCb4=; b=UuuUxw7nt5KVrklaDRRZBHd61OlLTmKhYvIsjrAIXx2zb7oEtT0hZ08MCY2CZv9ZIE x+EYwuvOUOyIyLf9gCEzvhvAwwWRNz1X9bMiNsdU2OYChNlEyLBeEsyFGZv/y0zWfcWA OepmXFV4p6SOKPDpgObZnoaxt+Iif0ctqOXMkaZgCEZh2cEn/0JpmEqWc2wFRDf+gb/r NXi4KHhkIP377DAUC1vBsuboqBjTXj1227MLLnhitkZATbinSESsAN9VTo2+PFXwAiZX X9WMWW2MsNiD11fpcMlAHwcnGe8WGF5sGTtjccANRfvit7OExHlF5Xnl9/dgL3BuDm9n pToA== X-Gm-Message-State: AOJu0YxERL9JUm40TlgTk75UTyOXYQ6EroeQD53Ow8rfin4jeBmnfOq6 V4kFwrbqN3LolFUbiIMoh1Vu8nKkomUUKFOPjtmSIeL19KEnUAz5XuxumcPgwAHg X-Gm-Gg: ASbGncvz3TH3jFA/0T2XJx5MmJ12OqpNZLZCscbJMYhrBd60qRkAi7ehAMfEtDSIuxo /RXOn91NFSodVQiAavlAl6YmBGqaKHHwaqdjRU9m/nOfxg8pN+Y6lTzesAYvepZk6MAxT+bQSLy gmM6I3Ek69vYONv3wWbBzdlXfvESmlEQXjdqSXIRMbPB5VtauT2MlD4GFpj8C+aK17uW/XX3PeV yXZK+Atc6lklMkTjlGwWX0qh7tf/ewr4o2iFY/5FkfX85e6Wjc2QcQjT8+8xIJY7jDBA1sxChqd L8/AmOL4sENRbcltud5HNuqItr44UjmiEGU55raYff5oSTzniqTbINvWpSIrXspcKchh8mbZKmR d6Gvvbx+wD/yMK6vUPYc= X-Google-Smtp-Source: AGHT+IEBRw28OTAqlpyBITcMJG/0Tdh1pQzbkqaLu3usR+Bwj+ooXZvLRgVP6EX2DD53mzMJpTDiRA== X-Received: by 2002:a05:6870:596:b0:2d6:49e3:2e25 with SMTP id 586e51a60fabf-2e3c8184fe5mr15329093fac.2.1747865145542; Wed, 21 May 2025 15:05:45 -0700 (PDT) Received: from mac.lan (ip72-211-125-114.no.no.cox.net. [72.211.125.114]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-734f6b6066fsm2282245a34.68.2025.05.21.15.05.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 21 May 2025 15:05:45 -0700 (PDT) From: Romain Beauxis To: ffmpeg-devel@ffmpeg.org Date: Wed, 21 May 2025 17:05:37 -0500 Message-Id: <20250521220538.16624-4-romain.beauxis@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250521220538.16624-1-romain.beauxis@gmail.com> References: <20250521220538.16624-1-romain.beauxis@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 3/4] ogg/vorbis: implement header packet skip in chained ogg bitstreams. 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: Romain Beauxis Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- libavcodec/vorbis_parser.h | 11 ++++ libavcodec/vorbisdec.c | 75 +++++++++++++--------- libavformat/oggparsevorbis.c | 63 +++++++++++++++++- tests/ref/fate/ogg-vorbis-chained-meta.txt | 3 - 4 files changed, 115 insertions(+), 37 deletions(-) diff --git a/libavcodec/vorbis_parser.h b/libavcodec/vorbis_parser.h index 789932ac49..b176fe536c 100644 --- a/libavcodec/vorbis_parser.h +++ b/libavcodec/vorbis_parser.h @@ -30,6 +30,17 @@ typedef struct AVVorbisParseContext AVVorbisParseContext; +/** + * Used by the vorbis parser to pass new chained stream headers + * as extradata. + */ +typedef struct vorbis_new_extradata { + uint8_t *header; + size_t header_size; + uint8_t *setup; + size_t setup_size; +} vorbis_new_extradata; + /** * Allocate and initialize the Vorbis parser using headers in the extradata. */ diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c index adbd726183..6c5d3fa50f 100644 --- a/libavcodec/vorbisdec.c +++ b/libavcodec/vorbisdec.c @@ -43,6 +43,7 @@ #include "vorbis.h" #include "vorbisdsp.h" #include "vorbis_data.h" +#include "vorbis_parser.h" #include "xiph.h" #define V_NB_BITS 8 @@ -1778,47 +1779,59 @@ static int vorbis_decode_frame(AVCodecContext *avctx, AVFrame *frame, GetBitContext *gb = &vc->gb; float *channel_ptrs[255]; int i, len, ret; + size_t new_extradata_size; + vorbis_new_extradata *new_extradata; + const uint8_t *header; + const uint8_t *setup; ff_dlog(NULL, "packet length %d \n", buf_size); - if (*buf == 1 && buf_size > 7) { - if ((ret = init_get_bits8(gb, buf + 1, buf_size - 1)) < 0) - return ret; + new_extradata = (vorbis_new_extradata *)av_packet_get_side_data( + avpkt, AV_PKT_DATA_NEW_EXTRADATA, &new_extradata_size); - vorbis_free(vc); - if ((ret = vorbis_parse_id_hdr(vc))) { - av_log(avctx, AV_LOG_ERROR, "Id header corrupt.\n"); - vorbis_free(vc); - return ret; - } + if (new_extradata) { + header = new_extradata->header; + setup = new_extradata->setup; - av_channel_layout_uninit(&avctx->ch_layout); - if (vc->audio_channels > 8) { - avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; - avctx->ch_layout.nb_channels = vc->audio_channels; - } else { - av_channel_layout_copy(&avctx->ch_layout, &ff_vorbis_ch_layouts[vc->audio_channels - 1]); - } + if (header && *header == 1 && new_extradata->header_size > 7) { + if ((ret = init_get_bits8( + gb, header + 1, + new_extradata->header_size - 1)) < 0) + return ret; - avctx->sample_rate = vc->audio_samplerate; - return buf_size; - } + vorbis_free(vc); + if ((ret = vorbis_parse_id_hdr(vc))) { + av_log(avctx, AV_LOG_ERROR, "Id header corrupt.\n"); + vorbis_free(vc); + return ret; + } - if (*buf == 3 && buf_size > 7) { - av_log(avctx, AV_LOG_DEBUG, "Ignoring comment header\n"); - return buf_size; - } + av_channel_layout_uninit(&avctx->ch_layout); + if (vc->audio_channels > 8) { + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + avctx->ch_layout.nb_channels = vc->audio_channels; + } else { + av_channel_layout_copy( + &avctx->ch_layout, + &ff_vorbis_ch_layouts[vc->audio_channels - 1]); + } - if (*buf == 5 && buf_size > 7 && vc->channel_residues && !vc->modes) { - if ((ret = init_get_bits8(gb, buf + 1, buf_size - 1)) < 0) - return ret; + avctx->sample_rate = vc->audio_samplerate; + } - if ((ret = vorbis_parse_setup_hdr(vc))) { - av_log(avctx, AV_LOG_ERROR, "Setup header corrupt.\n"); - vorbis_free(vc); - return ret; + if (setup && *setup == 5 && new_extradata->setup_size > 7 && + vc->channel_residues && !vc->modes) { + if ((ret = init_get_bits8( + gb, setup + 1, + new_extradata->setup_size - 1)) < 0) + return ret; + + if ((ret = vorbis_parse_setup_hdr(vc))) { + av_log(avctx, AV_LOG_ERROR, "Setup header corrupt.\n"); + vorbis_free(vc); + return ret; + } } - return buf_size; } if (!vc->channel_residues || !vc->modes) { diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index 62cc2da6de..ee2e01f468 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -255,12 +255,19 @@ static void vorbis_cleanup(AVFormatContext *s, int idx) struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; struct oggvorbis_private *priv = os->private; + vorbis_new_extradata *new_extradata; int i; if (os->private) { av_vorbis_parse_free(&priv->vp); for (i = 0; i < 3; i++) av_freep(&priv->packet[i]); } + + if (os->new_extradata) { + new_extradata = (vorbis_new_extradata *)os->new_extradata; + av_freep(&new_extradata->header); + av_freep(&new_extradata->setup); + } } static int vorbis_update_metadata(AVFormatContext *s, int idx) @@ -433,7 +440,10 @@ static int vorbis_packet(AVFormatContext *s, int idx) struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; struct oggvorbis_private *priv = os->private; + vorbis_new_extradata *new_extradata; int duration, flags = 0; + int skip_packet = 0; + int ret; if (!priv->vp) return AVERROR_INVALIDDATA; @@ -496,10 +506,57 @@ static int vorbis_packet(AVFormatContext *s, int idx) if (duration < 0) { os->pflags |= AV_PKT_FLAG_CORRUPT; return 0; - } else if (flags & VORBIS_FLAG_COMMENT) { - vorbis_update_metadata(s, idx); + } + + if (flags & VORBIS_FLAG_HEADER) { + ret = vorbis_parse_header(s, s->streams[idx], os->buf + os->pstart, os->psize); + if (ret < 0) + return ret; + + ret = av_reallocp(&os->new_extradata, sizeof(vorbis_new_extradata)); + if (ret < 0) + return ret; + + os->new_extradata_size = sizeof(vorbis_new_extradata); + new_extradata = (vorbis_new_extradata *)os->new_extradata; + + ret = av_reallocp(&new_extradata->header, os->psize); + if (ret < 0) + return ret; + + memcpy(new_extradata->header, os->buf + os->pstart, os->psize); + new_extradata->header_size = os->psize; + + skip_packet = 1; + } + + if (flags & VORBIS_FLAG_COMMENT) { + ret = vorbis_update_metadata(s, idx); + if (ret < 0) + return ret; + flags = 0; + skip_packet = 1; } + + if (flags & VORBIS_FLAG_SETUP) { + ret = av_reallocp(&os->new_extradata, sizeof(vorbis_new_extradata)); + if (ret < 0) + return ret; + + os->new_extradata_size = sizeof(vorbis_new_extradata); + new_extradata = (vorbis_new_extradata *)os->new_extradata; + + ret = av_reallocp(&new_extradata->setup, os->psize); + if (ret < 0) + return ret; + + memcpy(new_extradata->setup, os->buf + os->pstart, os->psize); + new_extradata->setup_size = os->psize; + + skip_packet = 1; + } + os->pduration = duration; } @@ -521,7 +578,7 @@ static int vorbis_packet(AVFormatContext *s, int idx) priv->final_duration += os->pduration; } - return 0; + return skip_packet; } const struct ogg_codec ff_vorbis_codec = { diff --git a/tests/ref/fate/ogg-vorbis-chained-meta.txt b/tests/ref/fate/ogg-vorbis-chained-meta.txt index b7a97c90e2..1206f86c1f 100644 --- a/tests/ref/fate/ogg-vorbis-chained-meta.txt +++ b/tests/ref/fate/ogg-vorbis-chained-meta.txt @@ -6,10 +6,7 @@ Stream ID: 0, frame PTS: 128, metadata: N/A Stream ID: 0, packet PTS: 704, packet DTS: 704 Stream ID: 0, frame PTS: 704, metadata: N/A Stream ID: 0, packet PTS: 0, packet DTS: 0 -Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, new metadata: encoder=Lavc61.19.100 libvorbis:title=Second Stream -Stream ID: 0, packet PTS: 0, packet DTS: 0 -Stream ID: 0, packet PTS: 0, packet DTS: 0 Stream ID: 0, frame PTS: 0, metadata: N/A Stream ID: 0, packet PTS: 128, packet DTS: 128 Stream ID: 0, frame PTS: 128, metadata: N/A -- 2.39.5 (Apple Git-154) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".