Commit 8df6cd72 authored by Wim Taymans's avatar Wim Taymans

Remove old query functions. Ported old code.

Original commit message from CVS:
Remove old query functions. Ported old code.
Added position/convert helper functions to gstutils.
Reordered gstpad.c code, grouping relevant things.
Remove gst_message_new(), always need to speficy a specific
message.
parent 328ddd73
2005-05-09 Wim Taymans <wim@fluendo.com>
* docs/design/draft-push-pull.txt:
* gst/base/gstbasesrc.c: (gst_basesrc_init), (gst_basesrc_query):
* gst/elements/gstfilesink.c: (gst_filesink_init),
(gst_filesink_query):
* gst/elements/gsttypefindelement.c: (gst_type_find_element_init),
(gst_type_find_handle_src_query), (find_element_get_length):
* gst/gstelement.c: (gst_element_seek), (gst_element_query):
* gst/gstelement.h:
* gst/gstmessage.c:
* gst/gstmessage.h:
* gst/gstpad.c: (gst_real_pad_init), (gst_pad_get_query_types),
(gst_real_pad_get_caps_unlocked),
(gst_pad_get_internal_links_default), (gst_pad_get_internal_links),
(gst_pad_event_default_dispatch), (gst_pad_event_default),
(gst_pad_dispatcher), (gst_pad_query), (gst_pad_query_default),
(gst_real_pad_dispose), (gst_real_pad_finalize),
(gst_pad_load_and_link), (gst_pad_save_thyself),
(gst_ghost_pad_save_thyself), (handle_pad_block), (gst_pad_push),
(gst_pad_check_pull_range), (gst_pad_pull_range),
(gst_pad_template_get_type), (gst_pad_template_class_init),
(gst_pad_template_init), (gst_pad_template_dispose),
(name_is_valid), (gst_static_pad_template_get),
(gst_pad_template_new), (gst_static_pad_template_get_caps),
(gst_pad_template_get_caps), (gst_pad_set_element_private),
(gst_pad_get_element_private), (gst_pad_start_task),
(gst_pad_pause_task), (gst_pad_stop_task),
(gst_ghost_pad_get_type), (gst_ghost_pad_class_init),
(gst_ghost_pad_init), (gst_ghost_pad_dispose),
(gst_ghost_pad_set_property), (gst_ghost_pad_get_property),
(gst_ghost_pad_new):
* gst/gstpad.h:
* gst/gstquery.c: (_gst_query_initialize), (gst_query_new),
(gst_query_new_position), (gst_query_set_position),
(gst_query_parse_position), (gst_query_new_convert),
(gst_query_set_convert), (gst_query_parse_convert):
* gst/gstquery.h:
* gst/gstqueryutils.c:
* gst/gstqueryutils.h:
* gst/gstqueue.c: (gst_queue_init), (gst_queue_getcaps),
(gst_queue_bufferalloc), (gst_queue_handle_sink_event),
(gst_queue_handle_src_query):
* gst/gstutils.c: (gst_element_get_compatible_pad_template),
(gst_element_query_position), (gst_element_query_convert),
(intersect_caps_func), (gst_pad_query_position),
(gst_pad_query_convert):
* gst/gstutils.h:
* tools/gst-inspect.c: (print_pad_info):
* tools/gst-xmlinspect.c: (print_element_info):
Remove old query functions. Ported old code.
Added position/convert helper functions to gstutils.
Reordered gstpad.c code, grouping relevant things.
Remove gst_message_new(), always need to speficy a specific
message.
2005-05-09 Andy Wingo <wingo@pobox.com>
* gst/gstiterator.h: Add some includes.
......
......@@ -80,9 +80,31 @@ Proposition:
decision.
Things to query:
- pad can do real random access (downstream peer can ask for offset != -1)
- min offset
- suggest sequential access
- max offset
- align: all offsets should be aligned with this value.
- pad can give ranges from A to B length (peer can ask for A <= length <= B)
- min length
- suggested length
- max length
Use cases:
- An audio source can provide random access to the samples queued in its
DMA buffer, it however suggests sequential access method.
An audio source can provide a random number of samples but prefers
reading from the hardware using a fixed segment size.
- A caching network source would suggest sequential access but is seekable
in the cached region. Applications can query for the already downloaded
portion and update the GUI, a seek can be done in that area.
- a live video source can only provide buffers sequentialy. It exposes
offsets as -1. lengths are also -1.
......
......@@ -89,9 +89,11 @@ static void gst_basesrc_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static gboolean gst_basesrc_event_handler (GstPad * pad, GstEvent * event);
static gboolean gst_basesrc_query2 (GstPad * pad, GstQuery * query);
static gboolean gst_basesrc_query (GstPad * pad, GstQuery * query);
#if 0
static const GstEventMask *gst_basesrc_get_event_mask (GstPad * pad);
#endif
static gboolean gst_basesrc_unlock (GstBaseSrc * basesrc);
static gboolean gst_basesrc_get_size (GstBaseSrc * basesrc, guint64 * size);
......@@ -158,9 +160,7 @@ gst_basesrc_init (GstBaseSrc * basesrc, gpointer g_class)
gst_pad_set_activate_function (pad, gst_basesrc_activate);
gst_pad_set_event_function (pad, gst_basesrc_event_handler);
gst_pad_set_event_mask_function (pad, gst_basesrc_get_event_mask);
gst_pad_set_query2_function (pad, gst_basesrc_query2);
gst_pad_set_query_function (pad, gst_basesrc_query);
gst_pad_set_checkgetrange_function (pad, gst_basesrc_check_get_range);
......@@ -193,7 +193,7 @@ gst_basesrc_set_dataflow_funcs (GstBaseSrc * this)
}
static gboolean
gst_basesrc_query2 (GstPad * pad, GstQuery * query)
gst_basesrc_query (GstPad * pad, GstQuery * query)
{
gboolean b;
guint64 ui64;
......@@ -207,7 +207,7 @@ gst_basesrc_query2 (GstPad * pad, GstQuery * query)
{
GstFormat format;
gst_query_parse_position_query (query, &format);
gst_query_parse_position (query, &format, NULL, NULL);
switch (format) {
case GST_FORMAT_DEFAULT:
case GST_FORMAT_BYTES:
......@@ -243,10 +243,11 @@ gst_basesrc_query2 (GstPad * pad, GstQuery * query)
case GST_QUERY_RATE:
case GST_QUERY_CONVERT:
default:
return gst_pad_query2_default (pad, query);
return gst_pad_query_default (pad, query);
}
}
#if 0
static const GstEventMask *
gst_basesrc_get_event_mask (GstPad * pad)
{
......@@ -260,6 +261,7 @@ gst_basesrc_get_event_mask (GstPad * pad)
};
return masks;
}
#endif
static gboolean
gst_basesrc_do_seek (GstBaseSrc * src, GstEvent * event)
......
......@@ -80,7 +80,7 @@ static gboolean gst_filesink_event (GstBaseSink * sink, GstEvent * event);
static GstFlowReturn gst_filesink_render (GstBaseSink * sink,
GstBuffer * buffer);
static gboolean gst_filesink_query2 (GstPad * pad, GstQuery * query);
static gboolean gst_filesink_query (GstPad * pad, GstQuery * query);
static void gst_filesink_uri_handler_init (gpointer g_iface,
gpointer iface_data);
......@@ -144,7 +144,7 @@ gst_filesink_init (GstFileSink * filesink)
pad = GST_BASESINK_PAD (filesink);
gst_pad_set_query2_function (pad, gst_filesink_query2);
gst_pad_set_query_function (pad, gst_filesink_query);
filesink->filename = NULL;
filesink->file = NULL;
......@@ -255,7 +255,7 @@ gst_filesink_close_file (GstFileSink * sink)
}
static gboolean
gst_filesink_query2 (GstPad * pad, GstQuery * query)
gst_filesink_query (GstPad * pad, GstQuery * query)
{
GstFileSink *self;
GstFormat format;
......@@ -264,7 +264,7 @@ gst_filesink_query2 (GstPad * pad, GstQuery * query)
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION:
gst_query_parse_position_query (query, &format);
gst_query_parse_position (query, &format, NULL, NULL);
switch (format) {
case GST_FORMAT_DEFAULT:
case GST_FORMAT_BYTES:
......@@ -280,7 +280,7 @@ gst_filesink_query2 (GstPad * pad, GstQuery * query)
return TRUE;
default:
return gst_pad_query2_default (pad, query);
return gst_pad_query_default (pad, query);
}
}
......
......@@ -115,11 +115,13 @@ static void gst_type_find_element_set_property (GObject * object,
static void gst_type_find_element_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
#if 0
static const GstEventMask *gst_type_find_element_src_event_mask (GstPad * pad);
#endif
static gboolean gst_type_find_element_src_event (GstPad * pad,
GstEvent * event);
static gboolean gst_type_find_handle_src_query (GstPad * pad,
GstQueryType type, GstFormat * fmt, gint64 * value);
static gboolean gst_type_find_handle_src_query (GstPad * pad, GstQuery * query);
static GstFlowReturn push_buffer_store (GstTypeFindElement * typefind);
static gboolean gst_type_find_element_handle_event (GstPad * pad,
......@@ -219,8 +221,6 @@ gst_type_find_element_init (GstTypeFindElement * typefind)
gst_type_find_element_checkgetrange);
gst_pad_set_getrange_function (typefind->src, gst_type_find_element_getrange);
gst_pad_set_event_function (typefind->src, gst_type_find_element_src_event);
gst_pad_set_event_mask_function (typefind->src,
gst_type_find_element_src_event_mask);
gst_pad_set_query_function (typefind->src,
GST_DEBUG_FUNCPTR (gst_type_find_handle_src_query));
gst_pad_use_fixed_caps (typefind->src);
......@@ -295,32 +295,48 @@ gst_type_find_element_get_property (GObject * object, guint prop_id,
}
static gboolean
gst_type_find_handle_src_query (GstPad * pad,
GstQueryType type, GstFormat * fmt, gint64 * value)
gst_type_find_handle_src_query (GstPad * pad, GstQuery * query)
{
GstTypeFindElement *typefind =
GST_TYPE_FIND_ELEMENT (gst_pad_get_parent (pad));
GstTypeFindElement *typefind;
gboolean res;
res = gst_pad_query (GST_PAD_PEER (typefind->sink), type, fmt, value);
typefind = GST_TYPE_FIND_ELEMENT (GST_PAD_PARENT (pad));
res = gst_pad_query (GST_PAD_PEER (typefind->sink), query);
if (!res)
return FALSE;
if (type == GST_QUERY_POSITION && typefind->store != NULL) {
/* FIXME: this code assumes that there's no discont in the queue */
switch (*fmt) {
case GST_FORMAT_BYTES:
*value -= gst_buffer_store_get_size (typefind->store, 0);
break;
default:
/* FIXME */
break;
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION:
{
gint64 peer_pos, peer_total;
GstFormat format;
if (typefind->store == NULL)
return TRUE;
gst_query_parse_position (query, &format, &peer_pos, &peer_total);
/* FIXME: this code assumes that there's no discont in the queue */
switch (format) {
case GST_FORMAT_BYTES:
peer_pos -= gst_buffer_store_get_size (typefind->store, 0);
break;
default:
/* FIXME */
break;
}
gst_query_set_position (query, format, peer_pos, peer_total);
break;
}
default:
break;
}
return TRUE;
}
#if 0
static const GstEventMask *
gst_type_find_element_src_event_mask (GstPad * pad)
{
......@@ -334,6 +350,7 @@ gst_type_find_element_src_event_mask (GstPad * pad)
return mask;
}
#endif
static gboolean
gst_type_find_element_src_event (GstPad * pad, GstEvent * event)
......@@ -462,24 +479,29 @@ find_element_get_length (gpointer data)
return 0;
}
if (entry->self->stream_length == 0) {
typefind->stream_length_available =
gst_pad_query (GST_PAD_PEER (entry->self->sink), GST_QUERY_TOTAL,
&format, (gint64 *) & entry->self->stream_length);
if (format != GST_FORMAT_BYTES)
if (!gst_pad_query_position (GST_PAD_PEER (entry->self->sink), &format,
NULL, (gint64 *) & entry->self->stream_length))
goto no_length;
if (format != GST_FORMAT_BYTES) {
typefind->stream_length_available = FALSE;
if (!typefind->stream_length_available) {
GST_DEBUG_OBJECT (entry->self,
"'%s' called get_length () but it's not available",
GST_PLUGIN_FEATURE_NAME (entry->factory));
return 0;
entry->self->stream_length = 0;
} else {
GST_DEBUG_OBJECT (entry->self,
"'%s' called get_length () and it's %" G_GUINT64_FORMAT " bytes",
GST_PLUGIN_FEATURE_NAME (entry->factory), entry->self->stream_length);
}
}
return entry->self->stream_length;
no_length:
{
typefind->stream_length_available = FALSE;
GST_DEBUG_OBJECT (entry->self,
"'%s' called get_length () but it's not available",
GST_PLUGIN_FEATURE_NAME (entry->factory));
return 0;
}
}
static gboolean
......
......@@ -1049,48 +1049,6 @@ wrong_direction:
}
}
/**
* gst_element_get_event_masks:
* @element: a #GstElement to query
*
* Get an array of event masks from the element.
* If the element doesn't implement an event masks function,
* the query will be forwarded to a random linked sink pad.
*
* Returns: An array of #GstEventMask elements. The array
* cannot be modified or freed.
*
* MT safe.
*/
const GstEventMask *
gst_element_get_event_masks (GstElement * element)
{
GstElementClass *oclass;
const GstEventMask *result = NULL;
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
oclass = GST_ELEMENT_GET_CLASS (element);
if (oclass->get_event_masks) {
result = oclass->get_event_masks (element);
} else {
GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SINK);
if (pad) {
GstPad *peer = gst_pad_get_peer (pad);
if (peer) {
result = gst_pad_get_event_masks (peer);
gst_object_unref (GST_OBJECT (peer));
}
gst_object_unref (GST_OBJECT (pad));
}
}
return result;
}
/**
* gst_element_send_event:
* @element: a #GstElement to send the event to.
......@@ -1156,9 +1114,12 @@ gst_element_send_event (GstElement * element, GstEvent * event)
gboolean
gst_element_seek (GstElement * element, GstSeekType seek_type, guint64 offset)
{
GstEvent *event = gst_event_new_seek (seek_type, offset);
GstEvent *event;
gboolean result;
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
event = gst_event_new_seek (seek_type, offset);
result = gst_element_send_event (element, event);
return result;
......@@ -1224,25 +1185,23 @@ gst_element_get_query_types (GstElement * element)
* MT safe.
*/
gboolean
gst_element_query (GstElement * element, GstQueryType type,
GstFormat * format, gint64 * value)
gst_element_query (GstElement * element, GstQuery * query)
{
GstElementClass *oclass;
gboolean result = FALSE;
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
g_return_val_if_fail (format != NULL, FALSE);
g_return_val_if_fail (value != NULL, FALSE);
g_return_val_if_fail (query != NULL, FALSE);
oclass = GST_ELEMENT_GET_CLASS (element);
if (oclass->query) {
result = oclass->query (element, type, format, value);
result = oclass->query (element, query);
} else {
GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SRC);
if (pad) {
result = gst_pad_query (pad, type, format, value);
result = gst_pad_query (pad, query);
gst_object_unref (GST_OBJECT (pad));
} else {
......@@ -1251,7 +1210,7 @@ gst_element_query (GstElement * element, GstQueryType type,
GstPad *peer = gst_pad_get_peer (pad);
if (peer) {
result = gst_pad_query (peer, type, format, value);
result = gst_pad_query (peer, query);
gst_object_unref (GST_OBJECT (peer));
}
......@@ -1262,104 +1221,6 @@ gst_element_query (GstElement * element, GstQueryType type,
return result;
}
/**
* gst_element_get_formats:
* @element: a #GstElement to query
*
* Get an array of formats from the element.
* If the element doesn't implement a formats function,
* the query will be forwarded to a random sink pad.
*
* Returns: An array of #GstFormat elements.
*
* MT safe.
*/
const GstFormat *
gst_element_get_formats (GstElement * element)
{
GstElementClass *oclass;
const GstFormat *result = NULL;
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
oclass = GST_ELEMENT_GET_CLASS (element);
if (oclass->get_formats) {
result = oclass->get_formats (element);
} else {
GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SINK);
if (pad) {
GstPad *peer = gst_pad_get_peer (pad);
if (peer) {
result = gst_pad_get_formats (peer);
gst_object_unref (GST_OBJECT (peer));
}
gst_object_unref (GST_OBJECT (pad));
}
}
return result;
}
/**
* gst_element_convert:
* @element: a #GstElement to invoke the converter on.
* @src_format: the source #GstFormat.
* @src_value: the source value.
* @dest_format: a pointer to the destination #GstFormat.
* @dest_value: a pointer to the destination value.
*
* Invokes a conversion on the element.
* If the element doesn't implement a convert function,
* the query will be forwarded to a random sink pad.
*
* Returns: TRUE if the conversion could be performed.
*
* MT safe.
*/
gboolean
gst_element_convert (GstElement * element,
GstFormat src_format, gint64 src_value,
GstFormat * dest_format, gint64 * dest_value)
{
GstElementClass *oclass;
gboolean result = FALSE;
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
g_return_val_if_fail (dest_format != NULL, FALSE);
g_return_val_if_fail (dest_value != NULL, FALSE);
if (src_format == *dest_format) {
*dest_value = src_value;
return TRUE;
}
oclass = GST_ELEMENT_GET_CLASS (element);
if (oclass->convert) {
result = oclass->convert (element,
src_format, src_value, dest_format, dest_value);
} else {
GstPad *pad = gst_element_get_random_pad (element, GST_PAD_SINK);
if (pad) {
GstPad *peer = gst_pad_get_peer (pad);
if (peer) {
result = gst_pad_convert (peer,
src_format, src_value, dest_format, dest_value);
gst_object_unref (GST_OBJECT (peer));
}
gst_object_unref (GST_OBJECT (pad));
}
}
return result;
}
/**
* gst_element_post_message:
* @element: a #GstElement posting the message
......
......@@ -249,13 +249,13 @@ struct _GstElementClass
void (*release_pad) (GstElement *element, GstPad *pad);
/* state changes */
GstElementStateReturn (*get_state) (GstElement * element, GstElementState * state,
GstElementState * pending, GTimeVal * timeout);
GstElementStateReturn (*get_state) (GstElement * element, GstElementState * state,
GstElementState * pending, GTimeVal * timeout);
GstElementStateReturn (*change_state) (GstElement *element);
/* manager */
void (*set_manager) (GstElement * element, GstPipeline * pipeline);
void (*set_bus) (GstElement * element, GstBus * bus);
void (*set_manager) (GstElement * element, GstPipeline * pipeline);
void (*set_bus) (GstElement * element, GstBus * bus);
void (*set_scheduler) (GstElement *element, GstScheduler *scheduler);
/* set/get clocks */
......@@ -266,16 +266,11 @@ struct _GstElementClass
GstIndex* (*get_index) (GstElement *element);
void (*set_index) (GstElement *element, GstIndex *index);
/* query/convert/events functions */
const GstEventMask* (*get_event_masks) (GstElement *element);
/* query functions */
gboolean (*send_event) (GstElement *element, GstEvent *event);
const GstFormat* (*get_formats) (GstElement *element);
gboolean (*convert) (GstElement *element,
GstFormat src_format, gint64 src_value,
GstFormat *dest_format, gint64 *dest_value);
const GstQueryType* (*get_query_types) (GstElement *element);
gboolean (*query) (GstElement *element, GstQueryType type,
GstFormat *format, gint64 *value);
gboolean (*query) (GstElement *element, GstQuery *query);
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
......@@ -309,10 +304,10 @@ void gst_element_set_index (GstElement *element, GstIndex *index);
GstIndex* gst_element_get_index (GstElement *element);
/* manager and tasks */
void gst_element_set_manager (GstElement * element, GstPipeline * pipeline);
GstPipeline *gst_element_get_manager (GstElement * element);
void gst_element_set_bus (GstElement * element, GstBus * bus);
GstBus *gst_element_get_bus (GstElement * element);
void gst_element_set_manager (GstElement * element, GstPipeline * pipeline);
GstPipeline * gst_element_get_manager (GstElement * element);
void gst_element_set_bus (GstElement * element, GstBus * bus);
GstBus * gst_element_get_bus (GstElement * element);
void gst_element_set_scheduler (GstElement *element, GstScheduler *sched);
GstScheduler* gst_element_get_scheduler (GstElement *element);
......@@ -330,44 +325,37 @@ void gst_element_release_request_pad (GstElement *element, GstPad *pad);
GstIterator * gst_element_iterate_pads (GstElement * element);
/* event/query/format stuff */
G_CONST_RETURN GstEventMask*
gst_element_get_event_masks (GstElement *element);
gboolean gst_element_send_event (GstElement *element, GstEvent *event);
gboolean gst_element_seek (GstElement *element, GstSeekType seek_type,
guint64 offset);
G_CONST_RETURN GstQueryType*
gst_element_get_query_types (GstElement *element);
gboolean gst_element_query (GstElement *element, GstQueryType type,
GstFormat *format, gint64 *value);
G_CONST_RETURN GstFormat*
gst_element_get_formats (GstElement *element);
gboolean gst_element_convert (GstElement *element,
GstFormat src_format, gint64 src_value,
GstFormat *dest_format, gint64 *dest_value);
gboolean gst_element_query (GstElement *element, GstQuery *query);
/* messages */
gboolean gst_element_post_message (GstElement * element, GstMessage * message);
gboolean gst_element_post_message (GstElement * element, GstMessage * message);
/* error handling */
gchar * _gst_element_error_printf (const gchar *format, ...);
void gst_element_message_full (GstElement * element, GstMessageType type,
GQuark domain, gint code, gchar * text, gchar * debug, const gchar * file,
const gchar * function, gint line);