summaryrefslogtreecommitdiff
path: root/gst/aiff
diff options
context:
space:
mode:
authorMatthieu Bouron <matthieu.bouron@collabora.com>2014-03-26 17:43:33 +0000
committerStefan Sauer <ensonic@users.sf.net>2015-01-23 16:01:35 +0100
commit6716671762e2fdf8adc282300cc7cbc0479081e0 (patch)
tree79ba764cc722a04f9d6e4a5063d6ac018f847604 /gst/aiff
parent2b59d8ab7c46a3dd0cc78241b6cc1822407a9aec (diff)
downloadgstreamer-plugins-bad-6716671762e2fdf8adc282300cc7cbc0479081e0.tar.gz
aiffmux: write padding byte at end of SSND chunk if needed
AIFF chunks are supposed to be even aligned. Aligning the SSND chunk will allow the aiff muxer to properly write chunks (like the ID3 one) at the end of the file. https://bugzilla.gnome.org/show_bug.cgi?id=727402
Diffstat (limited to 'gst/aiff')
-rw-r--r--gst/aiff/aiffmux.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/gst/aiff/aiffmux.c b/gst/aiff/aiffmux.c
index f2e0f6979..5d5fded20 100644
--- a/gst/aiff/aiffmux.c
+++ b/gst/aiff/aiffmux.c
@@ -132,12 +132,19 @@ static void
gst_aiff_mux_write_form_header (GstAiffMux * aiffmux, guint32 audio_data_size,
GstByteWriter * writer)
{
+ guint64 cur_size;
+
/* ckID == 'FORM' */
gst_byte_writer_put_uint32_le_unchecked (writer,
GST_MAKE_FOURCC ('F', 'O', 'R', 'M'));
- /* ckSize is currently bogus but we'll know what it is later */
- gst_byte_writer_put_uint32_be_unchecked (writer,
- audio_data_size + AIFF_HEADER_LEN - 8);
+
+ /* AIFF chunks must be even aligned */
+ cur_size = AIFF_HEADER_LEN - 8 + audio_data_size;
+ if ((cur_size & 1) && cur_size + 1 < G_MAXUINT32) {
+ cur_size += 1;
+ }
+
+ gst_byte_writer_put_uint32_be_unchecked (writer, cur_size);
/* formType == 'AIFF' */
gst_byte_writer_put_uint32_le_unchecked (writer,
GST_MAKE_FOURCC ('A', 'I', 'F', 'F'));
@@ -395,8 +402,25 @@ gst_aiff_mux_event (GstPad * pad, GstObject * parent, GstEvent * event)
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_EOS:{
+ guint64 cur_size;
GST_DEBUG_OBJECT (aiffmux, "got EOS");
+ cur_size = aiffmux->length + AIFF_HEADER_LEN - 8;
+
+ /* ID3 chunk must be even aligned */
+ if ((aiffmux->length & 1) && cur_size + 1 < G_MAXUINT32) {
+ GstFlowReturn ret;
+ guint8 *data = g_new0 (guint8, 1);
+ GstBuffer *buffer = gst_buffer_new_wrapped (data, 1);
+ GST_BUFFER_OFFSET (buffer) = AIFF_HEADER_LEN + aiffmux->length;
+ GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE;
+ ret = gst_pad_push (aiffmux->srcpad, buffer);
+ if (ret != GST_FLOW_OK) {
+ GST_WARNING_OBJECT (aiffmux, "failed to push padding byte: %s",
+ gst_flow_get_name (ret));
+ }
+ }
+
/* write header with correct length values */
gst_aiff_mux_push_header (aiffmux, aiffmux->length);