wavenc creates corrupted INFO block when tag value is not aligned on 2 byte boundarys
Tag value length gets aligned to 2 byte boundary's and written, but the value its self does not get padded to meet the new alignment. This results in corrupting the tags that following.
String length includes the the null termnation.
So odd string length don't work
gst-launch-1.0 audiotestsrc num-buffers=1 ! taginject tags='comment=test,artist=test' ! wavenc ! filesink location=bad.wav
gst-discoverer-1.0 -v bad.wav
...
Tags:
container format: WAV
bitrate: 705600
audio codec: Uncompressed 16-bit PCM audio
comment: test
...
While strings that are even in length work
gst-launch-1.0 audiotestsrc num-buffers=1 ! taginject tags='comment=test1,artist=test3' ! wavenc ! filesink location=good.wav
gst-discoverer-1.0 -v good.wav
...
Tags:
container format: WAV
bitrate: 705600
audio codec: Uncompressed 16-bit PCM audio
comment: test1
artist: test3
...
This patch fixed the issue for me
@@ -546,6 +546,7 @@ gst_wavparse_tags_foreach (const GstTagList * tags, const gchar * tag,
0, NULL}
};
gint n;
+ size_t len;
gchar *str = NULL;
GstByteWriter *bw = data;
for (n = 0; rifftags[n].fcc != 0; n++) {
@@ -563,9 +564,14 @@ gst_wavparse_tags_foreach (const GstTagList * tags, const gchar * tag,
gst_tag_list_get_string (tags, tag, &str);
}
if (str) {
+ len = strlen (str);
gst_byte_writer_put_uint32_le (bw, rifftags[n].fcc);
- gst_byte_writer_put_uint32_le (bw, GST_ROUND_UP_2 (strlen (str)));
- gst_byte_writer_put_string (bw, str);
+ gst_byte_writer_put_uint32_le (bw, GST_ROUND_UP_2 (len));
+ gst_byte_writer_put_data (bw, str, len);
+ /* add padding if need be */
+ if (GST_ROUND_UP_2 (len) > len) {
+ gst_byte_writer_put_uint8 (bw, 0);
+ }
g_free (str);
str = NULL;
break;
As a side not, I am not sure if the null termination needs to be written? since the size is stored.