message: rename GST_MESSAGE_DURATION -> GST_MESSAGE_DURATION_CHANGED

The duration should be re-queried via a query using the
normal path, we don't want applications to use the value
from the message itself, since it might no match what a
duration query done from the sink upstream might yield.

Also disables duration caching in GstBin. It should be
added back again at some point.
This commit is contained in:
Tim-Philipp Müller 2012-09-02 01:17:44 +01:00
parent a053bfb6f4
commit f712a9596c
9 changed files with 52 additions and 66 deletions

View file

@ -1434,8 +1434,7 @@ gst_message_new_segment_start
gst_message_parse_segment_start gst_message_parse_segment_start
gst_message_new_segment_done gst_message_new_segment_done
gst_message_parse_segment_done gst_message_parse_segment_done
gst_message_new_duration gst_message_new_duration_changed
gst_message_parse_duration
gst_message_new_latency gst_message_new_latency
gst_message_new_async_start gst_message_new_async_start
gst_message_new_async_done gst_message_new_async_done

View file

@ -351,6 +351,11 @@ The 0.11 porting guide
The GstStructure is removed from the public API, use the getters to get The GstStructure is removed from the public API, use the getters to get
a handle to a GstStructure. a handle to a GstStructure.
GST_MESSAGE_DURATION -> GST_MESSAGE_DURATION_CHANGED
gst_message_parse_duration() was removed (not needed any longer, do
a duration query to query the updated duration)
* GstCaps * GstCaps
Is now a boxed type derived from GstMiniObject. Is now a boxed type derived from GstMiniObject.
@ -602,8 +607,8 @@ The 0.11 porting guide
create request pads from elements. create request pads from elements.
* some elements that used to have a single dynamic source pad have a * some elements that used to have a single dynamic source pad have a
static source pad now. Example: wavparse, id3demux, apedemux. (This static source pad now. Example: wavparse, id3demux, iceydemux, apedemux.
does not affect applications using decodebin or playbin) (This does not affect applications using decodebin or playbin).
* the name of the GstXOverlay "prepare-xwindow-id" message has changed * the name of the GstXOverlay "prepare-xwindow-id" message has changed
to "prepare-window-handle" (and GstXOverlay has been renamed to to "prepare-window-handle" (and GstXOverlay has been renamed to

View file

@ -78,7 +78,7 @@
* a SEGMENT_START have posted a SEGMENT_DONE.</para></listitem> * a SEGMENT_START have posted a SEGMENT_DONE.</para></listitem>
* </varlistentry> * </varlistentry>
* <varlistentry> * <varlistentry>
* <term>GST_MESSAGE_DURATION</term> * <term>GST_MESSAGE_DURATION_CHANGED</term>
* <listitem><para> Is posted by an element that detected a change * <listitem><para> Is posted by an element that detected a change
* in the stream duration. The default bin behaviour is to clear any * in the stream duration. The default bin behaviour is to clear any
* cached duration values so that the next duration query will perform * cached duration values so that the next duration query will perform
@ -3229,7 +3229,7 @@ bin_do_message_forward (GstBin * bin, GstMessage * message)
* with the segment_done message. If there are no more segment_start * with the segment_done message. If there are no more segment_start
* messages, post segment_done message upwards. * messages, post segment_done message upwards.
* *
* GST_MESSAGE_DURATION: remove all previously cached duration messages. * GST_MESSAGE_DURATION_CHANGED: clear any cached durations.
* Whenever someone performs a duration query on the bin, we store the * Whenever someone performs a duration query on the bin, we store the
* result so we can answer it quicker the next time. Any element that * result so we can answer it quicker the next time. Any element that
* changes its duration marks our cached values invalid. * changes its duration marks our cached values invalid.
@ -3392,13 +3392,15 @@ gst_bin_handle_message_func (GstBin * bin, GstMessage * message)
} }
break; break;
} }
case GST_MESSAGE_DURATION: case GST_MESSAGE_DURATION_CHANGED:
{ {
/* remove all cached duration messages, next time somebody asks /* FIXME: remove all cached durations, next time somebody asks
* for duration, we will recalculate. */ * for duration, we will recalculate. */
#if 0
GST_OBJECT_LOCK (bin); GST_OBJECT_LOCK (bin);
bin_remove_messages (bin, NULL, GST_MESSAGE_DURATION); bin_remove_messages (bin, NULL, GST_MESSAGE_DURATION);
GST_OBJECT_UNLOCK (bin); GST_OBJECT_UNLOCK (bin);
#endif
goto forward; goto forward;
} }
case GST_MESSAGE_CLOCK_LOST: case GST_MESSAGE_CLOCK_LOST:
@ -3634,11 +3636,14 @@ bin_query_duration_done (GstBin * bin, QueryFold * fold)
GST_DEBUG_OBJECT (bin, "max duration %" G_GINT64_FORMAT, fold->max); GST_DEBUG_OBJECT (bin, "max duration %" G_GINT64_FORMAT, fold->max);
/* FIXME: re-implement duration caching */
#if 0
/* and cache now */ /* and cache now */
GST_OBJECT_LOCK (bin); GST_OBJECT_LOCK (bin);
bin->messages = g_list_prepend (bin->messages, bin->messages = g_list_prepend (bin->messages,
gst_message_new_duration (GST_OBJECT_CAST (bin), format, fold->max)); gst_message_new_duration (GST_OBJECT_CAST (bin), format, fold->max));
GST_OBJECT_UNLOCK (bin); GST_OBJECT_UNLOCK (bin);
#endif
} }
static gboolean static gboolean
@ -3752,6 +3757,8 @@ gst_bin_query (GstElement * element, GstQuery * query)
switch (GST_QUERY_TYPE (query)) { switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_DURATION: case GST_QUERY_DURATION:
{ {
/* FIXME: implement duration caching in GstBin again */
#if 0
GList *cached; GList *cached;
GstFormat qformat; GstFormat qformat;
@ -3782,6 +3789,9 @@ gst_bin_query (GstElement * element, GstQuery * query)
} }
} }
GST_OBJECT_UNLOCK (bin); GST_OBJECT_UNLOCK (bin);
#else
GST_FIXME ("implement duration caching in GstBin again");
#endif
/* no cached value found, iterate and collect durations */ /* no cached value found, iterate and collect durations */
fold_func = (GstIteratorFoldFunction) bin_query_duration_fold; fold_func = (GstIteratorFoldFunction) bin_query_duration_fold;
fold_init = bin_query_min_max_init; fold_init = bin_query_min_max_init;
@ -3847,7 +3857,6 @@ gst_bin_query (GstElement * element, GstQuery * query)
done: done:
gst_iterator_free (iter); gst_iterator_free (iter);
exit:
GST_DEBUG_OBJECT (bin, "query %p result %d", query, res); GST_DEBUG_OBJECT (bin, "query %p result %d", query, res);
return res; return res;

View file

@ -80,6 +80,19 @@ gst_pad_set_caps (GstPad * pad, GstCaps * caps)
#ifndef GST_DISABLE_DEPRECATED #ifndef GST_DISABLE_DEPRECATED
#define GST_MESSAGE_DURATION GST_MESSAGE_DURATION_CHANGED
#define gst_message_new_duration_changed(src,fmt,dur) \
gst_message_new_duration_changed(src)
#define gst_message_parse_duration(msg,fmt,dur) \
G_STMT_START { \
GstFormat *p_fmt = fmt; \
gint64 *p_dur = dur; \
if (p_fmt) \
*p_fmt = GST_FORMAT_TIME; \
if (p_dur) \
*p_dur = GST_CLOCK_TIME_NONE; \
} G_STMT_END
#endif /* not GST_DISABLE_DEPRECATED */ #endif /* not GST_DISABLE_DEPRECATED */
G_END_DECLS G_END_DECLS

View file

@ -96,7 +96,7 @@ static GstMessageQuarks message_quarks[] = {
{GST_MESSAGE_ELEMENT, "element", 0}, {GST_MESSAGE_ELEMENT, "element", 0},
{GST_MESSAGE_SEGMENT_START, "segment-start", 0}, {GST_MESSAGE_SEGMENT_START, "segment-start", 0},
{GST_MESSAGE_SEGMENT_DONE, "segment-done", 0}, {GST_MESSAGE_SEGMENT_DONE, "segment-done", 0},
{GST_MESSAGE_DURATION, "duration", 0}, {GST_MESSAGE_DURATION_CHANGED, "duration-changed", 0},
{GST_MESSAGE_LATENCY, "latency", 0}, {GST_MESSAGE_LATENCY, "latency", 0},
{GST_MESSAGE_ASYNC_START, "async-start", 0}, {GST_MESSAGE_ASYNC_START, "async-start", 0},
{GST_MESSAGE_ASYNC_DONE, "async-done", 0}, {GST_MESSAGE_ASYNC_DONE, "async-done", 0},
@ -805,33 +805,28 @@ gst_message_new_element (GstObject * src, GstStructure * structure)
} }
/** /**
* gst_message_new_duration: * gst_message_new_duration_changed:
* @src: (transfer none): The object originating the message. * @src: (transfer none): The object originating the message.
* @format: The format of the duration
* @duration: The new duration
* *
* Create a new duration message. This message is posted by elements that * Create a new duration changed message. This message is posted by elements
* know the duration of a stream in a specific format. This message * that know the duration of a stream when the duration changes. This message
* is received by bins and is used to calculate the total duration of a * is received by bins and is used to calculate the total duration of a
* pipeline. Elements may post a duration message with a duration of * pipeline. Elements may post a duration message with a duration of
* GST_CLOCK_TIME_NONE to indicate that the duration has changed and the * GST_CLOCK_TIME_NONE to indicate that the duration has changed and the
* cached duration should be discarded. The new duration can then be * cached duration should be discarded. The new duration can then be
* retrieved via a query. * retrieved via a query.
* *
* Returns: (transfer full): The new duration message. * Returns: (transfer full): The new duration-changed message.
* *
* MT safe. * MT safe.
*/ */
GstMessage * GstMessage *
gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration) gst_message_new_duration_changed (GstObject * src)
{ {
GstMessage *message; GstMessage *message;
GstStructure *structure;
structure = gst_structure_new_id (GST_QUARK (MESSAGE_DURATION), message = gst_message_new_custom (GST_MESSAGE_DURATION_CHANGED, src,
GST_QUARK (FORMAT), GST_TYPE_FORMAT, format, gst_structure_new_id_empty (GST_QUARK (MESSAGE_DURATION_CHANGED)));
GST_QUARK (DURATION), G_TYPE_INT64, duration, NULL);
message = gst_message_new_custom (GST_MESSAGE_DURATION, src, structure);
return message; return message;
} }
@ -1481,39 +1476,6 @@ gst_message_parse_segment_done (GstMessage * message, GstFormat * format,
GST_QUARK (POSITION))); GST_QUARK (POSITION)));
} }
/**
* gst_message_parse_duration:
* @message: A valid #GstMessage of type GST_MESSAGE_DURATION.
* @format: (out): Result location for the format, or NULL
* @duration: (out): Result location for the duration, or NULL
*
* Extracts the duration and format from the duration message. The duration
* might be GST_CLOCK_TIME_NONE, which indicates that the duration has
* changed. Applications should always use a query to retrieve the duration
* of a pipeline.
*
* MT safe.
*/
void
gst_message_parse_duration (GstMessage * message, GstFormat * format,
gint64 * duration)
{
GstStructure *structure;
g_return_if_fail (GST_IS_MESSAGE (message));
g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_DURATION);
structure = GST_MESSAGE_STRUCTURE (message);
if (format)
*format = (GstFormat)
g_value_get_enum (gst_structure_id_get_value (structure,
GST_QUARK (FORMAT)));
if (duration)
*duration =
g_value_get_int64 (gst_structure_id_get_value (structure,
GST_QUARK (DURATION)));
}
/** /**
* gst_message_parse_async_done: * gst_message_parse_async_done:
* @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE. * @message: A valid #GstMessage of type GST_MESSAGE_ASYNC_DONE.

View file

@ -71,8 +71,8 @@ typedef struct _GstMessage GstMessage;
* @GST_MESSAGE_SEGMENT_DONE: pipeline completed playback of a segment. This * @GST_MESSAGE_SEGMENT_DONE: pipeline completed playback of a segment. This
* message is forwarded to the application after all elements that posted * message is forwarded to the application after all elements that posted
* @GST_MESSAGE_SEGMENT_START posted a GST_MESSAGE_SEGMENT_DONE message. * @GST_MESSAGE_SEGMENT_START posted a GST_MESSAGE_SEGMENT_DONE message.
* @GST_MESSAGE_DURATION: The duration of a pipeline changed. The application * @GST_MESSAGE_DURATION_CHANGED: The duration of a pipeline changed. The
* can get the new duration with a duration query. * application can get the new duration with a duration query.
* @GST_MESSAGE_ASYNC_START: Posted by elements when they start an ASYNC * @GST_MESSAGE_ASYNC_START: Posted by elements when they start an ASYNC
* #GstStateChange. This message is not forwarded to the application but is used * #GstStateChange. This message is not forwarded to the application but is used
* internally. * internally.
@ -125,7 +125,7 @@ typedef enum
GST_MESSAGE_ELEMENT = (1 << 15), GST_MESSAGE_ELEMENT = (1 << 15),
GST_MESSAGE_SEGMENT_START = (1 << 16), GST_MESSAGE_SEGMENT_START = (1 << 16),
GST_MESSAGE_SEGMENT_DONE = (1 << 17), GST_MESSAGE_SEGMENT_DONE = (1 << 17),
GST_MESSAGE_DURATION = (1 << 18), GST_MESSAGE_DURATION_CHANGED = (1 << 18),
GST_MESSAGE_LATENCY = (1 << 19), GST_MESSAGE_LATENCY = (1 << 19),
GST_MESSAGE_ASYNC_START = (1 << 20), GST_MESSAGE_ASYNC_START = (1 << 20),
GST_MESSAGE_ASYNC_DONE = (1 << 21), GST_MESSAGE_ASYNC_DONE = (1 << 21),
@ -488,10 +488,8 @@ GstMessage * gst_message_new_segment_done (GstObject * src, GstFormat form
void gst_message_parse_segment_done (GstMessage *message, GstFormat *format, void gst_message_parse_segment_done (GstMessage *message, GstFormat *format,
gint64 *position); gint64 *position);
/* DURATION */ /* DURATION_CHANGED */
GstMessage * gst_message_new_duration (GstObject * src, GstFormat format, gint64 duration) G_GNUC_MALLOC; GstMessage * gst_message_new_duration_changed (GstObject * src) G_GNUC_MALLOC;
void gst_message_parse_duration (GstMessage *message, GstFormat *format,
gint64 *duration);
/* LATENCY */ /* LATENCY */
GstMessage * gst_message_new_latency (GstObject * src) G_GNUC_MALLOC; GstMessage * gst_message_new_latency (GstObject * src) G_GNUC_MALLOC;

View file

@ -43,7 +43,8 @@ static const gchar *_quark_strings[] = {
"GstMessageError", "GstMessageWarning", "GstMessageInfo", "GstMessageError", "GstMessageWarning", "GstMessageInfo",
"GstMessageBuffering", "GstMessageStateChanged", "GstMessageClockProvide", "GstMessageBuffering", "GstMessageStateChanged", "GstMessageClockProvide",
"GstMessageClockLost", "GstMessageNewClock", "GstMessageStructureChange", "GstMessageClockLost", "GstMessageNewClock", "GstMessageStructureChange",
"GstMessageSegmentStart", "GstMessageSegmentDone", "GstMessageDuration", "GstMessageSegmentStart", "GstMessageSegmentDone",
"GstMessageDurationChanged",
"GstMessageAsyncDone", "GstMessageRequestState", "GstMessageStreamStatus", "GstMessageAsyncDone", "GstMessageRequestState", "GstMessageStreamStatus",
"GstQueryPosition", "GstQueryDuration", "GstQueryLatency", "GstQueryConvert", "GstQueryPosition", "GstQueryDuration", "GstQueryLatency", "GstQueryConvert",
"GstQuerySegment", "GstQuerySeeking", "GstQueryFormats", "GstQueryBuffering", "GstQuerySegment", "GstQuerySeeking", "GstQueryFormats", "GstQueryBuffering",

View file

@ -96,7 +96,7 @@ typedef enum _GstQuarkId
GST_QUARK_MESSAGE_STRUCTURE_CHANGE = 67, GST_QUARK_MESSAGE_STRUCTURE_CHANGE = 67,
GST_QUARK_MESSAGE_SEGMENT_START = 68, GST_QUARK_MESSAGE_SEGMENT_START = 68,
GST_QUARK_MESSAGE_SEGMENT_DONE = 69, GST_QUARK_MESSAGE_SEGMENT_DONE = 69,
GST_QUARK_MESSAGE_DURATION = 70, GST_QUARK_MESSAGE_DURATION_CHANGED = 70,
GST_QUARK_MESSAGE_ASYNC_DONE = 71, GST_QUARK_MESSAGE_ASYNC_DONE = 71,
GST_QUARK_MESSAGE_REQUEST_STATE = 72, GST_QUARK_MESSAGE_REQUEST_STATE = 72,
GST_QUARK_MESSAGE_STREAM_STATUS = 73, GST_QUARK_MESSAGE_STREAM_STATUS = 73,

View file

@ -555,7 +555,7 @@ EXPORTS
gst_message_new_clock_lost gst_message_new_clock_lost
gst_message_new_clock_provide gst_message_new_clock_provide
gst_message_new_custom gst_message_new_custom
gst_message_new_duration gst_message_new_duration_changed
gst_message_new_element gst_message_new_element
gst_message_new_eos gst_message_new_eos
gst_message_new_error gst_message_new_error
@ -583,7 +583,6 @@ EXPORTS
gst_message_parse_buffering_stats gst_message_parse_buffering_stats
gst_message_parse_clock_lost gst_message_parse_clock_lost
gst_message_parse_clock_provide gst_message_parse_clock_provide
gst_message_parse_duration
gst_message_parse_error gst_message_parse_error
gst_message_parse_info gst_message_parse_info
gst_message_parse_new_clock gst_message_parse_new_clock