[rygel-gst-0-10-media-engine] Even more cleanup, code style and bugs fixes.



commit da56f89ecbe1f4b336d9a0a697bee50808a64ac3
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Fri Jan 11 12:04:35 2013 +0100

    Even more cleanup, code style and bugs fixes.

 src/Makefile.am              |    1 +
 src/rygel-aac-transcoder.c   |    5 +-
 src/rygel-aac-transcoder.h   |   18 +-
 src/rygel-audio-transcoder.c |  277 +++++++++++++---------
 src/rygel-audio-transcoder.h |   10 +-
 src/rygel-avc-transcoder.c   |   31 ++--
 src/rygel-avc-transcoder.h   |   10 +-
 src/rygel-gst-data-source.c  |  534 ++++++++++++++++++++++--------------------
 src/rygel-gst-data-source.h  |   24 +--
 src/rygel-gst-errors.c       |   38 +++
 src/rygel-gst-errors.h       |   57 +++++
 src/rygel-gst-media-engine.c |   90 +++++---
 src/rygel-gst-media-engine.h |   18 +-
 src/rygel-gst-sink.c         |  381 +++++++++++++++++-------------
 src/rygel-gst-sink.h         |   22 +--
 src/rygel-gst-transcoder.c   |  290 ++++++++++++++---------
 src/rygel-gst-transcoder.h   |   14 +-
 src/rygel-gst-utils.c        |   95 ++++----
 src/rygel-gst-utils.h        |   31 ++--
 src/rygel-l16-transcoder.c   |   44 ++--
 src/rygel-l16-transcoder.h   |   16 +-
 src/rygel-mp2ts-transcoder.c |  174 +++++++++------
 src/rygel-mp2ts-transcoder.h |   17 +-
 src/rygel-mp3-transcoder.c   |   10 +-
 src/rygel-mp3-transcoder.h   |   16 +-
 src/rygel-video-transcoder.c |  254 +++++++++++++--------
 src/rygel-video-transcoder.h |   13 +-
 src/rygel-wmv-transcoder.c   |   12 +-
 src/rygel-wmv-transcoder.h   |   10 +-
 tests/test_simple.c          |    1 +
 30 files changed, 1454 insertions(+), 1059 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index fe2383c..1114f0a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,6 +8,7 @@ librygel_media_engine_gst_0_10_la_SOURCES = \
 	rygel-audio-transcoder.c \
 	rygel-avc-transcoder.c \
 	rygel-gst-data-source.c \
+	rygel-gst-errors.c \
 	rygel-gst-media-engine.c \
 	rygel-gst-sink.c \
 	rygel-gst-transcoder.c \
diff --git a/src/rygel-aac-transcoder.c b/src/rygel-aac-transcoder.c
index ae0bc9b..2eb24e2 100644
--- a/src/rygel-aac-transcoder.c
+++ b/src/rygel-aac-transcoder.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2011 Nokia Corporation.
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * Author: Luis de Bethencourt <luis debethencourt collabora com>
  * Author: Murray Cumming <murrayc openismus com>
@@ -43,8 +43,7 @@ rygel_aac_transcoder_new (void) {
 }
 
 static void
-rygel_aac_transcoder_class_init (RygelAACTranscoderClass *klass) {
-  rygel_aac_transcoder_parent_class = g_type_class_peek_parent (klass);
+rygel_aac_transcoder_class_init (RygelAACTranscoderClass *aac_transcoder_class G_GNUC_UNUSED) {
 }
 
 static void
diff --git a/src/rygel-aac-transcoder.h b/src/rygel-aac-transcoder.h
index 3625d64..2a59ba0 100644
--- a/src/rygel-aac-transcoder.h
+++ b/src/rygel-aac-transcoder.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -20,18 +20,12 @@
 #ifndef __RYGEL_GST_0_10_MEDIA_ENGINE_AAC_TRANSCODER_H__
 #define __RYGEL_GST_0_10_MEDIA_ENGINE_AAC_TRANSCODER_H__
 
+
 #include <glib.h>
 #include <glib-object.h>
-#include <stdlib.h>
-#include <string.h>
-#include <rygel-server.h>
-#include <gst/gst.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
-#include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <gee.h>
-#include <rygel-core.h>
 #include "rygel-audio-transcoder.h"
 
+
 G_BEGIN_DECLS
 
 #define RYGEL_TYPE_AAC_TRANSCODER (rygel_aac_transcoder_get_type ())
@@ -54,9 +48,11 @@ struct _RygelAACTranscoderClass {
   RygelAudioTranscoderClass parent_class;
 };
 
-GType rygel_aac_transcoder_get_type (void) G_GNUC_CONST;
+GType
+rygel_aac_transcoder_get_type (void) G_GNUC_CONST;
 
-RygelAACTranscoder *rygel_aac_transcoder_new (void);
+RygelAACTranscoder *
+rygel_aac_transcoder_new (void);
 
 G_END_DECLS
 
diff --git a/src/rygel-audio-transcoder.c b/src/rygel-audio-transcoder.c
index 1870f09..3cdc79c 100644
--- a/src/rygel-audio-transcoder.c
+++ b/src/rygel-audio-transcoder.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2011 Nokia Corporation.
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * Author: Jens Georg <jensg openismus com>
  * Author: Murray Cumming <murrayc openismus com>
@@ -34,8 +34,8 @@ G_DEFINE_TYPE (RygelAudioTranscoder, rygel_audio_transcoder, RYGEL_TYPE_GST_TRAN
 
 struct _RygelAudioTranscoderPrivate {
   gint audio_bitrate;
-  GstCaps* container_format;
-  GstCaps* audio_codec_format;
+  GstCaps *container_format;
+  GstCaps *audio_codec_format;
 };
 
 enum  {
@@ -45,19 +45,102 @@ enum  {
   RYGEL_AUDIO_TRANSCODER_CONTAINER_CAPS
 };
 
-static void rygel_audio_transcoder_finalize (GObject* obj);
-static void rygel_audio_transcoder_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void rygel_audio_transcoder_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+static void
+rygel_audio_transcoder_dispose (GObject *object) {
+  RygelAudioTranscoder *self = RYGEL_AUDIO_TRANSCODER (object);
+  RygelAudioTranscoderPrivate *priv = self->priv;
 
-static GUPnPDIDLLiteResource*
-rygel_audio_transcoder_real_add_resource (RygelTranscoder *base, GUPnPDIDLLiteItem *didl_item, RygelMediaItem *item, RygelTranscodeManager *manager, GError **error) {
-  RygelAudioTranscoder *self;
-  GUPnPDIDLLiteResource* resource;
-  GError *inner_error = NULL;
+  if (priv->container_format) {
+    gst_caps_unref (priv->container_format);
+  }
 
-  self = RYGEL_AUDIO_TRANSCODER (base);
+  if (priv->audio_codec_format) {
+    gst_caps_unref (priv->audio_codec_format);
+  }
+
+  G_OBJECT_CLASS (rygel_audio_transcoder_parent_class)->dispose (object);
+}
+
+static void
+rygel_audio_transcoder_get_property (GObject    *object,
+                                     guint       property_id,
+                                     GValue     *value,
+                                     GParamSpec *pspec) {
+  RygelAudioTranscoder *self = RYGEL_AUDIO_TRANSCODER (object);
+  RygelAudioTranscoderPrivate *priv = self->priv;
+
+  switch (property_id) {
+  case RYGEL_AUDIO_TRANSCODER_AUDIO_BITRATE:
+    g_value_set_int (value, priv->audio_bitrate);
+    break;
+
+  case RYGEL_AUDIO_TRANSCODER_AUDIO_CAPS:
+    g_value_take_string (value, gst_caps_to_string (priv->audio_codec_format));
+    break;
+
+  case RYGEL_AUDIO_TRANSCODER_CONTAINER_CAPS:
+    g_value_take_string (value, gst_caps_to_string (priv->container_format));
+    break;
+
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    break;
+  }
+}
+
+static void
+rygel_audio_transcoder_set_property (GObject      *object,
+                                     guint         property_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec) {
+  RygelAudioTranscoder *self = RYGEL_AUDIO_TRANSCODER (object);
+  RygelAudioTranscoderPrivate *priv = self->priv;
+  const gchar *str;
+
+  switch (property_id) {
+  case RYGEL_AUDIO_TRANSCODER_AUDIO_BITRATE:
+    priv->audio_bitrate = g_value_get_int (value);
+    break;
+
+  case RYGEL_AUDIO_TRANSCODER_AUDIO_CAPS:
+    if (priv->audio_codec_format) {
+      gst_caps_unref (priv->audio_codec_format);
+    }
+    str = g_value_get_string (value);
+    if (!str) {
+      str = "NULL";
+    }
+    priv->audio_codec_format = gst_caps_from_string (str);
+    break;
+
+  case RYGEL_AUDIO_TRANSCODER_CONTAINER_CAPS:
+    if (priv->container_format) {
+      gst_caps_unref (priv->container_format);
+      priv->container_format = NULL;
+    }
+    str = g_value_get_string (value);
+    if (!str) {
+      str = "NULL";
+    }
+    priv->container_format = gst_caps_from_string (str);
+    break;
+
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    break;
+  }
+}
+
+static GUPnPDIDLLiteResource *
+rygel_audio_transcoder_real_add_resource (RygelTranscoder        *base,
+                                          GUPnPDIDLLiteItem      *didl_item,
+                                          RygelMediaItem         *item,
+                                          RygelTranscodeManager  *manager,
+                                          GError                **error) {
+  RygelAudioTranscoder *self = RYGEL_AUDIO_TRANSCODER (base);
+  GError *inner_error = NULL;
+  GUPnPDIDLLiteResource *resource = RYGEL_TRANSCODER_CLASS (rygel_audio_transcoder_parent_class)->add_resource (base, didl_item, item, manager, &inner_error);
 
-  resource = RYGEL_TRANSCODER_CLASS (rygel_audio_transcoder_parent_class)->add_resource (RYGEL_TRANSCODER (self), didl_item, item, manager, &inner_error);
   if (inner_error != NULL) {
     g_propagate_error (error, inner_error);
     return NULL;
@@ -72,139 +155,113 @@ rygel_audio_transcoder_real_add_resource (RygelTranscoder *base, GUPnPDIDLLiteIt
 }
 
 static guint
-rygel_audio_transcoder_real_get_distance (RygelTranscoder *base, RygelMediaItem *item) {
+rygel_audio_transcoder_real_get_distance (RygelTranscoder *base,
+                                          RygelMediaItem  *item) {
   RygelAudioTranscoder *self;
   RygelAudioItem *audio_item;
   guint distance;
   guint bitrate;
 
-  g_return_val_if_fail (item, 0U);
-
-  self = RYGEL_AUDIO_TRANSCODER (base);
-
   if (!RYGEL_IS_AUDIO_ITEM (item) || RYGEL_IS_VIDEO_ITEM (item)) {
-    return 0U;
+    return G_MAXUINT;
   }
 
+  self = RYGEL_AUDIO_TRANSCODER (base);
   audio_item = RYGEL_AUDIO_ITEM (item);
 
   bitrate = rygel_audio_item_get_bitrate (audio_item);
   distance = 0;
-  if(bitrate > 0) {
-    distance += abs(bitrate - self->priv->audio_bitrate);
+  if (bitrate > 0) {
+    distance = abs (bitrate - self->priv->audio_bitrate);
   }
 
   return distance;
 }
 
-static GstEncodingProfile*
+static GstEncodingProfile *
 rygel_audio_transcoder_real_get_encoding_profile (RygelGstTranscoder *base) {
-  RygelAudioTranscoder *self;
-  GstEncodingProfile* enc_audio_profile = NULL;
-  const gchar *preset;
+  RygelAudioTranscoder *self = RYGEL_AUDIO_TRANSCODER (base);
+  const gchar *preset = rygel_gst_transcoder_get_preset (RYGEL_GST_TRANSCODER (self));
+  GstEncodingAudioProfile *enc_audio_profile = gst_encoding_audio_profile_new (self->priv->audio_codec_format, preset, NULL, 1);
+  GstEncodingProfile *audio_profile = GST_ENCODING_PROFILE (enc_audio_profile);
 
-  self = RYGEL_AUDIO_TRANSCODER (base);
-
-  preset = rygel_gst_transcoder_get_preset (RYGEL_GST_TRANSCODER (self));
-  enc_audio_profile = GST_ENCODING_PROFILE (gst_encoding_audio_profile_new (self->priv->audio_codec_format, preset, NULL, 1));
-  gst_encoding_profile_set_name (enc_audio_profile, "audio");
+  gst_encoding_profile_set_name (audio_profile, "audio");
 
   if (self->priv->container_format) {
-    GstEncodingContainerProfile* enc_container_profile
-      = gst_encoding_container_profile_new ("container", NULL, self->priv->container_format, preset);
-    gst_encoding_container_profile_add_profile (enc_container_profile, enc_audio_profile);
+    GstEncodingContainerProfile *enc_container_profile = gst_encoding_container_profile_new ("container", NULL, self->priv->container_format, preset);
+    gst_encoding_container_profile_add_profile (enc_container_profile, audio_profile);
     return GST_ENCODING_PROFILE (enc_container_profile);
   }
 
-  return enc_audio_profile;
+  return audio_profile;
 }
 
 static void
-rygel_audio_transcoder_class_init (RygelAudioTranscoderClass *klass) {
-  rygel_audio_transcoder_parent_class = g_type_class_peek_parent (klass);
-  RYGEL_TRANSCODER_CLASS (klass)->add_resource = rygel_audio_transcoder_real_add_resource;
-  RYGEL_TRANSCODER_CLASS (klass)->get_distance = rygel_audio_transcoder_real_get_distance;
-  RYGEL_GST_TRANSCODER_CLASS (klass)->get_encoding_profile = rygel_audio_transcoder_real_get_encoding_profile;
-  G_OBJECT_CLASS (klass)->finalize = rygel_audio_transcoder_finalize;
-  G_OBJECT_CLASS (klass)->get_property = rygel_audio_transcoder_get_property;
-  G_OBJECT_CLASS (klass)->set_property = rygel_audio_transcoder_set_property;
-  g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_AUDIO_TRANSCODER_AUDIO_BITRATE, g_param_spec_int ("audio-bitrate", "audio-bitrate", "audio-bitrate", 0, G_MAXINT, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
-  g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_AUDIO_TRANSCODER_AUDIO_CAPS, g_param_spec_string ("audio-caps", "audio-caps", "audio-caps", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
-  g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_AUDIO_TRANSCODER_CONTAINER_CAPS, g_param_spec_string ("container-caps", "container-caps", "container-caps", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
-  g_type_class_add_private (klass, sizeof (RygelAudioTranscoderPrivate));
+rygel_audio_transcoder_class_init (RygelAudioTranscoderClass *rygel_audio_transcoder_class) {
+  GObjectClass *object_class = G_OBJECT_CLASS (rygel_audio_transcoder_class);
+  RygelTranscoderClass *transcoder_class = RYGEL_TRANSCODER_CLASS (rygel_audio_transcoder_class);
+  RygelGstTranscoderClass *gst_transcoder_class = RYGEL_GST_TRANSCODER_CLASS (rygel_audio_transcoder_class);
+
+  transcoder_class->add_resource = rygel_audio_transcoder_real_add_resource;
+  transcoder_class->get_distance = rygel_audio_transcoder_real_get_distance;
+  gst_transcoder_class->get_encoding_profile = rygel_audio_transcoder_real_get_encoding_profile;
+  object_class->dispose = rygel_audio_transcoder_dispose;
+  object_class->get_property = rygel_audio_transcoder_get_property;
+  object_class->set_property = rygel_audio_transcoder_set_property;
+
+  g_object_class_install_property (object_class,
+                                   RYGEL_AUDIO_TRANSCODER_AUDIO_BITRATE,
+                                   g_param_spec_int ("audio-bitrate",
+                                                     "audio-bitrate",
+                                                     "audio-bitrate",
+                                                     0,
+                                                     G_MAXINT,
+                                                     0,
+                                                     G_PARAM_STATIC_NAME |
+                                                     G_PARAM_STATIC_NICK |
+                                                     G_PARAM_STATIC_BLURB |
+                                                     G_PARAM_CONSTRUCT_ONLY |
+                                                     G_PARAM_READABLE |
+                                                     G_PARAM_WRITABLE));
+
+  g_object_class_install_property (object_class,
+                                   RYGEL_AUDIO_TRANSCODER_AUDIO_CAPS,
+                                   g_param_spec_string ("audio-caps",
+                                                        "audio-caps",
+                                                        "audio-caps",
+                                                        NULL,
+                                                        G_PARAM_STATIC_NAME |
+                                                        G_PARAM_STATIC_NICK |
+                                                        G_PARAM_STATIC_BLURB |
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE));
+
+  g_object_class_install_property (object_class,
+                                   RYGEL_AUDIO_TRANSCODER_CONTAINER_CAPS,
+                                   g_param_spec_string ("container-caps",
+                                                        "container-caps",
+                                                        "container-caps",
+                                                        NULL,
+                                                        G_PARAM_STATIC_NAME |
+                                                        G_PARAM_STATIC_NICK |
+                                                        G_PARAM_STATIC_BLURB |
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE));
+
+  g_type_class_add_private (rygel_audio_transcoder_class,
+                            sizeof (RygelAudioTranscoderPrivate));
 }
 
 static void
 rygel_audio_transcoder_init (RygelAudioTranscoder *self) {
   self->priv = RYGEL_AUDIO_TRANSCODER_GET_PRIVATE (self);
+  self->priv->audio_bitrate = 0;
   self->priv->container_format = NULL;
   self->priv->audio_codec_format = NULL;
 }
 
-static void
-rygel_audio_transcoder_finalize (GObject* obj) {
-  RygelAudioTranscoder *self;
-  self = RYGEL_AUDIO_TRANSCODER (obj);
-
-  if (self->priv->container_format) {
-    gst_caps_unref (self->priv->container_format);
-  }
-
-  if (self->priv->audio_codec_format) {
-    gst_caps_unref (self->priv->audio_codec_format);
-  }
-
-  G_OBJECT_CLASS (rygel_audio_transcoder_parent_class)->finalize (obj);
-}
-
-static void
-rygel_audio_transcoder_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) {
-  RygelAudioTranscoder *self = RYGEL_AUDIO_TRANSCODER (object);
-  RygelAudioTranscoderPrivate *priv = self->priv;
-
-  switch (property_id) {
-    case RYGEL_AUDIO_TRANSCODER_AUDIO_BITRATE:
-      g_value_set_int (value, priv->audio_bitrate);
-      break;
-    case RYGEL_AUDIO_TRANSCODER_AUDIO_CAPS:
-      g_value_take_string (value, gst_caps_to_string (priv->audio_codec_format));
-      break;
-    case RYGEL_AUDIO_TRANSCODER_CONTAINER_CAPS:
-      g_value_take_string (value, gst_caps_to_string (priv->container_format));
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-      break;
-  }
-}
-
-static void
-rygel_audio_transcoder_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) {
-  RygelAudioTranscoder *self = RYGEL_AUDIO_TRANSCODER (object);
-  RygelAudioTranscoderPrivate *priv = self->priv;
-
-  switch (property_id) {
-    case RYGEL_AUDIO_TRANSCODER_AUDIO_BITRATE:
-      priv->audio_bitrate = g_value_get_int (value);
-      break;
-    case RYGEL_AUDIO_TRANSCODER_AUDIO_CAPS:
-      if (priv->audio_codec_format) {
-        gst_caps_unref (priv->audio_codec_format);
-      }
-      priv->audio_codec_format = gst_caps_from_string (g_value_get_string (value));
-      break;
-    case RYGEL_AUDIO_TRANSCODER_CONTAINER_CAPS:
-      if (priv->container_format) {
-        gst_caps_unref (priv->container_format);
-      }
-      priv->container_format = gst_caps_from_string (g_value_get_string (value));
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-      break;
-  }
-}
-
 gint
 rygel_audio_transcoder_get_audio_bitrate (RygelAudioTranscoder *transcoder)
 {
diff --git a/src/rygel-audio-transcoder.h b/src/rygel-audio-transcoder.h
index 5382541..f430e31 100644
--- a/src/rygel-audio-transcoder.h
+++ b/src/rygel-audio-transcoder.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -22,14 +22,6 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <stdlib.h>
-#include <string.h>
-#include <rygel-server.h>
-#include <gst/gst.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
-#include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <gee.h>
-#include <rygel-core.h>
 #include "rygel-gst-transcoder.h"
 
 G_BEGIN_DECLS
diff --git a/src/rygel-avc-transcoder.c b/src/rygel-avc-transcoder.c
index fca1b5a..ca2e3fb 100644
--- a/src/rygel-avc-transcoder.c
+++ b/src/rygel-avc-transcoder.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2011 Nokia Corporation.
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * Author: Luis de Bethencourt <luis debethencourt collabora com>
  * Author: Murray Cumming <murrayc openismus com>
@@ -33,9 +33,7 @@ G_DEFINE_TYPE (RygelAVCTranscoder, rygel_avc_transcoder, RYGEL_TYPE_VIDEO_TRANSC
 #define RYGEL_AVC_TRANSCODER_VIDEO_CAPS "video/x-h264,stream-format=avc"
 #define RYGEL_AVC_TRANSCODER_RESTRICTIONS "video/x-raw-yuv,framerate=(fraction)15/1,width=352,height=288"
 
-static GUPnPDIDLLiteResource* rygel_avc_transcoder_real_add_resource (RygelTranscoder *base, GUPnPDIDLLiteItem *didl_item, RygelMediaItem *item, RygelTranscodeManager *manager, GError **error);
-
-RygelAVCTranscoder*
+RygelAVCTranscoder *
 rygel_avc_transcoder_new (void) {
   return RYGEL_AVC_TRANSCODER (g_object_new (RYGEL_TYPE_AVC_TRANSCODER,
                                              "mime-type", "video/mp4",
@@ -51,14 +49,18 @@ rygel_avc_transcoder_new (void) {
                                              NULL));
 }
 
-static GUPnPDIDLLiteResource*
-rygel_avc_transcoder_real_add_resource (RygelTranscoder *base, GUPnPDIDLLiteItem *didl_item, RygelMediaItem *item, RygelTranscodeManager *manager, GError **error) {
-  GUPnPDIDLLiteResource* resource;
-  GError* inner_error = NULL;
+static GUPnPDIDLLiteResource *
+rygel_avc_transcoder_real_add_resource (RygelTranscoder        *base,
+                                        GUPnPDIDLLiteItem      *didl_item,
+                                        RygelMediaItem         *item,
+                                        RygelTranscodeManager  *manager,
+                                        GError                **error) {
+  GUPnPDIDLLiteResource *resource;
+  GError *inner_error = NULL;
 
-  g_return_val_if_fail (didl_item != NULL, NULL);
-  g_return_val_if_fail (item != NULL, NULL);
-  g_return_val_if_fail (manager != NULL, NULL);
+  g_return_val_if_fail (GUPNP_IS_DIDL_LITE_ITEM (didl_item), NULL);
+  g_return_val_if_fail (RYGEL_IS_MEDIA_ITEM (item), NULL);
+  g_return_val_if_fail (RYGEL_IS_TRANSCODE_MANAGER (manager), NULL);
 
   resource = RYGEL_TRANSCODER_CLASS (rygel_avc_transcoder_parent_class)->add_resource (base, didl_item, item, manager, &inner_error);
   if (inner_error != NULL) {
@@ -77,9 +79,10 @@ rygel_avc_transcoder_real_add_resource (RygelTranscoder *base, GUPnPDIDLLiteItem
 }
 
 static void
-rygel_avc_transcoder_class_init (RygelAVCTranscoderClass *klass) {
-  rygel_avc_transcoder_parent_class = g_type_class_peek_parent (klass);
-  RYGEL_TRANSCODER_CLASS (klass)->add_resource = rygel_avc_transcoder_real_add_resource;
+rygel_avc_transcoder_class_init (RygelAVCTranscoderClass *avc_transcoder_class) {
+  RygelTranscoderClass *transcoder_class = RYGEL_TRANSCODER_CLASS (avc_transcoder_class);
+
+  transcoder_class->add_resource = rygel_avc_transcoder_real_add_resource;
 }
 
 static void
diff --git a/src/rygel-avc-transcoder.h b/src/rygel-avc-transcoder.h
index 11895f0..051040f 100644
--- a/src/rygel-avc-transcoder.h
+++ b/src/rygel-avc-transcoder.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -20,6 +20,8 @@
 #ifndef __RYGEL_GST_0_10_MEDIA_ENGINE_AVC_TRANSCODER_H__
 #define __RYGEL_GST_0_10_MEDIA_ENGINE_AVC_TRANSCODER_H__
 
+#include <glib.h>
+#include <glib-object.h>
 #include "rygel-video-transcoder.h"
 
 G_BEGIN_DECLS
@@ -44,9 +46,11 @@ struct _RygelAVCTranscoderClass {
   RygelVideoTranscoderClass parent_class;
 };
 
-GType rygel_avc_transcoder_get_type (void) G_GNUC_CONST;
+GType
+rygel_avc_transcoder_get_type (void) G_GNUC_CONST;
 
-RygelAVCTranscoder* rygel_avc_transcoder_new (void);
+RygelAVCTranscoder *
+rygel_avc_transcoder_new (void);
 
 G_END_DECLS
 
diff --git a/src/rygel-gst-data-source.c b/src/rygel-gst-data-source.c
index caa23ae..a35b47e 100644
--- a/src/rygel-gst-data-source.c
+++ b/src/rygel-gst-data-source.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * Author: Jens Georg <jensg openismus com>
  *
@@ -20,66 +20,44 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include "rygel-gst-utils.h"
+#include <glib/gi18n-lib.h>
+#include <rygel-server.h>
 #include "rygel-gst-data-source.h"
+#include "rygel-gst-errors.h"
 #include "rygel-gst-sink.h"
-#include <glib/gi18n-lib.h>
-
-static void rygel_gst_data_source_rygel_data_source_interface_init (RygelDataSourceIface *iface);
-static void rygel_gst_data_source_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void rygel_gst_data_source_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+#include "rygel-gst-utils.h"
 
-G_DEFINE_TYPE_WITH_CODE (RygelGstDataSource, rygel_gst_data_source, G_TYPE_OBJECT,
-  G_IMPLEMENT_INTERFACE (RYGEL_TYPE_DATA_SOURCE, rygel_gst_data_source_rygel_data_source_interface_init))
+static void
+rygel_gst_data_source_rygel_data_source_interface_init (RygelDataSourceIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (RygelGstDataSource,
+                         rygel_gst_data_source,
+                         G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (RYGEL_TYPE_DATA_SOURCE,
+                                                rygel_gst_data_source_rygel_data_source_interface_init))
+
+#define RYGEL_GST_DATA_SOURCE_GET_PRIVATE(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+                                RYGEL_TYPE_GST_DATA_SOURCE, \
+                                RygelGstDataSourcePrivate))
+#define RYGEL_GST_SINK_NAME "http-gst-sink"
 
 enum  {
   RYGEL_GST_DATA_SOURCE_DUMMY_PROPERTY,
   RYGEL_GST_DATA_SOURCE_SOURCE
 };
 
-typedef enum  {
-  RYGEL_GST_DATA_SOURCE_ERROR_NOT_COMPATIBLE
-} RygelGstDataSourceError;
-
-#define RYGEL_GST_DATA_SOURCE_ERROR rygel_gst_data_source_error_quark ()
-
 struct _RygelGstDataSourcePrivate {
-  GstElement* src;
-  GstPipeline* pipeline;
-  RygelHTTPSeek* seek;
-  RygelGstSink* sink;
+  GstElement *src;
+  GstPipeline *pipeline;
+  RygelHTTPSeek *seek;
+  RygelGstSink *sink;
   guint bus_watch_id;
 };
 
-static RygelDataSourceIface* rygel_gst_data_source_rygel_data_source_parent_iface = NULL;
-
-GQuark
-rygel_gst_error_quark (void) {
-  return g_quark_from_static_string ("rygel_gst_error-quark");
-}
-
-
-#define RYGEL_GST_DATA_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_GST_DATA_SOURCE, RygelGstDataSourcePrivate))
-
-static void rygel_gst_data_source_real_start (RygelDataSource *base, RygelHTTPSeek* offsets, GError **error);
-static void rygel_gst_data_source_prepare_pipeline (RygelGstDataSource* self, const gchar *name, GstElement* src, GError **error);
-static void rygel_gst_data_source_real_freeze (RygelDataSource *base);
-static void rygel_gst_data_source_real_thaw (RygelDataSource *base);
-static void rygel_gst_data_source_real_stop (RygelDataSource *base);
-static void on_pad_added (GstElement* _sender, GstPad* pad, gpointer self);
-static gboolean on_bus_watch (GstBus* bus, GstMessage* message, gpointer self);
-#define RYGEL_GST_SINK_NAME "http-gst-sink"
-
-static gboolean rygel_gst_data_source_perform_seek (RygelGstDataSource* self);
-static void rygel_gst_data_source_finalize (GObject* obj);
-
-
-GQuark rygel_gst_data_source_error_quark (void) {
-  return g_quark_from_static_string ("rygel_gst_data_source_error-quark");
-}
-
 RygelGstDataSource *
-rygel_gst_data_source_new (const gchar *uri, GError **error) {
+rygel_gst_data_source_new_from_uri (const gchar  *uri,
+                                    GError      **error) {
   GstElement *source = rygel_gst_utils_create_source_for_uri (uri);
   RygelGstDataSource *data_source;
 
@@ -93,109 +71,47 @@ rygel_gst_data_source_new (const gchar *uri, GError **error) {
     return NULL;
   }
 
-  data_source = rygel_gst_data_source_new_from_element (source);
+  data_source = rygel_gst_data_source_new (source);
   gst_object_unref (source);
 
   return data_source;
 }
 
-RygelGstDataSource*
-rygel_gst_data_source_new_from_element (GstElement* element) {
+RygelGstDataSource *
+rygel_gst_data_source_new (GstElement *source) {
+  g_return_val_if_fail (GST_IS_ELEMENT (source), NULL);
+
   return RYGEL_GST_DATA_SOURCE (g_object_new (RYGEL_TYPE_GST_DATA_SOURCE,
-                                              "source", element,
+                                              "source", source,
                                               NULL));
 }
 
 static void
-rygel_gst_data_source_real_start (RygelDataSource *base, RygelHTTPSeek* offsets, GError **error) {
-  RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (base);
-  GError *inner_error = NULL;
-
-  self->priv->seek = offsets;
-  rygel_gst_data_source_prepare_pipeline (self, "RygelGstDataSource", self->priv->src, &inner_error);
-  if (inner_error) {
-    g_propagate_error (error, inner_error);
-    return;
-  }
-
-  if (self->priv->seek) {
-    gst_element_set_state (GST_ELEMENT (self->priv->pipeline), GST_STATE_PAUSED);
-  } else {
-    gst_element_set_state (GST_ELEMENT (self->priv->pipeline), GST_STATE_PLAYING);
-  }
-}
-
-static void
-rygel_gst_data_source_real_freeze (RygelDataSource *base) {
-  RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (base);
-
-  rygel_gst_sink_freeze (self->priv->sink);
-}
-
-static void
-rygel_gst_data_source_real_thaw (RygelDataSource *base) {
-  RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (base);
-  rygel_gst_sink_thaw (self->priv->sink);
-}
-
-static gboolean
-on_idle_emit_done (gpointer user_data) {
-  RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (user_data);
-
-  g_signal_emit_by_name (self, "done");
-  return FALSE;
-}
-
-static void
-rygel_gst_data_source_real_stop (RygelDataSource *base) {
-  RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (base);
-
-  if (self->priv->sink) {
-    g_cancellable_cancel (rygel_gst_sink_get_cancellable (self->priv->sink));
-  }
-
-  if (self->priv->pipeline) {
-    gst_element_set_state (GST_ELEMENT (self->priv->pipeline), GST_STATE_NULL);
-  }
-
-  g_source_remove (self->priv->bus_watch_id);
-
-  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, on_idle_emit_done, g_object_ref (self), g_object_unref);
-}
-
-
-static void
-on_pad_added (GstElement* src, GstPad* src_pad, gpointer user_data) {
+on_pad_added (GstElement *src G_GNUC_UNUSED,
+              GstPad     *src_pad,
+              gpointer    user_data) {
   RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (user_data);
+  GstCaps *caps = gst_pad_get_caps_reffed (src_pad);
+  GstElement *sink = gst_bin_get_by_name (GST_BIN (self->priv->pipeline),
+                                          RYGEL_GST_SINK_NAME);
+  GstPad *sink_pad = NULL;
+  GstElement *depay = rygel_gst_utils_get_rtp_depayloader (caps);
 
-  g_return_if_fail (self != NULL);
-  g_return_if_fail (src != NULL);
-  g_return_if_fail (src_pad != NULL);
-
-  GstCaps* caps = gst_pad_get_caps_reffed (src_pad);
-  GstElement* sink = gst_bin_get_by_name (GST_BIN (self->priv->pipeline), RYGEL_GST_SINK_NAME);
-  GstPad* sink_pad = NULL;
-
-  GstElement* depay = rygel_gst_utils_get_rtp_depayloader (caps);
   if (depay) {
     gst_bin_add (GST_BIN (self->priv->pipeline), depay);
 
     if (!gst_element_link (depay, sink)) {
        gchar *depay_name = gst_object_get_name (GST_OBJECT (depay));
        gchar *sink_name = gst_object_get_name (GST_OBJECT (sink));
+
        g_critical (_("Failed to link %s to %s"),
-         depay_name,
-         sink_name);
+		   depay_name,
+		   sink_name);
        g_free (depay_name);
        g_free (sink_name);
 
        g_signal_emit_by_name (self, "done");
-       gst_object_unref (depay);
-       gst_object_unref (sink_pad);
-       gst_object_unref (sink);
-       gst_caps_unref (caps);
-
-       return;
+       goto done;
     }
 
     sink_pad = gst_element_get_compatible_pad (depay, src_pad, caps);
@@ -207,46 +123,116 @@ on_pad_added (GstElement* src, GstPad* src_pad, gpointer user_data) {
   if (gst_pad_link (src_pad, sink_pad) != GST_PAD_LINK_OK) {
     gchar *src_pad_name = gst_object_get_name (GST_OBJECT (src_pad));
     gchar *sink_pad_name = gst_object_get_name (GST_OBJECT (sink_pad));
+
     g_critical (_("Failed to link pad %s to %s"),
-       src_pad_name, sink_pad_name);
+		src_pad_name,
+		sink_pad_name);
     g_free (src_pad_name);
     g_free (sink_pad_name);
 
     g_signal_emit_by_name (self, "done");
+    goto done;
+  }
+
+  if (depay) {
+    gst_element_sync_state_with_parent (depay);
+  }
+
+done:
+  if (depay) {
     gst_object_unref (depay);
+  }
+  if (sink_pad) {
     gst_object_unref (sink_pad);
+  }
+  if (sink) {
     gst_object_unref (sink);
+  }
+  if (caps) {
     gst_caps_unref (caps);
+  }
+}
 
-    return;
+static gboolean
+rygel_gst_data_source_perform_seek (RygelGstDataSource *self) {
+  GstSeekType stop_type = GST_SEEK_TYPE_NONE;
+  GstFormat format;
+  GstSeekFlags flags = GST_SEEK_FLAG_FLUSH;
+  gint64 start;
+  gint64 stop;
+
+  if (self->priv->seek &&
+      rygel_http_seek_get_length (self->priv->seek) >= rygel_http_seek_get_total_length (self->priv->seek)) {
+    return TRUE;
   }
 
-  if (depay) {
-    gst_element_sync_state_with_parent (depay);
+  if (rygel_http_seek_get_seek_type (self->priv->seek) == RYGEL_HTTP_SEEK_TYPE_TIME) {
+    format = GST_FORMAT_TIME;
+    flags |= GST_SEEK_FLAG_KEY_UNIT;
+    start = rygel_http_seek_get_start (self->priv->seek) * GST_USECOND;
+    stop = rygel_http_seek_get_stop (self->priv->seek) * GST_USECOND;
+  } else {
+    format = GST_FORMAT_BYTES;
+    flags |= GST_SEEK_FLAG_ACCURATE;
+    start = rygel_http_seek_get_start (self->priv->seek);
+    stop = rygel_http_seek_get_stop (self->priv->seek);
   }
 
-  gst_object_unref (depay);
-  gst_object_unref (sink_pad);
-  gst_object_unref (sink);
-  gst_caps_unref (caps);
+  if (rygel_http_seek_get_stop (self->priv->seek) > 0) {
+    stop_type = GST_SEEK_TYPE_SET;
+  }
+
+  if (gst_element_seek (GST_ELEMENT (self->priv->pipeline),
+                        1.0,
+                        format,
+                        flags,
+                        GST_SEEK_TYPE_SET,
+                        start,
+                        stop_type,
+                        stop + 1)) {
+    GError *error;
+
+    g_warning(_("Failed to seek to offsets %lld:%lld"),
+      rygel_http_seek_get_start (self->priv->seek),
+      rygel_http_seek_get_stop (self->priv->seek));
+
+    error  = g_error_new_literal (RYGEL_DATA_SOURCE_ERROR,
+                                  RYGEL_DATA_SOURCE_ERROR_SEEK_FAILED,
+                                  _("Failed to seek"));
+    g_signal_emit_by_name (self, "error", error);
+    g_error_free (error);
+
+    return FALSE;
+  }
+
+  return TRUE;
 }
 
 static gboolean
-on_bus_watch (GstBus* bus G_GNUC_UNUSED,
-              GstMessage* message,
-              gpointer user_data) {
+on_idle_emit_done (gpointer user_data) {
+  RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (user_data);
+
+  g_signal_emit_by_name (self, "done");
+  return FALSE;
+}
+
+static gboolean
+on_bus_watch (GstBus     *bus G_GNUC_UNUSED,
+              GstMessage *message,
+              gpointer    user_data) {
   RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (user_data);
   gboolean ret = TRUE;
 
   if (message->type == GST_MESSAGE_EOS) {
     ret = FALSE;
   } else if (message->type == GST_MESSAGE_STATE_CHANGED) {
+    GstState old_state;
+    GstState new_state;
+
     if (message->src != GST_OBJECT (self->priv->pipeline)) {
       return TRUE;
     }
 
-    GstState old_state;
-    GstState new_state;
     gst_message_parse_state_changed (message, &old_state, &new_state, NULL);
 
     if (old_state == GST_STATE_NULL && new_state == GST_STATE_READY) {
@@ -269,31 +255,29 @@ on_bus_watch (GstBus* bus G_GNUC_UNUSED,
       }
     }
 
-    if (self->priv->seek) {
-      if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED) {
-        if (rygel_gst_data_source_perform_seek (self)) {
-          gst_element_set_state (GST_ELEMENT (self->priv->pipeline), GST_STATE_PLAYING);
-        }
-      }
+    if (self->priv->seek &&
+        old_state == GST_STATE_READY &&
+        new_state == GST_STATE_PAUSED &&
+        rygel_gst_data_source_perform_seek (self)) {
+      gst_element_set_state (GST_ELEMENT (self->priv->pipeline),
+                             GST_STATE_PLAYING);
     }
-
   } else {
-
     gchar *err_msg = NULL;
-    gst_message_parse_error (message, NULL, &err_msg);
-
     gchar *pipeline_name = gst_object_get_name (GST_OBJECT (self->priv->pipeline));
 
     if (message->type == GST_MESSAGE_ERROR) {
+      gst_message_parse_error (message, NULL, &err_msg);
       g_critical (_("Error from pipeline %s: %s"),
-        pipeline_name,
-        err_msg);
+                  pipeline_name,
+                  err_msg);
 
       ret = FALSE;
     } else if (message->type == GST_MESSAGE_WARNING) {
+      gst_message_parse_warning (message, NULL, &err_msg);
       g_warning (_("Warning from pipeline %s: %s"),
-        pipeline_name,
-        err_msg);
+                 pipeline_name,
+                 err_msg);
     }
 
     g_free (pipeline_name);
@@ -301,41 +285,58 @@ on_bus_watch (GstBus* bus G_GNUC_UNUSED,
   }
 
   if (!ret) {
-    g_idle_add_full (G_PRIORITY_DEFAULT, on_idle_emit_done, g_object_ref (self), g_object_unref);
+    g_idle_add_full (G_PRIORITY_DEFAULT,
+                     on_idle_emit_done,
+                     g_object_ref (self),
+                     g_object_unref);
   }
 
   return ret;
 }
 
 static void
-rygel_gst_data_source_prepare_pipeline (RygelGstDataSource* self, const gchar *name, GstElement* src, GError **error) {
+rygel_gst_data_source_prepare_pipeline (RygelGstDataSource  *self,
+                                        const gchar         *name,
+                                        GstElement          *src,
+                                        GError             **error) {
+  GstBus *bus;
+
   self->priv->sink = rygel_gst_sink_new (RYGEL_DATA_SOURCE (self), self->priv->seek);
 
   self->priv->pipeline = GST_PIPELINE (gst_pipeline_new (name));
-  if(self->priv->pipeline == NULL) {
-    g_set_error (error,
-      RYGEL_DATA_SOURCE_ERROR,
-      RYGEL_DATA_SOURCE_ERROR_GENERAL,
-      _("Failed to create pipeline"));
+  if (self->priv->pipeline == NULL) {
+    g_set_error_literal (error,
+                         RYGEL_DATA_SOURCE_ERROR,
+                         RYGEL_DATA_SOURCE_ERROR_GENERAL,
+                         _("Failed to create pipeline"));
+    return;
   }
 
-  gst_bin_add_many (GST_BIN (self->priv->pipeline), self->priv->src, self->priv->sink, NULL);
+  gst_bin_add_many (GST_BIN (self->priv->pipeline),
+                    self->priv->src,
+                    self->priv->sink,
+                    NULL);
 
   if (src->numsrcpads == 0) {
     // Seems source uses dynamic pads, so link when the pad is available
 
-    g_signal_connect_object (self->priv->src, "pad-added", (GCallback) on_pad_added, self, 0);
+    g_signal_connect_object (self->priv->src,
+                             "pad-added",
+                             G_CALLBACK (on_pad_added),
+                             self,
+                             0);
   } else {
     // static pads? easy!
     if (!gst_element_link (self->priv->src, GST_ELEMENT (self->priv->sink))) {
       gchar *src_name = gst_object_get_name (GST_OBJECT (self->priv->src));
       gchar *sink_name = gst_object_get_name (GST_OBJECT (self->priv->sink));
+
       g_set_error (error,
-        RYGEL_GST_ERROR,
-        RYGEL_GST_ERROR_LINK,
-        "Failed to link %s to %s",
-        src_name,
-        sink_name);
+                   RYGEL_GST_ERROR,
+                   RYGEL_GST_ERROR_LINK,
+                   "Failed to link %s to %s",
+                   src_name,
+                   sink_name);
       g_free (src_name);
       g_free (sink_name);
 
@@ -344,119 +345,101 @@ rygel_gst_data_source_prepare_pipeline (RygelGstDataSource* self, const gchar *n
   }
 
   // Bus handler
-  GstBus *bus = gst_pipeline_get_bus (self->priv->pipeline);
-  self->priv->bus_watch_id = gst_bus_add_watch_full (bus, G_PRIORITY_DEFAULT, on_bus_watch, g_object_ref (self), g_object_unref);
+  bus = gst_pipeline_get_bus (self->priv->pipeline);
+  self->priv->bus_watch_id = gst_bus_add_watch_full (bus,
+                                                     G_PRIORITY_DEFAULT,
+                                                     on_bus_watch,
+                                                     g_object_ref (self),
+                                                     g_object_unref);
   gst_object_unref (bus);
 }
 
-static gboolean
-rygel_gst_data_source_perform_seek (RygelGstDataSource* self) {
-  GstSeekType stop_type = GST_SEEK_TYPE_NONE;
-  GstFormat format = 0;
-  GstSeekFlags flags = GST_SEEK_FLAG_FLUSH;
-  gint64 start = 0LL;
-  gint64 stop = 0LL;
+static void
+rygel_gst_data_source_real_start (RygelDataSource  *base,
+                                  RygelHTTPSeek    *offsets,
+                                  GError          **error) {
+  RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (base);
+  GError *inner_error = NULL;
 
-  if (self->priv->seek &&
-      rygel_http_seek_get_length (self->priv->seek) >= rygel_http_seek_get_total_length (self->priv->seek)) {
-    return TRUE;
+  if (offsets) {
+    g_object_ref (offsets);
   }
-
-  if (rygel_http_seek_get_seek_type (self->priv->seek) == RYGEL_HTTP_SEEK_TYPE_TIME) {
-    format = GST_FORMAT_TIME;
-    flags |= GST_SEEK_FLAG_KEY_UNIT;
-    start = rygel_http_seek_get_start (self->priv->seek) * GST_USECOND;
-    stop = rygel_http_seek_get_stop (self->priv->seek) * GST_USECOND;
-  } else {
-    format = GST_FORMAT_BYTES;
-    flags |= GST_SEEK_FLAG_ACCURATE;
-    start = rygel_http_seek_get_start (self->priv->seek);
-    stop = rygel_http_seek_get_stop (self->priv->seek);
+  if (self->priv->seek) {
+    g_object_unref (self->priv->seek);
   }
-
-  if (rygel_http_seek_get_stop (self->priv->seek) > ((gint64) 0)) {
-    stop_type = GST_SEEK_TYPE_SET;
+  self->priv->seek = offsets;
+  rygel_gst_data_source_prepare_pipeline (self, "RygelGstDataSource", self->priv->src, &inner_error);
+  if (inner_error) {
+    g_propagate_error (error, inner_error);
+    return;
   }
 
-  if(gst_element_seek (GST_ELEMENT (self->priv->pipeline),
-    1.0, format, flags, GST_SEEK_TYPE_SET,
-    start, stop_type, stop + 1)) {
-    GError *error;
-    g_warning(_("Failed to seek to offsets %lld:%lld"),
-      rygel_http_seek_get_start (self->priv->seek),
-      rygel_http_seek_get_stop (self->priv->seek));
-
-    error  = g_error_new_literal (RYGEL_DATA_SOURCE_ERROR,
-      RYGEL_DATA_SOURCE_ERROR_SEEK_FAILED,
-      _("Failed to seek"));
-    g_signal_emit_by_name (self, "error", error);
-    g_error_free (error);
-
-    return FALSE;
+  if (self->priv->seek) {
+    gst_element_set_state (GST_ELEMENT (self->priv->pipeline), GST_STATE_PAUSED);
+  } else {
+    gst_element_set_state (GST_ELEMENT (self->priv->pipeline), GST_STATE_PLAYING);
   }
-
-  return TRUE;
 }
 
 static void
-rygel_gst_data_source_class_init (RygelGstDataSourceClass *klass) {
-  rygel_gst_data_source_parent_class = g_type_class_peek_parent (klass);
-  g_type_class_add_private (klass, sizeof (RygelGstDataSourcePrivate));
-  G_OBJECT_CLASS (klass)->finalize = rygel_gst_data_source_finalize;
-  G_OBJECT_CLASS (klass)->get_property = rygel_gst_data_source_get_property;
-  G_OBJECT_CLASS (klass)->set_property = rygel_gst_data_source_set_property;
-  g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_GST_DATA_SOURCE_SOURCE, g_param_spec_object ("source", "souce", "source", GST_TYPE_ELEMENT, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
-}
+rygel_gst_data_source_real_freeze (RygelDataSource *base) {
+  RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (base);
 
-static void
-rygel_gst_data_source_rygel_data_source_interface_init (RygelDataSourceIface *iface) {
-  rygel_gst_data_source_rygel_data_source_parent_iface = g_type_interface_peek_parent (iface);
-  iface->start = (void (*)(RygelDataSource*, RygelHTTPSeek*, GError**)) rygel_gst_data_source_real_start;
-  iface->freeze = (void (*)(RygelDataSource*)) rygel_gst_data_source_real_freeze;
-  iface->thaw = (void (*)(RygelDataSource*)) rygel_gst_data_source_real_thaw;
-  iface->stop = (void (*)(RygelDataSource*)) rygel_gst_data_source_real_stop;
+  rygel_gst_sink_freeze (self->priv->sink);
 }
 
 static void
-rygel_gst_data_source_init (RygelGstDataSource *self) {
-  self->priv = RYGEL_GST_DATA_SOURCE_GET_PRIVATE (self);
-  self->priv->seek = NULL;
+rygel_gst_data_source_real_thaw (RygelDataSource *base) {
+  RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (base);
+
+  rygel_gst_sink_thaw (self->priv->sink);
 }
 
 static void
-rygel_gst_data_source_finalize (GObject* obj) {
-  RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (obj);
+rygel_gst_data_source_real_stop (RygelDataSource *base) {
+  RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (base);
 
   if (self->priv->sink) {
     g_cancellable_cancel (rygel_gst_sink_get_cancellable (self->priv->sink));
   }
 
   if (self->priv->pipeline) {
-    gst_element_set_state (GST_ELEMENT ( self->priv->pipeline), GST_STATE_NULL);
+    gst_element_set_state (GST_ELEMENT (self->priv->pipeline), GST_STATE_NULL);
   }
 
-  gst_object_unref (self->priv->src);
-  gst_object_unref (self->priv->pipeline);
-  g_object_unref (self->priv->seek);
-  gst_object_unref (self->priv->sink);
+  g_source_remove (self->priv->bus_watch_id);
 
-  G_OBJECT_CLASS (rygel_gst_data_source_parent_class)->finalize (obj);
+  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+                   on_idle_emit_done,
+                   g_object_ref (self),
+                   g_object_unref);
 }
 
-/**
- * rygel_gst_data_source_get_gst_element:
- * @self: A #RygelGstDataSource
- *
- * Retrieves the underyling GStreamer element, for use by
- *
- * Return value: a #GstElement
- */
-GstElement*
-rygel_gst_data_source_get_gst_element (RygelGstDataSource *self)
-{
-  g_return_val_if_fail (self, NULL);
+static void
+rygel_gst_data_source_dispose (GObject *object) {
+  RygelGstDataSource *self = RYGEL_GST_DATA_SOURCE (object);
+  RygelGstDataSourcePrivate *priv = self->priv;
 
-  return self->priv->src;
+  if (priv->sink) {
+    g_cancellable_cancel (rygel_gst_sink_get_cancellable (priv->sink));
+    gst_object_unref (priv->sink);
+    priv->sink = NULL;
+  }
+
+  if (priv->pipeline) {
+    gst_element_set_state (GST_ELEMENT (priv->pipeline), GST_STATE_NULL);
+    gst_object_unref (priv->pipeline);
+    priv->pipeline = NULL;
+  }
+
+  if (priv->src) {
+    gst_object_unref (priv->src);
+  }
+  if (priv->seek) {
+    g_object_unref (priv->seek);
+  }
+
+  G_OBJECT_CLASS (rygel_gst_data_source_parent_class)->dispose (object);
 }
 
 static void
@@ -491,3 +474,54 @@ rygel_gst_data_source_set_property (GObject *object, guint property_id, const GV
       break;
   }
 }
+
+static void
+rygel_gst_data_source_class_init (RygelGstDataSourceClass *gst_data_source_class) {
+  GObjectClass *object_class = G_OBJECT_CLASS (gst_data_source_class);
+
+  object_class->dispose = rygel_gst_data_source_dispose;
+  object_class->get_property = rygel_gst_data_source_get_property;
+  object_class->set_property = rygel_gst_data_source_set_property;
+  g_object_class_install_property (object_class,
+                                   RYGEL_GST_DATA_SOURCE_SOURCE,
+                                   g_param_spec_object ("source",
+                                                        "source",
+                                                        "source",
+                                                        GST_TYPE_ELEMENT,
+                                                        G_PARAM_STATIC_NAME |
+                                                        G_PARAM_STATIC_NICK |
+                                                        G_PARAM_STATIC_BLURB |
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE));
+  g_type_class_add_private (gst_data_source_class, sizeof (RygelGstDataSourcePrivate));
+}
+
+static void
+rygel_gst_data_source_rygel_data_source_interface_init (RygelDataSourceIface *iface) {
+  iface->start = rygel_gst_data_source_real_start;
+  iface->freeze = rygel_gst_data_source_real_freeze;
+  iface->thaw = rygel_gst_data_source_real_thaw;
+  iface->stop = rygel_gst_data_source_real_stop;
+}
+
+static void
+rygel_gst_data_source_init (RygelGstDataSource *self) {
+  self->priv = RYGEL_GST_DATA_SOURCE_GET_PRIVATE (self);
+}
+
+/**
+ * rygel_gst_data_source_get_gst_element:
+ * @self: A #RygelGstDataSource
+ *
+ * Retrieves the underyling GStreamer element, for use by
+ *
+ * Return value: a #GstElement
+ */
+GstElement*
+rygel_gst_data_source_get_gst_element (RygelGstDataSource *self)
+{
+  g_return_val_if_fail (RYGEL_IS_GST_DATA_SOURCE (self), NULL);
+
+  return self->priv->src;
+}
diff --git a/src/rygel-gst-data-source.h b/src/rygel-gst-data-source.h
index 784e8a1..8468f4f 100644
--- a/src/rygel-gst-data-source.h
+++ b/src/rygel-gst-data-source.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -22,14 +22,7 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <stdlib.h>
-#include <string.h>
-#include <rygel-server.h>
 #include <gst/gst.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
-#include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <gee.h>
-#include <rygel-core.h>
 
 G_BEGIN_DECLS
 
@@ -57,24 +50,15 @@ GType
 rygel_gst_data_source_get_type (void) G_GNUC_CONST;
 
 RygelGstDataSource *
-rygel_gst_data_source_new (const gchar *uri,
-                           GError **error);
+rygel_gst_data_source_new_from_uri (const gchar  *uri,
+                                    GError      **error);
 
 RygelGstDataSource *
-rygel_gst_data_source_new_from_element (GstElement *element);
+rygel_gst_data_source_new (GstElement *source);
 
 GstElement *
 rygel_gst_data_source_get_gst_element (RygelGstDataSource *self);
 
-typedef enum  {
-  RYGEL_GST_ERROR_MISSING_PLUGIN,
-  RYGEL_GST_ERROR_LINK
-} RygelGstError;
-
-#define RYGEL_GST_ERROR rygel_gst_error_quark ()
-GQuark rygel_gst_error_quark (void);
-
-
 G_END_DECLS
 
 #endif /* __RYGEL_GST_0_10_MEDIA_ENGINE_GST_DATA_SOURCE_H__ */
diff --git a/src/rygel-gst-errors.c b/src/rygel-gst-errors.c
new file mode 100644
index 0000000..a8f5ddb
--- /dev/null
+++ b/src/rygel-gst-errors.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Author: Krzesimir Nowak <krnowak openismus com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ */
+
+#include "rygel-gst-errors.h"
+
+GQuark
+rygel_gst_error_quark (void) {
+  return g_quark_from_static_string ("rygel-gst-error-quark");
+}
+
+GQuark
+rygel_gst_data_source_error_quark (void) {
+  return g_quark_from_static_string ("rygel-gst-data-source-error-quark");
+}
+
+GQuark
+rygel_gst_transcoder_error_quark (void) {
+  return g_quark_from_static_string ("rygel-gst-transcoder-error-quark");
+}
diff --git a/src/rygel-gst-errors.h b/src/rygel-gst-errors.h
new file mode 100644
index 0000000..bebff22
--- /dev/null
+++ b/src/rygel-gst-errors.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2013 Intel Corporation.
+ *
+ * Author: Krzesimir Nowak <krnowak openismus com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ */
+
+#ifndef __RYGEL_GST_0_10_MEDIA_ENGINE_ERRORS_H__
+#define __RYGEL_GST_0_10_MEDIA_ENGINE_ERRORS_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum  {
+  RYGEL_GST_ERROR_MISSING_PLUGIN,
+  RYGEL_GST_ERROR_LINK
+} RygelGstError;
+
+#define RYGEL_GST_ERROR (rygel_gst_error_quark ())
+GQuark
+rygel_gst_error_quark (void);
+
+typedef enum  {
+  RYGEL_GST_DATA_SOURCE_ERROR_NOT_COMPATIBLE
+} RygelGstDataSourceError;
+
+#define RYGEL_GST_DATA_SOURCE_ERROR (rygel_gst_data_source_error_quark ())
+GQuark
+rygel_gst_data_source_error_quark (void);
+
+typedef enum  {
+  RYGEL_GST_TRANSCODER_ERROR_CANT_TRANSCODE
+} RygelGstTranscoderError;
+
+#define RYGEL_GST_TRANSCODER_ERROR (rygel_gst_transcoder_error_quark ())
+GQuark
+rygel_gst_transcoder_error_quark (void);
+
+G_END_DECLS
+
+#endif /* __RYGEL_GST_0_10_MEDIA_ENGINE_ERRORS_H__ */
diff --git a/src/rygel-gst-media-engine.c b/src/rygel-gst-media-engine.c
index 2ac5f7a..d20c3fe 100644
--- a/src/rygel-gst-media-engine.c
+++ b/src/rygel-gst-media-engine.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * Author: Jens Georg <jensg openismus com>
  *
@@ -20,6 +20,11 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+#include <gee.h>
+#include <rygel-core.h>
+#include <gst/gst.h>
+#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
+#include <libgupnp-dlna/gupnp-dlna-profile.h>
 #include "rygel-gst-data-source.h"
 #include "rygel-gst-media-engine.h"
 #include "rygel-aac-transcoder.h"
@@ -36,37 +41,41 @@ struct _RygelGstMediaEnginePrivate {
   GList *transcoders;
 };
 
-#define RYGEL_GST_MEDIA_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_GST_MEDIA_ENGINE, RygelGstMediaEnginePrivate))
+#define RYGEL_GST_MEDIA_ENGINE_GET_PRIVATE(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+                                RYGEL_TYPE_GST_MEDIA_ENGINE, \
+                                RygelGstMediaEnginePrivate))
 
-static void rygel_gst_media_engine_finalize (GObject *obj);
-
-RygelGstMediaEngine*
+RygelGstMediaEngine *
 rygel_gst_media_engine_new (void) {
   return RYGEL_GST_MEDIA_ENGINE (g_object_new (RYGEL_TYPE_GST_MEDIA_ENGINE, NULL));
 }
 
-static GList*
+static GList *
 rygel_gst_media_engine_real_get_dlna_profiles (RygelMediaEngine *base) {
   RygelGstMediaEngine *self = RYGEL_GST_MEDIA_ENGINE (base);
+
   return self->priv->dlna_profiles;
 }
 
-static GList*
+static GList *
 rygel_gst_media_engine_real_get_transcoders (RygelMediaEngine *base) {
   RygelGstMediaEngine *self = RYGEL_GST_MEDIA_ENGINE (base);
+
   return self->priv->transcoders;
 }
 
 
-static RygelDataSource*
+static RygelDataSource *
 rygel_gst_media_engine_real_create_data_source (RygelMediaEngine *base G_GNUC_UNUSED,
                                                 const gchar *uri) {
-  RygelDataSource *result = NULL;
-  GError *error = NULL;
+  RygelDataSource *result;
+  GError *error;
 
   g_return_val_if_fail (uri != NULL, NULL);
 
-  result = RYGEL_DATA_SOURCE (rygel_gst_data_source_new (uri, &error));
+  error = NULL;
+  result = RYGEL_DATA_SOURCE (rygel_gst_data_source_new_from_uri (uri, &error));
   if (error) {
     g_warning ("rygel_gst_data_source_new() failed: %s", error->message);
     g_error_free (error);
@@ -76,12 +85,38 @@ rygel_gst_media_engine_real_create_data_source (RygelMediaEngine *base G_GNUC_UN
 }
 
 static void
-rygel_gst_media_engine_class_init (RygelGstMediaEngineClass *klass) {
-  g_type_class_add_private (klass, sizeof (RygelGstMediaEnginePrivate));
-  RYGEL_MEDIA_ENGINE_CLASS (klass)->get_dlna_profiles = rygel_gst_media_engine_real_get_dlna_profiles;
-  RYGEL_MEDIA_ENGINE_CLASS (klass)->get_transcoders = rygel_gst_media_engine_real_get_transcoders;
-  RYGEL_MEDIA_ENGINE_CLASS (klass)->create_data_source = rygel_gst_media_engine_real_create_data_source;
-  G_OBJECT_CLASS (klass)->finalize = rygel_gst_media_engine_finalize;
+rygel_gst_media_engine_dispose (GObject *object) {
+  RygelGstMediaEngine *self = RYGEL_GST_MEDIA_ENGINE (object);
+  RygelGstMediaEnginePrivate *priv = self->priv;
+
+  if (priv->dlna_profiles) {
+    GList *profiles = priv->dlna_profiles;
+
+    priv->dlna_profiles = NULL;
+    g_list_free_full (profiles, (GDestroyNotify) rygel_dlna_profile_unref);
+  }
+  if (priv->transcoders) {
+    GList *transcoders = priv->transcoders;
+
+    priv->transcoders = NULL;
+    g_list_free_full (transcoders, (GDestroyNotify) g_object_unref);
+  }
+
+  G_OBJECT_CLASS (rygel_gst_media_engine_parent_class)->dispose (object);
+}
+
+static void
+rygel_gst_media_engine_class_init (RygelGstMediaEngineClass *gst_media_engine_class) {
+  GObjectClass *object_class = G_OBJECT_CLASS (gst_media_engine_class);
+  RygelMediaEngineClass *media_engine_class = RYGEL_MEDIA_ENGINE_CLASS (gst_media_engine_class);
+
+  media_engine_class->get_dlna_profiles = rygel_gst_media_engine_real_get_dlna_profiles;
+  media_engine_class->get_transcoders = rygel_gst_media_engine_real_get_transcoders;
+  media_engine_class->create_data_source = rygel_gst_media_engine_real_create_data_source;
+  object_class->dispose = rygel_gst_media_engine_dispose;
+
+  g_type_class_add_private (gst_media_engine_class,
+                            sizeof (RygelGstMediaEnginePrivate));
 }
 
 static void
@@ -89,7 +124,7 @@ rygel_gst_media_engine_init (RygelGstMediaEngine *self) {
   GUPnPDLNADiscoverer *discoverer;
   const GList *profile_collection;
   GeeArrayList *transcoder_list = NULL;
-  RygelMetaConfig *config;
+  RygelConfiguration *config;
   GError *error = NULL;
   const GList *profile_it;
 
@@ -129,14 +164,17 @@ rygel_gst_media_engine_init (RygelGstMediaEngine *self) {
    * sometimes even preferring transcoded formats over the original data,
    * so this forces them to use other formats.
    */
-  config = rygel_meta_config_get_default ();
+  config = RYGEL_CONFIGURATION (rygel_meta_config_get_default ());
 
-  rygel_configuration_get_transcoding (RYGEL_CONFIGURATION (config), &error);
+  rygel_configuration_get_transcoding (config, &error);
   if (error) {
     g_clear_error (&error);
   } else {
     /* Note that the default GStreamer media engine uses the same config group name. */
-    transcoder_list = rygel_configuration_get_string_list (RYGEL_CONFIGURATION (config), "GstMediaEngine", "transcoders", &error);
+    transcoder_list = rygel_configuration_get_string_list (config,
+                                                           "GstMediaEngine",
+                                                           "transcoders",
+                                                           &error);
     if (error) {
       g_clear_error (&error);
       transcoder_list = NULL;
@@ -200,16 +238,6 @@ rygel_gst_media_engine_init (RygelGstMediaEngine *self) {
   g_object_unref (discoverer);
 }
 
-static void
-rygel_gst_media_engine_finalize (GObject *obj) {
-  RygelGstMediaEngine *self = RYGEL_GST_MEDIA_ENGINE (obj);
-
-  g_list_free_full (self->priv->dlna_profiles, (GDestroyNotify) rygel_dlna_profile_unref);
-  g_list_free_full (self->priv->transcoders, (GDestroyNotify) g_object_unref);
-
-  G_OBJECT_CLASS (rygel_gst_media_engine_parent_class)->finalize (obj);
-}
-
 RygelMediaEngine*
 module_get_instance (void) {
   gst_init (NULL, NULL);
diff --git a/src/rygel-gst-media-engine.h b/src/rygel-gst-media-engine.h
index 8d07dd9..da0d1b2 100644
--- a/src/rygel-gst-media-engine.h
+++ b/src/rygel-gst-media-engine.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * This file is part of Rygel.
  *
@@ -23,14 +23,7 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <stdlib.h>
-#include <string.h>
 #include <rygel-server.h>
-#include <gst/gst.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
-#include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <gee.h>
-#include <rygel-core.h>
 
 G_BEGIN_DECLS
 
@@ -54,11 +47,14 @@ struct _RygelGstMediaEngineClass {
   RygelMediaEngineClass parent_class;
 };
 
-GType rygel_gst_media_engine_get_type (void) G_GNUC_CONST;
+GType
+rygel_gst_media_engine_get_type (void) G_GNUC_CONST;
 
-RygelGstMediaEngine* rygel_gst_media_engine_new (void);
+RygelGstMediaEngine *
+rygel_gst_media_engine_new (void);
 
-RygelMediaEngine* module_get_instance (void);
+RygelMediaEngine *
+module_get_instance (void);
 
 G_END_DECLS
 
diff --git a/src/rygel-gst-sink.c b/src/rygel-gst-sink.c
index 7ad88f7..992715d 100644
--- a/src/rygel-gst-sink.c
+++ b/src/rygel-gst-sink.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2011 Nokia Corporation.
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
  *                               <zeeshan ali nokia com>
@@ -23,10 +23,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-
 #include "rygel-gst-sink.h"
 
-
 G_DEFINE_TYPE (RygelGstSink, rygel_gst_sink, GST_TYPE_BASE_SINK)
 
 enum
@@ -43,59 +41,62 @@ struct _RygelGstSinkPrivate {
   gint64 max_bytes;
   GMutex buffer_mutex;
   GCond buffer_condition;
-  RygelDataSource* source;
-  RygelHTTPSeek* offsets;
+  RygelDataSource *source;
+  RygelHTTPSeek *offsets;
   gboolean frozen;
-  GCancellable* cancellable;
+  GCancellable *cancellable;
 };
 
-typedef struct _CallbackData CallbackData;
+typedef struct CallbackData_ CallbackData;
 
-struct _CallbackData {
-  int _ref_count_;
+struct CallbackData_ {
+  int ref_count;
   RygelGstSink *self;
-  GstBuffer* buffer;
+  GstBuffer *buffer;
 };
 
-#define RYGEL_GST_SINK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_GST_SINK, RygelGstSinkPrivate))
+#define RYGEL_GST_SINK_GET_PRIVATE(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+                                RYGEL_TYPE_GST_SINK, \
+                                RygelGstSinkPrivate))
 
 #define RYGEL_GST_SINK_NAME "http-gst-sink"
 #define RYGEL_GST_SINK_PAD_NAME "sink"
 #define RYGEL_GST_SINK_MAX_BUFFERED_CHUNKS ((guint) 32)
 #define RYGEL_GST_SINK_MIN_BUFFERED_CHUNKS ((guint) 4)
 
-static void rygel_gst_sink_on_cancelled (RygelGstSink* self);
-static void on_cancelled (GCancellable* sender, gpointer user_data);
-static GstFlowReturn rygel_gst_sink_real_render (GstBaseSink *base, GstBuffer* buffer);
-static gboolean rygel_gst_sink_push_data (RygelGstSink* self, GstBuffer* buffer);
-static gboolean on_idle_push_data (gpointer self);
-static void rygel_gst_sink_finalize (GObject* obj);
-static void rygel_gst_sink_constructed (GObject* obj);
-static void rygel_gst_sink_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void rygel_gst_sink_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-static void clear_gmutex (GMutex *mutex);
-static void clear_gcond (GCond *mutex);
+static void
+rygel_gst_sink_on_cancelled (RygelGstSink *self) {
+  RygelGstSinkPrivate *priv = self->priv;
+
+  g_mutex_lock (&priv->buffer_mutex);
+  g_cond_broadcast (&priv->buffer_condition);
+  g_mutex_unlock (&priv->buffer_mutex);
+}
 
 static void
-on_cancelled (GCancellable* sender G_GNUC_UNUSED,
-              gpointer user_data) {
+on_cancelled (GCancellable *sender G_GNUC_UNUSED,
+              gpointer      user_data) {
   RygelGstSink *self = RYGEL_GST_SINK (user_data);
 
   rygel_gst_sink_on_cancelled (self);
 }
 
-RygelGstSink*
-rygel_gst_sink_new (RygelDataSource* source, RygelHTTPSeek* offsets) {
+RygelGstSink *
+rygel_gst_sink_new (RygelDataSource *source,
+                    RygelHTTPSeek   *offsets) {
+  g_return_val_if_fail (RYGEL_IS_DATA_SOURCE (source), NULL);
+  g_return_val_if_fail (RYGEL_IS_HTTP_SEEK (offsets) || offsets == NULL, NULL);
+
   return RYGEL_GST_SINK (g_object_new (RYGEL_TYPE_GST_SINK,
                                        "source", source,
                                        "offsets", offsets,
                                        NULL));
 }
 
-
 void
-rygel_gst_sink_freeze (RygelGstSink* self) {
-  g_return_if_fail (self);
+rygel_gst_sink_freeze (RygelGstSink *self) {
+  g_return_if_fail (RYGEL_IS_GST_SINK (self));
 
   if (self->priv->frozen) {
     return;
@@ -107,8 +108,8 @@ rygel_gst_sink_freeze (RygelGstSink* self) {
 }
 
 void
-rygel_gst_sink_thaw (RygelGstSink* self) {
-  g_return_if_fail (self);
+rygel_gst_sink_thaw (RygelGstSink *self) {
+  g_return_if_fail (RYGEL_IS_GST_SINK (self));
 
   if (!self->priv->frozen) {
     return;
@@ -120,210 +121,270 @@ rygel_gst_sink_thaw (RygelGstSink* self) {
   g_mutex_unlock (&self->priv->buffer_mutex);
 }
 
-static gboolean on_idle_push_data (gpointer user_data) {
-  CallbackData* data = (CallbackData*)user_data;
+/* Runs in application thread */
+static gboolean
+rygel_gst_sink_push_data (RygelGstSink *self,
+                          GstBuffer    *buffer) {
 
-  return rygel_gst_sink_push_data (data->self, data->buffer);
+  gint64 left = self->priv->max_bytes - self->priv->bytes_sent;
+  guint bufsize;
+  gint64 to_send;
+
+
+  if (g_cancellable_is_cancelled (self->priv->cancellable) ||
+      left <= 0) {
+    return FALSE;
+  }
+
+  bufsize = buffer->size;
+  to_send = MIN ((gint64) bufsize, left);
+
+  g_signal_emit_by_name (self->priv->source, "data-available", buffer->data, to_send);
+  self->priv->chunks_buffered++;
+  self->priv->bytes_sent += to_send;
+
+  return FALSE;
 }
 
-static CallbackData*
-callback_data_ref (CallbackData* callback_data) {
-  g_atomic_int_inc (&callback_data->_ref_count_);
-  return callback_data;
+static gboolean on_idle_push_data (gpointer user_data) {
+  CallbackData *data = (CallbackData *) user_data;
+
+  return rygel_gst_sink_push_data (data->self, data->buffer);
 }
 
 static void
-callback_data_unref (void *user_data) {
-  CallbackData* callback_data = (CallbackData*) user_data;
-  if (g_atomic_int_dec_and_test (&callback_data->_ref_count_)) {
+callback_data_unref (gpointer user_data) {
+  CallbackData *callback_data = (CallbackData *) user_data;
+
+  if (g_atomic_int_dec_and_test (&callback_data->ref_count)) {
     RygelGstSink *self = callback_data->self;
-    gst_buffer_unref (callback_data->buffer);
-    gst_object_unref (self);
+
+    if (callback_data->buffer) {
+      gst_buffer_unref (callback_data->buffer);
+    }
+    if (self) {
+      gst_object_unref (self);
+    }
     g_slice_free (CallbackData, callback_data);
   }
 }
 
-static GstFlowReturn rygel_gst_sink_real_render (GstBaseSink *base, GstBuffer* buffer) {
+static GstFlowReturn
+rygel_gst_sink_real_render (GstBaseSink *base,
+                            GstBuffer   *buffer) {
   RygelGstSink *self = RYGEL_GST_SINK (base);
-  CallbackData* callback_data;
+  CallbackData *callback_data;
 
   g_mutex_lock (&self->priv->buffer_mutex);
   while (!g_cancellable_is_cancelled (self->priv->cancellable) &&
-    self->priv->frozen) {
+         self->priv->frozen) {
     /* Client is either not reading (Paused) or not fast enough */
     g_cond_wait (&self->priv->buffer_condition, &self->priv->buffer_mutex);
   }
   g_mutex_unlock (&self->priv->buffer_mutex);
 
-  if(g_cancellable_is_cancelled (self->priv->cancellable)) {
+  if (g_cancellable_is_cancelled (self->priv->cancellable)) {
     return GST_FLOW_OK;
   }
 
   /* Use a ref-counted object to pass both this sink and the buffer
    * to the idle callback. */
   callback_data = g_slice_new0 (CallbackData);
-  callback_data->_ref_count_ = 1;
+  callback_data->ref_count = 1;
   callback_data->self = gst_object_ref (self);
-  callback_data->buffer = gst_object_ref (buffer);
-  g_idle_add_full (self->priv->priority, on_idle_push_data, callback_data_ref (callback_data), callback_data_unref);
+  callback_data->buffer = gst_buffer_ref (buffer);
+  g_idle_add_full (self->priv->priority,
+                   on_idle_push_data,
+                   callback_data,
+                   callback_data_unref);
 
   return GST_FLOW_OK;
 }
 
-/* Runs in application thread */
-static gboolean
-rygel_gst_sink_push_data (RygelGstSink* self, GstBuffer* buffer) {
-
-  gint64 left = self->priv->max_bytes - self->priv->bytes_sent;
-
-  if(g_cancellable_is_cancelled (self->priv->cancellable) ||
-    left <= 0) {
-    return FALSE;
+static void
+clear_gmutex (GMutex *mutex) {
+  GMutex zero_mutex = { 0 };
+  if (memcmp (mutex, &zero_mutex, sizeof (GMutex))) {
+    g_mutex_clear (mutex);
+    memset (mutex, 0, sizeof (GMutex));
   }
-
-  guint bufsize = buffer->size;
-  gint64 to_send = MIN ((gint64) bufsize, left);
-
-  g_signal_emit_by_name (self->priv->source, "data-available", buffer->data, to_send);
-  self->priv->chunks_buffered++;
-  self->priv->bytes_sent += to_send;
-
-  return FALSE;
 }
 
 static void
-rygel_gst_sink_on_cancelled (RygelGstSink* self) {
-  g_return_if_fail (self != NULL);
-  g_mutex_lock (&self->priv->buffer_mutex);
-  g_cond_broadcast (&self->priv->buffer_condition);
-  g_mutex_unlock (&self->priv->buffer_mutex);
+clear_gcond (GCond *mutex) {
+  GCond zero_mutex = { 0 };
+  if (memcmp (mutex, &zero_mutex, sizeof (GCond))) {
+    g_cond_clear (mutex);
+    memset (mutex, 0, sizeof (GCond));
+  }
 }
 
 static void
-rygel_gst_sink_class_init (RygelGstSinkClass *klass) {
-  GstCaps* caps;
-  GstPadTemplate* template;
+rygel_gst_sink_dispose (GObject *object) {
+  RygelGstSink *self = RYGEL_GST_SINK (object);
+  RygelGstSinkPrivate *priv = self->priv;
 
-  g_type_class_add_private (klass, sizeof (RygelGstSinkPrivate));
+  if (priv->cancellable) {
+    GCancellable *cancellable = priv->cancellable;
 
-  GST_BASE_SINK_CLASS (klass)->render = rygel_gst_sink_real_render;
-  G_OBJECT_CLASS (klass)->finalize = rygel_gst_sink_finalize;
-  G_OBJECT_CLASS (klass)->constructed = rygel_gst_sink_constructed;
-  G_OBJECT_CLASS (klass)->get_property = rygel_gst_sink_get_property;
-  G_OBJECT_CLASS (klass)->set_property = rygel_gst_sink_set_property;
-  g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_GST_SINK_SOURCE, g_param_spec_object ("source", "source", "source", RYGEL_TYPE_DATA_SOURCE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY | G_PARAM_READABLE | G_PARAM_WRITABLE));
-  g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_GST_SINK_OFFSETS, g_param_spec_object ("offsets", "offsets", "offsets", RYGEL_TYPE_HTTP_SEEK, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY | G_PARAM_READABLE | G_PARAM_WRITABLE));
+    priv->cancellable = NULL;
+    g_object_unref (cancellable);
+  }
+  if (priv->offsets) {
+    RygelHTTPSeek *offsets = self->priv->offsets;
 
-  caps = gst_caps_new_any ();
-  template =  gst_pad_template_new (RYGEL_GST_SINK_PAD_NAME,
-    GST_PAD_SINK, GST_PAD_ALWAYS, caps);
-  gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass), template);
-  gst_object_unref (template);
-  gst_caps_unref (caps);
+    self->priv->offsets = NULL;
+    g_object_unref (offsets);
+  }
+
+  G_OBJECT_CLASS (rygel_gst_sink_parent_class)->dispose (object);
 }
 
 static void
-rygel_gst_sink_init (RygelGstSink *self) {
-  GMutex mutex = {0};
-  GCond cond = {0};
+rygel_gst_sink_finalize (GObject *object) {
+  RygelGstSink *self = RYGEL_GST_SINK (object);
+  RygelGstSinkPrivate *priv = self->priv;
 
-  self->priv = RYGEL_GST_SINK_GET_PRIVATE (self);
+  clear_gmutex (&priv->buffer_mutex);
+  clear_gcond (&priv->buffer_condition);
 
-  g_mutex_init (&mutex);
-  self->priv->buffer_mutex = mutex;
-  g_cond_init (&cond);
-  self->priv->buffer_condition = cond;
+  G_OBJECT_CLASS (rygel_gst_sink_parent_class)->finalize (object);
 }
 
-static void
-rygel_gst_sink_finalize (GObject* obj) {
-  RygelGstSink *self = RYGEL_GST_SINK (obj);
+static void rygel_gst_sink_constructed (GObject *object)
+{
+  RygelGstSink *self = RYGEL_GST_SINK (object);
+  RygelGstSinkPrivate *priv = self->priv;
 
-  g_object_unref (self->priv->cancellable);
-  clear_gmutex (&self->priv->buffer_mutex);
-  clear_gcond (&self->priv->buffer_condition);
-  g_object_unref (self->priv->offsets);
+  priv->chunks_buffered = 0;
+  priv->bytes_sent = 0;
+  priv->max_bytes = G_MAXINT64;
+  priv->cancellable = g_cancellable_new ();
 
-  G_OBJECT_CLASS (rygel_gst_sink_parent_class)->finalize (obj);
-}
+  gst_base_sink_set_sync (GST_BASE_SINK (self), FALSE);
+  gst_object_set_name (GST_OBJECT (self), RYGEL_GST_SINK_NAME);
+  priv->frozen = FALSE;
 
-static void
-clear_gmutex (GMutex *mutex) {
-  GMutex zero_mutex = { 0 };
-  if (memcmp (mutex, &zero_mutex, sizeof (GMutex))) {
-    g_mutex_clear (mutex);
-    memset (mutex, 0, sizeof (GMutex));
+  if (priv->offsets &&
+      rygel_http_seek_get_seek_type (priv->offsets) == RYGEL_HTTP_SEEK_TYPE_BYTE) {
+    priv->max_bytes = rygel_http_seek_get_length (priv->offsets);
   }
-}
 
-static void
-clear_gcond (GCond *mutex) {
-  GCond zero_mutex = { 0 };
-  if (memcmp (mutex, &zero_mutex, sizeof (GCond))) {
-    g_cond_clear (mutex);
-    memset (mutex, 0, sizeof (GCond));
-  }
+  g_signal_connect_object (priv->cancellable,
+                           "cancelled",
+                           G_CALLBACK (on_cancelled),
+                           self,
+                           0);
 }
 
 static void
-rygel_gst_sink_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) {
+rygel_gst_sink_get_property (GObject    *object,
+                             guint       property_id,
+                             GValue     *value,
+                             GParamSpec *pspec) {
   RygelGstSink *self = RYGEL_GST_SINK (object);
   RygelGstSinkPrivate *priv = self->priv;
 
   switch (property_id) {
-    case RYGEL_GST_SINK_SOURCE:
-      g_value_set_object (value, priv->source);
-      break;
-    case RYGEL_GST_SINK_OFFSETS:
-      g_value_set_object (value, priv->offsets);
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-      break;
+  case RYGEL_GST_SINK_SOURCE:
+    g_value_set_object (value, priv->source);
+    break;
+
+  case RYGEL_GST_SINK_OFFSETS:
+    g_value_set_object (value, priv->offsets);
+    break;
+
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    break;
   }
 }
 
 static void
-rygel_gst_sink_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) {
+rygel_gst_sink_set_property (GObject      *object,
+                             guint         property_id,
+                             const GValue *value,
+                             GParamSpec   *pspec) {
   RygelGstSink *self = RYGEL_GST_SINK (object);
   RygelGstSinkPrivate *priv = self->priv;
 
   switch (property_id) {
-    case RYGEL_GST_SINK_SOURCE:
-      priv->source = g_value_get_object (value);
-      break;
-    case RYGEL_GST_SINK_OFFSETS:
-      if (priv->offsets) {
-        g_object_unref (priv->offsets);
-      }
-      priv->offsets = g_value_dup_object (value);
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-      break;
+  case RYGEL_GST_SINK_SOURCE:
+    priv->source = g_value_get_object (value);
+    break;
+
+  case RYGEL_GST_SINK_OFFSETS:
+    if (priv->offsets) {
+      g_object_unref (priv->offsets);
+    }
+    priv->offsets = g_value_dup_object (value);
+    break;
+
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    break;
   }
 }
 
-static void rygel_gst_sink_constructed (GObject* object)
-{
-  RygelGstSink *self = RYGEL_GST_SINK (object);
+static void
+rygel_gst_sink_class_init (RygelGstSinkClass *gst_sink_class) {
+  GstBaseSinkClass *base_sink_class = GST_BASE_SINK_CLASS (gst_sink_class);
+  GObjectClass *object_class = G_OBJECT_CLASS (gst_sink_class);
+  GstElementClass *element_class = GST_ELEMENT_CLASS (gst_sink_class);
+  GstCaps* caps;
+  GstPadTemplate* template;
 
-  self->priv->chunks_buffered = (gint64) 0;
-  self->priv->bytes_sent = (gint64) 0;
-  self->priv->max_bytes = G_MAXINT64;
-  self->priv->cancellable = g_cancellable_new ();
+  base_sink_class->render = rygel_gst_sink_real_render;
+  object_class->dispose = rygel_gst_sink_dispose;
+  object_class->finalize = rygel_gst_sink_finalize;
+  object_class->constructed = rygel_gst_sink_constructed;
+  object_class->get_property = rygel_gst_sink_get_property;
+  object_class->set_property = rygel_gst_sink_set_property;
+
+  g_object_class_install_property (object_class,
+                                   RYGEL_GST_SINK_SOURCE,
+                                   g_param_spec_object ("source",
+                                                        "source",
+                                                        "source",
+                                                        RYGEL_TYPE_DATA_SOURCE,
+                                                        G_PARAM_STATIC_NAME |
+                                                        G_PARAM_STATIC_NICK |
+                                                        G_PARAM_STATIC_BLURB |
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE));
+
+  g_object_class_install_property (object_class,
+                                   RYGEL_GST_SINK_OFFSETS,
+                                   g_param_spec_object ("offsets",
+                                                        "offsets",
+                                                        "offsets",
+                                                        RYGEL_TYPE_HTTP_SEEK,
+                                                        G_PARAM_STATIC_NAME |
+                                                        G_PARAM_STATIC_NICK |
+                                                        G_PARAM_STATIC_BLURB |
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE));
 
-  gst_base_sink_set_sync (GST_BASE_SINK (self), FALSE);
-  gst_object_set_name (GST_OBJECT (self), RYGEL_GST_SINK_NAME);
-  self->priv->frozen = FALSE;
+  caps = gst_caps_new_any ();
+  template =  gst_pad_template_new (RYGEL_GST_SINK_PAD_NAME,
+                                    GST_PAD_SINK,
+                                    GST_PAD_ALWAYS,
+                                    caps);
+  gst_element_class_add_pad_template (element_class, template);
+  gst_object_unref (template);
+  gst_caps_unref (caps);
 
-  if (self->priv->offsets) {
-    if (rygel_http_seek_get_seek_type (self->priv->offsets) == RYGEL_HTTP_SEEK_TYPE_BYTE) {
-      self->priv->max_bytes = rygel_http_seek_get_length (self->priv->offsets);
-    }
-  }
+  g_type_class_add_private (gst_sink_class, sizeof (RygelGstSinkPrivate));
+}
+
+static void
+rygel_gst_sink_init (RygelGstSink *self) {
+  self->priv = RYGEL_GST_SINK_GET_PRIVATE (self);
 
-  g_signal_connect_object (self->priv->cancellable, "cancelled", (GCallback) on_cancelled, self, 0);
+  g_mutex_init (&self->priv->buffer_mutex);
+  g_cond_init (&self->priv->buffer_condition);
 }
 
 GCancellable *
diff --git a/src/rygel-gst-sink.h b/src/rygel-gst-sink.h
index 97f962e..19a6511 100644
--- a/src/rygel-gst-sink.h
+++ b/src/rygel-gst-sink.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -22,15 +22,8 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <stdlib.h>
-#include <string.h>
+#include <gio/gio.h>
 #include <rygel-server.h>
-#include <gst/gst.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
-#include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <gee.h>
-#include <rygel-core.h>
-#include <gst/gst.h>
 #include <gst/base/gstbasesink.h>
 
 G_BEGIN_DECLS
@@ -55,17 +48,18 @@ struct _RygelGstSinkClass {
   GstBaseSinkClass parent_class;
 };
 
-GType rygel_gst_sink_get_type (void) G_GNUC_CONST;
+GType
+rygel_gst_sink_get_type (void) G_GNUC_CONST;
 
 RygelGstSink *
-rygel_gst_sink_new (RygelDataSource* source,
-                    RygelHTTPSeek* offsets);
+rygel_gst_sink_new (RygelDataSource *source,
+                    RygelHTTPSeek   *offsets);
 
 void
-rygel_gst_sink_freeze (RygelGstSink* self);
+rygel_gst_sink_freeze (RygelGstSink *self);
 
 void
-rygel_gst_sink_thaw (RygelGstSink* self);
+rygel_gst_sink_thaw (RygelGstSink *self);
 
 GCancellable *
 rygel_gst_sink_get_cancellable (RygelGstSink *sink);
diff --git a/src/rygel-gst-transcoder.c b/src/rygel-gst-transcoder.c
index 8afcd86..2fbced0 100644
--- a/src/rygel-gst-transcoder.c
+++ b/src/rygel-gst-transcoder.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009-2012 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -17,11 +17,11 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include "rygel-gst-transcoder.h"
 #include "rygel-gst-data-source.h"
+#include "rygel-gst-errors.h"
+#include "rygel-gst-transcoder.h"
 #include "rygel-gst-utils.h"
 
-/* TODO: Rename these? */
 #define RYGEL_GST_TRANSCODER_DEFAULT_ENCODING_PRESET "Rygel DLNA preset"
 #define RYGEL_GST_TRANSCODER_DECODE_BIN "decodebin2"
 #define RYGEL_GST_TRANSCODER_ENCODE_BIN "encodebin"
@@ -41,48 +41,52 @@ struct _RygelGstTranscoderPrivate {
   gboolean link_failed;
 };
 
-#define RYGEL_GST_TRANSCODER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_GST_TRANSCODER, RygelGstTranscoderPrivate))
-
-static void rygel_gst_transcoder_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void rygel_gst_transcoder_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-static void rygel_gst_transcoder_finalize (GObject* obj);
+#define RYGEL_GST_TRANSCODER_GET_PRIVATE(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+                                RYGEL_TYPE_GST_TRANSCODER, \
+                                RygelGstTranscoderPrivate))
 
 static void
-on_decoder_pad_added (GstElement* decodebin G_GNUC_UNUSED,
-                      GstPad* new_pad,
-                      gpointer user_data) {
+on_decoder_pad_added (GstElement *decodebin G_GNUC_UNUSED,
+                      GstPad     *new_pad,
+                      gpointer    user_data) {
   RygelGstTranscoder* self = RYGEL_GST_TRANSCODER (user_data);
-
-  GstPad* sinkpad = gst_element_get_compatible_pad (self->priv->encoder, new_pad, NULL);
+  GstPad* sinkpad = gst_element_get_compatible_pad (self->priv->encoder,
+                                                    new_pad,
+                                                    NULL);
 
   if (!sinkpad) {
     GstCaps *caps =  gst_pad_get_caps_reffed (new_pad);
+
     g_signal_emit_by_name (self->priv->encoder, "request-pad", caps, &sinkpad, NULL);
     gst_caps_unref (caps);
   }
 
   if (!sinkpad) {
-    g_debug ("No compatible encodebin pad found for pad '%s'. Ignoring.", gst_object_get_name (GST_OBJECT (new_pad)));
+    g_debug ("No compatible encodebin pad found for pad '%s'. Ignoring.",
+             gst_object_get_name (GST_OBJECT (new_pad)));
     return;
   }
 
   if (gst_pad_link (new_pad, sinkpad) == GST_PAD_LINK_OK) {
     self->priv->link_failed = FALSE;
   } else {
-    g_warning ("Failed to link pad '%s' to '%s'", gst_object_get_name (GST_OBJECT (new_pad)), gst_object_get_name (GST_OBJECT (sinkpad)));
+    g_warning ("Failed to link pad '%s' to '%s'",
+               gst_object_get_name (GST_OBJECT (new_pad)),
+               gst_object_get_name (GST_OBJECT (sinkpad)));
   }
 
   gst_object_unref (sinkpad);
 }
 
 static gboolean
-on_decoder_autoplug_continue (GstElement* decodebin G_GNUC_UNUSED,
-                              GstPad* new_pad G_GNUC_UNUSED,
-                              GstCaps* caps,
-                              gpointer user_data) {
+on_decoder_autoplug_continue (GstElement *decodebin G_GNUC_UNUSED,
+                              GstPad     *new_pad G_GNUC_UNUSED,
+                              GstCaps    *caps,
+                              gpointer    user_data) {
   RygelGstTranscoder* self = RYGEL_GST_TRANSCODER (user_data);
-
   GstPad* sinkpad = NULL;
+
   g_signal_emit_by_name (self->priv->encoder, "request-pad", caps, &sinkpad, NULL);
   if (!sinkpad) {
     return TRUE;
@@ -96,15 +100,20 @@ static void
 on_decoder_no_more_pads (GstElement* decodebin G_GNUC_UNUSED,
                          gpointer user_data) {
   RygelGstTranscoder* self = RYGEL_GST_TRANSCODER (user_data);
+  RygelGstTranscoderPrivate *priv = self->priv;
 
   /* We haven't found any pads we could link */
-  if (self->priv->link_failed) {
+  if (priv->link_failed) {
     /* Signal that error. */
-    GstBin *bin = GST_BIN (gst_object_get_parent (GST_OBJECT (self->priv->encoder)));
-    GError *error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Could not link");
-    GstMessage* message = gst_message_new_error (GST_OBJECT (bin), error, RYGEL_GST_TRANSCODER_DESCRIPTION);
-
+    GstBin *bin = GST_BIN (gst_object_get_parent (GST_OBJECT (priv->encoder)));
+    GError *error = g_error_new_literal (G_IO_ERROR,
+                                         G_IO_ERROR_FAILED,
+                                         "Could not link");
+    GstMessage* message = gst_message_new_error (GST_OBJECT (bin),
+                                                 error,
+                                                 RYGEL_GST_TRANSCODER_DESCRIPTION);
     GstBus* bus = gst_element_get_bus (GST_ELEMENT (bin));
+
     gst_bus_post (bus, message);
 
     gst_object_unref (bus);
@@ -114,54 +123,65 @@ on_decoder_no_more_pads (GstElement* decodebin G_GNUC_UNUSED,
 }
 
 static RygelDataSource *
-rygel_gst_transcoder_create_source (RygelTranscoder *base,
-                                    RygelMediaItem *item,
-                                    RygelDataSource *src,
-                                    GError **error) {
+rygel_gst_transcoder_create_source (RygelTranscoder  *base,
+                                    RygelMediaItem   *item,
+                                    RygelDataSource  *src,
+                                    GError          **error) {
   RygelGstTranscoder *self;
+  RygelGstTranscoderPrivate *priv;
   RygelGstDataSource *data_source;
   GstEncodingProfile *encoding_profile;
   GstBin *bin;
   GError *inner_error = NULL;
+  GstElement *element;
+  GstPad *pad;
+  GstGhostPad *ghost_pad;
+  RygelDataSource *result;
 
-  g_return_val_if_fail (item != NULL, NULL);
-  g_return_val_if_fail (src != NULL, NULL);
-
+  g_return_val_if_fail (RYGEL_IS_MEDIA_ITEM (item), NULL);
   /* We can only link GStreamer data sources together,
    * so check that the RygelDataSource is of the expected type:
    */
   g_return_val_if_fail (RYGEL_IS_GST_DATA_SOURCE (src), NULL);
 
   self = RYGEL_GST_TRANSCODER (base);
+  priv = self->priv;
   data_source = RYGEL_GST_DATA_SOURCE (src);
 
-  if (self->priv->decoder) {
-    g_object_unref (self->priv->decoder);
+  if (priv->decoder) {
+    g_object_unref (priv->decoder);
   }
 
-  self->priv->decoder =
-    rygel_gst_utils_create_element (RYGEL_GST_TRANSCODER_DECODE_BIN,
-      RYGEL_GST_TRANSCODER_DECODE_BIN,
-      &inner_error);
+  priv->decoder = rygel_gst_utils_create_element (RYGEL_GST_TRANSCODER_DECODE_BIN,
+                                                  RYGEL_GST_TRANSCODER_DECODE_BIN,
+                                                  &inner_error);
   if (inner_error) {
     g_propagate_error (error, inner_error);
     return NULL;
   }
 
-  if (self->priv->encoder) {
-    g_object_unref (self->priv->encoder);
+  if (priv->encoder) {
+    g_object_unref (priv->encoder);
   }
 
-  self->priv->encoder =
-    rygel_gst_utils_create_element (RYGEL_GST_TRANSCODER_ENCODE_BIN,
-      RYGEL_GST_TRANSCODER_ENCODE_BIN,
-      &inner_error);
+  priv->encoder = rygel_gst_utils_create_element (RYGEL_GST_TRANSCODER_ENCODE_BIN,
+                                                  RYGEL_GST_TRANSCODER_ENCODE_BIN,
+                                                  &inner_error);
   if (inner_error) {
     g_propagate_error (error, inner_error);
     return NULL;
   }
 
   encoding_profile = rygel_gst_transcoder_get_encoding_profile (self);
+  if (!encoding_profile) {
+    g_set_error_literal (error,
+                         RYGEL_GST_TRANSCODER_ERROR,
+                         RYGEL_GST_TRANSCODER_ERROR_CANT_TRANSCODE,
+                         "Could not create a transcoder configuration. "
+                         "Your GStreamer installation might be missing a plug-in");
+    return NULL;
+  }
+
   g_object_set (self->priv->encoder, "profile", encoding_profile, NULL);
   gst_object_unref (encoding_profile);
   g_debug ("%s using the following encoding profile:", G_OBJECT_TYPE_NAME (self));
@@ -172,21 +192,33 @@ rygel_gst_transcoder_create_source (RygelTranscoder *base,
 
   /* Use the RygelGstDataSource-specific API to get the underlying Gstreamer element.
    */
-  GstElement *element = rygel_gst_data_source_get_gst_element (data_source);
-  gst_bin_add_many (bin, element, self->priv->decoder, self->priv->encoder, NULL);
-
-  gst_element_link (element, self->priv->decoder);
-
-  g_signal_connect_object (self->priv->decoder, "pad-added", (GCallback) on_decoder_pad_added, self, 0);
-  g_signal_connect_object (self->priv->decoder, "autoplug_continue", (GCallback) on_decoder_autoplug_continue, self, 0);
-  g_signal_connect_object (self->priv->decoder, "no-more-pads", (GCallback) on_decoder_no_more_pads, self, 0);
-
-  GstPad *pad = gst_element_get_static_pad (self->priv->encoder, "src");
-  GstGhostPad *ghost_pad = GST_GHOST_PAD (gst_ghost_pad_new (NULL, pad));
+  element = rygel_gst_data_source_get_gst_element (data_source);
+  gst_bin_add_many (bin, element, priv->decoder, priv->encoder, NULL);
+
+  gst_element_link (element, priv->decoder);
+
+  g_signal_connect_object (priv->decoder,
+                           "pad-added",
+                           G_CALLBACK (on_decoder_pad_added),
+                           self,
+                           0);
+  g_signal_connect_object (priv->decoder,
+                           "autoplug_continue",
+                           G_CALLBACK (on_decoder_autoplug_continue),
+                           self,
+                           0);
+  g_signal_connect_object (priv->decoder,
+                           "no-more-pads",
+                           G_CALLBACK (on_decoder_no_more_pads),
+                           self,
+                           0);
+
+  pad = gst_element_get_static_pad (priv->encoder, "src");
+  ghost_pad = GST_GHOST_PAD (gst_ghost_pad_new (NULL, pad));
   gst_object_ref_sink (ghost_pad);
   gst_element_add_pad (GST_ELEMENT (bin), GST_PAD (ghost_pad));
 
-  RygelDataSource *result = RYGEL_DATA_SOURCE (rygel_gst_data_source_new_from_element (GST_ELEMENT (bin)));
+  result = RYGEL_DATA_SOURCE (rygel_gst_data_source_new (GST_ELEMENT (bin)));
   gst_object_unref (ghost_pad);
   gst_object_unref (pad);
   gst_object_unref (bin);
@@ -199,102 +231,138 @@ rygel_gst_transcoder_create_source (RygelTranscoder *base,
  *
  * @return the GstEncodingProfile for this transcoder. You must call gst_object_unref() on this.
  */
-static GstEncodingProfile*
-rygel_gst_transcoder_real_get_encoding_profile (RygelGstTranscoder* self) {
+static GstEncodingProfile *
+rygel_gst_transcoder_real_get_encoding_profile (RygelGstTranscoder *self) {
   /* This must be implemented by derived types. */
   g_critical ("Type `%s' does not implement abstract method `rygel_gst_transcoder_get_encoding_profile'", G_OBJECT_TYPE_NAME (self));
   return NULL;
 }
 
 GstEncodingProfile*
-rygel_gst_transcoder_get_encoding_profile (RygelGstTranscoder* self) {
-  g_return_val_if_fail (self != NULL, NULL);
+rygel_gst_transcoder_get_encoding_profile (RygelGstTranscoder *self) {
+  g_return_val_if_fail (RYGEL_IS_GST_TRANSCODER (self), NULL);
+
   return RYGEL_GST_TRANSCODER_GET_CLASS (self)->get_encoding_profile (self);
 }
 
 const gchar*
-rygel_gst_transcoder_get_preset (RygelGstTranscoder* self) {
+rygel_gst_transcoder_get_preset (RygelGstTranscoder *self) {
+  g_return_val_if_fail (RYGEL_IS_GST_TRANSCODER (self), NULL);
+
   return self->priv->preset;
 }
 
 void
-rygel_gst_transcoder_set_preset (RygelGstTranscoder* self, const gchar *value) {
-  g_return_if_fail (self != NULL);
+rygel_gst_transcoder_set_preset (RygelGstTranscoder *self,
+                                 const gchar *value) {
+  RygelGstTranscoderPrivate *priv;
 
-  if (self->priv->preset) {
-    g_free (self->priv->preset);
-    self->priv->preset = NULL;
-  }
+  g_return_if_fail (RYGEL_IS_GST_TRANSCODER (self));
 
-  if (value) {
-    self->priv->preset = g_strdup (value);
+  priv = self->priv;
+  if (priv->preset) {
+    g_free (priv->preset);
   }
 
+  priv->preset = g_strdup (value);
+
   g_object_notify (G_OBJECT (self), "preset");
 }
 
 static
-void rygel_gst_transcoder_class_init (RygelGstTranscoderClass *klass) {
-  rygel_gst_transcoder_parent_class = g_type_class_peek_parent (klass);
-  g_type_class_add_private (klass, sizeof (RygelGstTranscoderPrivate));
-  RYGEL_TRANSCODER_CLASS (klass)->create_source = rygel_gst_transcoder_create_source;
-  RYGEL_GST_TRANSCODER_CLASS (klass)->get_encoding_profile = rygel_gst_transcoder_real_get_encoding_profile;
-  G_OBJECT_CLASS (klass)->get_property = rygel_gst_transcoder_get_property;
-  G_OBJECT_CLASS (klass)->set_property = rygel_gst_transcoder_set_property;
-  G_OBJECT_CLASS (klass)->finalize = rygel_gst_transcoder_finalize;
-  g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_GST_TRANSCODER_PRESET, g_param_spec_string ("preset", "preset", "preset", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
-}
+void rygel_gst_transcoder_dispose (GObject* object) {
+  RygelGstTranscoder *self = RYGEL_GST_TRANSCODER (object);
+  RygelGstTranscoderPrivate *priv = self->priv;
 
-static
-void rygel_gst_transcoder_init (RygelGstTranscoder *self) {
-  self->priv = RYGEL_GST_TRANSCODER_GET_PRIVATE (self);
-  self->priv->preset = g_strdup (RYGEL_GST_TRANSCODER_DEFAULT_ENCODING_PRESET);
-  self->priv->link_failed = TRUE;
+  if (priv->decoder) {
+    GstElement *decoder = priv->decoder;
+
+    priv->decoder = NULL;
+    gst_object_unref (decoder);
+  }
+  if (priv->encoder) {
+    GstElement *encoder = priv->encoder;
+
+    priv->encoder = NULL;
+    gst_object_unref (encoder);
+  }
+
+  G_OBJECT_CLASS (rygel_gst_transcoder_parent_class)->dispose (object);
 }
 
 static
 void rygel_gst_transcoder_finalize (GObject* obj) {
-  RygelGstTranscoder *self;
+  RygelGstTranscoder *self = RYGEL_GST_TRANSCODER (obj);
 
-  self = RYGEL_GST_TRANSCODER (obj);
   g_free (self->priv->preset);
-  /* TODO: Move it to dispose. */
-  if (self->priv->decoder) {
-    gst_object_unref (self->priv->decoder);
-  }
-  if (self->priv->encoder) {
-    gst_object_unref (self->priv->encoder);
-  }
 
   G_OBJECT_CLASS (rygel_gst_transcoder_parent_class)->finalize (obj);
 }
 
 static void
-rygel_gst_transcoder_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) {
-  RygelGstTranscoder *self;
-  self = RYGEL_GST_TRANSCODER (object);
+rygel_gst_transcoder_get_property (GObject    *object,
+				   guint       property_id,
+				   GValue     *value,
+				   GParamSpec *pspec) {
+  RygelGstTranscoder *self = RYGEL_GST_TRANSCODER (object);
 
   switch (property_id) {
-    case RYGEL_GST_TRANSCODER_PRESET:
-      g_value_set_string (value, rygel_gst_transcoder_get_preset (self));
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-      break;
+  case RYGEL_GST_TRANSCODER_PRESET:
+    g_value_set_string (value, rygel_gst_transcoder_get_preset (self));
+    break;
+
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    break;
   }
 }
 
 static void
-rygel_gst_transcoder_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) {
-  RygelGstTranscoder *self;
-  self = RYGEL_GST_TRANSCODER (object);
+rygel_gst_transcoder_set_property (GObject      *object,
+				   guint         property_id,
+				   const GValue *value,
+				   GParamSpec   *pspec) {
+  RygelGstTranscoder *self = RYGEL_GST_TRANSCODER (object);
 
   switch (property_id) {
-    case RYGEL_GST_TRANSCODER_PRESET:
-      rygel_gst_transcoder_set_preset (self, g_value_get_string (value));
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-      break;
+  case RYGEL_GST_TRANSCODER_PRESET:
+    rygel_gst_transcoder_set_preset (self, g_value_get_string (value));
+    break;
+
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    break;
   }
 }
+
+static
+void rygel_gst_transcoder_class_init (RygelGstTranscoderClass *gst_transcoder_class) {
+  GObjectClass *object_class = G_OBJECT_CLASS (gst_transcoder_class);
+  RygelTranscoderClass *transcoder_class = RYGEL_TRANSCODER_CLASS (gst_transcoder_class);
+
+  transcoder_class->create_source = rygel_gst_transcoder_create_source;
+  gst_transcoder_class->get_encoding_profile = rygel_gst_transcoder_real_get_encoding_profile;
+  object_class->get_property = rygel_gst_transcoder_get_property;
+  object_class->set_property = rygel_gst_transcoder_set_property;
+  object_class->dispose = rygel_gst_transcoder_dispose;
+  object_class->finalize = rygel_gst_transcoder_finalize;
+  g_object_class_install_property (object_class,
+                                   RYGEL_GST_TRANSCODER_PRESET,
+                                   g_param_spec_string ("preset",
+                                                        "preset",
+                                                        "preset",
+                                                        NULL,
+                                                        G_PARAM_STATIC_NAME |
+                                                        G_PARAM_STATIC_NICK |
+                                                        G_PARAM_STATIC_BLURB |
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE));
+  g_type_class_add_private (gst_transcoder_class, sizeof (RygelGstTranscoderPrivate));
+}
+
+static
+void rygel_gst_transcoder_init (RygelGstTranscoder *self) {
+  self->priv = RYGEL_GST_TRANSCODER_GET_PRIVATE (self);
+  self->priv->preset = g_strdup (RYGEL_GST_TRANSCODER_DEFAULT_ENCODING_PRESET);
+  self->priv->link_failed = TRUE;
+}
diff --git a/src/rygel-gst-transcoder.h b/src/rygel-gst-transcoder.h
index f281010..eef37e8 100644
--- a/src/rygel-gst-transcoder.h
+++ b/src/rygel-gst-transcoder.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -22,14 +22,8 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <stdlib.h>
-#include <string.h>
 #include <rygel-server.h>
-#include <gst/gst.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
-#include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <gee.h>
-#include <rygel-core.h>
+#include <gst/pbutils/encoding-profile.h>
 
 G_BEGIN_DECLS
 
@@ -50,9 +44,9 @@ struct _RygelGstTranscoder {
 };
 
 struct _RygelGstTranscoderClass {
-  RygelMediaEngineClass parent_class;
+  RygelTranscoderClass parent_class;
 
-  GstEncodingProfile* (*get_encoding_profile) (RygelGstTranscoder* self);
+  GstEncodingProfile * (* get_encoding_profile) (RygelGstTranscoder *self);
 };
 
 GType
diff --git a/src/rygel-gst-utils.c b/src/rygel-gst-utils.c
index 30dae07..6fad5e5 100644
--- a/src/rygel-gst-utils.c
+++ b/src/rygel-gst-utils.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation.
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
  *                               <zeeshan ali nokia com>
@@ -23,23 +23,19 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include <gst/gst.h>
 #include <glib/gi18n-lib.h>
-#include <gst/pbutils/pbutils.h>
-#include <gobject/gvaluecollector.h>
-#include "rygel-gst-data-source.h"
+#include "rygel-gst-errors.h"
 #include "rygel-gst-utils.h"
-#include <glib/gi18n-lib.h>
-
-static gboolean rygel_gst_utils_need_rtp_depayloader (GstCaps* caps);
 
-GstElement*
-rygel_gst_utils_create_element (const gchar *factoryname, const gchar *name, GError **error) {
-  GstElement* element;
+GstElement *
+rygel_gst_utils_create_element (const gchar  *factory_name,
+                                const gchar  *name,
+                                GError      **error) {
+  GstElement *element;
 
-  g_return_val_if_fail (factoryname != NULL, NULL);
+  g_return_val_if_fail (factory_name != NULL, NULL);
 
-  element = gst_element_factory_make (factoryname, name);
+  element = gst_element_factory_make (factory_name, name);
   if (element) {
     gst_object_ref_sink (element);
   } else {
@@ -47,15 +43,15 @@ rygel_gst_utils_create_element (const gchar *factoryname, const gchar *name, GEr
                  RYGEL_GST_ERROR,
                  RYGEL_GST_ERROR_MISSING_PLUGIN,
                  _("Required element %s missing"),
-                 factoryname);
+                 factory_name);
   }
 
   return element;
 }
 
-GstElement*
+GstElement *
 rygel_gst_utils_create_source_for_uri (const gchar *uri) {
-  GstElement* src;
+  GstElement *src;
 
   g_return_val_if_fail (uri != NULL, NULL);
 
@@ -79,11 +75,12 @@ rygel_gst_utils_create_source_for_uri (const gchar *uri) {
 }
 
 void
-rygel_gst_utils_dump_encoding_profile (GstEncodingProfile* profile, gint indent) {
+rygel_gst_utils_dump_encoding_profile (GstEncodingProfile *profile,
+                                       gint                indent) {
   gchar *indent_s;
-  const GstCaps* caps;
+  const GstCaps *caps;
   gchar *format_name;
-  const GstCaps* restriction;
+  const GstCaps *restriction;
 
   g_return_if_fail (profile != NULL);
 
@@ -103,12 +100,13 @@ rygel_gst_utils_dump_encoding_profile (GstEncodingProfile* profile, gint indent)
   }
 
   if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) {
-    GstEncodingContainerProfile* container = GST_ENCODING_CONTAINER_PROFILE (profile);
+    GstEncodingContainerProfile *container = GST_ENCODING_CONTAINER_PROFILE (profile);
+    const GList *subprofile_collection = gst_encoding_container_profile_get_profiles (container);
+    const GList *subprofile_it;
 
-    const GList* subprofile_collection = gst_encoding_container_profile_get_profiles (container);
-    const GList* subprofile_it;
     for (subprofile_it = subprofile_collection; subprofile_it != NULL; subprofile_it = subprofile_it->next) {
-      GstEncodingProfile* subprofile = GST_ENCODING_PROFILE (subprofile_it->data);
+      GstEncodingProfile *subprofile = GST_ENCODING_PROFILE (subprofile_it->data);
+
       rygel_gst_utils_dump_encoding_profile (subprofile, indent + 4);
       gst_encoding_profile_unref (subprofile);
     }
@@ -117,8 +115,23 @@ rygel_gst_utils_dump_encoding_profile (GstEncodingProfile* profile, gint indent)
   g_free (indent_s);
 }
 
-GstElement* rygel_gst_utils_get_rtp_depayloader (GstCaps* caps) {
-  GList* features;
+static gboolean
+rygel_gst_utils_need_rtp_depayloader (GstCaps *caps) {
+  const GstStructure *structure;
+  const gchar *name;
+
+  g_return_val_if_fail (caps != NULL, FALSE);
+
+  structure = gst_caps_get_structure (caps, (guint) 0);
+  name = gst_structure_get_name (structure);
+
+  return (g_strcmp0 (name, "application/x-rtp") == 0);
+}
+
+GstElement *
+rygel_gst_utils_get_rtp_depayloader (GstCaps *caps) {
+  GList *features;
+  GList *filtered;
   const gchar *feature_name;
 
   if (!rygel_gst_utils_need_rtp_depayloader (caps)) {
@@ -126,42 +139,32 @@ GstElement* rygel_gst_utils_get_rtp_depayloader (GstCaps* caps) {
   }
 
   features = gst_element_factory_list_get_elements ((GstElementFactoryListType) GST_ELEMENT_FACTORY_TYPE_DEPAYLOADER, GST_RANK_NONE);
-  features = gst_element_factory_list_filter (features, caps, GST_PAD_SINK, FALSE);
-  g_list_free_full (features, gst_object_unref);
+  filtered = gst_element_factory_list_filter (features, caps, GST_PAD_SINK, FALSE);
+  gst_plugin_feature_list_free (features);
 
-  feature_name = gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (features->data));
+  feature_name = gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (filtered->data));
+  /* If most "fitting" depayloader was rtpdepay skip it because it is
+   * just some kind of proxy.
+   */
   if (g_strcmp0 (feature_name, "rtpdepay") == 0) {
-    if (features->next) {
-      GstElement* element = gst_element_factory_create (GST_ELEMENT_FACTORY (features->next), NULL);
+    if (filtered->next) {
+      GstElement* element = gst_element_factory_create (GST_ELEMENT_FACTORY (filtered->next->data), NULL);
       if (element) {
         gst_object_ref_sink (element);
       }
 
-      g_list_free_full (features, gst_object_unref);
+      gst_plugin_feature_list_free (filtered);
       return element;
     }
 
     return NULL;
   } else {
-    GstElement* element = gst_element_factory_create (GST_ELEMENT_FACTORY (features), NULL);
+    GstElement* element = gst_element_factory_create (GST_ELEMENT_FACTORY (filtered->data), NULL);
     if (element) {
       gst_object_ref_sink (element);
     }
 
-    g_list_free_full (features, gst_object_unref);
+    gst_plugin_feature_list_free (filtered);
     return element;
   }
 }
-
-static gboolean
-rygel_gst_utils_need_rtp_depayloader (GstCaps* caps) {
-  const GstStructure* structure;
-  const gchar *name;
-
-  g_return_val_if_fail (caps != NULL, FALSE);
-
-  structure = gst_caps_get_structure (caps, (guint) 0);
-  name = gst_structure_get_name (structure);
-
-  return (g_strcmp0 (name, "application/x-rtp") == 0);
-}
diff --git a/src/rygel-gst-utils.h b/src/rygel-gst-utils.h
index 65996ce..098eaf5 100644
--- a/src/rygel-gst-utils.h
+++ b/src/rygel-gst-utils.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -21,24 +21,25 @@
 #define __RYGEL_GST_0_10_MEDIA_ENGINE_GST_UTILS_H__
 
 #include <glib.h>
-#include <glib-object.h>
-#include <stdlib.h>
-#include <string.h>
-#include <rygel-server.h>
 #include <gst/gst.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
-#include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <gee.h>
-#include <rygel-core.h>
-#include <gst/gst.h>
-#include <gst/base/gstbasesink.h>
+#include <gst/pbutils/encoding-profile.h>
 
 G_BEGIN_DECLS
 
-GstElement* rygel_gst_utils_create_element (const gchar *factoryname, const gchar *name, GError **error);
-GstElement* rygel_gst_utils_create_source_for_uri (const gchar *uri);
-void rygel_gst_utils_dump_encoding_profile (GstEncodingProfile* profile, gint indent);
-GstElement* rygel_gst_utils_get_rtp_depayloader (GstCaps* caps);
+GstElement*
+rygel_gst_utils_create_element (const gchar  *factory_name,
+                                const gchar  *name,
+                                GError      **error);
+
+GstElement*
+rygel_gst_utils_create_source_for_uri (const gchar *uri);
+
+void
+rygel_gst_utils_dump_encoding_profile (GstEncodingProfile *profile,
+                                       gint                indent);
+
+GstElement *
+rygel_gst_utils_get_rtp_depayloader (GstCaps *caps);
 
 G_END_DECLS
 
diff --git a/src/rygel-l16-transcoder.c b/src/rygel-l16-transcoder.c
index eadab15..7878482 100644
--- a/src/rygel-l16-transcoder.c
+++ b/src/rygel-l16-transcoder.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -38,10 +38,7 @@ G_DEFINE_TYPE (RygelL16Transcoder, rygel_l16_transcoder, RYGEL_TYPE_AUDIO_TRANSC
                              ",endianness=" G_STRINGIFY (RYGEL_L16_TRANSCODER_ENDIANNESS)
 
 
-static GUPnPDIDLLiteResource* rygel_l16_transcoder_real_add_resource (RygelTranscoder *base, GUPnPDIDLLiteItem *didl_item, RygelMediaItem *item, RygelTranscodeManager *manager, GError **error);
-static guint rygel_l16_transcoder_real_get_distance (RygelTranscoder *base, RygelMediaItem *item);
-
-RygelL16Transcoder*
+RygelL16Transcoder *
 rygel_l16_transcoder_new (void) {
   return RYGEL_L16_TRANSCODER (g_object_new (RYGEL_TYPE_L16_TRANSCODER,
                                              "mime-type", RYGEL_L16_MIME_TYPE,
@@ -54,17 +51,21 @@ rygel_l16_transcoder_new (void) {
                                              NULL));
 }
 
-static GUPnPDIDLLiteResource*
-rygel_l16_transcoder_real_add_resource (RygelTranscoder *base, GUPnPDIDLLiteItem *didl_item, RygelMediaItem *item, RygelTranscodeManager *manager, GError **error) {
-  RygelL16Transcoder *self = RYGEL_L16_TRANSCODER (base);
+static GUPnPDIDLLiteResource *
+rygel_l16_transcoder_real_add_resource (RygelTranscoder        *base,
+                                        GUPnPDIDLLiteItem      *didl_item,
+                                        RygelMediaItem         *item,
+                                        RygelTranscodeManager  *manager,
+                                        GError                **error) {
   GError *inner_error = NULL;
+  GUPnPDIDLLiteResource* resource;
+  gint bitrate;
 
-  g_return_val_if_fail (didl_item != NULL, NULL);
-  g_return_val_if_fail (item != NULL, NULL);
-  g_return_val_if_fail (manager != NULL, NULL);
+  g_return_val_if_fail (GUPNP_IS_DIDL_LITE_ITEM (didl_item), NULL);
+  g_return_val_if_fail (RYGEL_MEDIA_ITEM (item), NULL);
+  g_return_val_if_fail (RYGEL_TRANSCODE_MANAGER (manager), NULL);
 
-  GUPnPDIDLLiteResource* resource =
-    RYGEL_TRANSCODER_CLASS (rygel_l16_transcoder_parent_class)->add_resource (RYGEL_TRANSCODER (self), didl_item, item, manager, &inner_error);
+  resource = RYGEL_TRANSCODER_CLASS (rygel_l16_transcoder_parent_class)->add_resource (base, didl_item, item, manager, &inner_error);
   if (!inner_error) {
     g_propagate_error (error, inner_error);
     return NULL;
@@ -74,25 +75,26 @@ rygel_l16_transcoder_real_add_resource (RygelTranscoder *base, GUPnPDIDLLiteItem
     return NULL;
   }
 
+  bitrate = ((RYGEL_L16_TRANSCODER_FREQUENCY * RYGEL_L16_TRANSCODER_CHANNELS) * RYGEL_L16_TRANSCODER_WIDTH) / 8;
+
   gupnp_didl_lite_resource_set_sample_freq (resource, RYGEL_L16_TRANSCODER_FREQUENCY);
   gupnp_didl_lite_resource_set_audio_channels (resource, RYGEL_L16_TRANSCODER_CHANNELS);
   gupnp_didl_lite_resource_set_bits_per_sample (resource, RYGEL_L16_TRANSCODER_WIDTH);
-  gupnp_didl_lite_resource_set_bitrate (resource,
-    ((RYGEL_L16_TRANSCODER_FREQUENCY * RYGEL_L16_TRANSCODER_CHANNELS) * RYGEL_L16_TRANSCODER_WIDTH) / 8);
+  gupnp_didl_lite_resource_set_bitrate (resource, bitrate);
 
   return resource;
 }
 
 static guint
 rygel_l16_transcoder_real_get_distance (RygelTranscoder *base G_GNUC_UNUSED,
-                                        RygelMediaItem *item) {
+                                        RygelMediaItem  *item) {
   RygelAudioItem *audio_item;
   guint distance;
   guint sample_freq;
   guint channels;
   guint bits_per_sample;
 
-  g_return_val_if_fail (item != NULL, 0U);
+  g_return_val_if_fail (RYGEL_IS_MEDIA_ITEM (item), G_MAXUINT);
 
   if (!RYGEL_IS_AUDIO_ITEM (item) || RYGEL_IS_VIDEO_ITEM (item)) {
     return G_MAXUINT;
@@ -120,10 +122,10 @@ rygel_l16_transcoder_real_get_distance (RygelTranscoder *base G_GNUC_UNUSED,
 }
 
 static void
-rygel_l16_transcoder_class_init (RygelL16TranscoderClass *klass) {
-  rygel_l16_transcoder_parent_class = g_type_class_peek_parent (klass);
-  RYGEL_TRANSCODER_CLASS (klass)->add_resource = rygel_l16_transcoder_real_add_resource;
-  RYGEL_TRANSCODER_CLASS (klass)->get_distance = rygel_l16_transcoder_real_get_distance;
+rygel_l16_transcoder_class_init (RygelL16TranscoderClass *l16_transcoder_class) {
+  RygelTranscoderClass *transcoder_class = RYGEL_TRANSCODER_CLASS (l16_transcoder_class);
+  transcoder_class->add_resource = rygel_l16_transcoder_real_add_resource;
+  transcoder_class->get_distance = rygel_l16_transcoder_real_get_distance;
 }
 
 static void
diff --git a/src/rygel-l16-transcoder.h b/src/rygel-l16-transcoder.h
index c7d62ad..579c80c 100644
--- a/src/rygel-l16-transcoder.h
+++ b/src/rygel-l16-transcoder.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -22,14 +22,6 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <stdlib.h>
-#include <string.h>
-#include <rygel-server.h>
-#include <gst/gst.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
-#include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <gee.h>
-#include <rygel-core.h>
 #include "rygel-audio-transcoder.h"
 
 G_BEGIN_DECLS
@@ -54,9 +46,11 @@ struct _RygelL16TranscoderClass {
   RygelAudioTranscoderClass parent_class;
 };
 
-GType rygel_l16_transcoder_get_type (void) G_GNUC_CONST;
+GType
+rygel_l16_transcoder_get_type (void) G_GNUC_CONST;
 
-RygelL16Transcoder* rygel_l16_transcoder_new (void);
+RygelL16Transcoder *
+rygel_l16_transcoder_new (void);
 
 G_END_DECLS
 
diff --git a/src/rygel-mp2ts-transcoder.c b/src/rygel-mp2ts-transcoder.c
index e3fcb86..3e3e976 100644
--- a/src/rygel-mp2ts-transcoder.c
+++ b/src/rygel-mp2ts-transcoder.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation.
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
  *                               <zeeshan ali nokia com>
@@ -29,7 +29,9 @@
  * Transcoder for mpeg transport stream containing mpeg 2 video and mp2 audio.
  */
 
-G_DEFINE_TYPE (RygelMP2TSTranscoder, rygel_mp2_ts_transcoder, RYGEL_TYPE_VIDEO_TRANSCODER)
+G_DEFINE_TYPE (RygelMP2TSTranscoder,
+               rygel_mp2_ts_transcoder,
+               RYGEL_TYPE_VIDEO_TRANSCODER)
 
 enum
 {
@@ -61,7 +63,10 @@ struct _RygelMP2TSTranscoderPrivate {
   RygelMP2TSProfile profile;
 };
 
-#define RYGEL_MP2_TS_TRANSCODER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_MP2_TS_TRANSCODER, RygelMP2TSTranscoderPrivate))
+#define RYGEL_MP2_TS_TRANSCODER_GET_PRIVATE(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+                                RYGEL_TYPE_MP2_TS_TRANSCODER, \
+                                RygelMP2TSTranscoderPrivate))
 
 #define RYGEL_MP2_TS_TRANSCODER_VIDEO_BITRATE 1500
 #define RYGEL_MP2_TS_TRANSCODER_AUDIO_BITRATE 192
@@ -81,18 +86,27 @@ struct _RygelMP2TSTranscoderPrivate {
                                                       ",framerate=(fraction)" G_STRINGIFY (fr) "/1" \
                                                       ",width=" G_STRINGIFY (w) \
                                                       ",height=" G_STRINGIFY (h)
-#define RYGEL_MP2_TS_TRANSCODER_RESTRICTION_SD_EU RYGEL_MP2_TS_TRANSCODER_RESTRICTION (RYGEL_MP2_TS_TRANSCODER_FRAME_RATE_SD_EU, RYGEL_MP2_TS_TRANSCODER_WIDTH_SD_EU, RYGEL_MP2_TS_TRANSCODER_HEIGHT_SD_EU)
-#define RYGEL_MP2_TS_TRANSCODER_RESTRICTION_HD_NA RYGEL_MP2_TS_TRANSCODER_RESTRICTION (RYGEL_MP2_TS_TRANSCODER_FRAME_RATE_HD_NA, RYGEL_MP2_TS_TRANSCODER_WIDTH_HD_NA, RYGEL_MP2_TS_TRANSCODER_HEIGHT_HD_NA)
-
-static GUPnPDIDLLiteResource* rygel_mp2_ts_transcoder_real_add_resource (RygelTranscoder *base, GUPnPDIDLLiteItem *didl_item, RygelMediaItem *item, RygelTranscodeManager *manager, GError **error);
-static guint rygel_mp2_ts_transcoder_real_get_distance (RygelTranscoder *base, RygelMediaItem *item);
-static void rygel_mp2_ts_transcoder_finalize (GObject* obj);
-static void rygel_mp2_ts_transcoder_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void rygel_mp2_ts_transcoder_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-static const gint RYGEL_MP2_TS_TRANSCODER_WIDTH[2] = {RYGEL_MP2_TS_TRANSCODER_WIDTH_SD_EU, RYGEL_MP2_TS_TRANSCODER_WIDTH_HD_NA};
-static const gint RYGEL_MP2_TS_TRANSCODER_HEIGHT[2] = {RYGEL_MP2_TS_TRANSCODER_HEIGHT_SD_EU, RYGEL_MP2_TS_TRANSCODER_HEIGHT_HD_NA};
-static const gint RYGEL_MP2_TS_TRANSCODER_FRAME_RATE[2] = {RYGEL_MP2_TS_TRANSCODER_FRAME_RATE_SD_EU, RYGEL_MP2_TS_TRANSCODER_FRAME_RATE_HD_NA};
+#define RYGEL_MP2_TS_TRANSCODER_RESTRICTION_SD_EU \
+  RYGEL_MP2_TS_TRANSCODER_RESTRICTION (RYGEL_MP2_TS_TRANSCODER_FRAME_RATE_SD_EU, \
+				       RYGEL_MP2_TS_TRANSCODER_WIDTH_SD_EU, \
+				       RYGEL_MP2_TS_TRANSCODER_HEIGHT_SD_EU)
+#define RYGEL_MP2_TS_TRANSCODER_RESTRICTION_HD_NA \
+  RYGEL_MP2_TS_TRANSCODER_RESTRICTION (RYGEL_MP2_TS_TRANSCODER_FRAME_RATE_HD_NA, \
+				       RYGEL_MP2_TS_TRANSCODER_WIDTH_HD_NA, \
+				       RYGEL_MP2_TS_TRANSCODER_HEIGHT_HD_NA)
+
+static const gint RYGEL_MP2_TS_TRANSCODER_WIDTH[2] = {
+  RYGEL_MP2_TS_TRANSCODER_WIDTH_SD_EU,
+  RYGEL_MP2_TS_TRANSCODER_WIDTH_HD_NA
+};
+static const gint RYGEL_MP2_TS_TRANSCODER_HEIGHT[2] = {
+  RYGEL_MP2_TS_TRANSCODER_HEIGHT_SD_EU,
+  RYGEL_MP2_TS_TRANSCODER_HEIGHT_HD_NA
+};
+static const gint RYGEL_MP2_TS_TRANSCODER_FRAME_RATE[2] = {
+  RYGEL_MP2_TS_TRANSCODER_FRAME_RATE_SD_EU,
+  RYGEL_MP2_TS_TRANSCODER_FRAME_RATE_HD_NA
+};
 
 RygelMP2TSTranscoder *
 rygel_mp2_ts_transcoder_new_sd_eu (void)
@@ -130,17 +144,22 @@ rygel_mp2_ts_transcoder_new_hd_na (void)
                                                 NULL));
 }
 
-static GUPnPDIDLLiteResource*
-rygel_mp2_ts_transcoder_real_add_resource (RygelTranscoder *base, GUPnPDIDLLiteItem *didl_item, RygelMediaItem *item, RygelTranscodeManager *manager, GError **error) {
+static GUPnPDIDLLiteResource *
+rygel_mp2_ts_transcoder_real_add_resource (RygelTranscoder        *base,
+                                           GUPnPDIDLLiteItem      *didl_item,
+                                           RygelMediaItem         *item,
+                                           RygelTranscodeManager  *manager,
+                                           GError                **error) {
   RygelMP2TSTranscoder *self = RYGEL_MP2_TS_TRANSCODER (base);
   GError *inner_error = NULL;
+  GUPnPDIDLLiteResource* resource;
+  gint bitrate;
 
-  g_return_val_if_fail (didl_item != NULL, NULL);
-  g_return_val_if_fail (item != NULL, NULL);
-  g_return_val_if_fail (manager != NULL, NULL);
+  g_return_val_if_fail (GUPNP_IS_DIDL_LITE_ITEM (didl_item), NULL);
+  g_return_val_if_fail (RYGEL_IS_MEDIA_ITEM (item), NULL);
+  g_return_val_if_fail (RYGEL_IS_TRANSCODE_MANAGER (manager), NULL);
 
-  GUPnPDIDLLiteResource* resource =
-    RYGEL_TRANSCODER_CLASS (rygel_mp2_ts_transcoder_parent_class)->add_resource (RYGEL_TRANSCODER (self), didl_item, item, manager, &inner_error);
+  resource = RYGEL_TRANSCODER_CLASS (rygel_mp2_ts_transcoder_parent_class)->add_resource (RYGEL_TRANSCODER (self), didl_item, item, manager, &inner_error);
   if (!inner_error) {
     g_propagate_error (error, inner_error);
     return NULL;
@@ -150,25 +169,27 @@ rygel_mp2_ts_transcoder_real_add_resource (RygelTranscoder *base, GUPnPDIDLLiteI
     return NULL;
   }
 
-  gupnp_didl_lite_resource_set_width (resource, RYGEL_MP2_TS_TRANSCODER_WIDTH[self->priv->profile]);
-  gupnp_didl_lite_resource_set_height (resource, RYGEL_MP2_TS_TRANSCODER_HEIGHT[self->priv->profile]);
-  gupnp_didl_lite_resource_set_bitrate (resource,
-    ((RYGEL_MP2_TS_TRANSCODER_VIDEO_BITRATE + RYGEL_MP2_TS_TRANSCODER_AUDIO_BITRATE) * 1000) / 8);
+  bitrate = ((RYGEL_MP2_TS_TRANSCODER_VIDEO_BITRATE + RYGEL_MP2_TS_TRANSCODER_AUDIO_BITRATE) * 1000) / 8;
+  gupnp_didl_lite_resource_set_width (resource,
+                                      RYGEL_MP2_TS_TRANSCODER_WIDTH[self->priv->profile]);
+  gupnp_didl_lite_resource_set_height (resource,
+                                       RYGEL_MP2_TS_TRANSCODER_HEIGHT[self->priv->profile]);
+  gupnp_didl_lite_resource_set_bitrate (resource, bitrate);
 
   return resource;
 }
 
 static guint
-rygel_mp2_ts_transcoder_real_get_distance (RygelTranscoder *base, RygelMediaItem *item) {
+rygel_mp2_ts_transcoder_real_get_distance (RygelTranscoder *base,
+                                           RygelMediaItem  *item) {
   RygelMP2TSTranscoder *self = RYGEL_MP2_TS_TRANSCODER (base);
-
   RygelVideoItem *video_item;
   guint distance;
   guint bitrate;
   guint width;
   guint height;
 
-  g_return_val_if_fail (item != NULL, 0U);
+  g_return_val_if_fail (RYGEL_IS_MEDIA_ITEM (item), G_MAXUINT);
 
   if (!RYGEL_IS_VIDEO_ITEM (item)) {
     return G_MAXUINT;
@@ -178,17 +199,17 @@ rygel_mp2_ts_transcoder_real_get_distance (RygelTranscoder *base, RygelMediaItem
   distance = 0;
 
   bitrate = rygel_audio_item_get_bits_per_sample (RYGEL_AUDIO_ITEM (video_item));
-  if(bitrate > 0) {
+  if (bitrate > 0) {
     distance += abs(bitrate - RYGEL_MP2_TS_TRANSCODER_VIDEO_BITRATE);
   }
 
   width = rygel_visual_item_get_width (RYGEL_VISUAL_ITEM (video_item));
-  if(width > 0) {
+  if (width > 0) {
     distance += abs(width - RYGEL_MP2_TS_TRANSCODER_WIDTH[self->priv->profile]);
   }
 
   height = rygel_visual_item_get_height (RYGEL_VISUAL_ITEM (video_item));
-  if(height > 0) {
+  if (height > 0) {
     distance += abs(height - RYGEL_MP2_TS_TRANSCODER_HEIGHT[self->priv->profile]);
   }
 
@@ -196,54 +217,71 @@ rygel_mp2_ts_transcoder_real_get_distance (RygelTranscoder *base, RygelMediaItem
 }
 
 static void
-rygel_mp2_ts_transcoder_class_init (RygelMP2TSTranscoderClass *klass) {
-  rygel_mp2_ts_transcoder_parent_class = g_type_class_peek_parent (klass);
-  g_type_class_add_private (klass, sizeof (RygelMP2TSTranscoderPrivate));
-  RYGEL_TRANSCODER_CLASS (klass)->add_resource = rygel_mp2_ts_transcoder_real_add_resource;
-  RYGEL_TRANSCODER_CLASS (klass)->get_distance = rygel_mp2_ts_transcoder_real_get_distance;
-  G_OBJECT_CLASS (klass)->finalize = rygel_mp2_ts_transcoder_finalize;
-  G_OBJECT_CLASS (klass)->get_property = rygel_mp2_ts_transcoder_get_property;
-  G_OBJECT_CLASS (klass)->set_property = rygel_mp2_ts_transcoder_set_property;
-  g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_MP2_TS_TRANSCODER_PROFILE, g_param_spec_enum ("mp2-profile", "mp2-profile", "mp2-profile", RYGEL_TYPE_MP2_TS_PROFILE, RYGEL_MP2_TS_PROFILE_SD, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
-}
-
+rygel_mp2_ts_transcoder_get_property (GObject    *object,
+                                      guint       property_id,
+                                      GValue     *value,
+                                      GParamSpec *pspec) {
+  RygelMP2TSTranscoder *self = RYGEL_MP2_TS_TRANSCODER (object);
+  RygelMP2TSTranscoderPrivate *priv = self->priv;
 
-static void
-rygel_mp2_ts_transcoder_init (RygelMP2TSTranscoder *self) {
-  self->priv = RYGEL_MP2_TS_TRANSCODER_GET_PRIVATE (self);
-}
+  switch (property_id) {
+  case RYGEL_MP2_TS_TRANSCODER_PROFILE:
+    g_value_set_enum (value, priv->profile);
+    break;
 
-static void
-rygel_mp2_ts_transcoder_finalize (GObject* obj) {
-  G_OBJECT_CLASS (rygel_mp2_ts_transcoder_parent_class)->finalize (obj);
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    break;
+  }
 }
 
 static void
-rygel_mp2_ts_transcoder_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) {
+rygel_mp2_ts_transcoder_set_property (GObject      *object,
+                                      guint         property_id,
+                                      const GValue *value,
+                                      GParamSpec   *pspec) {
   RygelMP2TSTranscoder *self = RYGEL_MP2_TS_TRANSCODER (object);
   RygelMP2TSTranscoderPrivate *priv = self->priv;
 
   switch (property_id) {
-    case RYGEL_MP2_TS_TRANSCODER_PROFILE:
-      g_value_set_enum (value, priv->profile);
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-      break;
+  case RYGEL_MP2_TS_TRANSCODER_PROFILE:
+    priv->profile = g_value_get_enum (value);
+    break;
+
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    break;
   }
 }
 
 static void
-rygel_mp2_ts_transcoder_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) {
-  RygelMP2TSTranscoder *self = RYGEL_MP2_TS_TRANSCODER (object);
-  RygelMP2TSTranscoderPrivate *priv = self->priv;
+rygel_mp2_ts_transcoder_class_init (RygelMP2TSTranscoderClass *mp2_ts_transcoder_class) {
+  GObjectClass *object_class = G_OBJECT_CLASS (mp2_ts_transcoder_class);
+  RygelTranscoderClass *transcoder_class = RYGEL_TRANSCODER_CLASS (mp2_ts_transcoder_class);
+
+  transcoder_class->add_resource = rygel_mp2_ts_transcoder_real_add_resource;
+  transcoder_class->get_distance = rygel_mp2_ts_transcoder_real_get_distance;
+  object_class->get_property = rygel_mp2_ts_transcoder_get_property;
+  object_class->set_property = rygel_mp2_ts_transcoder_set_property;
+
+  g_object_class_install_property (object_class,
+                                   RYGEL_MP2_TS_TRANSCODER_PROFILE,
+                                   g_param_spec_enum ("mp2-profile",
+                                                      "mp2-profile",
+                                                      "mp2-profile",
+                                                      RYGEL_TYPE_MP2_TS_PROFILE,
+                                                      RYGEL_MP2_TS_PROFILE_SD,
+                                                      G_PARAM_STATIC_NAME |
+                                                      G_PARAM_STATIC_NICK |
+                                                      G_PARAM_STATIC_BLURB |
+                                                      G_PARAM_READABLE |
+                                                      G_PARAM_WRITABLE));
+
+  g_type_class_add_private (mp2_ts_transcoder_class,
+                            sizeof (RygelMP2TSTranscoderPrivate));
+}
 
-  switch (property_id) {
-    case RYGEL_MP2_TS_TRANSCODER_PROFILE:
-      priv->profile = g_value_get_enum (value);
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-      break;
-  }
+static void
+rygel_mp2_ts_transcoder_init (RygelMP2TSTranscoder *self) {
+  self->priv = RYGEL_MP2_TS_TRANSCODER_GET_PRIVATE (self);
 }
diff --git a/src/rygel-mp2ts-transcoder.h b/src/rygel-mp2ts-transcoder.h
index f2a57e8..c9f65ba 100644
--- a/src/rygel-mp2ts-transcoder.h
+++ b/src/rygel-mp2ts-transcoder.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -22,14 +22,6 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <stdlib.h>
-#include <string.h>
-#include <rygel-server.h>
-#include <gst/gst.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
-#include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <gee.h>
-#include <rygel-core.h>
 #include "rygel-video-transcoder.h"
 
 G_BEGIN_DECLS
@@ -61,8 +53,11 @@ typedef enum  {
 
 #define RYGEL_TYPE_MP2_TS_PROFILE (rygel_mp2_ts_profile_get_type ())
 
-GType rygel_mp2_ts_profile_get_type (void) G_GNUC_CONST;
-GType rygel_mp2_ts_transcoder_get_type (void) G_GNUC_CONST;
+GType
+rygel_mp2_ts_profile_get_type (void) G_GNUC_CONST;
+
+GType
+rygel_mp2_ts_transcoder_get_type (void) G_GNUC_CONST;
 
 RygelMP2TSTranscoder *
 rygel_mp2_ts_transcoder_new_sd_eu (void);
diff --git a/src/rygel-mp3-transcoder.c b/src/rygel-mp3-transcoder.c
index 906fc5e..ba575f1 100644
--- a/src/rygel-mp3-transcoder.c
+++ b/src/rygel-mp3-transcoder.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation.
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
  *                               <zeeshan ali nokia com>
@@ -23,14 +23,15 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-
 #include "rygel-mp3-transcoder.h"
 
 /**
  * Transcoder for mpeg 1 layer 3 audio.
  */
 
-G_DEFINE_TYPE (RygelMP3Transcoder, rygel_mp3_transcoder, RYGEL_TYPE_AUDIO_TRANSCODER)
+G_DEFINE_TYPE (RygelMP3Transcoder,
+	       rygel_mp3_transcoder,
+	       RYGEL_TYPE_AUDIO_TRANSCODER)
 
 #define RYGEL_MP3_TRANSCODER_BITRATE 128
 #define RYGEL_MP3_TRANSCODER_FORMAT "audio/mpeg,mpegversion=1,layer=3"
@@ -49,8 +50,7 @@ rygel_mp3_transcoder_new (void) {
 }
 
 static void
-rygel_mp3_transcoder_class_init (RygelMP3TranscoderClass *klass) {
-  rygel_mp3_transcoder_parent_class = g_type_class_peek_parent (klass);
+rygel_mp3_transcoder_class_init (RygelMP3TranscoderClass *mp3_transcoder_class G_GNUC_UNUSED) {
 }
 
 static void
diff --git a/src/rygel-mp3-transcoder.h b/src/rygel-mp3-transcoder.h
index a7afe02..16aa0e2 100644
--- a/src/rygel-mp3-transcoder.h
+++ b/src/rygel-mp3-transcoder.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -22,14 +22,6 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <stdlib.h>
-#include <string.h>
-#include <rygel-server.h>
-#include <gst/gst.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
-#include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <gee.h>
-#include <rygel-core.h>
 #include "rygel-audio-transcoder.h"
 
 G_BEGIN_DECLS
@@ -54,9 +46,11 @@ struct _RygelMP3TranscoderClass {
   RygelAudioTranscoderClass parent_class;
 };
 
-GType rygel_mp3_transcoder_get_type (void) G_GNUC_CONST;
+GType
+rygel_mp3_transcoder_get_type (void) G_GNUC_CONST;
 
-RygelMP3Transcoder* rygel_mp3_transcoder_new (void);
+RygelMP3Transcoder *
+rygel_mp3_transcoder_new (void);
 
 G_END_DECLS
 
diff --git a/src/rygel-video-transcoder.c b/src/rygel-video-transcoder.c
index e4eea2e..52c8b32 100644
--- a/src/rygel-video-transcoder.c
+++ b/src/rygel-video-transcoder.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2011 Nokia Corporation.
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * Author: Jens Georg <jensg openismus com>
  *
@@ -27,12 +27,14 @@
  * Base class for all transcoders that handle video.
  */
 
-G_DEFINE_TYPE (RygelVideoTranscoder, rygel_video_transcoder, RYGEL_TYPE_GST_TRANSCODER)
+G_DEFINE_TYPE (RygelVideoTranscoder,
+               rygel_video_transcoder,
+               RYGEL_TYPE_GST_TRANSCODER)
 
 struct _RygelVideoTranscoderPrivate {
   gint video_bitrate;
-  GstCaps* video_codec_format;
-  GstCaps* video_restrictions;
+  GstCaps *video_codec_format;
+  GstCaps *video_restrictions;
 };
 
 enum  {
@@ -42,26 +44,30 @@ enum  {
   RYGEL_VIDEO_TRANSCODER_VIDEO_RESTRICTIONS
 };
 
-#define RYGEL_VIDEO_TRANSCODER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RYGEL_TYPE_VIDEO_TRANSCODER, RygelVideoTranscoderPrivate))
-
-static void rygel_video_transcoder_finalize (GObject* obj);
-static void rygel_video_transcoder_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
-static void rygel_video_transcoder_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
-
-static GUPnPDIDLLiteResource* rygel_video_transcoder_real_add_resource (RygelTranscoder *base, GUPnPDIDLLiteItem *didl_item, RygelMediaItem *item, RygelTranscodeManager *manager, GError **error) {
+#define RYGEL_VIDEO_TRANSCODER_GET_PRIVATE(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+                                RYGEL_TYPE_VIDEO_TRANSCODER, \
+                                RygelVideoTranscoderPrivate))
+
+static GUPnPDIDLLiteResource *
+rygel_video_transcoder_real_add_resource (RygelTranscoder        *base,
+                                          GUPnPDIDLLiteItem      *didl_item,
+                                          RygelMediaItem         *item,
+                                          RygelTranscodeManager  *manager,
+                                          GError                **error) {
   RygelVideoTranscoder *self;
-  RygelVideoItem *video_item;
-  GUPnPDIDLLiteResource* resource;
-  GError *inner_error = NULL;
+  RygelVisualItem *visual_item;
+  GUPnPDIDLLiteResource *resource;
+  GError *inner_error;
+  gint audio_bitrate;
 
-  g_return_val_if_fail (didl_item != NULL, NULL);
-  g_return_val_if_fail (item != NULL, NULL);
-  g_return_val_if_fail (manager != NULL, NULL);
+  g_return_val_if_fail (GUPNP_IS_DIDL_LITE_ITEM (didl_item), NULL);
+  g_return_val_if_fail (RYGEL_IS_MEDIA_ITEM (item), NULL);
+  g_return_val_if_fail (RYGEL_IS_TRANSCODE_MANAGER (manager), NULL);
 
-  self = RYGEL_VIDEO_TRANSCODER (base);
-  video_item = RYGEL_VIDEO_ITEM (item);
+  inner_error = NULL;
 
-  resource = RYGEL_TRANSCODER_CLASS (rygel_video_transcoder_parent_class)->add_resource (RYGEL_TRANSCODER (self), didl_item, item, manager, &inner_error);
+  resource = RYGEL_TRANSCODER_CLASS (rygel_video_transcoder_parent_class)->add_resource (base, didl_item, item, manager, &inner_error);
   if (inner_error != NULL) {
     g_propagate_error (error, inner_error);
     return NULL;
@@ -71,12 +77,14 @@ static GUPnPDIDLLiteResource* rygel_video_transcoder_real_add_resource (RygelTra
     return NULL;
   }
 
-  gint audio_bitrate = rygel_audio_transcoder_get_audio_bitrate (RYGEL_AUDIO_TRANSCODER (self));
+  self = RYGEL_VIDEO_TRANSCODER (base);
+  audio_bitrate = rygel_audio_transcoder_get_audio_bitrate (RYGEL_AUDIO_TRANSCODER (self));
 
+  visual_item = RYGEL_VISUAL_ITEM (item);
   gupnp_didl_lite_resource_set_width (resource,
-    rygel_visual_item_get_width (RYGEL_VISUAL_ITEM (video_item)));
+    rygel_visual_item_get_width (RYGEL_VISUAL_ITEM (visual_item)));
   gupnp_didl_lite_resource_set_height (resource,
-    rygel_visual_item_get_height (RYGEL_VISUAL_ITEM (video_item)));
+    rygel_visual_item_get_height (RYGEL_VISUAL_ITEM (visual_item)));
   gupnp_didl_lite_resource_set_bitrate (resource,
     (self->priv->video_bitrate + audio_bitrate) * 1000 / 8);
 
@@ -84,44 +92,42 @@ static GUPnPDIDLLiteResource* rygel_video_transcoder_real_add_resource (RygelTra
 }
 
 static guint
-rygel_video_transcoder_real_get_distance (RygelTranscoder *base, RygelMediaItem *item) {
+rygel_video_transcoder_real_get_distance (RygelTranscoder *base,
+                                          RygelMediaItem  *item) {
   RygelVideoTranscoder *self;
-  RygelVideoItem *video_item;
+  RygelAudioItem *audio_item;
   guint distance;
   guint bitrate;
 
-  g_return_val_if_fail (item != NULL, G_MAXUINT);
-
-  self = RYGEL_VIDEO_TRANSCODER (base);
+  g_return_val_if_fail (RYGEL_IS_MEDIA_ITEM (item), G_MAXUINT);
 
   if (!RYGEL_IS_VIDEO_ITEM (item)) {
     return G_MAXUINT;
   }
 
-  video_item = RYGEL_VIDEO_ITEM (item);
+  self = RYGEL_VIDEO_TRANSCODER (base);
+  audio_item = RYGEL_AUDIO_ITEM (item);
 
-  bitrate = rygel_audio_item_get_bitrate (RYGEL_AUDIO_ITEM (video_item));
+  bitrate = rygel_audio_item_get_bitrate (audio_item);
   distance = 0;
-  if(bitrate > 0) {
+  if (bitrate > 0) {
     distance += abs(bitrate - self->priv->video_bitrate);
   }
 
   return distance;
 }
 
-static GstEncodingProfile*
+static GstEncodingProfile *
 rygel_video_transcoder_real_get_encoding_profile (RygelGstTranscoder *base) {
-  RygelVideoTranscoder *self;
+  RygelVideoTranscoder *self = RYGEL_VIDEO_TRANSCODER (base);
   GstEncodingContainerProfile *enc_container_profile;
   GstEncodingProfile *enc_video_profile;
 
-  self = RYGEL_VIDEO_TRANSCODER (base);
-
   enc_container_profile = GST_ENCODING_CONTAINER_PROFILE (RYGEL_GST_TRANSCODER_CLASS (rygel_video_transcoder_parent_class)->get_encoding_profile (RYGEL_GST_TRANSCODER (self)));
   enc_video_profile = GST_ENCODING_PROFILE (gst_encoding_video_profile_new (self->priv->video_codec_format,
-    rygel_gst_transcoder_get_preset (RYGEL_GST_TRANSCODER (self)),
-    self->priv->video_restrictions,
-    1));
+                                                                            rygel_gst_transcoder_get_preset (RYGEL_GST_TRANSCODER (self)),
+                                                                            self->priv->video_restrictions,
+                                                                            1));
 
   gst_encoding_profile_set_name (enc_video_profile, "video");
   gst_encoding_container_profile_add_profile (enc_container_profile, enc_video_profile);
@@ -131,79 +137,137 @@ rygel_video_transcoder_real_get_encoding_profile (RygelGstTranscoder *base) {
 }
 
 static void
-rygel_video_transcoder_class_init (RygelVideoTranscoderClass *klass) {
-  rygel_video_transcoder_parent_class = g_type_class_peek_parent (klass);
-  g_type_class_add_private (klass, sizeof (RygelVideoTranscoderPrivate));
-  RYGEL_TRANSCODER_CLASS (klass)->add_resource = rygel_video_transcoder_real_add_resource;
-  RYGEL_TRANSCODER_CLASS (klass)->get_distance = rygel_video_transcoder_real_get_distance;
-  RYGEL_GST_TRANSCODER_CLASS (klass)->get_encoding_profile = rygel_video_transcoder_real_get_encoding_profile;
-  G_OBJECT_CLASS (klass)->finalize = rygel_video_transcoder_finalize;
-  G_OBJECT_CLASS (klass)->get_property = rygel_video_transcoder_get_property;
-  G_OBJECT_CLASS (klass)->set_property = rygel_video_transcoder_set_property;
-  g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_VIDEO_TRANSCODER_VIDEO_BITRATE, g_param_spec_int ("video-bitrate", "video-bitrate", "video-bitrate", 0, G_MAXINT, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
-  g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_VIDEO_TRANSCODER_VIDEO_CAPS, g_param_spec_string ("video-caps", "video-caps", "video-caps", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
-  g_object_class_install_property (G_OBJECT_CLASS (klass), RYGEL_VIDEO_TRANSCODER_VIDEO_RESTRICTIONS, g_param_spec_string ("video-restrictions", "video-restrictions", "video-restrictions", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
-}
+rygel_video_transcoder_dispose (GObject *object) {
+  RygelVideoTranscoder *self = RYGEL_VIDEO_TRANSCODER (object);
+  RygelVideoTranscoderPrivate *priv = self->priv;
 
-static void
-rygel_video_transcoder_init (RygelVideoTranscoder *self) {
-  self->priv = RYGEL_VIDEO_TRANSCODER_GET_PRIVATE (self);
-  self->priv->video_restrictions = NULL;
-}
+  if (priv->video_codec_format) {
+    GstCaps *format = priv->video_codec_format;
 
-static void
-rygel_video_transcoder_finalize (GObject* obj) {
-  RygelVideoTranscoder *self;
-  self = RYGEL_VIDEO_TRANSCODER (obj);
-  gst_caps_unref (self->priv->video_codec_format);
-  gst_caps_unref (self->priv->video_restrictions);
-  G_OBJECT_CLASS (rygel_video_transcoder_parent_class)->finalize (obj);
+    priv->video_codec_format = NULL;
+    gst_caps_unref (format);
+  }
+  if (priv->video_restrictions) {
+    GstCaps *restrictions = priv->video_restrictions;
+
+    priv->video_restrictions = NULL;
+    gst_caps_unref (restrictions);
+  }
+
+  G_OBJECT_CLASS (rygel_video_transcoder_parent_class)->dispose (object);
 }
 
 static void
-rygel_video_transcoder_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) {
+rygel_video_transcoder_get_property (GObject    *object,
+                                     guint       property_id,
+                                     GValue     *value,
+                                     GParamSpec *pspec) {
   RygelVideoTranscoder *self = RYGEL_VIDEO_TRANSCODER (object);
   RygelVideoTranscoderPrivate *priv = self->priv;
 
   switch (property_id) {
-    case RYGEL_VIDEO_TRANSCODER_VIDEO_BITRATE:
-      g_value_set_int (value, priv->video_bitrate);
-      break;
-    case RYGEL_VIDEO_TRANSCODER_VIDEO_CAPS:
-      g_value_take_string (value, gst_caps_to_string (priv->video_codec_format));
-      break;
-    case RYGEL_VIDEO_TRANSCODER_VIDEO_RESTRICTIONS:
-      g_value_take_string (value, gst_caps_to_string (priv->video_restrictions));
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-      break;
+  case RYGEL_VIDEO_TRANSCODER_VIDEO_BITRATE:
+    g_value_set_int (value, priv->video_bitrate);
+    break;
+
+  case RYGEL_VIDEO_TRANSCODER_VIDEO_CAPS:
+    g_value_take_string (value, gst_caps_to_string (priv->video_codec_format));
+    break;
+
+  case RYGEL_VIDEO_TRANSCODER_VIDEO_RESTRICTIONS:
+    g_value_take_string (value, gst_caps_to_string (priv->video_restrictions));
+    break;
+
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    break;
   }
 }
 
 static void
-rygel_video_transcoder_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) {
+rygel_video_transcoder_set_property (GObject      *object,
+                                     guint         property_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec) {
   RygelVideoTranscoder *self = RYGEL_VIDEO_TRANSCODER (object);
   RygelVideoTranscoderPrivate *priv = self->priv;
 
   switch (property_id) {
-    case RYGEL_VIDEO_TRANSCODER_VIDEO_BITRATE:
-      priv->video_bitrate = g_value_get_int (value);
-      break;
-    case RYGEL_VIDEO_TRANSCODER_VIDEO_CAPS:
-      if (priv->video_codec_format) {
-        gst_caps_unref (priv->video_codec_format);
-      }
-      priv->video_codec_format = gst_caps_from_string (g_value_get_string (value));
-      break;
-    case RYGEL_VIDEO_TRANSCODER_VIDEO_RESTRICTIONS:
-      if (priv->video_restrictions) {
-        gst_caps_unref (priv->video_restrictions);
-      }
-      priv->video_restrictions = gst_caps_from_string (g_value_get_string (value));
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-      break;
+  case RYGEL_VIDEO_TRANSCODER_VIDEO_BITRATE:
+    priv->video_bitrate = g_value_get_int (value);
+    break;
+
+  case RYGEL_VIDEO_TRANSCODER_VIDEO_CAPS:
+    if (priv->video_codec_format) {
+      gst_caps_unref (priv->video_codec_format);
+    }
+    priv->video_codec_format = gst_caps_from_string (g_value_get_string (value));
+    break;
+
+  case RYGEL_VIDEO_TRANSCODER_VIDEO_RESTRICTIONS:
+    if (priv->video_restrictions) {
+      gst_caps_unref (priv->video_restrictions);
+    }
+    priv->video_restrictions = gst_caps_from_string (g_value_get_string (value));
+    break;
+
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    break;
   }
 }
+
+static void
+rygel_video_transcoder_class_init (RygelVideoTranscoderClass *video_transcoder_class) {
+  GObjectClass *object_class = G_OBJECT_CLASS (video_transcoder_class);
+  RygelTranscoderClass *transcoder_class = RYGEL_TRANSCODER_CLASS (video_transcoder_class);
+  RygelGstTranscoderClass *gst_transcoder_class = RYGEL_GST_TRANSCODER_CLASS (video_transcoder_class);
+
+  transcoder_class->add_resource = rygel_video_transcoder_real_add_resource;
+  transcoder_class->get_distance = rygel_video_transcoder_real_get_distance;
+  gst_transcoder_class->get_encoding_profile = rygel_video_transcoder_real_get_encoding_profile;
+  object_class->dispose = rygel_video_transcoder_dispose;
+  object_class->get_property = rygel_video_transcoder_get_property;
+  object_class->set_property = rygel_video_transcoder_set_property;
+  g_object_class_install_property (object_class,
+                                   RYGEL_VIDEO_TRANSCODER_VIDEO_BITRATE,
+                                   g_param_spec_int ("video-bitrate",
+                                                     "video-bitrate",
+                                                     "video-bitrate",
+                                                     0,
+                                                     G_MAXINT,
+                                                     0,
+                                                     G_PARAM_STATIC_NAME |
+                                                     G_PARAM_STATIC_NICK |
+                                                     G_PARAM_STATIC_BLURB |
+                                                     G_PARAM_READABLE |
+                                                     G_PARAM_WRITABLE));
+  g_object_class_install_property (object_class,
+                                   RYGEL_VIDEO_TRANSCODER_VIDEO_CAPS,
+                                   g_param_spec_string ("video-caps",
+                                                        "video-caps",
+                                                        "video-caps",
+                                                        NULL,
+                                                        G_PARAM_STATIC_NAME |
+                                                        G_PARAM_STATIC_NICK |
+                                                        G_PARAM_STATIC_BLURB |
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE));
+  g_object_class_install_property (object_class,
+                                   RYGEL_VIDEO_TRANSCODER_VIDEO_RESTRICTIONS,
+                                   g_param_spec_string ("video-restrictions",
+                                                        "video-restrictions",
+                                                        "video-restrictions",
+                                                        NULL,
+                                                        G_PARAM_STATIC_NAME |
+                                                        G_PARAM_STATIC_NICK |
+                                                        G_PARAM_STATIC_BLURB |
+                                                        G_PARAM_READABLE |
+                                                        G_PARAM_WRITABLE));
+  g_type_class_add_private (object_class, sizeof (RygelVideoTranscoderPrivate));
+}
+
+static void
+rygel_video_transcoder_init (RygelVideoTranscoder *self) {
+  self->priv = RYGEL_VIDEO_TRANSCODER_GET_PRIVATE (self);
+}
diff --git a/src/rygel-video-transcoder.h b/src/rygel-video-transcoder.h
index c03fdf2..26bc43d 100644
--- a/src/rygel-video-transcoder.h
+++ b/src/rygel-video-transcoder.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -22,14 +22,6 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <stdlib.h>
-#include <string.h>
-#include <rygel-server.h>
-#include <gst/gst.h>
-#include <libgupnp-dlna/gupnp-dlna-discoverer.h>
-#include <libgupnp-dlna/gupnp-dlna-profile.h>
-#include <gee.h>
-#include <rygel-core.h>
 #include "rygel-audio-transcoder.h"
 
 G_BEGIN_DECLS
@@ -55,7 +47,8 @@ struct _RygelVideoTranscoderClass {
   RygelAudioTranscoderClass parent_class;
 };
 
-GType rygel_video_transcoder_get_type (void) G_GNUC_CONST;
+GType
+rygel_video_transcoder_get_type (void) G_GNUC_CONST;
 
 G_END_DECLS
 
diff --git a/src/rygel-wmv-transcoder.c b/src/rygel-wmv-transcoder.c
index 76ffbe8..f6d7e66 100644
--- a/src/rygel-wmv-transcoder.c
+++ b/src/rygel-wmv-transcoder.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Jens Georg <mail jensge org>.
- * Copyright (C) 2012 Intel Corporation.
+ * Copyright (C) 2012, 2013 Intel Corporation.
  *
  * Author: Jens Georg <mail jensge org>
  *
@@ -22,14 +22,15 @@
  */
 
 #include "rygel-wmv-transcoder.h"
-#include "rygel-gst-utils.h"
 
-G_DEFINE_TYPE (RygelWMVTranscoder, rygel_wmv_transcoder, RYGEL_TYPE_VIDEO_TRANSCODER)
+G_DEFINE_TYPE (RygelWMVTranscoder,
+               rygel_wmv_transcoder,
+               RYGEL_TYPE_VIDEO_TRANSCODER)
 
 #define RYGEL_WMV_TRANSCODER_VIDEO_BITRATE 1200
 #define RYGEL_WMV_TRANSCODER_AUDIO_BITRATE 64
 
-RygelWMVTranscoder*
+RygelWMVTranscoder *
 rygel_wmv_transcoder_new (void) {
   return RYGEL_WMV_TRANSCODER (g_object_new (RYGEL_TYPE_WMV_TRANSCODER,
                                              "mime-type", "video/x-ms-wmv",
@@ -46,8 +47,7 @@ rygel_wmv_transcoder_new (void) {
 }
 
 static void
-rygel_wmv_transcoder_class_init (RygelWMVTranscoderClass *klass) {
-  rygel_wmv_transcoder_parent_class = g_type_class_peek_parent (klass);
+rygel_wmv_transcoder_class_init (RygelWMVTranscoderClass *wmv_transcoder_class G_GNUC_UNUSED) {
 }
 
 static void
diff --git a/src/rygel-wmv-transcoder.h b/src/rygel-wmv-transcoder.h
index 9179ff5..db54387 100644
--- a/src/rygel-wmv-transcoder.h
+++ b/src/rygel-wmv-transcoder.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 Nokia Corporation
- * Copyright (C) 2012 Intel Corporation
+ * Copyright (C) 2012, 2013 Intel Corporation
  *
  * Rygel is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -20,6 +20,8 @@
 #ifndef __RYGEL_GST_0_10_MEDIA_ENGINE_WMV_TRANSCODER_H__
 #define __RYGEL_GST_0_10_MEDIA_ENGINE_WMV_TRANSCODER_H__
 
+#include <glib.h>
+#include <glib-object.h>
 #include "rygel-video-transcoder.h"
 
 G_BEGIN_DECLS
@@ -44,9 +46,11 @@ struct _RygelWMVTranscoderClass {
   RygelVideoTranscoderClass parent_class;
 };
 
-GType rygel_wmv_transcoder_get_type (void) G_GNUC_CONST;
+GType
+rygel_wmv_transcoder_get_type (void) G_GNUC_CONST;
 
-RygelWMVTranscoder* rygel_wmv_transcoder_new (void);
+RygelWMVTranscoder *
+rygel_wmv_transcoder_new (void);
 
 G_END_DECLS
 
diff --git a/tests/test_simple.c b/tests/test_simple.c
index 232485d..e033a91 100644
--- a/tests/test_simple.c
+++ b/tests/test_simple.c
@@ -18,6 +18,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+#include <gst/gst.h>
 #include "rygel-gst-media-engine.h"
 
 int main(int argc, char *argv[])



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]