diff options
author | Jan Schmidt <jan@centricular.com> | 2016-05-15 19:04:20 +1000 |
---|---|---|
committer | Jan Schmidt <jan@centricular.com> | 2016-05-15 19:30:55 +1000 |
commit | e3b554f0e63bac97bb57a7b81bc8c5ae3810cb3f (patch) | |
tree | f867d1eb3f8c77c19e3a8d0abd467c50222c2497 | |
parent | d520e25db314f2a29c140b3344021079051d2d57 (diff) |
mpegdemux: Fix backward timestamp scan on small files.
When the file size is smaller than the configured 4MB scan
limit for timestamps, don't underflow the guard variable
when checking if it's time to stop.
Limit the backward SCR scan to the same 4MB as the PTS scan.
Add some comments.
-rw-r--r-- | gst/mpegdemux/gstmpegdemux.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/gst/mpegdemux/gstmpegdemux.c b/gst/mpegdemux/gstmpegdemux.c index 5d7507bee..3a7229d8a 100644 --- a/gst/mpegdemux/gstmpegdemux.c +++ b/gst/mpegdemux/gstmpegdemux.c @@ -2597,9 +2597,11 @@ gst_ps_demux_scan_forward_ts (GstPsDemux * demux, guint64 * pos, GstMapInfo map; do { + /* Check we can get at least scan_sz bytes */ if (offset + scan_sz > demux->sink_segment.stop) return FALSE; + /* Don't go further than 'limit' bytes */ if (limit && offset > *pos + limit) return FALSE; @@ -2658,10 +2660,12 @@ gst_ps_demux_scan_backward_ts (GstPsDemux * demux, guint64 * pos, GstMapInfo map; do { + /* Check we have at least scan_sz bytes available */ if (offset < scan_sz - 1) return FALSE; - if (limit && offset < *pos - limit) + /* Don't go backward past the start or 'limit' bytes */ + if (limit && offset + limit < *pos) return FALSE; if (offset > BLOCK_SZ) @@ -2750,7 +2754,8 @@ gst_ps_sink_get_duration (GstPsDemux * demux) demux->first_scr_offset = offset; /* scan for last SCR in the stream */ offset = demux->sink_segment.stop; - gst_ps_demux_scan_backward_ts (demux, &offset, SCAN_SCR, &demux->last_scr, 0); + gst_ps_demux_scan_backward_ts (demux, &offset, SCAN_SCR, &demux->last_scr, + DURATION_SCAN_LIMIT); GST_DEBUG_OBJECT (demux, "Last SCR: %" G_GINT64_FORMAT " %" GST_TIME_FORMAT " in packet starting at %" G_GUINT64_FORMAT, demux->last_scr, GST_TIME_ARGS (MPEGTIME_TO_GSTTIME (demux->last_scr)), |