Made chapter selection based on a timeframe public.

This commit is contained in:
Moritz Bunkus 2003-09-11 22:50:44 +00:00
parent c2010e1a65
commit 0d7fe88692
3 changed files with 41 additions and 27 deletions

View File

@ -601,6 +601,38 @@ bool probe_xml_chapters(mm_text_io_c *in) {
return false; return false;
} }
KaxChapters *select_chapters_in_timeframe(KaxChapters *chapters,
int64_t min_tc, int64_t max_tc,
int64_t offset, bool validate) {
uint32_t i;
KaxEditionEntry *eentry;
for (i = 0; i < chapters->ListSize(); i++) {
if (validate)
validate_chapters(0, -1, *static_cast<EbmlMaster *>((*chapters)[i]));
remove_entries(min_tc, max_tc, offset,
*static_cast<EbmlMaster *>((*chapters)[i]));
}
i = 0;
while (i < chapters->ListSize()) {
eentry = static_cast<KaxEditionEntry *>((*chapters)[i]);
if (eentry->ListSize() == 0) {
chapters->Remove(i);
delete eentry;
} else
i++;
}
if (chapters->ListSize() == 0) {
delete chapters;
chapters = NULL;
}
return chapters;
}
KaxChapters *parse_xml_chapters(mm_text_io_c *in, int64_t min_tc, KaxChapters *parse_xml_chapters(mm_text_io_c *in, int64_t min_tc,
int64_t max_tc, int64_t offset) { int64_t max_tc, int64_t offset) {
bool done; bool done;
@ -608,10 +640,8 @@ KaxChapters *parse_xml_chapters(mm_text_io_c *in, int64_t min_tc,
XML_Parser parser; XML_Parser parser;
XML_Error xerror; XML_Error xerror;
char *emsg; char *emsg;
int i;
string buffer; string buffer;
KaxChapters *chapters; KaxChapters *chapters;
KaxEditionEntry *eentry;
done = 0; done = 0;
@ -650,29 +680,9 @@ KaxChapters *parse_xml_chapters(mm_text_io_c *in, int64_t min_tc,
chapters = pdata->chapters; chapters = pdata->chapters;
if (chapters != NULL) { if (chapters != NULL) {
chapters = select_chapters_in_timeframe(chapters, min_tc, max_tc, offset,
for (i = 0; i < chapters->ListSize(); i++) { true);
validate_chapters(0, -1, *static_cast<EbmlMaster *>((*chapters)[i])); if ((chapters != NULL) && !chapters->CheckMandatory())
remove_entries(min_tc, max_tc, offset,
*static_cast<EbmlMaster *>((*chapters)[i]));
}
i = 0;
while (i < chapters->ListSize()) {
eentry = static_cast<KaxEditionEntry *>((*chapters)[i]);
if (eentry->ListSize() == 0) {
chapters->Remove(i);
delete eentry;
} else
i++;
}
if (chapters->ListSize() == 0) {
delete chapters;
chapters = NULL;
} else if (!chapters->CheckMandatory())
die("chapters->CheckMandatory() failed. Should not have happened!"); die("chapters->CheckMandatory() failed. Should not have happened!");
} }

View File

@ -43,6 +43,9 @@ void write_chapters_xml(KaxChapters *chapters, FILE *out);
void write_chapters_simple(int &chapter_num, KaxChapters *chapters, FILE *out); void write_chapters_simple(int &chapter_num, KaxChapters *chapters, FILE *out);
KaxChapters *copy_chapters(KaxChapters *source); KaxChapters *copy_chapters(KaxChapters *source);
KaxChapters *select_chapters_in_timeframe(KaxChapters *chapters,
int64_t min_tc, int64_t max_tc,
int64_t offset, bool validate);
#endif // __CHAPTERS_H #endif // __CHAPTERS_H

View File

@ -1900,8 +1900,9 @@ void finish_file() {
start = cluster_helper->get_first_timecode() + offset; start = cluster_helper->get_first_timecode() + offset;
end = cluster_helper->get_max_timecode() + offset; end = cluster_helper->get_max_timecode() + offset;
chapters_here = parse_chapters(chapter_file_name, start, end, offset, chapters_here = copy_chapters(kax_chapters);
chapter_language, chapter_charset); chapters_here = select_chapters_in_timeframe(chapters_here, start, end,
offset, false);
if (chapters_here != NULL) if (chapters_here != NULL)
kax_chapters_void->ReplaceWith(*chapters_here, *out, true); kax_chapters_void->ReplaceWith(*chapters_here, *out, true);
delete kax_chapters_void; delete kax_chapters_void;