static const AVCodecTag codec_au_tags[] = {
{ AV_CODEC_ID_PCM_MULAW, 1 },
static const AVCodecTag codec_au_tags[] = {
{ AV_CODEC_ID_PCM_MULAW, 1 },
av_log(s, AV_LOG_ERROR, "Memory error while parsing AU metadata.\n");
} else {
av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED);
av_log(s, AV_LOG_ERROR, "Memory error while parsing AU metadata.\n");
} else {
av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED);
if (av_strcasecmp(keys[i], key) == 0) {
av_dict_set(&(s->metadata), keys[i], value, AV_DICT_DONT_STRDUP_VAL);
if (av_strcasecmp(keys[i], key) == 0) {
av_dict_set(&(s->metadata), keys[i], value, AV_DICT_DONT_STRDUP_VAL);
tag = avio_rl32(pb);
if (tag != MKTAG('.', 's', 'n', 'd'))
tag = avio_rl32(pb);
if (tag != MKTAG('.', 's', 'n', 'd'))
t = av_dict_get(m, keys[i], NULL, 0);
if (t != NULL) {
if (cnt++)
t = av_dict_get(m, keys[i], NULL, 0);
if (t != NULL) {
if (cnt++)
- av_bprint_chars(&bprint, '\n', 1);
- av_bprint_append_data(&bprint, keys[i], strlen(keys[i]));
- av_bprint_chars(&bprint, '=', 1);
- av_bprint_append_data(&bprint, t->value, strlen(t->value));
+ av_bprint_chars(annotations, '\n', 1);
+ av_bprintf(annotations, "%s=%s", keys[i], t->value);
- /* pad with 0's */
- av_bprint_append_data(&bprint, "\0\0\0\0\0\0\0\0", 8);
- return av_bprint_finalize(&bprint, buffer);
+ /* The specification requires the annotation field to be zero-terminated
+ * and its length to be a multiple of eight, so pad with 0's */
+ av_bprint_chars(annotations, '\0', 8);
+ return av_bprint_is_complete(annotations) ? 0 : AVERROR(ENOMEM);
if (s->nb_streams != 1) {
av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
if (s->nb_streams != 1) {
av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
- if (av_dict_count(s->metadata) > 0) {
- ret = au_get_annotations(s, &annotations);
- if (ret < 0)
- return ret;
- if (annotations != NULL) {
- au->header_size = (24 + strlen(annotations) + 8) & ~7;
- if (au->header_size < AU_DEFAULT_HEADER_SIZE)
- au->header_size = AU_DEFAULT_HEADER_SIZE;
- }
- }
+ av_bprint_init(&annotations, 0, INT_MAX - 24);
+ ret = au_get_annotations(s, &annotations);
+ if (ret < 0)
+ goto fail;
+ au->header_size = 24 + annotations.len & ~7;
+
ffio_wfourcc(pb, ".snd"); /* magic number */
avio_wb32(pb, au->header_size); /* header size */
avio_wb32(pb, AU_UNKNOWN_SIZE); /* data size */
avio_wb32(pb, par->codec_tag); /* codec ID */
avio_wb32(pb, par->sample_rate);
avio_wb32(pb, par->channels);
ffio_wfourcc(pb, ".snd"); /* magic number */
avio_wb32(pb, au->header_size); /* header size */
avio_wb32(pb, AU_UNKNOWN_SIZE); /* data size */
avio_wb32(pb, par->codec_tag); /* codec ID */
avio_wb32(pb, par->sample_rate);
avio_wb32(pb, par->channels);
- if (annotations != NULL) {
- avio_write(pb, annotations, au->header_size - 24);
- av_freep(&annotations);
- } else {
- avio_wb64(pb, 0); /* annotation field */
- }
- avio_flush(pb);
+ avio_write(pb, annotations.str, annotations.len & ~7);
avio_seek(pb, 8, SEEK_SET);
avio_wb32(pb, (uint32_t)(file_size - au->header_size));
avio_seek(pb, file_size, SEEK_SET);
avio_seek(pb, 8, SEEK_SET);
avio_wb32(pb, (uint32_t)(file_size - au->header_size));
avio_seek(pb, file_size, SEEK_SET);