38 #include "io_strings.h"
47 io::ExitTrigger et(rdr, beg);
53 ID3D_NOTICE(
"id3::v2::parseFrames(): rdr.getBeg() = " << rdr.
getBeg() );
54 ID3D_NOTICE(
"id3::v2::parseFrames(): rdr.getCur() = " << rdr.
getCur() );
55 ID3D_NOTICE(
"id3::v2::parseFrames(): rdr.getEnd() = " << rdr.
getEnd() );
59 bool goodParse = f->Parse(rdr);
60 frameSize = rdr.
getCur() - last_pos;
61 ID3D_NOTICE(
"id3::v2::parseFrames(): frameSize = " << frameSize );
62 totalSize += frameSize;
68 ID3D_WARNING(
"id3::v2::parseFrames(): frame size is 0, can't " <<
69 "continue parsing frames");
77 ID3D_WARNING(
"id3::v2::parseFrames(): bad parse, deleting frame");
82 ID3D_NOTICE(
"id3::v2::parseFrames(): attaching non-compressed " <<
89 ID3D_NOTICE(
"id3::v2::parseFrames(): parsing ID3v2.2.1 " <<
101 ID3D_WARNING(
"id3::v2::parseFrames(): unknown compression id " <<
102 " = '" << ch <<
"'" );
106 uint32 newSize = io::readBENumber(mr,
sizeof(uint32));
107 size_t oldSize = f->GetDataSize() -
sizeof(uint32) - 1;
108 io::CompressedReader cr(mr, newSize);
109 parseFrames(tag, cr);
114 ID3D_WARNING(
"id3::v2::parseFrames(): didn't parse entire " <<
115 "id3v2.2.1 compressed memory stream");
121 et.setExitPos(rdr.
getCur());
125 ID3D_NOTICE(
"id3::v2::parseFrames: done parsing, padding at postion " <<
130 ID3D_NOTICE(
"id3::v2::parseFrames: done parsing, [cur, end] = [" <<
140 io::ExitTrigger et(reader);
146 if (!hdr.
Parse(wr) || wr.getCur() == beg)
148 ID3D_NOTICE(
"id3::v2::parse(): parsing header failes" );
158 ID3D_NOTICE(
"ID3_TagImpl::Parse(ID3_Reader&): dataSize = " << dataSize);
160 wr.setWindow(wr.getCur(), dataSize);
161 et.setExitPos(wr.getEnd());
163 ID3D_NOTICE(
"ID3_TagImpl::Parse(ID3_Reader&): data window beg = " << wr.getBeg() );
164 ID3D_NOTICE(
"ID3_TagImpl::Parse(ID3_Reader&): data window cur = " << wr.getCur() );
165 ID3D_NOTICE(
"ID3_TagImpl::Parse(ID3_Reader&): data window end = " << wr.getEnd() );
170 parseFrames(tag, wr);
185 BString raw = io::readAllBinary(wr);
186 io::BStringReader bsr(raw);
187 io::UnsyncedReader ur(bsr);
188 ID3D_NOTICE(
"ID3_TagImpl::Parse(ID3_Reader&): unsync beg = " << ur.getBeg() );
189 ID3D_NOTICE(
"ID3_TagImpl::Parse(ID3_Reader&): unsync cur = " << ur.getCur() );
190 ID3D_NOTICE(
"ID3_TagImpl::Parse(ID3_Reader&): unsync end = " << ur.getEnd() );
197 BString synced = io::readAllBinary(ur);
198 io::BStringReader sr(synced);
199 parseFrames(tag, sr);
221 size_t mp3_core_size;
222 size_t bytes_till_sync;
224 io::WindowedReader wr(reader);
225 wr.setBeg(wr.getCur());
228 _file_size = reader.
getEnd();
248 }
while (!wr.atEnd() && cur > last);
251 if (!wr.atEnd() && wr.peekChar() ==
'\0')
253 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): found padding outside tag" );
257 cur = wr.getCur() + 1;
260 }
while (!wr.atEnd() && cur > last && wr.peekChar() ==
'\0');
262 if (!wr.atEnd() && _file_size - (cur - beg) > 4 && wr.peekChar() == 255)
265 if (wr.readChar() ==
'\0' && wr.readChar() ==
'\0' && wr.peekChar() ==
'\0')
271 cur = wr.getCur() + 1;
274 }
while (!wr.atEnd() && cur > last && wr.peekChar() ==
'\0');
279 _prepended_bytes = cur - beg;
284 if (!wr.atEnd() && wr.peekChar() != 0xFF)
286 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): Didn't find mp3 sync byte" );
287 if ((_file_size - (cur - beg)) >= 4)
289 unsigned char buf[5];
290 wr.readChars(buf, 4);
293 if (strncmp((
char*)buf,
"RIFF", 4) == 0 || strncmp((
char*)buf,
"RIFX", 4) == 0)
296 cur = wr.getCur() + 4;
299 if (!wr.atEnd() && wr.peekChar() != 0xFF)
304 cur = wr.getCur() + 1;
306 }
while (!wr.atEnd() && cur > last && wr.peekChar() != 0xFF);
309 else if (strncmp((
char*)buf,
"fLaC", 4) == 0)
319 if (!wr.atEnd() && wr.peekChar() != 0xFF)
324 cur = wr.getCur() + 1;
326 }
while (!wr.atEnd() && cur > last && wr.peekChar() != 0xFF);
337 bytes_till_sync = cur - beg;
339 cur = wr.setCur(end);
340 if (_file_size > _prepended_bytes)
345 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): beg = " << wr.getBeg() );
346 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): cur = " << wr.getCur() );
347 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): end = " << wr.getEnd() );
349 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): musicmatch? cur = " << wr.getCur() );
352 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): musicmatch! cur = " << wr.getCur() );
354 wr.setEnd(wr.getCur());
356 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): lyr3v1? cur = " << wr.getCur() );
359 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): lyr3v1! cur = " << wr.getCur() );
361 wr.setEnd(wr.getCur());
363 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): lyr3v2? cur = " << wr.getCur() );
366 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): lyr3v2! cur = " << wr.getCur() );
369 wr.setCur(wr.getEnd());
371 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): id3v1? cur = " << wr.getCur() );
374 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): id3v1! cur = " << wr.getCur() );
380 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): id3v1? cur = " << wr.getCur() );
383 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): id3v1! cur = " << wr.getCur() );
384 wr.setEnd(wr.getCur());
388 }
while (cur != last);
389 _appended_bytes = end - cur;
392 mp3_core_size = (_file_size - _appended_bytes) - (_prepended_bytes + bytes_till_sync);
393 if (mp3_core_size >= 4)
395 wr.setBeg(_prepended_bytes + bytes_till_sync);
396 wr.setCur(_prepended_bytes + bytes_till_sync);
397 wr.setEnd(_file_size - _appended_bytes);
400 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): mp3header? cur = " << wr.getCur() );
402 if (_mp3_info->Parse(wr, mp3_core_size))
404 ID3D_NOTICE(
"ID3_TagImpl::ParseReader(): mp3header! cur = " << wr.getCur() );
414 this->SetPadding(
false);
The representative class of an ID3v2 field.
virtual const uchar * GetRawBinary() const =0
virtual size_t BinSize() const =0
The representative class of an id3v2 frame.
virtual pos_type getCur()=0
Return the current position in the reader.
virtual pos_type getEnd()
Return the ending position in the reader.
virtual pos_type getBeg()
Return the beginning position in the reader.
virtual int_type peekChar()=0
Return the next character to be read without advancing the internal position.
void ParseReader(ID3_Reader &reader)
ID3_V2Spec GetSpec() const
bool AttachFrame(ID3_Frame *)
@ ID3E_NoError
No error reported.
@ ID3TT_LYRICS3
Represents a Lyrics3 tag.
@ ID3TT_ID3V2
Represents an id3v2 tag.
@ ID3TT_LYRICS3V2
Represents a Lyrics3 v2.00 tag.
@ ID3TT_MUSICMATCH
Represents a MusicMatch tag.
@ ID3TT_ID3V1
Represents an id3v1 or id3v1.1 tag.
@ ID3FID_METACOMPRESSION
Compressed meta frame (id3v2.2.1)
bool parse(ID3_TagImpl &, ID3_Reader &)
bool parse(ID3_TagImpl &tag, ID3_Reader &rdr)
bool parse(ID3_TagImpl &, ID3_Reader &)
bool parse(ID3_TagImpl &, ID3_Reader &)
bool parse(ID3_TagImpl &, ID3_Reader &)
ID3_Err ID3_C_EXPORT openReadableFile(String, fstream &)