core: Don't transcode to different item class
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Thu, 5 Aug 2010 16:35:20 +0000 (19:35 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Thu, 5 Aug 2010 16:35:20 +0000 (19:35 +0300)
Don't offer transcoding from video to audio and viceversa. This makes
sense anyway, reduces network traffic and (last but not the least)
satisfies DLNA (7.3.25.1).

src/rygel/rygel-l16-transcoder.vala
src/rygel/rygel-mp2ts-transcoder.vala
src/rygel/rygel-mp3-transcoder.vala
src/rygel/rygel-wma-transcoder.vala
src/rygel/rygel-wmv-transcoder.vala

index 49ba980..5032b06 100644 (file)
@@ -83,28 +83,22 @@ internal class Rygel.L16Transcoder : Rygel.Transcoder {
     }
 
     public override uint get_distance (MediaItem item) {
-        if (item.upnp_class.has_prefix (MediaItem.IMAGE_CLASS)) {
+        if (!item.upnp_class.has_prefix (MediaItem.AUDIO_CLASS)) {
             return uint.MAX;
         }
 
-        uint distance;
+        var distance = uint.MIN;
 
-        if (item.upnp_class.has_prefix (MediaItem.AUDIO_CLASS)) {
-            distance = uint.MIN;
-
-            if (item.sample_freq > 0) {
-                distance += (item.sample_freq - FREQUENCY).abs ();
-            }
+        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.n_audio_channels > 0) {
+            distance += (item.n_audio_channels - CHANNELS).abs ();
+        }
 
-            if (item.bits_per_sample > 0) {
-                distance += (item.bits_per_sample - WIDTH).abs ();
-            }
-        } else {
-            distance = uint.MAX / 2;
+        if (item.bits_per_sample > 0) {
+            distance += (item.bits_per_sample - WIDTH).abs ();
         }
 
         return distance;
index b53b6aa..12a5a94 100644 (file)
@@ -78,28 +78,22 @@ internal class Rygel.MP2TSTranscoder : Rygel.Transcoder {
     }
 
     public override uint get_distance (MediaItem item) {
-        if (item.upnp_class.has_prefix (MediaItem.IMAGE_CLASS)) {
+        if (!item.upnp_class.has_prefix (MediaItem.VIDEO_CLASS)) {
             return uint.MAX;
         }
 
-        uint distance;
+        var distance = uint.MIN;
 
-        if (item.upnp_class.has_prefix (MediaItem.VIDEO_CLASS)) {
-            distance = uint.MIN;
-
-            if (item.bitrate > 0) {
-                distance += (item.bitrate - BITRATE).abs ();
-            }
+        if (item.bitrate > 0) {
+            distance += (item.bitrate - BITRATE).abs ();
+        }
 
-            if (item.width > 0) {
-                distance += (item.width - WIDTH[this.profile]).abs ();
-            }
+        if (item.width > 0) {
+            distance += (item.width - WIDTH[this.profile]).abs ();
+        }
 
-            if (item.height > 0) {
-                distance += (item.height - HEIGHT[this.profile]).abs ();
-            }
-        } else {
-            distance = uint.MAX / 2;
+        if (item.height > 0) {
+            distance += (item.height - HEIGHT[this.profile]).abs ();
         }
 
         return distance;
index 398725b..0c2f494 100644 (file)
@@ -65,20 +65,14 @@ internal class Rygel.MP3Transcoder : Rygel.Transcoder {
     }
 
     public override uint get_distance (MediaItem item) {
-        if (item.upnp_class.has_prefix (MediaItem.IMAGE_CLASS)) {
+        if (!item.upnp_class.has_prefix (MediaItem.AUDIO_CLASS)) {
             return uint.MAX;
         }
 
-        uint distance;
+        var distance = uint.MIN;
 
-        if (item.upnp_class.has_prefix (MediaItem.AUDIO_CLASS)) {
-            distance = uint.MIN;
-
-            if (item.bitrate > 0) {
-                distance += (item.bitrate - BITRATE).abs ();
-            }
-        } else {
-            distance = uint.MAX / 2;
+        if (item.bitrate > 0) {
+            distance += (item.bitrate - BITRATE).abs ();
         }
 
         return distance;
index 22869e9..f356f6c 100644 (file)
@@ -52,20 +52,14 @@ internal class Rygel.WMATranscoder : Rygel.Transcoder {
     }
 
     public override uint get_distance (MediaItem item) {
-        if (item.upnp_class.has_prefix (MediaItem.IMAGE_CLASS)) {
+        if (!item.upnp_class.has_prefix (MediaItem.AUDIO_CLASS)) {
             return uint.MAX;
         }
 
-        uint distance;
+        var distance = uint.MIN;
 
-        if (item.upnp_class.has_prefix (MediaItem.AUDIO_CLASS)) {
-            distance = uint.MIN;
-
-            if (item.bitrate > 0) {
-                distance += (item.bitrate - BITRATE).abs ();
-            }
-        } else {
-            distance = uint.MAX / 2;
+        if (item.bitrate > 0) {
+            distance += (item.bitrate - BITRATE).abs ();
         }
 
         return distance;
index 118e68f..d715c83 100644 (file)
@@ -57,20 +57,14 @@ internal class Rygel.WMVTranscoder : Rygel.Transcoder {
     }
 
     public override uint get_distance (MediaItem item) {
-        if (item.upnp_class.has_prefix (MediaItem.IMAGE_CLASS)) {
+        if (!item.upnp_class.has_prefix (MediaItem.VIDEO_CLASS)) {
             return uint.MAX;
         }
 
-        uint distance;
+        var distance = uint.MIN;
 
-        if (item.upnp_class.has_prefix (MediaItem.VIDEO_CLASS)) {
-            distance = uint.MIN;
-
-            if (item.bitrate > 0) {
-                distance += (item.bitrate - BITRATE).abs ();
-            }
-        } else {
-            distance = uint.MAX / 2;
+        if (item.bitrate > 0) {
+            distance += (item.bitrate - BITRATE).abs ();
         }
 
         return distance;