[vlc-commits] mux: mp4: try not to set artitrary length on boundaries

Francois Cartegnie git at videolan.org
Wed Jun 11 20:50:22 CEST 2014


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Jun 11 20:47:52 2014 +0200| [a4db08e9758c216ee58864adbda9b6454f78553b] | committer: Francois Cartegnie

mux: mp4: try not to set artitrary length on boundaries

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a4db08e9758c216ee58864adbda9b6454f78553b
---

 modules/mux/mp4.c |   35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/modules/mux/mp4.c b/modules/mux/mp4.c
index 0f7444f..2f2f34e 100644
--- a/modules/mux/mp4.c
+++ b/modules/mux/mp4.c
@@ -473,9 +473,38 @@ static int Mux(sout_mux_t *p_mux)
             /* Fix length of the sample */
             if (block_FifoCount(p_input->p_fifo) > 0) {
                 block_t *p_next = block_FifoShow(p_input->p_fifo);
-                int64_t i_diff  = p_next->i_dts - p_data->i_dts;
-                if (i_diff < CLOCK_FREQ) /* protection */
-                    p_data->i_length = i_diff;
+                if ( p_next->i_flags & BLOCK_FLAG_DISCONTINUITY )
+                { /* we have no way to know real length except by decoding */
+                    if ( p_stream->fmt.i_cat == VIDEO_ES )
+                    {
+                        p_data->i_length = CLOCK_FREQ *
+                                           p_stream->fmt.video.i_frame_rate_base /
+                                           p_stream->fmt.video.i_frame_rate;
+                        msg_Dbg( p_mux, "video track %d fixup to %"PRId64" for sample %u",
+                                 p_stream->i_track_id, p_data->i_length, p_stream->i_entry_count );
+                    }
+                    else if ( p_stream->fmt.i_cat == AUDIO_ES &&
+                              p_stream->fmt.audio.i_rate &&
+                              p_data->i_nb_samples )
+                    {
+                        p_data->i_length = CLOCK_FREQ * p_data->i_nb_samples /
+                                           p_stream->fmt.audio.i_rate;
+                        msg_Dbg( p_mux, "audio track %d fixup to %"PRId64" for sample %u",
+                                 p_stream->i_track_id, p_data->i_length, p_stream->i_entry_count );
+                    }
+                    else if ( p_data->i_length <= 0 )
+                    {
+                        msg_Warn( p_mux, "unknown length for track %d sample %u",
+                                  p_stream->i_track_id, p_stream->i_entry_count );
+                        p_data->i_length = 1;
+                    }
+                }
+                else
+                {
+                    int64_t i_diff  = p_next->i_dts - p_data->i_dts;
+                    if (i_diff < CLOCK_FREQ) /* protection */
+                        p_data->i_length = i_diff;
+                }
             }
             if (p_data->i_length <= 0) {
                 msg_Warn(p_mux, "i_length <= 0");



More information about the vlc-commits mailing list