Skip to content

Commit 70c6a0c

Browse files
StefanBruensufleisch
authored andcommitted
Set last header flag in FLAC Metadata block type field
In case the Vorbis comment block is the last one the last block flag has to be set. As the other metadata blocks are kept as is, and in original order, and no other metadata blocks are added/inserted, these can be kept as is. Also warn if the header scan loop detects a frame sync sequence (which is the head of the first non-header packet). Previously, this was detected as the last header packet, but streamStart and streamLength are unused, and all packets but the vorbis comment packet are just copied in order. See taglib#1297
1 parent c67e434 commit 70c6a0c

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

taglib/ogg/flac/oggflacfile.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Ogg::FLAC::File::FilePrivate
4646

4747
bool hasXiphComment { false };
4848
int commentPacket { 0 };
49+
int lastHeaderPacket { 0 };
4950
};
5051

5152
////////////////////////////////////////////////////////////////////////////////
@@ -129,6 +130,12 @@ bool Ogg::FLAC::File::save()
129130

130131
v[0] = 4;
131132

133+
// If the comment block is the last one, set the corresponding bit
134+
135+
if (d->commentPacket == d->lastHeaderPacket) {
136+
v[0] = static_cast<char>(0x84);
137+
}
138+
132139
// Append the comment-data after the 32 bit header
133140

134141
v.append(d->xiphCommentData);
@@ -282,6 +289,12 @@ void Ogg::FLAC::File::scan()
282289
return;
283290
}
284291

292+
if(((header[0] & 0xff) == 0xff) && ((header[1] & 0xff) == 0xf8)) {
293+
ipacket--;
294+
debug("Ogg::FLAC::File::scan() -- Found frame sync marker, possibly missing last block marker");
295+
break;
296+
}
297+
285298
blockType = header[0] & 0x7f;
286299
lastBlock = (header[0] & 0x80) != 0;
287300
length = header.toUInt(1, 3, true);
@@ -315,6 +328,7 @@ void Ogg::FLAC::File::scan()
315328
debug("Ogg::FLAC::File::scan() -- Unknown metadata block");
316329
}
317330
}
331+
d->lastHeaderPacket = ipacket;
318332

319333
// End of metadata, now comes the datastream
320334
d->streamStart = overhead;

0 commit comments

Comments
 (0)