Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksoid <aleksoid@users.sourceforge.net>2010-07-21 06:26:19 +0400
committerAleksoid <aleksoid@users.sourceforge.net>2010-07-21 06:26:19 +0400
commit0dbc894c010daa71873d77d00ec498a2fa4824e5 (patch)
tree4e12a8b227633acc38d3413afbd3b20362f86c59 /src/filters/parser
parentc13bcc7289aa38d76c96753585a4fd185d7a65e6 (diff)
Fix : Can't open specific mp3, Ticket #363(modify path by koolspin);
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@2140 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/filters/parser')
-rw-r--r--src/filters/parser/MpaSplitter/MpaSplitterFile.cpp116
1 files changed, 75 insertions, 41 deletions
diff --git a/src/filters/parser/MpaSplitter/MpaSplitterFile.cpp b/src/filters/parser/MpaSplitter/MpaSplitterFile.cpp
index 6696d7807..2b08ff4ec 100644
--- a/src/filters/parser/MpaSplitter/MpaSplitterFile.cpp
+++ b/src/filters/parser/MpaSplitter/MpaSplitterFile.cpp
@@ -227,36 +227,62 @@ HRESULT CMpaSplitterFile::Init()
BitRead(8), m_startpos++;
}
- __int64 searchlen = min(m_endpos - m_startpos, m_startpos > 0 ? 0x200 : 7);
+ __int64 searchlen;
+ __int64 startpos;
+ __int64 syncpos;
- __int64 startpos = m_startpos;
-
- Seek(m_startpos);
-
- if(m_mode == none && Read(m_mpahdr, searchlen, true, &m_mt))
+ while (m_mode == none)
{
- m_mode = mpa;
+ // Be more liberal in finding header bytes since mp3 header corruption
+ // is very prevalent.
+ searchlen = min(m_endpos - m_startpos, 0x200);
+ Seek(m_startpos);
- startpos = GetPos() - 4;
-
- // make sure the first frame is followed by another of the same kind (validates m_mpahdr basically)
- Seek(startpos + m_mpahdr.FrameSize);
- if(!Sync(4)) m_mode = none;
- }
+ // If we fail to see sync bytes, we reposition here and search again
+ syncpos = m_startpos + searchlen;
- Seek(m_startpos);
+ // Check for a valid MPA header
+ if(Read(m_mpahdr, searchlen, true, &m_mt))
+ {
+ m_mode = mpa;
- if(m_mode == none && Read(m_aachdr, searchlen, &m_mt))
- {
- m_mode = mp4a;
+ syncpos = GetPos();
+ startpos = syncpos - 4;
+
+ // make sure the first frame is followed by another of the same kind (validates m_mpahdr basically)
+ Seek(startpos + m_mpahdr.FrameSize);
+ if(!Sync(4))
+ m_mode = none;
+ else
+ break;
+ }
+ else
+ {
+ // No luck, try AAC
+ Seek(m_startpos);
+ if(Read(m_aachdr, searchlen, &m_mt))
+ {
+ m_mode = mp4a;
- startpos = GetPos() - (m_aachdr.fcrc?7:9);
+ syncpos = GetPos();
+ startpos = syncpos - (m_aachdr.fcrc?7:9);
- // make sure the first frame is followed by another of the same kind (validates m_aachdr basically)
- Seek(startpos + m_aachdr.aac_frame_length);
- if(!Sync(9)) m_mode = none;
- }
+ // make sure the first frame is followed by another of the same kind (validates m_aachdr basically)
+ Seek(startpos + m_aachdr.aac_frame_length);
+ if(!Sync(9))
+ m_mode = none;
+ else
+ break;
+ }
+ }
+ // If we have enough room to search for a valid header, then skip ahead and try again
+ if (m_endpos - syncpos >= 8)
+ m_startpos = syncpos;
+ else
+ break;
+ }
+
if(m_mode == none)
return E_FAIL;
@@ -295,19 +321,23 @@ bool CMpaSplitterFile::Sync(int& FrameSize, REFERENCE_TIME& rtDuration, int limi
{
mpahdr h;
- if(Read(h, endpos - GetPos(), true)
- && m_mpahdr.version == h.version
- && m_mpahdr.layer == h.layer
- && m_mpahdr.channels == h.channels)
+ if(Read(h, endpos - GetPos(), true))
{
- Seek(GetPos() - 4);
- AdjustDuration(h.nBytesPerSec);
+ if (m_mpahdr.version == h.version
+ && m_mpahdr.layer == h.layer
+ && m_mpahdr.channels == h.channels)
+ {
+ Seek(GetPos() - 4);
+ AdjustDuration(h.nBytesPerSec);
- FrameSize = h.FrameSize;
- rtDuration = h.rtDuration;
+ FrameSize = h.FrameSize;
+ rtDuration = h.rtDuration;
- return true;
+ return true;
+ }
}
+ else
+ break;
}
}
else if(m_mode == mp4a)
@@ -316,20 +346,24 @@ bool CMpaSplitterFile::Sync(int& FrameSize, REFERENCE_TIME& rtDuration, int limi
{
aachdr h;
- if(Read(h, endpos - GetPos())
- && m_aachdr.version == h.version
- && m_aachdr.layer == h.layer
- && m_aachdr.channels == h.channels)
+ if(Read(h, endpos - GetPos()))
{
- Seek(GetPos() - (h.fcrc?7:9));
- AdjustDuration(h.nBytesPerSec);
- Seek(GetPos() + (h.fcrc?7:9));
+ if (m_aachdr.version == h.version
+ && m_aachdr.layer == h.layer
+ && m_aachdr.channels == h.channels)
+ {
+ Seek(GetPos() - (h.fcrc?7:9));
+ AdjustDuration(h.nBytesPerSec);
+ Seek(GetPos() + (h.fcrc?7:9));
- FrameSize = h.FrameSize;
- rtDuration = h.rtDuration;
+ FrameSize = h.FrameSize;
+ rtDuration = h.rtDuration;
- return true;
+ return true;
+ }
}
+ else
+ break;
}
}