diff options
author | Stefan Sauer <ensonic@users.sf.net> | 2014-01-06 15:15:27 +0100 |
---|---|---|
committer | Stefan Sauer <ensonic@users.sf.net> | 2014-01-06 22:17:15 +0100 |
commit | a59d2c481713dd194cbedb5a6853be1a8cd435c2 (patch) | |
tree | 3044bb0f1cc04a24005c491b3df743d1995357e4 /ext/sndfile | |
parent | 0d9690ba1ea12d3635297c36fef4ff8d11aa6975 (diff) |
sfdec: break long method
Extract taglist creation into separate funtion.
Diffstat (limited to 'ext/sndfile')
-rw-r--r-- | ext/sndfile/gstsfdec.c | 193 |
1 files changed, 101 insertions, 92 deletions
diff --git a/ext/sndfile/gstsfdec.c b/ext/sndfile/gstsfdec.c index 7369cc3d5..29302ccf3 100644 --- a/ext/sndfile/gstsfdec.c +++ b/ext/sndfile/gstsfdec.c @@ -469,93 +469,13 @@ gst_sf_dec_sink_activate_mode (GstPad * sinkpad, GstObject * parent, return res; } -static gboolean -gst_sf_dec_open_file (GstSFDec * self) +static void +create_and_send_tags (GstSFDec * self, SF_INFO * info, SF_LOOP_INFO * loop_info, + SF_INSTRUMENT * instrument) { - SF_INFO info = { 0, }; - SF_LOOP_INFO loop_info = { 0, }; - SF_INSTRUMENT instrument = { 0, }; - GstCaps *caps; - GstStructure *s; - GstSegment seg; GstTagList *tags; - gint width; - const gchar *format; const gchar *tag; const gchar *codec_name; - gchar *stream_id; - gboolean have_loop_info = FALSE; - gboolean have_instrument = FALSE; - - GST_DEBUG_OBJECT (self, "opening the stream"); - if (!(self->file = sf_open_virtual (&gst_sf_vio, SFM_READ, &info, self))) - goto open_failed; - - stream_id = - gst_pad_create_stream_id (self->srcpad, GST_ELEMENT_CAST (self), NULL); - gst_pad_push_event (self->srcpad, gst_event_new_stream_start (stream_id)); - g_free (stream_id); - - self->channels = info.channels; - self->rate = info.samplerate; - self->duration = info.frames; - self->seekable = info.seekable; - GST_DEBUG_OBJECT (self, "stream openend: channels=%d, rate=%d, seekable=%d", - info.channels, info.samplerate, info.seekable); - - /* negotiate srcpad caps */ - if ((caps = gst_pad_get_allowed_caps (self->srcpad)) == NULL) { - caps = gst_pad_get_pad_template_caps (self->srcpad); - } - caps = gst_caps_make_writable (caps); - GST_DEBUG_OBJECT (self, "allowed caps %" GST_PTR_FORMAT, caps); - - s = gst_caps_get_structure (caps, 0); - gst_structure_set (s, - "channels", G_TYPE_INT, self->channels, - "rate", G_TYPE_INT, self->rate, NULL); - - if (!gst_structure_fixate_field_string (s, "format", GST_AUDIO_NE (S16))) - GST_WARNING_OBJECT (self, "Failed to fixate format to S16NE"); - - caps = gst_caps_fixate (caps); - - GST_DEBUG_OBJECT (self, "fixated caps %" GST_PTR_FORMAT, caps); - - /* configure to output the negotiated format */ - s = gst_caps_get_structure (caps, 0); - format = gst_structure_get_string (s, "format"); - if (g_str_equal (format, GST_AUDIO_NE (S32))) { - self->reader = (GstSFReader) sf_readf_int; - width = 32; - } else if (g_str_equal (format, GST_AUDIO_NE (S16))) { - self->reader = (GstSFReader) sf_readf_short; - width = 16; - } else { - self->reader = (GstSFReader) sf_readf_float; - width = 32; - } - self->bytes_per_frame = width * self->channels / 8; - - gst_pad_set_caps (self->srcpad, caps); - gst_caps_unref (caps); - - /* push initial segment */ - gst_segment_init (&seg, GST_FORMAT_TIME); - seg.stop = gst_util_uint64_scale_int (self->duration, GST_SECOND, self->rate); - gst_pad_push_event (self->srcpad, gst_event_new_segment (&seg)); - - /* get extra details */ - if (sf_command (self->file, SFC_GET_LOOP_INFO, &loop_info, - sizeof (loop_info))) { - GST_DEBUG_OBJECT (self, "have loop info"); - have_loop_info = TRUE; - } - if (sf_command (self->file, SFC_GET_INSTRUMENT, &instrument, - sizeof (instrument))) { - GST_DEBUG_OBJECT (self, "have instrument"); - have_instrument = TRUE; - } /* send tags */ tags = gst_tag_list_new_empty (); @@ -603,22 +523,22 @@ gst_sf_dec_open_file (GstSFDec * self) } g_value_unset (&tag_val); } - if (have_loop_info) { - if (loop_info.bpm != 0.0) { + if (loop_info) { + if (loop_info->bpm != 0.0) { gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_BEATS_PER_MINUTE, - (gdouble) loop_info.bpm, NULL); + (gdouble) loop_info->bpm, NULL); } - if (loop_info.root_key != -1) { + if (loop_info->root_key != -1) { gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_MIDI_BASE_NOTE, - (guint) loop_info.root_key, NULL); + (guint) loop_info->root_key, NULL); } } - if (have_instrument) { + if (instrument) { gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_MIDI_BASE_NOTE, - (guint) instrument.basenote, NULL); + (guint) instrument->basenote, NULL); } /* TODO: calculate bitrate: GST_TAG_BITRATE */ - switch (info.format & SF_FORMAT_SUBMASK) { + switch (info->format & SF_FORMAT_SUBMASK) { case SF_FORMAT_PCM_S8: case SF_FORMAT_PCM_16: case SF_FORMAT_PCM_24: @@ -663,7 +583,7 @@ gst_sf_dec_open_file (GstSFDec * self) default: codec_name = NULL; GST_WARNING_OBJECT (self, "unmapped codec_type: %d", - info.format & SF_FORMAT_SUBMASK); + info->format & SF_FORMAT_SUBMASK); break; } if (codec_name) { @@ -677,6 +597,95 @@ gst_sf_dec_open_file (GstSFDec * self) } else { gst_tag_list_unref (tags); } +} + +static gboolean +gst_sf_dec_open_file (GstSFDec * self) +{ + SF_INFO info = { 0, }; + SF_LOOP_INFO loop_info = { 0, }; + SF_INSTRUMENT instrument = { 0, }; + GstCaps *caps; + GstStructure *s; + GstSegment seg; + gint width; + const gchar *format; + gchar *stream_id; + gboolean have_loop_info = FALSE; + gboolean have_instrument = FALSE; + + GST_DEBUG_OBJECT (self, "opening the stream"); + if (!(self->file = sf_open_virtual (&gst_sf_vio, SFM_READ, &info, self))) + goto open_failed; + + stream_id = + gst_pad_create_stream_id (self->srcpad, GST_ELEMENT_CAST (self), NULL); + gst_pad_push_event (self->srcpad, gst_event_new_stream_start (stream_id)); + g_free (stream_id); + + self->channels = info.channels; + self->rate = info.samplerate; + self->duration = info.frames; + self->seekable = info.seekable; + GST_DEBUG_OBJECT (self, "stream openend: channels=%d, rate=%d, seekable=%d", + info.channels, info.samplerate, info.seekable); + + /* negotiate srcpad caps */ + if ((caps = gst_pad_get_allowed_caps (self->srcpad)) == NULL) { + caps = gst_pad_get_pad_template_caps (self->srcpad); + } + caps = gst_caps_make_writable (caps); + GST_DEBUG_OBJECT (self, "allowed caps %" GST_PTR_FORMAT, caps); + + s = gst_caps_get_structure (caps, 0); + gst_structure_set (s, + "channels", G_TYPE_INT, self->channels, + "rate", G_TYPE_INT, self->rate, NULL); + + if (!gst_structure_fixate_field_string (s, "format", GST_AUDIO_NE (S16))) + GST_WARNING_OBJECT (self, "Failed to fixate format to S16NE"); + + caps = gst_caps_fixate (caps); + + GST_DEBUG_OBJECT (self, "fixated caps %" GST_PTR_FORMAT, caps); + + /* configure to output the negotiated format */ + s = gst_caps_get_structure (caps, 0); + format = gst_structure_get_string (s, "format"); + if (g_str_equal (format, GST_AUDIO_NE (S32))) { + self->reader = (GstSFReader) sf_readf_int; + width = 32; + } else if (g_str_equal (format, GST_AUDIO_NE (S16))) { + self->reader = (GstSFReader) sf_readf_short; + width = 16; + } else { + self->reader = (GstSFReader) sf_readf_float; + width = 32; + } + self->bytes_per_frame = width * self->channels / 8; + + gst_pad_set_caps (self->srcpad, caps); + gst_caps_unref (caps); + + /* push initial segment */ + gst_segment_init (&seg, GST_FORMAT_TIME); + seg.stop = gst_util_uint64_scale_int (self->duration, GST_SECOND, self->rate); + gst_pad_push_event (self->srcpad, gst_event_new_segment (&seg)); + + /* get extra details */ + if (sf_command (self->file, SFC_GET_LOOP_INFO, &loop_info, + sizeof (loop_info))) { + GST_DEBUG_OBJECT (self, "have loop info"); + have_loop_info = TRUE; + } + if (sf_command (self->file, SFC_GET_INSTRUMENT, &instrument, + sizeof (instrument))) { + GST_DEBUG_OBJECT (self, "have instrument"); + have_instrument = TRUE; + } + + create_and_send_tags (self, &info, (have_loop_info ? &loop_info : NULL), + (have_instrument ? &instrument : NULL)); return TRUE; |