rtsp: Port to GIO
[platform/upstream/gstreamer.git] / gst-libs / gst / tag / gstvorbistag.c
index da1a1f3..63ea2f6 100644 (file)
@@ -98,6 +98,11 @@ static const GstTagEntryMatch tag_matches[] = {
    * http://mail.kde.org/pipermail/amarok/2006-May/000090.html
    */
   {GST_TAG_BEATS_PER_MINUTE, "BPM"},
+  /* What GStreamer calls encoder ("encoder used to encode this stream") is
+     stored in the vendor string in Vorbis/Theora/Kate and possibly others.
+     The Vorbis comment packet used in those streams uses ENCODER as the name
+     of the encoding program, which GStreamer calls application-name. */
+  {GST_TAG_APPLICATION_NAME, "ENCODER"},
   {NULL, NULL}
 };
 
@@ -267,7 +272,7 @@ gst_vorbis_tag_add (GstTagList * list, const gchar * tag, const gchar * value)
       break;
     }
     default:{
-      if (tag_type == GST_TYPE_DATE) {
+      if (tag_type == G_TYPE_DATE) {
         guint y, d = 1, m = 1;
         gchar *check = (gchar *) value;
 
@@ -313,7 +318,7 @@ static void
 gst_vorbis_tag_add_coverart (GstTagList * tags, gchar * img_data_base64,
     gint base64_len)
 {
-  GstBuffer *img;
+  GstSample *img;
   gsize img_len;
 
   if (base64_len < 2)
@@ -327,7 +332,7 @@ gst_vorbis_tag_add_coverart (GstTagList * tags, gchar * img_data_base64,
     goto decode_failed;
 
   img =
-      gst_tag_image_data_to_image_buffer ((const guint8 *) img_data_base64,
+      gst_tag_image_data_to_image_sample ((const guint8 *) img_data_base64,
       img_len, GST_TAG_IMAGE_TYPE_NONE);
 
   if (img == NULL)
@@ -336,7 +341,7 @@ gst_vorbis_tag_add_coverart (GstTagList * tags, gchar * img_data_base64,
   gst_tag_list_add (tags, GST_TAG_MERGE_APPEND,
       GST_TAG_PREVIEW_IMAGE, img, NULL);
 
-  gst_buffer_unref (img);
+  gst_sample_unref (img);
   return;
 
 /* ERRORS */
@@ -417,8 +422,9 @@ decode_failed:
 }
 
 /**
- * gst_tag_list_from_vorbiscomment_buffer:
- * @buffer: buffer to convert
+ * gst_tag_list_from_vorbiscomment:
+ * @data: data to convert
+ * @size: size of @data
  * @id_data: identification data at start of stream
  * @id_data_length: length of identification data
  * @vendor_string: pointer to a string that should take the vendor string
@@ -431,7 +437,7 @@ decode_failed:
  *          given vorbiscomment buffer or NULL on error.
  */
 GstTagList *
-gst_tag_list_from_vorbiscomment_buffer (const GstBuffer * buffer,
+gst_tag_list_from_vorbiscomment (const guint8 * data, gsize size,
     const guint8 * id_data, const guint id_data_length, gchar ** vendor_string)
 {
 #define ADVANCE(x) G_STMT_START{                                                \
@@ -447,16 +453,13 @@ gst_tag_list_from_vorbiscomment_buffer (const GstBuffer * buffer,
   gchar *cur, *value;
   guint cur_size;
   guint iterations;
-  guint8 *data;
-  guint size, value_len;
+  guint value_len;
   GstTagList *list;
 
-  g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
+  g_return_val_if_fail (data != NULL, NULL);
   g_return_val_if_fail (id_data != NULL || id_data_length == 0, NULL);
 
-  data = GST_BUFFER_DATA (buffer);
-  size = GST_BUFFER_SIZE (buffer);
-  list = gst_tag_list_new ();
+  list = gst_tag_list_new_empty ();
 
   if (size < 11 || size <= id_data_length + 4)
     goto error;
@@ -510,6 +513,37 @@ error:
 #undef ADVANCE
 }
 
+/**
+ * gst_tag_list_from_vorbiscomment_buffer:
+ * @buffer: buffer to convert
+ * @id_data: identification data at start of stream
+ * @id_data_length: length of identification data
+ * @vendor_string: pointer to a string that should take the vendor string
+ *                 of this vorbis comment or NULL if you don't need it.
+ *
+ * Creates a new tag list that contains the information parsed out of a
+ * vorbiscomment packet.
+ *
+ * Returns: A new #GstTagList with all tags that could be extracted from the
+ *          given vorbiscomment buffer or NULL on error.
+ */
+GstTagList *
+gst_tag_list_from_vorbiscomment_buffer (GstBuffer * buffer,
+    const guint8 * id_data, const guint id_data_length, gchar ** vendor_string)
+{
+  GstTagList *res;
+  guint8 *data;
+  gsize size;
+
+  data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
+  res =
+      gst_tag_list_from_vorbiscomment (data, size, id_data, id_data_length,
+      vendor_string);
+  gst_buffer_unmap (buffer, data, size);
+
+  return res;
+}
+
 typedef struct
 {
   guint count;
@@ -522,20 +556,30 @@ static GList *
 gst_tag_to_metadata_block_picture (const gchar * tag,
     const GValue * image_value)
 {
+#if 0
   gchar *comment_data, *data_result;
   const gchar *mime_type;
   guint mime_type_len;
   GstStructure *mime_struct;
   GstBuffer *buffer;
+#endif
   GList *l = NULL;
+#if 0
+  guint8 *data;
+  gsize size;
   GstByteWriter writer;
   GstTagImageType image_type = GST_TAG_IMAGE_TYPE_NONE;
   gint width = 0, height = 0;
   guint8 *metadata_block;
   guint metadata_block_len;
+#endif
 
   g_return_val_if_fail (image_value != NULL, NULL);
 
+  /* FIXME, no more buffer caps */
+  g_assert_not_reached ();
+
+#if 0
   buffer = gst_value_get_buffer (image_value);
   g_return_val_if_fail (gst_caps_is_fixed (buffer->caps), NULL);
   mime_struct = gst_caps_get_structure (buffer->caps, 0);
@@ -549,7 +593,7 @@ gst_tag_to_metadata_block_picture (const gchar * tag,
       &image_type, "width", G_TYPE_INT, &width, "height", G_TYPE_INT, &height,
       NULL);
 
-  metadata_block_len = 32 + mime_type_len + GST_BUFFER_SIZE (buffer);
+  metadata_block_len = 32 + mime_type_len + gst_buffer_get_size (buffer);
   gst_byte_writer_init_with_size (&writer, metadata_block_len, TRUE);
 
   if (image_type == GST_TAG_IMAGE_TYPE_NONE
@@ -575,9 +619,12 @@ gst_tag_to_metadata_block_picture (const gchar * tag,
   gst_byte_writer_put_uint32_be_unchecked (&writer, 0);
   /* for indexed formats the number of colors */
   gst_byte_writer_put_uint32_be_unchecked (&writer, 0);
-  gst_byte_writer_put_uint32_be_unchecked (&writer, GST_BUFFER_SIZE (buffer));
-  gst_byte_writer_put_data_unchecked (&writer, GST_BUFFER_DATA (buffer),
-      GST_BUFFER_SIZE (buffer));
+
+  data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
+  gst_byte_writer_put_uint32_be_unchecked (&writer, size);
+  gst_byte_writer_put_data_unchecked (&writer, data, size);
+  gst_buffer_unmap (buffer, data, size);
+
   g_assert (gst_byte_writer_get_pos (&writer) == metadata_block_len);
 
   metadata_block = gst_byte_writer_reset_and_get_data (&writer);
@@ -587,6 +634,7 @@ gst_tag_to_metadata_block_picture (const gchar * tag,
   g_free (comment_data);
 
   l = g_list_append (l, data_result);
+#endif
 
   return l;
 }
@@ -599,7 +647,7 @@ gst_tag_to_metadata_block_picture (const gchar * tag,
  * Creates a new tag list that contains the information parsed out of a
  * vorbiscomment packet.
  *
- * Returns: A #GList of newly-allowcated key=value strings. Free with
+ * Returns: A #GList of newly-allocated key=value strings. Free with
  *          g_list_foreach (list, (GFunc) g_free, NULL) plus g_list_free (list)
  */
 GList *
@@ -680,7 +728,7 @@ gst_tag_to_vorbis_comments (const GstTagList * list, const gchar * tag)
         break;
       }
       default:{
-        if (tag_type == GST_TYPE_DATE) {
+        if (tag_type == G_TYPE_DATE) {
           GDate *date;
 
           if (!gst_tag_list_get_date_index (list, tag, i, &date))
@@ -743,7 +791,7 @@ gst_tag_list_to_vorbiscomment_buffer (const GstTagList * list,
     const gchar * vendor_string)
 {
   GstBuffer *buffer;
-  guint8 *data;
+  guint8 *data, *odata;
   guint i;
   GList *l;
   MyForEach my_data = { 0, 0, NULL };
@@ -759,8 +807,9 @@ gst_tag_list_to_vorbiscomment_buffer (const GstTagList * list,
   required_size = id_data_length + 4 + vendor_len + 4 + 1;
   gst_tag_list_foreach ((GstTagList *) list, write_one_tag, &my_data);
   required_size += 4 * my_data.count + my_data.data_count;
+
   buffer = gst_buffer_new_and_alloc (required_size);
-  data = GST_BUFFER_DATA (buffer);
+  odata = data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
   if (id_data_length > 0) {
     memcpy (data, id_data, id_data_length);
     data += id_data_length;
@@ -788,6 +837,7 @@ gst_tag_list_to_vorbiscomment_buffer (const GstTagList * list,
   g_list_foreach (my_data.entries, (GFunc) g_free, NULL);
   g_list_free (my_data.entries);
   *data = 1;
+  gst_buffer_unmap (buffer, odata, required_size);
 
   return buffer;
 }