Reorganization part 1. Added the packetizer to produce a packet for to the reader's read() function. Removed get_packet() from all readers.

This commit is contained in:
Moritz Bunkus 2003-09-06 18:22:29 +00:00
parent 74fe2ce5c5
commit a9842b0976
26 changed files with 60 additions and 201 deletions

View File

@ -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() {

View File

@ -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;

View File

@ -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;
}

View File

@ -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();

View File

@ -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;
}

View File

@ -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();

View File

@ -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;
}
// }}}

View File

@ -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();

View File

@ -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;
}

View File

@ -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();

View File

@ -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;

View File

@ -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();

View File

@ -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;
}

View File

@ -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();

View File

@ -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;
}

View File

@ -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();

View File

@ -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;

View File

@ -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();

View File

@ -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;

View File

@ -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();

View File

@ -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;
}

View File

@ -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();

View File

@ -211,7 +211,7 @@ string ssa_reader_c::recode_text(vector<string> &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;
}

View File

@ -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();

View File

@ -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;
}

View File

@ -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();