Skip to content

Commit

Permalink
pbutils: add compile time and runtime version checks for gst-plugins-…
Browse files Browse the repository at this point in the history
…base

So people can check what version of the gst-plugins-base libs they're
building against or linked against.

API: GST_PLUGINS_BASE_VERSION_MAJOR
API: GST_PLUGINS_BASE_VERSION_MINOR
API: GST_PLUGINS_BASE_VERSION_MICRO
API: GST_PLUGINS_BASE_VERSION_NANO
API: GST_CHECK_PLUGINS_BASE_VERSION
API: gst_plugins_base_version()
API: gst_plugins_base_version_string()
  • Loading branch information
Tim-Philipp Müller committed Jul 26, 2010
1 parent 93f9727 commit 5a0c251
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -43,6 +43,7 @@ Makefile
*.gir
*.typelib

gst-libs/gst/pbutils/gstpluginsbaseversion.h
gst-libs/gst/tag/mklangtables

tmp-orc.c
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -911,6 +911,7 @@ gst-libs/gst/rtsp/Makefile
gst-libs/gst/sdp/Makefile
gst-libs/gst/tag/Makefile
gst-libs/gst/pbutils/Makefile
gst-libs/gst/pbutils/gstpluginsbaseversion.h
gst-libs/gst/video/Makefile
tools/Makefile
pkgconfig/Makefile
Expand Down
8 changes: 8 additions & 0 deletions docs/libs/gst-plugins-base-libs-sections.txt
Expand Up @@ -1729,6 +1729,14 @@ gst_tag_get_language_code_iso_639_2T
<INCLUDE>gst/pbutils/pbutils.h</INCLUDE>
<SUBSECTION>
gst_pb_utils_init
<SUBSECTION>
GST_PLUGINS_BASE_VERSION_MAJOR
GST_PLUGINS_BASE_VERSION_MINOR
GST_PLUGINS_BASE_VERSION_MICRO
GST_PLUGINS_BASE_VERSION_NANO
GST_CHECK_PLUGINS_BASE_VERSION
gst_plugins_base_version
gst_plugins_base_version_string
</SECTION>

<SECTION>
Expand Down
8 changes: 7 additions & 1 deletion gst-libs/gst/pbutils/Makefile.am
Expand Up @@ -18,7 +18,11 @@ built_sources = \
built_headers = \
pbutils-enumtypes.h

built_headers_configure = \
gstpluginsbaseversion.h

libgstpbutils_@GST_MAJORMINOR@_la_SOURCES = \
gstpluginsbaseversion.c \
pbutils.c \
descriptions.c \
install-plugins.c \
Expand All @@ -31,7 +35,7 @@ libgstpbutils_@GST_MAJORMINOR@includedir = $(includedir)/gstreamer-@GST_MAJORMIN
libgstpbutils_@GST_MAJORMINOR@include_HEADERS = \
$(headers_pbutils)
nodist_libgstpbutils_@GST_MAJORMINOR@include_HEADERS = \
pbutils-enumtypes.h
$(built_headers) $(built_headers_configure)

libgstpbutils_@GST_MAJORMINOR@_la_LIBADD = $(GST_LIBS)
libgstpbutils_@GST_MAJORMINOR@_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
Expand All @@ -43,6 +47,8 @@ BUILT_SOURCES = \

CLEANFILES = $(BUILT_SOURCES)

# DISTCLEANFILES is for files generated by configure
DISTCLEANFILES = $(built_header_configure)

include $(top_srcdir)/common/gst-glib-gen.mak

Expand Down
78 changes: 78 additions & 0 deletions gst-libs/gst/pbutils/gstpluginsbaseversion.c
@@ -0,0 +1,78 @@
/* GStreamer base plugins libraries version information
* Copyright (C) 2010 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.
*/

/**
* SECTION:gstpluginsbaseversion
* @short_description: GStreamer gst-plugins-base libraries version macros.
*
* Use the GST_PLUGINS_BASE_VERSION_* macros e.g. to check what version of
* gst-plugins-base you are building against, and gst_plugins_base_version()
* if you need to check at runtime what version of the gst-plugins-base
* libraries are being used / you are currently linked against.
*
* The version macros get defined by including <gst/pbutils/pbutils.h>.
*/

#include "gstpluginsbaseversion.h"

/**
* gst_plugins_base_version:
* @major: (out): pointer to a guint to store the major version number, or %NULL
* @minor: (out): pointer to a guint to store the minor version number, or %NULL
* @micro: (out): pointer to a guint to store the micro version number, or %NULL
* @nano: (out): pointer to a guint to store the nano version number, or %NULL
*
* Gets the version number of the GStreamer Plugins Base libraries.
*
* Since: 0.10.31
*/
void
gst_plugins_base_version (guint * major, guint * minor, guint * micro,
guint * nano)
{
if (major)
*major = GST_PLUGINS_BASE_VERSION_MAJOR;
if (minor)
*minor = GST_PLUGINS_BASE_VERSION_MINOR;
if (micro)
*micro = GST_PLUGINS_BASE_VERSION_MICRO;
if (nano)
*nano = GST_PLUGINS_BASE_VERSION_NANO;
}

/**
* gst_plugins_base_version_string:
*
* This function returns a string that is useful for describing this version
* of GStreamer's gst-plugins-base libraries to the outside world: user agent
* strings, logging, about dialogs ...
*
* Returns: a newly allocated string describing this version of gst-plugins-base
*
* Since: 0.10.31
*/
gchar *
gst_plugins_base_version_string (void)
{
return g_strdup_printf ("GStreamer Base Plugins %d.%d.%d%s",
GST_PLUGINS_BASE_VERSION_MAJOR, GST_PLUGINS_BASE_VERSION_MINOR,
GST_PLUGINS_BASE_VERSION_MICRO,
((GST_PLUGINS_BASE_VERSION_NANO == 0) ? "" :
((GST_PLUGINS_BASE_VERSION_NANO == 1) ? " (GIT)" : " (prerelease)")));
}
84 changes: 84 additions & 0 deletions gst-libs/gst/pbutils/gstpluginsbaseversion.h.in
@@ -0,0 +1,84 @@
/* GStreamer base plugins libraries version information
* Copyright (C) 2010 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_PLUGINS_BASE_VERSION_H__
#define __GST_PLUGINS_BASE_VERSION_H__

#include <glib.h>

G_BEGIN_DECLS

/**
* GST_PLUGINS_BASE_VERSION_MAJOR:
*
* The major version of GStreamer's gst-plugins-base libraries at compile time.
*
* Since: 0.10.31
*/
#define GST_PLUGINS_BASE_VERSION_MAJOR (@PACKAGE_VERSION_MAJOR@)
/**
* GST_PLUGINS_BASE_VERSION_MINOR:
*
* The minor version of GStreamer's gst-plugins-base libraries at compile time.
*
* Since: 0.10.31
*/
#define GST_PLUGINS_BASE_VERSION_MINOR (@PACKAGE_VERSION_MINOR@)
/**
* GST_PLUGINS_BASE_VERSION_MICRO:
*
* The micro version of GStreamer's gst-plugins-base libraries at compile time.
*
* Since: 0.10.31
*/
#define GST_PLUGINS_BASE_VERSION_MICRO (@PACKAGE_VERSION_MICRO@)
/**
* GST_PLUGINS_BASE_VERSION_NANO:
*
* The nano version of GStreamer's gst-plugins-base libraries at compile time.
* Actual releases have 0, GIT versions have 1, prerelease versions have 2-...
*
* Since: 0.10.31
*/
#define GST_PLUGINS_BASE_VERSION_NANO (@PACKAGE_VERSION_NANO@)

/**
* GST_CHECK_PLUGIN_BASE_VERSION:
* @major: a number indicating the major version
* @minor: a number indicating the minor version
* @micro: a number indicating the micro version
*
* Check whether a GStreamer's gst-plugins-base libraries' version equal to
* or greater than major.minor.micro is present.
*
* Since: 0.10.31
*/
#define GST_CHECK_PLUGINS_BASE_VERSION(major,minor,micro) \
(GST_PLUGINS_BASE_VERSION_MAJOR > (major) || \
(GST_PLUGINS_BASE_VERSION_MAJOR == (major) && GST_PLUGINS_BASE_VERSION_MINOR > (minor)) || \
(GST_PLUGINS_BASE_VERSION_MAJOR == (major) && GST_PLUGINS_BASE_VERSION_MINOR == (minor) && \
GST_PLUGINS_BASE_VERSION_MICRO >= (micro)))

void gst_plugins_base_version (guint *major, guint *minor, guint *micro, guint *nano);

gchar * gst_plugins_base_version_string (void);

G_END_DECLS

#endif /* __GST_PLUGINS_BASE_VERSION_H__ */
1 change: 1 addition & 0 deletions gst-libs/gst/pbutils/pbutils.h
Expand Up @@ -22,6 +22,7 @@

#include <gst/gst.h>

#include <gst/pbutils/gstpluginsbaseversion.h>
#include <gst/pbutils/descriptions.h>
#include <gst/pbutils/missing-plugins.h>
#include <gst/pbutils/install-plugins.h>
Expand Down
28 changes: 28 additions & 0 deletions tests/check/libs/pbutils.c
Expand Up @@ -704,6 +704,33 @@ GST_START_TEST (test_pb_utils_installer_details)

GST_END_TEST;

GST_START_TEST (test_pb_utils_versions)
{
gchar *s;
guint maj, min, mic, nano;

gst_plugins_base_version (NULL, NULL, NULL, NULL);
gst_plugins_base_version (&maj, &min, &mic, &nano);
fail_unless_equals_int (maj, GST_PLUGINS_BASE_VERSION_MAJOR);
fail_unless_equals_int (min, GST_PLUGINS_BASE_VERSION_MINOR);
fail_unless_equals_int (mic, GST_PLUGINS_BASE_VERSION_MICRO);
fail_unless_equals_int (nano, GST_PLUGINS_BASE_VERSION_NANO);

s = gst_plugins_base_version_string ();
if (GST_PLUGINS_BASE_VERSION_NANO == 0) {
fail_if (strstr (s, "GIT") || strstr (s, "git") || strstr (s, "prerel"));
}
if (GST_PLUGINS_BASE_VERSION_NANO == 1) {
fail_unless (strstr (s, "GIT") || strstr (s, "git"));
}
if (GST_PLUGINS_BASE_VERSION_NANO >= 2) {
fail_unless (strstr (s, "Prerelease") || strstr (s, "prerelease"));
}
g_free (s);
}

GST_END_TEST;

static Suite *
libgstpbutils_suite (void)
{
Expand All @@ -717,6 +744,7 @@ libgstpbutils_suite (void)
tcase_add_test (tc_chain, test_pb_utils_get_codec_description);
tcase_add_test (tc_chain, test_pb_utils_install_plugins);
tcase_add_test (tc_chain, test_pb_utils_installer_details);
tcase_add_test (tc_chain, test_pb_utils_versions);
return s;
}

Expand Down
2 changes: 2 additions & 0 deletions win32/common/libgstpbutils.def
Expand Up @@ -30,3 +30,5 @@ EXPORTS
gst_pb_utils_get_sink_description
gst_pb_utils_get_source_description
gst_pb_utils_init
gst_plugins_base_version
gst_plugins_base_version_string

0 comments on commit 5a0c251

Please sign in to comment.