From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id E58B74CA1D for ; Mon, 10 Feb 2025 19:27:06 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0AACE68BE6E; Mon, 10 Feb 2025 21:26:35 +0200 (EET) Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5952068BE56 for ; Mon, 10 Feb 2025 21:26:28 +0200 (EET) Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-6f972c031efso49012347b3.1 for ; Mon, 10 Feb 2025 11:26:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739215586; x=1739820386; 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=kuBtfyjjH2K04sSFzgyTPn31LS3tncxYxX4lTEtUWOU=; b=mvbTAEX9GRz3reHrMM+aD2wP08ME/yPnYd/YHq0cjmk8W3OuW7m5jRD56g7tsFqoM0 undWhI6zMb54KrCeCPukAQbdmhqWKR/H7LwOr2/qp3AMdigTktYvDbop+9D3j3xquEU3 uHHht1HaBuRuPZ8q6SwlRjIONtg0GOse5LX3vLiWDSRZil66BDwKuX+0+u4QOnTVEMAU pP4Q0C1rHgvgCr20f86uE100jtm2/x9WE3iZVNouHc6fdoIMJKyOM6eDVLeBYwMDHCGS z90hEmC8uYjNP6kS9z79o3S2JjIMzyrVd3udXn8rO/clc1camf/Xs6/EYBHZt+M+vzjG YtMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739215586; x=1739820386; 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=kuBtfyjjH2K04sSFzgyTPn31LS3tncxYxX4lTEtUWOU=; b=EoNC5zs/lL5tR9YNzaVzwSUuO4oG4lgI6pGYvcxs5fDToUa7LE/jFnwjrd0DjFKmoc P+UXlNWyg1OLjS8WsiX4oGct9eunR+ro5iZasAg0hc/PLdcPAg6/RI14ffZuKDjH0E/9 CrH8pq1bEH4z5h+enUiAYGOOHVRp8md9LLEOvwCVzzRrtJVhCN4sEwUcrCsNQ13X1bYo Jke3a0pQVRcFC62wkYQJYbK6AJ6sGHooui+iIuW6E/Vo8LF+F47839lFhUAx6E9NTuJf eb0DGjYWKE8KNd8ryKjT7HcvS2h1rZp0WWRp3kJTQr2dsAmynELMaHkJaFvWsyUjMoxr Yd4w== X-Gm-Message-State: AOJu0YxqbkXIGuICqa6fq//3ENwKI2LXmI4+2/NWyC00GLyuo9QyuRlX DdcCUdO83FLhBHrIaJX2Bl04KJ7xWtgopelpQXgyR3CJvBAW6WdKuHx0Mw== X-Gm-Gg: ASbGnctFiQsFjyvyMQpSDEzQ+Hkgg6GicmfwdWowXHYNEcvwZTSCRYrJCHm1NpFfZPj Ssr7j+m1svuYnot28qPs230EfqX8qLwaeij7XHixhRxOfAJOxf8SygRhahlS+FRr4EIbCoY0Oog JKMN9w5UBtyGrdQEDC0JMMxgPijmRykV0c1foKQiaJY1d1RmH2SdepoEl74NTgnEkrS8rOsNonu B/1pzhvSEme7+H7lyhcOGm6NVHcS/IvikWmWsVP3jRv1db+AY7zqsBwVTiEyfLsDbz1OWrUkVbn 5lI8O6HsvqqOGmBOkfnfuDezybqYPHmXLnVr8BQE8priqepX19WbrAI= X-Google-Smtp-Source: AGHT+IFADvVUI1qZXc7iaNEnwXqM31NmQlMSpXS53q66WgFtwgzb2hsaALTd8BF8AlCYsfJQ7fr/xg== X-Received: by 2002:a05:690c:a82:b0:6f9:b027:1bfc with SMTP id 00721157ae682-6fb0c4442cbmr8602847b3.3.1739215586487; Mon, 10 Feb 2025 11:26:26 -0800 (PST) Received: from localhost.localdomain ([2607:fb91:fe6:4ec3:28a5:3f0e:2e51:b5ed]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6fafee87110sm4985567b3.15.2025.02.10.11.26.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 10 Feb 2025 11:26:25 -0800 (PST) From: Romain Beauxis To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Feb 2025 13:25:57 -0600 Message-Id: <20250210192600.42502-4-romain.beauxis@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250210192600.42502-1-romain.beauxis@gmail.com> References: <20250210192600.42502-1-romain.beauxis@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 3/6] Pass secondary ogg/opus chained streams metadata. 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: These changes parse ogg/opus comment in secondary chained ogg/opus streams and attach them as extradata to the corresponding packet. They can then be decoded in the opus decoder and attached to the next decoded frame. libavformat/oggparseopus.c: Parse comments from secondary chained ogg/opus streams and pass them as ogg stream new_metadata. libavcodec/opus/dec.c: Unpack comments from secondary chained ogg/opus streams and attach them to the next decoded frame. --- libavcodec/opus/dec.c | 25 ++++++++++++++++++++++--- libavformat/oggparseopus.c | 16 +++++++++++++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/libavcodec/opus/dec.c b/libavcodec/opus/dec.c index 88a650c81c..cddcefcb5f 100644 --- a/libavcodec/opus/dec.c +++ b/libavcodec/opus/dec.c @@ -125,6 +125,8 @@ typedef struct OpusContext { AVFloatDSPContext *fdsp; float gain; + AVDictionary *pending_metadata; + OpusParseContext p; } OpusContext; @@ -485,12 +487,24 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame, int decoded_samples = INT_MAX; int delayed_samples = 0; int i, ret; + size_t size; + const uint8_t *side_metadata; - if (buf_size > 8 && ( - !memcmp(buf, "OpusHead", 8) || - !memcmp(buf, "OpusTags", 8))) + if (buf_size > 8 && !memcmp(buf, "OpusHead", 8)) return buf_size; + if (buf_size > 8 && !memcmp(buf, "OpusTags", 8)) { + /* New metadata */ + side_metadata = av_packet_get_side_data(avpkt, AV_PKT_DATA_METADATA_UPDATE, &size); + if (side_metadata) { + av_dict_free(&c->pending_metadata); + ret = av_packet_unpack_dictionary(side_metadata, size, &c->pending_metadata); + if (ret < 0) + return ret; + } + return buf_size; + } + /* calculate the number of delayed samples */ for (int i = 0; i < c->p.nb_streams; i++) { OpusStreamContext *s = &c->streams[i]; @@ -631,6 +645,11 @@ static int opus_decode_packet(AVCodecContext *avctx, AVFrame *frame, frame->nb_samples = decoded_samples; *got_frame_ptr = !!decoded_samples; + if (c->pending_metadata) { + av_dict_copy(&frame->metadata, c->pending_metadata, AV_DICT_APPEND); + av_dict_free(&c->pending_metadata); + } + return avpkt->size; } diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c index 950b93bd31..3e94a7df3c 100644 --- a/libavformat/oggparseopus.c +++ b/libavformat/oggparseopus.c @@ -116,6 +116,7 @@ static int opus_packet(AVFormatContext *avf, int idx) AVStream *st = avf->streams[idx]; struct oggopus_private *priv = os->private; uint8_t *packet = os->buf + os->pstart; + AVDictionary *new_metadata = NULL; int ret; if (!os->psize) @@ -133,8 +134,21 @@ static int opus_packet(AVFormatContext *avf, int idx) return 0; } - if (os->psize > 8 && !memcmp(packet, "OpusTags", 8)) + if (os->psize > 8 && !memcmp(packet, "OpusTags", 8)) { + ret = ff_vorbis_comment(avf, &new_metadata, os->buf + os->pstart + 8, + os->psize - 8, 1); + + if (ret < 0) + return ret; + + os->new_metadata = av_packet_pack_dictionary(new_metadata, &os->new_metadata_size); + av_dict_free(&new_metadata); + + if (!os->new_metadata) + return AVERROR(ENOMEM); + return 0; + } if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS)) { int seg, d; -- 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".