diff mbox series

[FFmpeg-devel] Add support for flac in-stream metadata.

Message ID 20230422154523.22794-1-toots@rastageeks.org
State New
Headers show
Series [FFmpeg-devel] Add support for flac in-stream metadata. | expand

Checks

Context Check Description
andriy/commit_msg_x86 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
yinshiyou/commit_msg_loongarch64 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Romain Beauxis April 22, 2023, 3:45 p.m. UTC
From: Romain Beauxis <toots@rastageeks.org>

This patch adds support for in-stream metadata updates in the ogg/flac parser.

Code for detecting metadata frame is based on libavcodec/flacdec.c, code for
handling comment update is based on libavformat/oggparsevorbis.c.

This has been successfully tested locally. To reproduce:
* Setup an ogg/flac icecast stream.
* Read the stream
* Check the associated AVStream metadata

There seems to be similar issues with opus as well, which will be addressed
in a separate patch.

---
 libavformat/oggparseflac.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c
index eef6e09927..1dd292483d 100644
--- a/libavformat/oggparseflac.c
+++ b/libavformat/oggparseflac.c
@@ -126,10 +126,30 @@  fail:
     return ret;
 }
 
+static int flac_packet(AVFormatContext *s, int idx)
+{
+    struct ogg *ogg = s->priv_data;
+    struct ogg_stream *os = ogg->streams + idx;
+    int ret;
+
+    if (os->psize > 4 && (*(os->buf + os->pstart) & 0x7F) == FLAC_METADATA_TYPE_VORBIS_COMMENT) {
+        AVStream *st = s->streams[idx];
+        av_dict_free(&st->metadata);
+        ret = ff_vorbis_stream_comment(s, st, os->buf + os->pstart + 4,
+                                       os->psize - 4);
+
+        if (ret < 0) return ret;
+    }
+
+    return 0;
+}
+
+
 const struct ogg_codec ff_flac_codec = {
     .magic = "\177FLAC",
     .magicsize = 5,
     .header = flac_header,
+    .packet = flac_packet,
     .nb_header = 2,
 };