From d7010b9d36fa2d6deb41b83443b4197b84906e2b Mon Sep 17 00:00:00 2001 From: Luis de Bethencourt Date: Tue, 17 May 2011 20:35:49 +0200 Subject: dlna: fix typos --- src/Makefile.am | 4 +- src/dlna.c | 580 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/dlna.h | 143 ++++++++++++++ src/gst_engine.c | 6 - src/mpris.c | 591 ------------------------------------------------------- src/mpris.h | 143 -------------- src/snappy.c | 5 +- 7 files changed, 728 insertions(+), 744 deletions(-) create mode 100644 src/dlna.c create mode 100644 src/dlna.h delete mode 100644 src/mpris.c delete mode 100644 src/mpris.h diff --git a/src/Makefile.am b/src/Makefile.am index f5d5893..93216e2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,14 +3,14 @@ NULL = public_headers = \ utils.h \ user_interface.h \ - mpris.h + dlna.h \ gst_engine.h \ screensaver.h c_sources = \ utils.c \ user_interface.c \ - mpris.c \ + dlna.c \ gst_engine.c \ screensaver.c \ snappy.c diff --git a/src/dlna.c b/src/dlna.c new file mode 100644 index 0000000..20ed99a --- /dev/null +++ b/src/dlna.c @@ -0,0 +1,580 @@ +/* + * snappy - 0.1 beta + * + * Copyright (C) 2011 Collabora Multimedia Ltd. + * + * + * 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, or (at your option) + * any later 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 Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#include +#include + +#include "dlna.h" + +const char *mpris_introspection_xml = + "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; + +/* for now */ +static const GDBusInterfaceVTable interface_vtable = { + (GDBusInterfaceMethodCallFunc) handle_method_call, + (GDBusInterfaceGetPropertyFunc) handle_get_property, + (GDBusInterfaceSetPropertyFunc) handle_set_property +}; + +static const GDBusInterfaceVTable root_vtable = { + (GDBusInterfaceMethodCallFunc) handle_root_method_call, + (GDBusInterfaceGetPropertyFunc) get_root_property, + NULL +}; + +static GDBusNodeInfo *introspection_data = NULL; + +G_DEFINE_TYPE (SnappyMP, my_object, G_TYPE_OBJECT); + +static void +my_object_init (SnappyMP * object) +{ + // g_print ("my_object_init\n"); + + object->name = "snappy"; +} + +static void +my_object_finalize (GObject * object) +{ + SnappyMP *myobj = (SnappyMP *) object; + + g_free (myobj->name); + + G_OBJECT_CLASS (my_object_parent_class)->finalize (object); +} + +static void +my_object_get_property (GObject * object, + guint prop_id, + GValue * value, + GParamSpec * pspec) +{ + SnappyMP *myobj = (SnappyMP *) object; + + switch (prop_id) { + case PROP_NAME: + g_value_set_string (value, myobj->name); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +my_object_set_property (GObject * object, + guint prop_id, + const GValue * value, + GParamSpec * pspec) +{ + SnappyMP *myobj = (SnappyMP *) object; + + switch (prop_id) { + case PROP_NAME: + g_free (myobj->name); + myobj->name = g_value_dup_string (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +my_object_class_init (SnappyMPClass * class) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + + gobject_class->finalize = my_object_finalize; + gobject_class->set_property = my_object_set_property; + gobject_class->get_property = my_object_get_property; + + g_object_class_install_property (gobject_class, + PROP_NAME, + g_param_spec_string ("name", "Name", "Name", NULL, G_PARAM_READWRITE)); + + mediaplayer_signals[OPEN_URI] = + g_signal_newv ("open-uri", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, + NULL, + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0, + NULL); +} + +void +my_object_change_uri (SnappyMP * myobj, gchar * uri) +{ + if (myobj != NULL) + myobj->uri = uri; + + // g_print ("changing uri: %s\n", uri); + g_object_set (G_OBJECT (myobj), "uri", uri, NULL); + + engine_open_uri (myobj->engine, uri); +} + +static void +handle_result (GDBusMethodInvocation * invocation, + gboolean ret, + GError * error) +{ + if (ret) { + g_dbus_method_invocation_return_value (invocation, NULL); + } else { + if (error != NULL) { + g_print ("DLNA returning error: %s", error->message); + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + } else { + g_print ("DLNA returning unknown error"); + g_dbus_method_invocation_return_error_literal (invocation, + G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Unknown error"); + } + } +} + +void +handle_method_call (GDBusConnection * connection, + const gchar * sender, + const gchar * object_path, + const gchar * interface_name, + const gchar * method_name, + GVariant * parameters, + GDBusMethodInvocation * invocation, + SnappyMP * myobj) +{ + gboolean ret = TRUE; + GError *error = NULL; + + // g_print ("handle_method_call: %s\n", method_name); + + if (g_strcmp0 (object_path, MPRIS_OBJECT_NAME) != 0 || + g_strcmp0 (interface_name, MPRIS_PLAYER_INTERFACE) != 0) { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_NOT_SUPPORTED, + "Method %s.%s not supported", + interface_name, + method_name); + return; + } + + if (g_strcmp0 (method_name, "OpenUri") == 0) { + gchar *uri; + + g_variant_get (parameters, "(s)", &uri); + my_object_change_uri (myobj, uri); + + g_dbus_method_invocation_return_value (invocation, NULL); + + } else if (g_strcmp0 (method_name, "Next") == 0) { + /// ToDo: next track call + + handle_result (invocation, ret, error); + } else if (g_strcmp0 (method_name, "Play") == 0) { + engine_play (myobj->engine); + + handle_result (invocation, ret, error); + } else if (g_strcmp0 (method_name, "Stop") == 0) { + engine_stop (myobj->engine); + + handle_result (invocation, ret, error); + } + +} + +GVariant * +handle_get_property (GDBusConnection * connection, + const gchar * sender, + const gchar * object_path, + const gchar * interface_name, + const gchar * property_name, GError ** error, gpointer user_data) +{ + GVariant *ret; + SnappyMP *myobj = user_data; + + // g_print ("handle_get_property: %s\n", property_name); + + ret = NULL; + if (g_strcmp0 (property_name, "Name") == 0) { + //ret = g_variant_new_string (myobj->name ? myobj->name : ""); + ret = g_variant_new_string ("snappy"); + + } else if (g_strcmp0 (property_name, "PlaybackStatus") == 0) { + ret = g_variant_new_string ("Paused"); + } else if (g_strcmp0 (property_name, "LoopStatus") == 0) { + ret = g_variant_new_string ("Paused"); + } else if (g_strcmp0 (property_name, "Rate") == 0) { + ret = g_variant_new_double (0); + } else if (g_strcmp0 (property_name, "Shuffle") == 0) { + ret = g_variant_new_boolean (FALSE); + } else if (g_strcmp0 (property_name, "Metadata") == 0) { + const char *strv[] = { "", NULL }; + ret = g_variant_new_strv (strv, -1); + } else if (g_strcmp0 (property_name, "Volume") == 0) { + ret = g_variant_new_double (0); + } else if (g_strcmp0 (property_name, "Position") == 0) { + ret = g_variant_new_double (0); + } else if (g_strcmp0 (property_name, "MinimumRate") == 0) { + ret = g_variant_new_double (0); + } else if (g_strcmp0 (property_name, "MaximumRate") == 0) { + ret = g_variant_new_double (0); + } else if (g_strcmp0 (property_name, "CanGoNext") == 0) { + ret = g_variant_new_boolean (FALSE); + } else if (g_strcmp0 (property_name, "CanGoPrevious") == 0) { + ret = g_variant_new_boolean (FALSE); + } else if (g_strcmp0 (property_name, "CanPlay") == 0) { + ret = g_variant_new_boolean (FALSE); + } else if (g_strcmp0 (property_name, "CanPause") == 0) { + ret = g_variant_new_boolean (FALSE); + } else if (g_strcmp0 (property_name, "CanSeek") == 0) { + ret = g_variant_new_boolean (FALSE); + } else if (g_strcmp0 (property_name, "CanControl") == 0) { + ret = g_variant_new_boolean (FALSE); + + } else if (g_strcmp0 (property_name, "Identity") == 0) { + return g_variant_new_string ("snappy"); + } else if (g_strcmp0 (property_name, "SupportedUriSchemes") == 0) { + /* not planning to support this seriously */ + const char *fake_supported_schemes[] = { + "file", "http", "cdda", "smb", "sftp", NULL + }; + return g_variant_new_strv (fake_supported_schemes, -1); + } else if (g_strcmp0 (property_name, "SupportedMimeTypes") == 0) { + /* nor this */ + const char *fake_supported_mimetypes[] = { + "application/ogg", "audio/x-vorbis+ogg", "audio/x-flac", "audio/mpeg", + NULL + }; + return g_variant_new_strv (fake_supported_mimetypes, -1); + } + + return ret; +} + +gboolean +handle_set_property (GDBusConnection * connection, + const gchar * sender, + const gchar * object_path, + const gchar * interface_name, + const gchar * property_name, + GVariant * value, GError ** error, gpointer user_data) +{ + SnappyMP *myobj = user_data; + + if (g_strcmp0 (property_name, "Name") == 0) { + g_object_set (myobj, "name", g_variant_get_string (value, NULL), NULL); + } + + return TRUE; +} + +void +handle_root_method_call (GDBusConnection * connection, + const char *sender, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant * parameters, + GDBusMethodInvocation * invocation, SnappyMP * mp) +{ + if (g_strcmp0 (object_path, MPRIS_OBJECT_NAME) != 0 || + g_strcmp0 (interface_name, MPRIS_ROOT_INTERFACE) != 0) { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_NOT_SUPPORTED, + "Method %s.%s not supported", interface_name, method_name); + return; + } + + if (g_strcmp0 (method_name, "Raise") == 0) { + g_dbus_method_invocation_return_value (invocation, NULL); + } else if (g_strcmp0 (method_name, "Quit") == 0) { + g_dbus_method_invocation_return_value (invocation, NULL); + } else { + g_dbus_method_invocation_return_error (invocation, + G_DBUS_ERROR, + G_DBUS_ERROR_NOT_SUPPORTED, + "Method %s.%s not supported", interface_name, method_name); + } +} + +GVariant * +get_root_property (GDBusConnection * connection, + const char *sender, + const char *object_path, + const char *interface_name, + const char *property_name, GError ** error, SnappyMP * mp) +{ + // g_print ("get_root_property: %s\n", property_name); + + if (g_strcmp0 (object_path, MPRIS_OBJECT_NAME) != 0 || + g_strcmp0 (interface_name, MPRIS_ROOT_INTERFACE) != 0) { + g_set_error (error, + G_DBUS_ERROR, + G_DBUS_ERROR_NOT_SUPPORTED, + "Property %s.%s not supported", interface_name, property_name); + return NULL; + } + + if (g_strcmp0 (property_name, "CanQuit") == 0) { + return g_variant_new_boolean (TRUE); + } else if (g_strcmp0 (property_name, "CanRaise") == 0) { + return g_variant_new_boolean (TRUE); + } else if (g_strcmp0 (property_name, "HasTrackList") == 0) { + return g_variant_new_boolean (FALSE); + } else if (g_strcmp0 (property_name, "Identity") == 0) { + return g_variant_new_string ("snappy"); + } else if (g_strcmp0 (property_name, "DesktopEntry") == 0) { + GVariant *v = NULL; + char *path; + return v; + } else if (g_strcmp0 (property_name, "SupportedUriSchemes") == 0) { + /* not planning to support this seriously */ + const char *fake_supported_schemes[] = { + "file", "http", "cdda", "smb", "sftp", NULL + }; + return g_variant_new_strv (fake_supported_schemes, -1); + } else if (g_strcmp0 (property_name, "SupportedMimeTypes") == 0) { + /* nor this */ + const char *fake_supported_mimetypes[] = { + "application/ogg", "audio/x-vorbis+ogg", "audio/x-flac", "audio/mpeg", + NULL + }; + return g_variant_new_strv (fake_supported_mimetypes, -1); + } + + g_set_error (error, + G_DBUS_ERROR, + G_DBUS_ERROR_NOT_SUPPORTED, + "Property %s.%s not supported", interface_name, property_name); + return NULL; +} + +static void +send_property_change (GObject * obj, + GParamSpec * pspec, + GDBusConnection * connection) +{ + + GVariantBuilder *builder; + GVariantBuilder *invalidated_builder; + SnappyMP *myobj = (SnappyMP *) obj; + + builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY); + invalidated_builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + + if (g_strcmp0 (pspec->name, "name") == 0) + g_variant_builder_add (builder, + "{sv}", "Name", g_variant_new_string (myobj->name ? myobj->name : "")); + + // g_print ("some property changed %s\n", pspec->name); + + g_dbus_connection_emit_signal (connection, + NULL, + "org/mpris/MediaPlayer2", + "org.freedesktop.DBus.Properties", + "PropertiesChanged", + g_variant_new ("(sa{sv}as)", + "org.mpris.MediaPlayer2", builder, invalidated_builder), NULL); +} + +static void +on_name_acquired (GDBusConnection * connection, + const gchar * name, + gpointer user_data) +{ + // g_print ("DLNA MediaPlayer name acquired.\n"); +} + +static void +on_name_lost (GDBusConnection * connection, + const gchar * name, + gpointer user_data) +{ + exit (1); +} + +gboolean +load_dlna (SnappyMP *mp) +{ + guint owner_id, player_id, root_id; + GError *error = NULL; + GDBusInterfaceInfo *ifaceinfo; + GDBusConnection *connection; + + g_type_init (); + + connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); + + /* Build the introspection data structures from the XML */ + introspection_data = + g_dbus_node_info_new_for_xml (mpris_introspection_xml, NULL); + g_assert (introspection_data != NULL); + + /* register media player interface */ + ifaceinfo = + g_dbus_node_info_lookup_interface (introspection_data, + MPRIS_PLAYER_INTERFACE); + mp->player_id = + g_dbus_connection_register_object (connection, MPRIS_OBJECT_NAME, + ifaceinfo, &interface_vtable, mp, NULL, &error); + + /* register root interface */ + ifaceinfo = + g_dbus_node_info_lookup_interface (introspection_data, + MPRIS_ROOT_INTERFACE); + mp->root_id = + g_dbus_connection_register_object (connection, MPRIS_OBJECT_NAME, + ifaceinfo, &root_vtable, NULL, NULL, &error); + if (error != NULL) { + g_warning ("unable to register MPRIS root interface: %s", error->message); + g_error_free (error); + } + + mp->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, + "org.mpris.MediaPlayer2.snappy", + G_BUS_NAME_OWNER_FLAGS_NONE, + NULL, + (GBusNameAcquiredCallback) on_name_acquired, + (GBusNameLostCallback) on_name_lost, + g_object_ref (mp), + g_object_unref); + g_assert (mp->owner_id > 0); + + return TRUE; +} + +gboolean +close_dlna (SnappyMP *mp) +{ + g_bus_unown_name (mp->owner_id); + + g_dbus_node_info_unref (introspection_data); + + g_object_unref (mp); + + return TRUE; +} diff --git a/src/dlna.h b/src/dlna.h new file mode 100644 index 0000000..159c62f --- /dev/null +++ b/src/dlna.h @@ -0,0 +1,143 @@ +/* + * snappy - 0.1 beta + * + * Copyright (C) 2011 Collabora Multimedia Ltd. + * + * + * 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, or (at your option) + * any later 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 Street, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#ifndef __DLNA_H__ +#define __DLNA_H__ + +#include +#include + +#include "gst_engine.h" + +G_BEGIN_DECLS + +#define MPRIS_BUS_NAME_PREFIX "org.mpris.MediaPlayer2" +#define MPRIS_OBJECT_NAME "/org/mpris/MediaPlayer2" + +#define MPRIS_ROOT_INTERFACE "org.mpris.MediaPlayer2" +#define MPRIS_PLAYER_INTERFACE "org.mpris.MediaPlayer2.Player" +#define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList" +#define MPRIS_PLAYLISTS_INTERFACE "org.mpris.MediaPlayer2.Playlists" + +#define SNAPPY_TYPE_MP (snappy_mp_get_type ()) +#define SNAPPY_MP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SNAPPY_TYPE_MP, SnappyMP)) +#define SNAPPY_IS_MP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SNAPPY_TYPE_MP)) +#define SNAPPY_MP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SNAPPY_TYPE_MP, SnappyMPClass)) +#define SNAPPY_IS_MP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SNAPPY_TYPE_MP)) +#define SNAPPY_MP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SNAPPY_TYPE_MP, SnappyMPClass)) + +/* The object we want to export */ +typedef struct _SnappyMP SnappyMP; +typedef struct _SnappyMPClass SnappyMPClass; + +struct _SnappyMP +{ + GObject parent_instance; + + gchar *name; + + GDBusConnection *connection; + GDBusNodeInfo *node_info; + guint name_own_id; + guint root_id; + guint player_id; + guint playlists_id; + guint owner_id; + + int playlist_count; + + GHashTable *player_property_changes; + GHashTable *playlist_property_changes; + guint property_emit_id; + + gint64 last_elapsed; + + gchar *uri; + + GstEngine *engine; +}; + +struct _SnappyMPClass +{ + GObjectClass parent_class; +}; + +/* used by SNAPPY_TYPE_MP */ +GType snappy_mp_get_type(); + +enum +{ + PROP_0, + PROP_COUNT, + PROP_NAME +}; + +enum { + OPEN_URI, + LAST_SIGNAL +}; + +static guint +mediaplayer_signals[LAST_SIGNAL] = { 0 }; + +// Declaration of non-static functions +gboolean load_dlna (SnappyMP *mp_obj); +gboolean close_dlna (SnappyMP *mp_obj); + +void handle_method_call (GDBusConnection * connection, + const gchar * sender, + const gchar * object_path, + const gchar * interface_name, + const gchar * method_name, + GVariant * parameters, + GDBusMethodInvocation * invocation, SnappyMP * myobj); + +GVariant * handle_get_property (GDBusConnection * connection, + const gchar * sender, + const gchar * object_path, + const gchar * interface_name, + const gchar * property_name, GError ** error, gpointer user_data); + +gboolean handle_set_property (GDBusConnection * connection, + const gchar * sender, + const gchar * object_path, + const gchar * interface_name, + const gchar * property_name, + GVariant * value, GError ** error, gpointer user_data); + +void handle_root_method_call (GDBusConnection * connection, + const char *sender, + const char *object_path, + const char *interface_name, + const char *method_name, + GVariant * parameters, + GDBusMethodInvocation * invocation, SnappyMP * mp); + +GVariant * get_root_property (GDBusConnection * connection, + const char *sender, + const char *object_path, + const char *interface_name, + const char *property_name, GError ** error, SnappyMP * mp); + + +G_END_DECLS +#endif /* __DLNA_H__ */ diff --git a/src/gst_engine.c b/src/gst_engine.c index f31a4ae..621dd08 100644 --- a/src/gst_engine.c +++ b/src/gst_engine.c @@ -402,8 +402,6 @@ engine_load_uri (GstEngine * engine, gchar * uri) gboolean engine_open_uri (GstEngine * engine, gchar * uri) { - g_print ("opennning uriii! %s \n", uri); - g_object_set (G_OBJECT (engine->player), "uri", uri, NULL); gst_element_set_state (engine->player, GST_STATE_READY); @@ -413,8 +411,6 @@ engine_open_uri (GstEngine * engine, gchar * uri) gboolean engine_play (GstEngine * engine) { - g_print ("Plaaayingg\n"); - gst_element_set_state (engine->player, GST_STATE_PLAYING); return TRUE; @@ -423,8 +419,6 @@ engine_play (GstEngine * engine) gboolean engine_stop (GstEngine * engine) { - g_print ("Stopping\n"); - gst_element_set_state (engine->player, GST_STATE_READY); return TRUE; diff --git a/src/mpris.c b/src/mpris.c deleted file mode 100644 index 0559954..0000000 --- a/src/mpris.c +++ /dev/null @@ -1,591 +0,0 @@ -/* - * snappy - 0.1 beta - * - * Copyright (C) 2011 Collabora Multimedia Ltd. - * - * - * 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, or (at your option) - * any later 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 Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ - -#include -#include - -#include "mpris.h" - -const char *mpris_introspection_xml = - "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - ""; - -/* for now */ -static const GDBusInterfaceVTable interface_vtable = { - (GDBusInterfaceMethodCallFunc) handle_method_call, - (GDBusInterfaceGetPropertyFunc) handle_get_property, - (GDBusInterfaceSetPropertyFunc) handle_set_property -}; - -static const GDBusInterfaceVTable root_vtable = { - (GDBusInterfaceMethodCallFunc) handle_root_method_call, - (GDBusInterfaceGetPropertyFunc) get_root_property, - NULL -}; - -static GDBusNodeInfo *introspection_data = NULL; - -G_DEFINE_TYPE (SnappyMP, my_object, G_TYPE_OBJECT); - -static void -my_object_init (SnappyMP * object) -{ - g_print ("my_object_init\n"); - - object->name = "snappy"; -} - -static void -my_object_finalize (GObject * object) -{ - SnappyMP *myobj = (SnappyMP *) object; - - g_free (myobj->name); - - G_OBJECT_CLASS (my_object_parent_class)->finalize (object); -} - -static void -my_object_get_property (GObject * object, - guint prop_id, - GValue * value, - GParamSpec * pspec) -{ - SnappyMP *myobj = (SnappyMP *) object; - - g_print ("my_object_get_property\n"); - - switch (prop_id) { - case PROP_NAME: - g_value_set_string (value, myobj->name); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -my_object_set_property (GObject * object, - guint prop_id, - const GValue * value, - GParamSpec * pspec) -{ - SnappyMP *myobj = (SnappyMP *) object; - - g_print ("my_object_set_property\n"); - - switch (prop_id) { - case PROP_NAME: - g_free (myobj->name); - myobj->name = g_value_dup_string (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -my_object_class_init (SnappyMPClass * class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (class); - - g_print ("my_object_class_init\n"); - - gobject_class->finalize = my_object_finalize; - gobject_class->set_property = my_object_set_property; - gobject_class->get_property = my_object_get_property; - - g_object_class_install_property (gobject_class, - PROP_NAME, - g_param_spec_string ("name", "Name", "Name", NULL, G_PARAM_READWRITE)); - - mediaplayer_signals[OPEN_URI] = - g_signal_newv ("open-uri", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - NULL, - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0, - NULL); -} - -void -my_object_change_uri (SnappyMP * myobj, gchar * uri) -{ - g_print ("my_object_change_uri\n"); - if (myobj == NULL) - g_print ("object is NULL\n"); - myobj->uri = uri; - - g_print ("changing uri: %s\n", uri); - g_object_set (G_OBJECT (myobj), "uri", uri, NULL); - - engine_open_uri (myobj->engine, uri); -} - -static void -handle_result (GDBusMethodInvocation * invocation, - gboolean ret, - GError * error) -{ - if (ret) { - g_dbus_method_invocation_return_value (invocation, NULL); - } else { - if (error != NULL) { - g_print ("returning error: %s", error->message); - g_dbus_method_invocation_return_gerror (invocation, error); - g_error_free (error); - } else { - g_print ("returning unknown error"); - g_dbus_method_invocation_return_error_literal (invocation, - G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Unknown error"); - } - } -} - -void -handle_method_call (GDBusConnection * connection, - const gchar * sender, - const gchar * object_path, - const gchar * interface_name, - const gchar * method_name, - GVariant * parameters, - GDBusMethodInvocation * invocation, - SnappyMP * myobj) -{ - gboolean ret = TRUE; - GError *error = NULL; - - g_print ("handle_method_call: %s\n", method_name); - - if (g_strcmp0 (object_path, MPRIS_OBJECT_NAME) != 0 || - g_strcmp0 (interface_name, MPRIS_PLAYER_INTERFACE) != 0) { - g_dbus_method_invocation_return_error (invocation, - G_DBUS_ERROR, - G_DBUS_ERROR_NOT_SUPPORTED, - "Method %s.%s not supported", - interface_name, - method_name); - return; - } - - if (g_strcmp0 (method_name, "OpenUri") == 0) { - gchar *uri; - - g_variant_get (parameters, "(s)", &uri); - my_object_change_uri (myobj, uri); - - g_dbus_method_invocation_return_value (invocation, NULL); - - } else if (g_strcmp0 (method_name, "Next") == 0) { - /// ToDo: next track call - - handle_result (invocation, ret, error); - } else if (g_strcmp0 (method_name, "Play") == 0) { - engine_play (myobj->engine); - - handle_result (invocation, ret, error); - } else if (g_strcmp0 (method_name, "Stop") == 0) { - engine_stop (myobj->engine); - - handle_result (invocation, ret, error); - } - -} - -GVariant * -handle_get_property (GDBusConnection * connection, - const gchar * sender, - const gchar * object_path, - const gchar * interface_name, - const gchar * property_name, GError ** error, gpointer user_data) -{ - GVariant *ret; - SnappyMP *myobj = user_data; - - // g_print ("handle_get_property: %s\n", property_name); - - ret = NULL; - if (g_strcmp0 (property_name, "Name") == 0) { - //ret = g_variant_new_string (myobj->name ? myobj->name : ""); - ret = g_variant_new_string ("snappy"); - - } else if (g_strcmp0 (property_name, "PlaybackStatus") == 0) { - ret = g_variant_new_string ("Paused"); - } else if (g_strcmp0 (property_name, "LoopStatus") == 0) { - ret = g_variant_new_string ("Paused"); - } else if (g_strcmp0 (property_name, "Rate") == 0) { - ret = g_variant_new_double (0); - } else if (g_strcmp0 (property_name, "Shuffle") == 0) { - ret = g_variant_new_boolean (FALSE); - } else if (g_strcmp0 (property_name, "Metadata") == 0) { - const char *strv[] = { "", NULL }; - ret = g_variant_new_strv (strv, -1); - } else if (g_strcmp0 (property_name, "Volume") == 0) { - ret = g_variant_new_double (0); - } else if (g_strcmp0 (property_name, "Position") == 0) { - ret = g_variant_new_double (0); - } else if (g_strcmp0 (property_name, "MinimumRate") == 0) { - ret = g_variant_new_double (0); - } else if (g_strcmp0 (property_name, "MaximumRate") == 0) { - ret = g_variant_new_double (0); - } else if (g_strcmp0 (property_name, "CanGoNext") == 0) { - ret = g_variant_new_boolean (FALSE); - } else if (g_strcmp0 (property_name, "CanGoPrevious") == 0) { - ret = g_variant_new_boolean (FALSE); - } else if (g_strcmp0 (property_name, "CanPlay") == 0) { - ret = g_variant_new_boolean (FALSE); - } else if (g_strcmp0 (property_name, "CanPause") == 0) { - ret = g_variant_new_boolean (FALSE); - } else if (g_strcmp0 (property_name, "CanSeek") == 0) { - ret = g_variant_new_boolean (FALSE); - } else if (g_strcmp0 (property_name, "CanControl") == 0) { - ret = g_variant_new_boolean (FALSE); - - } else if (g_strcmp0 (property_name, "Identity") == 0) { - return g_variant_new_string ("snappy"); - } else if (g_strcmp0 (property_name, "SupportedUriSchemes") == 0) { - /* not planning to support this seriously */ - const char *fake_supported_schemes[] = { - "file", "http", "cdda", "smb", "sftp", NULL - }; - return g_variant_new_strv (fake_supported_schemes, -1); - } else if (g_strcmp0 (property_name, "SupportedMimeTypes") == 0) { - /* nor this */ - const char *fake_supported_mimetypes[] = { - "application/ogg", "audio/x-vorbis+ogg", "audio/x-flac", "audio/mpeg", - NULL - }; - return g_variant_new_strv (fake_supported_mimetypes, -1); - } - - return ret; -} - -gboolean -handle_set_property (GDBusConnection * connection, - const gchar * sender, - const gchar * object_path, - const gchar * interface_name, - const gchar * property_name, - GVariant * value, GError ** error, gpointer user_data) -{ - SnappyMP *myobj = user_data; - - g_print ("handle_set_property\n"); - - if (g_strcmp0 (property_name, "Name") == 0) { - g_object_set (myobj, "name", g_variant_get_string (value, NULL), NULL); - } - - return TRUE; -} - -void -handle_root_method_call (GDBusConnection * connection, - const char *sender, - const char *object_path, - const char *interface_name, - const char *method_name, - GVariant * parameters, - GDBusMethodInvocation * invocation, SnappyMP * mp) -{ - if (g_strcmp0 (object_path, MPRIS_OBJECT_NAME) != 0 || - g_strcmp0 (interface_name, MPRIS_ROOT_INTERFACE) != 0) { - g_dbus_method_invocation_return_error (invocation, - G_DBUS_ERROR, - G_DBUS_ERROR_NOT_SUPPORTED, - "Method %s.%s not supported", interface_name, method_name); - return; - } - - if (g_strcmp0 (method_name, "Raise") == 0) { - g_dbus_method_invocation_return_value (invocation, NULL); - } else if (g_strcmp0 (method_name, "Quit") == 0) { - g_dbus_method_invocation_return_value (invocation, NULL); - } else { - g_dbus_method_invocation_return_error (invocation, - G_DBUS_ERROR, - G_DBUS_ERROR_NOT_SUPPORTED, - "Method %s.%s not supported", interface_name, method_name); - } -} - -GVariant * -get_root_property (GDBusConnection * connection, - const char *sender, - const char *object_path, - const char *interface_name, - const char *property_name, GError ** error, SnappyMP * mp) -{ - g_print ("get_root_property: %s\n", property_name); - - if (g_strcmp0 (object_path, MPRIS_OBJECT_NAME) != 0 || - g_strcmp0 (interface_name, MPRIS_ROOT_INTERFACE) != 0) { - g_set_error (error, - G_DBUS_ERROR, - G_DBUS_ERROR_NOT_SUPPORTED, - "Property %s.%s not supported", interface_name, property_name); - return NULL; - } - - if (g_strcmp0 (property_name, "CanQuit") == 0) { - return g_variant_new_boolean (TRUE); - } else if (g_strcmp0 (property_name, "CanRaise") == 0) { - return g_variant_new_boolean (TRUE); - } else if (g_strcmp0 (property_name, "HasTrackList") == 0) { - return g_variant_new_boolean (FALSE); - } else if (g_strcmp0 (property_name, "Identity") == 0) { - return g_variant_new_string ("snappy"); - } else if (g_strcmp0 (property_name, "DesktopEntry") == 0) { - GVariant *v = NULL; - char *path; - return v; - } else if (g_strcmp0 (property_name, "SupportedUriSchemes") == 0) { - /* not planning to support this seriously */ - const char *fake_supported_schemes[] = { - "file", "http", "cdda", "smb", "sftp", NULL - }; - return g_variant_new_strv (fake_supported_schemes, -1); - } else if (g_strcmp0 (property_name, "SupportedMimeTypes") == 0) { - /* nor this */ - const char *fake_supported_mimetypes[] = { - "application/ogg", "audio/x-vorbis+ogg", "audio/x-flac", "audio/mpeg", - NULL - }; - return g_variant_new_strv (fake_supported_mimetypes, -1); - } - - g_set_error (error, - G_DBUS_ERROR, - G_DBUS_ERROR_NOT_SUPPORTED, - "Property %s.%s not supported", interface_name, property_name); - return NULL; -} - -static void -send_property_change (GObject * obj, - GParamSpec * pspec, - GDBusConnection * connection) -{ - g_print ("send_property_change\n"); - - GVariantBuilder *builder; - GVariantBuilder *invalidated_builder; - SnappyMP *myobj = (SnappyMP *) obj; - - builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY); - invalidated_builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - - if (g_strcmp0 (pspec->name, "name") == 0) - g_variant_builder_add (builder, - "{sv}", "Name", g_variant_new_string (myobj->name ? myobj->name : "")); - - g_print ("some property changed %s\n", pspec->name); - - g_dbus_connection_emit_signal (connection, - NULL, - "org/mpris/MediaPlayer2", - "org.freedesktop.DBus.Properties", - "PropertiesChanged", - g_variant_new ("(sa{sv}as)", - "org.mpris.MediaPlayer2", builder, invalidated_builder), NULL); -} - -static void -on_name_acquired (GDBusConnection * connection, - const gchar * name, - gpointer user_data) -{ - g_print ("on_name_acquired\n"); -} - -static void -on_name_lost (GDBusConnection * connection, - const gchar * name, - gpointer user_data) -{ - exit (1); -} - -gboolean -load_mpris (SnappyMP *mp) -{ - guint owner_id, player_id, root_id; - GError *error = NULL; - GDBusInterfaceInfo *ifaceinfo; - GDBusConnection *connection; - - g_type_init (); - - connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); - - /* Build the introspection data structures from the XML */ - introspection_data = - g_dbus_node_info_new_for_xml (mpris_introspection_xml, NULL); - g_assert (introspection_data != NULL); - - /* register media player interface */ - ifaceinfo = - g_dbus_node_info_lookup_interface (introspection_data, - MPRIS_PLAYER_INTERFACE); - mp->player_id = - g_dbus_connection_register_object (connection, MPRIS_OBJECT_NAME, - ifaceinfo, &interface_vtable, mp, NULL, &error); - - /* register root interface */ - ifaceinfo = - g_dbus_node_info_lookup_interface (introspection_data, - MPRIS_ROOT_INTERFACE); - mp->root_id = - g_dbus_connection_register_object (connection, MPRIS_OBJECT_NAME, - ifaceinfo, &root_vtable, NULL, NULL, &error); - if (error != NULL) { - g_warning ("unable to register MPRIS root interface: %s", error->message); - g_error_free (error); - } - - mp->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, - "org.mpris.MediaPlayer2.snappy", - G_BUS_NAME_OWNER_FLAGS_NONE, - NULL, - (GBusNameAcquiredCallback) on_name_acquired, - (GBusNameLostCallback) on_name_lost, - g_object_ref (mp), - g_object_unref); - g_assert (mp->owner_id > 0); - - return TRUE; -} - -gboolean -close_mpris (SnappyMP *mp) -{ - g_bus_unown_name (mp->owner_id); - - g_dbus_node_info_unref (introspection_data); - - g_object_unref (mp); - - return TRUE; -} diff --git a/src/mpris.h b/src/mpris.h deleted file mode 100644 index dd290b7..0000000 --- a/src/mpris.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * snappy - 0.1 beta - * - * Copyright (C) 2011 Collabora Multimedia Ltd. - * - * - * 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, or (at your option) - * any later 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 Street, Fifth Floor, Boston, MA 02110-1301 - * USA - */ - -#ifndef __MPRIS_H__ -#define __MPRIS_H__ - -#include -#include - -#include "gst_engine.h" - -G_BEGIN_DECLS - -#define MPRIS_BUS_NAME_PREFIX "org.mpris.MediaPlayer2" -#define MPRIS_OBJECT_NAME "/org/mpris/MediaPlayer2" - -#define MPRIS_ROOT_INTERFACE "org.mpris.MediaPlayer2" -#define MPRIS_PLAYER_INTERFACE "org.mpris.MediaPlayer2.Player" -#define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList" -#define MPRIS_PLAYLISTS_INTERFACE "org.mpris.MediaPlayer2.Playlists" - -#define SNAPPY_TYPE_MP (snappy_mp_get_type ()) -#define SNAPPY_MP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SNAPPY_TYPE_MP, SnappyMP)) -#define SNAPPY_IS_MP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SNAPPY_TYPE_MP)) -#define SNAPPY_MP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SNAPPY_TYPE_MP, SnappyMPClass)) -#define SNAPPY_IS_MP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SNAPPY_TYPE_MP)) -#define SNAPPY_MP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SNAPPY_TYPE_MP, SnappyMPClass)) - -/* The object we want to export */ -typedef struct _SnappyMP SnappyMP; -typedef struct _SnappyMPClass SnappyMPClass; - -struct _SnappyMP -{ - GObject parent_instance; - - gchar *name; - - GDBusConnection *connection; - GDBusNodeInfo *node_info; - guint name_own_id; - guint root_id; - guint player_id; - guint playlists_id; - guint owner_id; - - int playlist_count; - - GHashTable *player_property_changes; - GHashTable *playlist_property_changes; - guint property_emit_id; - - gint64 last_elapsed; - - gchar *uri; - - GstEngine *engine; -}; - -struct _SnappyMPClass -{ - GObjectClass parent_class; -}; - -/* used by SNAPPY_TYPE_MP */ -GType snappy_mp_get_type(); - -enum -{ - PROP_0, - PROP_COUNT, - PROP_NAME -}; - -enum { - OPEN_URI, - LAST_SIGNAL -}; - -static guint -mediaplayer_signals[LAST_SIGNAL] = { 0 }; - -// Declaration of non-static functions -gboolean load_mpris (SnappyMP *mp_obj); -gboolean close_mpris (SnappyMP *mp_obj); - -void handle_method_call (GDBusConnection * connection, - const gchar * sender, - const gchar * object_path, - const gchar * interface_name, - const gchar * method_name, - GVariant * parameters, - GDBusMethodInvocation * invocation, SnappyMP * myobj); - -GVariant * handle_get_property (GDBusConnection * connection, - const gchar * sender, - const gchar * object_path, - const gchar * interface_name, - const gchar * property_name, GError ** error, gpointer user_data); - -gboolean handle_set_property (GDBusConnection * connection, - const gchar * sender, - const gchar * object_path, - const gchar * interface_name, - const gchar * property_name, - GVariant * value, GError ** error, gpointer user_data); - -void handle_root_method_call (GDBusConnection * connection, - const char *sender, - const char *object_path, - const char *interface_name, - const char *method_name, - GVariant * parameters, - GDBusMethodInvocation * invocation, SnappyMP * mp); - -GVariant * get_root_property (GDBusConnection * connection, - const char *sender, - const char *object_path, - const char *interface_name, - const char *property_name, GError ** error, SnappyMP * mp); - - -G_END_DECLS -#endif /* __MPRIS_H__ */ diff --git a/src/snappy.c b/src/snappy.c index c110f7b..0f28248 100644 --- a/src/snappy.c +++ b/src/snappy.c @@ -29,7 +29,7 @@ #include #include "user_interface.h" -#include "mpris.h" +#include "dlna.h" #include "gst_engine.h" #include "utils.h" @@ -139,6 +139,7 @@ main (int argc, char *argv[]) { UserInterface *ui = NULL; GstEngine *engine = NULL; + SnappyMP *mp_obj = NULL; ClutterActor *video_texture; GstElement *sink; @@ -196,7 +197,7 @@ main (int argc, char *argv[]) mp_obj = g_new (SnappyMP, 1); mp_obj->engine = engine; - load_mpris (mp_obj); + load_dlna (mp_obj); // g_signal_connect (mp_obj, "open-uri", // G_CALLBACK (open_uri_callback), engine); -- cgit v1.2.3