Commit 1450f0fb authored by Tim-Philipp Müller's avatar Tim-Philipp Müller
Browse files

API: add new libgstbaseutils library with functions

Original commit message from CVS:
* configure.ac:
* gst-libs/gst/Makefile.am:
* gst-libs/gst/utils/Makefile.am:
* gst-libs/gst/utils/base-utils.c: (gst_base_utils_init):
* gst-libs/gst/utils/base-utils.h:
* gst-libs/gst/utils/descriptions.c: (format_info_get_desc),
(find_format_info), (caps_are_rtp_caps),
(gst_base_utils_get_source_description),
(gst_base_utils_get_sink_description),
(gst_base_utils_get_decoder_description),
(gst_base_utils_get_encoder_description),
(gst_base_utils_get_element_description),
(gst_base_utils_add_codec_description_to_tag_list),
(gst_base_utils_get_codec_description), (gst_base_utils_list_all):
* gst-libs/gst/utils/descriptions.h:
* gst-libs/gst/utils/missing-plugins.c:
(missing_structure_get_type), (copy_and_clean_caps),
(gst_missing_uri_source_message_new),
(gst_missing_uri_sink_message_new),
(gst_missing_element_message_new),
(gst_missing_decoder_message_new),
(gst_missing_encoder_message_new),
(missing_structure_get_string_detail),
(missing_structure_get_caps_detail),
(gst_missing_plugin_message_get_installer_detail),
(gst_missing_plugin_message_get_description),
(gst_is_missing_plugin_message):
* gst-libs/gst/utils/missing-plugins.h:
API: add new libgstbaseutils library with functions
- to create and parse missing-plugins messages
- that provide (translated) descriptions for caps/decoders/sources/etc.
Closes #392393.
* pkgconfig/gstreamer-plugins-base-uninstalled.pc.in:
* pkgconfig/gstreamer-plugins-base.pc.in:
Add new lib.
* docs/libs/gst-plugins-base-libs-docs.sgml:
* docs/libs/gst-plugins-base-libs-sections.txt:
Generate docs for new lib and API.
* tests/check/Makefile.am:
* tests/check/libs/.cvsignore:
* tests/check/libs/utils.c: (missing_msg_check_getters),
(GST_START_TEST), (libgstbaseutils_suite):
Add some basic unit tests.
parent 056723b9
2007-01-09 Tim-Philipp Müller <tim at centricular dot net>
* configure.ac:
* gst-libs/gst/Makefile.am:
* gst-libs/gst/utils/Makefile.am:
* gst-libs/gst/utils/base-utils.c: (gst_base_utils_init):
* gst-libs/gst/utils/base-utils.h:
* gst-libs/gst/utils/descriptions.c: (format_info_get_desc),
(find_format_info), (caps_are_rtp_caps),
(gst_base_utils_get_source_description),
(gst_base_utils_get_sink_description),
(gst_base_utils_get_decoder_description),
(gst_base_utils_get_encoder_description),
(gst_base_utils_get_element_description),
(gst_base_utils_add_codec_description_to_tag_list),
(gst_base_utils_get_codec_description), (gst_base_utils_list_all):
* gst-libs/gst/utils/descriptions.h:
* gst-libs/gst/utils/missing-plugins.c:
(missing_structure_get_type), (copy_and_clean_caps),
(gst_missing_uri_source_message_new),
(gst_missing_uri_sink_message_new),
(gst_missing_element_message_new),
(gst_missing_decoder_message_new),
(gst_missing_encoder_message_new),
(missing_structure_get_string_detail),
(missing_structure_get_caps_detail),
(gst_missing_plugin_message_get_installer_detail),
(gst_missing_plugin_message_get_description),
(gst_is_missing_plugin_message):
* gst-libs/gst/utils/missing-plugins.h:
API: add new libgstbaseutils library with functions
- to create and parse missing-plugins messages
- that provide (translated) descriptions for caps/decoders/sources/etc.
Closes #392393.
* pkgconfig/gstreamer-plugins-base-uninstalled.pc.in:
* pkgconfig/gstreamer-plugins-base.pc.in:
Add new lib.
* docs/libs/gst-plugins-base-libs-docs.sgml:
* docs/libs/gst-plugins-base-libs-sections.txt:
Generate docs for new lib and API.
* tests/check/Makefile.am:
* tests/check/libs/.cvsignore:
* tests/check/libs/utils.c: (missing_msg_check_getters),
(GST_START_TEST), (libgstbaseutils_suite):
Add some basic unit tests.
2007-01-09 Tim-Philipp Müller <tim at centricular dot net>
 
* ext/ogg/Makefile.am:
......@@ -182,6 +182,9 @@ AC_CHECK_HEADERS([sys/socket.h],
HAVE_SYS_SOCKET_H="yes", HAVE_SYS_SOCKET_H="no")
AM_CONDITIONAL(HAVE_SYS_SOCKET_H, test "x$HAVE_SYS_SOCKET_H" = "xyes")
dnl used in gst-libs/gst/utils
AC_CHECK_HEADERS([process.h])
dnl ffmpegcolorspace includes _stdint.h
dnl also, Windows does not have long long
AX_CREATE_STDINT_H
......@@ -619,6 +622,7 @@ gst-libs/gst/netbuffer/Makefile
gst-libs/gst/riff/Makefile
gst-libs/gst/rtp/Makefile
gst-libs/gst/tag/Makefile
gst-libs/gst/utils/Makefile
gst-libs/gst/video/Makefile
tools/Makefile
win32/common/config.h
......
......@@ -45,6 +45,10 @@
<!ENTITY GstTag SYSTEM "xml/gsttag.xml">
<!ENTITY GstTagVorbis SYSTEM "xml/gsttagvorbis.xml">
<!ENTITY GstTagID3 SYSTEM "xml/gsttagid3.xml">
<!-- utils -->
<!ENTITY GstBaseUtils SYSTEM "xml/gstbaseutils.xml">
<!ENTITY GstBaseUtilsDescriptions SYSTEM "xml/gstbaseutilsdescriptions.xml">
<!ENTITY GstBaseUtilsMissingPlugins SYSTEM "xml/gstbaseutilsmissingplugins.xml">
<!-- video -->
<!ENTITY GstVideo SYSTEM "xml/gstvideo.xml">
<!ENTITY GstVideoFilter SYSTEM "xml/gstvideofilter.xml">
......@@ -173,6 +177,19 @@
&GstTagID3;
</chapter>
<chapter id="gstreamer-base-utils">
<title>Base Utils Library</title>
<para>
This library should be linked to by getting cflags and libs from
<filename>gstreamer-plugins-base.pc</filename> and adding
<filename>-lgstbaseutils-&GST_MAJORMINOR;</filename> to the library
flags.
</para>
&GstBaseUtils;
&GstBaseUtilsDescriptions;
&GstBaseUtilsMissingPlugins;
</chapter>
<chapter id="gstreamer-video">
<title>Video Library</title>
<para>
......
......@@ -917,6 +917,43 @@ gst_tag_from_id3_user_tag
gst_tag_to_id3_tag
</SECTION>
# base utils
<SECTION>
<FILE>gstbaseutils</FILE>
<INCLUDE>gst/utils/base-utils.h</INCLUDE>
<SUBSECTION>
gst_base_utils_init
</SECTION>
<SECTION>
<FILE>gstbaseutilsmissingplugins</FILE>
<INCLUDE>gst/utils/missing-plugins.h</INCLUDE>
<SUBSECTION>
gst_missing_plugin_message_get_installer_detail
gst_missing_plugin_message_get_description
gst_is_missing_plugin_message
<SUBSECTION>
gst_missing_decoder_message_new
gst_missing_encoder_message_new
gst_missing_uri_source_message_new
gst_missing_uri_sink_message_new
gst_missing_element_message_new
</SECTION>
<SECTION>
<FILE>gstbaseutilsdescriptions</FILE>
<INCLUDE>gst/utils/descriptions.h</INCLUDE>
<SUBSECTION>
gst_base_utils_get_source_description
gst_base_utils_get_sink_description
gst_base_utils_get_decoder_description
gst_base_utils_get_encoder_description
gst_base_utils_get_element_description
<SUBSECTION>
gst_base_utils_add_codec_description_to_tag_list
gst_base_utils_get_codec_description
</SECTION>
# video
......
......@@ -11,6 +11,7 @@ SUBDIRS = \
netbuffer \
riff \
rtp \
utils \
video
noinst_HEADERS = gettext.h gst-i18n-plugin.h
lib_LTLIBRARIES = libgstbaseutils-@GST_MAJORMINOR@.la
libgstbaseutils_@GST_MAJORMINOR@_la_SOURCES = \
base-utils.c \
base-utils.h \
descriptions.c \
descriptions.h \
missing-plugins.c \
missing-plugins.h
libgstbaseutils_@GST_MAJORMINOR@includedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/utils
libgstbaseutils_@GST_MAJORMINOR@include_HEADERS = \
base-utils.h \
descriptions.h \
missing-plugins.h
libgstbaseutils_@GST_MAJORMINOR@_la_LIBADD = $(GST_LIBS)
libgstbaseutils_@GST_MAJORMINOR@_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
libgstbaseutils_@GST_MAJORMINOR@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) $(GST_LT_LDFLAGS)
This diff is collapsed.
/* GStreamer base utils library source/sink/codec description support
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
*
* 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.
*/
#ifndef __GST_BASE_UTILS_DESCRIPTIONS_H__
#define __GST_BASE_UTILS_DESCRIPTIONS_H__
#include <gst/gsttaglist.h>
#include <gst/gstcaps.h>
G_BEGIN_DECLS
/*
* functions for use by demuxers or decoders to add CODEC tags to tag lists
* from caps
*/
gboolean gst_base_utils_add_codec_description_to_tag_list (GstTagList * taglist,
const gchar * codec_tag,
const GstCaps * caps);
gchar * gst_base_utils_get_codec_description (const GstCaps * caps);
/*
* functions mainly used by the missing plugins message creation functions to
* find descriptions of what exactly is missing
*/
gchar * gst_base_utils_get_source_description (const gchar * protocol);
gchar * gst_base_utils_get_sink_description (const gchar * protocol);
gchar * gst_base_utils_get_decoder_description (const GstCaps * caps);
gchar * gst_base_utils_get_encoder_description (const GstCaps * caps);
gchar * gst_base_utils_get_element_description (const gchar * factory_name);
G_END_DECLS
#endif /* __GST_BASE_UTILS_DESCRIPTIONS_H__ */
/* GStreamer base utils library missing plugins support
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
*
* 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.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h> /* getpid on UNIX */
#endif
#ifdef HAVE_PROCESS_H
# include <process.h> /* getpid on win32 */
#endif
#include "gst/gst-i18n-plugin.h"
#include "base-utils.h"
#include <string.h>
#define GST_DETAIL_STRING_MARKER "gstreamer.net"
typedef enum
{
GST_MISSING_TYPE_UNKNOWN = 0,
GST_MISSING_TYPE_URISOURCE,
GST_MISSING_TYPE_URISINK,
GST_MISSING_TYPE_ELEMENT,
GST_MISSING_TYPE_DECODER,
GST_MISSING_TYPE_ENCODER
} GstMissingType;
static const struct
{
GstMissingType type;
const gchar type_string[12];
} missing_type_mapping[] = {
{
GST_MISSING_TYPE_URISOURCE, "urisource"}, {
GST_MISSING_TYPE_URISINK, "urisink"}, {
GST_MISSING_TYPE_ELEMENT, "element"}, {
GST_MISSING_TYPE_DECODER, "decoder"}, {
GST_MISSING_TYPE_ENCODER, "encoder"}
};
static GstMissingType
missing_structure_get_type (const GstStructure * s)
{
const gchar *type;
guint i;
type = gst_structure_get_string (s, "type");
g_return_val_if_fail (type != NULL, GST_MISSING_TYPE_UNKNOWN);
for (i = 0; i < G_N_ELEMENTS (missing_type_mapping); ++i) {
if (strcmp (missing_type_mapping[i].type_string, type) == 0)
return missing_type_mapping[i].type;
}
return GST_MISSING_TYPE_UNKNOWN;
}
static GstCaps *
copy_and_clean_caps (const GstCaps * caps)
{
GstStructure *s;
GstCaps *ret;
ret = gst_caps_copy (caps);
/* make caps easier to interpret, remove common fields that are likely
* to be irrelevant for determining the right plugin (ie. mostly fields
* where template caps usually have the standard MIN - MAX range as value) */
s = gst_caps_get_structure (ret, 0);
gst_structure_remove_field (s, "codec_data");
gst_structure_remove_field (s, "palette_data");
gst_structure_remove_field (s, "pixel-aspect-ratio");
gst_structure_remove_field (s, "framerate");
/* maybe remove width/height too? */
return ret;
}
/**
* gst_missing_uri_source_message_new:
* @element: the #GstElement posting the message
* @protocol: the URI protocol the missing source needs to implement,
* e.g. "http" or "mms"
*
* Creates a missing-plugin message for @element to notify the application
* that a source element for a particular URI protocol is missing. This
* function is mainly for use in plugins.
*
* Returns: a new #GstMessage, or NULL on error
*/
GstMessage *
gst_missing_uri_source_message_new (GstElement * element,
const gchar * protocol)
{
GstStructure *s;
gchar *description;
g_return_val_if_fail (element != NULL, NULL);
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
g_return_val_if_fail (protocol != NULL, NULL);
description = gst_base_utils_get_source_description (protocol);
s = gst_structure_new ("missing-plugin", "type", G_TYPE_STRING,
"urisource", "detail", G_TYPE_STRING, protocol, "name", G_TYPE_STRING,
description, NULL);
g_free (description);
return gst_message_new_element (GST_OBJECT_CAST (element), s);
}
/**
* gst_missing_uri_sink_message_new:
* @element: the #GstElement posting the message
* @protocol: the URI protocol the missing sink needs to implement,
* e.g. "http" or "smb"
*
* Creates a missing-plugin message for @element to notify the application
* that a sink element for a particular URI protocol is missing. This
* function is mainly for use in plugins.
*
* Returns: a new #GstMessage, or NULL on error
*/
GstMessage *
gst_missing_uri_sink_message_new (GstElement * element, const gchar * protocol)
{
GstStructure *s;
gchar *description;
g_return_val_if_fail (element != NULL, FALSE);
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
g_return_val_if_fail (protocol != NULL, FALSE);
description = gst_base_utils_get_sink_description (protocol);
s = gst_structure_new ("missing-plugin", "type", G_TYPE_STRING,
"urisink", "detail", G_TYPE_STRING, protocol, "name", G_TYPE_STRING,
description, NULL);
g_free (description);
return gst_message_new_element (GST_OBJECT_CAST (element), s);
}
/**
* gst_missing_element_message_new:
* @element: the #GstElement posting the message
* @factory_name: the name of the missing element (element factory),
* e.g. "videoscale" or "cdparanoiasrc"
*
* Creates a missing-plugin message for @element to notify the application
* that a certain required element is missing. This function is mainly for
* use in plugins.
*
* Returns: a new #GstMessage, or NULL on error
*/
GstMessage *
gst_missing_element_message_new (GstElement * element,
const gchar * factory_name)
{
GstStructure *s;
gchar *description;
g_return_val_if_fail (element != NULL, FALSE);
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
g_return_val_if_fail (factory_name != NULL, FALSE);
description = gst_base_utils_get_element_description (factory_name);
s = gst_structure_new ("missing-plugin", "type", G_TYPE_STRING,
"element", "detail", G_TYPE_STRING, factory_name, "name", G_TYPE_STRING,
description, NULL);
g_free (description);
return gst_message_new_element (GST_OBJECT_CAST (element), s);
}
/**
* gst_missing_decoder_message_new:
* @element: the #GstElement posting the message
* @decode_caps: the (fixed) caps for which a decoder element is needed
*
* Creates a missing-plugin message for @element to notify the application
* that a decoder element for a particular set of (fixed) caps is missing.
* This function is mainly for use in plugins.
*
* Returns: a new #GstMessage, or NULL on error
*/
GstMessage *
gst_missing_decoder_message_new (GstElement * element,
const GstCaps * decode_caps)
{
GstStructure *s;
GstCaps *caps;
gchar *description;
g_return_val_if_fail (element != NULL, FALSE);
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
g_return_val_if_fail (decode_caps != NULL, FALSE);
g_return_val_if_fail (GST_IS_CAPS (decode_caps), FALSE);
g_return_val_if_fail (!gst_caps_is_any (decode_caps), FALSE);
g_return_val_if_fail (!gst_caps_is_empty (decode_caps), FALSE);
g_return_val_if_fail (gst_caps_is_fixed (decode_caps), FALSE);
description = gst_base_utils_get_decoder_description (decode_caps);
caps = copy_and_clean_caps (decode_caps);
s = gst_structure_new ("missing-plugin", "type", G_TYPE_STRING,
"decoder", "detail", GST_TYPE_CAPS, caps, "name", G_TYPE_STRING,
description, NULL);
gst_caps_unref (caps);
g_free (description);
return gst_message_new_element (GST_OBJECT_CAST (element), s);
}
/**
* gst_missing_encoder_message_new:
* @element: the #GstElement posting the message
* @encode_caps: the (fixed) caps for which an encoder element is needed
*
* Creates a missing-plugin message for @element to notify the application
* that an encoder element for a particular set of (fixed) caps is missing.
* This function is mainly for use in plugins.
*
* Returns: a new #GstMessage, or NULL on error
*/
GstMessage *
gst_missing_encoder_message_new (GstElement * element,
const GstCaps * encode_caps)
{
GstStructure *s;
GstCaps *caps;
gchar *description;
g_return_val_if_fail (element != NULL, FALSE);
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
g_return_val_if_fail (encode_caps != NULL, FALSE);
g_return_val_if_fail (GST_IS_CAPS (encode_caps), FALSE);
g_return_val_if_fail (!gst_caps_is_any (encode_caps), FALSE);
g_return_val_if_fail (!gst_caps_is_empty (encode_caps), FALSE);
g_return_val_if_fail (gst_caps_is_fixed (encode_caps), FALSE);
description = gst_base_utils_get_encoder_description (encode_caps);
caps = copy_and_clean_caps (encode_caps);
s = gst_structure_new ("missing-plugin", "type", G_TYPE_STRING,
"encoder", "detail", GST_TYPE_CAPS, caps, "name", G_TYPE_STRING,
description, NULL);
gst_caps_unref (caps);
g_free (description);
return gst_message_new_element (GST_OBJECT_CAST (element), s);
}
static gboolean
missing_structure_get_string_detail (const GstStructure * s, gchar ** p_detail)
{
const gchar *detail;
GType detail_type;
*p_detail = NULL;
detail_type = gst_structure_get_field_type (s, "detail");
if (!g_type_is_a (detail_type, G_TYPE_STRING)) {
GST_WARNING ("expected 'detail' field to be of G_TYPE_STRING");
return FALSE;
}
detail = gst_structure_get_string (s, "detail");
if (detail == NULL || *detail == '\0') {
GST_WARNING ("empty 'detail' field");
return FALSE;
}
*p_detail = g_strdup (detail);
return TRUE;
}
static gboolean
missing_structure_get_caps_detail (const GstStructure * s, GstCaps ** p_caps)
{
const GstCaps *caps;
const GValue *val;
GType detail_type;
*p_caps = NULL;
detail_type = gst_structure_get_field_type (s, "detail");
if (!g_type_is_a (detail_type, GST_TYPE_CAPS)) {
GST_WARNING ("expected 'detail' field to be of GST_TYPE_CAPS");
return FALSE;
}
val = gst_structure_get_value (s, "detail");
caps = gst_value_get_caps (val);
if (gst_caps_is_empty (caps) || gst_caps_is_any (caps)) {
GST_WARNING ("EMPTY or ANY caps not allowed");
return FALSE;
}
*p_caps = gst_caps_copy (caps);
return TRUE;
}
/**
* gst_missing_plugin_message_get_installer_detail:
* @msg: a missing-plugin #GstMessage of type #GST_MESSAGE_ELEMENT
*
* Returns an opaque string containing all the details about the missing
* element to be passed to an external installer or installer library
* such as libgimme-codec.
*
* This function is mainly for applications that use libgimme-codec or
* other libraries that call external plugin installation mechanisms.
*
* Returns: a newly-allocated detail string, or NULL on error. Free string
* with g_free() when not needed any longer.
*/
gchar *
gst_missing_plugin_message_get_installer_detail (GstMessage * msg)
{
GstMissingType missing_type;
const gchar *progname;
const gchar *type;
GString *str = NULL;
gchar *detail = NULL;
gchar *desc;
g_return_val_if_fail (gst_is_missing_plugin_message (msg), NULL);
GST_LOG ("Parsing missing-plugin message: %" GST_PTR_FORMAT, msg->structure);
missing_type = missing_structure_get_type (msg->structure);
if (missing_type == GST_MISSING_TYPE_UNKNOWN) {
GST_WARNING ("couldn't parse 'type' field");
goto error;
}
type = gst_structure_get_string (msg->structure, "type");
g_assert (type != NULL); /* validity already checked above */
str = g_string_new (GST_DETAIL_STRING_MARKER "|");
g_string_append_printf (str, "%u.%u|", GST_VERSION_MAJOR, GST_VERSION_MINOR);
progname = (const gchar *) g_get_prgname ();
if (progname) {
g_string_append_printf (str, "%s|", progname);
} else {
g_string_append_printf (str, "pid/%lu", (gulong) getpid ());
}
desc = gst_missing_plugin_message_get_description (msg);
if (desc) {
g_strdelimit (desc, "|", '#');
g_string_append_printf (str, "%s|", desc);
g_free (desc);
} else {
g_string_append (str, "|");
}
switch (missing_type) {
case GST_MISSING_TYPE_URISOURCE:
case GST_MISSING_TYPE_URISINK: