summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Hervey <bilboed@bilboed.com>2009-05-11 16:59:20 +0200
committerEdward Hervey <bilboed@bilboed.com>2009-05-11 16:59:20 +0200
commitf9dfc44a67320b6f73bb34e05ec80e67e9c8c087 (patch)
treed6087e6ff7e57a543e65a2ddd7806c75293fd10d
parentbc062b9acf1232ee5643dd7976741c7a47378cd6 (diff)
downloadgst-plugins-bad-f9dfc44a67320b6f73bb34e05ec80e67e9c8c087.tar.gz
gst-plugins-bad-f9dfc44a67320b6f73bb34e05ec80e67e9c8c087.tar.bz2
gst-plugins-bad-f9dfc44a67320b6f73bb34e05ec80e67e9c8c087.zip
mpegtsdemux: Protect bitrate estimation against bogus values.
If the estimated bitrate is lower than 188 bytes, there's most likely something completely wrong with the two samples. If that happens, force recalculation. Use guint64 for observation PCR, I saw cases where it would overflow.
-rw-r--r--gst/mpegdemux/gstmpegtsdemux.c21
-rw-r--r--gst/mpegdemux/gstmpegtsdemux.h2
2 files changed, 18 insertions, 5 deletions
diff --git a/gst/mpegdemux/gstmpegtsdemux.c b/gst/mpegdemux/gstmpegtsdemux.c
index f07e1743..cad385d0 100644
--- a/gst/mpegdemux/gstmpegtsdemux.c
+++ b/gst/mpegdemux/gstmpegtsdemux.c
@@ -2355,14 +2355,27 @@ gst_mpegts_demux_parse_transport_packet (GstMpegTSDemux * demux,
MPEGTS_NORMAL_TS_PACKETSIZE - 1);
if (demux->pcr[1] != -1 && demux->bitrate == -1) {
- GST_DEBUG_OBJECT (demux, "stream->last_PCR_difference: %" G_GINT64_FORMAT
+ guint64 bitrate;
+ GST_DEBUG_OBJECT (demux, "pcr[0]:%" G_GUINT64_FORMAT, demux->pcr[0]);
+ GST_DEBUG_OBJECT (demux, "pcr[1]:%" G_GUINT64_FORMAT, demux->pcr[1]);
+ GST_DEBUG_OBJECT (demux, "diff in time %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (MPEGTIME_TO_GSTTIME (demux->pcr[1] - demux->pcr[0])));
+ GST_DEBUG_OBJECT (demux, "stream->last_PCR_difference: %" G_GUINT64_FORMAT
", demux->num_packets %" G_GUINT64_FORMAT,
demux->pcr[1] - demux->pcr[0], demux->num_packets);
- demux->bitrate = gst_util_uint64_scale (GST_SECOND,
+ bitrate = gst_util_uint64_scale (GST_SECOND,
MPEGTS_NORMAL_TS_PACKETSIZE * demux->num_packets,
MPEGTIME_TO_GSTTIME (demux->pcr[1] - demux->pcr[0]));
- GST_DEBUG_OBJECT (demux, "bitrate is %" G_GINT64_FORMAT
- " bytes per second", demux->bitrate);
+ /* somehow... I doubt a bitrate below one packet per second is valid */
+ if (bitrate > MPEGTS_NORMAL_TS_PACKETSIZE - 1) {
+ demux->bitrate = bitrate;
+ GST_DEBUG_OBJECT (demux, "bitrate is %" G_GINT64_FORMAT
+ " bytes per second", demux->bitrate);
+ } else {
+ GST_WARNING_OBJECT (demux, "Couldn't compute valid bitrate, recomputing");
+ demux->pcr[0] = demux->pcr[1] = -1;
+ demux->num_packets = -1;
+ }
}
demux->num_packets++;
return ret;
diff --git a/gst/mpegdemux/gstmpegtsdemux.h b/gst/mpegdemux/gstmpegtsdemux.h
index 2e2a8e63..dad2b023 100644
--- a/gst/mpegdemux/gstmpegtsdemux.h
+++ b/gst/mpegdemux/gstmpegtsdemux.h
@@ -213,7 +213,7 @@ struct _GstMpegTSDemux {
gint64 bitrate;
/* Two PCRs observations to calculate bitrate */
- gint64 pcr[2];
+ guint64 pcr[2];
/* Cached duration estimation */
GstClockTime cache_duration;