mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-12 10:25:33 +00:00
avidemux: short-circuit gst_avi_demux_src_convert() when parsing the index
Don't call gst_avi_demux_src_convert() for each single index entry. Not only do we already have the pointer to the stream context, we also know the formats we want to convert from and to already, so we may just as well use optimised conversion routines that bypass some of the checks and lookups made in gst_avi_demux_src_convert().
This commit is contained in:
parent
86c2299ed1
commit
632bb7818a
1 changed files with 51 additions and 37 deletions
|
@ -410,6 +410,23 @@ gst_avi_demux_get_src_formats (GstPad * pad)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* assumes stream->strf.auds->av_bps != 0 */
|
||||||
|
static inline GstClockTime
|
||||||
|
avi_stream_convert_bytes_to_time_unchecked (avi_stream_context * stream,
|
||||||
|
guint64 bytes)
|
||||||
|
{
|
||||||
|
return gst_util_uint64_scale (bytes, GST_SECOND, stream->strf.auds->av_bps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* assumes stream->strh->rate != 0 */
|
||||||
|
static inline GstClockTime
|
||||||
|
avi_stream_convert_frames_to_time_unchecked (avi_stream_context * stream,
|
||||||
|
guint64 frames)
|
||||||
|
{
|
||||||
|
return gst_util_uint64_scale (frames, stream->strh->scale * GST_SECOND,
|
||||||
|
stream->strh->rate);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_avi_demux_src_convert (GstPad * pad,
|
gst_avi_demux_src_convert (GstPad * pad,
|
||||||
GstFormat src_format,
|
GstFormat src_format,
|
||||||
|
@ -458,8 +475,8 @@ gst_avi_demux_src_convert (GstPad * pad,
|
||||||
switch (*dest_format) {
|
switch (*dest_format) {
|
||||||
case GST_FORMAT_TIME:
|
case GST_FORMAT_TIME:
|
||||||
if (stream->strf.auds->av_bps != 0) {
|
if (stream->strf.auds->av_bps != 0) {
|
||||||
*dest_value = gst_util_uint64_scale (src_value, GST_SECOND,
|
*dest_value = avi_stream_convert_bytes_to_time_unchecked (stream,
|
||||||
(guint64) stream->strf.auds->av_bps);
|
src_value);
|
||||||
} else
|
} else
|
||||||
res = FALSE;
|
res = FALSE;
|
||||||
break;
|
break;
|
||||||
|
@ -471,8 +488,8 @@ gst_avi_demux_src_convert (GstPad * pad,
|
||||||
case GST_FORMAT_DEFAULT:
|
case GST_FORMAT_DEFAULT:
|
||||||
switch (*dest_format) {
|
switch (*dest_format) {
|
||||||
case GST_FORMAT_TIME:
|
case GST_FORMAT_TIME:
|
||||||
*dest_value = gst_util_uint64_scale (src_value,
|
*dest_value =
|
||||||
stream->strh->scale * GST_SECOND, (guint64) stream->strh->rate);
|
avi_stream_convert_frames_to_time_unchecked (stream, src_value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
res = FALSE;
|
res = FALSE;
|
||||||
|
@ -1024,7 +1041,6 @@ gst_avi_demux_parse_subindex (GstAviDemux * avi,
|
||||||
guint64 baseoff;
|
guint64 baseoff;
|
||||||
gst_avi_index_entry *entries, *entry;
|
gst_avi_index_entry *entries, *entry;
|
||||||
GList *entries_list = NULL;
|
GList *entries_list = NULL;
|
||||||
GstFormat format = GST_FORMAT_TIME;
|
|
||||||
guint size;
|
guint size;
|
||||||
|
|
||||||
*_entries_list = NULL;
|
*_entries_list = NULL;
|
||||||
|
@ -1087,16 +1103,16 @@ gst_avi_demux_parse_subindex (GstAviDemux * avi,
|
||||||
if (stream->is_vbr) {
|
if (stream->is_vbr) {
|
||||||
/* VBR stream next timestamp */
|
/* VBR stream next timestamp */
|
||||||
if (stream->strh->type == GST_RIFF_FCC_auds) {
|
if (stream->strh->type == GST_RIFF_FCC_auds) {
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT,
|
next_ts = avi_stream_convert_frames_to_time_unchecked (stream,
|
||||||
stream->total_blocks + 1, &format, &next_ts);
|
stream->total_blocks + 1);
|
||||||
} else {
|
} else {
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT,
|
next_ts = avi_stream_convert_frames_to_time_unchecked (stream,
|
||||||
stream->total_frames + 1, &format, &next_ts);
|
stream->total_frames + 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* CBR get next timestamp */
|
/* CBR get next timestamp */
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES,
|
next_ts = avi_stream_convert_bytes_to_time_unchecked (stream,
|
||||||
stream->total_bytes + entry->size, &format, &next_ts);
|
stream->total_bytes + entry->size);
|
||||||
}
|
}
|
||||||
/* duration is next - current */
|
/* duration is next - current */
|
||||||
entry->dur = next_ts - entry->ts;
|
entry->dur = next_ts - entry->ts;
|
||||||
|
@ -1912,16 +1928,16 @@ gst_avi_demux_parse_index (GstAviDemux * avi,
|
||||||
if (stream->is_vbr) {
|
if (stream->is_vbr) {
|
||||||
/* VBR stream next timestamp */
|
/* VBR stream next timestamp */
|
||||||
if (stream->strh->type == GST_RIFF_FCC_auds) {
|
if (stream->strh->type == GST_RIFF_FCC_auds) {
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT,
|
next_ts = avi_stream_convert_frames_to_time_unchecked (stream,
|
||||||
stream->total_blocks + 1, &format, &next_ts);
|
stream->total_blocks + 1);
|
||||||
} else {
|
} else {
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT,
|
next_ts = avi_stream_convert_frames_to_time_unchecked (stream,
|
||||||
stream->total_frames + 1, &format, &next_ts);
|
stream->total_frames + 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* constant rate stream */
|
/* constant rate stream */
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES,
|
next_ts = avi_stream_convert_bytes_to_time_unchecked (stream,
|
||||||
stream->total_bytes + target->size, &format, &next_ts);
|
stream->total_bytes + target->size);
|
||||||
}
|
}
|
||||||
/* duration is next - current */
|
/* duration is next - current */
|
||||||
target->dur = next_ts - target->ts;
|
target->dur = next_ts - target->ts;
|
||||||
|
@ -2364,7 +2380,6 @@ gst_avi_demux_stream_scan (GstAviDemux * avi,
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
guint stream_nr;
|
guint stream_nr;
|
||||||
guint size = 0;
|
guint size = 0;
|
||||||
gint64 tmpts, tmpnextts;
|
|
||||||
|
|
||||||
res = gst_avi_demux_next_data_buffer (avi, &pos, &tag, &size);
|
res = gst_avi_demux_next_data_buffer (avi, &pos, &tag, &size);
|
||||||
if (G_UNLIKELY (res != GST_FLOW_OK))
|
if (G_UNLIKELY (res != GST_FLOW_OK))
|
||||||
|
@ -2404,26 +2419,25 @@ gst_avi_demux_stream_scan (GstAviDemux * avi,
|
||||||
format = GST_FORMAT_TIME;
|
format = GST_FORMAT_TIME;
|
||||||
if (stream->is_vbr) {
|
if (stream->is_vbr) {
|
||||||
/* VBR stream */
|
/* VBR stream */
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT,
|
entry->ts = avi_stream_convert_frames_to_time_unchecked (stream,
|
||||||
stream->total_frames, &format, &tmpts);
|
stream->total_frames);
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT,
|
entry->dur = avi_stream_convert_frames_to_time_unchecked (stream,
|
||||||
stream->total_frames + 1, &format, &tmpnextts);
|
stream->total_frames + 1);
|
||||||
} else {
|
} else {
|
||||||
/* constant rate stream */
|
/* constant rate stream */
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES,
|
entry->ts = avi_stream_convert_bytes_to_time_unchecked (stream,
|
||||||
stream->total_bytes, &format, &tmpts);
|
stream->total_bytes);
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES,
|
entry->dur = avi_stream_convert_bytes_to_time_unchecked (stream,
|
||||||
stream->total_bytes + entry->size, &format, &tmpnextts);
|
stream->total_bytes + entry->size);
|
||||||
}
|
}
|
||||||
entry->ts = tmpts;
|
entry->dur -= entry->ts;
|
||||||
entry->dur = tmpnextts - tmpts;
|
|
||||||
|
|
||||||
/* stream position */
|
/* stream position */
|
||||||
entry->bytes_before = stream->total_bytes;
|
entry->bytes_before = stream->total_bytes;
|
||||||
stream->total_bytes += entry->size;
|
stream->total_bytes += entry->size;
|
||||||
entry->frames_before = stream->total_frames;
|
entry->frames_before = stream->total_frames;
|
||||||
stream->total_frames++;
|
stream->total_frames++;
|
||||||
stream->idx_duration = tmpnextts;
|
stream->idx_duration = entry->ts + entry->dur;
|
||||||
|
|
||||||
list = g_list_prepend (list, entry);
|
list = g_list_prepend (list, entry);
|
||||||
GST_DEBUG_OBJECT (avi, "Added index entry %d (in stream: %d), offset %"
|
GST_DEBUG_OBJECT (avi, "Added index entry %d (in stream: %d), offset %"
|
||||||
|
@ -2466,16 +2480,16 @@ gst_avi_demux_stream_scan (GstAviDemux * avi,
|
||||||
/* timestamps */
|
/* timestamps */
|
||||||
if (stream->is_vbr) {
|
if (stream->is_vbr) {
|
||||||
/* VBR stream */
|
/* VBR stream */
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT,
|
entry->ts = avi_stream_convert_frames_to_time_unchecked (stream,
|
||||||
stream->total_frames, &format, &entry->ts);
|
stream->total_frames);
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_DEFAULT,
|
entry->dur = avi_stream_convert_frames_to_time_unchecked (stream,
|
||||||
stream->total_frames + 1, &format, &entry->dur);
|
stream->total_frames + 1);
|
||||||
} else {
|
} else {
|
||||||
/* constant rate stream */
|
/* constant rate stream */
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES,
|
entry->ts = avi_stream_convert_bytes_to_time_unchecked (stream,
|
||||||
stream->total_bytes, &format, &entry->ts);
|
stream->total_bytes);
|
||||||
gst_avi_demux_src_convert (stream->pad, GST_FORMAT_BYTES,
|
entry->dur = avi_stream_convert_bytes_to_time_unchecked (stream,
|
||||||
stream->total_bytes + entry->size, &format, &entry->dur);
|
stream->total_bytes + entry->size);
|
||||||
}
|
}
|
||||||
entry->dur -= entry->ts;
|
entry->dur -= entry->ts;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue