Fix FSF address
[platform/upstream/gstreamer.git] / gst-libs / gst / pbutils / gstdiscoverer.c
index 2630eaa..6ff01fa 100644 (file)
@@ -14,8 +14,8 @@
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 /**
 #endif
 
 #include <gst/video/video.h>
+#include <gst/audio/audio.h>
 
 #include "pbutils.h"
 #include "pbutils-private.h"
 
-#include "gst/glib-compat-private.h"
-
 GST_DEBUG_CATEGORY_STATIC (discoverer_debug);
 #define GST_CAT_DEFAULT discoverer_debug
 
@@ -80,7 +79,7 @@ struct _GstDiscovererPrivate
   /* list of pending URI to process (current excluded) */
   GList *pending_uris;
 
-  GMutex *lock;
+  GMutex lock;
 
   /* TRUE if processing a URI */
   gboolean processing;
@@ -125,8 +124,8 @@ struct _GstDiscovererPrivate
   gulong bus_cb_id;
 };
 
-#define DISCO_LOCK(dc) g_mutex_lock (dc->priv->lock);
-#define DISCO_UNLOCK(dc) g_mutex_unlock (dc->priv->lock);
+#define DISCO_LOCK(dc) g_mutex_lock (&dc->priv->lock);
+#define DISCO_UNLOCK(dc) g_mutex_unlock (&dc->priv->lock);
 
 static void
 _do_init (void)
@@ -177,6 +176,7 @@ static void uridecodebin_source_changed_cb (GstElement * uridecodebin,
     GParamSpec * pspec, GstDiscoverer * dc);
 
 static void gst_discoverer_dispose (GObject * dc);
+static void gst_discoverer_finalize (GObject * dc);
 static void gst_discoverer_set_property (GObject * object, guint prop_id,
     const GValue * value, GParamSpec * pspec);
 static void gst_discoverer_get_property (GObject * object, guint prop_id,
@@ -188,6 +188,7 @@ gst_discoverer_class_init (GstDiscovererClass * klass)
   GObjectClass *gobject_class = (GObjectClass *) klass;
 
   gobject_class->dispose = gst_discoverer_dispose;
+  gobject_class->finalize = gst_discoverer_finalize;
 
   gobject_class->set_property = gst_discoverer_set_property;
   gobject_class->get_property = gst_discoverer_get_property;
@@ -298,7 +299,7 @@ gst_discoverer_init (GstDiscoverer * dc)
   dc->priv->async = FALSE;
   dc->priv->async_done = FALSE;
 
-  dc->priv->lock = g_mutex_new ();
+  g_mutex_init (&dc->priv->lock);
 
   dc->priv->pending_subtitle_pads = 0;
 
@@ -396,11 +397,6 @@ gst_discoverer_dispose (GObject * obj)
 
   gst_discoverer_stop (dc);
 
-  if (dc->priv->lock) {
-    g_mutex_free (dc->priv->lock);
-    dc->priv->lock = NULL;
-  }
-
   if (dc->priv->seeking_query) {
     gst_query_unref (dc->priv->seeking_query);
     dc->priv->seeking_query = NULL;
@@ -410,6 +406,16 @@ gst_discoverer_dispose (GObject * obj)
 }
 
 static void
+gst_discoverer_finalize (GObject * obj)
+{
+  GstDiscoverer *dc = (GstDiscoverer *) obj;
+
+  g_mutex_clear (&dc->priv->lock);
+
+  G_OBJECT_CLASS (gst_discoverer_parent_class)->finalize (obj);
+}
+
+static void
 gst_discoverer_set_property (GObject * object, guint prop_id,
     const GValue * value, GParamSpec * pspec)
 {
@@ -472,7 +478,7 @@ _event_probe (GstPad * pad, GstPadProbeInfo * info, PrivateStream * ps)
           ps->tags);
       tmp = gst_tag_list_merge (ps->tags, tl, GST_TAG_MERGE_APPEND);
       if (ps->tags)
-        gst_tag_list_free (ps->tags);
+        gst_tag_list_unref (ps->tags);
       ps->tags = tmp;
       GST_DEBUG_OBJECT (pad, "private stream %p new tags %" GST_PTR_FORMAT, ps,
           tmp);
@@ -674,7 +680,7 @@ uridecodebin_pad_removed_cb (GstElement * uridecodebin, GstPad * pad,
   gst_bin_remove_many (dc->priv->pipeline, ps->sink, ps->queue, NULL);
 
   if (ps->tags) {
-    gst_tag_list_free (ps->tags);
+    gst_tag_list_unref (ps->tags);
   }
   if (ps->toc) {
     gst_toc_unref (ps->toc);
@@ -731,7 +737,7 @@ gst_discoverer_merge_and_replace_tags (GstTagList ** taglist,
   }
 
   gst_tag_list_insert (*taglist, new_tags, GST_TAG_MERGE_REPLACE);
-  gst_tag_list_free (new_tags);
+  gst_tag_list_unref (new_tags);
 }
 
 /* Parses a set of caps and tags in st and populates a GstDiscovererStreamInfo
@@ -764,6 +770,7 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
 
   if (g_str_has_prefix (name, "audio/")) {
     GstDiscovererAudioInfo *info;
+    const gchar *format_str;
 
     if (parent)
       info = (GstDiscovererAudioInfo *) gst_discoverer_stream_info_ref (parent);
@@ -779,8 +786,17 @@ collect_information (GstDiscoverer * dc, const GstStructure * st,
     if (gst_structure_get_int (caps_st, "channels", &tmp))
       info->channels = (guint) tmp;
 
-    if (gst_structure_get_int (caps_st, "depth", &tmp))
-      info->depth = (guint) tmp;
+    /* FIXME: we only want to extract depth if raw audio is what's in the
+     * container (i.e. not if there is a decoder involved) */
+    format_str = gst_structure_get_string (caps_st, "format");
+    if (format_str != NULL) {
+      const GstAudioFormatInfo *finfo;
+      GstAudioFormat format;
+
+      format = gst_audio_format_from_string (format_str);
+      finfo = gst_audio_format_get_info (format);
+      info->depth = GST_AUDIO_FORMAT_INFO_DEPTH (finfo);
+    }
 
     if (gst_structure_id_has_field (st, _TAGS_QUARK)) {
       gst_structure_id_get (st, _TAGS_QUARK, GST_TYPE_TAG_LIST, &tags_st, NULL);
@@ -1096,9 +1112,9 @@ parse_stream_topology (GstDiscoverer * dc, const GstStructure * topology,
       tmp =
           gst_tag_list_merge (cont->parent.tags, (GstTagList *) tags,
           GST_TAG_MERGE_APPEND);
-      gst_tag_list_free (tags);
+      gst_tag_list_unref (tags);
       if (cont->parent.tags)
-        gst_tag_list_free (cont->parent.tags);
+        gst_tag_list_unref (cont->parent.tags);
       cont->parent.tags = tmp;
       GST_DEBUG ("Container info tags %" GST_PTR_FORMAT, tmp);
     }
@@ -1204,12 +1220,14 @@ discoverer_collect (GstDiscoverer * dc)
     if (dc->priv->current_info->duration == 0 &&
         dc->priv->current_info->stream_info != NULL &&
         dc->priv->current_info->stream_info->next == NULL) {
-      GstStructure *st =
-          gst_caps_get_structure (dc->priv->current_info->stream_info->caps, 0);
+      GstDiscovererStreamInfo *stream_info;
+      GstStructure *st;
+
+      stream_info = dc->priv->current_info->stream_info;
+      st = gst_caps_get_structure (stream_info->caps, 0);
 
       if (g_str_has_prefix (gst_structure_get_name (st), "image/"))
-        ((GstDiscovererVideoInfo *) dc->priv->current_info->
-            stream_info)->is_image = TRUE;
+        ((GstDiscovererVideoInfo *) stream_info)->is_image = TRUE;
     }
   }
 
@@ -1358,9 +1376,9 @@ handle_message (GstDiscoverer * dc, GstMessage * msg)
       tmp =
           gst_tag_list_merge (dc->priv->current_info->tags, tl,
           GST_TAG_MERGE_APPEND);
-      gst_tag_list_free (tl);
+      gst_tag_list_unref (tl);
       if (dc->priv->current_info->tags)
-        gst_tag_list_free (dc->priv->current_info->tags);
+        gst_tag_list_unref (dc->priv->current_info->tags);
       dc->priv->current_info->tags = tmp;
       GST_DEBUG_OBJECT (GST_MESSAGE_SRC (msg), "Current info %p, tags %"
           GST_PTR_FORMAT, dc->priv->current_info, tmp);