vorbisdec: simplify tag handling using base class helper

This commit is contained in:
Mark Nauwelaerts 2012-03-06 15:57:21 +01:00
parent 8a3f818dce
commit 600b91e878
2 changed files with 15 additions and 41 deletions

View file

@ -128,14 +128,6 @@ vorbis_dec_finalize (GObject * object)
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
static void
gst_vorbis_dec_reset (GstVorbisDec * dec)
{
if (dec->taglist)
gst_tag_list_free (dec->taglist);
dec->taglist = NULL;
}
static gboolean static gboolean
vorbis_dec_start (GstAudioDecoder * dec) vorbis_dec_start (GstAudioDecoder * dec)
{ {
@ -145,7 +137,6 @@ vorbis_dec_start (GstAudioDecoder * dec)
vorbis_info_init (&vd->vi); vorbis_info_init (&vd->vi);
vorbis_comment_init (&vd->vc); vorbis_comment_init (&vd->vc);
vd->initialized = FALSE; vd->initialized = FALSE;
gst_vorbis_dec_reset (vd);
return TRUE; return TRUE;
} }
@ -163,7 +154,6 @@ vorbis_dec_stop (GstAudioDecoder * dec)
vorbis_dsp_clear (&vd->vd); vorbis_dsp_clear (&vd->vd);
vorbis_comment_clear (&vd->vc); vorbis_comment_clear (&vd->vc);
vorbis_info_clear (&vd->vi); vorbis_info_clear (&vd->vi);
gst_vorbis_dec_reset (vd);
return TRUE; return TRUE;
} }
@ -308,7 +298,7 @@ vorbis_handle_comment_packet (GstVorbisDec * vd, ogg_packet * packet)
{ {
guint bitrate = 0; guint bitrate = 0;
gchar *encoder = NULL; gchar *encoder = NULL;
GstTagList *list, *old_list; GstTagList *list;
GstBuffer *buf; GstBuffer *buf;
GST_DEBUG_OBJECT (vd, "parsing comment packet"); GST_DEBUG_OBJECT (vd, "parsing comment packet");
@ -321,58 +311,53 @@ vorbis_handle_comment_packet (GstVorbisDec * vd, ogg_packet * packet)
gst_tag_list_from_vorbiscomment_buffer (buf, (guint8 *) "\003vorbis", 7, gst_tag_list_from_vorbiscomment_buffer (buf, (guint8 *) "\003vorbis", 7,
&encoder); &encoder);
old_list = vd->taglist; if (!list) {
vd->taglist = gst_tag_list_merge (vd->taglist, list, GST_TAG_MERGE_REPLACE); GST_ERROR_OBJECT (vd, "couldn't decode comments");
list = gst_tag_list_new ();
}
if (old_list)
gst_tag_list_free (old_list);
gst_tag_list_free (list);
gst_buffer_unref (buf); gst_buffer_unref (buf);
if (!vd->taglist) {
GST_ERROR_OBJECT (vd, "couldn't decode comments");
vd->taglist = gst_tag_list_new ();
}
if (encoder) { if (encoder) {
if (encoder[0]) if (encoder[0])
gst_tag_list_add (vd->taglist, GST_TAG_MERGE_REPLACE, gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
GST_TAG_ENCODER, encoder, NULL); GST_TAG_ENCODER, encoder, NULL);
g_free (encoder); g_free (encoder);
} }
gst_tag_list_add (vd->taglist, GST_TAG_MERGE_REPLACE, gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
GST_TAG_ENCODER_VERSION, vd->vi.version, GST_TAG_ENCODER_VERSION, vd->vi.version,
GST_TAG_AUDIO_CODEC, "Vorbis", NULL); GST_TAG_AUDIO_CODEC, "Vorbis", NULL);
if (vd->vi.bitrate_nominal > 0 && vd->vi.bitrate_nominal <= 0x7FFFFFFF) { if (vd->vi.bitrate_nominal > 0 && vd->vi.bitrate_nominal <= 0x7FFFFFFF) {
gst_tag_list_add (vd->taglist, GST_TAG_MERGE_REPLACE, gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
GST_TAG_NOMINAL_BITRATE, (guint) vd->vi.bitrate_nominal, NULL); GST_TAG_NOMINAL_BITRATE, (guint) vd->vi.bitrate_nominal, NULL);
bitrate = vd->vi.bitrate_nominal; bitrate = vd->vi.bitrate_nominal;
} }
if (vd->vi.bitrate_upper > 0 && vd->vi.bitrate_upper <= 0x7FFFFFFF) { if (vd->vi.bitrate_upper > 0 && vd->vi.bitrate_upper <= 0x7FFFFFFF) {
gst_tag_list_add (vd->taglist, GST_TAG_MERGE_REPLACE, gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
GST_TAG_MAXIMUM_BITRATE, (guint) vd->vi.bitrate_upper, NULL); GST_TAG_MAXIMUM_BITRATE, (guint) vd->vi.bitrate_upper, NULL);
if (!bitrate) if (!bitrate)
bitrate = vd->vi.bitrate_upper; bitrate = vd->vi.bitrate_upper;
} }
if (vd->vi.bitrate_lower > 0 && vd->vi.bitrate_lower <= 0x7FFFFFFF) { if (vd->vi.bitrate_lower > 0 && vd->vi.bitrate_lower <= 0x7FFFFFFF) {
gst_tag_list_add (vd->taglist, GST_TAG_MERGE_REPLACE, gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
GST_TAG_MINIMUM_BITRATE, (guint) vd->vi.bitrate_lower, NULL); GST_TAG_MINIMUM_BITRATE, (guint) vd->vi.bitrate_lower, NULL);
if (!bitrate) if (!bitrate)
bitrate = vd->vi.bitrate_lower; bitrate = vd->vi.bitrate_lower;
} }
if (bitrate) { if (bitrate) {
gst_tag_list_add (vd->taglist, GST_TAG_MERGE_REPLACE, gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
GST_TAG_BITRATE, (guint) bitrate, NULL); GST_TAG_BITRATE, (guint) bitrate, NULL);
} }
gst_audio_decoder_merge_tags (GST_AUDIO_DECODER_CAST (vd), list,
GST_TAG_MERGE_REPLACE);
if (vd->initialized) { if (vd->initialized) {
gst_element_found_tags_for_pad (GST_ELEMENT_CAST (vd), gst_tag_list_free (list);
GST_AUDIO_DECODER_SRC_PAD (vd), vd->taglist);
vd->taglist = NULL;
} else { } else {
/* Only post them as messages for the time being. * /* Only post them as messages for the time being. *
* They will be pushed on the pad once the decoder is initialized */ * They will be pushed on the pad once the decoder is initialized */
gst_element_post_message (GST_ELEMENT_CAST (vd), gst_element_post_message (GST_ELEMENT_CAST (vd),
gst_message_new_tag (GST_OBJECT (vd), gst_tag_list_copy (vd->taglist))); gst_message_new_tag (GST_OBJECT (vd), list));
} }
return GST_FLOW_OK; return GST_FLOW_OK;
@ -398,12 +383,6 @@ vorbis_handle_type_packet (GstVorbisDec * vd)
vd->initialized = TRUE; vd->initialized = TRUE;
if (vd->taglist) {
/* The tags have already been sent on the bus as messages. */
gst_pad_push_event (GST_AUDIO_DECODER_SRC_PAD (vd),
gst_event_new_tag (vd->taglist));
vd->taglist = NULL;
}
return GST_FLOW_OK; return GST_FLOW_OK;
/* ERRORS */ /* ERRORS */
@ -728,7 +707,4 @@ vorbis_dec_flush (GstAudioDecoder * dec, gboolean hard)
#ifdef HAVE_VORBIS_SYNTHESIS_RESTART #ifdef HAVE_VORBIS_SYNTHESIS_RESTART
vorbis_synthesis_restart (&vd->vd); vorbis_synthesis_restart (&vd->vd);
#endif #endif
if (hard)
gst_vorbis_dec_reset (vd);
} }

View file

@ -64,8 +64,6 @@ struct _GstVorbisDec {
gboolean initialized; gboolean initialized;
guint width; guint width;
GstTagList *taglist;
CopySampleFunc copy_samples; CopySampleFunc copy_samples;
}; };