[rygel] core: Add Transcoder.get_distance()
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [rygel] core: Add Transcoder.get_distance()
- Date: Wed, 26 Aug 2009 11:45:57 +0000 (UTC)
commit 3b1b7d88286bc0682c76203b62a38b19e26b60a8
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Mon Jul 6 18:07:59 2009 +0300
core: Add Transcoder.get_distance()
Add a method to Transcoder classes that returns a the numeric value that
gives an estimate of how hard would it be to trancode @item to target
profile of this transcoder.
src/rygel/rygel-l16-transcoder.vala | 24 ++++++++++++++++++++++++
src/rygel/rygel-mp2ts-transcoder.vala | 24 ++++++++++++++++++++++++
src/rygel/rygel-mp3-transcoder.vala | 14 ++++++++++++++
src/rygel/rygel-transcoder.vala | 12 ++++++++++++
4 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/src/rygel/rygel-l16-transcoder.vala b/src/rygel/rygel-l16-transcoder.vala
index baeac4a..f534fd8 100644
--- a/src/rygel/rygel-l16-transcoder.vala
+++ b/src/rygel/rygel-l16-transcoder.vala
@@ -82,6 +82,30 @@ internal class Rygel.L16Transcoder : Rygel.Transcoder {
return resource;
}
+ public override uint get_distance (MediaItem item) {
+ if (item.upnp_class.has_prefix (MediaItem.IMAGE_CLASS)) {
+ return uint.MAX;
+ }
+
+ uint distance = uint.MIN;
+
+ if (item.upnp_class.has_prefix (MediaItem.MUSIC_CLASS)) {
+ if (item.sample_freq > 0) {
+ distance += (item.sample_freq - FREQUENCY).abs ();
+ }
+
+ if (item.n_audio_channels > 0) {
+ distance += (item.n_audio_channels - CHANNELS).abs ();
+ }
+
+ if (item.bits_per_sample > 0) {
+ distance += (item.bits_per_sample - WIDTH).abs ();
+ }
+ }
+
+ return distance;
+ }
+
public Element create_encoder (MediaItem item,
string? src_pad_name,
string? sink_pad_name)
diff --git a/src/rygel/rygel-mp2ts-transcoder.vala b/src/rygel/rygel-mp2ts-transcoder.vala
index e42bc98..769b966 100644
--- a/src/rygel/rygel-mp2ts-transcoder.vala
+++ b/src/rygel/rygel-mp2ts-transcoder.vala
@@ -76,6 +76,30 @@ internal class Rygel.MP2TSTranscoder : Rygel.Transcoder {
return resource;
}
+ public override uint get_distance (MediaItem item) {
+ if (item.upnp_class.has_prefix (MediaItem.IMAGE_CLASS)) {
+ return uint.MAX;
+ }
+
+ uint distance = uint.MIN;
+
+ if (item.upnp_class.has_prefix (MediaItem.VIDEO_CLASS)) {
+ if (item.bitrate > 0) {
+ distance += (item.bitrate - BITRATE).abs ();
+ }
+
+ if (item.width > 0) {
+ distance += (item.width - WIDTH[this.profile]).abs ();
+ }
+
+ if (item.height > 0) {
+ distance += (item.height - HEIGHT[this.profile]).abs ();
+ }
+ }
+
+ return distance;
+ }
+
public Element create_encoder (MediaItem item,
string? src_pad_name,
string? sink_pad_name)
diff --git a/src/rygel/rygel-mp3-transcoder.vala b/src/rygel/rygel-mp3-transcoder.vala
index e059d76..da68384 100644
--- a/src/rygel/rygel-mp3-transcoder.vala
+++ b/src/rygel/rygel-mp3-transcoder.vala
@@ -64,6 +64,20 @@ internal class Rygel.MP3Transcoder : Rygel.Transcoder {
return resource;
}
+ public override uint get_distance (MediaItem item) {
+ if (item.upnp_class.has_prefix (MediaItem.IMAGE_CLASS)) {
+ return uint.MAX;
+ }
+
+ uint distance = uint.MIN;
+
+ if (item.bitrate > 0) {
+ distance += (item.bitrate - BITRATE).abs ();
+ }
+
+ return distance;
+ }
+
public Element create_encoder (MediaItem item,
string? src_pad_name,
string? sink_pad_name)
diff --git a/src/rygel/rygel-transcoder.vala b/src/rygel/rygel-transcoder.vala
index b136c79..5015f1b 100644
--- a/src/rygel/rygel-transcoder.vala
+++ b/src/rygel/rygel-transcoder.vala
@@ -85,6 +85,18 @@ internal abstract class Rygel.Transcoder : GLib.Object {
return target == this.dlna_profile;
}
+ /**
+ * Gets the numeric value that gives an gives an estimate of how hard
+ * would it be to trancode @item to target profile of this transcoder.
+ *
+ * @param item the media item to calculate the distance for
+ *
+ * @return the distance from the @item, uint.MIN if providing such a
+ * value is impossible or uint.MAX if it doesn't make any
+ * sense to use this transcoder for @item
+ */
+ public abstract uint get_distance (MediaItem item);
+
protected bool mime_type_is_a (string mime_type1,
string mime_type2) {
string content_type1 = g_content_type_from_mime_type (mime_type1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]