[rhythmbox/gstreamer-0.11: 6/12] mtp: convert to GStreamer 0.11
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox/gstreamer-0.11: 6/12] mtp: convert to GStreamer 0.11
- Date: Mon, 27 Feb 2012 13:37:28 +0000 (UTC)
commit 069e8fa5f03b8b647295ede23b8728a5bf8db424
Author: Jonathan Matthew <jonathan d14n org>
Date: Mon Feb 27 23:03:33 2012 +1000
mtp: convert to GStreamer 0.11
plugins/mtpdevice/Makefile.am | 2 +
plugins/mtpdevice/rb-mtp-gst-sink.c | 85 ++++++++--------------------
plugins/mtpdevice/rb-mtp-gst-src.c | 106 ++++++++++++-----------------------
plugins/mtpdevice/rb-mtp-gst.c | 58 +++++++++++++++++++
plugins/mtpdevice/rb-mtp-gst.h | 39 +++++++++++++
plugins/mtpdevice/rb-mtp-plugin.c | 5 +-
6 files changed, 161 insertions(+), 134 deletions(-)
---
diff --git a/plugins/mtpdevice/Makefile.am b/plugins/mtpdevice/Makefile.am
index 534d243..ac193bc 100644
--- a/plugins/mtpdevice/Makefile.am
+++ b/plugins/mtpdevice/Makefile.am
@@ -6,6 +6,8 @@ plugin_LTLIBRARIES = libmtpdevice.la
libmtpdevice_la_SOURCES = \
rb-mtp-plugin.c \
+ rb-mtp-gst.c \
+ rb-mtp-gst.h \
rb-mtp-gst-src.c \
rb-mtp-gst-sink.c \
rb-mtp-source.c \
diff --git a/plugins/mtpdevice/rb-mtp-gst-sink.c b/plugins/mtpdevice/rb-mtp-gst-sink.c
index bc89012..26840ec 100644
--- a/plugins/mtpdevice/rb-mtp-gst-sink.c
+++ b/plugins/mtpdevice/rb-mtp-gst-sink.c
@@ -86,41 +86,13 @@ static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_ALWAYS,
GST_STATIC_CAPS_ANY);
-static GstElementDetails rb_mtp_sink_details =
-GST_ELEMENT_DETAILS ("RB MTP Sink",
- "Sink/File",
- "Uploads tracks to MTP devices",
- "Jonathan Matthew <jonathan d14n org>");
-
GType rb_mtp_sink_get_type (void);
-static void rb_mtp_sink_uri_handler_init (gpointer g_iface, gpointer iface_data);
-
-static void
-_do_init (GType mtp_sink_type)
-{
- static const GInterfaceInfo urihandler_info = {
- rb_mtp_sink_uri_handler_init,
- NULL,
- NULL
- };
-
- g_type_add_interface_static (mtp_sink_type, GST_TYPE_URI_HANDLER,
- &urihandler_info);
-}
+static void uri_handler_init (gpointer g_iface, gpointer iface_data);
-GST_BOILERPLATE_FULL (RBMTPSink, rb_mtp_sink, GstBin, GST_TYPE_BIN, _do_init);
-
-static void
-rb_mtp_sink_base_init (gpointer g_class)
-{
- GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&sinktemplate));
- gst_element_class_set_details (element_class, &rb_mtp_sink_details);
-}
+G_DEFINE_TYPE_WITH_CODE (RBMTPSink, rb_mtp_sink, GST_TYPE_BIN, G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, uri_handler_init));
static void
-rb_mtp_sink_init (RBMTPSink *sink, RBMTPSinkClass *klass)
+rb_mtp_sink_init (RBMTPSink *sink)
{
GstPad *pad;
@@ -138,7 +110,7 @@ rb_mtp_sink_init (RBMTPSink *sink, RBMTPSinkClass *klass)
gst_object_ref (sink->fdsink);
/* create ghost pad */
- pad = gst_element_get_pad (sink->fdsink, "sink");
+ pad = gst_element_get_static_pad (sink->fdsink, "sink");
sink->ghostpad = gst_ghost_pad_new ("sink", pad);
gst_element_add_pad (GST_ELEMENT (sink), sink->ghostpad);
gst_object_ref (sink->ghostpad);
@@ -289,7 +261,7 @@ rb_mtp_sink_handle_message (GstBin *bin, GstMessage *message)
}
}
- GST_BIN_CLASS (parent_class)->handle_message (bin, message);
+ GST_BIN_CLASS (rb_mtp_sink_parent_class)->handle_message (bin, message);
}
static GstStateChangeReturn
@@ -315,7 +287,7 @@ rb_mtp_sink_change_state (GstElement *element, GstStateChange transition)
break;
}
- ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
+ ret = GST_ELEMENT_CLASS (rb_mtp_sink_parent_class)->change_state (element, transition);
switch (transition) {
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
@@ -397,7 +369,7 @@ rb_mtp_sink_dispose (GObject *object)
sink->device_thread = NULL;
}
- G_OBJECT_CLASS (parent_class)->dispose (object);
+ G_OBJECT_CLASS (rb_mtp_sink_parent_class)->dispose (object);
}
static void
@@ -417,7 +389,7 @@ rb_mtp_sink_finalize (GObject *object)
g_strfreev (sink->folder_path);
}
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (rb_mtp_sink_parent_class)->finalize (object);
}
static void
@@ -458,33 +430,41 @@ rb_mtp_sink_class_init (RBMTPSinkClass *klass)
"device handling thread",
G_TYPE_OBJECT,
G_PARAM_READWRITE));
+
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&sinktemplate));
+ gst_element_class_set_details_simple (element_class,
+ "RB MTP Sink",
+ "Sink/File",
+ "Uploads tracks to MTP devices",
+ "Jonathan Matthew <jonathan d14n org>");
}
/* URI handler interface */
static guint
-rb_mtp_sink_uri_get_type (void)
+rb_mtp_sink_uri_get_type (GType type)
{
return GST_URI_SINK;
}
-static gchar **
-rb_mtp_sink_uri_get_protocols (void)
+static const gchar *const *
+rb_mtp_sink_uri_get_protocols (GType type)
{
- static gchar *protocols[] = {"xrbmtp", NULL};
+ static const gchar *protocols[] = {"xrbmtp", NULL};
return protocols;
}
-static const gchar *
+static gchar *
rb_mtp_sink_uri_get_uri (GstURIHandler *handler)
{
/* more or less */
- return "xrbmtp://";
+ return g_strdup ("xrbmtp://");
}
static gboolean
-rb_mtp_sink_uri_set_uri (GstURIHandler *handler, const gchar *uri)
+rb_mtp_sink_uri_set_uri (GstURIHandler *handler, const gchar *uri, GError **error)
{
RBMTPSink *sink = RB_MTP_SINK (handler);
@@ -502,7 +482,7 @@ rb_mtp_sink_uri_set_uri (GstURIHandler *handler, const gchar *uri)
}
static void
-rb_mtp_sink_uri_handler_init (gpointer g_iface, gpointer iface_data)
+uri_handler_init (gpointer g_iface, gpointer iface_data)
{
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
@@ -511,20 +491,3 @@ rb_mtp_sink_uri_handler_init (gpointer g_iface, gpointer iface_data)
iface->get_uri = rb_mtp_sink_uri_get_uri;
iface->set_uri = rb_mtp_sink_uri_set_uri;
}
-
-static gboolean
-plugin_init (GstPlugin *plugin)
-{
- gboolean ret = gst_element_register (plugin, "rbmtpsink", GST_RANK_PRIMARY, RB_TYPE_MTP_SINK);
- return ret;
-}
-
-GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR,
- GST_VERSION_MINOR,
- "rbmtpsink",
- "element to upload files to MTP devices",
- plugin_init,
- VERSION,
- "GPL",
- PACKAGE,
- "");
diff --git a/plugins/mtpdevice/rb-mtp-gst-src.c b/plugins/mtpdevice/rb-mtp-gst-src.c
index 9b431e5..1a5a8bc 100644
--- a/plugins/mtpdevice/rb-mtp-gst-src.c
+++ b/plugins/mtpdevice/rb-mtp-gst-src.c
@@ -33,6 +33,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <stdlib.h>
#include <glib/gi18n.h>
#include <libmtp.h>
@@ -88,38 +89,16 @@ static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
GST_STATIC_CAPS_ANY);
GType rb_mtp_src_get_type (void);
-static void rb_mtp_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
+static void uri_handler_init (gpointer g_iface, gpointer iface_data);
-static void
-_do_init (GType mtp_src_type)
-{
- static const GInterfaceInfo urihandler_info = {
- rb_mtp_src_uri_handler_init,
- NULL,
- NULL
- };
-
- g_type_add_interface_static (mtp_src_type, GST_TYPE_URI_HANDLER,
- &urihandler_info);
-}
-
-GST_BOILERPLATE_FULL (RBMTPSrc, rb_mtp_src, GstBaseSrc, GST_TYPE_BASE_SRC, _do_init);
-
-static void
-rb_mtp_src_base_init (gpointer g_class)
-{
- GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&srctemplate));
- gst_element_class_set_details_simple (element_class,
- "RB MTP Source",
- "Source/File",
- "Downloads and plays files from MTP devices",
- "Jonathan Matthew <jonathan d14n org>");
-}
+G_DEFINE_TYPE_WITH_CODE (RBMTPSrc,
+ rb_mtp_src,
+ GST_TYPE_BASE_SRC,
+ G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER,
+ uri_handler_init));
static void
-rb_mtp_src_init (RBMTPSrc *src, RBMTPSrcClass *klass)
+rb_mtp_src_init (RBMTPSrc *src)
{
src->download_mutex = g_mutex_new ();
src->download_cond = g_cond_new ();
@@ -154,10 +133,10 @@ rb_mtp_src_set_uri (RBMTPSrc *src, const char *uri)
}
static GstFlowReturn
-rb_mtp_src_create (GstBaseSrc *basesrc, guint64 offset, guint length, GstBuffer **buffer)
+rb_mtp_src_fill (GstBaseSrc *basesrc, guint64 offset, guint length, GstBuffer *buf)
{
RBMTPSrc *src = RB_MTP_SRC (basesrc);
- GstBuffer *buf;
+ GstMapInfo mapinfo;
int ret;
/* seek if required */
@@ -172,29 +151,24 @@ rb_mtp_src_create (GstBaseSrc *basesrc, guint64 offset, guint length, GstBuffer
src->read_position = offset;
}
- buf = gst_buffer_try_new_and_alloc (length);
- if (buf == NULL && length > 0) {
- GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", length);
- return GST_FLOW_ERROR;
- }
-
if (length > 0) {
- ret = read (src->fd, GST_BUFFER_DATA (buf), length);
+ gst_buffer_map (buf, &mapinfo, GST_MAP_WRITE);
+ ret = read (src->fd, mapinfo.data, length);
if (ret < length) {
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
+ gst_buffer_unmap (buf, &mapinfo);
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
}
- length = ret;
- GST_BUFFER_SIZE (buf) = length;
+ gst_buffer_unmap (buf, &mapinfo);
+ gst_buffer_resize (buf, 0, length);
GST_BUFFER_OFFSET (buf) = offset;
GST_BUFFER_OFFSET_END (buf) = offset + length;
src->read_position += length;
}
- *buffer = buf;
return GST_FLOW_OK;
}
@@ -362,7 +336,7 @@ rb_mtp_src_dispose (GObject *object)
src->device_thread = NULL;
}
- G_OBJECT_CLASS (parent_class)->dispose (object);
+ G_OBJECT_CLASS (rb_mtp_src_parent_class)->dispose (object);
}
static void
@@ -385,7 +359,7 @@ rb_mtp_src_finalize (GObject *object)
src->tempfile = NULL;
}
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (rb_mtp_src_parent_class)->finalize (object);
}
static void
@@ -393,6 +367,7 @@ rb_mtp_src_class_init (RBMTPSrcClass *klass)
{
GObjectClass *gobject_class;
GstBaseSrcClass *basesrc_class;
+ GstElementClass *element_class;
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->dispose = rb_mtp_src_dispose;
@@ -405,7 +380,7 @@ rb_mtp_src_class_init (RBMTPSrcClass *klass)
basesrc_class->stop = GST_DEBUG_FUNCPTR (rb_mtp_src_stop);
basesrc_class->is_seekable = GST_DEBUG_FUNCPTR (rb_mtp_src_is_seekable);
basesrc_class->get_size = GST_DEBUG_FUNCPTR (rb_mtp_src_get_size);
- basesrc_class->create = GST_DEBUG_FUNCPTR (rb_mtp_src_create);
+ basesrc_class->fill = GST_DEBUG_FUNCPTR (rb_mtp_src_fill);
g_object_class_install_property (gobject_class,
PROP_URI,
@@ -421,34 +396,42 @@ rb_mtp_src_class_init (RBMTPSrcClass *klass)
"device handling thread",
G_TYPE_OBJECT,
G_PARAM_READWRITE));
+
+ element_class = GST_ELEMENT_CLASS (klass);
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&srctemplate));
+ gst_element_class_set_details_simple (element_class,
+ "RB MTP Source",
+ "Source/File",
+ "Downloads and plays files from MTP devices",
+ "Jonathan Matthew <jonathan d14n org>");
}
/* URI handler interface */
static guint
-rb_mtp_src_uri_get_type (void)
+rb_mtp_src_uri_get_type (GType type)
{
return GST_URI_SRC;
}
-static gchar **
-rb_mtp_src_uri_get_protocols (void)
+static const gchar *const *
+rb_mtp_src_uri_get_protocols (GType type)
{
- static gchar *protocols[] = {"xrbmtp", NULL};
+ static const gchar *protocols[] = {"xrbmtp", NULL};
return protocols;
}
-static const gchar *
+static gchar *
rb_mtp_src_uri_get_uri (GstURIHandler *handler)
{
RBMTPSrc *src = RB_MTP_SRC (handler);
-
- return src->track_uri;
+ return g_strdup (src->track_uri);
}
static gboolean
-rb_mtp_src_uri_set_uri (GstURIHandler *handler, const gchar *uri)
+rb_mtp_src_uri_set_uri (GstURIHandler *handler, const gchar *uri, GError **error)
{
RBMTPSrc *src = RB_MTP_SRC (handler);
@@ -464,7 +447,7 @@ rb_mtp_src_uri_set_uri (GstURIHandler *handler, const gchar *uri)
}
static void
-rb_mtp_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
+uri_handler_init (gpointer g_iface, gpointer iface_data)
{
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
@@ -473,20 +456,3 @@ rb_mtp_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
iface->get_uri = rb_mtp_src_uri_get_uri;
iface->set_uri = rb_mtp_src_uri_set_uri;
}
-
-static gboolean
-plugin_init (GstPlugin *plugin)
-{
- gboolean ret = gst_element_register (plugin, "rbmtpsrc", GST_RANK_PRIMARY, RB_TYPE_MTP_SRC);
- return ret;
-}
-
-GST_PLUGIN_DEFINE_STATIC (GST_VERSION_MAJOR,
- GST_VERSION_MINOR,
- "rbmtpsrc",
- "element to download and play files from MTP devices",
- plugin_init,
- VERSION,
- "GPL",
- PACKAGE,
- "");
diff --git a/plugins/mtpdevice/rb-mtp-gst.c b/plugins/mtpdevice/rb-mtp-gst.c
new file mode 100644
index 0000000..20b0eb3
--- /dev/null
+++ b/plugins/mtpdevice/rb-mtp-gst.c
@@ -0,0 +1,58 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Jonathan Matthew <jonathan d14n org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The Rhythmbox authors hereby grant permission for non-GPL compatible
+ * GStreamer plugins to be used and distributed together with GStreamer
+ * and Rhythmbox. This permission is above and beyond the permissions granted
+ * by the GPL license by which Rhythmbox is covered. If you modify this code
+ * you may extend this exception to your version of the code, but you are not
+ * obligated to do so. If you do not wish to do so, delete this exception
+ * statement from your version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include "config.h"
+
+#include <gst/gst.h>
+
+#include "rb-mtp-gst.h"
+
+static gboolean
+plugin_init (GstPlugin *plugin)
+{
+ if (gst_element_register (plugin, "rbmtpsrc", GST_RANK_PRIMARY, RB_TYPE_MTP_SRC) == FALSE)
+ return FALSE;
+ if (gst_element_register (plugin, "rbmtpsink", GST_RANK_PRIMARY, RB_TYPE_MTP_SINK) == FALSE)
+ return FALSE;
+ return TRUE;
+}
+
+void
+rb_mtp_gst_init (void)
+{
+ gst_plugin_register_static (GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "rbmtp",
+ "elements for handling files on MTP devices",
+ plugin_init,
+ VERSION,
+ "GPL",
+ PACKAGE,
+ "",
+ "");
+}
diff --git a/plugins/mtpdevice/rb-mtp-gst.h b/plugins/mtpdevice/rb-mtp-gst.h
new file mode 100644
index 0000000..90936f1
--- /dev/null
+++ b/plugins/mtpdevice/rb-mtp-gst.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 Jonathan Matthew <jonathan d14n org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The Rhythmbox authors hereby grant permission for non-GPL compatible
+ * GStreamer plugins to be used and distributed together with GStreamer
+ * and Rhythmbox. This permission is above and beyond the permissions granted
+ * by the GPL license by which Rhythmbox is covered. If you modify this code
+ * you may extend this exception to your version of the code, but you are not
+ * obligated to do so. If you do not wish to do so, delete this exception
+ * statement from your version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#ifndef RB_MTP_GST_H
+#define RB_MTP_GST_H
+
+#define RB_TYPE_MTP_SRC (rb_mtp_src_get_type ())
+#define RB_TYPE_MTP_SINK (rb_mtp_sink_get_type ())
+
+GType rb_mtp_src_get_type (void);
+GType rb_mtp_sink_get_type (void);
+
+void rb_mtp_gst_init (void);
+
+#endif
diff --git a/plugins/mtpdevice/rb-mtp-plugin.c b/plugins/mtpdevice/rb-mtp-plugin.c
index f8fb0ea..b9e46a5 100644
--- a/plugins/mtpdevice/rb-mtp-plugin.c
+++ b/plugins/mtpdevice/rb-mtp-plugin.c
@@ -60,6 +60,7 @@
#include "rb-shell.h"
#include "rb-stock-icons.h"
#include "rb-removable-media-manager.h"
+#include "rb-mtp-gst.h"
#define RB_TYPE_MTP_PLUGIN (rb_mtp_plugin_get_type ())
@@ -501,9 +502,7 @@ peas_register_types (PeasObjectModule *module)
_rb_mtp_source_register_type (G_TYPE_MODULE (module));
_rb_mtp_thread_register_type (G_TYPE_MODULE (module));
- /* ensure the gstreamer elements get linked in */
- rb_mtp_src_get_type ();
- rb_mtp_sink_get_type ();
+ rb_mtp_gst_init ();
peas_object_module_register_extension_type (module,
PEAS_TYPE_ACTIVATABLE,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]