gst/videoparse/gstvideoparse.c: Improve duration query by first asking upstream and if it can't handle the query try ...

Original commit message from CVS:
* gst/videoparse/gstvideoparse.c: (gst_video_parse_sink_event),
(gst_video_parse_src_event), (gst_video_parse_src_query):
Improve duration query by first asking upstream and if it can't handle
the query try to get the duration in bytes from upstream and convert.
For seeks, try if upstream handles this already first and do our
conversion to byte format only if it doesn't and if we get a
newsegment event in time format keep it and only do our conversions
if the event has another format.
This commit is contained in:
Sebastian Dröge 2007-12-15 13:10:00 +00:00
parent b648c8ea44
commit 00ec95f3d2
2 changed files with 82 additions and 27 deletions

View file

@ -1,3 +1,14 @@
2007-12-15 Sebastian Dröge <slomo@circular-chaos.org>
* gst/videoparse/gstvideoparse.c: (gst_video_parse_sink_event),
(gst_video_parse_src_event), (gst_video_parse_src_query):
Improve duration query by first asking upstream and if it can't handle
the query try to get the duration in bytes from upstream and convert.
For seeks, try if upstream handles this already first and do our
conversion to byte format only if it doesn't and if we get a
newsegment event in time format keep it and only do our conversions
if the event has another format.
2007-12-15 Sebastian Dröge <slomo@circular-chaos.org> 2007-12-15 Sebastian Dröge <slomo@circular-chaos.org>
* gst/videoparse/gstvideoparse.c: * gst/videoparse/gstvideoparse.c:

View file

@ -697,22 +697,34 @@ gst_video_parse_sink_event (GstPad * pad, GstEvent * event)
gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format, gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
&start, &stop, &time); &start, &stop, &time);
ret = if (format == GST_FORMAT_TIME) {
gst_video_parse_convert (vp, format, start, GST_FORMAT_TIME, &start); ret = gst_pad_push_event (vp->srcpad, event);
ret &= gst_video_parse_convert (vp, format, time, GST_FORMAT_TIME, &time); gst_segment_set_newsegment_full (&vp->segment, update, rate, arate,
ret &= gst_video_parse_convert (vp, format, stop, GST_FORMAT_TIME, &stop); GST_FORMAT_TIME, start, stop, time);
if (!ret) { } else {
GST_ERROR_OBJECT (vp,
"Failed converting to GST_FORMAT_TIME format (%d)", format); gst_event_unref (event);
break;
ret =
gst_video_parse_convert (vp, format, start, GST_FORMAT_TIME,
&start);
ret &=
gst_video_parse_convert (vp, format, time, GST_FORMAT_TIME, &time);
ret &=
gst_video_parse_convert (vp, format, stop, GST_FORMAT_TIME, &stop);
if (!ret) {
GST_ERROR_OBJECT (vp,
"Failed converting to GST_FORMAT_TIME format (%d)", format);
break;
}
gst_segment_set_newsegment_full (&vp->segment, update, rate, arate,
GST_FORMAT_TIME, start, stop, time);
event = gst_event_new_new_segment (FALSE, vp->segment.rate,
GST_FORMAT_TIME, start, stop, time);
ret = gst_pad_push_event (vp->srcpad, event);
} }
gst_segment_set_newsegment_full (&vp->segment, update, rate, arate,
GST_FORMAT_TIME, start, stop, time);
event = gst_event_new_new_segment (FALSE, vp->segment.rate,
GST_FORMAT_TIME, start, stop, time);
ret = gst_pad_push_event (vp->srcpad, event);
break; break;
} }
default: default:
@ -742,12 +754,15 @@ gst_video_parse_src_event (GstPad * pad, GstEvent * event)
gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start, gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
&stop_type, &stop); &stop_type, &stop);
/* We only handle TIME and DEFAULT (aka frames), forward everything /* First try if upstream handles the seek */
* upstream */ ret = gst_pad_push_event (vp->sinkpad, event);
if (format != GST_FORMAT_TIME && format != GST_FORMAT_DEFAULT) { if (ret)
gst_event_ref (event); goto done;
ret = gst_pad_push_event (vp->sinkpad, event);
} else { /* Otherwise convert to bytes and push upstream */
if (format == GST_FORMAT_TIME || format == GST_FORMAT_DEFAULT) {
gst_event_unref (event);
ret = ret =
gst_video_parse_convert (vp, format, start, GST_FORMAT_BYTES, gst_video_parse_convert (vp, format, start, GST_FORMAT_BYTES,
&start); &start);
@ -769,6 +784,7 @@ gst_video_parse_src_event (GstPad * pad, GstEvent * event)
break; break;
} }
done:
gst_object_unref (vp); gst_object_unref (vp);
return ret; return ret;
@ -801,7 +817,7 @@ gst_video_parse_src_query (GstPad * pad, GstQuery * query)
GstFormat format; GstFormat format;
gint64 time, value; gint64 time, value;
GST_ERROR ("query position"); GST_LOG ("query position");
gst_query_parse_position (query, &format, NULL); gst_query_parse_position (query, &format, NULL);
@ -813,18 +829,46 @@ gst_video_parse_src_query (GstPad * pad, GstQuery * query)
break; break;
} }
case GST_QUERY_DURATION: case GST_QUERY_DURATION:{
GST_ERROR ("query duration"); gint64 duration;
ret = gst_pad_query (GST_PAD_PEER (vp->srcpad), query); GstFormat format;
if (!ret) GstQuery *bquery;
GST_LOG ("query duration");
ret = gst_pad_peer_query (vp->srcpad, query);
if (ret)
goto done;
gst_query_parse_duration (query, &format, NULL);
/* We only handle TIME and DEFAULT format */
if (format != GST_FORMAT_TIME && format != GST_FORMAT_DEFAULT)
goto error; goto error;
bquery = gst_query_new_duration (GST_FORMAT_BYTES);
ret = gst_pad_peer_query (vp->srcpad, bquery);
if (!ret) {
gst_query_unref (bquery);
goto error;
}
gst_query_parse_duration (bquery, NULL, &duration);
gst_query_unref (bquery);
ret =
gst_video_parse_convert (vp, GST_FORMAT_BYTES, duration, format,
&duration);
if (ret)
gst_query_set_duration (query, format, duration);
break; break;
}
case GST_QUERY_CONVERT: case GST_QUERY_CONVERT:
{ {
GstFormat src_fmt, dest_fmt; GstFormat src_fmt, dest_fmt;
gint64 src_val, dest_val; gint64 src_val, dest_val;
GST_ERROR ("query convert"); GST_LOG ("query convert");
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val); gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
ret = gst_video_parse_convert (vp, src_fmt, src_val, dest_fmt, &dest_val); ret = gst_video_parse_convert (vp, src_fmt, src_val, dest_fmt, &dest_val);