2000-12-28 22:12:02 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gstcaps.c: Element capabilities subsystem
|
2000-12-03 17:51:29 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2000-12-28 22:12:02 +00:00
|
|
|
#include "gst_private.h"
|
2000-12-03 20:15:15 +00:00
|
|
|
|
2000-12-15 01:57:34 +00:00
|
|
|
#include "gstcaps.h"
|
|
|
|
#include "gsttype.h"
|
2003-02-02 19:58:11 +00:00
|
|
|
#include "gstmemchunk.h"
|
2003-06-29 14:05:49 +00:00
|
|
|
#include "gstinfo.h"
|
2000-12-03 20:15:15 +00:00
|
|
|
|
2003-02-10 20:32:32 +00:00
|
|
|
#ifndef GST_DISABLE_TRACE
|
2003-02-02 19:58:11 +00:00
|
|
|
/* #define GST_WITH_ALLOC_TRACE */
|
|
|
|
#include "gsttrace.h"
|
|
|
|
|
|
|
|
static GstAllocTrace *_gst_caps_trace;
|
2003-02-10 20:32:32 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static GstMemChunk *_gst_caps_chunk;
|
2000-12-28 22:12:02 +00:00
|
|
|
|
2002-03-30 17:05:03 +00:00
|
|
|
GType _gst_caps_type;
|
|
|
|
|
2003-05-17 00:47:01 +00:00
|
|
|
extern GstProps * __gst_props_from_string_func (gchar *s, gchar **end, gboolean caps);
|
|
|
|
extern gboolean __gst_props_parse_string (gchar *r, gchar **end, gchar **next);
|
|
|
|
|
|
|
|
/* transform functions */
|
|
|
|
static void gst_caps_transform_to_string (const GValue *src_value, GValue *dest_value);
|
|
|
|
|
2003-05-18 02:42:19 +00:00
|
|
|
static void gst_caps_destroy (GstCaps *caps);
|
|
|
|
|
|
|
|
|
2002-09-17 21:22:31 +00:00
|
|
|
static void
|
2003-05-17 00:47:01 +00:00
|
|
|
gst_caps_transform_to_string (const GValue *src_value, GValue *dest_value)
|
2002-09-17 21:22:31 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps = g_value_peek_pointer (src_value);
|
2003-05-17 00:47:01 +00:00
|
|
|
dest_value->data[0].v_pointer = gst_caps_to_string (caps);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* gst_caps_to_string:
|
|
|
|
* caps: the caps to convert to a string
|
|
|
|
*
|
|
|
|
* Converts a #GstCaps into a readable format. This is mainly intended for
|
|
|
|
* debugging purposes. You have to free the string using g_free.
|
|
|
|
* A string converted with #gst_caps_to_string can always be converted back to
|
|
|
|
* its caps representation using #gst_caps_from_string.
|
|
|
|
*
|
|
|
|
* Returns: A newly allocated string
|
|
|
|
*/
|
|
|
|
gchar *
|
|
|
|
gst_caps_to_string (GstCaps *caps)
|
|
|
|
{
|
|
|
|
gchar *ret;
|
|
|
|
GString *result;
|
|
|
|
|
|
|
|
result = g_string_new ("");
|
2002-09-17 21:22:31 +00:00
|
|
|
|
2003-05-30 03:02:38 +00:00
|
|
|
if(caps==NULL){
|
|
|
|
g_string_append(result, "NULL");
|
|
|
|
}
|
|
|
|
|
2002-09-17 21:22:31 +00:00
|
|
|
while (caps) {
|
|
|
|
gchar *props;
|
|
|
|
GValue value = { 0, }; /* the important thing is that value.type = 0 */
|
|
|
|
|
2003-05-17 00:47:01 +00:00
|
|
|
g_string_append_printf (result, "\"%s\"", gst_caps_get_mime (caps));
|
2002-09-17 21:22:31 +00:00
|
|
|
|
2003-05-17 00:47:01 +00:00
|
|
|
if (caps->properties) {
|
|
|
|
g_value_init (&value, GST_TYPE_PROPS);
|
|
|
|
g_value_set_boxed (&value, caps->properties);
|
|
|
|
props = g_strdup_value_contents (&value);
|
2002-09-17 21:22:31 +00:00
|
|
|
|
2003-05-17 00:47:01 +00:00
|
|
|
g_value_unset (&value);
|
|
|
|
g_string_append (result, ", ");
|
|
|
|
g_string_append (result, props);
|
|
|
|
g_free (props);
|
|
|
|
}
|
2002-09-17 21:22:31 +00:00
|
|
|
|
|
|
|
caps = caps->next;
|
2003-05-17 00:47:01 +00:00
|
|
|
if (caps)
|
|
|
|
g_string_append (result, "; ");
|
2002-09-17 21:22:31 +00:00
|
|
|
}
|
2003-05-17 00:47:01 +00:00
|
|
|
ret = result->str;
|
2003-02-02 19:58:11 +00:00
|
|
|
g_string_free (result, FALSE);
|
2003-05-17 00:47:01 +00:00
|
|
|
return ret;
|
2002-09-17 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
2003-05-17 00:47:01 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_caps_from_string_func (gchar *r)
|
|
|
|
{
|
|
|
|
gchar *mime, *w;
|
|
|
|
GstCaps *caps, *append;
|
|
|
|
GstProps *props = NULL;
|
|
|
|
|
|
|
|
mime = r;
|
|
|
|
if (!__gst_props_parse_string (r, &w, &r)) goto error;
|
|
|
|
|
|
|
|
if (*r == '\0') goto found;
|
|
|
|
if (*r++ != ',') goto error;
|
|
|
|
while (g_ascii_isspace (*r)) r++;
|
|
|
|
|
|
|
|
props = __gst_props_from_string_func (r, &r, TRUE);
|
|
|
|
if (!props) goto error;
|
|
|
|
|
|
|
|
found:
|
|
|
|
*w = '\0';
|
|
|
|
if (*mime == '\0') {
|
|
|
|
gst_props_unref (props);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
caps = gst_caps_new ("parsed caps", mime, props);
|
|
|
|
if (*r == '\0')
|
|
|
|
return caps;
|
|
|
|
|
|
|
|
while (g_ascii_isspace (*r)) r++;
|
|
|
|
if (*r == ';') {
|
|
|
|
r++;
|
|
|
|
while (g_ascii_isspace (*r)) r++;
|
|
|
|
append = gst_caps_from_string_func (r);
|
|
|
|
if (!append) {
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
gst_caps_append (caps, append);
|
|
|
|
}
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
|
|
|
|
error:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* gst_caps_from_string:
|
|
|
|
* str: the str to convert into caps
|
|
|
|
*
|
|
|
|
* Tries to convert a string into a #GstCaps. This is mainly intended for
|
|
|
|
* debugging purposes. The returned caps are floating.
|
|
|
|
*
|
|
|
|
* Returns: A floating caps or NULL if the string couldn't be converted
|
|
|
|
*/
|
|
|
|
GstCaps *
|
|
|
|
gst_caps_from_string (gchar *str)
|
|
|
|
{
|
|
|
|
gchar *s;
|
|
|
|
GstCaps *caps;
|
|
|
|
g_return_val_if_fail (str != NULL, NULL);
|
|
|
|
|
|
|
|
s = g_strdup (str);
|
|
|
|
caps = gst_caps_from_string_func (s);
|
|
|
|
g_free (s);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
2001-03-07 21:52:56 +00:00
|
|
|
void
|
|
|
|
_gst_caps_initialize (void)
|
2000-12-03 17:51:29 +00:00
|
|
|
{
|
2003-02-02 19:58:11 +00:00
|
|
|
_gst_caps_chunk = gst_mem_chunk_new ("GstCaps",
|
2001-03-20 18:29:00 +00:00
|
|
|
sizeof (GstCaps), sizeof (GstCaps) * 256,
|
|
|
|
G_ALLOC_AND_FREE);
|
2002-03-30 17:05:03 +00:00
|
|
|
|
|
|
|
_gst_caps_type = g_boxed_type_register_static ("GstCaps",
|
|
|
|
(GBoxedCopyFunc) gst_caps_ref,
|
|
|
|
(GBoxedFreeFunc) gst_caps_unref);
|
|
|
|
|
2003-05-17 00:47:01 +00:00
|
|
|
g_value_register_transform_func (_gst_caps_type, G_TYPE_STRING,
|
|
|
|
gst_caps_transform_to_string);
|
2003-02-02 19:58:11 +00:00
|
|
|
|
2003-02-10 20:32:32 +00:00
|
|
|
#ifndef GST_DISABLE_TRACE
|
2003-02-02 19:58:11 +00:00
|
|
|
_gst_caps_trace = gst_alloc_trace_register (GST_CAPS_TRACE_NAME);
|
2003-02-10 20:32:32 +00:00
|
|
|
#endif
|
2000-12-03 17:51:29 +00:00
|
|
|
}
|
2000-12-11 00:04:25 +00:00
|
|
|
|
2003-03-16 20:06:02 +00:00
|
|
|
GType
|
|
|
|
gst_caps_get_type (void)
|
|
|
|
{
|
|
|
|
return _gst_caps_type;
|
|
|
|
}
|
|
|
|
|
2000-12-11 00:04:25 +00:00
|
|
|
static guint16
|
2001-01-06 02:35:17 +00:00
|
|
|
get_type_for_mime (const gchar *mime)
|
2000-12-11 00:04:25 +00:00
|
|
|
{
|
|
|
|
guint16 typeid;
|
|
|
|
|
|
|
|
typeid = gst_type_find_by_mime (mime);
|
|
|
|
if (typeid == 0) {
|
2001-08-21 20:16:48 +00:00
|
|
|
GstTypeDefinition definition;
|
|
|
|
GstTypeFactory *factory;
|
2000-12-11 00:04:25 +00:00
|
|
|
|
2001-08-21 20:16:48 +00:00
|
|
|
definition.name = "capstype";
|
|
|
|
definition.mime = g_strdup (mime);
|
|
|
|
definition.exts = NULL;
|
|
|
|
definition.typefindfunc = NULL;
|
2000-12-11 00:04:25 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
factory = gst_type_factory_new (&definition);
|
2001-08-21 20:16:48 +00:00
|
|
|
typeid = gst_type_register (factory);
|
2003-08-07 12:45:31 +00:00
|
|
|
|
|
|
|
g_free (definition.mime);
|
2000-12-11 00:04:25 +00:00
|
|
|
}
|
|
|
|
return typeid;
|
|
|
|
}
|
|
|
|
|
2000-12-13 19:29:35 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_new:
|
2000-12-31 16:12:48 +00:00
|
|
|
* @name: the name of this capability
|
2000-12-13 19:29:35 +00:00
|
|
|
* @mime: the mime type to attach to the capability
|
2001-04-14 18:56:37 +00:00
|
|
|
* @props: the properties to add to this capability
|
2000-12-13 19:29:35 +00:00
|
|
|
*
|
2002-09-23 08:36:05 +00:00
|
|
|
* Create a new capability with the given mime type and properties.
|
2000-12-13 19:29:35 +00:00
|
|
|
*
|
|
|
|
* Returns: a new capability
|
|
|
|
*/
|
|
|
|
GstCaps*
|
2001-04-14 18:56:37 +00:00
|
|
|
gst_caps_new (const gchar *name, const gchar *mime, GstProps *props)
|
2000-12-13 19:29:35 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (mime != NULL, NULL);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2002-01-13 22:22:42 +00:00
|
|
|
return gst_caps_new_id (name, get_type_for_mime (mime), props);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_new_id:
|
|
|
|
* @name: the name of this capability
|
|
|
|
* @id: the id of the mime type
|
|
|
|
* @props: the properties to add to this capability
|
|
|
|
*
|
|
|
|
* Create a new capability with the given mime typeid and properties.
|
|
|
|
*
|
|
|
|
* Returns: a new capability
|
|
|
|
*/
|
|
|
|
GstCaps*
|
|
|
|
gst_caps_new_id (const gchar *name, const guint16 id, GstProps *props)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
2003-02-02 19:58:11 +00:00
|
|
|
caps = gst_mem_chunk_alloc (_gst_caps_chunk);
|
2003-02-10 20:32:32 +00:00
|
|
|
#ifndef GST_DISABLE_TRACE
|
2003-02-02 19:58:11 +00:00
|
|
|
gst_alloc_trace_new (_gst_caps_trace, caps);
|
2003-02-10 20:32:32 +00:00
|
|
|
#endif
|
2003-02-02 19:58:11 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_CAPS, "new %p, props %p", caps, props);
|
2003-02-02 19:58:11 +00:00
|
|
|
|
|
|
|
gst_props_ref (props);
|
|
|
|
gst_props_sink (props);
|
2001-03-20 18:29:00 +00:00
|
|
|
|
2000-12-31 16:12:48 +00:00
|
|
|
caps->name = g_strdup (name);
|
2002-01-13 22:22:42 +00:00
|
|
|
caps->id = id;
|
2001-04-14 18:56:37 +00:00
|
|
|
caps->properties = props;
|
2001-03-12 21:02:12 +00:00
|
|
|
caps->next = NULL;
|
2001-03-20 18:29:00 +00:00
|
|
|
caps->refcount = 1;
|
2003-02-02 19:58:11 +00:00
|
|
|
GST_CAPS_FLAG_SET (caps, GST_CAPS_FLOATING);
|
|
|
|
|
2000-12-13 19:29:35 +00:00
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2003-08-19 04:08:29 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_get_any:
|
|
|
|
*
|
|
|
|
* Return a copy of the caps that represents any capability.
|
|
|
|
*
|
|
|
|
* Returns: the ANY capability
|
|
|
|
*/
|
|
|
|
GstCaps*
|
|
|
|
gst_caps_get_any (void)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
static GstCaps *caps;
|
|
|
|
|
|
|
|
if (!caps){
|
|
|
|
caps = GST_CAPS_NEW ("gst_caps_any", "*", NULL);
|
|
|
|
gst_caps_ref(caps);
|
|
|
|
gst_caps_sink(caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gst_caps_ref(caps);
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-02-02 19:58:11 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_replace:
|
|
|
|
* @oldcaps: the caps to take replace
|
|
|
|
* @newcaps: the caps to take replace
|
|
|
|
*
|
|
|
|
* Replace the pointer to the caps, doing proper
|
|
|
|
* refcounting.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_caps_replace (GstCaps **oldcaps, GstCaps *newcaps)
|
|
|
|
{
|
|
|
|
if (*oldcaps != newcaps) {
|
|
|
|
if (newcaps) gst_caps_ref (newcaps);
|
|
|
|
if (*oldcaps) gst_caps_unref (*oldcaps);
|
|
|
|
|
|
|
|
*oldcaps = newcaps;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_replace_sink:
|
|
|
|
* @oldcaps: the caps to take replace
|
|
|
|
* @newcaps: the caps to take replace
|
|
|
|
*
|
|
|
|
* Replace the pointer to the caps and take ownership.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_caps_replace_sink (GstCaps **oldcaps, GstCaps *newcaps)
|
|
|
|
{
|
|
|
|
gst_caps_replace (oldcaps, newcaps);
|
|
|
|
gst_caps_sink (newcaps);
|
|
|
|
}
|
|
|
|
|
2001-03-20 18:29:00 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_destroy:
|
|
|
|
* @caps: the caps to destroy
|
|
|
|
*
|
|
|
|
* Frees the memory used by this caps structure and all
|
|
|
|
* the chained caps and properties.
|
|
|
|
*/
|
2003-05-18 02:42:19 +00:00
|
|
|
static void
|
2001-03-20 18:29:00 +00:00
|
|
|
gst_caps_destroy (GstCaps *caps)
|
|
|
|
{
|
2001-03-24 17:22:03 +00:00
|
|
|
GstCaps *next;
|
2001-03-20 18:29:00 +00:00
|
|
|
|
2002-01-13 22:22:42 +00:00
|
|
|
if (caps == NULL)
|
|
|
|
return;
|
2002-08-02 11:40:27 +00:00
|
|
|
|
2001-03-24 17:22:03 +00:00
|
|
|
next = caps->next;
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_CAPS, "destroy %p", caps);
|
2003-02-02 19:58:11 +00:00
|
|
|
|
2002-01-13 22:22:42 +00:00
|
|
|
gst_props_unref (caps->properties);
|
|
|
|
g_free (caps->name);
|
2003-02-02 19:58:11 +00:00
|
|
|
|
2003-08-19 04:10:29 +00:00
|
|
|
#ifdef USE_POISONING
|
|
|
|
memset(caps, 0xff, sizeof(*caps));
|
|
|
|
#endif
|
|
|
|
|
2003-02-10 20:32:32 +00:00
|
|
|
#ifndef GST_DISABLE_TRACE
|
2003-02-02 19:58:11 +00:00
|
|
|
gst_alloc_trace_free (_gst_caps_trace, caps);
|
2003-02-10 20:32:32 +00:00
|
|
|
#endif
|
2003-02-02 19:58:11 +00:00
|
|
|
gst_mem_chunk_free (_gst_caps_chunk, caps);
|
2002-01-13 22:22:42 +00:00
|
|
|
|
2001-03-24 17:22:03 +00:00
|
|
|
if (next)
|
|
|
|
gst_caps_unref (next);
|
2001-03-20 18:29:00 +00:00
|
|
|
}
|
|
|
|
|
2002-03-03 00:44:41 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_debug:
|
|
|
|
* @caps: the caps to print out
|
|
|
|
* @label: a label to put on the printout, or NULL
|
|
|
|
*
|
|
|
|
* Print out the contents of the caps structure. Useful for debugging.
|
|
|
|
*/
|
2002-01-13 22:22:42 +00:00
|
|
|
void
|
2002-03-03 00:44:41 +00:00
|
|
|
gst_caps_debug (GstCaps *caps, const gchar *label)
|
2002-01-13 22:22:42 +00:00
|
|
|
{
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "starting caps debug: %s", label);
|
|
|
|
if (caps && caps->refcount == 0) {
|
|
|
|
g_warning ("Warning: refcount of caps %s is 0", label);
|
|
|
|
return;
|
|
|
|
}
|
2003-06-13 21:26:33 +00:00
|
|
|
|
2002-01-13 22:22:42 +00:00
|
|
|
while (caps) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "caps: %p %s %s (%sfixed) (refcount %d) %s",
|
2003-02-02 19:58:11 +00:00
|
|
|
caps, caps->name, gst_caps_get_mime (caps),
|
|
|
|
GST_CAPS_IS_FIXED (caps) ? "" : "NOT ", caps->refcount,
|
|
|
|
GST_CAPS_IS_FLOATING (caps) ? "FLOATING" : "");
|
2002-01-13 22:22:42 +00:00
|
|
|
|
|
|
|
if (caps->properties) {
|
|
|
|
gst_props_debug (caps->properties);
|
|
|
|
}
|
|
|
|
else {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "no properties");
|
2002-01-13 22:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
caps = caps->next;
|
|
|
|
}
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "finished caps debug");
|
2002-01-13 22:22:42 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 18:29:00 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_unref:
|
|
|
|
* @caps: the caps to unref
|
|
|
|
*
|
|
|
|
* Decrease the refcount of this caps structure,
|
|
|
|
* destroying it when the refcount is 0
|
2001-04-16 21:45:02 +00:00
|
|
|
*
|
2001-04-17 21:14:55 +00:00
|
|
|
* Returns: caps or NULL if the refcount reached 0
|
2001-03-20 18:29:00 +00:00
|
|
|
*/
|
2001-04-16 21:45:02 +00:00
|
|
|
GstCaps*
|
2001-03-20 18:29:00 +00:00
|
|
|
gst_caps_unref (GstCaps *caps)
|
|
|
|
{
|
2001-03-24 17:22:03 +00:00
|
|
|
gboolean zero;
|
|
|
|
|
2002-01-13 22:22:42 +00:00
|
|
|
if (caps == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2001-04-16 21:45:02 +00:00
|
|
|
g_return_val_if_fail (caps->refcount > 0, NULL);
|
2001-03-20 18:29:00 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_CAPS, "unref %p (%d->%d) %d",
|
2003-02-02 19:58:11 +00:00
|
|
|
caps, caps->refcount, caps->refcount-1, GST_CAPS_FLAGS (caps));
|
|
|
|
|
2001-03-20 18:29:00 +00:00
|
|
|
caps->refcount--;
|
2001-03-24 17:22:03 +00:00
|
|
|
zero = (caps->refcount == 0);
|
2001-03-20 18:29:00 +00:00
|
|
|
|
2001-04-16 21:45:02 +00:00
|
|
|
if (zero) {
|
2001-03-20 18:29:00 +00:00
|
|
|
gst_caps_destroy (caps);
|
2001-04-16 21:45:02 +00:00
|
|
|
caps = NULL;
|
|
|
|
}
|
|
|
|
return caps;
|
2001-03-20 18:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_ref:
|
|
|
|
* @caps: the caps to ref
|
|
|
|
*
|
|
|
|
* Increase the refcount of this caps structure
|
2001-04-16 21:45:02 +00:00
|
|
|
*
|
2001-04-17 21:14:55 +00:00
|
|
|
* Returns: the caps with the refcount incremented
|
2001-03-20 18:29:00 +00:00
|
|
|
*/
|
2001-04-16 21:45:02 +00:00
|
|
|
GstCaps*
|
2001-03-20 18:29:00 +00:00
|
|
|
gst_caps_ref (GstCaps *caps)
|
|
|
|
{
|
2003-02-02 19:58:11 +00:00
|
|
|
if (caps == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (caps->refcount > 0, NULL);
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_CAPS, "ref %p (%d->%d) %d",
|
2003-02-02 19:58:11 +00:00
|
|
|
caps, caps->refcount, caps->refcount+1, GST_CAPS_FLAGS (caps));
|
2001-03-20 18:29:00 +00:00
|
|
|
|
|
|
|
caps->refcount++;
|
2001-04-16 21:45:02 +00:00
|
|
|
|
|
|
|
return caps;
|
2001-03-20 18:29:00 +00:00
|
|
|
}
|
|
|
|
|
2003-02-02 19:58:11 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_sink:
|
|
|
|
* @caps: the caps to take ownership of
|
|
|
|
*
|
|
|
|
* Take ownership of a GstCaps
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_caps_sink (GstCaps *caps)
|
|
|
|
{
|
|
|
|
if (caps == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (GST_CAPS_IS_FLOATING (caps)) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_LOG (GST_CAT_CAPS, "sink %p", caps);
|
2003-02-02 19:58:11 +00:00
|
|
|
|
|
|
|
GST_CAPS_FLAG_UNSET (caps, GST_CAPS_FLOATING);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-20 11:55:35 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_copy_1:
|
|
|
|
* @caps: the caps to copy
|
|
|
|
*
|
|
|
|
* Copies the caps, not copying any chained caps.
|
|
|
|
*
|
2003-02-02 19:58:11 +00:00
|
|
|
* Returns: a floating copy of the GstCaps structure.
|
2002-01-20 11:55:35 +00:00
|
|
|
*/
|
|
|
|
GstCaps*
|
|
|
|
gst_caps_copy_1 (GstCaps *caps)
|
|
|
|
{
|
|
|
|
GstCaps *newcaps;
|
|
|
|
|
|
|
|
if (!caps)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
newcaps = gst_caps_new_id (
|
|
|
|
caps->name,
|
|
|
|
caps->id,
|
|
|
|
gst_props_copy (caps->properties));
|
|
|
|
|
|
|
|
return newcaps;
|
|
|
|
}
|
|
|
|
|
2001-03-20 18:29:00 +00:00
|
|
|
/**
|
2001-03-21 21:43:56 +00:00
|
|
|
* gst_caps_copy:
|
2001-03-20 18:29:00 +00:00
|
|
|
* @caps: the caps to copy
|
|
|
|
*
|
2001-03-21 21:43:56 +00:00
|
|
|
* Copies the caps.
|
|
|
|
*
|
2003-02-02 19:58:11 +00:00
|
|
|
* Returns: a floating copy of the GstCaps structure.
|
2001-03-20 18:29:00 +00:00
|
|
|
*/
|
|
|
|
GstCaps*
|
|
|
|
gst_caps_copy (GstCaps *caps)
|
|
|
|
{
|
2002-01-13 22:22:42 +00:00
|
|
|
GstCaps *new = NULL, *walk = NULL;
|
2000-12-03 17:51:29 +00:00
|
|
|
|
2002-01-13 22:22:42 +00:00
|
|
|
while (caps) {
|
|
|
|
GstCaps *newcaps;
|
2000-12-03 17:51:29 +00:00
|
|
|
|
2002-01-20 11:55:35 +00:00
|
|
|
newcaps = gst_caps_copy_1 (caps);
|
2002-01-13 22:22:42 +00:00
|
|
|
|
|
|
|
if (new == NULL) {
|
|
|
|
new = walk = newcaps;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
walk = walk->next = newcaps;
|
|
|
|
}
|
|
|
|
caps = caps->next;
|
|
|
|
}
|
2000-12-31 16:12:48 +00:00
|
|
|
|
2001-03-20 18:29:00 +00:00
|
|
|
return new;
|
|
|
|
}
|
2000-12-03 17:51:29 +00:00
|
|
|
|
2001-03-20 18:29:00 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_copy_on_write:
|
|
|
|
* @caps: the caps to copy
|
|
|
|
*
|
|
|
|
* Copies the caps if the refcount is greater than 1
|
2001-03-21 21:43:56 +00:00
|
|
|
*
|
|
|
|
* Returns: a pointer to a GstCaps strcuture that can
|
2003-02-02 19:58:11 +00:00
|
|
|
* be safely written to.
|
2001-03-20 18:29:00 +00:00
|
|
|
*/
|
|
|
|
GstCaps*
|
|
|
|
gst_caps_copy_on_write (GstCaps *caps)
|
|
|
|
{
|
2001-03-24 17:22:03 +00:00
|
|
|
GstCaps *new = caps;
|
|
|
|
gboolean needcopy;
|
2001-03-20 18:29:00 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (caps != NULL, NULL);
|
|
|
|
|
2001-03-24 17:22:03 +00:00
|
|
|
needcopy = (caps->refcount > 1);
|
|
|
|
|
|
|
|
if (needcopy) {
|
2001-03-20 18:29:00 +00:00
|
|
|
new = gst_caps_copy (caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
2000-12-03 17:51:29 +00:00
|
|
|
}
|
|
|
|
|
2001-01-06 02:35:17 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_get_name:
|
|
|
|
* @caps: the caps to get the name from
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Get the name of a GstCaps structure.
|
2001-01-06 02:35:17 +00:00
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Returns: the name of the caps
|
2001-01-06 02:35:17 +00:00
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
const gchar*
|
2001-01-06 02:35:17 +00:00
|
|
|
gst_caps_get_name (GstCaps *caps)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (caps != NULL, NULL);
|
|
|
|
|
|
|
|
return (const gchar *)caps->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_set_name:
|
2001-03-07 21:52:56 +00:00
|
|
|
* @caps: the caps to set the name to
|
2001-01-06 02:35:17 +00:00
|
|
|
* @name: the name to set
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Set the name of a caps.
|
2001-01-06 02:35:17 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_caps_set_name (GstCaps *caps, const gchar *name)
|
|
|
|
{
|
|
|
|
g_return_if_fail (caps != NULL);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2003-02-02 19:58:11 +00:00
|
|
|
g_free (caps->name);
|
2001-01-06 02:35:17 +00:00
|
|
|
caps->name = g_strdup (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_get_mime:
|
|
|
|
* @caps: the caps to get the mime type from
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Get the mime type of the caps as a string.
|
2001-01-06 02:35:17 +00:00
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Returns: the mime type of the caps
|
2001-01-06 02:35:17 +00:00
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
const gchar*
|
2001-01-06 02:35:17 +00:00
|
|
|
gst_caps_get_mime (GstCaps *caps)
|
|
|
|
{
|
|
|
|
GstType *type;
|
|
|
|
|
|
|
|
g_return_val_if_fail (caps != NULL, NULL);
|
|
|
|
|
|
|
|
type = gst_type_find_by_id (caps->id);
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
if (type)
|
2001-01-06 02:35:17 +00:00
|
|
|
return type->mime;
|
2001-03-07 21:52:56 +00:00
|
|
|
else
|
2001-01-06 02:35:17 +00:00
|
|
|
return "unknown/unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_set_mime:
|
|
|
|
* @caps: the caps to set the mime type to
|
|
|
|
* @mime: the mime type to attach to the caps
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Set the mime type of the caps as a string.
|
2001-01-06 02:35:17 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_caps_set_mime (GstCaps *caps, const gchar *mime)
|
|
|
|
{
|
|
|
|
g_return_if_fail (caps != NULL);
|
|
|
|
g_return_if_fail (mime != NULL);
|
|
|
|
|
|
|
|
caps->id = get_type_for_mime (mime);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_get_type_id:
|
|
|
|
* @caps: the caps to get the type id from
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Get the type id of the caps.
|
2001-01-06 02:35:17 +00:00
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Returns: the type id of the caps
|
2001-01-06 02:35:17 +00:00
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
guint16
|
2001-01-06 02:35:17 +00:00
|
|
|
gst_caps_get_type_id (GstCaps *caps)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (caps != NULL, 0);
|
|
|
|
|
|
|
|
return caps->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_set_type_id:
|
|
|
|
* @caps: the caps to set the type id to
|
2001-03-21 21:43:56 +00:00
|
|
|
* @type_id: the type id to set
|
2001-01-06 02:35:17 +00:00
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Set the type id of the caps.
|
2001-01-06 02:35:17 +00:00
|
|
|
*/
|
|
|
|
void
|
2001-03-07 21:52:56 +00:00
|
|
|
gst_caps_set_type_id (GstCaps *caps, guint16 type_id)
|
2001-01-06 02:35:17 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (caps != NULL);
|
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
caps->id = type_id;
|
2001-01-06 02:35:17 +00:00
|
|
|
}
|
|
|
|
|
2000-12-28 21:42:23 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_set_props:
|
|
|
|
* @caps: the caps to attach the properties to
|
|
|
|
* @props: the properties to attach
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Set the properties to the given caps.
|
2000-12-28 21:42:23 +00:00
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Returns: the new caps structure
|
2000-12-28 21:42:23 +00:00
|
|
|
*/
|
2000-12-19 16:36:10 +00:00
|
|
|
GstCaps*
|
|
|
|
gst_caps_set_props (GstCaps *caps, GstProps *props)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (caps != NULL, caps);
|
|
|
|
|
2003-02-02 19:58:11 +00:00
|
|
|
gst_props_replace_sink (&caps->properties, props);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2000-12-19 16:36:10 +00:00
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2000-12-28 21:42:23 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_get_props:
|
|
|
|
* @caps: the caps to get the properties from
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Get the properties of the given caps.
|
2000-12-28 21:42:23 +00:00
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Returns: the properties of the caps
|
2000-12-28 21:42:23 +00:00
|
|
|
*/
|
2000-12-19 16:36:10 +00:00
|
|
|
GstProps*
|
|
|
|
gst_caps_get_props (GstCaps *caps)
|
|
|
|
{
|
2000-12-31 16:12:48 +00:00
|
|
|
g_return_val_if_fail (caps != NULL, NULL);
|
2000-12-19 16:36:10 +00:00
|
|
|
|
|
|
|
return caps->properties;
|
|
|
|
}
|
2000-12-03 17:51:29 +00:00
|
|
|
|
2003-07-29 12:00:38 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_has_property:
|
|
|
|
* @caps: the caps to query
|
|
|
|
* @name: the name of the property to search for
|
|
|
|
*
|
|
|
|
* Figure out whether this caps contains the requested property.
|
|
|
|
*
|
|
|
|
* Returns: true if the caps contains the property.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_caps_has_property (GstCaps *caps, const gchar *name)
|
|
|
|
{
|
|
|
|
GstProps *props = gst_caps_get_props (caps);
|
|
|
|
|
|
|
|
return (props != NULL &&
|
|
|
|
gst_props_has_property (props, name));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_has_property_typed:
|
|
|
|
* @caps: the caps to query
|
|
|
|
* @name: the name of the property to search for
|
|
|
|
* @type: the type of the property to search for
|
|
|
|
*
|
|
|
|
* Figure out whether this caps contains the requested property,
|
|
|
|
* and whether this property is of the requested type.
|
|
|
|
*
|
|
|
|
* Returns: true if the caps contains the typed property.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_caps_has_property_typed (GstCaps *caps, const gchar *name, GstPropsType type)
|
|
|
|
{
|
|
|
|
GstProps *props = gst_caps_get_props (caps);
|
|
|
|
|
|
|
|
return (props != NULL &&
|
|
|
|
gst_props_has_property_typed (props, name, type));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_has_fixed_property
|
|
|
|
* @caps: the caps to query
|
|
|
|
* @name: the name of the property to search for
|
|
|
|
*
|
|
|
|
* Figure out whether this caps contains the requested property,
|
|
|
|
* and whether this property is fixed.
|
|
|
|
*
|
|
|
|
* Returns: true if the caps contains the fixed property.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_caps_has_fixed_property (GstCaps *caps, const gchar *name)
|
|
|
|
{
|
|
|
|
GstProps *props = gst_caps_get_props (caps);
|
|
|
|
|
|
|
|
return (props != NULL &&
|
|
|
|
gst_props_has_fixed_property (props, name));
|
|
|
|
}
|
|
|
|
|
2003-02-02 19:58:11 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_next:
|
|
|
|
* @caps: the caps to query
|
|
|
|
*
|
|
|
|
* Get the next caps of this chained caps.
|
|
|
|
*
|
|
|
|
* Returns: the next caps or NULL if the chain ended.
|
|
|
|
*/
|
|
|
|
GstCaps*
|
|
|
|
gst_caps_next (GstCaps *caps)
|
|
|
|
{
|
|
|
|
if (caps == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return caps->next;
|
|
|
|
}
|
|
|
|
|
2001-04-16 21:45:02 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_chain:
|
|
|
|
* @caps: a capabilty
|
|
|
|
* @...: more capabilities
|
|
|
|
*
|
|
|
|
* chains the given capabilities
|
|
|
|
*
|
|
|
|
* Returns: the new capability
|
|
|
|
*/
|
|
|
|
GstCaps*
|
|
|
|
gst_caps_chain (GstCaps *caps, ...)
|
|
|
|
{
|
|
|
|
GstCaps *orig = caps;
|
|
|
|
va_list var_args;
|
|
|
|
|
|
|
|
va_start (var_args, caps);
|
|
|
|
|
|
|
|
while (caps) {
|
|
|
|
GstCaps *toadd;
|
|
|
|
|
|
|
|
toadd = va_arg (var_args, GstCaps*);
|
|
|
|
gst_caps_append (caps, toadd);
|
|
|
|
|
|
|
|
caps = toadd;
|
|
|
|
}
|
|
|
|
va_end (var_args);
|
|
|
|
|
|
|
|
return orig;
|
|
|
|
}
|
|
|
|
|
2000-12-03 17:51:29 +00:00
|
|
|
/**
|
2001-03-12 21:02:12 +00:00
|
|
|
* gst_caps_append:
|
|
|
|
* @caps: a capabilty
|
|
|
|
* @capstoadd: the capability to append
|
2000-12-03 17:51:29 +00:00
|
|
|
*
|
2001-03-12 21:02:12 +00:00
|
|
|
* Appends a capability to the existing capability.
|
2000-12-03 17:51:29 +00:00
|
|
|
*
|
2001-03-12 21:02:12 +00:00
|
|
|
* Returns: the new capability
|
2000-12-03 17:51:29 +00:00
|
|
|
*/
|
2001-03-12 21:02:12 +00:00
|
|
|
GstCaps*
|
|
|
|
gst_caps_append (GstCaps *caps, GstCaps *capstoadd)
|
2000-12-03 17:51:29 +00:00
|
|
|
{
|
2001-03-12 21:02:12 +00:00
|
|
|
GstCaps *orig = caps;
|
2001-03-29 22:32:00 +00:00
|
|
|
|
2002-02-17 21:19:13 +00:00
|
|
|
if (caps == NULL || caps == capstoadd)
|
2001-03-12 21:02:12 +00:00
|
|
|
return capstoadd;
|
|
|
|
|
|
|
|
while (caps->next) {
|
|
|
|
caps = caps->next;
|
|
|
|
}
|
2003-02-02 19:58:11 +00:00
|
|
|
gst_caps_replace_sink (&caps->next, capstoadd);
|
2001-03-12 21:02:12 +00:00
|
|
|
|
|
|
|
return orig;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_prepend:
|
|
|
|
* @caps: a capabilty
|
|
|
|
* @capstoadd: a capabilty to prepend
|
|
|
|
*
|
|
|
|
* prepend the capability to the list of capabilities
|
|
|
|
*
|
|
|
|
* Returns: the new capability
|
|
|
|
*/
|
|
|
|
GstCaps*
|
|
|
|
gst_caps_prepend (GstCaps *caps, GstCaps *capstoadd)
|
|
|
|
{
|
|
|
|
GstCaps *orig = capstoadd;
|
|
|
|
|
|
|
|
if (capstoadd == NULL)
|
|
|
|
return caps;
|
|
|
|
|
2002-01-13 22:22:42 +00:00
|
|
|
g_return_val_if_fail (caps != capstoadd, caps);
|
|
|
|
|
2001-03-12 21:02:12 +00:00
|
|
|
while (capstoadd->next) {
|
|
|
|
capstoadd = capstoadd->next;
|
|
|
|
}
|
2003-02-02 19:58:11 +00:00
|
|
|
gst_caps_replace_sink (&capstoadd->next, caps);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2001-03-12 21:02:12 +00:00
|
|
|
return orig;
|
|
|
|
}
|
|
|
|
|
2001-03-21 21:43:56 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_get_by_name:
|
|
|
|
* @caps: a capabilty
|
|
|
|
* @name: the name of the capability to get
|
|
|
|
*
|
|
|
|
* Get the capability with the given name from this
|
|
|
|
* chain of capabilities.
|
|
|
|
*
|
|
|
|
* Returns: the first capability in the chain with the
|
|
|
|
* given name
|
|
|
|
*/
|
2001-03-12 21:02:12 +00:00
|
|
|
GstCaps*
|
|
|
|
gst_caps_get_by_name (GstCaps *caps, const gchar *name)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (caps != NULL, NULL);
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
|
|
|
while (caps) {
|
|
|
|
if (!strcmp (caps->name, name))
|
|
|
|
return caps;
|
|
|
|
caps = caps->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_caps_check_compatibility_func (GstCaps *fromcaps, GstCaps *tocaps)
|
|
|
|
{
|
2000-12-19 13:41:55 +00:00
|
|
|
if (fromcaps->id != tocaps->id) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS,"mime types differ (%s to %s)",
|
2001-04-02 14:21:08 +00:00
|
|
|
gst_type_find_by_id (fromcaps->id)->mime,
|
|
|
|
gst_type_find_by_id (tocaps->id)->mime);
|
2000-12-03 17:51:29 +00:00
|
|
|
return FALSE;
|
2000-12-19 13:41:55 +00:00
|
|
|
}
|
2000-12-03 17:51:29 +00:00
|
|
|
|
2000-12-17 16:24:14 +00:00
|
|
|
if (tocaps->properties) {
|
|
|
|
if (fromcaps->properties) {
|
|
|
|
return gst_props_check_compatibility (fromcaps->properties, tocaps->properties);
|
|
|
|
}
|
|
|
|
else {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS,"no source caps");
|
2000-12-17 16:24:14 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2001-12-14 22:59:21 +00:00
|
|
|
/* assume it accepts everything */
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS,"no caps");
|
2000-12-17 16:24:14 +00:00
|
|
|
return TRUE;
|
2000-12-15 16:43:26 +00:00
|
|
|
}
|
2000-12-03 17:51:29 +00:00
|
|
|
}
|
|
|
|
|
2000-12-31 16:12:48 +00:00
|
|
|
/**
|
2002-10-02 07:51:54 +00:00
|
|
|
* gst_caps_is_always_compatible:
|
|
|
|
* @fromcaps: a #GstCaps capability to check compatibility of.
|
2003-01-09 22:59:37 +00:00
|
|
|
* @tocaps: the #GstCaps capability to check compatibility with.
|
2000-12-31 16:12:48 +00:00
|
|
|
*
|
2003-01-09 22:59:37 +00:00
|
|
|
* Checks if a link is always possible from fromcaps to tocaps, for all
|
2002-10-02 07:51:54 +00:00
|
|
|
* possible capabilities.
|
2000-12-31 16:12:48 +00:00
|
|
|
*
|
2002-10-02 07:51:54 +00:00
|
|
|
* Returns: TRUE if compatible under all circumstances, FALSE otherwise.
|
2000-12-31 16:12:48 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2002-10-02 07:51:54 +00:00
|
|
|
gst_caps_is_always_compatible (GstCaps *fromcaps, GstCaps *tocaps)
|
2000-12-31 16:12:48 +00:00
|
|
|
{
|
2001-03-18 02:42:30 +00:00
|
|
|
if (fromcaps == NULL) {
|
|
|
|
if (tocaps == NULL) {
|
2003-01-09 22:59:37 +00:00
|
|
|
/* if both are NULL, they can always link. Think filesrc ! filesink */
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "both caps NULL, compatible");
|
2001-03-18 02:42:30 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else {
|
2002-10-02 07:51:54 +00:00
|
|
|
/* if source caps are NULL, it could be sending anything, so the
|
|
|
|
* destination can't know if it can accept this. Think filesrc ! mad */
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "source caps NULL, not guaranteed compatible");
|
2001-03-18 02:42:30 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (tocaps == NULL) {
|
2002-10-02 07:51:54 +00:00
|
|
|
/* if the dest caps are NULL, the element can accept anything, always,
|
|
|
|
* so they're compatible by definition. Think mad ! filesink */
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS,"destination caps NULL");
|
2001-03-18 02:42:30 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2001-03-13 20:26:23 +00:00
|
|
|
}
|
|
|
|
|
2000-12-31 16:12:48 +00:00
|
|
|
while (fromcaps) {
|
2001-03-12 21:02:12 +00:00
|
|
|
GstCaps *destcaps = tocaps;
|
2003-05-08 19:57:06 +00:00
|
|
|
/* assume caps is incompatible */
|
|
|
|
gboolean compat = FALSE;
|
2000-12-31 16:12:48 +00:00
|
|
|
|
2003-05-08 19:57:06 +00:00
|
|
|
while (destcaps && !compat) {
|
|
|
|
if (gst_caps_check_compatibility_func (fromcaps, destcaps)) {
|
|
|
|
compat = TRUE;
|
|
|
|
}
|
2001-03-12 21:02:12 +00:00
|
|
|
destcaps = destcaps->next;
|
2000-12-31 16:12:48 +00:00
|
|
|
}
|
2003-05-08 19:57:06 +00:00
|
|
|
if (!compat)
|
|
|
|
return FALSE;
|
|
|
|
|
2001-03-12 21:02:12 +00:00
|
|
|
fromcaps = fromcaps->next;
|
2000-12-31 16:12:48 +00:00
|
|
|
}
|
2003-05-08 19:57:06 +00:00
|
|
|
return TRUE;
|
2000-12-31 16:12:48 +00:00
|
|
|
}
|
2000-12-11 00:04:25 +00:00
|
|
|
|
2002-01-13 22:22:42 +00:00
|
|
|
static GstCaps*
|
|
|
|
gst_caps_intersect_func (GstCaps *caps1, GstCaps *caps2)
|
|
|
|
{
|
|
|
|
GstCaps *result = NULL;
|
|
|
|
GstProps *props;
|
|
|
|
|
|
|
|
if (caps1->id != caps2->id) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "mime types differ (%s to %s)",
|
2002-01-13 22:22:42 +00:00
|
|
|
gst_type_find_by_id (caps1->id)->mime,
|
|
|
|
gst_type_find_by_id (caps2->id)->mime);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (caps1->properties == NULL) {
|
|
|
|
return gst_caps_ref (caps2);
|
|
|
|
}
|
|
|
|
if (caps2->properties == NULL) {
|
|
|
|
return gst_caps_ref (caps1);
|
|
|
|
}
|
|
|
|
|
|
|
|
props = gst_props_intersect (caps1->properties, caps2->properties);
|
|
|
|
if (props) {
|
|
|
|
result = gst_caps_new_id ("intersect", caps1->id, props);
|
2003-02-02 19:58:11 +00:00
|
|
|
gst_caps_ref (result);
|
|
|
|
gst_caps_sink (result);
|
2002-01-13 22:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_intersect:
|
2002-10-01 11:42:32 +00:00
|
|
|
* @caps1: a capability
|
|
|
|
* @caps2: a capability
|
2002-01-13 22:22:42 +00:00
|
|
|
*
|
|
|
|
* Make the intersection between two caps.
|
|
|
|
*
|
|
|
|
* Returns: The intersection of the two caps or NULL if the intersection
|
2003-02-02 19:58:11 +00:00
|
|
|
* is empty. unref the caps after use.
|
2002-01-13 22:22:42 +00:00
|
|
|
*/
|
|
|
|
GstCaps*
|
|
|
|
gst_caps_intersect (GstCaps *caps1, GstCaps *caps2)
|
|
|
|
{
|
|
|
|
GstCaps *result = NULL, *walk = NULL;
|
|
|
|
|
2002-10-01 11:42:32 +00:00
|
|
|
/* printing the name is not useful here since caps can be chained */
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "intersecting caps %p and %p", caps1, caps2);
|
2002-10-01 11:42:32 +00:00
|
|
|
|
2002-01-13 22:22:42 +00:00
|
|
|
if (caps1 == NULL) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "first caps is NULL, return other caps");
|
2003-02-02 19:58:11 +00:00
|
|
|
return gst_caps_ref (caps2);
|
2002-01-13 22:22:42 +00:00
|
|
|
}
|
|
|
|
if (caps2 == NULL) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "second caps is NULL, return other caps");
|
2003-02-02 19:58:11 +00:00
|
|
|
return gst_caps_ref (caps1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* same caps */
|
|
|
|
if (caps1 == caps2) {
|
|
|
|
return gst_caps_ref (caps1);
|
2002-01-13 22:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (caps1) {
|
|
|
|
GstCaps *othercaps = caps2;
|
|
|
|
|
|
|
|
while (othercaps) {
|
2002-02-02 13:32:32 +00:00
|
|
|
GstCaps *intersection;
|
|
|
|
|
|
|
|
intersection = gst_caps_intersect_func (caps1, othercaps);
|
2002-01-13 22:22:42 +00:00
|
|
|
|
|
|
|
if (intersection) {
|
|
|
|
if (!result) {
|
|
|
|
walk = result = intersection;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
walk = walk->next = intersection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
othercaps = othercaps->next;
|
|
|
|
}
|
2003-02-02 19:58:11 +00:00
|
|
|
caps1 = caps1->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstCaps*
|
|
|
|
gst_caps_union (GstCaps *caps1, GstCaps *caps2)
|
|
|
|
{
|
|
|
|
GstCaps *result = NULL;
|
|
|
|
|
|
|
|
/* printing the name is not useful here since caps can be chained */
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "making union of caps %p and %p", caps1, caps2);
|
2003-02-02 19:58:11 +00:00
|
|
|
|
|
|
|
if (caps1 == NULL) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "first caps is NULL, return other caps");
|
2003-02-02 19:58:11 +00:00
|
|
|
return gst_caps_ref (caps2);
|
|
|
|
}
|
|
|
|
if (caps2 == NULL) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "second caps is NULL, return other caps");
|
2003-02-02 19:58:11 +00:00
|
|
|
return gst_caps_ref (caps1);
|
2002-01-13 22:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-03-31 14:04:50 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_normalize:
|
|
|
|
* @caps: a capabilty
|
|
|
|
*
|
|
|
|
* Make the normalisation of the caps. This will return a new caps
|
|
|
|
* that is equivalent to the input caps with the exception that all
|
|
|
|
* lists are unrolled. This function is useful when you want to iterate
|
2003-02-02 19:58:11 +00:00
|
|
|
* the caps. unref the caps after use.
|
2002-03-31 14:04:50 +00:00
|
|
|
*
|
2003-02-02 19:58:11 +00:00
|
|
|
* Returns: The normalisation of the caps. Unref after usage.
|
2002-03-31 14:04:50 +00:00
|
|
|
*/
|
2002-01-13 22:22:42 +00:00
|
|
|
GstCaps*
|
|
|
|
gst_caps_normalize (GstCaps *caps)
|
|
|
|
{
|
2003-02-02 19:58:11 +00:00
|
|
|
GstCaps *result = NULL, *walk;
|
2002-01-13 22:22:42 +00:00
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
return caps;
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_CAT_DEBUG (GST_CAT_CAPS, "normalizing caps %p ", caps);
|
2003-02-02 19:58:11 +00:00
|
|
|
|
|
|
|
walk = caps;
|
|
|
|
|
2002-01-13 22:22:42 +00:00
|
|
|
while (caps) {
|
|
|
|
GList *proplist;
|
|
|
|
|
|
|
|
proplist = gst_props_normalize (caps->properties);
|
|
|
|
while (proplist) {
|
|
|
|
GstProps *props = (GstProps *) proplist->data;
|
|
|
|
GstCaps *newcaps = gst_caps_new_id (caps->name, caps->id, props);
|
|
|
|
|
2003-02-02 19:58:11 +00:00
|
|
|
gst_caps_ref (newcaps);
|
|
|
|
gst_caps_sink (newcaps);
|
|
|
|
|
2002-01-13 22:22:42 +00:00
|
|
|
if (result == NULL)
|
|
|
|
walk = result = newcaps;
|
|
|
|
else {
|
2003-02-02 19:58:11 +00:00
|
|
|
walk = walk->next = newcaps;
|
2002-01-13 22:22:42 +00:00
|
|
|
}
|
|
|
|
proplist = g_list_next (proplist);
|
|
|
|
}
|
|
|
|
caps = caps->next;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-10-17 10:21:27 +00:00
|
|
|
#ifndef GST_DISABLE_LOADSAVE_REGISTRY
|
2000-12-28 21:42:23 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_save_thyself:
|
|
|
|
* @caps: a capabilty to save
|
|
|
|
* @parent: the parent XML node pointer
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Save the capability into an XML representation.
|
2000-12-28 21:42:23 +00:00
|
|
|
*
|
|
|
|
* Returns: a new XML node pointer
|
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
xmlNodePtr
|
2000-12-11 00:04:25 +00:00
|
|
|
gst_caps_save_thyself (GstCaps *caps, xmlNodePtr parent)
|
|
|
|
{
|
|
|
|
xmlNodePtr subtree;
|
2001-03-12 21:02:12 +00:00
|
|
|
xmlNodePtr subsubtree;
|
2000-12-11 00:04:25 +00:00
|
|
|
|
2001-03-12 21:02:12 +00:00
|
|
|
while (caps) {
|
|
|
|
subtree = xmlNewChild (parent, NULL, "capscomp", NULL);
|
2000-12-11 00:04:25 +00:00
|
|
|
|
2001-03-12 21:02:12 +00:00
|
|
|
xmlNewChild (subtree, NULL, "name", caps->name);
|
|
|
|
xmlNewChild (subtree, NULL, "type", gst_type_find_by_id (caps->id)->mime);
|
|
|
|
if (caps->properties) {
|
|
|
|
subsubtree = xmlNewChild (subtree, NULL, "properties", NULL);
|
2000-12-11 00:04:25 +00:00
|
|
|
|
2001-03-12 21:02:12 +00:00
|
|
|
gst_props_save_thyself (caps->properties, subsubtree);
|
|
|
|
}
|
|
|
|
|
|
|
|
caps = caps->next;
|
2000-12-11 00:04:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2000-12-28 21:42:23 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_load_thyself:
|
|
|
|
* @parent: the parent XML node pointer
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Load a new caps from the XML representation.
|
2000-12-28 21:42:23 +00:00
|
|
|
*
|
|
|
|
* Returns: a new capability
|
|
|
|
*/
|
2001-03-07 21:52:56 +00:00
|
|
|
GstCaps*
|
2000-12-11 00:04:25 +00:00
|
|
|
gst_caps_load_thyself (xmlNodePtr parent)
|
|
|
|
{
|
2001-03-12 21:02:12 +00:00
|
|
|
GstCaps *result = NULL;
|
2001-01-18 11:16:53 +00:00
|
|
|
xmlNodePtr field = parent->xmlChildrenNode;
|
2000-12-11 00:04:25 +00:00
|
|
|
|
|
|
|
while (field) {
|
2001-03-12 21:02:12 +00:00
|
|
|
if (!strcmp (field->name, "capscomp")) {
|
|
|
|
xmlNodePtr subfield = field->xmlChildrenNode;
|
2001-03-20 18:29:00 +00:00
|
|
|
GstCaps *caps;
|
2001-03-12 21:02:12 +00:00
|
|
|
gchar *content;
|
2001-03-20 18:29:00 +00:00
|
|
|
|
2003-02-02 19:58:11 +00:00
|
|
|
caps = gst_mem_chunk_alloc0 (_gst_caps_chunk);
|
2003-02-10 20:32:32 +00:00
|
|
|
#ifndef GST_DISABLE_TRACE
|
2003-02-02 19:58:11 +00:00
|
|
|
gst_alloc_trace_new (_gst_caps_trace, caps);
|
2003-02-10 20:32:32 +00:00
|
|
|
#endif
|
2001-03-20 18:29:00 +00:00
|
|
|
|
|
|
|
caps->refcount = 1;
|
2003-02-02 19:58:11 +00:00
|
|
|
GST_CAPS_FLAG_SET (caps, GST_CAPS_FLOATING);
|
2001-03-29 22:32:00 +00:00
|
|
|
caps->next = NULL;
|
2001-03-12 21:02:12 +00:00
|
|
|
|
|
|
|
while (subfield) {
|
|
|
|
if (!strcmp (subfield->name, "name")) {
|
|
|
|
caps->name = xmlNodeGetContent (subfield);
|
|
|
|
}
|
|
|
|
if (!strcmp (subfield->name, "type")) {
|
|
|
|
content = xmlNodeGetContent (subfield);
|
|
|
|
caps->id = get_type_for_mime (content);
|
|
|
|
g_free (content);
|
|
|
|
}
|
|
|
|
else if (!strcmp (subfield->name, "properties")) {
|
2003-02-02 19:58:11 +00:00
|
|
|
GstProps *props = gst_props_load_thyself (subfield);
|
|
|
|
|
|
|
|
gst_props_ref (props);
|
|
|
|
gst_props_sink (props);
|
|
|
|
caps->properties = props;
|
2001-03-12 21:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
subfield = subfield->next;
|
|
|
|
}
|
2002-12-18 23:00:34 +00:00
|
|
|
|
2001-03-12 21:02:12 +00:00
|
|
|
result = gst_caps_append (result, caps);
|
2000-12-11 00:04:25 +00:00
|
|
|
}
|
|
|
|
field = field->next;
|
|
|
|
}
|
|
|
|
|
2001-03-12 21:02:12 +00:00
|
|
|
return result;
|
2000-12-11 00:04:25 +00:00
|
|
|
}
|
2001-09-10 19:46:01 +00:00
|
|
|
|
2001-10-17 10:21:27 +00:00
|
|
|
#endif /* GST_DISABLE_LOADSAVE_REGISTRY */
|