Commit 4dbc7a5b authored by Wim Taymans's avatar Wim Taymans

gst/base/gstbasesink.c: Speed up current position calculation.

Original commit message from CVS:
* gst/base/gstbasesink.c: (gst_base_sink_get_position),
(gst_base_sink_query):
Speed up current position calculation.

* gst/base/gstbasesrc.c: (gst_base_src_query),
(gst_base_src_default_newsegment):
Correctly set stream position in newsegment.

* gst/gstbin.c: (gst_bin_add_func), (add_to_queue),
(update_degree), (gst_bin_sort_iterator_next),
(gst_bin_sort_iterator_resync), (gst_bin_sort_iterator_free):
* gst/gstmessage.c: (gst_message_new_custom):
Clean up debugging info

* gst/gstqueue.c: (gst_queue_link_src), (gst_queue_chain),
(gst_queue_loop), (gst_queue_handle_src_query):
Pause task faster.
parent ce3b4e17
2005-10-20 Wim Taymans <wim@fluendo.com>
* gst/base/gstbasesink.c: (gst_base_sink_get_position),
(gst_base_sink_query):
Speed up current position calculation.
* gst/base/gstbasesrc.c: (gst_base_src_query),
(gst_base_src_default_newsegment):
Correctly set stream position in newsegment.
* gst/gstbin.c: (gst_bin_add_func), (add_to_queue),
(update_degree), (gst_bin_sort_iterator_next),
(gst_bin_sort_iterator_resync), (gst_bin_sort_iterator_free):
* gst/gstmessage.c: (gst_message_new_custom):
Clean up debugging info
* gst/gstqueue.c: (gst_queue_link_src), (gst_queue_chain),
(gst_queue_loop), (gst_queue_handle_src_query):
Pause task faster.
2005-10-19 Wim Taymans <wim@fluendo.com>
* gst/base/gstbasesink.c: (gst_base_sink_commit_state),
......
......@@ -1392,6 +1392,49 @@ gst_base_sink_peer_query (GstBaseSink * sink, GstQuery * query)
return res;
}
static gboolean
gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format,
gint64 * cur)
{
GstClock *clock;
gboolean res = FALSE;
switch (format) {
case GST_FORMAT_TIME:
{
/* we can answer time format */
GST_LOCK (basesink);
if ((clock = GST_ELEMENT_CLOCK (basesink))) {
GstClockTime now;
gst_object_ref (clock);
GST_UNLOCK (basesink);
now = gst_clock_get_time (clock);
GST_LOCK (basesink);
*cur =
now - GST_ELEMENT_CAST (basesink)->base_time +
basesink->segment_time;
GST_DEBUG_OBJECT (basesink,
"now %" GST_TIME_FORMAT " + segment_time %" GST_TIME_FORMAT " = %"
GST_TIME_FORMAT, GST_TIME_ARGS (now),
GST_TIME_ARGS (basesink->segment_time), GST_TIME_ARGS (*cur));
gst_object_unref (clock);
res = TRUE;
} else {
}
GST_UNLOCK (basesink);
}
default:
break;
}
return res;
}
static gboolean
gst_base_sink_query (GstElement * element, GstQuery * query)
{
......@@ -1401,8 +1444,21 @@ gst_base_sink_query (GstElement * element, GstQuery * query)
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION:
res = gst_base_sink_peer_query (basesink, query);
{
gint64 cur = 0;
GstFormat format;
gst_query_parse_position (query, &format, NULL);
GST_DEBUG_OBJECT (basesink, "current position format %d", format);
if ((res = gst_base_sink_get_position (basesink, format, &cur))) {
gst_query_set_position (query, format, cur);
} else {
res = gst_base_sink_peer_query (basesink, query);
}
break;
}
case GST_QUERY_DURATION:
res = gst_base_sink_peer_query (basesink, query);
break;
......
......@@ -395,7 +395,8 @@ gst_base_src_default_newsegment (GstBaseSrc * src)
(gint64) src->segment_end);
event = gst_event_new_newsegment (FALSE, 1.0,
GST_FORMAT_BYTES,
(gint64) src->segment_start, (gint64) src->segment_end, (gint64) 0);
(gint64) src->segment_start, (gint64) src->segment_end,
(gint64) src->segment_start);
return gst_pad_push_event (src->srcpad, event);
}
......
......@@ -503,8 +503,7 @@ gst_bin_add_func (GstBin * bin, GstElement * element)
GST_OBJECT_FLAG_SET (bin, GST_ELEMENT_IS_SINK);
}
if (gst_element_provides_clock (element)) {
GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin,
"element \"%s\" can provide a clock", elem_name);
GST_DEBUG_OBJECT (bin, "element \"%s\" can provide a clock", elem_name);
bin->clock_dirty = TRUE;
}
......@@ -516,10 +515,7 @@ gst_bin_add_func (GstBin * bin, GstElement * element)
gst_element_set_bus (element, bin->child_bus);
/* propagate the current base time and clock */
GST_DEBUG_OBJECT (element, "setting base time %" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_ELEMENT (bin)->base_time));
gst_element_set_base_time (element, GST_ELEMENT (bin)->base_time);
GST_DEBUG_OBJECT (element, "setting clock %p", GST_ELEMENT_CLOCK (bin));
gst_element_set_clock (element, GST_ELEMENT_CLOCK (bin));
bin->state_dirty = TRUE;
GST_UNLOCK (bin);
......@@ -1137,7 +1133,7 @@ typedef struct _GstBinSortIterator
static void
add_to_queue (GstBinSortIterator * bit, GstElement * element)
{
GST_DEBUG ("%s add to queue", GST_ELEMENT_NAME (element));
GST_DEBUG_OBJECT (bit->bin, "%s add to queue", GST_ELEMENT_NAME (element));
gst_object_ref (element);
g_queue_push_tail (bit->queue, element);
HASH_SET_DEGREE (bit, element, -1);
......@@ -1209,9 +1205,10 @@ update_degree (GstElement * element, GstBinSortIterator * bit)
old_deg = HASH_GET_DEGREE (bit, peer_element);
new_deg = old_deg + bit->mode;
GST_DEBUG ("change element %s, degree %d->%d, linked to %s",
GST_ELEMENT_NAME (peer_element),
old_deg, new_deg, GST_ELEMENT_NAME (element));
GST_DEBUG_OBJECT (bit->bin,
"change element %s, degree %d->%d, linked to %s",
GST_ELEMENT_NAME (peer_element), old_deg, new_deg,
GST_ELEMENT_NAME (element));
/* update degree */
if (new_deg == 0) {
......@@ -1230,7 +1227,7 @@ update_degree (GstElement * element, GstBinSortIterator * bit)
}
}
if (!linked) {
GST_DEBUG ("element %s not linked on any sinkpads",
GST_DEBUG_OBJECT (bit->bin, "element %s not linked on any sinkpads",
GST_ELEMENT_NAME (element));
}
GST_UNLOCK (element);
......@@ -1259,23 +1256,28 @@ find_element (GstElement * element, GstBinSortIterator * bit)
static GstIteratorResult
gst_bin_sort_iterator_next (GstBinSortIterator * bit, gpointer * result)
{
GstBin *bin = bit->bin;
/* empty queue, we have to find a next best element */
if (g_queue_is_empty (bit->queue)) {
GstElement *best;
bit->best = NULL;
bit->best_deg = G_MAXINT;
g_list_foreach (bit->bin->children, (GFunc) find_element, bit);
if (bit->best) {
g_list_foreach (bin->children, (GFunc) find_element, bit);
if ((best = bit->best)) {
if (bit->best_deg != 0) {
/* we don't fail on this one yet */
g_warning ("loop detected in the graph !!");
}
/* best unhandled element, schedule as next element */
GST_DEBUG ("queue empty, next best: %s", GST_ELEMENT_NAME (bit->best));
gst_object_ref (bit->best);
HASH_SET_DEGREE (bit, bit->best, -1);
*result = bit->best;
GST_DEBUG_OBJECT (bin, "queue empty, next best: %s",
GST_ELEMENT_NAME (best));
gst_object_ref (best);
HASH_SET_DEGREE (bit, best, -1);
*result = best;
} else {
GST_DEBUG ("queue empty, elements exhausted");
GST_DEBUG_OBJECT (bin, "queue empty, elements exhausted");
/* no more unhandled elements, we are done */
return GST_ITERATOR_DONE;
}
......@@ -1284,7 +1286,7 @@ gst_bin_sort_iterator_next (GstBinSortIterator * bit, gpointer * result)
*result = g_queue_pop_head (bit->queue);
}
GST_DEBUG ("queue head gives %s", GST_ELEMENT_NAME (*result));
GST_DEBUG_OBJECT (bin, "queue head gives %s", GST_ELEMENT_NAME (*result));
/* update degrees of linked elements */
update_degree (GST_ELEMENT_CAST (*result), bit);
......@@ -1295,12 +1297,15 @@ gst_bin_sort_iterator_next (GstBinSortIterator * bit, gpointer * result)
static void
gst_bin_sort_iterator_resync (GstBinSortIterator * bit)
{
GstBin *bin = bit->bin;
GST_DEBUG_OBJECT (bin, "resync");
clear_queue (bit->queue);
/* reset degrees */
g_list_foreach (bit->bin->children, (GFunc) reset_degree, bit);
g_list_foreach (bin->children, (GFunc) reset_degree, bit);
/* calc degrees, incrementing */
bit->mode = 1;
g_list_foreach (bit->bin->children, (GFunc) update_degree, bit);
g_list_foreach (bin->children, (GFunc) update_degree, bit);
/* for the rest of the function we decrement the degrees */
bit->mode = -1;
}
......@@ -1309,10 +1314,13 @@ gst_bin_sort_iterator_resync (GstBinSortIterator * bit)
static void
gst_bin_sort_iterator_free (GstBinSortIterator * bit)
{
GstBin *bin = bit->bin;
GST_DEBUG_OBJECT (bin, "free");
clear_queue (bit->queue);
g_queue_free (bit->queue);
g_hash_table_destroy (bit->hash);
gst_object_unref (bit->bin);
gst_object_unref (bin);
g_free (bit);
}
......
......@@ -265,17 +265,16 @@ gst_message_new_custom (GstMessageType type, GstObject * src,
message = (GstMessage *) gst_mini_object_new (GST_TYPE_MESSAGE);
GST_CAT_LOG (GST_CAT_MESSAGE, "creating new message %p %s", message,
GST_CAT_LOG (GST_CAT_MESSAGE, "source %s: creating new message %p %s",
(src ? GST_OBJECT_NAME (src) : "NULL"), message,
gst_message_type_get_name (type));
message->type = type;
if (src) {
message->src = gst_object_ref (src);
GST_CAT_DEBUG_OBJECT (GST_CAT_MESSAGE, src, "message source");
} else {
message->src = NULL;
GST_CAT_DEBUG (GST_CAT_MESSAGE, "NULL message source");
}
if (src)
gst_object_ref (src);
message->src = src;
if (structure) {
gst_structure_set_parent_refcount (structure,
&message->mini_object.refcount);
......
......@@ -439,7 +439,7 @@ gst_queue_link_src (GstPad * pad, GstPad * peer)
queue = GST_QUEUE (gst_pad_get_parent (pad));
GST_DEBUG ("queue linking source pad");
GST_DEBUG_OBJECT (queue, "queue linking source pad");
if (GST_PAD_LINKFUNC (peer)) {
result = GST_PAD_LINKFUNC (peer) (peer, pad);
......@@ -449,9 +449,9 @@ gst_queue_link_src (GstPad * pad, GstPad * peer)
GST_QUEUE_MUTEX_LOCK (queue);
if (queue->srcresult == GST_FLOW_OK) {
gst_pad_start_task (pad, (GstTaskFunction) gst_queue_loop, pad);
GST_DEBUG ("starting task as pad is linked");
GST_DEBUG_OBJECT (queue, "starting task as pad is linked");
} else {
GST_DEBUG ("not starting task reason %s",
GST_DEBUG_OBJECT (queue, "not starting task reason %s",
gst_flow_get_name (queue->srcresult));
}
GST_QUEUE_MUTEX_UNLOCK (queue);
......@@ -740,6 +740,7 @@ out_flushing:
GstFlowReturn ret = queue->srcresult;
const gchar *flowname = gst_flow_get_name (ret);
gst_pad_pause_task (queue->srcpad);
GST_CAT_LOG_OBJECT (queue_dataflow, queue,
"exit because task paused, reason: %s", flowname);
GST_QUEUE_MUTEX_UNLOCK (queue);
......@@ -823,7 +824,7 @@ restart:
("streaming stopped, reason %s", flowname));
gst_pad_push_event (queue->srcpad, gst_event_new_eos ());
}
GST_DEBUG ("pausing queue, reason %s", flowname);
GST_DEBUG_OBJECT (queue, "pausing queue, reason %s", flowname);
gst_pad_pause_task (queue->srcpad);
}
} else {
......@@ -831,7 +832,7 @@ restart:
/* all incomming data is now unexpected */
queue->srcresult = GST_FLOW_UNEXPECTED;
/* and we don't need to process anymore */
GST_DEBUG ("pausing queue, we're EOS now");
GST_DEBUG_OBJECT (queue, "pausing queue, we're EOS now");
gst_pad_pause_task (queue->srcpad);
restart = FALSE;
}
......@@ -854,6 +855,7 @@ out_flushing:
{
const gchar *flowname = gst_flow_get_name (queue->srcresult);
gst_pad_pause_task (queue->srcpad);
GST_CAT_LOG_OBJECT (queue_dataflow, queue,
"exit because task paused, reason: %s", flowname);
GST_QUEUE_MUTEX_UNLOCK (queue);
......
......@@ -1392,6 +1392,49 @@ gst_base_sink_peer_query (GstBaseSink * sink, GstQuery * query)
return res;
}
static gboolean
gst_base_sink_get_position (GstBaseSink * basesink, GstFormat format,
gint64 * cur)
{
GstClock *clock;
gboolean res = FALSE;
switch (format) {
case GST_FORMAT_TIME:
{
/* we can answer time format */
GST_LOCK (basesink);
if ((clock = GST_ELEMENT_CLOCK (basesink))) {
GstClockTime now;
gst_object_ref (clock);
GST_UNLOCK (basesink);
now = gst_clock_get_time (clock);
GST_LOCK (basesink);
*cur =
now - GST_ELEMENT_CAST (basesink)->base_time +
basesink->segment_time;
GST_DEBUG_OBJECT (basesink,
"now %" GST_TIME_FORMAT " + segment_time %" GST_TIME_FORMAT " = %"
GST_TIME_FORMAT, GST_TIME_ARGS (now),
GST_TIME_ARGS (basesink->segment_time), GST_TIME_ARGS (*cur));
gst_object_unref (clock);
res = TRUE;
} else {
}
GST_UNLOCK (basesink);
}
default:
break;
}
return res;
}
static gboolean
gst_base_sink_query (GstElement * element, GstQuery * query)
{
......@@ -1401,8 +1444,21 @@ gst_base_sink_query (GstElement * element, GstQuery * query)
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION:
res = gst_base_sink_peer_query (basesink, query);
{
gint64 cur = 0;
GstFormat format;
gst_query_parse_position (query, &format, NULL);
GST_DEBUG_OBJECT (basesink, "current position format %d", format);
if ((res = gst_base_sink_get_position (basesink, format, &cur))) {
gst_query_set_position (query, format, cur);
} else {
res = gst_base_sink_peer_query (basesink, query);
}
break;
}
case GST_QUERY_DURATION:
res = gst_base_sink_peer_query (basesink, query);
break;
......
......@@ -395,7 +395,8 @@ gst_base_src_default_newsegment (GstBaseSrc * src)
(gint64) src->segment_end);
event = gst_event_new_newsegment (FALSE, 1.0,
GST_FORMAT_BYTES,
(gint64) src->segment_start, (gint64) src->segment_end, (gint64) 0);
(gint64) src->segment_start, (gint64) src->segment_end,
(gint64) src->segment_start);
return gst_pad_push_event (src->srcpad, event);
}
......
......@@ -439,7 +439,7 @@ gst_queue_link_src (GstPad * pad, GstPad * peer)
queue = GST_QUEUE (gst_pad_get_parent (pad));
GST_DEBUG ("queue linking source pad");
GST_DEBUG_OBJECT (queue, "queue linking source pad");
if (GST_PAD_LINKFUNC (peer)) {
result = GST_PAD_LINKFUNC (peer) (peer, pad);
......@@ -449,9 +449,9 @@ gst_queue_link_src (GstPad * pad, GstPad * peer)
GST_QUEUE_MUTEX_LOCK (queue);
if (queue->srcresult == GST_FLOW_OK) {
gst_pad_start_task (pad, (GstTaskFunction) gst_queue_loop, pad);
GST_DEBUG ("starting task as pad is linked");
GST_DEBUG_OBJECT (queue, "starting task as pad is linked");
} else {
GST_DEBUG ("not starting task reason %s",
GST_DEBUG_OBJECT (queue, "not starting task reason %s",
gst_flow_get_name (queue->srcresult));
}
GST_QUEUE_MUTEX_UNLOCK (queue);
......@@ -740,6 +740,7 @@ out_flushing:
GstFlowReturn ret = queue->srcresult;
const gchar *flowname = gst_flow_get_name (ret);
gst_pad_pause_task (queue->srcpad);
GST_CAT_LOG_OBJECT (queue_dataflow, queue,
"exit because task paused, reason: %s", flowname);
GST_QUEUE_MUTEX_UNLOCK (queue);
......@@ -823,7 +824,7 @@ restart:
("streaming stopped, reason %s", flowname));
gst_pad_push_event (queue->srcpad, gst_event_new_eos ());
}
GST_DEBUG ("pausing queue, reason %s", flowname);
GST_DEBUG_OBJECT (queue, "pausing queue, reason %s", flowname);
gst_pad_pause_task (queue->srcpad);
}
} else {
......@@ -831,7 +832,7 @@ restart:
/* all incomming data is now unexpected */
queue->srcresult = GST_FLOW_UNEXPECTED;
/* and we don't need to process anymore */
GST_DEBUG ("pausing queue, we're EOS now");
GST_DEBUG_OBJECT (queue, "pausing queue, we're EOS now");
gst_pad_pause_task (queue->srcpad);
restart = FALSE;
}
......@@ -854,6 +855,7 @@ out_flushing:
{
const gchar *flowname = gst_flow_get_name (queue->srcresult);
gst_pad_pause_task (queue->srcpad);
GST_CAT_LOG_OBJECT (queue_dataflow, queue,
"exit because task paused, reason: %s", flowname);
GST_QUEUE_MUTEX_UNLOCK (queue);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment