diff --git a/src/input/r_matroska.cpp b/src/input/r_matroska.cpp index e1535a36b..bb5a08902 100644 --- a/src/input/r_matroska.cpp +++ b/src/input/r_matroska.cpp @@ -2157,15 +2157,6 @@ kax_reader_c::add_attachments(KaxAttachments *a) { } } -void -kax_reader_c::flush_packetizers() { - uint32_t i; - - for (i = 0; i < tracks.size(); i++) - if (tracks[i]->ptzr != -1) - PTZR(tracks[i]->ptzr)->flush(); -} - void kax_reader_c::add_available_track_ids() { int i; diff --git a/src/input/r_matroska.h b/src/input/r_matroska.h index 0f9050c26..f2ed68458 100644 --- a/src/input/r_matroska.h +++ b/src/input/r_matroska.h @@ -182,7 +182,6 @@ protected: virtual void handle_attachments(mm_io_c *io, EbmlElement *l0, int64_t pos); virtual void handle_chapters(mm_io_c *io, EbmlElement *l0, int64_t pos); virtual void handle_tags(mm_io_c *io, EbmlElement *l0, int64_t pos); - virtual void flush_packetizers(); }; diff --git a/src/input/r_mpeg.cpp b/src/input/r_mpeg.cpp index 611da6c62..674feab3f 100644 --- a/src/input/r_mpeg.cpp +++ b/src/input/r_mpeg.cpp @@ -899,14 +899,6 @@ mpeg_ps_reader_c::read(generic_packetizer_c *, return FILE_STATUS_DONE; } -void -mpeg_ps_reader_c::flush_packetizers() { - vector::iterator i; - - foreach(i, reader_packetizers) - (*i)->flush(); -} - int mpeg_ps_reader_c::get_progress() { return 100 * io->getFilePointer() / size; diff --git a/src/input/r_mpeg.h b/src/input/r_mpeg.h index 75d6c8a1c..2f308408c 100644 --- a/src/input/r_mpeg.h +++ b/src/input/r_mpeg.h @@ -111,8 +111,6 @@ public: virtual bool find_next_packet(int &id); virtual bool find_next_packet_for_id(int id); - virtual void flush_packetizers(); - static int probe_file(mm_io_c *io, int64_t size); }; diff --git a/src/input/r_ogm.cpp b/src/input/r_ogm.cpp index 6bffe6700..dd9a4b514 100644 --- a/src/input/r_ogm.cpp +++ b/src/input/r_ogm.cpp @@ -1060,15 +1060,6 @@ ogm_reader_c::identify() { } } -void -ogm_reader_c::flush_packetizers() { - int i; - - for (i = 0; i < sdemuxers.size(); i++) - if (sdemuxers[i]->ptzr != -1) - PTZR(sdemuxers[i]->ptzr)->flush(); -} - void ogm_reader_c::handle_stream_comments() { int i, j, cch; diff --git a/src/input/r_ogm.h b/src/input/r_ogm.h index f4d0058c9..4998ebdce 100644 --- a/src/input/r_ogm.h +++ b/src/input/r_ogm.h @@ -123,7 +123,6 @@ private: virtual int read_headers(); virtual void process_header_page(ogg_page *pg); virtual void process_header_packets(ogm_demuxer_t *dmx); - virtual void flush_packetizers(); virtual void handle_stream_comments(); }; diff --git a/src/input/r_qtmp4.cpp b/src/input/r_qtmp4.cpp index 9cd884a4f..3738a531f 100644 --- a/src/input/r_qtmp4.cpp +++ b/src/input/r_qtmp4.cpp @@ -1573,15 +1573,6 @@ qtmp4_reader_c::identify() { } } -void -qtmp4_reader_c::flush_packetizers() { - uint32_t i; - - for (i = 0; i < demuxers.size(); i++) - if (demuxers[i]->ptzr != -1) - PTZR(demuxers[i]->ptzr)->flush(); -} - void qtmp4_reader_c::add_available_track_ids() { int i; diff --git a/src/input/r_qtmp4.h b/src/input/r_qtmp4.h index d7f94b05b..6f4f3ca36 100644 --- a/src/input/r_qtmp4.h +++ b/src/input/r_qtmp4.h @@ -210,7 +210,6 @@ protected: virtual bool parse_esds_atom(mm_mem_io_c &memio, qtmp4_demuxer_ptr &dmx, int level); virtual uint32_t read_esds_descr_len(mm_mem_io_c &memio); - virtual void flush_packetizers(); virtual void handle_video_with_bframes(qtmp4_demuxer_ptr &dmx, int64_t timecode, int64_t duration, diff --git a/src/input/r_real.cpp b/src/input/r_real.cpp index 1f0ec1622..d917ed14a 100644 --- a/src/input/r_real.cpp +++ b/src/input/r_real.cpp @@ -857,15 +857,6 @@ real_reader_c::get_information_from_data() { file->num_packets_read = 0; } -void -real_reader_c::flush_packetizers() { - uint32_t i; - - for (i = 0; i < demuxers.size(); i++) - if (demuxers[i]->ptzr != -1) - PTZR(demuxers[i]->ptzr)->flush(); -} - void real_reader_c::add_available_track_ids() { int i; diff --git a/src/input/r_real.h b/src/input/r_real.h index df2a00754..fe3e0da68 100644 --- a/src/input/r_real.h +++ b/src/input/r_real.h @@ -87,7 +87,6 @@ protected: virtual void set_dimensions(real_demuxer_t *dmx, unsigned char *buffer, int size); virtual void get_information_from_data(); - virtual void flush_packetizers(); virtual void deliver_aac_frames(real_demuxer_t *dmx, memory_c &mem); virtual void queue_audio_frames(real_demuxer_t *dmx, memory_c &mem, uint64_t timecode, uint32_t flags); diff --git a/src/input/r_srt.cpp b/src/input/r_srt.cpp index d4b52a7a2..1f744ab21 100644 --- a/src/input/r_srt.cpp +++ b/src/input/r_srt.cpp @@ -232,7 +232,11 @@ srt_reader_c::read(generic_packetizer_c *, subs.process(PTZR0); - return subs.empty() ? FILE_STATUS_DONE : FILE_STATUS_MOREDATA; + if (subs.empty()) { + flush_packetizers(); + return FILE_STATUS_DONE; + } + return FILE_STATUS_MOREDATA; } int diff --git a/src/input/r_ssa.cpp b/src/input/r_ssa.cpp index 695e5af2c..583880039 100644 --- a/src/input/r_ssa.cpp +++ b/src/input/r_ssa.cpp @@ -264,7 +264,11 @@ ssa_reader_c::read(generic_packetizer_c *, subs.process((textsubs_packetizer_c *)PTZR0); - return subs.empty() ? FILE_STATUS_DONE : FILE_STATUS_MOREDATA; + if (subs.empty()) { + flush_packetizers(); + return FILE_STATUS_DONE; + } + return FILE_STATUS_MOREDATA; } int diff --git a/src/input/r_tta.cpp b/src/input/r_tta.cpp index 0d2727d2e..7afee4305 100644 --- a/src/input/r_tta.cpp +++ b/src/input/r_tta.cpp @@ -156,8 +156,10 @@ tta_reader_c::read(generic_packetizer_c *, PTZR0->process(new packet_t(mem)); bytes_processed += nread; - if (pos >= seek_points.size()) + if (pos >= seek_points.size()) { + PTZR0->flush(); return FILE_STATUS_DONE; + } return FILE_STATUS_MOREDATA; } diff --git a/src/input/r_usf.cpp b/src/input/r_usf.cpp index 7bef6e932..2a567d4ae 100644 --- a/src/input/r_usf.cpp +++ b/src/input/r_usf.cpp @@ -358,8 +358,11 @@ usf_reader_c::read(generic_packetizer_c *ptzr, entry.m_start)); ++(track->m_current_entry); - if (track->m_entries.end() == track->m_current_entry) + if (track->m_entries.end() == track->m_current_entry) { + PTZR(track->m_ptzr)->flush(); return FILE_STATUS_DONE; + } + return FILE_STATUS_MOREDATA; } diff --git a/src/input/r_wav.cpp b/src/input/r_wav.cpp index 14f0a33be..2b8604cb5 100644 --- a/src/input/r_wav.cpp +++ b/src/input/r_wav.cpp @@ -195,12 +195,10 @@ wav_reader_c::read(generic_packetizer_c *, bytes_processed += nread; - if (nread != bps) { + if ((nread != bps) || io->eof()) { PTZR0->flush(); return FILE_STATUS_DONE; - } else if (io->eof()) - return FILE_STATUS_DONE; - else + } else return FILE_STATUS_MOREDATA; } diff --git a/src/input/r_wavpack.cpp b/src/input/r_wavpack.cpp index 02d2c1d5c..7ca5f6cf5 100644 --- a/src/input/r_wavpack.cpp +++ b/src/input/r_wavpack.cpp @@ -130,14 +130,18 @@ wavpack_reader_c::read(generic_packetizer_c *ptzr, while (dummy_meta.channel_count < meta.channel_count) { extra_frames_number++; block_size = wv_parse_frame(io, dummy_header, dummy_meta, false, false); - if (block_size == -1) + if (block_size == -1) { + PTZR0->flush(); return FILE_STATUS_DONE; + } data_size += block_size; io->skip(block_size); } - if (data_size < 0) + if (data_size < 0) { + PTZR0->flush(); return FILE_STATUS_DONE; + } data_size += 3 * sizeof(uint32_t); if (extra_frames_number) @@ -162,8 +166,10 @@ wavpack_reader_c::read(generic_packetizer_c *ptzr, put_uint32_le(databuffer, block_size); databuffer += 4; } - if (io->read(databuffer, block_size) < 0) + if (io->read(databuffer, block_size) < 0) { + PTZR0->flush(); return FILE_STATUS_DONE; + } databuffer += block_size; } @@ -181,8 +187,10 @@ wavpack_reader_c::read(generic_packetizer_c *ptzr, extra_frames_number++; block_size = wv_parse_frame(io_correc, dummy_header_correc, dummy_meta, false, false); - if (block_size == -1) + if (block_size == -1) { + PTZR0->flush(); return FILE_STATUS_DONE; + } data_size += block_size; io_correc->skip(block_size); } diff --git a/src/merge/pr_generic.cpp b/src/merge/pr_generic.cpp index 2282563e1..98fe85363 100644 --- a/src/merge/pr_generic.cpp +++ b/src/merge/pr_generic.cpp @@ -72,6 +72,7 @@ generic_packetizer_c::generic_packetizer_c(generic_reader_c *nreader, max_timecode_seen = 0; default_track_warning_printed = false; connected_to = 0; + has_been_flushed = false; // Let's see if the user specified audio sync for this track. found = false; @@ -1253,6 +1254,14 @@ generic_reader_c::get_queued_bytes() { return bytes; } +void +generic_reader_c::flush_packetizers() { + vector::const_iterator it; + + foreach(it, reader_packetizers) + (*it)->flush(); +} + // //-------------------------------------------------------------------- diff --git a/src/merge/pr_generic.h b/src/merge/pr_generic.h index e84e18d4f..cdb8ce134 100644 --- a/src/merge/pr_generic.h +++ b/src/merge/pr_generic.h @@ -381,6 +381,8 @@ public: virtual int64_t get_queued_bytes(); + virtual void flush_packetizers(); + protected: virtual bool demuxing_requested(char type, int64_t id); }; @@ -466,6 +468,8 @@ protected: int64_t last_cue_timecode; + bool has_been_flushed; + public: track_info_c ti; generic_reader_c *reader; @@ -497,6 +501,7 @@ public: return packet_queue.size(); } virtual void flush() { + has_been_flushed = true; } virtual int64_t get_smallest_timecode() { return (packet_queue.size() == 0) ? 0x0FFFFFFF : diff --git a/src/output/p_pcm.cpp b/src/output/p_pcm.cpp index ae2dc5dfb..2bab6b500 100644 --- a/src/output/p_pcm.cpp +++ b/src/output/p_pcm.cpp @@ -132,6 +132,8 @@ pcm_packetizer_c::flush() { bytes_output += size; buffer.remove(size); } + + generic_packetizer_c::flush(); } void diff --git a/src/output/p_video.cpp b/src/output/p_video.cpp index b5017f10d..f09b066b1 100644 --- a/src/output/p_video.cpp +++ b/src/output/p_video.cpp @@ -360,7 +360,8 @@ mpeg4_p2_video_packetizer_c::process_non_native(packet_cptr packet) { "native mode.\n"); } - mpeg4_p2_find_frame_types(packet->memory->data, packet->memory->size, frames); + mpeg4_p2_find_frame_types(packet->memory->data, packet->memory->size, + frames); // Add a timecode and a duration if they've been given. if (-1 != packet->timecode) @@ -505,6 +506,7 @@ mpeg4_p2_video_packetizer_c::flush_frames() { void mpeg4_p2_video_packetizer_c::flush() { flush_frames(); + generic_packetizer_c::flush(); } void