From dcb20aca12ea2182414088919494a299ba26d70b Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sat, 8 Nov 2003 10:26:07 +0000 Subject: [PATCH] Sped up the parsing of the .idx files. --- src/input/r_matroska.cpp | 25 +++++++++----- src/input/r_matroska.h | 10 +----- src/input/r_vobsub.cpp | 73 ++++++++++++++++++++++++---------------- 3 files changed, 61 insertions(+), 47 deletions(-) diff --git a/src/input/r_matroska.cpp b/src/input/r_matroska.cpp index 6ae8fdbf6..f47e5f297 100644 --- a/src/input/r_matroska.cpp +++ b/src/input/r_matroska.cpp @@ -114,9 +114,8 @@ int kax_reader_c::probe_file(mm_io_c *mm_io, int64_t size) { kax_reader_c::kax_reader_c(track_info_t *nti) throw (error_c): generic_reader_c(nti) { - num_buffers = 0; - buffers = NULL; + title = ""; segment_duration = 0.0; first_timecode = -1.0; @@ -765,11 +764,9 @@ int kax_reader_c::read_headers() { if (verbose > 1) mxinfo(PFX "| + title: %s\n", tmp); safefree(tmp); - if (segment_title.length() == 0) { - tmp = UTFstring_to_cstrutf8(UTFstring(*ktitle)); - segment_title = tmp; - safefree(tmp); - } + tmp = UTFstring_to_cstrutf8(UTFstring(*ktitle)); + title = tmp; + safefree(tmp); } } else if (EbmlId(*l1) == KaxTracks::ClassInfos.GlobalId) { @@ -1420,6 +1417,9 @@ void kax_reader_c::create_packetizers() { "file.\n", t->tuid); } } + + if (segment_title.length() == 0) + segment_title = title; } // }}} @@ -1687,13 +1687,20 @@ void kax_reader_c::identify() { string info; char *str; - mxinfo("File '%s': container: Matroska\n", ti->fname); + if (identify_verbose && (title.length() > 0)) + mxinfo("File '%s': container: Matroska [title:%s]\n", ti->fname, + escape(title.c_str()).c_str()); + else + mxinfo("File '%s': container: Matroska\n", ti->fname); for (i = 0; i < tracks.size(); i++) if (tracks[i]->ok) { if (identify_verbose) { info = " ["; if (tracks[i]->language != NULL) - info += string("language:") + string(tracks[i]->language) + + info += string("language:") + escape(tracks[i]->language) + + string(" "); + if (tracks[i]->track_name != NULL) + info += string("track_name:") + escape(tracks[i]->track_name) + string(" "); info += "]"; } else diff --git a/src/input/r_matroska.h b/src/input/r_matroska.h index 010f0e15b..84d52d247 100644 --- a/src/input/r_matroska.h +++ b/src/input/r_matroska.h @@ -102,11 +102,6 @@ typedef struct { generic_packetizer_c *packetizer; } kax_track_t; -typedef struct { - unsigned char *data; - int length; -} buffer_t; - class kax_reader_c: public generic_reader_c { private: int act_wchar; @@ -120,13 +115,10 @@ private: EbmlStream *es; EbmlElement *saved_l1, *saved_l2, *segment; - KaxCluster *cluster; - buffer_t **buffers; - int num_buffers; - float segment_duration, last_timecode, first_timecode; + string title; vector attachments; diff --git a/src/input/r_vobsub.cpp b/src/input/r_vobsub.cpp index 583f933db..f62906a58 100644 --- a/src/input/r_vobsub.cpp +++ b/src/input/r_vobsub.cpp @@ -192,9 +192,10 @@ void vobsub_reader_c::parse_headers() { const char *sline; char language[3]; vobsub_track_c *track; - int64_t filepos, timestamp, next_pos; + int64_t filepos, timestamp, next_pos, this_pos; int hour, minute, second, msecond, idx; - uint32_t i, k, l, m; + vector *positions, sorted_positions; + uint32_t i, k, l, tsize, psize, ssize; language[0] = 0; track = NULL; @@ -252,36 +253,50 @@ void vobsub_reader_c::parse_headers() { idx_data += "\n"; } - filepos = sub_file->get_size(); - for (i = 0; i < tracks.size(); i++) { - for (k = 0; k < tracks[i]->positions.size(); k++) { - next_pos = filepos; - for (l = 0; l < tracks.size(); l++) { - for (m = 0; m < tracks[l]->positions.size(); m++) { - if ((tracks[l]->positions[m] < next_pos) && - (tracks[l]->positions[m] > tracks[i]->positions[k])) - next_pos = tracks[l]->positions[m]; - } - } - tracks[i]->sizes.push_back(next_pos - tracks[i]->positions[k]); + if (!identifying) { + filepos = sub_file->get_size(); + tsize = tracks.size(); + for (i = 0; i < tsize; i++) { + positions = &tracks[i]->positions; + psize = positions->size(); + for (k = 0; k < psize; k++) + sorted_positions.push_back((*positions)[k]); } - } + sort(sorted_positions.begin(), sorted_positions.end()); + ssize = sorted_positions.size(); - for (i = 0; i < tracks.size(); i++) - if ((tracks[i]->positions.size() != tracks[i]->timecodes.size()) || - (tracks[i]->positions.size() != tracks[i]->sizes.size())) - mxerror(PFX "Have %u positions, %u sizes and %u timecodes. This should " - "not have happened. Please file a bug report.\n", - tracks[i]->positions.size(), tracks[i]->sizes.size(), - tracks[i]->timecodes.size()); + for (i = 0; i < tsize; i++) { + positions = &tracks[i]->positions; + psize = positions->size(); + for (k = 0; k < psize; k++) { + next_pos = filepos; + this_pos = (*positions)[k]; + for (l = 0; l < ssize; l++) + if (sorted_positions[l] > this_pos) { + next_pos = sorted_positions[l]; + break; + } - if (verbose > 1) { - for (i = 0; i < tracks.size(); i++) { - mxinfo("vobsub_reader: Track number %u\n", i); - for (k = 0; k < tracks[i]->positions.size(); k++) - mxinfo("vobsub_reader: %04u position: %12lld, size: %12lld, " - "timecode: " "%12lld\n", k, tracks[i]->positions[k], - tracks[i]->sizes[k], tracks[i]->timecodes[k]); + tracks[i]->sizes.push_back(next_pos - this_pos); + } + } + + for (i = 0; i < tracks.size(); i++) + if ((tracks[i]->positions.size() != tracks[i]->timecodes.size()) || + (tracks[i]->positions.size() != tracks[i]->sizes.size())) + mxerror(PFX "Have %u positions, %u sizes and %u timecodes. This " + "should not have happened. Please file a bug report.\n", + tracks[i]->positions.size(), tracks[i]->sizes.size(), + tracks[i]->timecodes.size()); + + if (verbose > 1) { + for (i = 0; i < tracks.size(); i++) { + mxinfo("vobsub_reader: Track number %u\n", i); + for (k = 0; k < tracks[i]->positions.size(); k++) + mxinfo("vobsub_reader: %04u position: %12lld, size: %12lld, " + "timecode: " "%12lld\n", k, tracks[i]->positions[k], + tracks[i]->sizes[k], tracks[i]->timecodes[k]); + } } } }