[Matroska-cvs] [matroska] r1257 - trunk/foo_input_matroska
ayana at matroska.org
ayana at matroska.org
Mon Jul 17 08:48:08 CEST 2006
Author: ayana
Date: 2006-07-17 10:48:03 +0400 (Mon, 17 Jul 2006)
New Revision: 1257
Modified:
trunk/foo_input_matroska/foo_input_matroska.cpp
trunk/foo_input_matroska/matroska_parser.cpp
trunk/foo_input_matroska/matroska_parser.h
Log:
change: simplify parsing except decoding
Modified: trunk/foo_input_matroska/foo_input_matroska.cpp
===================================================================
--- trunk/foo_input_matroska/foo_input_matroska.cpp 2006-07-17 06:46:55 UTC (rev 1256)
+++ trunk/foo_input_matroska/foo_input_matroska.cpp 2006-07-17 06:48:03 UTC (rev 1257)
@@ -143,8 +143,7 @@
m_parser = new MatroskaAudioParser(m_file, p_abort);
- //if (m_parser->Parse(!(p_reason & input_open_decode))) {
- if (m_parser->Parse()) {
+ if (m_parser->Parse(!(m_reason & input_open_decode))) {
console::error("Matroska: Invalid Matroska file.");
cleanup();
throw exception_io_unsupported_format();
@@ -208,8 +207,8 @@
m_parser->SetFB2KInfo(p_info, m_subsong);
- //hprintf(L"Matroska: m_parser->GetDuration(): %f\n", (double)(int64)m_parser->GetDuration() / 1000000000.0);
- p_info.set_length((double)(int64)m_parser->GetDuration() / 1000000000.0);
+ hprintf(L"Matroska: m_parser->GetDuration(): %f\n", m_parser->GetDuration());
+ p_info.set_length(m_parser->GetDuration());
if (p_info.info_get_bitrate() == 0) {
p_info.info_set_bitrate(m_parser->GetAvgBitrate());
@@ -247,9 +246,9 @@
return false;
}
- if (m_position>=m_length)
+ if (m_position >= m_length)
{
- hprintf(L"Matroska: decode_run() return false\n");
+ hprintf(L"Matroska: decode_run() return false: m_position=%d\n", m_position);
return false;
}
@@ -265,18 +264,22 @@
int64 delta = duration_to_samples(m_frame.timecode) - m_position;
console::info(uStringPrintf("drift: %d",(int)delta));
}
-*/
+*/
if (m_frame_remaining==0 || m_frame==0)
{
if (m_frame!=0)
delete m_frame;
m_frame = m_parser->ReadSingleFrame();
- if (m_frame==0)
+ if (m_frame==0) {
+ hprintf(L"Matroska: decode_run() return false: m_frame=0\n");
return false;
+ }
m_frame_remaining = m_frame->dataBuffer.size();
- if (m_frame_remaining == 0)
+ if (m_frame_remaining == 0) {
+ hprintf(L"Matroska: decode_run() return false: m_frame_remaining=0\n");
return false;
+ }
}
{
@@ -298,7 +301,8 @@
console::error(uStringPrintf("Matroska: '%s' decode error.", (const char*)currentTrack.codecID.c_str()));
//console::error(uStringPrintf("buffer_size = %d, m_frame_remaining = %d", buffer_size, m_frame_remaining));
//console::error(uStringPrintf("buffer 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X", m_buffer[0], m_buffer[1], m_buffer[2], m_buffer[3], m_buffer[4], m_buffer[5], m_buffer[6], m_buffer[7]));
- cleanup();
+ hprintf(L"Matroska: decode_run() return false: decode error\n");
+ cleanup();
return false;
}
if (m_tempchunk.is_valid())
@@ -340,6 +344,7 @@
{
console::error("Matroska: decoder produced invalid chunk.");
cleanup();
+ hprintf(L"Matroska: decode_run() return false: invalid chunk\n");
return false;
}
unsigned samplerate,channels,decoded_sample_count;
@@ -380,8 +385,10 @@
if (duration>max)
duration = max;
m_position += duration;
- if (m_position==m_length && duration==0)
+ if (m_position==m_length && duration==0) {
+ hprintf(L"Matroska: decode_run() return false: duration=0\n");
return false;
+ }
}
@@ -532,14 +539,14 @@
m_parser = NULL;
}
}
- int64 duration_to_samples(int64 val)
+ int64 duration_to_samples(double val)
{
- return (int64) ( (double)val * (double)m_expected_sample_rate / 1000000000.0 + 0.5);
+ return static_cast<int64>(val * (double)m_expected_sample_rate + 0.5);
}
- int64 samples_to_duration(int64 val)
+ double samples_to_duration(int64 val)
{
- return (int64) ( (double)val * 1000000000.0 / (double)m_expected_sample_rate + 0.5);
+ return static_cast<double>(val) / static_cast<double>(m_expected_sample_rate);
}
void set_current_track(unsigned int p_index) {
@@ -605,10 +612,7 @@
m_skip_frames = 0;
m_frame_remaining = 0;
m_frame = 0;
- if (decode_can_seek()) {
- decode_seek(0, p_abort);
- }
- m_frame = m_parser->ReadSingleFrame();
+ m_frame = m_parser->ReadFirstFrame();
if (m_frame != NULL) {
unsigned int buffer_size = m_frame->dataBuffer.at(0).size();
m_buffer.set_size(buffer_size);
@@ -633,7 +637,7 @@
#endif
DECLARE_COMPONENT_VERSION(
INPUT_MATROSKA_NAME,
- "0.9.1.0",
+ "0.9.1.1",
"ported to 0.9 by Haru Ayana <ayana at matroska.org>\n"
"Copyright (C) 2003-2004 Jory Stone (jcsston at toughguy.net)\n"
"Copyright (C) 2003-2004 Peter Pawlowski"
Modified: trunk/foo_input_matroska/matroska_parser.cpp
===================================================================
--- trunk/foo_input_matroska/matroska_parser.cpp 2006-07-17 06:46:55 UTC (rev 1256)
+++ trunk/foo_input_matroska/matroska_parser.cpp 2006-07-17 06:48:03 UTC (rev 1257)
@@ -381,8 +381,8 @@
KaxDuration &duration = *static_cast<KaxDuration *>(ElementLevel2.get());
duration.ReadData(m_InputStream.I_O());
- // it's in milliseconds?
- m_Duration = double(duration) * (double)(int64)m_TimecodeScale;
+ // it's in milliseconds? -- in seconds.
+ m_Duration = float(duration) * m_TimecodeScale;
//matroskaGlobalTrack->SetDuration(float(duration) * int64(m_TimecodeScale) / 1000000000.0);
} else if (EbmlId(*ElementLevel2) == KaxDateUTC::ClassInfos.GlobalId) {
@@ -1074,11 +1074,11 @@
return foundTag;
};
-uint64 MatroskaAudioParser::GetDuration() {
+double MatroskaAudioParser::GetDuration() {
if (m_CurrentChapter != NULL) {
- return m_CurrentChapter->timeEnd - m_CurrentChapter->timeStart;
+ return TimecodeToSeconds(m_CurrentChapter->timeEnd - m_CurrentChapter->timeStart);
};
- return m_Duration;
+ return m_Duration / 1000000000.0;
if (m_Tracks.size() != 0) {
return m_Tracks.at(m_CurrentTrackNo).defaultDuration * (int64)m_TimecodeScale;
}
@@ -1520,7 +1520,7 @@
m_CurrentEdition = NULL;
m_CurrentChapter = NULL;
if(m_Editions.size() > 0)
- m_CurrentEdition = &m_Editions.at(0);
+ m_CurrentEdition = &m_Editions.at(0);
if (m_Chapters.size() > subsong)
m_CurrentChapter = &m_Chapters.at(subsong);
@@ -1529,10 +1529,10 @@
int32 MatroskaAudioParser::GetAvgBitrate()
{
double ret = 0;
- ret = (double)(int64)m_FileSize / 1024;
- ret = ret / ((double)(int64)m_Duration / (double)(int64)1000000000);
+ ret = static_cast<double>(int64(m_FileSize)) / 1024;
+ ret = ret / (m_Duration / 1000000000.0);
ret = ret * 8;
- return (int32)ret;
+ return static_cast<int32>(ret);
};
bool MatroskaAudioParser::skip_frames_until(double destination,unsigned & frames,double & last_timecode_delta,unsigned hint_samplerate)
@@ -1628,6 +1628,12 @@
}
};
+MatroskaAudioFrame * MatroskaAudioParser::ReadFirstFrame()
+{
+ m_CurrentTimecode = 0;
+ return ReadSingleFrame();
+};
+
typedef boost::shared_ptr<EbmlId> EbmlIdPtr;
void MatroskaAudioParser::Parse_MetaSeek(ElementPtr metaSeekElement, bool bInfoOnly)
@@ -1651,6 +1657,9 @@
if (UpperElementLevel < 0) {
UpperElementLevel = 0;
}
+ if (bInfoOnly) {
+ if (m_ClusterIndex.size() >= 1) break;
+ }
if (EbmlId(*l2) == KaxSeek::ClassInfos.GlobalId) {
//Wow we found the SeekEntries, time to speed up reading ;)
@@ -1664,6 +1673,9 @@
if (UpperElementLevel < 0) {
UpperElementLevel = 0;
}
+ if (bInfoOnly) {
+ if (m_ClusterIndex.size() >= 1) break;
+ }
if (EbmlId(*l3) == KaxSeekID::ClassInfos.GlobalId) {
binary *b = NULL;
@@ -1682,7 +1694,7 @@
if (endSeekPos < lastSeekPos)
endSeekPos = uint64(seek_pos);
- if ((*id == KaxCluster::ClassInfos.GlobalId) && !bInfoOnly) {
+ if (*id == KaxCluster::ClassInfos.GlobalId) {
//NOTE1("Found Cluster Seek Entry Postion: %u", (unsigned long)lastSeekPos);
//uint64 orig_pos = inputFile.getFilePointer();
//MatroskaMetaSeekClusterEntry newCluster;
@@ -1691,13 +1703,13 @@
newCluster->filePos = static_cast<KaxSegment *>(m_ElementLevel0.get())->GetGlobalPosition(lastSeekPos);
m_ClusterIndex.push_back(newCluster);
- } else if ((*id == KaxSeekHead::ClassInfos.GlobalId) && !bInfoOnly) {
+ } else if (*id == KaxSeekHead::ClassInfos.GlobalId) {
NOTE1("Found MetaSeek Seek Entry Postion: %u", (unsigned long)lastSeekPos);
uint64 orig_pos = m_IOCallback.getFilePointer();
m_IOCallback.setFilePointer(static_cast<KaxSegment *>(m_ElementLevel0.get())->GetGlobalPosition(lastSeekPos));
ElementPtr levelUnknown = ElementPtr(m_InputStream.FindNextID(KaxSeekHead::ClassInfos, 0xFFFFFFFFFFFFFFFFL));
- Parse_MetaSeek(levelUnknown, false);
+ Parse_MetaSeek(levelUnknown, bInfoOnly);
m_IOCallback.setFilePointer(orig_pos);
}
@@ -2402,7 +2414,7 @@
return m_ClusterIndex.at(0);
cluster_entry_ptr_t correctEntry;
- double clusterDuration = (double)(int64)m_ClusterIndex.size() / (double)(int64)m_Duration;
+ double clusterDuration = (double)(int64)m_ClusterIndex.size() / m_Duration;
size_t clusterIndex = clusterDuration * (double)(int64)timecode;
//int lookCount = 0;
if (clusterIndex > m_ClusterIndex.size())
@@ -2505,7 +2517,7 @@
if (m_Chapters.size() > 0) {
MatroskaChapterInfo *nextChapter = &m_Chapters.at(m_Chapters.size()-1);
if (nextChapter->timeEnd == 0) {
- nextChapter->timeEnd = m_Duration;
+ nextChapter->timeEnd = static_cast<uint64>(m_Duration);
}
for (uint32 c = 0; c < m_Chapters.size()-1; c++) {
MatroskaChapterInfo ¤tChapter = m_Chapters.at(c);
@@ -2516,7 +2528,7 @@
}
nextChapter = &m_Chapters.at(m_Chapters.size()-1);
if ((nextChapter->timeEnd == 0) || (nextChapter->timeEnd == nextChapter->timeStart)) {
- nextChapter->timeEnd = m_Duration;
+ nextChapter->timeEnd = static_cast<uint64>(m_Duration);
}
}
}
Modified: trunk/foo_input_matroska/matroska_parser.h
===================================================================
--- trunk/foo_input_matroska/matroska_parser.h 2006-07-17 06:46:55 UTC (rev 1256)
+++ trunk/foo_input_matroska/matroska_parser.h 2006-07-17 06:48:03 UTC (rev 1257)
@@ -251,7 +251,7 @@
MatroskaTrackInfo &GetTrack(uint16 trackNo) { return m_Tracks.at(trackNo); };
uint64 GetTimecodeScale() { return m_TimecodeScale; };
/// Returns an adjusted duration of the file
- uint64 GetDuration();
+ double GetDuration();
/// Returns the track index of the first decodable track
int32 GetFirstAudioTrack();
@@ -296,6 +296,7 @@
/// \return 1 If file could not be read or it not open
/// \return 2 End of track (EOT)
MatroskaAudioFrame * ReadSingleFrame();
+ MatroskaAudioFrame * ReadFirstFrame();
UTFstring GetSegmentFileName() { return m_SegmentFilename; }
typedef pfc::list_t<MatroskaAttachment> attachment_list_t;
@@ -358,7 +359,7 @@
attachment_list_t m_AttachmentList;
uint64 m_CurrentTimecode;
- uint64 m_Duration;
+ double m_Duration;
uint64 m_TimecodeScale;
UTFstring m_WritingApp;
UTFstring m_MuxingApp;
More information about the Matroska-cvs
mailing list