yading@11: /* yading@11: * APE tag writer yading@11: * Copyright (c) 2012 Paul B Mahol yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #include "libavutil/dict.h" yading@11: #include "avio_internal.h" yading@11: #include "avformat.h" yading@11: #include "apetag.h" yading@11: yading@11: static int string_is_ascii(const uint8_t *str) yading@11: { yading@11: while (*str && *str >= 0x20 && *str <= 0x7e ) str++; yading@11: return !*str; yading@11: } yading@11: yading@11: void ff_ape_write(AVFormatContext *s) yading@11: { yading@11: int64_t tag_bytes; yading@11: AVDictionaryEntry *t = NULL; yading@11: AVIOContext *pb = s->pb; yading@11: int tags = 0, vlen; yading@11: yading@11: tag_bytes = avio_tell(s->pb); yading@11: while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) { yading@11: if (!string_is_ascii(t->key)) { yading@11: av_log(s, AV_LOG_WARNING, "Non ASCII keys are not allowed\n"); yading@11: continue; yading@11: } yading@11: yading@11: vlen = strlen(t->value); yading@11: avio_wl32(pb, vlen + 1); yading@11: avio_wl32(pb, 0); // flags yading@11: avio_put_str(pb, t->key); yading@11: avio_put_str(pb, t->value); yading@11: tags++; yading@11: } yading@11: tag_bytes = avio_tell(s->pb) - tag_bytes; yading@11: yading@11: if (!tags) yading@11: return; yading@11: yading@11: avio_write(pb, APE_TAG_PREAMBLE, 8); yading@11: avio_wl32(pb, APE_TAG_VERSION); yading@11: avio_wl32(pb, tag_bytes + APE_TAG_FOOTER_BYTES); yading@11: avio_wl32(pb, tags); // item count yading@11: avio_wl32(pb, 0); // global flags yading@11: ffio_fill(pb, 0, 8); // reserved yading@11: }