yading@11: /* yading@11: * VorbisComment writer yading@11: * Copyright (c) 2009 James Darnley 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 "avformat.h" yading@11: #include "metadata.h" yading@11: #include "vorbiscomment.h" yading@11: #include "libavcodec/bytestream.h" yading@11: #include "libavutil/dict.h" yading@11: yading@11: /** yading@11: * VorbisComment metadata conversion mapping. yading@11: * from Ogg Vorbis I format specification: comment field and header specification yading@11: * http://xiph.org/vorbis/doc/v-comment.html yading@11: */ yading@11: const AVMetadataConv ff_vorbiscomment_metadata_conv[] = { yading@11: { "ALBUMARTIST", "album_artist"}, yading@11: { "TRACKNUMBER", "track" }, yading@11: { "DISCNUMBER", "disc" }, yading@11: { 0 } yading@11: }; yading@11: yading@11: int ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string, yading@11: unsigned *count) yading@11: { yading@11: int len = 8; yading@11: len += strlen(vendor_string); yading@11: *count = 0; yading@11: if (m) { yading@11: AVDictionaryEntry *tag = NULL; yading@11: while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) { yading@11: len += 4 +strlen(tag->key) + 1 + strlen(tag->value); yading@11: (*count)++; yading@11: } yading@11: } yading@11: return len; yading@11: } yading@11: yading@11: int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m, yading@11: const char *vendor_string, const unsigned count) yading@11: { yading@11: bytestream_put_le32(p, strlen(vendor_string)); yading@11: bytestream_put_buffer(p, vendor_string, strlen(vendor_string)); yading@11: if (*m) { yading@11: AVDictionaryEntry *tag = NULL; yading@11: bytestream_put_le32(p, count); yading@11: while ((tag = av_dict_get(*m, "", tag, AV_DICT_IGNORE_SUFFIX))) { yading@11: unsigned int len1 = strlen(tag->key); yading@11: unsigned int len2 = strlen(tag->value); yading@11: bytestream_put_le32(p, len1+1+len2); yading@11: bytestream_put_buffer(p, tag->key, len1); yading@11: bytestream_put_byte(p, '='); yading@11: bytestream_put_buffer(p, tag->value, len2); yading@11: } yading@11: } else yading@11: bytestream_put_le32(p, 0); yading@11: return 0; yading@11: }