Use g_memdup2() where available and add fallback for older GLib versions
[platform/upstream/gstreamer.git] / gst-libs / gst / riff / riff-read.c
index 6afaa1e..5e9f331 100644 (file)
@@ -235,7 +235,8 @@ gst_riff_parse_file_header (GstElement * element,
     goto too_small;
 
   tag = GST_READ_UINT32_LE (info.data);
-  if (tag != GST_RIFF_TAG_RIFF && tag != GST_RIFF_TAG_AVF0)
+  if (tag != GST_RIFF_TAG_RIFF && tag != GST_RIFF_TAG_AVF0
+      && tag != GST_RIFF_TAG_RF64)
     goto not_riff;
 
   *doctype = GST_READ_UINT32_LE (info.data + 8);
@@ -258,8 +259,7 @@ too_small:
 not_riff:
   {
     GST_ELEMENT_ERROR (element, STREAM, WRONG_TYPE, (NULL),
-        ("Stream is no RIFF stream: %" GST_FOURCC_FORMAT,
-            GST_FOURCC_ARGS (tag)));
+        ("Stream is no RIFF stream: 0x%" G_GINT32_MODIFIER "x", tag));
     gst_buffer_unmap (buf, &info);
     gst_buffer_unref (buf);
     return FALSE;
@@ -293,7 +293,7 @@ gst_riff_parse_strh (GstElement * element,
   if (info.size < sizeof (gst_riff_strh))
     goto too_small;
 
-  strh = g_memdup (info.data, info.size);
+  strh = g_memdup2 (info.data, info.size);
   gst_buffer_unmap (buf, &info);
 
   gst_buffer_unref (buf);
@@ -362,7 +362,7 @@ too_small:
  *        containing extradata for this particular stream (e.g.
  *        palette, codec initialization data).
  *
- * Parses a video stream´s strf structure plus optionally some
+ * Parses a video stream's strf structure plus optionally some
  * extradata from input data. This function takes ownership of @buf.
  *
  * Returns: TRUE if parsing succeeded, otherwise FALSE. The stream
@@ -384,7 +384,7 @@ gst_riff_parse_strf_vids (GstElement * element,
   if (info.size < sizeof (gst_riff_strf_vids))
     goto too_small;
 
-  strf = g_memdup (info.data, info.size);
+  strf = g_memdup2 (info.data, info.size);
   gst_buffer_unmap (buf, &info);
 
 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
@@ -460,7 +460,7 @@ too_small:
  *        containing extradata for this particular stream (e.g.
  *        codec initialization data).
  *
- * Parses an audio stream´s strf structure plus optionally some
+ * Parses an audio stream's strf structure plus optionally some
  * extradata from input data. This function takes ownership of @buf.
  * use.
  *
@@ -482,7 +482,7 @@ gst_riff_parse_strf_auds (GstElement * element,
   if (info.size < sizeof (gst_riff_strf_auds))
     goto too_small;
 
-  strf = g_memdup (info.data, info.size);
+  strf = g_memdup2 (info.data, info.size);
 
 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
   strf->format = GUINT16_FROM_LE (strf->format);
@@ -574,7 +574,7 @@ gst_riff_parse_strf_iavs (GstElement * element,
   if (info.size < sizeof (gst_riff_strf_iavs))
     goto too_small;
 
-  strf = g_memdup (info.data, info.size);
+  strf = g_memdup2 (info.data, info.size);
   gst_buffer_unmap (buf, &info);
 
   gst_buffer_unref (buf);
@@ -823,136 +823,3 @@ gst_riff_parse_info (GstElement * element,
 
   return;
 }
-
-/**
- * gst_riff_parse_ncdt:
- * @element: caller element (used for debugging/error).
- * @buf: input data to be used for parsing, stripped from header.
- * @taglist: a pointer to a taglist (returned by this function)
- *           containing information about this stream. May be
- *           NULL if no supported tags were found.
- *
- * Parses Nikon metadata from input data.
- *
- * Since: 1.4
- */
-void
-gst_riff_parse_ncdt (GstElement * element,
-    GstBuffer * buf, GstTagList ** _taglist)
-{
-  GstMapInfo info;
-  guint8 *ptr;
-  gsize left;
-  guint tsize;
-  guint32 tag;
-  const gchar *type;
-  GstTagList *taglist;
-
-  g_return_if_fail (_taglist != NULL);
-
-  if (!buf) {
-    *_taglist = NULL;
-    return;
-  }
-  gst_buffer_map (buf, &info, GST_MAP_READ);
-
-  taglist = gst_tag_list_new_empty ();
-
-  ptr = info.data;
-  left = info.size;
-
-  while (left > 8) {
-    tag = GST_READ_UINT32_LE (ptr);
-    tsize = GST_READ_UINT32_LE (ptr + 4);
-
-    GST_MEMDUMP_OBJECT (element, "tag chunk", ptr, MIN (tsize + 8, left));
-
-    left -= 8;
-    ptr += 8;
-
-    GST_DEBUG ("tag %" GST_FOURCC_FORMAT ", size %u",
-        GST_FOURCC_ARGS (tag), tsize);
-
-    if (tsize > left) {
-      GST_WARNING_OBJECT (element,
-          "Tagsize %d is larger than available data %" G_GSIZE_FORMAT,
-          tsize, left);
-      tsize = left;
-    }
-
-    /* find out the type of metadata */
-    switch (tag) {
-      case GST_RIFF_LIST_nctg:{
-        while (tsize > 4) {
-          guint16 sub_tag = GST_READ_UINT16_LE (ptr);
-          guint16 sub_size = GST_READ_UINT16_LE (ptr + 2);
-
-          tsize -= 4;
-          ptr += 4;
-
-          GST_DEBUG ("sub-tag %u, size %u", sub_tag, sub_size);
-          /* http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Nikon.html#NCTG
-           * for some reason the sub_tag has a +2 offset
-           */
-          switch (sub_tag) {
-            case 0x03:         /* Make */
-              type = GST_TAG_DEVICE_MANUFACTURER;
-              break;
-            case 0x04:         /* Model */
-              type = GST_TAG_DEVICE_MODEL;
-              break;
-              /* TODO: 0x05: is software version, like V1.0 */
-            case 0x06:         /* Software */
-              type = GST_TAG_ENCODER;
-              break;
-            case 0x13:         /* CreationDate */
-              type = GST_TAG_DATE_TIME;
-              if (ptr[4] == ':')
-                ptr[4] = '-';
-              if (ptr[7] == ':')
-                ptr[7] = '-';
-              break;
-            default:
-              type = NULL;
-              break;
-          }
-          if (type != NULL && ptr[0] != '\0') {
-            GST_DEBUG_OBJECT (element, "mapped tag %u to tag %s", sub_tag,
-                type);
-
-            parse_tag_value (element, taglist, type, ptr, sub_size);
-          }
-
-          ptr += sub_size;
-          tsize -= sub_size;
-        }
-        break;
-      default:
-        type = NULL;
-        GST_WARNING_OBJECT (element,
-            "Unknown ncdt (metadata) tag entry %" GST_FOURCC_FORMAT,
-            GST_FOURCC_ARGS (tag));
-        break;
-      }
-
-        if (tsize & 1) {
-          tsize++;
-          if (tsize > left)
-            tsize = left;
-        }
-
-        ptr += tsize;
-        left -= tsize;
-    }
-
-    if (!gst_tag_list_is_empty (taglist)) {
-      GST_INFO_OBJECT (element, "extracted tags: %" GST_PTR_FORMAT, taglist);
-      *_taglist = taglist;
-    } else {
-      *_taglist = NULL;
-      gst_tag_list_unref (taglist);
-    }
-    gst_buffer_unmap (buf, &info);
-
-    return;
-  }