Beispiel #1
0
// what looks like the last frame in an MPEG stream may actually be truncated and somewhere inside it an ID3V1 or Ape tag may actually begin; if that's the case, that "frame" is removed from the stream; then most likely an "Unknown" stream will be detected, followed by an ID3V1 or Ape stream //ttt2 make sure that that is the case; a possibility is that the standard allows the last frame to be shorter than the calculated size, if some condition is met; this seems unlikely, though
void Mp3Handler::checkLastFrameInMpegStream(ifstream_utf8& in)
{
    STRM_ASSERT (!m_vpAllStreams.empty());
    MpegStream* pStream (dynamic_cast<MpegStream*>(m_vpAllStreams.back()));
    if (0 == pStream) {
        return;
    }

    streampos pos (pStream->getLastFramePos());
    streampos posNext (pStream->getPos());
    posNext += pStream->getSize();

    NoteColl notes (0);

    for (;;)
    {
        if (posNext - pos <= 0)
        {
            //clearPtrContainer(vpNotes);
            return;
        }
        in.clear();

        in.seekg(pos);
        try
        {
            DataStream* p (new Id3V240Stream(0, notes, in, m_pFileName));
            delete p;
            break;
        }
        catch (const std::bad_alloc&) {
            throw;
        }
        catch (...) //ttt2 replace "..." with something app-specific, to avoid catching system exceptions
        {
            in.clear();
            in.seekg(pos);
        }

        in.seekg(pos);
        try
        {
            DataStream* p (new ApeStream(0, notes, in));
            delete p;
            break;
        }
        catch (const std::bad_alloc&) {
            throw;
        }
        catch (...) //ttt2 replace "..." with something app-specific, to avoid catching system exceptions
        {
            in.clear();
            in.seekg(pos);
        }

        in.seekg(pos);
        try
        {
            DataStream* p (new Id3V1Stream(0, notes, in));
            delete p;
            break;
        }
        catch (const std::bad_alloc&) {
            throw;
        }
        catch (...) //ttt2 replace "..." with something app-specific, to avoid catching system exceptions
        {
            in.clear();
            in.seekg(pos);
        }

        in.seekg(pos);
        try
        {
            DataStream* p (new LyricsStream(0, notes, in, m_pFileName->s));
            delete p;
            break;
        }
        catch (const std::bad_alloc&) {
            throw;
        }
        catch (...) //ttt2 replace "..." with something app-specific, to avoid catching system exceptions
        {
            in.clear();
            in.seekg(pos);
        }


        try
        {
            pos = getNextStream(in, pos);
        }
        catch (const EndOfFile&)
        {
            return;
        }

    }

    //clearPtrContainer(notes);
    pStream->removeLastFrame();
}