diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2010-05-06 10:56:21 +0200 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2010-05-06 10:58:01 +0200 |
commit | 549bc3c80ed8891ff746eeef20f9217328ae0cef (patch) | |
tree | aab9a34cf0ee6a185d46e5828a6b94c2b75a1bdd /ext | |
parent | 18f07f03d1e603a84cd411e7d06e9570ed22732b (diff) |
oggdemux: use index to estimate bitrate
When we have an index, use it to much more accurately estimate the total stream
bitrate.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/ogg/gstoggdemux.c | 10 | ||||
-rw-r--r-- | ext/ogg/gstoggstream.c | 20 | ||||
-rw-r--r-- | ext/ogg/gstoggstream.h | 1 |
3 files changed, 28 insertions, 3 deletions
diff --git a/ext/ogg/gstoggdemux.c b/ext/ogg/gstoggdemux.c index 74d41c021..c490beee3 100644 --- a/ext/ogg/gstoggdemux.c +++ b/ext/ogg/gstoggdemux.c @@ -1677,11 +1677,11 @@ gst_ogg_demux_activate_chain (GstOggDemux * ogg, GstOggChain * chain, /* FIXME, should not be called with NULL */ if (chain != NULL) { - gint bitrate; + gint bitrate, idx_bitrate; GST_DEBUG_OBJECT (ogg, "activating chain %p", chain); - bitrate = 0; + bitrate = idx_bitrate = 0; /* first add the pads */ for (i = 0; i < chain->streams->len; i++) { @@ -1690,6 +1690,9 @@ gst_ogg_demux_activate_chain (GstOggDemux * ogg, GstOggChain * chain, pad = g_array_index (chain->streams, GstOggPad *, i); + if (pad->map.idx_bitrate) + idx_bitrate = MAX (idx_bitrate, pad->map.idx_bitrate); + bitrate += pad->map.bitrate; /* mark discont */ @@ -1714,7 +1717,8 @@ gst_ogg_demux_activate_chain (GstOggDemux * ogg, GstOggChain * chain, gst_element_add_pad (GST_ELEMENT (ogg), GST_PAD_CAST (pad)); pad->added = TRUE; } - ogg->bitrate = bitrate; + /* prefer the index bitrate over the ones encoded in the streams */ + ogg->bitrate = (idx_bitrate ? idx_bitrate : bitrate); } /* after adding the new pads, remove the old pads */ diff --git a/ext/ogg/gstoggstream.c b/ext/ogg/gstoggstream.c index 5c0303ae9..a4e18912b 100644 --- a/ext/ogg/gstoggstream.c +++ b/ext/ogg/gstoggstream.c @@ -922,6 +922,26 @@ gst_ogg_map_add_index (GstOggStream * pad, const guint8 * data, guint size) G_GUINT64_FORMAT, n_keypoints, isize); } pad->n_index = isize; + /* try to use the index to estimate the bitrate */ + if (isize > 2) { + guint64 so, eo, st, et, b, t; + + /* get start and end offset and timestamps */ + so = pad->index[0].offset; + st = pad->index[0].timestamp; + eo = pad->index[isize - 1].offset; + et = pad->index[isize - 1].timestamp; + + b = eo - so; + t = et - st; + + GST_DEBUG ("bytes/time %" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, b, t); + + /* this is the total stream bitrate according to this index */ + pad->idx_bitrate = gst_util_uint64_scale (8 * b, pad->kp_denom, t); + + GST_DEBUG ("bitrate %" G_GUINT64_FORMAT, pad->idx_bitrate); + } return TRUE; } diff --git a/ext/ogg/gstoggstream.h b/ext/ogg/gstoggstream.h index f47fdcef3..b70b5b3b2 100644 --- a/ext/ogg/gstoggstream.h +++ b/ext/ogg/gstoggstream.h @@ -89,6 +89,7 @@ struct _GstOggStream guint n_index; GstOggIndex *index; guint64 kp_denom; + guint64 idx_bitrate; }; |