From a9842b097673adbb5458538e1a87b8a681a5755f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sat, 6 Sep 2003 18:22:29 +0000 Subject: [PATCH] Reorganization part 1. Added the packetizer to produce a packet for to the reader's read() function. Removed get_packet() from all readers. --- src/pr_generic.cpp | 2 +- src/pr_generic.h | 3 +- src/r_aac.cpp | 6 +--- src/r_aac.h | 3 +- src/r_ac3.cpp | 6 +--- src/r_ac3.h | 3 +- src/r_avi.cpp | 69 ++++++++++++++++------------------------------ src/r_avi.h | 3 +- src/r_dts.cpp | 6 +--- src/r_dts.h | 3 +- src/r_matroska.cpp | 28 ++----------------- src/r_matroska.h | 3 +- src/r_mp3.cpp | 6 +--- src/r_mp3.h | 3 +- src/r_mp4.cpp | 22 +++++++-------- src/r_mp4.h | 3 +- src/r_ogm.cpp | 26 +---------------- src/r_ogm.h | 3 +- src/r_real.cpp | 28 ++----------------- src/r_real.h | 3 +- src/r_srt.cpp | 6 +--- src/r_srt.h | 3 +- src/r_ssa.cpp | 6 +--- src/r_ssa.h | 3 +- src/r_wav.cpp | 11 +------- src/r_wav.h | 3 +- 26 files changed, 60 insertions(+), 201 deletions(-) diff --git a/src/pr_generic.cpp b/src/pr_generic.cpp index f5982fde7..cd967a93d 100644 --- a/src/pr_generic.cpp +++ b/src/pr_generic.cpp @@ -178,7 +178,7 @@ void generic_packetizer_c::set_tag_track_uid() { } int generic_packetizer_c::read() { - return reader->read(); + return reader->read(this); } void generic_packetizer_c::reset() { diff --git a/src/pr_generic.h b/src/pr_generic.h index baf8d5149..db33cfdcf 100644 --- a/src/pr_generic.h +++ b/src/pr_generic.h @@ -214,8 +214,7 @@ protected: public: generic_reader_c(track_info_t *nti); virtual ~generic_reader_c(); - virtual int read() = 0; - virtual packet_t *get_packet() = 0; + virtual int read(generic_packetizer_c *ptzr) = 0; virtual int display_priority() = 0; virtual void display_progress() = 0; virtual void set_headers() = 0; diff --git a/src/r_aac.cpp b/src/r_aac.cpp index 20bce6952..f3bf5bebf 100644 --- a/src/r_aac.cpp +++ b/src/r_aac.cpp @@ -141,7 +141,7 @@ void aac_reader_c::guess_adts_version() { } } -int aac_reader_c::read() { +int aac_reader_c::read(generic_packetizer_c *) { int nread; nread = mm_io->read(chunk, 4096); @@ -154,10 +154,6 @@ int aac_reader_c::read() { return EMOREDATA; } -packet_t *aac_reader_c::get_packet() { - return aacpacketizer->get_packet(); -} - int aac_reader_c::display_priority() { return DISPLAYPRIORITY_HIGH - 1; } diff --git a/src/r_aac.h b/src/r_aac.h index 79c2c22be..e7d49533c 100644 --- a/src/r_aac.h +++ b/src/r_aac.h @@ -44,8 +44,7 @@ public: aac_reader_c(track_info_t *nti) throw (error_c); virtual ~aac_reader_c(); - virtual int read(); - virtual packet_t *get_packet(); + virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); virtual void display_progress(); virtual void set_headers(); diff --git a/src/r_ac3.cpp b/src/r_ac3.cpp index 81f7f5fdc..6d09f7c09 100644 --- a/src/r_ac3.cpp +++ b/src/r_ac3.cpp @@ -94,7 +94,7 @@ ac3_reader_c::~ac3_reader_c() { delete ac3packetizer; } -int ac3_reader_c::read() { +int ac3_reader_c::read(generic_packetizer_c *) { int nread; nread = mm_io->read(chunk, 4096); @@ -107,10 +107,6 @@ int ac3_reader_c::read() { return EMOREDATA; } -packet_t *ac3_reader_c::get_packet() { - return ac3packetizer->get_packet(); -} - int ac3_reader_c::display_priority() { return DISPLAYPRIORITY_HIGH - 1; } diff --git a/src/r_ac3.h b/src/r_ac3.h index c08098ebf..d1f4a99da 100644 --- a/src/r_ac3.h +++ b/src/r_ac3.h @@ -43,8 +43,7 @@ public: ac3_reader_c(track_info_t *nti) throw (error_c); virtual ~ac3_reader_c(); - virtual int read(); - virtual packet_t *get_packet(); + virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); virtual void display_progress(); virtual void set_headers(); diff --git a/src/r_avi.cpp b/src/r_avi.cpp index db2e25e9e..e420ee320 100644 --- a/src/r_avi.cpp +++ b/src/r_avi.cpp @@ -297,17 +297,17 @@ int avi_reader_c::is_keyframe(unsigned char *data, long size, int suggestion) { // {{{ FUNCTION avi_reader_c::read -int avi_reader_c::read() { +int avi_reader_c::read(generic_packetizer_c *ptzr) { int nread, key, last_frame, i; avi_demuxer_t *demuxer; bool need_more_data, done; int frames_read, size; int64_t duration; - debug_enter("avi_reader_c::read (video)"); + if ((vpacketizer != NULL) && !video_done && (vpacketizer == ptzr)) { + debug_enter("avi_reader_c::read (video)"); - need_more_data = false; - if ((vpacketizer != NULL) && !video_done) { + need_more_data = false; last_frame = 0; done = false; @@ -377,16 +377,24 @@ int avi_reader_c::read() { video_done = 1; } else if (frames != (maxframes + 1)) need_more_data = true; - } - debug_leave("avi_reader_c::read (video)"); - debug_enter("avi_reader_c::read (audio)"); + debug_leave("avi_reader_c::read (video)"); + + if (need_more_data) + return EMOREDATA; + else + return 0; + } for (i = 0; i < ademuxers.size(); i++) { demuxer = ademuxers[i]; - if (demuxer->packetizer->packet_available() >= 2) + + if (demuxer->packetizer != ptzr) continue; + debug_enter("avi_reader_c::read (audio)"); + + need_more_data = false; AVI_set_audio_track(avi, demuxer->aid); if (AVI_audio_format(avi) == 0x0001) size = demuxer->channels * demuxer->bits_per_sample * @@ -406,45 +414,16 @@ int avi_reader_c::read() { } if (!demuxer->eos) need_more_data = true; + + debug_leave("avi_reader_c::read (audio)"); + + if (need_more_data) + return EMOREDATA; + else + return 0; } - debug_leave("avi_reader_c::read (audio)"); - - if (need_more_data) - return EMOREDATA; - else - return 0; -} - -// }}} - -// {{{ FUNCTION avi_reader_c::get_packet - -packet_t *avi_reader_c::get_packet() { - generic_packetizer_c *winner; - avi_demuxer_t *demuxer; - int i; - - winner = NULL; - - if ((vpacketizer != NULL) && (vpacketizer->packet_available())) - winner = vpacketizer; - - for (i = 0; i < ademuxers.size(); i++) { - demuxer = ademuxers[i]; - if (winner == NULL) { - if (demuxer->packetizer->packet_available()) - winner = demuxer->packetizer; - } else if (winner->packet_available() && - (winner->get_smallest_timecode() > - demuxer->packetizer->get_smallest_timecode())) - winner = demuxer->packetizer; - } - - if (winner != NULL) - return winner->get_packet(); - else - return NULL; + return 0; } // }}} diff --git a/src/r_avi.h b/src/r_avi.h index 3d58fc283..4401ac0d2 100644 --- a/src/r_avi.h +++ b/src/r_avi.h @@ -63,8 +63,7 @@ public: avi_reader_c(track_info_t *nti) throw (error_c); virtual ~avi_reader_c(); - virtual int read(); - virtual packet_t *get_packet(); + virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); virtual void display_progress(); virtual void set_headers(); diff --git a/src/r_dts.cpp b/src/r_dts.cpp index e9cff76db..5a639a1e2 100644 --- a/src/r_dts.cpp +++ b/src/r_dts.cpp @@ -95,7 +95,7 @@ dts_reader_c::~dts_reader_c() { delete dtspacketizer; } -int dts_reader_c::read() { +int dts_reader_c::read(generic_packetizer_c *) { int nread; nread = mm_io->read(chunk, max_dts_packet_size); @@ -108,10 +108,6 @@ int dts_reader_c::read() { return EMOREDATA; } -packet_t *dts_reader_c::get_packet() { - return dtspacketizer->get_packet(); -} - int dts_reader_c::display_priority() { return DISPLAYPRIORITY_HIGH - 1; } diff --git a/src/r_dts.h b/src/r_dts.h index dc250779c..447ae51d9 100644 --- a/src/r_dts.h +++ b/src/r_dts.h @@ -43,8 +43,7 @@ public: dts_reader_c(track_info_t *nti) throw (error_c); virtual ~dts_reader_c(); - virtual int read(); - virtual packet_t *get_packet(); + virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); virtual void display_progress(); virtual void set_headers(); diff --git a/src/r_matroska.cpp b/src/r_matroska.cpp index 88343ae41..5e6773cd7 100644 --- a/src/r_matroska.cpp +++ b/src/r_matroska.cpp @@ -1242,7 +1242,7 @@ void kax_reader_c::create_packetizers() { // {{{ FUNCTION kax_reader_c::read() -int kax_reader_c::read() { +int kax_reader_c::read(generic_packetizer_c *) { int upper_lvl_el, i; // Elements for different levels EbmlElement *l0 = NULL, *l1 = NULL, *l2 = NULL; @@ -1414,31 +1414,7 @@ int kax_reader_c::read() { // }}} -// {{{ FUNCTIONS get_packet(), display_*, set_headers() - -packet_t *kax_reader_c::get_packet() { - generic_packetizer_c *winner; - kax_track_t *t; - int i; - - winner = NULL; - - for (i = 0; i < tracks.size(); i++) { - t = tracks[i]; - if (winner == NULL) { - if (t->packetizer->packet_available()) - winner = t->packetizer; - } else if (winner->packet_available() && - (winner->get_smallest_timecode() > - t->packetizer->get_smallest_timecode())) - winner = t->packetizer; - } - - if (winner != NULL) - return winner->get_packet(); - else - return NULL; -} +// {{{ FUNCTIONS display_*, set_headers() int kax_reader_c::display_priority() { int i; diff --git a/src/r_matroska.h b/src/r_matroska.h index f9a4cf8bf..d8fa6ce12 100644 --- a/src/r_matroska.h +++ b/src/r_matroska.h @@ -109,8 +109,7 @@ public: kax_reader_c(track_info_t *nti) throw (error_c); virtual ~kax_reader_c(); - virtual int read(); - virtual packet_t *get_packet(); + virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); virtual void display_progress(); diff --git a/src/r_mp3.cpp b/src/r_mp3.cpp index 50f9cfbfc..833bf57b6 100644 --- a/src/r_mp3.cpp +++ b/src/r_mp3.cpp @@ -104,7 +104,7 @@ mp3_reader_c::~mp3_reader_c() { delete mp3packetizer; } -int mp3_reader_c::read() { +int mp3_reader_c::read(generic_packetizer_c *) { int nread; nread = mm_io->read(chunk, 4096); @@ -117,10 +117,6 @@ int mp3_reader_c::read() { return EMOREDATA; } -packet_t *mp3_reader_c::get_packet() { - return mp3packetizer->get_packet(); -} - int mp3_reader_c::display_priority() { return DISPLAYPRIORITY_HIGH - 1; } diff --git a/src/r_mp3.h b/src/r_mp3.h index 7b31a6835..be027514f 100644 --- a/src/r_mp3.h +++ b/src/r_mp3.h @@ -42,8 +42,7 @@ public: mp3_reader_c(track_info_t *nti) throw (error_c); virtual ~mp3_reader_c(); - virtual int read(); - virtual packet_t *get_packet(); + virtual int read(generic_packetizer_c *ptzr); virtual void set_headers(); virtual void identify(); diff --git a/src/r_mp4.cpp b/src/r_mp4.cpp index d139aa6fd..259bd4ea3 100644 --- a/src/r_mp4.cpp +++ b/src/r_mp4.cpp @@ -670,7 +670,7 @@ void qtmp4_reader_c::handle_header_atoms(uint32_t parent, int64_t parent_size, io->setFilePointer(target_pos); } -int qtmp4_reader_c::read() { +int qtmp4_reader_c::read(generic_packetizer_c *ptzr) { uint32_t i, k, frame, frame_size; qtmp4_demuxer_t *dmx; bool chunks_left, is_keyframe; @@ -684,7 +684,7 @@ int qtmp4_reader_c::read() { for (i = 0; i < demuxers.size(); i++) { dmx = demuxers[i]; - if (dmx->packetizer == NULL) + if (dmx->packetizer != ptzr) continue; if (dmx->sample_size != 0) { @@ -799,14 +799,16 @@ int qtmp4_reader_c::read() { if (dmx->pos < dmx->sample_table_len) chunks_left = true; } + + if (chunks_left) + return EMOREDATA; + else { + done = true; + return 0; + } } - if (chunks_left) - return EMOREDATA; - else { - done = true; - return 0; - } + return 0; } void qtmp4_reader_c::create_packetizers() { @@ -867,10 +869,6 @@ void qtmp4_reader_c::set_headers() { demuxers[i]->packetizer->set_headers(); } -packet_t *qtmp4_reader_c::get_packet() { - return NULL; -} - int qtmp4_reader_c::display_priority() { return DISPLAYPRIORITY_MEDIUM; } diff --git a/src/r_mp4.h b/src/r_mp4.h index bb3571a78..22a6c5619 100644 --- a/src/r_mp4.h +++ b/src/r_mp4.h @@ -121,8 +121,7 @@ public: qtmp4_reader_c(track_info_t *nti) throw (error_c); virtual ~qtmp4_reader_c(); - virtual int read(); - virtual packet_t *get_packet(); + virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); virtual void display_progress(); virtual void set_headers(); diff --git a/src/r_ogm.cpp b/src/r_ogm.cpp index bc9bf4fba..1cc237254 100644 --- a/src/r_ogm.cpp +++ b/src/r_ogm.cpp @@ -662,7 +662,7 @@ int ogm_reader_c::read_headers() { * General reader. Before returning it MUST guarantee that each demuxer has * a page available OR that the corresponding stream is finished. */ -int ogm_reader_c::read() { +int ogm_reader_c::read(generic_packetizer_c *) { int i; ogg_page og; @@ -685,30 +685,6 @@ int ogm_reader_c::read() { return 0; } -packet_t *ogm_reader_c::get_packet() { - generic_packetizer_c *winner; - ogm_demuxer_t *demuxer; - int i; - - winner = NULL; - - for (i = 0; i < num_sdemuxers; i++) { - demuxer = sdemuxers[i]; - if (winner == NULL) { - if (demuxer->packetizer->packet_available()) - winner = demuxer->packetizer; - } else if (winner->packet_available() && - (winner->get_smallest_timecode() > - demuxer->packetizer->get_smallest_timecode())) - winner = demuxer->packetizer; - } - - if (winner != NULL) - return winner->get_packet(); - else - return NULL; -} - int ogm_reader_c::display_priority() { int i; diff --git a/src/r_ogm.h b/src/r_ogm.h index bdab1f461..dfb6d3a2d 100644 --- a/src/r_ogm.h +++ b/src/r_ogm.h @@ -63,8 +63,7 @@ public: ogm_reader_c(track_info_t *nti) throw (error_c); virtual ~ogm_reader_c(); - virtual int read(); - virtual packet_t *get_packet(); + virtual int read(generic_packetizer_c *ptzr); virtual void set_headers(); virtual void identify(); diff --git a/src/r_real.cpp b/src/r_real.cpp index 63e0a7602..51aed0294 100644 --- a/src/r_real.cpp +++ b/src/r_real.cpp @@ -536,7 +536,7 @@ int real_reader_c::finish() { // {{{ FUNCTION real_reader_c::read() -int real_reader_c::read() { +int real_reader_c::read(generic_packetizer_c *) { uint32_t object_version, length, id, timecode, flags, object_id; unsigned char *chunk; real_demuxer_t *dmx; @@ -632,31 +632,7 @@ int real_reader_c::read() { // }}} -// {{{ FUNCTIONS get_packet(), display_*(), set_headers(), identify() - -packet_t *real_reader_c::get_packet() { - generic_packetizer_c *winner; - real_demuxer_t *demuxer; - int i; - - winner = NULL; - - for (i = 0; i < demuxers.size(); i++) { - demuxer = demuxers[i]; - if (winner == NULL) { - if (demuxer->packetizer->packet_available()) - winner = demuxer->packetizer; - } else if (winner->packet_available() && - (winner->get_smallest_timecode() > - demuxer->packetizer->get_smallest_timecode())) - winner = demuxer->packetizer; - } - - if (winner != NULL) - return winner->get_packet(); - else - return NULL; -} +// {{{ FUNCTIONS display_*(), set_headers(), identify() int real_reader_c::display_priority() { return DISPLAYPRIORITY_MEDIUM; diff --git a/src/r_real.h b/src/r_real.h index 56e2c33d0..bf2269f36 100644 --- a/src/r_real.h +++ b/src/r_real.h @@ -75,8 +75,7 @@ public: real_reader_c(track_info_t *nti) throw (error_c); virtual ~real_reader_c(); - virtual int read(); - virtual packet_t *get_packet(); + virtual int read(generic_packetizer_c *ptzr); virtual int display_priority(); virtual void display_progress(); virtual void set_headers(); diff --git a/src/r_srt.cpp b/src/r_srt.cpp index baf0633f0..6ffdbe572 100644 --- a/src/r_srt.cpp +++ b/src/r_srt.cpp @@ -90,7 +90,7 @@ srt_reader_c::~srt_reader_c() { delete textsubs_packetizer; } -int srt_reader_c::read() { +int srt_reader_c::read(generic_packetizer_c *) { int64_t start, end; char *chunk; subtitles_c subs; @@ -148,10 +148,6 @@ int srt_reader_c::read() { return 0; } -packet_t *srt_reader_c::get_packet() { - return textsubs_packetizer->get_packet(); -} - int srt_reader_c::display_priority() { return DISPLAYPRIORITY_LOW; } diff --git a/src/r_srt.h b/src/r_srt.h index cb25b8644..b8fc80676 100644 --- a/src/r_srt.h +++ b/src/r_srt.h @@ -41,8 +41,7 @@ public: srt_reader_c(track_info_t *nti) throw (error_c); virtual ~srt_reader_c(); - virtual int read(); - virtual packet_t *get_packet(); + virtual int read(generic_packetizer_c *ptzr); virtual void set_headers(); virtual void identify(); diff --git a/src/r_ssa.cpp b/src/r_ssa.cpp index 5cd8af20b..4a71d6890 100644 --- a/src/r_ssa.cpp +++ b/src/r_ssa.cpp @@ -211,7 +211,7 @@ string ssa_reader_c::recode_text(vector &fields) { return res; } -int ssa_reader_c::read() { +int ssa_reader_c::read(generic_packetizer_c *) { string line, stime, orig_line, comma; int i, num; int64_t start, end; @@ -290,10 +290,6 @@ int ssa_reader_c::read() { return 0; } -packet_t *ssa_reader_c::get_packet() { - return textsubs_packetizer->get_packet(); -} - int ssa_reader_c::display_priority() { return DISPLAYPRIORITY_LOW; } diff --git a/src/r_ssa.h b/src/r_ssa.h index cecd15b4c..06022a91a 100644 --- a/src/r_ssa.h +++ b/src/r_ssa.h @@ -48,8 +48,7 @@ public: ssa_reader_c(track_info_t *nti) throw (error_c); virtual ~ssa_reader_c(); - virtual int read(); - virtual packet_t *get_packet(); + virtual int read(generic_packetizer_c *ptzr); virtual void set_headers(); virtual void identify(); diff --git a/src/r_wav.cpp b/src/r_wav.cpp index 321ae60e9..552658554 100644 --- a/src/r_wav.cpp +++ b/src/r_wav.cpp @@ -211,7 +211,7 @@ wav_reader_c::~wav_reader_c() { delete dtspacketizer; } -int wav_reader_c::read() { +int wav_reader_c::read(generic_packetizer_c *) { if (pcmpacketizer) { int nread; @@ -266,15 +266,6 @@ int wav_reader_c::read() { return 0; } -packet_t *wav_reader_c::get_packet() { - if (pcmpacketizer) - return pcmpacketizer->get_packet(); - else if (dtspacketizer) - return dtspacketizer->get_packet(); - - return NULL; -} - int wav_reader_c::display_priority() { return DISPLAYPRIORITY_HIGH - 1; } diff --git a/src/r_wav.h b/src/r_wav.h index f7e986eea..0c57aab46 100644 --- a/src/r_wav.h +++ b/src/r_wav.h @@ -53,8 +53,7 @@ public: wav_reader_c(track_info_t *nti) throw (error_c); virtual ~wav_reader_c(); - virtual int read(); - virtual packet_t *get_packet(); + virtual int read(generic_packetizer_c *ptzr); virtual void set_headers(); virtual void identify();