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-31 16:12:48 +00:00
|
|
|
//#define GST_DEBUG_ENABLED
|
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"
|
2000-12-03 20:15:15 +00:00
|
|
|
|
2000-12-17 16:24:14 +00:00
|
|
|
#include "gstpropsprivate.h"
|
2000-12-28 22:12:02 +00:00
|
|
|
|
2001-03-20 18:29:00 +00:00
|
|
|
static GMemChunk *_gst_caps_chunk;
|
|
|
|
static GMutex *_gst_caps_chunk_lock;
|
2000-12-28 22:12:02 +00:00
|
|
|
|
2001-03-07 21:52:56 +00:00
|
|
|
void
|
|
|
|
_gst_caps_initialize (void)
|
2000-12-03 17:51:29 +00:00
|
|
|
{
|
2001-03-20 18:29:00 +00:00
|
|
|
_gst_caps_chunk = g_mem_chunk_new ("GstCaps",
|
|
|
|
sizeof (GstCaps), sizeof (GstCaps) * 256,
|
|
|
|
G_ALLOC_AND_FREE);
|
|
|
|
_gst_caps_chunk_lock = g_mutex_new ();
|
2000-12-03 17:51:29 +00:00
|
|
|
}
|
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-01-07 07:45:54 +00:00
|
|
|
GstTypeFactory factory; // = g_new0 (GstTypeFactory, 1);
|
2000-12-11 00:04:25 +00:00
|
|
|
|
2001-01-07 07:45:54 +00:00
|
|
|
factory.mime = g_strdup (mime);
|
|
|
|
factory.exts = NULL;
|
|
|
|
factory.typefindfunc = NULL;
|
2000-12-11 00:04:25 +00:00
|
|
|
|
2001-01-07 07:45:54 +00:00
|
|
|
typeid = gst_type_register (&factory);
|
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-01-06 22:05:15 +00:00
|
|
|
* Create a new capability with the given mime type.
|
2000-12-13 19:29:35 +00:00
|
|
|
*
|
|
|
|
* Returns: a new capability
|
|
|
|
*/
|
|
|
|
GstCaps*
|
2001-01-06 02:35:17 +00:00
|
|
|
gst_caps_new (const gchar *name, const gchar *mime)
|
2000-12-13 19:29:35 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
g_return_val_if_fail (mime != NULL, NULL);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2001-03-20 18:29:00 +00:00
|
|
|
g_mutex_lock (_gst_caps_chunk_lock);
|
|
|
|
caps = g_mem_chunk_alloc (_gst_caps_chunk);
|
|
|
|
g_mutex_unlock (_gst_caps_chunk_lock);
|
|
|
|
|
2000-12-31 16:12:48 +00:00
|
|
|
caps->name = g_strdup (name);
|
2000-12-13 19:29:35 +00:00
|
|
|
caps->id = get_type_for_mime (mime);
|
2000-12-17 16:24:14 +00:00
|
|
|
caps->properties = NULL;
|
2001-03-12 21:02:12 +00:00
|
|
|
caps->next = NULL;
|
2001-03-20 18:29:00 +00:00
|
|
|
caps->refcount = 1;
|
2001-03-24 17:22:03 +00:00
|
|
|
caps->lock = g_mutex_new ();
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2000-12-13 19:29:35 +00:00
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2000-12-28 21:42:23 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_new_with_props:
|
2000-12-31 16:12:48 +00:00
|
|
|
* @name: the name of this capability
|
2000-12-28 21:42:23 +00:00
|
|
|
* @mime: the mime type to attach to the capability
|
|
|
|
* @props: the properties for this capability
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Create a new capability with the given mime type and the given properties.
|
2000-12-28 21:42:23 +00:00
|
|
|
*
|
|
|
|
* Returns: a new capability
|
|
|
|
*/
|
2000-12-19 16:36:10 +00:00
|
|
|
GstCaps*
|
2001-01-06 02:35:17 +00:00
|
|
|
gst_caps_new_with_props (const gchar *name, const gchar *mime, GstProps *props)
|
2000-12-19 16:36:10 +00:00
|
|
|
{
|
|
|
|
GstCaps *caps;
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2000-12-31 16:12:48 +00:00
|
|
|
caps = gst_caps_new (name, mime);
|
2000-12-19 16:36:10 +00:00
|
|
|
caps->properties = props;
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2000-12-03 17:51:29 +00:00
|
|
|
/**
|
|
|
|
* gst_caps_register:
|
|
|
|
* @factory: the factory to register
|
|
|
|
*
|
2001-03-07 21:52:56 +00:00
|
|
|
* Register the factory.
|
2000-12-03 17:51:29 +00:00
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Returns: the registered capability
|
2000-12-03 17:51:29 +00:00
|
|
|
*/
|
2000-12-13 19:29:35 +00:00
|
|
|
GstCaps*
|
2000-12-12 19:29:43 +00:00
|
|
|
gst_caps_register (GstCapsFactory *factory)
|
2000-12-31 16:12:48 +00:00
|
|
|
{
|
|
|
|
guint dummy;
|
|
|
|
|
|
|
|
return gst_caps_register_count (factory, &dummy);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_register_count:
|
|
|
|
* @factory: the factory to register
|
|
|
|
* @counter: count how many entries were consumed
|
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Register the factory.
|
2000-12-31 16:12:48 +00:00
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Returns: the registered capability
|
2000-12-31 16:12:48 +00:00
|
|
|
*/
|
|
|
|
GstCaps*
|
|
|
|
gst_caps_register_count (GstCapsFactory *factory, guint *counter)
|
2000-12-03 17:51:29 +00:00
|
|
|
{
|
|
|
|
GstCapsFactoryEntry tag;
|
|
|
|
gint i = 0;
|
2000-12-31 16:12:48 +00:00
|
|
|
gchar *name;
|
2000-12-03 17:51:29 +00:00
|
|
|
GstCaps *caps;
|
2000-12-31 16:12:48 +00:00
|
|
|
|
2000-12-03 17:51:29 +00:00
|
|
|
g_return_val_if_fail (factory != NULL, NULL);
|
|
|
|
|
2000-12-12 19:29:43 +00:00
|
|
|
tag = (*factory)[i++];
|
2000-12-31 16:12:48 +00:00
|
|
|
g_return_val_if_fail (tag != NULL, NULL);
|
|
|
|
|
|
|
|
name = tag;
|
2000-12-03 17:51:29 +00:00
|
|
|
|
2000-12-31 16:12:48 +00:00
|
|
|
tag = (*factory)[i++];
|
2000-12-03 17:51:29 +00:00
|
|
|
g_return_val_if_fail (tag != NULL, NULL);
|
2001-03-07 21:52:56 +00:00
|
|
|
|
2001-03-20 18:29:00 +00:00
|
|
|
caps = gst_caps_new_with_props (name, (gchar *)tag,
|
|
|
|
gst_props_register_count (&(*factory)[i], counter));
|
|
|
|
|
|
|
|
*counter += 2;
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_destroy:
|
|
|
|
* @caps: the caps to destroy
|
|
|
|
*
|
|
|
|
* Frees the memory used by this caps structure and all
|
|
|
|
* the chained caps and properties.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_caps_destroy (GstCaps *caps)
|
|
|
|
{
|
2001-03-24 17:22:03 +00:00
|
|
|
GstCaps *next;
|
2001-03-20 18:29:00 +00:00
|
|
|
|
2001-03-24 17:22:03 +00:00
|
|
|
g_return_if_fail (caps != NULL);
|
2001-03-20 18:29:00 +00:00
|
|
|
|
2001-03-24 17:22:03 +00:00
|
|
|
GST_CAPS_LOCK (caps);
|
|
|
|
next = caps->next;
|
2001-03-20 18:29:00 +00:00
|
|
|
g_free (caps->name);
|
|
|
|
g_free (caps);
|
2001-03-24 17:22:03 +00:00
|
|
|
GST_CAPS_UNLOCK (caps);
|
|
|
|
|
|
|
|
if (next)
|
|
|
|
gst_caps_unref (next);
|
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
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_caps_unref (GstCaps *caps)
|
|
|
|
{
|
2001-03-24 17:22:03 +00:00
|
|
|
gboolean zero;
|
|
|
|
GstCaps *next;
|
|
|
|
|
2001-03-20 18:29:00 +00:00
|
|
|
g_return_if_fail (caps != NULL);
|
|
|
|
|
2001-03-24 17:22:03 +00:00
|
|
|
GST_CAPS_LOCK (caps);
|
2001-03-20 18:29:00 +00:00
|
|
|
caps->refcount--;
|
2001-03-24 17:22:03 +00:00
|
|
|
zero = (caps->refcount == 0);
|
|
|
|
next = caps->next;
|
|
|
|
GST_CAPS_UNLOCK (caps);
|
2001-03-20 18:29:00 +00:00
|
|
|
|
2001-03-24 17:22:03 +00:00
|
|
|
if (next)
|
|
|
|
gst_caps_unref (next);
|
2001-03-20 18:29:00 +00:00
|
|
|
|
2001-03-24 17:22:03 +00:00
|
|
|
if (zero)
|
2001-03-20 18:29:00 +00:00
|
|
|
gst_caps_destroy (caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_caps_ref:
|
|
|
|
* @caps: the caps to ref
|
|
|
|
*
|
|
|
|
* Increase the refcount of this caps structure
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_caps_ref (GstCaps *caps)
|
|
|
|
{
|
|
|
|
g_return_if_fail (caps != NULL);
|
|
|
|
|
2001-03-24 17:22:03 +00:00
|
|
|
GST_CAPS_LOCK (caps);
|
2001-03-20 18:29:00 +00:00
|
|
|
caps->refcount++;
|
2001-03-24 17:22:03 +00:00
|
|
|
GST_CAPS_UNLOCK (caps);
|
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.
|
|
|
|
*
|
|
|
|
* Returns: a copy of the GstCaps structure.
|
2001-03-20 18:29:00 +00:00
|
|
|
*/
|
|
|
|
GstCaps*
|
|
|
|
gst_caps_copy (GstCaps *caps)
|
|
|
|
{
|
|
|
|
GstCaps *new = caps;;
|
2000-12-03 17:51:29 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (caps != NULL, NULL);
|
|
|
|
|
2001-03-24 17:22:03 +00:00
|
|
|
GST_CAPS_LOCK (caps);
|
2001-03-20 18:29:00 +00:00
|
|
|
new = gst_caps_new_with_props (
|
|
|
|
caps->name,
|
|
|
|
(gst_type_find_by_id (caps->id))->mime,
|
|
|
|
gst_props_copy (caps->properties));
|
2001-03-24 17:22:03 +00:00
|
|
|
GST_CAPS_UNLOCK (caps);
|
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
|
|
|
|
* 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
|
|
|
GST_CAPS_LOCK (caps);
|
|
|
|
needcopy = (caps->refcount > 1);
|
|
|
|
GST_CAPS_UNLOCK (caps);
|
|
|
|
|
|
|
|
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
|
|
|
|
2001-01-06 02:35:17 +00:00
|
|
|
if (caps->name)
|
|
|
|
g_free (caps->name);
|
|
|
|
|
|
|
|
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);
|
|
|
|
g_return_val_if_fail (props != NULL, caps);
|
|
|
|
g_return_val_if_fail (caps->properties == NULL, caps);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
|
|
|
g_return_val_if_fail (caps != capstoadd, caps);
|
2001-03-12 21:02:12 +00:00
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
return capstoadd;
|
|
|
|
|
|
|
|
while (caps->next) {
|
|
|
|
caps = caps->next;
|
|
|
|
}
|
|
|
|
caps->next = capstoadd;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2001-03-29 22:32:00 +00:00
|
|
|
g_return_val_if_fail (caps != capstoadd, caps);
|
|
|
|
|
2001-03-12 21:02:12 +00:00
|
|
|
if (capstoadd == NULL)
|
|
|
|
return caps;
|
|
|
|
|
|
|
|
while (capstoadd->next) {
|
|
|
|
capstoadd = capstoadd->next;
|
|
|
|
}
|
|
|
|
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) {
|
2001-01-18 11:16:53 +00:00
|
|
|
GST_DEBUG (0,"gstcaps: mime types differ (%d to %d)\n",
|
|
|
|
fromcaps->id, tocaps->id);
|
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 {
|
2001-01-01 03:14:40 +00:00
|
|
|
GST_DEBUG (0,"gstcaps: no source caps\n");
|
2000-12-17 16:24:14 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// assume it accepts everything
|
2001-01-01 03:14:40 +00:00
|
|
|
GST_DEBUG (0,"gstcaps: no caps\n");
|
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
|
|
|
/**
|
2001-03-21 21:43:56 +00:00
|
|
|
* gst_caps_check_compatibility:
|
2000-12-31 16:12:48 +00:00
|
|
|
* @fromcaps: a capabilty
|
|
|
|
* @tocaps: a capabilty
|
|
|
|
*
|
2001-03-21 21:43:56 +00:00
|
|
|
* Checks whether two capabilities are compatible.
|
2000-12-31 16:12:48 +00:00
|
|
|
*
|
2001-01-06 22:05:15 +00:00
|
|
|
* Returns: TRUE if compatible, FALSE otherwise
|
2000-12-31 16:12:48 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2001-03-12 21:02:12 +00:00
|
|
|
gst_caps_check_compatibility (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) {
|
|
|
|
GST_DEBUG (0,"gstcaps: no caps\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GST_DEBUG (0,"gstcaps: no src but destination caps\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (tocaps == NULL) {
|
|
|
|
GST_DEBUG (0,"gstcaps: src caps and no dest caps\n");
|
|
|
|
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;
|
2000-12-31 16:12:48 +00:00
|
|
|
|
|
|
|
while (destcaps) {
|
2001-03-12 21:02:12 +00:00
|
|
|
if (gst_caps_check_compatibility_func (fromcaps, destcaps))
|
2000-12-31 16:12:48 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2001-03-12 21:02:12 +00:00
|
|
|
destcaps = destcaps->next;
|
2000-12-31 16:12:48 +00:00
|
|
|
}
|
2001-03-12 21:02:12 +00:00
|
|
|
fromcaps = fromcaps->next;
|
2000-12-31 16:12:48 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-12-11 00:04:25 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
g_mutex_lock (_gst_caps_chunk_lock);
|
|
|
|
caps = g_mem_chunk_alloc0 (_gst_caps_chunk);
|
|
|
|
g_mutex_unlock (_gst_caps_chunk_lock);
|
|
|
|
|
|
|
|
caps->refcount = 1;
|
2001-03-24 17:22:03 +00:00
|
|
|
caps->lock = g_mutex_new ();
|
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")) {
|
|
|
|
caps->properties = gst_props_load_thyself (subfield);
|
|
|
|
}
|
|
|
|
|
|
|
|
subfield = subfield->next;
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|