From 3da5a32a4bb2928150a745affc899e7397b50662 Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Sun, 14 Dec 2008 20:22:23 +0000 Subject: [PATCH] Generalize: Put common code into TestItem class. Put common code from TestAudioItem and TestVideoItem into TestItem class. svn path=/trunk/; revision=345 --- src/plugins/test/Makefile.am | 5 +++ src/plugins/test/rygel-test-audio-item.vala | 48 +++++----------------- src/plugins/test/rygel-test-item.vala | 62 ++++++++++++++++++++++++----- src/plugins/test/rygel-test-video-item.vala | 48 +++++----------------- 4 files changed, 75 insertions(+), 88 deletions(-) diff --git a/src/plugins/test/Makefile.am b/src/plugins/test/Makefile.am index c0976ac..0c26dc1 100644 --- a/src/plugins/test/Makefile.am +++ b/src/plugins/test/Makefile.am @@ -12,6 +12,8 @@ AM_CFLAGS = $(LIBGUPNP_CFLAGS) \ BUILT_SOURCES = rygel-test.stamp \ rygel-test-content-dir.h \ rygel-test-content-dir.c \ + rygel-test-item.h \ + rygel-test-item.c \ rygel-test-audio-item.h \ rygel-test-audio-item.c \ rygel-test-video-item.h \ @@ -22,6 +24,9 @@ BUILT_SOURCES = rygel-test.stamp \ librygel_test_la_SOURCES = rygel-test-content-dir.h \ rygel-test-content-dir.c \ rygel-test-content-dir.vala \ + rygel-test-item.h \ + rygel-test-item.c \ + rygel-test-item.vala \ rygel-test-audio-item.h \ rygel-test-audio-item.c \ rygel-test-audio-item.vala \ diff --git a/src/plugins/test/rygel-test-audio-item.vala b/src/plugins/test/rygel-test-audio-item.vala index cf3c85d..b9d560a 100644 --- a/src/plugins/test/rygel-test-audio-item.vala +++ b/src/plugins/test/rygel-test-audio-item.vala @@ -32,54 +32,24 @@ using Gst; /** * Represents Test audio item. */ -public class Rygel.TestAudioItem : Rygel.MediaItem { +public class Rygel.TestAudioItem : Rygel.TestItem { const string TEST_PATH = "/test.wav"; const string TEST_MIMETYPE = "audio/x-wav"; - const string TEST_AUTHOR = "Zeeshan Ali (Khattak)"; - - private Streamer streamer; public TestAudioItem (string id, string parent_id, string title, Streamer streamer) { - base (id, parent_id, title, MediaItem.AUDIO_CLASS); - this.mime = TEST_MIMETYPE; - this.author = TEST_AUTHOR; - this.uri = streamer.create_uri_for_path (TEST_PATH); - - this.streamer = streamer; - - streamer.stream_available += this.on_stream_available; - } - - private void on_stream_available (Streamer streamer, - Stream stream, - string path) { - if (path != TEST_PATH) { - /* Not our path and therefore not interesting. */ - stream.reject (); - return; - } - - // FIXME: This should be done by GstStream - stream.set_mime_type (TestAudioItem.TEST_MIMETYPE); - - try { - Element src = this.create_gst_source (); - // 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 in attempting to start streaming %s: %s", - path, - error.message); - - return; - } + base (id, + parent_id, + title, + TEST_MIMETYPE, + MediaItem.AUDIO_CLASS, + streamer, + TEST_PATH); } - private Element create_gst_source () throws Error { + protected override Element create_gst_source () throws Error { Bin bin = new Bin (this.title); dynamic Element src = ElementFactory.make ("audiotestsrc", null); diff --git a/src/plugins/test/rygel-test-item.vala b/src/plugins/test/rygel-test-item.vala index 2e2707b..37e1ba8 100644 --- a/src/plugins/test/rygel-test-item.vala +++ b/src/plugins/test/rygel-test-item.vala @@ -26,20 +26,62 @@ using Rygel; using GUPnP; -using DBus; +using Gst; /** * Represents Test item. */ -public abstract class Rygel.TestItem : MediaItem { - protected string parent_id; - - public TestItem (string id, - string parent_id, - string title) { - this.id = id; - this.parent_id = parent_id; - this.title = title; +public abstract class Rygel.TestItem : Rygel.MediaItem { + const string TEST_AUTHOR = "Zeeshan Ali (Khattak)"; + + public string path; + + private Streamer streamer; + + public TestItem (string id, + string parent_id, + string title, + string mime, + string upnp_class, + Streamer streamer, + string path) { + base (id, parent_id, title, upnp_class); + this.mime = mime; + this.streamer = streamer; + this.author = TEST_AUTHOR; + this.path= path; + + this.uri = streamer.create_uri_for_path (path); + + streamer.stream_available += this.on_stream_available; } + + private void on_stream_available (Streamer streamer, + Stream stream, + string path) { + if (path != this.path) { + /* Not our path and therefore not interesting. */ + stream.reject (); + return; + } + + // FIXME: This should be done by GstStream + stream.set_mime_type (this.mime); + + try { + Element src = this.create_gst_source (); + // 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 in attempting to start streaming %s: %s", + path, + error.message); + + return; + } + } + + protected abstract Element create_gst_source () throws Error; } diff --git a/src/plugins/test/rygel-test-video-item.vala b/src/plugins/test/rygel-test-video-item.vala index 62f4568..3a90761 100644 --- a/src/plugins/test/rygel-test-video-item.vala +++ b/src/plugins/test/rygel-test-video-item.vala @@ -32,54 +32,24 @@ using Gst; /** * Represents Test video item. */ -public class Rygel.TestVideoItem : Rygel.MediaItem { +public class Rygel.TestVideoItem : Rygel.TestItem { const string TEST_PATH = "/test.ogg"; const string TEST_MIMETYPE = "application/ogg"; - const string TEST_AUTHOR = "Zeeshan Ali (Khattak)"; - - private Streamer streamer; public TestVideoItem (string id, string parent_id, string title, Streamer streamer) { - base (id, parent_id, title, MediaItem.VIDEO_CLASS); - this.mime = TEST_MIMETYPE; - this.author = TEST_AUTHOR; - this.uri = streamer.create_uri_for_path (TEST_PATH); - - this.streamer = streamer; - - streamer.stream_available += this.on_stream_available; - } - - private void on_stream_available (Streamer streamer, - Stream stream, - string path) { - if (path != TEST_PATH) { - /* Not our path and therefore not interesting. */ - stream.reject (); - return; - } - - // FIXME: This should be done by GstStream - stream.set_mime_type (TestVideoItem.TEST_MIMETYPE); - - try { - Element src = this.create_gst_source (); - // 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 in attempting to start streaming %s: %s", - path, - error.message); - - return; - } + base (id, + parent_id, + title, + TEST_MIMETYPE, + MediaItem.VIDEO_CLASS, + streamer, + TEST_PATH); } - private Element create_gst_source () throws Error { + protected override Element create_gst_source () throws Error { Bin bin = new Bin (this.title); dynamic Element src = ElementFactory.make ("videotestsrc", null); -- 2.7.4