mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 05:06:17 +00:00
mp3parse: don't put every single frame into the index
Let's not put every single mp3 frame in our index, a few frames per second should be more than enough. For now use an index interval of 100ms-500ms depending on the upstream size, to keep the index at a reasonable size. Factor out the code that adds the index entry into a separate function for better code readability.
This commit is contained in:
parent
1db592839e
commit
af3ab2ae94
2 changed files with 39 additions and 19 deletions
|
@ -589,16 +589,29 @@ gst_mp3parse_sink_event (GstPad * pad, GstEvent * event)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MPEGAudioSeekEntry *
|
static void
|
||||||
mp3parse_seek_table_last_entry (GstMPEGAudioParse * mp3parse)
|
gst_mp3parse_add_index_entry (GstMPEGAudioParse * mp3parse, guint64 offset,
|
||||||
|
GstClockTime ts)
|
||||||
{
|
{
|
||||||
MPEGAudioSeekEntry *ret = NULL;
|
MPEGAudioSeekEntry *entry, *last;
|
||||||
|
|
||||||
if (mp3parse->seek_table) {
|
if (G_LIKELY (mp3parse->seek_table != NULL)) {
|
||||||
ret = mp3parse->seek_table->data;
|
last = mp3parse->seek_table->data;
|
||||||
|
|
||||||
|
if (last->byte >= offset)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (GST_CLOCK_DIFF (last->timestamp, ts) < mp3parse->idx_interval)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
entry = mpeg_audio_seek_entry_new ();
|
||||||
|
entry->byte = offset;
|
||||||
|
entry->timestamp = ts;
|
||||||
|
mp3parse->seek_table = g_list_prepend (mp3parse->seek_table, entry);
|
||||||
|
|
||||||
|
GST_LOG_OBJECT (mp3parse, "Adding index entry %" GST_TIME_FORMAT " @ offset "
|
||||||
|
"0x%08" G_GINT64_MODIFIER "x", GST_TIME_ARGS (ts), offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare a buffer of the indicated size, timestamp it and output */
|
/* Prepare a buffer of the indicated size, timestamp it and output */
|
||||||
|
@ -664,18 +677,9 @@ gst_mp3parse_emit_frame (GstMPEGAudioParse * mp3parse, guint size,
|
||||||
|
|
||||||
if (mp3parse->seekable &&
|
if (mp3parse->seekable &&
|
||||||
mp3parse->exact_position && GST_BUFFER_TIMESTAMP_IS_VALID (outbuf) &&
|
mp3parse->exact_position && GST_BUFFER_TIMESTAMP_IS_VALID (outbuf) &&
|
||||||
mp3parse->cur_offset != GST_BUFFER_OFFSET_NONE &&
|
mp3parse->cur_offset != GST_BUFFER_OFFSET_NONE) {
|
||||||
(!mp3parse->seek_table ||
|
gst_mp3parse_add_index_entry (mp3parse, mp3parse->cur_offset,
|
||||||
(mp3parse_seek_table_last_entry (mp3parse))->byte <
|
GST_BUFFER_TIMESTAMP (outbuf));
|
||||||
GST_BUFFER_OFFSET (outbuf))) {
|
|
||||||
MPEGAudioSeekEntry *entry = mpeg_audio_seek_entry_new ();
|
|
||||||
|
|
||||||
entry->byte = mp3parse->cur_offset;
|
|
||||||
entry->timestamp = GST_BUFFER_TIMESTAMP (outbuf);
|
|
||||||
mp3parse->seek_table = g_list_prepend (mp3parse->seek_table, entry);
|
|
||||||
GST_DEBUG_OBJECT (mp3parse, "Adding index entry %" GST_TIME_FORMAT
|
|
||||||
" @ offset 0x%08" G_GINT64_MODIFIER "x",
|
|
||||||
GST_TIME_ARGS (entry->timestamp), entry->byte);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update our byte offset tracking */
|
/* Update our byte offset tracking */
|
||||||
|
@ -1168,6 +1172,7 @@ gst_mp3parse_check_seekability (GstMPEGAudioParse * mp3parse)
|
||||||
GstQuery *query;
|
GstQuery *query;
|
||||||
gboolean seekable = FALSE;
|
gboolean seekable = FALSE;
|
||||||
gint64 start = -1, stop = -1;
|
gint64 start = -1, stop = -1;
|
||||||
|
guint idx_interval = 0;
|
||||||
|
|
||||||
query = gst_query_new_seeking (GST_FORMAT_BYTES);
|
query = gst_query_new_seeking (GST_FORMAT_BYTES);
|
||||||
if (!gst_pad_peer_query (mp3parse->sinkpad, query)) {
|
if (!gst_pad_peer_query (mp3parse->sinkpad, query)) {
|
||||||
|
@ -1192,13 +1197,25 @@ gst_mp3parse_check_seekability (GstMPEGAudioParse * mp3parse)
|
||||||
seekable = FALSE;
|
seekable = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* let's not put every single frame into our index */
|
||||||
|
if (seekable) {
|
||||||
|
if (stop < 10 * 1024 * 1024)
|
||||||
|
idx_interval = 100;
|
||||||
|
else if (stop < 100 * 1024 * 1024)
|
||||||
|
idx_interval = 500;
|
||||||
|
else
|
||||||
|
idx_interval = 1000;
|
||||||
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|
||||||
GST_INFO_OBJECT (mp3parse, "seekable: %d (%" G_GUINT64_FORMAT " - %"
|
GST_INFO_OBJECT (mp3parse, "seekable: %d (%" G_GUINT64_FORMAT " - %"
|
||||||
G_GUINT64_FORMAT ")", seekable, start, stop);
|
G_GUINT64_FORMAT ")", seekable, start, stop);
|
||||||
|
|
||||||
mp3parse->seekable = seekable;
|
mp3parse->seekable = seekable;
|
||||||
|
|
||||||
|
GST_INFO_OBJECT (mp3parse, "idx_interval: %ums", idx_interval);
|
||||||
|
mp3parse->idx_interval = idx_interval * GST_MSECOND;
|
||||||
|
|
||||||
gst_query_unref (query);
|
gst_query_unref (query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,9 @@ struct _GstMPEGAudioParse {
|
||||||
* seekable. */
|
* seekable. */
|
||||||
gboolean seekable;
|
gboolean seekable;
|
||||||
|
|
||||||
|
/* minimum distance between two index entries */
|
||||||
|
GstClockTimeDiff idx_interval;
|
||||||
|
|
||||||
/* pending segment */
|
/* pending segment */
|
||||||
GstEvent *pending_segment;
|
GstEvent *pending_segment;
|
||||||
/* pending events */
|
/* pending events */
|
||||||
|
|
Loading…
Reference in a new issue