[rygel/wip/media-engine: 22/30] core: Move DLNA profile lookup to MediaEngine



commit ac39f47226969c059db0152cb45337d612194518
Author: Jens Georg <jensg openismus org>
Date:   Thu Aug 30 13:36:20 2012 +0200

    core: Move DLNA profile lookup to MediaEngine

 src/librygel-server/filelist.am                    |    6 +-
 src/librygel-server/rygel-gst-media-engine.vala    |   43 ++++++++++++
 src/librygel-server/rygel-item-creator.vala        |   23 +++----
 src/librygel-server/rygel-media-engine.vala        |   73 ++++++++++++++++++++
 .../rygel-source-connection-manager.vala           |   13 ++--
 .../tracker/rygel-tracker-item-factory.vala        |    3 +-
 tests/Makefile.am                                  |    3 +-
 tests/rygel-item-creator-test.vala                 |    7 ++
 tests/rygel-media-engine.vala                      |    1 +
 9 files changed, 148 insertions(+), 24 deletions(-)
---
diff --git a/src/librygel-server/filelist.am b/src/librygel-server/filelist.am
index 7e01d85..9bea5f8 100644
--- a/src/librygel-server/filelist.am
+++ b/src/librygel-server/filelist.am
@@ -20,7 +20,8 @@ LIBRYGEL_SERVER_VAPI_SOURCE_FILES = \
 	rygel-searchable-container.vala \
 	rygel-visual-item.vala \
 	rygel-writable-container.vala \
-	rygel-media-server.vala
+	rygel-media-server.vala \
+	rygel-media-engine.vala
 
 LIBRYGEL_SERVER_NONVAPI_SOURCE_FILES = \
 	rygel-aac-transcoder.vala \
@@ -66,7 +67,8 @@ LIBRYGEL_SERVER_NONVAPI_SOURCE_FILES = \
 	rygel-wmp-hacks.vala \
 	rygel-wmv-transcoder.vala \
 	rygel-xbmc-hacks.vala \
-	rygel-xbox-hacks.vala
+	rygel-xbox-hacks.vala \
+	rygel-gst-media-engine.vala
 
 LIBRYGEL_SERVER_VALAFLAGS_PKG = \
 	--pkg gstreamer-0.10 \
diff --git a/src/librygel-server/rygel-gst-media-engine.vala b/src/librygel-server/rygel-gst-media-engine.vala
new file mode 100644
index 0000000..e8de758
--- /dev/null
+++ b/src/librygel-server/rygel-gst-media-engine.vala
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Author: Jens Georg <jensg openismus com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ */
+
+using Gst;
+
+internal class Rygel.GstMediaEngine : Rygel.MediaEngine {
+    private GLib.List<DLNAProfile> dlna_profiles = null;
+
+    public GstMediaEngine () {
+        var discoverer = new GUPnP.DLNADiscoverer ((ClockTime) SECOND,
+                                                   true,
+                                                   false);
+        foreach (var profile in discoverer.list_profiles ()) {
+            var p = new DLNAProfile (profile.mime, profile.name);
+            this.dlna_profiles.prepend (p);
+        }
+
+        this.dlna_profiles.reverse ();
+    }
+
+    public override unowned GLib.List<DLNAProfile> get_dlna_profiles () {
+        return this.dlna_profiles;
+    }
+}
diff --git a/src/librygel-server/rygel-item-creator.vala b/src/librygel-server/rygel-item-creator.vala
index 65183a9..1f5dd70 100644
--- a/src/librygel-server/rygel-item-creator.vala
+++ b/src/librygel-server/rygel-item-creator.vala
@@ -1,7 +1,9 @@
 /*
- * Copyright (C) 2010 Nokia Corporation.
+ * Copyright (C) 2010-2011 Nokia Corporation.
+ * Copyright (C) 2012 Intel Corporation.
  *
  * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *         Jens Georg <jensg openismus com>
  *
  * This file is part of Rygel.
  *
@@ -21,7 +23,6 @@
  */
 
 using GUPnP;
-using Gst;
 
 /**
  * CreateObject action implementation.
@@ -593,26 +594,20 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
     /**
      * Check if the profile is supported.
      *
-     * The check is performed against GUPnP-DLNA's database explicitly excluding
+     * The check is performed against the MediaEngine's database explicitly excluding
      * the transcoders.
      *
      * @param profile to check
      * @returns true if the profile is supported, false otherwise.
      */
     private bool is_profile_valid (string profile) {
-        var discoverer = new GUPnP.DLNADiscoverer ((ClockTime) SECOND,
-                                                   true,
-                                                   false);
+        unowned GLib.List<DLNAProfile> profiles, result;
 
-        var valid = false;
-        foreach (var known_profile in discoverer.list_profiles ()) {
-            if (known_profile.name == profile) {
-                valid = true;
+        profiles = MediaEngine.get_default ().get_dlna_profiles ();
+        var p = new DLNAProfile (profile, "");
 
-                break;
-            }
-        }
+        result = profiles.find_custom (p, DLNAProfile.compare_by_name);
 
-        return valid;
+        return result != null;
     }
 }
diff --git a/src/librygel-server/rygel-media-engine.vala b/src/librygel-server/rygel-media-engine.vala
new file mode 100644
index 0000000..79fbacf
--- /dev/null
+++ b/src/librygel-server/rygel-media-engine.vala
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Author: Jens Georg <jensg openismus com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ */
+
+/**
+ * Data class representing a DLNA profile.
+ * It contains the name and the corresponding DLNA mime type.
+ *
+ * Note: The mime type can deviate from mime types typically used elsewhere.
+ */
+public class Rygel.DLNAProfile {
+    public string mime;
+    public string name;
+
+    public DLNAProfile (string name, string mime) {
+        this.mime = mime;
+        this.name = name;
+    }
+
+    /**
+     * Compare two DLNA profiles by name
+     */
+    public static int compare_by_name (DLNAProfile a, DLNAProfile b) {
+        return a.name.ascii_casecmp (b.name);
+    }
+}
+
+/**
+ * Base class for the media engine that will contain knowledge about streaming
+ * and transcoding capabilites of the media library in use.
+ */
+public abstract class Rygel.MediaEngine : GLib.Object {
+    private static MediaEngine instance;
+
+    /**
+     * Get the singleton instance of the currently used media engine.
+     *
+     * @return An instance of a concreate #MediaEngine implementation.
+     */
+    public static MediaEngine get_default () {
+        if (instance == null) {
+            instance = new GstMediaEngine ();
+        }
+
+        return instance;
+    }
+
+    /**
+     * Get a list of the DLNA profiles that are supported by this media
+     * engine.
+     *
+     * @return A list of #DLNAProfile<!-- -->s
+     */
+    public abstract unowned List<DLNAProfile> get_dlna_profiles ();
+}
diff --git a/src/librygel-server/rygel-source-connection-manager.vala b/src/librygel-server/rygel-source-connection-manager.vala
index 9903c6f..77031bd 100644
--- a/src/librygel-server/rygel-source-connection-manager.vala
+++ b/src/librygel-server/rygel-source-connection-manager.vala
@@ -1,8 +1,10 @@
 /*
- * Copyright (C) 2009 Nokia Corporation.
+ * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2009-2011 Nokia Corporation.
  * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
  *
  * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *         Jens Georg <jensg openismus com>
  *
  * This file is part of Rygel.
  *
@@ -22,7 +24,6 @@
  */
 
 using GUPnP;
-using Gst;
 using Gee;
 
 /**
@@ -50,12 +51,12 @@ internal class Rygel.SourceConnectionManager : Rygel.ConnectionManager {
         var server = this.get_http_server ();
         var protocol_infos = server.get_protocol_info ();
 
-        var discoverer = new GUPnP.DLNADiscoverer ((ClockTime) SECOND,
-                                                   true,
-                                                   false);
+        unowned GLib.List<DLNAProfile> profiles = MediaEngine.get_default ().
+                                                              get_dlna_profiles ();
+
         var protocol = server.get_protocol ();
 
-        foreach (var profile in discoverer.list_profiles ()) {
+        foreach (var profile in profiles) {
             var protocol_info = new ProtocolInfo ();
 
             protocol_info.protocol = protocol;
diff --git a/src/plugins/tracker/rygel-tracker-item-factory.vala b/src/plugins/tracker/rygel-tracker-item-factory.vala
index 630642b..0654a65 100644
--- a/src/plugins/tracker/rygel-tracker-item-factory.vala
+++ b/src/plugins/tracker/rygel-tracker-item-factory.vala
@@ -2,6 +2,7 @@
  * Copyright (C) 2008 Zeeshan Ali <zeenix gmail com>.
  * Copyright (C) 2008-2012 Nokia Corporation.
  * Copyright (C) 2010 MediaNet Inh.
+ * Copyright (C) 2012 Intel Corporation.
  *
  * Authors: Zeeshan Ali <zeenix gmail com>
  *          Sunil Mohan Adapa <sunil medhas org>
@@ -131,7 +132,7 @@ public abstract class Rygel.Tracker.ItemFactory {
             item.date = metadata.get_string (Metadata.DATE);
         }
 
-        var profile = null as DLNAProfile;
+        var profile = null as GUPnP.DLNAProfile;
         if (metadata.is_bound (Metadata.DLNA_PROFILE)) {
             item.dlna_profile = metadata.get_string (Metadata.DLNA_PROFILE);
             profile = this.discoverer.get_profile (item.dlna_profile);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7ee2aa7..d353b28 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -92,7 +92,8 @@ rygel_item_creator_test_SOURCES = rygel-item-creator-test.vala \
 				  rygel-item-creator.vala \
 				  rygel-state-machine_item-creator.vala \
 				  rygel-relational-expression.vala \
-				  rygel-search-expression.vala
+				  rygel-search-expression.vala \
+				  rygel-media-engine.vala
 
 
 rygel_playbin_renderer_test_SOURCES = rygel-playbin-renderer-test.vala
diff --git a/tests/rygel-item-creator-test.vala b/tests/rygel-item-creator-test.vala
index 27eda60..84e17b8 100644
--- a/tests/rygel-item-creator-test.vala
+++ b/tests/rygel-item-creator-test.vala
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2012 Nokia Corporation.
+ * Copyright (C) 2012 Intel Corporation.
  *
  * Author: Jens Georg <jensg openismus com>
  *
@@ -241,6 +242,12 @@ public errordomain Rygel.ContentDirectoryError {
     ERROR
 }
 
+public class Rygel.GstMediaEngine : Rygel.MediaEngine {
+    public override unowned GLib.List<DLNAProfile> get_dlna_profiles () {
+        return null;
+    }
+}
+
 public class Rygel.HTTPItemCreatorTest : GLib.Object {
 
     public static int main (string[] args) {
diff --git a/tests/rygel-media-engine.vala b/tests/rygel-media-engine.vala
new file mode 120000
index 0000000..8d6c01f
--- /dev/null
+++ b/tests/rygel-media-engine.vala
@@ -0,0 +1 @@
+../src/librygel-server/rygel-media-engine.vala
\ No newline at end of file



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