rygel r341 - in trunk/src: plugins/test rygel
- From: zeeshanak svn gnome org
- To: svn-commits-list gnome org
- Subject: rygel r341 - in trunk/src: plugins/test rygel
- Date: Sun, 14 Dec 2008 20:22:02 +0000 (UTC)
Author: zeeshanak
Date: Sun Dec 14 20:22:02 2008
New Revision: 341
URL: http://svn.gnome.org/viewvc/rygel?rev=341&view=rev
Log:
Move StreamContext to Rygel as GstStream.
This is to avoid code-duplication in plugins. Now plugins just create the
gst source element they want to stream from and tell the Streamer to
stream from that.
Added:
trunk/src/rygel/rygel-1.0.deps
trunk/src/rygel/rygel-gst-stream.vala
Modified:
trunk/src/plugins/test/rygel-test-audio-item.vala
trunk/src/rygel/Makefile.am
trunk/src/rygel/rygel-streamer.vala
Modified: trunk/src/plugins/test/rygel-test-audio-item.vala
==============================================================================
--- trunk/src/plugins/test/rygel-test-audio-item.vala (original)
+++ trunk/src/plugins/test/rygel-test-audio-item.vala Sun Dec 14 20:22:02 2008
@@ -29,10 +29,6 @@
using Gee;
using Gst;
-public errordomain Rygel.TestError {
- MISSING_PLUGIN
-}
-
/**
* Represents Test audio item.
*/
@@ -42,7 +38,6 @@
const string TEST_AUTHOR = "Zeeshan Ali (Khattak)";
private Streamer streamer;
- private HashMap<Stream,StreamContext> streams;
public TestAudioItem (string id,
string parent_id,
@@ -52,7 +47,6 @@
this.mime = TEST_MIMETYPE;
this.author = TEST_AUTHOR;
this.uri = streamer.create_uri_for_path (TEST_PATH);
- this.streams = new HashMap<Stream,StreamContext> ();
this.streamer = streamer;
@@ -68,35 +62,21 @@
return;
}
- StreamContext context;
+ // FIXME: This should be done by GstStream
+ stream.set_mime_type (TestAudioItem.TEST_MIMETYPE);
try {
Element src = this.create_gst_source ();
- context = new StreamContext (stream, "RygelStreamer", src);
+ // Ask streamer to handle the stream for us but use our source in
+ // the pipeline.
+ streamer.stream_from_gst_source (src, stream);
} catch (Error error) {
- critical ("Error creating stream context: %s", error.message);
+ critical ("Error in attempting to start streaming %s: %s",
+ path,
+ error.message);
return;
}
-
- context.set_state (State.PLAYING);
- stream.eos += on_eos;
-
- this.streams.set (stream, context);
- }
-
- private void on_eos (Stream stream) {
- StreamContext context = this.streams.get (stream);
- if (context == null)
- return;
-
- /* We don't need to wait for state change since downstream state changes
- * are guaranteed to be synchronous.
- */
- context.set_state (State.NULL);
-
- /* Remove the associated context. */
- this.streams.remove (stream);
}
private Element create_gst_source () throws Error {
@@ -106,7 +86,7 @@
Element encoder = ElementFactory.make ("wavenc", null);
if (src == null || encoder == null) {
- throw new TestError.MISSING_PLUGIN ("Required plugin missing");
+ throw new GstStreamError.MISSING_PLUGIN ("Required plugin missing");
}
// Add elements to our source bin
@@ -123,76 +103,3 @@
}
}
-private class StreamContext : Pipeline {
- public Stream stream;
-
- private AsyncQueue<Buffer> buffers;
-
- public StreamContext (Stream stream,
- string name,
- Element src) throws Error {
- this.stream = stream;
- this.name = name;
- this.buffers = new AsyncQueue<Buffer> ();
-
- this.stream.accept ();
- this.stream.set_mime_type (TestAudioItem.TEST_MIMETYPE);
- this.prepare_pipeline (src);
- }
-
- private void prepare_pipeline (Element src) throws Error {
- dynamic Element sink = ElementFactory.make ("appsink", null);
-
- if (sink == null) {
- throw new TestError.MISSING_PLUGIN ("Required plugin " +
- "'appsink' missing");
- }
-
- sink.emit_signals = true;
- sink.new_buffer += this.on_new_buffer;
- sink.new_preroll += this.on_new_preroll;
-
- this.add_many (src, sink);
- src.link (sink);
- }
-
- private void on_new_buffer (dynamic Element sink) {
- Buffer buffer = null;
-
- GLib.Signal.emit_by_name (sink, "pull-buffer", out buffer);
- if (buffer == null) {
- critical ("Failed to get buffer from pipeline");
- return;
- }
-
- this.queue_buffer (buffer);
- }
-
- private void on_new_preroll (dynamic Element sink) {
- Buffer buffer = null;
-
- GLib.Signal.emit_by_name (sink, "pull-preroll", out buffer);
- if (buffer == null) {
- critical ("Failed to get buffer from pipeline");
- return;
- }
-
- this.queue_buffer (buffer);
- }
-
- private void queue_buffer (Buffer buffer) {
- this.buffers.push (buffer);
- Idle.add_full (Priority.HIGH_IDLE, this.idle_handler);
- }
-
- private bool idle_handler () {
- var buffer = this.buffers.pop ();
-
- if (buffer != null) {
- this.stream.push_data (buffer.data, buffer.size);
- }
-
- return false;
- }
-}
-
Modified: trunk/src/rygel/Makefile.am
==============================================================================
--- trunk/src/rygel/Makefile.am (original)
+++ trunk/src/rygel/Makefile.am Sun Dec 14 20:22:02 2008
@@ -39,6 +39,8 @@
rygel-streamer.h \
rygel-stream.c \
rygel-stream.h \
+ rygel-gst-stream.c \
+ rygel-gst-stream.h \
rygel-resource-info.h \
rygel-resource-info.c \
rygel-icon-info.h \
@@ -77,6 +79,8 @@
rygel-streamer.h \
rygel-stream.c \
rygel-stream.h \
+ rygel-gst-stream.c \
+ rygel-gst-stream.h \
rygel-resource-info.h \
rygel-resource-info.c \
rygel-icon-info.h \
@@ -116,6 +120,7 @@
rygel-media-receiver-registrar.vala \
rygel-streamer.vala \
rygel-stream.vala \
+ rygel-gst-stream.vala \
rygel-resource-info.vala \
rygel-icon-info.vala \
rygel-plugin.vala \
@@ -123,7 +128,7 @@
rygel-media-container.vala \
rygel-media-item.vala
$(VALAC) -C --library=rygel-1.0 \
- --pkg gupnp-1.0 --pkg gupnp-av-1.0 --pkg gee-1.0 \
+ --pkg gupnp-1.0 --pkg gupnp-av-1.0 --pkg gee-1.0 --pkg gstreamer-0.10 \
$^
CLEANFILES = $(BUILT_SOURCES)
Added: trunk/src/rygel/rygel-1.0.deps
==============================================================================
--- (empty file)
+++ trunk/src/rygel/rygel-1.0.deps Sun Dec 14 20:22:02 2008
@@ -0,0 +1 @@
+gstreamer-0.10
Added: trunk/src/rygel/rygel-gst-stream.vala
==============================================================================
--- (empty file)
+++ trunk/src/rygel/rygel-gst-stream.vala Sun Dec 14 20:22:02 2008
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2008 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ * <zeeshan ali nokia com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ */
+
+using Rygel;
+using GUPnP;
+using Gee;
+using Gst;
+
+public errordomain Rygel.GstStreamError {
+ MISSING_PLUGIN
+}
+
+public class Rygel.GstStream : Pipeline {
+ public Stream stream;
+
+ private AsyncQueue<Buffer> buffers;
+
+ public GstStream (Stream stream,
+ string name,
+ Element src) throws Error {
+ this.stream = stream;
+ this.name = name;
+ this.buffers = new AsyncQueue<Buffer> ();
+
+ this.stream.accept ();
+ this.prepare_pipeline (src);
+ }
+
+ private void prepare_pipeline (Element src) throws Error {
+ dynamic Element sink = ElementFactory.make ("appsink", null);
+
+ if (sink == null) {
+ throw new GstStreamError.MISSING_PLUGIN ("Required plugin " +
+ "'appsink' missing");
+ }
+
+ sink.emit_signals = true;
+ sink.new_buffer += this.on_new_buffer;
+ sink.new_preroll += this.on_new_preroll;
+
+ this.add_many (src, sink);
+ src.link (sink);
+ }
+
+ private void on_new_buffer (dynamic Element sink) {
+ Buffer buffer = null;
+
+ GLib.Signal.emit_by_name (sink, "pull-buffer", out buffer);
+ if (buffer == null) {
+ critical ("Failed to get buffer from pipeline");
+ return;
+ }
+
+ this.queue_buffer (buffer);
+ }
+
+ private void on_new_preroll (dynamic Element sink) {
+ Buffer buffer = null;
+
+ GLib.Signal.emit_by_name (sink, "pull-preroll", out buffer);
+ if (buffer == null) {
+ critical ("Failed to get buffer from pipeline");
+ return;
+ }
+
+ this.queue_buffer (buffer);
+ }
+
+ private void queue_buffer (Buffer buffer) {
+ this.buffers.push (buffer);
+ Idle.add_full (Priority.HIGH_IDLE, this.idle_handler);
+ }
+
+ private bool idle_handler () {
+ var buffer = this.buffers.pop ();
+
+ if (buffer != null) {
+ this.stream.push_data (buffer.data, buffer.size);
+ }
+
+ return false;
+ }
+}
+
Modified: trunk/src/rygel/rygel-streamer.vala
==============================================================================
--- trunk/src/rygel/rygel-streamer.vala (original)
+++ trunk/src/rygel/rygel-streamer.vala Sun Dec 14 20:22:02 2008
@@ -24,17 +24,20 @@
*/
using Gee;
+using Gst;
public class Rygel.Streamer : GLib.Object {
private string server_path_root;
private GUPnP.Context context;
+ private HashMap<Stream,GstStream> streams;
public signal void stream_available (Rygel.Stream stream,
string path);
public Streamer (GUPnP.Context context, string name) {
this.context = context;
+ this.streams = new HashMap<Stream,GstStream> ();
this.server_path_root = "/" + name;
@@ -48,6 +51,32 @@
path);
}
+ public void stream_from_gst_source (Element# src,
+ Stream stream) throws Error {
+ GstStream gst_stream;
+
+ gst_stream = new GstStream (stream, "RygelGstStream", src);
+
+ gst_stream.set_state (State.PLAYING);
+ stream.eos += on_eos;
+
+ this.streams.set (stream, gst_stream);
+ }
+
+ private void on_eos (Stream stream) {
+ GstStream gst_stream = this.streams.get (stream);
+ if (gst_stream == null)
+ return;
+
+ /* We don't need to wait for state change since downstream state changes
+ * are guaranteed to be synchronous.
+ */
+ gst_stream.set_state (State.NULL);
+
+ /* Remove the associated Gst stream. */
+ this.streams.remove (stream);
+ }
+
private void server_handler (Soup.Server server,
Soup.Message msg,
string server_path,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]