[rygel] media-export: Add basic harvesting support



commit 8abd59ced4b0476bcf57b692c4fd809b28d418c1
Author: Jens Georg <mail jensge org>
Date:   Fri May 14 14:55:40 2010 +0200

    media-export: Add basic harvesting support
    
    Re-enable simple mode which enables media exporting even if no meta-data
    extractor is available.

 .../media-export/rygel-media-export-item.vala      |   71 ++++++++------------
 .../rygel-media-export-metadata-extractor.vala     |   72 +++++++++++--------
 2 files changed, 70 insertions(+), 73 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-item.vala b/src/plugins/media-export/rygel-media-export-item.vala
index a7cfd28..6f743dd 100644
--- a/src/plugins/media-export/rygel-media-export-item.vala
+++ b/src/plugins/media-export/rygel-media-export-item.vala
@@ -32,38 +32,6 @@ public class Rygel.MediaExport.MediaExportItem : Rygel.MediaItem {
     private const string TAG_HEIGHT = MetadataExtractor.TAG_RYGEL_HEIGHT;
     private const string TAG_DURATION = MetadataExtractor.TAG_RYGEL_DURATION;
 
-    public MediaExportItem (MediaContainer parent,
-                      File           file,
-                      FileInfo       info) {
-        string content_type = info.get_content_type ();
-        string item_class = null;
-        string id = Checksum.compute_for_string (ChecksumType.MD5,
-                                                 info.get_name ());
-
-        // use heuristics based on content type; will use MediaHarvester
-        // when it's ready
-
-        if (content_type.has_prefix ("video/")) {
-            item_class = Rygel.MediaItem.VIDEO_CLASS;
-        } else if (content_type.has_prefix ("audio/")) {
-            item_class = Rygel.MediaItem.AUDIO_CLASS;
-        } else if (content_type.has_prefix ("image/")) {
-            item_class = Rygel.MediaItem.PHOTO_CLASS;
-        }
-
-        if (item_class == null) {
-            item_class = Rygel.MediaItem.AUDIO_CLASS;
-            warning (_("Failed to detect UPnP class for '%s', assuming '%s'"),
-                     file.get_uri (),
-                     item_class);
-        }
-
-        base (id, parent, info.get_name (), item_class);
-
-        this.mime_type = content_type;
-        this.add_uri (file.get_uri (), null);
-    }
-
     public static MediaExportItem? create_from_taglist (MediaContainer parent,
                                                   File           file,
                                                   Gst.TagList    tag_list) {
@@ -90,10 +58,27 @@ public class Rygel.MediaExport.MediaExportItem : Rygel.MediaItem {
                                                 out duration)) {
                             class_guessed = Rygel.MediaItem.VIDEO_CLASS;
                         } else {
+                            string content_type;
+                            tag_list.get_string (MetadataExtractor.TAG_RYGEL_MIME,
+                                                 out content_type);
                             warning(_("File '%s' is of unknown format/type."),
                                     file.get_uri ());
-
-                            return null;
+                            warning (_("Trying to guess from content type %s"),
+                                    content_type);
+                            if (content_type.has_prefix ("video/")) {
+                                class_guessed = Rygel.MediaItem.VIDEO_CLASS;
+                            } else if (content_type.has_prefix ("audio/")) {
+                                class_guessed = Rygel.MediaItem.AUDIO_CLASS;
+                            } else if (content_type.has_prefix ("image/")) {
+                                class_guessed = Rygel.MediaItem.PHOTO_CLASS;
+                            }
+
+                            if (class_guessed == null) {
+                                class_guessed = Rygel.MediaItem.AUDIO_CLASS;
+                                warning (_("Failed to detect UPnP class for '%s', assuming '%s'"),
+                                         file.get_uri (),
+                                         class_guessed);
+                            }
                         }
                     }
                 } else {
@@ -117,18 +102,18 @@ public class Rygel.MediaExport.MediaExportItem : Rygel.MediaItem {
             return null;
         }
 
-        return new MediaExportItem.from_taglist (parent,
-                                                 id,
-                                                 file,
-                                                 tag_list,
-                                                 class_guessed);
+        return new MediaExportItem (parent,
+                                    id,
+                                    file,
+                                    tag_list,
+                                    class_guessed);
     }
 
-    private MediaExportItem.from_taglist (MediaContainer parent,
-                                          string         id,
-                                          File           file,
-                                          Gst.TagList    tag_list,
-                                          string         upnp_class) {
+    private MediaExportItem (MediaContainer parent,
+                             string         id,
+                             File           file,
+                             Gst.TagList    tag_list,
+                             string         upnp_class) {
         string title = null;
         if (upnp_class == Rygel.MediaItem.AUDIO_CLASS ||
             upnp_class == Rygel.MediaItem.MUSIC_CLASS) {
diff --git a/src/plugins/media-export/rygel-media-export-metadata-extractor.vala b/src/plugins/media-export/rygel-media-export-metadata-extractor.vala
index 85a0846..03b3033 100644
--- a/src/plugins/media-export/rygel-media-export-metadata-extractor.vala
+++ b/src/plugins/media-export/rygel-media-export-metadata-extractor.vala
@@ -80,28 +80,30 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
     }
 
     private void renew_playbin () {
-        // setup fake sinks
-        this.playbin = this.factory.create ("tag_reader");
-
-        // increase reference count of sinks to workaround
-        // bug #596078
-        var sink = ElementFactory.make ("fakesink", null);
-        sink.ref ();
-        this.playbin.video_sink = sink;
-
-        sink = ElementFactory.make ("fakesink", null);
-        sink.ref ();
-        this.playbin.audio_sink = sink;
-
-        var bus = this.playbin.get_bus ();
-        bus.add_signal_watch ();
-        bus.message["tag"] += this.tag_cb;
-        if (factory.get_element_type ().name () == "GstPlayBin2") {
-            bus.message["element"] += this.element_message_cb;
-        } else {
-            bus.message["state-changed"] += this.state_changed_cb;
+        if (this.factory != null) {
+            // setup fake sinks
+            this.playbin = this.factory.create ("tag_reader");
+
+            // increase reference count of sinks to workaround
+            // bug #596078
+            var sink = ElementFactory.make ("fakesink", null);
+            sink.ref ();
+            this.playbin.video_sink = sink;
+
+            sink = ElementFactory.make ("fakesink", null);
+            sink.ref ();
+            this.playbin.audio_sink = sink;
+
+            var bus = this.playbin.get_bus ();
+            bus.add_signal_watch ();
+            bus.message["tag"] += this.tag_cb;
+            if (factory.get_element_type ().name () == "GstPlayBin2") {
+                bus.message["element"] += this.element_message_cb;
+            } else {
+                bus.message["state-changed"] += this.state_changed_cb;
+            }
+            bus.message["error"] += this.error_cb;
         }
-        bus.message["error"] += this.error_cb;
     }
 
     public static MetadataExtractor? create() {
@@ -117,9 +119,8 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
                 if (factory != null) {
                     debug (_("Using playbin"));
                 } else {
-                    critical (_("Could not find any playbin.") + " " +
+                    warning (_("Could not find any playbin.") + " " +
                               _("Please check your gstreamer setup"));
-                    return null;
                 }
             }
             MetadataExtractor.factory = factory;
@@ -174,13 +175,24 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
                 debug (_("Scheduling file %s for metadata extraction"),
                        item.get_uri ());
                 this.extract_mime_and_size ();
-                renew_playbin ();
-                this.playbin.uri = item.get_uri ();
-                this.timeout_id = Timeout.add_seconds_full (
-                                                         Priority.DEFAULT,
-                                                         5,
-                                                         on_harvesting_timeout);
-                this.playbin.set_state (State.PAUSED);
+                if (this.factory != null) {
+                    renew_playbin ();
+                    this.playbin.uri = item.get_uri ();
+                    this.timeout_id = Timeout.add_seconds_full (
+                                        Priority.DEFAULT,
+                                        5,
+                                        on_harvesting_timeout);
+                    this.playbin.set_state (State.PAUSED);
+                } else {
+                    Idle.add (() => {
+                        extraction_done (this.file_queue.pop_head (),
+                                         this.tag_list);
+                        this.tag_list = new Gst.TagList ();
+                        this.extract_next ();
+
+                        return false;
+                    });
+                }
             } catch (Error error) {
                 // on error just move to the next uri in queue
                 this.extract_next ();



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