Merge the tizen patch and fix build err based on 1.12.2
[platform/upstream/gst-plugins-good.git] / ext / taglib / gstapev2mux.cc
index 532b2f7..9659daf 100644 (file)
@@ -15,8 +15,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.
  */
 
 /**
  * <refsect2>
  * <title>Example pipelines</title>
  * |[
- * gst-launch -v filesrc location=foo.ogg ! decodebin ! audioconvert ! lame ! apev2mux ! filesink location=foo.mp3
+ * gst-launch-1.0 -v filesrc location=foo.ogg ! decodebin ! audioconvert ! lame ! apev2mux ! filesink location=foo.mp3
  * ]| A pipeline that transcodes a file from Ogg/Vorbis to mp3 format with an
  * APEv2 that contains the same as the the Ogg/Vorbis file. Make sure the
  * Ogg/Vorbis file actually has comments to preserve.
  * |[
- * gst-launch -m filesrc location=foo.mp3 ! apedemux ! fakesink silent=TRUE 2&gt; /dev/null | grep taglist
+ * gst-launch-1.0 -m filesrc location=foo.mp3 ! apedemux ! fakesink silent=TRUE 2&gt; /dev/null | grep taglist
  * ]| Verify that tags have been written.
  * </refsect2>
  */
@@ -64,21 +64,32 @@ static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_ALWAYS,
     GST_STATIC_CAPS ("application/x-apetag"));
 
-GST_BOILERPLATE (GstApev2Mux, gst_apev2_mux, GstTagLibMux,
-    GST_TYPE_TAG_LIB_MUX);
+static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("ANY"));
+
+G_DEFINE_TYPE (GstApev2Mux, gst_apev2_mux, GST_TYPE_TAG_MUX);
 
-static GstBuffer *gst_apev2_mux_render_tag (GstTagLibMux * mux,
-    GstTagList * taglist);
+static GstBuffer *gst_apev2_mux_render_start_tag (GstTagMux * mux,
+    const GstTagList * taglist);
+static GstBuffer *gst_apev2_mux_render_end_tag (GstTagMux * mux,
+    const GstTagList * taglist);
 
 static void
-gst_apev2_mux_base_init (gpointer g_class)
+gst_apev2_mux_class_init (GstApev2MuxClass * klass)
 {
-  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
 
-  gst_element_class_add_pad_template (element_class,
-      gst_static_pad_template_get (&src_template));
+  GST_TAG_MUX_CLASS (klass)->render_start_tag =
+      GST_DEBUG_FUNCPTR (gst_apev2_mux_render_start_tag);
+  GST_TAG_MUX_CLASS (klass)->render_end_tag =
+      GST_DEBUG_FUNCPTR (gst_apev2_mux_render_end_tag);
 
-  gst_element_class_set_details_simple (element_class,
+  gst_element_class_add_static_pad_template (element_class, &sink_template);
+  gst_element_class_add_static_pad_template (element_class, &src_template);
+
+  gst_element_class_set_static_metadata (element_class,
       "TagLib-based APEv2 Muxer", "Formatter/Metadata",
       "Adds an APEv2 header to the beginning of files using taglib",
       "Sebastian Dröge <slomo@circular-chaos.org>");
@@ -88,16 +99,32 @@ gst_apev2_mux_base_init (gpointer g_class)
 }
 
 static void
-gst_apev2_mux_class_init (GstApev2MuxClass * klass)
+gst_apev2_mux_init (GstApev2Mux * apev2mux)
 {
-  GST_TAG_LIB_MUX_CLASS (klass)->render_tag =
-      GST_DEBUG_FUNCPTR (gst_apev2_mux_render_tag);
+  /* nothing to do */
 }
 
-static void
-gst_apev2_mux_init (GstApev2Mux * apev2mux, GstApev2MuxClass * apev2mux_class)
+static gboolean
+gst_apev2_mux_have_wavpack (GstApev2Mux * apev2mux)
 {
-  /* nothing to do */
+  const GstStructure *s;
+  gboolean ret;
+  GstCaps *caps;
+  GstPad *sink;
+
+  sink = gst_element_get_static_pad (GST_ELEMENT_CAST (apev2mux), "sink");
+  caps = gst_pad_get_current_caps (sink);
+  gst_object_unref (sink);
+
+  if (caps == NULL)
+    return FALSE;
+
+  s = gst_caps_get_structure (caps, 0);
+  ret = gst_structure_has_name (s, "audio/x-wavpack");
+  gst_caps_unref (caps);
+
+  GST_LOG_OBJECT (apev2mux, "got wavpack input: %s", ret ? "yes" : "no");
+  return ret;
 }
 
 static void
@@ -110,60 +137,54 @@ add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
    * work, only the first value will be taken into account
    */
   if (strcmp (tag, GST_TAG_TITLE) == 0) {
-    char *title;
+    const char *title;
 
-    result = gst_tag_list_get_string_index (list, tag, 0, &title);
+    result = gst_tag_list_peek_string_index (list, tag, 0, &title);
     if (result != FALSE) {
       GST_DEBUG ("Setting title to %s", title);
       apev2tag->setTitle (String (title, String::UTF8));
     }
-    g_free (title);
   } else if (strcmp (tag, GST_TAG_ALBUM) == 0) {
-    char *album;
+    const char *album;
 
-    result = gst_tag_list_get_string_index (list, tag, 0, &album);
+    result = gst_tag_list_peek_string_index (list, tag, 0, &album);
     if (result != FALSE) {
       GST_DEBUG ("Setting album to %s", album);
       apev2tag->setAlbum (String (album, String::UTF8));
     }
-    g_free (album);
   } else if (strcmp (tag, GST_TAG_ARTIST) == 0) {
-    char *artist;
+    const char *artist;
 
-    result = gst_tag_list_get_string_index (list, tag, 0, &artist);
+    result = gst_tag_list_peek_string_index (list, tag, 0, &artist);
     if (result != FALSE) {
       GST_DEBUG ("Setting artist to %s", artist);
       apev2tag->setArtist (String (artist, String::UTF8));
     }
-    g_free (artist);
   } else if (strcmp (tag, GST_TAG_COMPOSER) == 0) {
-    char *composer;
+    const char *composer;
 
-    result = gst_tag_list_get_string_index (list, tag, 0, &composer);
+    result = gst_tag_list_peek_string_index (list, tag, 0, &composer);
     if (result != FALSE) {
       GST_DEBUG ("Setting composer to %s", composer);
       apev2tag->addValue (String ("COMPOSER", String::UTF8),
           String (composer, String::UTF8));
     }
-    g_free (composer);
   } else if (strcmp (tag, GST_TAG_GENRE) == 0) {
-    char *genre;
+    const char *genre;
 
-    result = gst_tag_list_get_string_index (list, tag, 0, &genre);
+    result = gst_tag_list_peek_string_index (list, tag, 0, &genre);
     if (result != FALSE) {
       GST_DEBUG ("Setting genre to %s", genre);
       apev2tag->setGenre (String (genre, String::UTF8));
     }
-    g_free (genre);
   } else if (strcmp (tag, GST_TAG_COMMENT) == 0) {
-    char *comment;
+    const char *comment;
 
-    result = gst_tag_list_get_string_index (list, tag, 0, &comment);
+    result = gst_tag_list_peek_string_index (list, tag, 0, &comment);
     if (result != FALSE) {
       GST_DEBUG ("Setting comment to %s", comment);
       apev2tag->setComment (String (comment, String::UTF8));
     }
-    g_free (comment);
   } else if (strcmp (tag, GST_TAG_DATE) == 0) {
     GDate *date;
 
@@ -255,37 +276,34 @@ add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
     }
 #endif
   } else if (strcmp (tag, GST_TAG_COPYRIGHT) == 0) {
-    gchar *copyright;
+    const gchar *copyright;
 
-    result = gst_tag_list_get_string_index (list, tag, 0, &copyright);
+    result = gst_tag_list_peek_string_index (list, tag, 0, &copyright);
 
     if (result != FALSE) {
       GST_DEBUG ("Setting copyright to %s", copyright);
       apev2tag->addValue (String ("COPYRIGHT", String::UTF8),
           String (copyright, String::UTF8), true);
-      g_free (copyright);
     }
   } else if (strcmp (tag, GST_TAG_LOCATION) == 0) {
-    gchar *location;
+    const gchar *location;
 
-    result = gst_tag_list_get_string_index (list, tag, 0, &location);
+    result = gst_tag_list_peek_string_index (list, tag, 0, &location);
 
     if (result != FALSE) {
       GST_DEBUG ("Setting location to %s", location);
       apev2tag->addValue (String ("FILE", String::UTF8),
           String (location, String::UTF8), true);
-      g_free (location);
     }
   } else if (strcmp (tag, GST_TAG_ISRC) == 0) {
-    gchar *isrc;
+    const gchar *isrc;
 
-    result = gst_tag_list_get_string_index (list, tag, 0, &isrc);
+    result = gst_tag_list_peek_string_index (list, tag, 0, &isrc);
 
     if (result != FALSE) {
       GST_DEBUG ("Setting ISRC to %s", isrc);
       apev2tag->addValue (String ("ISRC", String::UTF8),
           String (isrc, String::UTF8), true);
-      g_free (isrc);
     }
   } else if (strcmp (tag, GST_TAG_TRACK_GAIN) == 0) {
     gdouble value;
@@ -349,7 +367,7 @@ add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
 }
 
 static GstBuffer *
-gst_apev2_mux_render_tag (GstTagLibMux * mux, GstTagList * taglist)
+gst_apev2_mux_render_tag (GstTagMux * mux, const GstTagList * taglist)
 {
   APE::Tag apev2tag;
   ByteVector rendered_tag;
@@ -366,18 +384,25 @@ gst_apev2_mux_render_tag (GstTagLibMux * mux, GstTagList * taglist)
 
   /* Create buffer with tag */
   buf = gst_buffer_new_and_alloc (tag_size);
-  memcpy (GST_BUFFER_DATA (buf), rendered_tag.data (), tag_size);
-  gst_buffer_set_caps (buf, GST_PAD_CAPS (mux->srcpad));
+  gst_buffer_fill (buf, 0, rendered_tag.data (), tag_size);
 
   return buf;
 }
 
-gboolean
-gst_apev2_mux_plugin_init (GstPlugin * plugin)
+static GstBuffer *
+gst_apev2_mux_render_start_tag (GstTagMux * mux, const GstTagList * taglist)
 {
-  if (!gst_element_register (plugin, "apev2mux", GST_RANK_NONE,
-          GST_TYPE_APEV2_MUX))
-    return FALSE;
+  if (gst_apev2_mux_have_wavpack (GST_APEV2_MUX (mux)))
+    return NULL;
+
+  return gst_apev2_mux_render_tag (mux, taglist);
+}
+
+static GstBuffer *
+gst_apev2_mux_render_end_tag (GstTagMux * mux, const GstTagList * taglist)
+{
+  if (gst_apev2_mux_have_wavpack (GST_APEV2_MUX (mux)))
+    return gst_apev2_mux_render_tag (mux, taglist);
 
-  return TRUE;
+  return NULL;
 }