core,media-export: Check for playbin
authorJens Georg <mail@jensge.org>
Wed, 21 Oct 2009 12:06:33 +0000 (14:06 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Sat, 24 Oct 2009 14:03:29 +0000 (17:03 +0300)
Properly check for playbin[2] availability upon creation and react more nicely
with a message to the user to check his/her setup

src/plugins/media-export/rygel-media-export-root-container.vala
src/rygel/rygel-metadata-extractor.vala

index bbb6af5..ad58baa 100644 (file)
@@ -144,7 +144,7 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer {
     private MediaExportRootContainer (MediaDB db) {
         base (db, "0", "MediaExportRoot");
 
-        this.extractor = new MetadataExtractor ();
+        this.extractor = MetadataExtractor.create ();
 
         this.harvester = new HashMap<File,MediaExportHarvester> (file_hash,
                                                                  file_equal);
@@ -212,7 +212,13 @@ public class Rygel.MediaExportRootContainer : Rygel.MediaDBContainer {
     }
 
     private void harvest (File file, MediaContainer parent = this) {
-        if (!this.harvester.contains (file)) {
+        if (this.extractor == null) {
+            warning ("No Metadata extractor available. Will not crawl");
+            return;
+        }
+
+        if (this.extractor != null &&
+            !this.harvester.contains (file)) {
             var harvester = new MediaExportHarvester (parent,
                                                       this.media_db,
                                                       this.extractor,
index e10143e..e11ccdd 100644 (file)
@@ -68,6 +68,8 @@ public class Rygel.MetadataExtractor: GLib.Object {
 
     private uint timeout_id;
 
+    private static ElementFactory factory;
+
     private static void register_custom_tag (string tag, Type type) {
         Gst.tag_register (tag,
                           TagFlag.META,
@@ -79,10 +81,7 @@ public class Rygel.MetadataExtractor: GLib.Object {
 
     private void renew_playbin () {
         // setup fake sinks
-        this.playbin = ElementFactory.make ("playbin2", null);
-        if (this.playbin == null) {
-            this.playbin = ElementFactory.make ("playbin", null);
-        }
+        this.playbin = this.factory.create ("tag_reader");
 
         // increase reference count of sinks to workaround
         // bug #596078
@@ -101,7 +100,31 @@ public class Rygel.MetadataExtractor: GLib.Object {
         bus.message["error"] += this.error_cb;
     }
 
-    public MetadataExtractor () {
+    public static MetadataExtractor? create() {
+        if (MetadataExtractor.factory == null) {
+            debug ("Checking for gstreamer playbin...");
+            var factory = ElementFactory.find("playbin2");
+            if (factory != null) {
+                debug ("Using playbin2");
+            } else {
+                debug ("Could not create Playbin2, trying Playbin");
+                factory = ElementFactory.find ("playbin");
+
+                if (factory != null) {
+                    debug ("Using playbin");
+                } else {
+                    critical ("Could not find any playbin. " +
+                            "Please check your gstreamer setup");
+                    return null;
+                }
+            }
+            MetadataExtractor.factory = factory;
+        }
+
+        return new MetadataExtractor ();
+    }
+
+    MetadataExtractor () {
         this.register_custom_tag (TAG_RYGEL_SIZE, typeof (int64));
         this.register_custom_tag (TAG_RYGEL_DURATION, typeof (int64));
         this.register_custom_tag (TAG_RYGEL_MIME, typeof (string));