[rygel/wip/media-engine] wip



commit de2032553a5cf012f940fe8363fbf225fa7f7a42
Author: Jens Georg <jensg openismus com>
Date:   Thu Sep 27 19:10:45 2012 +0200

    wip

 configure.ac                                       |    1 +
 data/rygel.conf                                    |    2 +-
 src/media-engines/Makefile.am                      |    2 +-
 src/media-engines/simple/Makefile.am               |   14 +++
 .../simple/rygel-simple-media-engine.vala          |  113 ++++++++++++++++++++
 .../tracker/rygel-tracker-plugin-factory.vala      |    2 +
 6 files changed, 132 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index fe90657..3d743e4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -270,6 +270,7 @@ src/rygel/Makefile
 src/ui/Makefile
 src/media-engines/Makefile
 src/media-engines/gstreamer/Makefile
+src/media-engines/simple/Makefile
 src/plugins/Makefile
 data/Makefile
 data/xml/Makefile
diff --git a/data/rygel.conf b/data/rygel.conf
index a0f2736..256a46d 100644
--- a/data/rygel.conf
+++ b/data/rygel.conf
@@ -27,7 +27,7 @@ picture-upload-folder= PICTURES@
 
 # Default media engine to load. If not specified, the engine directory is
 # searched recursively and the first engine found is loaded.
-media-engine=librygel-media-engine-gst.so
+#media-engine=librygel-media-engine-gst.so
 
 # The network interface to attach rygel to. You can also use network IP or even
 # ESSID for wireless networks if you are using NetworkManager. Leave it blank
diff --git a/src/media-engines/Makefile.am b/src/media-engines/Makefile.am
index 9cf45e9..ed2f101 100644
--- a/src/media-engines/Makefile.am
+++ b/src/media-engines/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS=
+SUBDIRS=simple
 
 if HAVE_GSTREAMER
 SUBDIRS += gstreamer
diff --git a/src/media-engines/simple/Makefile.am b/src/media-engines/simple/Makefile.am
new file mode 100644
index 0000000..b83f98a
--- /dev/null
+++ b/src/media-engines/simple/Makefile.am
@@ -0,0 +1,14 @@
+include $(top_srcdir)/common.am
+
+engine_LTLIBRARIES = librygel-media-engine-simple.la
+
+AM_CFLAGS += -DG_LOG_DOMAIN='"MediaEngine-Simple"'
+
+librygel_media_engine_simple_la_SOURCES = \
+	rygel-simple-media-engine.vala
+
+librygel_media_engine_simple_la_VALAFLAGS = \
+	$(RYGEL_COMMON_SERVER_PLUGIN_VALAFLAGS)
+
+librygel_media_engine_simple_la_LIBADD = $(RYGEL_COMMON_SERVER_LIBS)
+librygel_media_engine_simple_la_LDFLAGS = $(RYGEL_PLUGIN_LINKER_FLAGS)
diff --git a/src/media-engines/simple/rygel-simple-media-engine.vala b/src/media-engines/simple/rygel-simple-media-engine.vala
new file mode 100644
index 0000000..98eafd1
--- /dev/null
+++ b/src/media-engines/simple/rygel-simple-media-engine.vala
@@ -0,0 +1,113 @@
+internal class Rygel.SimpleDataSource : DataSource, Object {
+    private string uri;
+    private Thread<void*> thread;
+    private Mutex mutex = Mutex ();
+    private Cond cond = Cond ();
+    private uint64 offset = 0;
+    private bool frozen = false;
+
+    public SimpleDataSource (string uri) {
+        debug ("Creating new data source for %s", uri);
+        this.uri = uri;
+    }
+
+    public void start (HTTPSeek? offsets) throws Error {
+/*        if (offsets != null) {
+            throw new DataSourceError.SEEK_FAILED (_("Seek not supported"));
+        } */
+        debug ("Starting data source for uri %s", this.uri);
+        this.thread = new Thread<void*> ("Serving thread", this.thread_func);
+    }
+
+    public void freeze () {
+        if (this.frozen) {
+            return;
+        }
+
+        this.mutex.lock ();
+        this.frozen = true;
+        this.mutex.unlock ();
+    }
+
+    public void thaw () {
+        if (!this.frozen) {
+            return;
+        }
+
+        this.mutex.lock ();
+        this.frozen = false;
+        this.cond.broadcast ();
+        this.mutex.unlock ();
+   }
+
+    public void stop () {
+        // TBD
+    }
+
+    private void* thread_func () {
+        var file = File.new_for_commandline_arg (this.uri);
+        debug ("Spawning new thread for streaming file %s", this.uri);
+        try {
+            var mapped = new MappedFile (file.get_path (), false);
+            while (true) {
+                this.mutex.lock ();
+                while (this.frozen) {
+                    this.cond.wait (this.mutex);
+                }
+
+                this.mutex.unlock ();
+
+                if (offset == mapped.get_length ()) {
+                    debug ("Done streaming!");
+                    break;
+                }
+
+                var start = offset;
+                var stop = offset + 65535;
+                if (stop > mapped.get_length ()) {
+                    stop = mapped.get_length ();
+                }
+                unowned uint8[] data = (uint8[]) mapped.get_contents ();
+                data.length = (int) mapped.get_length ();
+                uint8[] slice = data[start:stop];
+                debug ("start: %llu, stop: %llu", start, stop);
+                offset = stop;
+
+                Idle.add ( () => {
+                    this.data_available (slice);
+
+                    return false;
+                });
+
+            }
+        } catch (Error error) {
+            warning ("Failed to map file: %s", error.message);
+        }
+
+        Idle.add ( () => { this.done (); return false; });
+
+        return null;
+    }
+}
+
+internal class Rygel.SimpleMediaEngine : MediaEngine {
+    private List<DLNAProfile> profiles = new List<DLNAProfile> ();
+
+    public SimpleMediaEngine () { }
+
+    public override unowned List<DLNAProfile> get_dlna_profiles () {
+        return this.profiles;
+    }
+
+    public override unowned List<Transcoder>? get_transcoders () {
+        return null;
+    }
+
+    public override DataSource create_data_source (string uri) {
+        return new SimpleDataSource (uri);
+    }
+}
+
+public static Rygel.MediaEngine module_get_instance () {
+    return new Rygel.SimpleMediaEngine ();
+}
diff --git a/src/plugins/tracker/rygel-tracker-plugin-factory.vala b/src/plugins/tracker/rygel-tracker-plugin-factory.vala
index 1c17779..045ffe4 100644
--- a/src/plugins/tracker/rygel-tracker-plugin-factory.vala
+++ b/src/plugins/tracker/rygel-tracker-plugin-factory.vala
@@ -29,6 +29,8 @@ using Gee;
 private Rygel.Tracker.PluginFactory plugin_factory;
 
 public void module_init (PluginLoader loader) {
+    unowned string[] args = null;
+    Gst.init (ref args);
     if (loader.plugin_disabled (Rygel.Tracker.Plugin.NAME)) {
         message ("Plugin '%s' disabled by user, ignoring..",
                  Rygel.Tracker.Plugin.NAME);



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