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 0B1CF48886 for ; Mon, 19 May 2025 14:47:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id EBD7468D6DC; Mon, 19 May 2025 17:46:54 +0300 (EEST) Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id A9E6F68D5FA for ; Mon, 19 May 2025 17:46:46 +0300 (EEST) Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-3fbaa18b810so1473078b6e.2 for ; Mon, 19 May 2025 07:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747666005; x=1748270805; 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=jTjIA5f9kGqwqHTVJgVMx2SK47jDAZFPazhP8MufQMM=; b=CfH6zjimfqkpgtY0oS4oPqM/tN32Ol7Z57Zwy8ZayqfijflhhQO1GlGQ89J74MHNhj cO9uUPs0VsY0J4JEKTSa53dxU9BLj92Cm5QPd2yjCSd1dzfejvryxxFggRzZEYysCNte lgvKk4u5KLxm8UWbB/io7Wus2Fg6sKukNylH1+SdVoafdslXuh5GUZ5MWDxgAUi5LBpB C4QZi/kQWzrrwI0CMDvg9PjQO74DXkGsHGalo21kK6FBERgMtWzU/G52w+I2K3r6MYvt c3TiwfXrZS7rkcGNREHtEcD6k6IOU6muF5LBn3NQsPy3cIqkMKRcSUbx4YhxtP/EWchV R7QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747666005; x=1748270805; 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=jTjIA5f9kGqwqHTVJgVMx2SK47jDAZFPazhP8MufQMM=; b=jRL75z9+Vy6DV8c/BPvMxLc+7BwOWcAeE1eI8VscT8cM7ENs8X7FqNr4JjCjePdrN3 KzxcqI6H/FXXgS7A7tvFV/kcLwl+vs7LMGiFiZBTW1eFjK3tOljI0HZUONb95yUsstNW q0TA3tN9qZDh2p1Ojt2ZY6hNYEIZxYeotM2Loti1j6HI8BduZum2TBqZ+Ryg0YriumCA 6WjFL7eMeiHGGCv8ctXDDRNd8k0YLYe0rPEufQcxQFx3sKnpN6bO6B/ccvSq/v80wqdc 0P8C2CBDpq9wz+oQO1sA/C6yj9+VP12ClO0kSNSU1zBrP94Ys0bvy7umc+YYtp19rk27 3DSQ== X-Gm-Message-State: AOJu0YwYxPxQmFopeEXsEBmH6O7y5pqVTfi7hH0lnfphnpcjfV/BRTT0 dt/OCqaSnaqnXPIY7n194b2VmPyrPvea3J7lWf7AlsjORotu/aTDmCkHxow+OD56 X-Gm-Gg: ASbGncs49CrwwnmzVYOEFeSfUXXkOs2w4O9xbHMrEBk3sS5MP8mMOnS9gV4AOuZZQ2E cG3iUrsAUIh4eThtJxbkbcZm/iPz0bP68t4bKZbTDMFwQ5CLNU7SCnq1VnOmJRpjH9i7KGBEL3A LOE1+akr+QzJJoF3sUjMTgh7ZB8ZzKupv9U9yIZLiSA3H+CeY888xnbMis0ZxDu3VrEDi99Dmjq GDl5pTiFxE4kSQaECJSeGu0TtDbalCXKSPqV44//zkqH1xoYHX/KtNb4nlW6cCT+QwWaRd2zQMo ruF4x+iCC/R9y2QEXWB7dXMAidguYnyKie1qtHrJwHplp2HH/ysSnlyIYWWQYtcwFOavUluwhus 1iGfrQUOE/nt49I5MTso= X-Google-Smtp-Source: AGHT+IFf50AQ+yzN4Z5u8O+JQdgv3p2vUgFWwDTZEaA4qg7WRxFWWPnYUEt1ZgqpGA0Iz2HofYFMHg== X-Received: by 2002:a05:6808:3a1b:b0:3fa:1ed7:f7c3 with SMTP id 5614622812f47-404da7dd7f9mr7118343b6e.29.1747666004813; Mon, 19 May 2025 07:46:44 -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 5614622812f47-404d9809667sm1413322b6e.30.2025.05.19.07.46.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 19 May 2025 07:46:44 -0700 (PDT) From: Romain Beauxis To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 May 2025 09:46:37 -0500 Message-Id: <20250519144639.36733-3-romain.beauxis@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250519144639.36733-1-romain.beauxis@gmail.com> References: <20250519144639.36733-1-romain.beauxis@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 2/4] ogg/vorbis: factor out header processing logic. 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: --- libavformat/oggparsevorbis.c | 104 ++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 44 deletions(-) diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index 9f50ab9ffc..62cc2da6de 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -293,6 +293,62 @@ static int vorbis_update_metadata(AVFormatContext *s, int idx) return ret; } +static int vorbis_parse_header(AVFormatContext *s, AVStream *st, + const uint8_t *p, unsigned int psize) +{ + unsigned blocksize, bs0, bs1; + int srate; + int channels; + + if (psize != 30) + return AVERROR_INVALIDDATA; + + p += 7; /* skip "\001vorbis" tag */ + + if (bytestream_get_le32(&p) != 0) /* vorbis_version */ + return AVERROR_INVALIDDATA; + + channels = bytestream_get_byte(&p); + if (st->codecpar->ch_layout.nb_channels && + channels != st->codecpar->ch_layout.nb_channels) { + av_log(s, AV_LOG_ERROR, "Channel change is not supported\n"); + return AVERROR_PATCHWELCOME; + } + st->codecpar->ch_layout.nb_channels = channels; + srate = bytestream_get_le32(&p); + p += 4; // skip maximum bitrate + st->codecpar->bit_rate = bytestream_get_le32(&p); // nominal bitrate + p += 4; // skip minimum bitrate + + blocksize = bytestream_get_byte(&p); + bs0 = blocksize & 15; + bs1 = blocksize >> 4; + + if (bs0 > bs1) + return AVERROR_INVALIDDATA; + if (bs0 < 6 || bs1 > 13) + return AVERROR_INVALIDDATA; + + if (bytestream_get_byte(&p) != 1) /* framing_flag */ + return AVERROR_INVALIDDATA; + + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_VORBIS; + + if (srate > 0) { + if (st->codecpar->sample_rate && + srate != st->codecpar->sample_rate) { + av_log(s, AV_LOG_ERROR, "Sample rate change is not supported\n"); + return AVERROR_PATCHWELCOME; + } + + st->codecpar->sample_rate = srate; + avpriv_set_pts_info(st, 64, 1, srate); + } + + return 1; +} + static int vorbis_header(AVFormatContext *s, int idx) { struct ogg *ogg = s->priv_data; @@ -329,50 +385,10 @@ static int vorbis_header(AVFormatContext *s, int idx) priv->packet[pkt_type >> 1] = av_memdup(os->buf + os->pstart, os->psize); if (!priv->packet[pkt_type >> 1]) return AVERROR(ENOMEM); - if (os->buf[os->pstart] == 1) { - const uint8_t *p = os->buf + os->pstart + 7; /* skip "\001vorbis" tag */ - unsigned blocksize, bs0, bs1; - int srate; - int channels; - - if (os->psize != 30) - return AVERROR_INVALIDDATA; - - if (bytestream_get_le32(&p) != 0) /* vorbis_version */ - return AVERROR_INVALIDDATA; - - channels = bytestream_get_byte(&p); - if (st->codecpar->ch_layout.nb_channels && - channels != st->codecpar->ch_layout.nb_channels) { - av_log(s, AV_LOG_ERROR, "Channel change is not supported\n"); - return AVERROR_PATCHWELCOME; - } - st->codecpar->ch_layout.nb_channels = channels; - srate = bytestream_get_le32(&p); - p += 4; // skip maximum bitrate - st->codecpar->bit_rate = bytestream_get_le32(&p); // nominal bitrate - p += 4; // skip minimum bitrate - - blocksize = bytestream_get_byte(&p); - bs0 = blocksize & 15; - bs1 = blocksize >> 4; - - if (bs0 > bs1) - return AVERROR_INVALIDDATA; - if (bs0 < 6 || bs1 > 13) - return AVERROR_INVALIDDATA; - - if (bytestream_get_byte(&p) != 1) /* framing_flag */ - return AVERROR_INVALIDDATA; - - st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; - st->codecpar->codec_id = AV_CODEC_ID_VORBIS; - - if (srate > 0) { - st->codecpar->sample_rate = srate; - avpriv_set_pts_info(st, 64, 1, srate); - } - } else if (os->buf[os->pstart] == 3) { + if (pkt_type == 1) + return vorbis_parse_header(s, st, os->buf + os->pstart, os->psize); + + if (pkt_type == 3) { if (vorbis_update_metadata(s, idx) >= 0 && priv->len[1] > 10) { unsigned new_len; -- 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".