rygel r740 - trunk/src/rygel
- From: zeeshanak svn gnome org
- To: svn-commits-list gnome org
- Subject: rygel r740 - trunk/src/rygel
- Date: Sat, 28 Mar 2009 00:43:56 +0000 (UTC)
Author: zeeshanak
Date: Sat Mar 28 00:43:56 2009
New Revision: 740
URL: http://svn.gnome.org/viewvc/rygel?rev=740&view=rev
Log:
Separate Transcoder and TranscoderBin classes.
* Divide Transcoder into two classes:
- public (internal) Transcoder
- The actual transcoder gstreamer bin.
Modified:
trunk/src/rygel/rygel-http-server.vala
trunk/src/rygel/rygel-l16-transcoder.vala
trunk/src/rygel/rygel-mp2ts-transcoder.vala
trunk/src/rygel/rygel-mp3-transcoder.vala
trunk/src/rygel/rygel-transcode-manager.vala
trunk/src/rygel/rygel-transcoder.vala
Modified: trunk/src/rygel/rygel-http-server.vala
==============================================================================
--- trunk/src/rygel/rygel-http-server.vala (original)
+++ trunk/src/rygel/rygel-http-server.vala Sat Mar 28 00:43:56 2009
@@ -39,6 +39,8 @@
public HTTPServer (ContentDirectory content_dir,
string name) {
+ base ();
+
this.root_container = content_dir.root_container;
this.context = content_dir.context;
this.requests = new ArrayList<HTTPRequest> ();
Modified: trunk/src/rygel/rygel-l16-transcoder.vala
==============================================================================
--- trunk/src/rygel/rygel-l16-transcoder.vala (original)
+++ trunk/src/rygel/rygel-l16-transcoder.vala Sat Mar 28 00:43:56 2009
@@ -26,15 +26,51 @@
using Gee;
internal class Rygel.L16Transcoder : Rygel.Transcoder {
- private const int channels = 2;
- private const int frequency = 44100;
- private const int width = 16;
- private const int depth = 16;
- private const int endianness = ByteOrder.BIG_ENDIAN; // Network byte order
+ private const int CHANNELS = 2;
+ private const int FREQUENCY = 44100;
+ private const int WIDTH = 16;
+ private const int DEPTH = 16;
+ private const int ENDIANNESS = ByteOrder.BIG_ENDIAN; // Network byte order
+ private const bool SIGNED = true; // Network byte order
private const string mime_type = "audio/L16;rate=44100;channels=2";
private const string dlna_profile = "LPCM";
+ public override Element create_source (Element src) throws Error {
+ return new L16TranscoderBin (src,
+ L16Transcoder.CHANNELS,
+ L16Transcoder.FREQUENCY,
+ L16Transcoder.WIDTH,
+ L16Transcoder.DEPTH,
+ L16Transcoder.ENDIANNESS,
+ L16Transcoder.SIGNED);
+ }
+
+ public override void add_resources (ArrayList<DIDLLiteResource?> resources,
+ MediaItem item,
+ TranscodeManager manager)
+ throws Error {
+ if (this.mime_type_is_a (item.mime_type, L16Transcoder.mime_type)) {
+ return;
+ }
+
+ var res = manager.create_resource (item,
+ L16Transcoder.mime_type,
+ L16Transcoder.dlna_profile);
+
+ res.sample_freq = L16Transcoder.FREQUENCY;
+ res.n_audio_channels = L16Transcoder.CHANNELS;
+ res.bits_per_sample = L16Transcoder.WIDTH;
+
+ resources.add (res);
+ }
+
+ internal override bool can_handle (string mime_type) {
+ return mime_type == L16Transcoder.mime_type;
+ }
+}
+
+private class Rygel.L16TranscoderBin : Rygel.TranscoderBin {
private const string DECODEBIN = "decodebin2";
private const string AUDIO_CONVERT = "audioconvert";
private const string AUDIO_RESAMPLE = "audioresample";
@@ -45,11 +81,24 @@
private dynamic Element audio_enc;
- public L16Transcoder (Element src) throws Error {
- Element decodebin = Transcoder.create_element (DECODEBIN, DECODEBIN);
-
- this.audio_enc = L16Transcoder.create_encoder (AUDIO_SRC_PAD,
- AUDIO_SINK_PAD);
+ public L16TranscoderBin (Element src,
+ int channels,
+ int frequency,
+ int width,
+ int depth,
+ int endianness,
+ bool signed_)
+ throws Error {
+ Element decodebin = TranscoderBin.create_element (DECODEBIN, DECODEBIN);
+
+ this.audio_enc = L16TranscoderBin.create_encoder (AUDIO_SRC_PAD,
+ AUDIO_SINK_PAD,
+ channels,
+ frequency,
+ width,
+ depth,
+ endianness,
+ signed_);
this.add_many (src, decodebin, this.audio_enc);
src.link (decodebin);
@@ -61,26 +110,6 @@
decodebin.pad_added += this.decodebin_pad_added;
}
- public static void add_resources (ArrayList<DIDLLiteResource?> resources,
- MediaItem item,
- TranscodeManager manager)
- throws Error {
- if (Transcoder.mime_type_is_a (item.mime_type,
- L16Transcoder.mime_type)) {
- return;
- }
-
- var res = manager.create_resource (item,
- L16Transcoder.mime_type,
- L16Transcoder.dlna_profile);
-
- res.sample_freq = L16Transcoder.frequency;
- res.n_audio_channels = L16Transcoder.channels;
- res.bits_per_sample = L16Transcoder.width;
-
- resources.add (res);
- }
-
private void decodebin_pad_added (Element decodebin, Pad new_pad) {
Pad enc_pad = this.audio_enc.get_pad (AUDIO_SINK_PAD);
if (!new_pad.can_link (enc_pad)) {
@@ -96,17 +125,24 @@
}
}
- internal static Element create_encoder (string? src_pad_name,
- string? sink_pad_name)
- throws Error {
- dynamic Element convert1 = Transcoder.create_element (AUDIO_CONVERT,
- null);
- dynamic Element resample = Transcoder.create_element (AUDIO_RESAMPLE,
- AUDIO_RESAMPLE);
- dynamic Element convert2 = Transcoder.create_element (AUDIO_CONVERT,
- null);
- dynamic Element capsfilter = Transcoder.create_element (CAPS_FILTER,
- CAPS_FILTER);
+ public static Element create_encoder (string? src_pad_name,
+ string? sink_pad_name,
+ int channels,
+ int frequency,
+ int width,
+ int depth,
+ int endianness,
+ bool signed_)
+ throws Error {
+ dynamic Element convert1 = TranscoderBin.create_element (AUDIO_CONVERT,
+ null);
+ dynamic Element resample = TranscoderBin.create_element (
+ AUDIO_RESAMPLE,
+ AUDIO_RESAMPLE);
+ dynamic Element convert2 = TranscoderBin.create_element (AUDIO_CONVERT,
+ null);
+ dynamic Element capsfilter = TranscoderBin.create_element (CAPS_FILTER,
+ CAPS_FILTER);
var bin = new Bin ("audio-encoder-bin");
bin.add_many (convert1, resample, convert2, capsfilter);
@@ -118,7 +154,7 @@
"width", typeof (int), width,
"depth", typeof (int), depth,
"endianness", typeof (int), endianness,
- "signed", typeof (bool), true);
+ "signed", typeof (bool), signed_);
convert1.link_many (resample, convert2, capsfilter);
@@ -132,8 +168,4 @@
return bin;
}
-
- internal static bool can_handle (string mime_type) {
- return mime_type == L16Transcoder.mime_type;
- }
}
Modified: trunk/src/rygel/rygel-mp2ts-transcoder.vala
==============================================================================
--- trunk/src/rygel/rygel-mp2ts-transcoder.vala (original)
+++ trunk/src/rygel/rygel-mp2ts-transcoder.vala Sat Mar 28 00:43:56 2009
@@ -29,6 +29,39 @@
public const string mime_type = "video/mpeg";
private const string dlna_profile = "MPEG_TS_HD_NA";
+ // HD
+ private const int WIDTH = 1920;
+ private const int HEIGHT = 1080;
+
+ public override Element create_source (Element src) throws Error {
+ return new MP2TSTranscoderBin (src,
+ MP2TSTranscoder.WIDTH,
+ MP2TSTranscoder.HEIGHT);
+ }
+
+ public override void add_resources (ArrayList<DIDLLiteResource?> resources,
+ MediaItem item,
+ TranscodeManager manager)
+ throws Error {
+ if (this.mime_type_is_a (item.mime_type, MP2TSTranscoder.mime_type)) {
+ return;
+ }
+
+ var res = manager.create_resource (item,
+ MP2TSTranscoder.mime_type,
+ MP2TSTranscoder.dlna_profile);
+ res.width = WIDTH;
+ res.height = HEIGHT;
+
+ resources.add (res);
+ }
+
+ internal override bool can_handle (string mime_type) {
+ return mime_type == MP2TSTranscoder.mime_type;
+ }
+}
+
+private class Rygel.MP2TSTranscoderBin : Rygel.TranscoderBin {
private const string DECODEBIN = "decodebin2";
private const string VIDEO_ENCODER = "mpeg2enc";
private const string COLORSPACE_CONVERT = "ffmpegcolorspace";
@@ -39,22 +72,24 @@
private const string AUDIO_ENC_SINK = "audio-enc-sink-pad";
private const string VIDEO_ENC_SINK = "sink";
- // HD
- private const int WIDTH = 1920;
- private const int HEIGHT = 1080;
-
private dynamic Element audio_enc;
private dynamic Element video_enc;
private dynamic Element muxer;
- public MP2TSTranscoder (Element src) throws Error {
- Element decodebin = Transcoder.create_element (DECODEBIN, DECODEBIN);
- this.audio_enc = MP3Transcoder.create_encoder (MP3Profile.LAYER2,
- null,
- AUDIO_ENC_SINK);
- this.video_enc = MP2TSTranscoder.create_encoder (null,
- VIDEO_ENC_SINK);
- this.muxer = Transcoder.create_element (MUXER, MUXER);
+ public MP2TSTranscoderBin (Element src,
+ int width,
+ int height)
+ throws Error {
+ var mp3_transcoder = new MP3Transcoder (MP3Profile.LAYER2);
+
+ Element decodebin = TranscoderBin.create_element (DECODEBIN, DECODEBIN);
+ this.audio_enc = mp3_transcoder.create_encoder (null,
+ AUDIO_ENC_SINK);
+ this.video_enc = MP2TSTranscoderBin.create_encoder (null,
+ VIDEO_ENC_SINK,
+ width,
+ height);
+ this.muxer = TranscoderBin.create_element (MUXER, MUXER);
this.add_many (src,
decodebin,
@@ -70,24 +105,6 @@
decodebin.pad_added += this.decodebin_pad_added;
}
- public static void add_resources (ArrayList<DIDLLiteResource?> resources,
- MediaItem item,
- TranscodeManager manager)
- throws Error {
- if (Transcoder.mime_type_is_a (item.mime_type,
- MP2TSTranscoder.mime_type)) {
- return;
- }
-
- var res = manager.create_resource (item,
- MP2TSTranscoder.mime_type,
- MP2TSTranscoder.dlna_profile);
- res.width = WIDTH;
- res.height = HEIGHT;
-
- resources.add (res);
- }
-
private void decodebin_pad_added (Element decodebin, Pad new_pad) {
Element encoder;
Pad enc_pad;
@@ -118,20 +135,24 @@
}
internal static Element create_encoder (string? src_pad_name,
- string? sink_pad_name)
+ string? sink_pad_name,
+ int width,
+ int height)
throws Error {
- var videorate = Transcoder.create_element (VIDEO_RATE, VIDEO_RATE);
- var videoscale = Transcoder.create_element (VIDEO_SCALE, VIDEO_SCALE);
- var convert = Transcoder.create_element (COLORSPACE_CONVERT,
- COLORSPACE_CONVERT);
- var encoder = Transcoder.create_element (VIDEO_ENCODER, VIDEO_ENCODER);
+ var videorate = TranscoderBin.create_element (VIDEO_RATE, VIDEO_RATE);
+ var videoscale = TranscoderBin.create_element (VIDEO_SCALE,
+ VIDEO_SCALE);
+ var convert = TranscoderBin.create_element (COLORSPACE_CONVERT,
+ COLORSPACE_CONVERT);
+ var encoder = TranscoderBin.create_element (VIDEO_ENCODER,
+ VIDEO_ENCODER);
var bin = new Bin ("video-encoder-bin");
bin.add_many (videorate, videoscale, convert, encoder);
var caps = new Caps.simple ("video/x-raw-yuv",
- "width", typeof (int), WIDTH,
- "height", typeof (int), HEIGHT);
+ "width", typeof (int), width,
+ "height", typeof (int), height);
videorate.link (convert);
convert.link (videoscale);
videoscale.link_filtered (encoder, caps);
@@ -146,8 +167,4 @@
return bin;
}
-
- internal static bool can_handle (string mime_type) {
- return mime_type == MP2TSTranscoder.mime_type;
- }
}
Modified: trunk/src/rygel/rygel-mp3-transcoder.vala
==============================================================================
--- trunk/src/rygel/rygel-mp3-transcoder.vala (original)
+++ trunk/src/rygel/rygel-mp3-transcoder.vala Sat Mar 28 00:43:56 2009
@@ -34,6 +34,43 @@
public const string mime_type = "audio/mpeg";
private const string dlna_profile = "MP3";
+ private MP3Profile layer;
+
+ public MP3Transcoder (MP3Profile layer) {
+ this.layer = layer;
+ }
+
+ public Element create_encoder (string? src_pad_name,
+ string? sink_pad_name)
+ throws Error {
+ return MP3TranscoderBin.create_encoder (this.layer,
+ src_pad_name,
+ sink_pad_name);
+ }
+
+ public override Element create_source (Element src) throws Error {
+ return new MP3TranscoderBin (src, this.layer);
+ }
+
+ public override void add_resources (ArrayList<DIDLLiteResource?> resources,
+ MediaItem item,
+ TranscodeManager manager)
+ throws Error {
+ if (this.mime_type_is_a (item.mime_type, MP3Transcoder.mime_type)) {
+ return;
+ }
+
+ resources.add (manager.create_resource (item,
+ MP3Transcoder.mime_type,
+ MP3Transcoder.dlna_profile));
+ }
+
+ public override bool can_handle (string mime_type) {
+ return mime_type == MP3Transcoder.mime_type;
+ }
+}
+
+private class Rygel.MP3TranscoderBin : Rygel.TranscoderBin {
private const string DECODEBIN = "decodebin2";
private const string AUDIO_CONVERT = "audioconvert";
private const string[] AUDIO_ENCODER = {null, "twolame", "lame"};
@@ -46,14 +83,14 @@
private dynamic Element audio_enc;
private MP3Profile layer;
- public MP3Transcoder (Element src, MP3Profile layer) throws Error {
+ public MP3TranscoderBin (Element src, MP3Profile layer) throws Error {
this.layer = layer;
- Element decodebin = Transcoder.create_element (DECODEBIN, DECODEBIN);
+ Element decodebin = TranscoderBin.create_element (DECODEBIN, DECODEBIN);
- this.audio_enc = MP3Transcoder.create_encoder (this.layer,
- AUDIO_SRC_PAD,
- AUDIO_SINK_PAD);
+ this.audio_enc = MP3TranscoderBin.create_encoder (this.layer,
+ AUDIO_SRC_PAD,
+ AUDIO_SINK_PAD);
this.add_many (src, decodebin, this.audio_enc);
src.link (decodebin);
@@ -65,48 +102,20 @@
decodebin.pad_added += this.decodebin_pad_added;
}
- public static void add_resources (ArrayList<DIDLLiteResource?> resources,
- MediaItem item,
- TranscodeManager manager)
- throws Error {
- if (Transcoder.mime_type_is_a (item.mime_type,
- MP3Transcoder.mime_type)) {
- return;
- }
-
- resources.add (manager.create_resource (item,
- MP3Transcoder.mime_type,
- MP3Transcoder.dlna_profile));
- }
-
- private void decodebin_pad_added (Element decodebin, Pad new_pad) {
- Pad enc_pad = this.audio_enc.get_pad (AUDIO_SINK_PAD);
- if (!new_pad.can_link (enc_pad)) {
- return;
- }
-
- if (new_pad.link (enc_pad) != PadLinkReturn.OK) {
- this.post_error (new LiveResponseError.LINK (
- "Failed to link pad %s to %s",
- new_pad.name,
- enc_pad.name));
- return;
- }
- }
-
- internal static Element create_encoder (MP3Profile layer,
- string? src_pad_name,
- string? sink_pad_name)
- throws Error {
- dynamic Element convert = Transcoder.create_element (AUDIO_CONVERT,
- AUDIO_CONVERT);
- dynamic Element resample = Transcoder.create_element (AUDIO_RESAMPLE,
- AUDIO_RESAMPLE);
- dynamic Element encoder = Transcoder.create_element (
- AUDIO_ENCODER[layer],
- AUDIO_ENCODER[layer]);
- dynamic Element parser = Transcoder.create_element (AUDIO_PARSER,
- AUDIO_PARSER);
+ public static Element create_encoder (MP3Profile layer,
+ string? src_pad_name,
+ string? sink_pad_name)
+ throws Error {
+ dynamic Element convert = TranscoderBin.create_element (AUDIO_CONVERT,
+ AUDIO_CONVERT);
+ dynamic Element resample = TranscoderBin.create_element (
+ AUDIO_RESAMPLE,
+ AUDIO_RESAMPLE);
+ dynamic Element encoder = TranscoderBin.create_element (
+ AUDIO_ENCODER[layer],
+ AUDIO_ENCODER[layer]);
+ dynamic Element parser = TranscoderBin.create_element (AUDIO_PARSER,
+ AUDIO_PARSER);
if (layer == MP3Profile.LAYER3) {
// Best quality
@@ -133,7 +142,18 @@
return bin;
}
- internal static bool can_handle (string mime_type) {
- return mime_type == MP3Transcoder.mime_type;
+ private void decodebin_pad_added (Element decodebin, Pad new_pad) {
+ Pad enc_pad = this.audio_enc.get_pad (AUDIO_SINK_PAD);
+ if (!new_pad.can_link (enc_pad)) {
+ return;
+ }
+
+ if (new_pad.link (enc_pad) != PadLinkReturn.OK) {
+ this.post_error (new LiveResponseError.LINK (
+ "Failed to link pad %s to %s",
+ new_pad.name,
+ enc_pad.name));
+ return;
+ }
}
}
Modified: trunk/src/rygel/rygel-transcode-manager.vala
==============================================================================
--- trunk/src/rygel/rygel-transcode-manager.vala (original)
+++ trunk/src/rygel/rygel-transcode-manager.vala Sat Mar 28 00:43:56 2009
@@ -27,6 +27,16 @@
using Gst;
public abstract class Rygel.TranscodeManager : GLib.Object {
+ private Transcoder l16_transcoder;
+ private Transcoder mp3_transcoder;
+ private Transcoder mp2ts_transcoder;
+
+ internal TranscodeManager () {
+ l16_transcoder = new L16Transcoder ();
+ mp3_transcoder = new MP3Transcoder (MP3Profile.LAYER3);
+ mp2ts_transcoder = new MP2TSTranscoder();
+ }
+
internal abstract string create_uri_for_item
(MediaItem item,
string? transcode_target,
@@ -39,22 +49,22 @@
// No transcoding for images yet :(
return;
} else if (item.upnp_class.has_prefix (MediaItem.MUSIC_CLASS)) {
- L16Transcoder.add_resources (resources, item, this);
- MP3Transcoder.add_resources (resources, item, this);
+ this.l16_transcoder.add_resources (resources, item, this);
+ this.mp3_transcoder.add_resources (resources, item, this);
} else {
- MP2TSTranscoder.add_resources (resources, item, this);
+ this.mp2ts_transcoder.add_resources (resources, item, this);
}
}
internal Element get_transcoding_src (Element src,
string target)
throws Error {
- if (MP3Transcoder.can_handle (target)) {
- return new MP3Transcoder (src, MP3Profile.LAYER3);
- } else if (L16Transcoder.can_handle (target)) {
- return new L16Transcoder (src);
- } else if (MP2TSTranscoder.can_handle (target)) {
- return new MP2TSTranscoder (src);
+ if (this.mp3_transcoder.can_handle (target)) {
+ return this.mp3_transcoder.create_source (src);
+ } else if (this.l16_transcoder.can_handle (target)) {
+ return this.l16_transcoder.create_source (src);
+ } else if (this.mp2ts_transcoder.can_handle (target)) {
+ return this.mp2ts_transcoder.create_source (src);
} else {
throw new HTTPRequestError.NOT_FOUND (
"No transcoder available for target format '%s'",
Modified: trunk/src/rygel/rygel-transcoder.vala
==============================================================================
--- trunk/src/rygel/rygel-transcoder.vala (original)
+++ trunk/src/rygel/rygel-transcoder.vala Sat Mar 28 00:43:56 2009
@@ -23,16 +23,28 @@
using Rygel;
using Gst;
using GUPnP;
+using Gee;
-internal abstract class Rygel.Transcoder : Gst.Bin {
- protected static bool mime_type_is_a (string mime_type1,
+internal abstract class Rygel.Transcoder : GLib.Object {
+ public abstract Element create_source (Element src) throws Error;
+
+ public abstract void add_resources (ArrayList<DIDLLiteResource?> resources,
+ MediaItem item,
+ TranscodeManager manager)
+ throws Error;
+
+ public abstract bool can_handle (string mime_type);
+
+ protected bool mime_type_is_a (string mime_type1,
string mime_type2) {
string content_type1 = g_content_type_from_mime_type (mime_type1);
string content_type2 = g_content_type_from_mime_type (mime_type2);
return g_content_type_is_a (content_type1, content_type2);
}
+}
+internal abstract class Rygel.TranscoderBin : Gst.Bin {
protected static Element create_element (string factoryname,
string? name)
throws Error {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]