mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-20 04:56:24 +00:00
[MOVED FROM GST-P-FARSIGHT] Add handling of position query to liveadder
20080704185721-3e2dc-7a687e346e74b44fa847c5e5b6eb64c3e0949764.gz
This commit is contained in:
parent
9e6d4708f8
commit
28d1fc48a6
1 changed files with 73 additions and 27 deletions
|
@ -585,34 +585,21 @@ newseg_wrong_format:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME:
|
|
||||||
*
|
|
||||||
* When we add a new stream (or remove a stream) the duration might
|
|
||||||
* also become invalid again and we need to post a new DURATION
|
|
||||||
* message to notify this fact to the parent.
|
|
||||||
* For now we take the max of all the upstream elements so the simple
|
|
||||||
* cases work at least somewhat.
|
|
||||||
*/
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_live_adder_query_duration (GstLiveAdder * adder, GstQuery * query)
|
gst_live_adder_query_pos_dur (GstLiveAdder * adder, GstFormat informat,
|
||||||
|
gboolean position, gint64 *outvalue)
|
||||||
{
|
{
|
||||||
gint64 max;
|
gint64 max = G_MININT64;
|
||||||
gboolean res;
|
gboolean res = TRUE;
|
||||||
GstFormat format;
|
|
||||||
GstIterator *it;
|
GstIterator *it;
|
||||||
gboolean done;
|
gboolean done = FALSE;
|
||||||
|
|
||||||
/* parse format */
|
|
||||||
gst_query_parse_duration (query, &format, NULL);
|
|
||||||
|
|
||||||
max = -1;
|
|
||||||
res = TRUE;
|
|
||||||
done = FALSE;
|
|
||||||
|
|
||||||
it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (adder));
|
it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (adder));
|
||||||
while (!done) {
|
while (!done) {
|
||||||
GstIteratorResult ires;
|
GstIteratorResult ires;
|
||||||
gpointer item;
|
gpointer item;
|
||||||
|
GstFormat format = informat;
|
||||||
|
|
||||||
ires = gst_iterator_next (it, &item);
|
ires = gst_iterator_next (it, &item);
|
||||||
switch (ires) {
|
switch (ires) {
|
||||||
|
@ -622,20 +609,29 @@ gst_live_adder_query_duration (GstLiveAdder * adder, GstQuery * query)
|
||||||
case GST_ITERATOR_OK:
|
case GST_ITERATOR_OK:
|
||||||
{
|
{
|
||||||
GstPad *pad = GST_PAD_CAST (item);
|
GstPad *pad = GST_PAD_CAST (item);
|
||||||
gint64 duration;
|
gint64 value;
|
||||||
|
gboolean curres;
|
||||||
|
|
||||||
/* ask sink peer for duration */
|
/* ask sink peer for duration */
|
||||||
res &= gst_pad_query_peer_duration (pad, &format, &duration);
|
if (position)
|
||||||
|
curres = gst_pad_query_peer_position (pad, &format, &value);
|
||||||
|
else
|
||||||
|
curres = gst_pad_query_peer_duration (pad, &format, &value);
|
||||||
|
|
||||||
/* take max from all valid return values */
|
/* take max from all valid return values */
|
||||||
if (res) {
|
/* Only if the format is the one we requested, otherwise ignore it ?
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (curres && format == informat) {
|
||||||
|
res &= curres;
|
||||||
|
|
||||||
/* valid unknown length, stop searching */
|
/* valid unknown length, stop searching */
|
||||||
if (duration == -1) {
|
if (value == -1) {
|
||||||
max = duration;
|
max = value;
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
|
} else if (value > max) {
|
||||||
|
max = value;
|
||||||
}
|
}
|
||||||
/* else see if bigger than current max */
|
|
||||||
else if (duration > max)
|
|
||||||
max = duration;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -651,6 +647,32 @@ gst_live_adder_query_duration (GstLiveAdder * adder, GstQuery * query)
|
||||||
}
|
}
|
||||||
gst_iterator_free (it);
|
gst_iterator_free (it);
|
||||||
|
|
||||||
|
if (res)
|
||||||
|
*outvalue = max;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* FIXME:
|
||||||
|
*
|
||||||
|
* When we add a new stream (or remove a stream) the duration might
|
||||||
|
* also become invalid again and we need to post a new DURATION
|
||||||
|
* message to notify this fact to the parent.
|
||||||
|
* For now we take the max of all the upstream elements so the simple
|
||||||
|
* cases work at least somewhat.
|
||||||
|
*/
|
||||||
|
static gboolean
|
||||||
|
gst_live_adder_query_duration (GstLiveAdder * adder, GstQuery * query)
|
||||||
|
{
|
||||||
|
GstFormat format;
|
||||||
|
gint64 max;
|
||||||
|
gboolean res;
|
||||||
|
|
||||||
|
/* parse format */
|
||||||
|
gst_query_parse_duration (query, &format, NULL);
|
||||||
|
|
||||||
|
res = gst_live_adder_query_pos_dur (adder, format, FALSE, &max);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
/* and store the max */
|
/* and store the max */
|
||||||
gst_query_set_duration (query, format, max);
|
gst_query_set_duration (query, format, max);
|
||||||
|
@ -659,6 +681,27 @@ gst_live_adder_query_duration (GstLiveAdder * adder, GstQuery * query)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_live_adder_query_position (GstLiveAdder * adder, GstQuery * query)
|
||||||
|
{
|
||||||
|
GstFormat format;
|
||||||
|
gint64 max;
|
||||||
|
gboolean res;
|
||||||
|
|
||||||
|
/* parse format */
|
||||||
|
gst_query_parse_position (query, &format, NULL);
|
||||||
|
|
||||||
|
res = gst_live_adder_query_pos_dur (adder, format, TRUE, &max);
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
/* and store the max */
|
||||||
|
gst_query_set_position (query, format, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_live_adder_query (GstPad * pad, GstQuery * query)
|
gst_live_adder_query (GstPad * pad, GstQuery * query)
|
||||||
|
@ -744,6 +787,9 @@ gst_live_adder_query (GstPad * pad, GstQuery * query)
|
||||||
case GST_QUERY_DURATION:
|
case GST_QUERY_DURATION:
|
||||||
res = gst_live_adder_query_duration (adder, query);
|
res = gst_live_adder_query_duration (adder, query);
|
||||||
break;
|
break;
|
||||||
|
case GST_QUERY_POSITION:
|
||||||
|
res = gst_live_adder_query_position (adder, query);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
res = gst_pad_query_default (pad, query);
|
res = gst_pad_query_default (pad, query);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue