3 * Copyright (c) 2012 Paul B Mahol
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/dict.h"
23 #include "avio_internal.h"
27 static int string_is_ascii(const uint8_t *str)
29 while (*str && *str >= 0x20 && *str <= 0x7e ) str++;
33 void ff_ape_write(AVFormatContext *s)
36 AVDictionaryEntry *t = NULL;
37 AVIOContext *pb = s->pb;
40 tag_bytes = avio_tell(s->pb);
41 while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
42 if (!string_is_ascii(t->key)) {
43 av_log(s, AV_LOG_WARNING, "Non ASCII keys are not allowed\n");
47 vlen = strlen(t->value);
48 avio_wl32(pb, vlen + 1);
49 avio_wl32(pb, 0); // flags
50 avio_put_str(pb, t->key);
51 avio_put_str(pb, t->value);
54 tag_bytes = avio_tell(s->pb) - tag_bytes;
59 avio_write(pb, APE_TAG_PREAMBLE, 8);
60 avio_wl32(pb, APE_TAG_VERSION);
61 avio_wl32(pb, tag_bytes + APE_TAG_FOOTER_BYTES);
62 avio_wl32(pb, tags); // item count
63 avio_wl32(pb, 0); // global flags
64 ffio_fill(pb, 0, 8); // reserved