4 #include "../vorbis/vorbiscomment.h" 6 #include "../exceptions.h" 7 #include "../mediafileinfo.h" 8 #include "../mediaformat.h" 10 #include "resources/config.h" 12 #include <c++utilities/io/copy.h> 33 FlacStream::FlacStream(
MediaFileInfo &mediaFileInfo, uint64 startOffset) :
35 m_mediaFileInfo(mediaFileInfo),
48 if(!m_vorbisComment) {
49 m_vorbisComment = make_unique<VorbisComment>();
51 return m_vorbisComment.get();
61 m_vorbisComment.reset();
70 static const string context(
"parsing raw FLAC header");
79 if(
m_reader.readUInt32BE() == 0x664C6143) {
86 header.parseHeader(buffer);
92 switch(static_cast<FlacMetaDataBlockType>(header.type())) {
94 if(header.dataSize() >= 0x22) {
97 streamInfo.
parse(buffer);
111 if(!m_vorbisComment) {
112 m_vorbisComment = make_unique<VorbisComment>();
134 if(!m_vorbisComment) {
136 m_vorbisComment = make_unique<VorbisComment>();
139 m_vorbisComment->fields().insert(make_pair(coverField.
id(), move(coverField)));
148 m_paddingSize += 4 + header.dataSize();
182 istream &originalStream = m_mediaFileInfo.
stream();
187 BE::getBytes(static_cast<uint32>(0x664C6143u), copy.buffer());
190 uint32 lastStartOffset = 0;
196 header.parseHeader(copy.buffer());
199 switch(static_cast<FlacMetaDataBlockType>(header.type())) {
203 m_istream->seekg(header.dataSize(), ios_base::cur);
208 copy.copy(originalStream,
outputStream, 4 + header.dataSize());
213 if(m_vorbisComment) {
228 header.
setDataSize(endOffset - lastStartOffset - 4);
229 header.
setLast(!m_vorbisComment->hasField(coverId));
237 const auto coverFields = m_vorbisComment->fields().equal_range(coverId);
238 for(
auto i = coverFields.first; i != coverFields.second; ) {
243 header.
setLast(++i == coverFields.second);
250 return lastStartOffset;
Contains utility classes helping to read and write streams.