History

ogg/flac: implement header packet skip in chained ogg bitstreams.

Romain Beauxis committed 1 year ago

Commit 2fb64161 parent bd2dcfa2 files · +26 −4Browse files

Unified · Split

2 files
  1. libavformat/oggparseflac.c +26 −2
  2. tests/ref/fate/ogg-flac-chained-meta.txt +0 −2
libavformat/oggparseflac.c+26−2
@@ -27,6 +27,8 @@ · 26 unmodified lines
2727 #include "oggdec.h"
2828
2929 #define OGG_FLAC_METADATA_TYPE_STREAMINFO 0x7F
30+#define OGG_FLAC_MAGIC "\177FLAC"
31+#define OGG_FLAC_MAGIC_SIZE sizeof(OGG_FLAC_MAGIC)-1
3032
3133 static int
3234 flac_header (AVFormatContext * s, int idx)
@@ -78,6 +80,27 @@ flac_header (AVFormatContext * s, int idx) · 45 unmodified lines
7880 return 1;
7981 }
8082
83+static int
84+flac_packet (AVFormatContext * s, int idx)
85+{
86+ struct ogg *ogg = s->priv_data;
87+ struct ogg_stream *os = ogg->streams + idx;
88+
89+ if (os->psize > OGG_FLAC_MAGIC_SIZE &&
90+ !memcmp(
91+ os->buf + os->pstart,
92+ OGG_FLAC_MAGIC,
93+ OGG_FLAC_MAGIC_SIZE))
94+ return 1;
95+
96+ if (os->psize > 0 &&
97+ ((os->buf[os->pstart] & 0x7F) == FLAC_METADATA_TYPE_VORBIS_COMMENT)) {
98+ return 1;
99+ }
100+
101+ return 0;
102+}
103+
81104 static int
82105 old_flac_header (AVFormatContext * s, int idx)
83106 {
@@ -127,10 +150,11 @@ fail: · 43 unmodified lines
127150 }
128151
129152 const struct ogg_codec ff_flac_codec = {
130− .magic = "\177FLAC",
131− .magicsize = 5,
153+ .magic = OGG_FLAC_MAGIC,
154+ .magicsize = OGG_FLAC_MAGIC_SIZE,
132155 .header = flac_header,
133156 .nb_header = 2,
157+ .packet = flac_packet,
134158 };
135159
136160 const struct ogg_codec ff_old_flac_codec = {
tests/ref/fate/ogg-flac-chained-meta.txt+0−2
@@ -5,8 +5,6 @@ Stream ID: 0, frame PTS: 0, metadata: N/A · 4 unmodified lines
55 Stream ID: 0, packet PTS: 4608, packet DTS: 4608
66 Stream ID: 0, frame PTS: 4608, metadata: N/A
77 Stream ID: 0, packet PTS: 0, packet DTS: 0
8−Stream ID: 0, packet PTS: 0, packet DTS: 0
9−Stream ID: 0, packet PTS: 0, packet DTS: 0
108 Stream ID: 0, frame PTS: 0, metadata: N/A
119 Stream ID: 0, packet PTS: 4608, packet DTS: 4608
1210 Stream ID: 0, frame PTS: 4608, metadata: N/A

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t