rygel r377 - in trunk: . src/plugins src/plugins/dvb



Author: zeeshanak
Date: Thu Dec 25 12:00:35 2008
New Revision: 377
URL: http://svn.gnome.org/viewvc/rygel?rev=377&view=rev

Log:
Add DVB plugin.

Right now it only builds, haven't tested because of broken python jhbuild.

Added:
   trunk/src/plugins/dvb/
   trunk/src/plugins/dvb/Makefile.am
   trunk/src/plugins/dvb/rygel-dvb-channel-group.vala
   trunk/src/plugins/dvb/rygel-dvb-channel.vala
   trunk/src/plugins/dvb/rygel-dvb-content-dir.vala
   trunk/src/plugins/dvb/rygel-dvb-plugin.vala
Modified:
   trunk/configure.ac
   trunk/src/plugins/Makefile.am

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Thu Dec 25 12:00:35 2008
@@ -125,6 +125,7 @@
 src/Makefile
 src/rygel/Makefile
 src/plugins/Makefile
+src/plugins/dvb/Makefile
 src/plugins/tracker/Makefile
 src/plugins/test/Makefile
 data/Makefile

Modified: trunk/src/plugins/Makefile.am
==============================================================================
--- trunk/src/plugins/Makefile.am	(original)
+++ trunk/src/plugins/Makefile.am	Thu Dec 25 12:00:35 2008
@@ -1,7 +1,7 @@
 if BUILD_TEST_PLUGIN
-SUBDIRS = tracker test
+SUBDIRS = tracker dvb test
 else
-SUBDIRS = tracker
+SUBDIRS = tracker dvb
 endif
 
 MAINTAINERCLEANFILES = Makefile.in

Added: trunk/src/plugins/dvb/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/src/plugins/dvb/Makefile.am	Thu Dec 25 12:00:35 2008
@@ -0,0 +1,49 @@
+plugindir = $(libdir)/rygel-1.0
+
+plugin_LTLIBRARIES = librygel-dvb.la
+
+AM_CFLAGS = $(LIBGUPNP_CFLAGS) \
+	    $(LIBGUPNP_AV_CFLAGS) \
+	    $(LIBDBUS_GLIB_CFLAGS) \
+	    $(GEE_CFLAGS) \
+	    $(LIBGSTREAMER_CFLAGS) \
+	    -I$(top_srcdir)/src/rygel -DDATA_DIR='"$(datadir)"'
+
+BUILT_SOURCES = rygel-dvb.stamp \
+		rygel-dvb-content-dir.h \
+		rygel-dvb-content-dir.c \
+		rygel-dvb-channel-group.h \
+		rygel-dvb-channel-group.c \
+		rygel-dvb-channel.h \
+		rygel-dvb-channel.c \
+		rygel-dvb-plugin.h \
+		rygel-dvb-plugin.c
+
+librygel_dvb_la_SOURCES = rygel-dvb-content-dir.h \
+			  rygel-dvb-content-dir.c \
+                          rygel-dvb-content-dir.vala \
+                          rygel-dvb-channel-group.h \
+                          rygel-dvb-channel-group.c \
+                          rygel-dvb-channel-group.vala \
+                          rygel-dvb-channel.h \
+                          rygel-dvb-channel.c \
+                          rygel-dvb-channel.vala \
+                          rygel-dvb-plugin.h \
+                          rygel-dvb-plugin.c \
+                          rygel-dvb-plugin.vala
+
+rygel-dvb.stamp: $(filter %.vala,$(librygel_dvb_la_SOURCES))
+	$(VALAC) -C --vapidir=$(top_srcdir)/src/rygel \
+	--pkg rygel-1.0 --pkg cstuff \
+	--pkg gupnp-1.0 --pkg gupnp-av-1.0 --pkg dbus-glib-1 --pkg gee-1.0 $^
+	touch $@
+
+librygel_dvb_la_LIBADD = $(LIBGUPNP_LIBS) \
+                         $(LIBGUPNP_AV_LIBS) \
+                         $(LIBDBUS_GLIB_LIBS) \
+	                 $(LIBGSTREAMER_LIBS) \
+                         $(GEE_LIBS)
+librygel_dvb_la_LDFLAGS = -shared -fPIC -module -avoid-version
+
+CLEANFILES = $(BUILT_SOURCES)
+MAINTAINERCLEANFILES = Makefile.in

Added: trunk/src/plugins/dvb/rygel-dvb-channel-group.vala
==============================================================================
--- (empty file)
+++ trunk/src/plugins/dvb/rygel-dvb-channel-group.vala	Thu Dec 25 12:00:35 2008
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *                               <zeeshan ali nokia com>
+ *
+ * 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.
+ *
+ * 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.
+ * 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.
+ */
+
+using Rygel;
+using GUPnP;
+using DBus;
+using Gee;
+
+/**
+ * Represents DVB channel group.
+ */
+public class Rygel.DVBChannelGroup : MediaContainer {
+    /* class-wide constants */
+    private const string DVB_SERVICE = "org.gnome.DVB";
+    private const string CHANNEL_LIST_PATH_ROOT = "/org/gnome/DVB/ChannelList/";
+    private const string CHANNEL_LIST_IFACE = "org.gnome.DVB.ChannelList";
+
+    private const string GID_PREFIX = "GroupID:";
+    private const string TITLE_PREFIX = "Group ";
+
+    public static dynamic DBus.Object channel_list;
+
+    /* Hashmap of (UPnP) IDs to channels */
+    private HashMap<string, DVBChannel> channels;
+
+    public Streamer streamer;
+
+    private uint gid; /* The DVB Daemon Device Group ID */
+
+    public DVBChannelGroup (uint     gid,
+                            string   parent_id,
+                            Streamer streamer) {
+        base (GID_PREFIX + gid.to_string (), // UPnP ID
+              parent_id,
+              TITLE_PREFIX + gid.to_string (),
+              0);
+        this.gid = gid;
+        //this.upnp_class = "object.container.channelGroup";
+        this.streamer = streamer;
+
+        channels = new HashMap<string, DVBChannel> (str_hash, str_equal);
+
+        DBus.Connection connection;
+        try {
+            connection = DBus.Bus.get (DBus.BusType.SESSION);
+        } catch (DBus.Error error) {
+            critical ("Failed to connect to Session bus: %s\n",
+                      error.message);
+            return;
+        }
+
+        string channel_list_path = DVBChannelGroup.CHANNEL_LIST_PATH_ROOT +
+                                   gid.to_string ();
+
+        // Get a proxy to DVB ChannelList object
+        this.channel_list = connection.get_object
+                                    (DVBChannelGroup.DVB_SERVICE,
+                                     channel_list_path,
+                                     DVBChannelGroup.CHANNEL_LIST_IFACE);
+        uint[] channel_ids = null;
+
+        try {
+            channel_ids = this.channel_list.GetChannels ();
+        } catch (GLib.Error error) {
+            critical ("error: %s", error.message);
+            return;
+        }
+
+        foreach (uint channel_id in channel_ids) {
+            // Create Channels
+            var channel = new DVBChannel (channel_id,
+                                          this.id,
+                                          channel_list,
+                                          streamer);
+            this.channels.set (channel.id, channel);
+        }
+    }
+
+    public uint add_channels (DIDLLiteWriter didl_writer,
+                              uint           index,
+                              uint           requested_count,
+                              out uint       total_matches) throws GLib.Error {
+        foreach (var channel in channels.get_values ()) {
+            channel.serialize (didl_writer);
+        }
+
+        total_matches = channels.size;
+
+        return total_matches;
+    }
+
+    public DVBChannel find_channel (DIDLLiteWriter didl_writer,
+                                    string         id) {
+        return this.channels.get (id);
+    }
+}
+

Added: trunk/src/plugins/dvb/rygel-dvb-channel.vala
==============================================================================
--- (empty file)
+++ trunk/src/plugins/dvb/rygel-dvb-channel.vala	Thu Dec 25 12:00:35 2008
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *                               <zeeshan ali nokia com>
+ *
+ * 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.
+ *
+ * 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.
+ * 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.
+ */
+
+using Rygel;
+using GUPnP;
+using DBus;
+
+/**
+ * Represents DVB item.
+ */
+public class Rygel.DVBChannel : MediaItem {
+    public static dynamic DBus.Object channel_list;
+
+    private uint cid; /* The DVB Daemon Channel ID */
+
+    public DVBChannel (uint                cid,
+                       string              parent_id,
+                       dynamic DBus.Object channel_list,
+                       Streamer            streamer) throws GLib.Error {
+        this.id = parent_id + ":" + cid.to_string (); /* UPnP ID */
+        this.parent_id = parent_id;
+        this.channel_list = channel_list;
+        this.streamer = streamer;
+
+        this.fetch_metadata ();
+    }
+
+    public void fetch_metadata () throws GLib.Error {
+        /* TODO: make this async */
+        this.title = this.channel_list.GetChannelName (cid);
+
+        bool is_radio = this.channel_list.IsRadioChannel (cid);
+        if (is_radio) {
+            this.upnp_class = "object.item.videoItem.videoBroadcast";
+            this.res.mime_type = "video/mpeg";
+        } else {
+            this.upnp_class = "object.item.audioItem.audioBroadcast";
+            this.res.mime_type = "audio/mpeg"; // correct?
+        }
+
+        // FIXME: (Leaky) Hack to assign the string to weak fields
+        string uri = this.channel_list.GetChannelURL (cid);
+        this.res.uri = (string *) uri;
+    }
+}
+

Added: trunk/src/plugins/dvb/rygel-dvb-content-dir.vala
==============================================================================
--- (empty file)
+++ trunk/src/plugins/dvb/rygel-dvb-content-dir.vala	Thu Dec 25 12:00:35 2008
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *                               <zeeshan ali nokia com>
+ *
+ * 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.
+ *
+ * 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.
+ * 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.
+ */
+
+using Rygel;
+using GUPnP;
+using DBus;
+
+/**
+ * Implementation of DVB ContentDirectory service.
+ */
+public class Rygel.DVBContentDir : ContentDirectory {
+    // class-wide constants
+    private const string DVB_SERVICE = "org.gnome.DVB";
+    private const string MANAGER_PATH = "/org/gnome/DVB/Manager";
+    private const string MANAGER_IFACE = "org.gnome.DVB.Manager";
+
+    public dynamic DBus.Object manager;
+
+    private List<DVBChannelGroup> groups;
+
+    // Pubic methods
+    public override void constructed () {
+        // Chain-up to base first
+        base.constructed ();
+
+        DBus.Connection connection;
+        try {
+            connection = DBus.Bus.get (DBus.BusType.SESSION);
+        } catch (DBus.Error error) {
+            critical ("Failed to connect to Session bus: %s\n",
+                      error.message);
+            return;
+        }
+
+        // Get a proxy to DVB Manager object
+        this.manager = connection.get_object (DVBContentDir.DVB_SERVICE,
+                                              DVBContentDir.MANAGER_PATH,
+                                              DVBContentDir.MANAGER_IFACE);
+        uint[] dev_groups = null;
+
+        try {
+            dev_groups = this.manager.GetRegisteredDeviceGroups ();
+        } catch (GLib.Error error) {
+            critical ("error: %s", error.message);
+            return;
+        }
+
+        Streamer streamer = new Streamer (this.context, "DVB");
+
+        this.groups = new List<DVBChannelGroup> ();
+        foreach (uint group_id in dev_groups) {
+            // Create ChannelGroup for each registered device group
+            this.groups.append (new DVBChannelGroup (group_id,
+                                                     this.root_container.id,
+                                                     streamer));
+        }
+    }
+
+    public override void add_children_metadata (DIDLLiteWriter didl_writer,
+                                                BrowseArgs     args)
+                                                throws GLib.Error {
+        DVBChannelGroup group;
+
+        group = this.find_group_by_id (args.object_id);
+        if (group == null)
+            args.number_returned = 0;
+        else {
+            args.number_returned = group.add_channels (didl_writer,
+                                                       args.index,
+                                                       args.requested_count,
+                                                       out args.total_matches);
+        }
+
+        if (args.number_returned > 0) {
+            args.update_id = uint32.MAX;
+        } else {
+            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
+        }
+    }
+
+    public override void add_metadata (DIDLLiteWriter didl_writer,
+                                       BrowseArgs     args) throws GLib.Error {
+        bool found = false;
+
+        DVBChannelGroup group;
+
+        // First try groups
+        group = find_group_by_id (args.object_id);
+
+        if (group != null) {
+            group.serialize (didl_writer);
+
+            found = true;
+        } else {
+            // Now try channels
+            found = this.add_channel (didl_writer, args.object_id);
+        }
+
+        if (!found) {
+            throw new ContentDirectoryError.NO_SUCH_OBJECT ("No such object");
+        }
+
+        args.update_id = uint32.MAX;
+    }
+
+    public override void add_root_children_metadata (DIDLLiteWriter didl_writer,
+                                                     BrowseArgs     args)
+                                                     throws GLib.Error {
+        foreach (DVBChannelGroup group in this.groups)
+            group.serialize (didl_writer);
+
+        args.total_matches = args.number_returned = this.groups.length ();
+        args.update_id = uint32.MAX;
+    }
+
+    // Private methods
+    private DVBChannelGroup? find_group_by_id (string id) {
+        DVBChannelGroup group = null;
+
+        foreach (DVBChannelGroup tmp in this.groups) {
+            if (id == tmp.id) {
+                group = tmp;
+
+                break;
+            }
+        }
+
+        return group;
+    }
+
+    private bool add_channel (DIDLLiteWriter didl_writer,
+                              string         id) throws GLib.Error {
+        bool found = false;
+
+        foreach (DVBChannelGroup group in this.groups) {
+            var channel = group.find_channel (didl_writer, id);
+            if (channel != null) {
+                channel.serialize (didl_writer);
+                found = true;
+                break;
+            }
+        }
+
+        return found;
+    }
+}
+

Added: trunk/src/plugins/dvb/rygel-dvb-plugin.vala
==============================================================================
--- (empty file)
+++ trunk/src/plugins/dvb/rygel-dvb-plugin.vala	Thu Dec 25 12:00:35 2008
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *                               <zeeshan ali nokia com>
+ *
+ * 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.
+ *
+ * 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.
+ * 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.
+ */
+
+/* Implementation of DVB related services, based on DVBDaemon. */
+
+using Rygel;
+using Gee;
+using CStuff;
+
+[ModuleInit]
+public Plugin load_plugin () {
+    Plugin plugin = new Plugin ("DVB");
+
+    // We only implement a ContentDirectory service
+    var resource_info = new ResourceInfo (ContentDirectory.UPNP_ID,
+                                          ContentDirectory.UPNP_TYPE,
+                                          ContentDirectory.DESCRIPTION_PATH,
+                                          typeof (DVBContentDir));
+
+    plugin.add_resource (resource_info);
+
+    return plugin;
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]