[rygel] media-export: Use new GstDiscoverer API



commit 8e6a0d1879bb18b6dd71e5d0af86363e8f2c93b1
Author: Arun Raghavan <arun raghavan collabora co uk>
Date:   Thu Jan 14 11:16:40 2010 +0530

    media-export: Use new GstDiscoverer API

 .../rygel-media-export-metadata-extractor.vala     |  138 ++++++--------------
 1 files changed, 40 insertions(+), 98 deletions(-)
---
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 0df0dda..c166ef0 100644
--- a/src/plugins/media-export/rygel-media-export-metadata-extractor.vala
+++ b/src/plugins/media-export/rygel-media-export-metadata-extractor.vala
@@ -41,9 +41,6 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
     public const string TAG_RYGEL_DEPTH = "rygel-depth";
     public const string TAG_RYGEL_MTIME = "rygel-mtime";
 
-    private const Quark _STREAM_TOPOLOGY_QUARK =
-                                        Quark.from_string ("stream-topology");
-
     /* Signals */
     public signal void extraction_done (File file, Gst.TagList tag_list);
 
@@ -95,23 +92,21 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
         this.discoverer.stop ();
     }
 
-    private void on_discovered (string               uri,
-                                Structure            info,
-                                GLib.Error           err,
-                                Gst.DiscovererResult res) {
-        assert (this.file_hash.has_key (uri));
+    private void on_discovered (owned Gst.DiscovererInformation info,
+                                GLib.Error                      err) {
+        assert (this.file_hash.has_key (info.uri));
 
-        File file = this.file_hash.get (uri);
+        File file = this.file_hash.get (info.uri);
         TagList tag_list = new TagList ();
 
-        this.file_hash.unset (uri);
+        this.file_hash.unset (info.uri);
 
-        if ((res & Gst.DiscovererResult.TIMEOUT) != 0) {
+        if ((info.result & Gst.DiscovererResult.TIMEOUT) != 0) {
             this.error (file,
                         new IOChannelError.FAILED ("Pipeline stuckwhile" +
                                                    "reading file info"));
             return;
-        } else if ((res & Gst.DiscovererResult.ERROR) != 0) {
+        } else if ((info.result & Gst.DiscovererResult.ERROR) != 0) {
             this.error (file, err);
             return;
         }
@@ -169,102 +164,49 @@ public class Rygel.MediaExport.MetadataExtractor: GLib.Object {
         tag_list.add (TagMergeMode.REPLACE, TAG_RYGEL_MTIME, mtime);
     }
 
-    private void extract_duration (Structure info, TagList tag_list) {
-        ClockTime duration;
-        this.discoverer.results_get_duration (info, out duration);
-
+    private void extract_duration (Gst.DiscovererInformation info,
+                                   TagList                   tag_list) {
         tag_list.add (TagMergeMode.REPLACE,
                       TAG_DURATION,
                       info.duration);
     }
 
-    /*
-     * Collect Caps from the stream information so we can extract bitrate,
-     * height, width, etc.
-     */
-    private ArrayList<Gst.Caps> get_caps (Structure info) {
-        ArrayList<Gst.Caps> caps_list = new ArrayList<Gst.Caps> ();
-        ArrayList<Structure> struct_list = new ArrayList<Structure> ();
-
-        struct_list.add (info);
-
-        for (int i = 0; i < struct_list.size; i++) {
-            Structure st = struct_list[i];
-
-            for (int f = 0; f < st.n_fields (); f++) {
-                string name = st.nth_field_name (f);
-                Quark field = Quark.from_string (name);
-                Gst.Value v = st.get_value (name);
-
-                if (field == MetadataExtractor._STREAM_TOPOLOGY_QUARK) {
-                    /* We don't care about the stream topology caps */
-                    continue;
-                } else if (v.holds (typeof (Gst.List))) {
-                    for (int j = 0; j < v.list_get_size (); j++) {
-                        Gst.Value item_value = v.list_get_value (j);
-
-                        if (item_value.type ().name () == "GstStructure")
-                            struct_list.add (item_value.get_structure ());
-                        else if (item_value.holds (typeof (Gst.Caps)))
-                            caps_list.add (item_value.get_caps ());
-                    }
-                } else if (v.type ().name () == "GstStructure") {
-                    /*
-                     * This should be v.holds (typeof (Gst.Structure)), but
-                     * requires a bug fix in GStreamer VAPI, which should hit
-                     * master soon
-                     */
-                    struct_list.add (v.get_structure ());
-                } else if (v.holds (typeof (Gst.Caps))) {
-                    caps_list.add (v.get_caps ());
-                }
+    private void extract_stream_info (Gst.DiscovererInformation info,
+                                      TagList                   tag_list) {
+        foreach (unowned Gst.StreamInformation i in info.stream_list) {
+            if (i.streamtype == Gst.StreamType.VIDEO) {
+                extract_video_info ((Gst.StreamVideoInformation) i, tag_list);
+            } else if (i.streamtype == Gst.StreamType.AUDIO) {
+                extract_audio_info ((Gst.StreamAudioInformation) i, tag_list);
             }
         }
-
-        return caps_list;
     }
 
-    private void extract_stream_info (Structure info, TagList tag_list) {
-        ArrayList<Gst.Caps> caps_list = get_caps (info);
-
-        foreach (Gst.Caps caps in caps_list) {
-            Structure caps_struct = caps.get_structure (0);
-            string name = caps_struct.get_name ();
-
-            if (name.has_prefix ("video")) {
-                extract_video_info (caps_struct, tag_list);
-            } else if (name.has_prefix ("audio")) {
-                extract_audio_info (caps_struct, tag_list);
-            }
-        }
-    }
-
-    private void extract_audio_info (Structure structure,
-                                     TagList tag_list) {
-        this.extract_int_value (structure, tag_list,"rate", TAG_RYGEL_RATE);
-        this.extract_int_value (structure,
-                                tag_list,
-                                "channels",
-                                TAG_RYGEL_CHANNELS);
+    private void extract_audio_info (Gst.StreamAudioInformation info,
+                                     TagList                    tag_list) {
+        if (info.sample_rate != 0)
+            tag_list.add (TagMergeMode.REPLACE,
+                          TAG_RYGEL_RATE,
+                          info.sample_rate);
+        if (info.channels != 0)
+            tag_list.add (TagMergeMode.REPLACE,
+                          TAG_RYGEL_CHANNELS,
+                          info.channels);
     }
 
-    private void extract_video_info (Structure structure, TagList tag_list) {
-        this.extract_int_value (structure, tag_list, "depth", TAG_RYGEL_DEPTH);
-        this.extract_int_value (structure, tag_list, "width", TAG_RYGEL_WIDTH);
-        this.extract_int_value (structure,
-                                tag_list,
-                                "height",
-                                TAG_RYGEL_HEIGHT);
-    }
-
-    private void extract_int_value (Structure structure,
-                                    TagList   tag_list,
-                                    string    key,
-                                    string    tag) {
-        int val;
-
-        if (structure.get_int (key, out val)) {
-            tag_list.add (TagMergeMode.REPLACE, tag, val);
-        }
+    private void extract_video_info (Gst.StreamVideoInformation info,
+                                     TagList                    tag_list) {
+        if (info.depth != 0)
+            tag_list.add (TagMergeMode.REPLACE,
+                          TAG_RYGEL_DEPTH,
+                          info.depth);
+        if (info.width != 0)
+            tag_list.add (TagMergeMode.REPLACE,
+                          TAG_RYGEL_WIDTH,
+                          info.width);
+        if (info.height != 0)
+            tag_list.add (TagMergeMode.REPLACE,
+                          TAG_RYGEL_HEIGHT,
+                          info.height);
     }
 }



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