mkvparser: Add basic cues walking to sample.

Change-Id: Ia90e760f04083fa60b44f4d372e118474fc59fee
This commit is contained in:
Tom Finegan
2014-01-23 15:19:32 -08:00
parent 5c14a3f035
commit 5440f20071

View File

@@ -20,7 +20,8 @@
#endif #endif
static const wchar_t* utf8towcs(const char* str) { static const wchar_t* utf8towcs(const char* str) {
if (str == NULL) return NULL; if (str == NULL)
return NULL;
// TODO: this probably requires that the locale be // TODO: this probably requires that the locale be
// configured somehow: // configured somehow:
@@ -38,6 +39,21 @@ static const wchar_t* utf8towcs(const char* str) {
return val; return val;
} }
bool InputHasCues(const mkvparser::Segment* const segment) {
const mkvparser::Cues* const cues = segment->GetCues();
if (cues == NULL)
return false;
while (!cues->DoneParsing())
cues->LoadCuePoint();
const mkvparser::CuePoint* const cue_point = cues->GetFirst();
if (cue_point == NULL)
return false;
return true;
}
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
if (argc == 1) { if (argc == 1) {
printf("\t\t\tMkv Parser Sample Application\n"); printf("\t\t\tMkv Parser Sample Application\n");
@@ -142,13 +158,13 @@ int main(int argc, char* argv[]) {
const mkvparser::Tracks* pTracks = pSegment->GetTracks(); const mkvparser::Tracks* pTracks = pSegment->GetTracks();
unsigned long i = 0; unsigned long track_num = 0;
const unsigned long j = pTracks->GetTracksCount(); const unsigned long num_tracks = pTracks->GetTracksCount();
printf("\n\t\t\t Track Info\n"); printf("\n\t\t\t Track Info\n");
while (i != j) { while (track_num != num_tracks) {
const Track* const pTrack = pTracks->GetTrackByIndex(i++); const Track* const pTrack = pTracks->GetTrackByIndex(track_num++);
if (pTrack == NULL) continue; if (pTrack == NULL) continue;
@@ -288,6 +304,37 @@ int main(int argc, char* argv[]) {
pCluster = pSegment->GetNext(pCluster); pCluster = pSegment->GetNext(pCluster);
} }
if (InputHasCues(pSegment.get())) {
// Walk them.
const mkvparser::Cues* const cues = pSegment->GetCues();
const mkvparser::CuePoint* cue = cues->GetFirst();
int cue_point_num = 1;
printf("\t\tCues\n");
do {
for (track_num = 1; track_num != num_tracks; ++track_num) {
const mkvparser::Track* const track =
pTracks->GetTrackByNumber(track_num);
const mkvparser::CuePoint::TrackPosition* const track_pos =
cue->Find(track);
if (track_pos != NULL) {
const char track_type =
(track->GetType() == mkvparser::Track::kVideo) ? 'V' : 'A';
printf("\t\t\tCue Point %4d Track %3u(%c) Time %14lld "
"Block %4lld Pos %8x\n",
cue_point_num,
track_num, track_type,
cue->GetTime(pSegment.get()),
track_pos->m_block, track_pos->m_pos);
}
}
cue = cues->GetNext(cue);
++cue_point_num;
} while (cue != NULL);
}
fflush(stdout); fflush(stdout);
return 0; return 0;
} }