LargeTrackInfoDisaply: replace an IDisposable cast/call with using{} syntax
[banshee.git] / libbanshee / banshee-gst.c
blobd00054bbab61b06c27d6e72a680ddec96ae5479b
1 //
2 // banshee-gst.c
3 //
4 // Author:
5 // Aaron Bockover <abockover@novell.com>
6 //
7 // Copyright (C) 2005-2008 Novell, Inc.
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <stdarg.h>
38 #include <gst/gst.h>
39 #include <gst/pbutils/pbutils.h>
41 #include "banshee-gst.h"
43 static gboolean gstreamer_initialized = FALSE;
44 static gboolean banshee_debugging;
45 static BansheeLogHandler banshee_log_handler = NULL;
46 static gint banshee_version = -1;
48 MYEXPORT void
49 gstreamer_initialize (gboolean debugging, BansheeLogHandler log_handler)
51 if (gstreamer_initialized) {
52 return;
55 banshee_debugging = debugging;
56 banshee_log_handler = log_handler;
58 gst_init (NULL, NULL);
60 gst_pb_utils_init ();
62 gstreamer_initialized = TRUE;
65 MYEXPORT gboolean
66 gstreamer_test_pipeline (gchar *pipeline)
68 GstElement *element = NULL;
69 GError *error = NULL;
71 element = gst_parse_launch (pipeline, &error);
73 if (element != NULL) {
74 gst_object_unref (GST_OBJECT (element));
77 return error == NULL;
80 MYEXPORT gchar *
81 gstreamer_version_string ()
83 return g_strdup_printf ("%i.%i.%i.%i", GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO, GST_VERSION_NANO);
86 gboolean
87 banshee_is_debugging ()
89 return banshee_debugging;
92 guint
93 banshee_get_version_number ()
95 guint16 major = 0, minor = 0, micro = 0;
97 if (banshee_version >= 0) {
98 return (guint)banshee_version;
101 if (sscanf (VERSION, "%" G_GUINT16_FORMAT ".%" G_GUINT16_FORMAT ".%" G_GUINT16_FORMAT,
102 &major, &minor, &micro) == 3) {
103 banshee_version = ((guint8)major << 16) | ((guint8)minor << 8) | ((guint8)micro);
104 // major = (banshee_version >> 16)
105 // minor = (banshee_version >> 8) & 0x00FF
106 // micro = banshee_version & 0x0000FF
107 } else {
108 banshee_version = 0;
111 return (guint)banshee_version;
114 static void
115 banshee_log (BansheeLogType type, const gchar *component, const gchar *message)
117 if (banshee_log_handler == NULL) {
118 switch (type) {
119 case BANSHEE_LOG_TYPE_WARNING: g_warning ("%s: %s", component, message); break;
120 case BANSHEE_LOG_TYPE_ERROR: g_error ("%s: %s", component, message); break;
121 default: g_debug ("%s: %s", component, message); break;
123 return;
126 (banshee_log_handler) (type, component, message);
129 void
130 banshee_log_debug (const gchar *component, const gchar *format, ...)
132 va_list args;
133 gchar *message;
135 if (!banshee_debugging) {
136 return;
139 va_start (args, format);
140 message = g_strdup_vprintf (format, args);
141 va_end (args);
143 banshee_log (BANSHEE_LOG_TYPE_DEBUG, component, message);
145 g_free (message);