matroskadec: parse the channel layout mask for FLAC
[libav.git] / libavformat / vorbiscomment.c
CommitLineData
66061a12
JD
1/*
2 * VorbisComment writer
3 * Copyright (c) 2009 James Darnley
4 *
2912e87a 5 * This file is part of Libav.
66061a12 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
66061a12
JD
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.
11 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
66061a12
JD
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.
16 *
17 * You should have received a copy of the GNU Lesser General Public
2912e87a 18 * License along with Libav; if not, write to the Free Software
66061a12
JD
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "avformat.h"
23#include "metadata.h"
24#include "vorbiscomment.h"
25#include "libavcodec/bytestream.h"
d2d67e42 26#include "libavutil/dict.h"
66061a12
JD
27
28/**
29 * VorbisComment metadata conversion mapping.
30 * from Ogg Vorbis I format specification: comment field and header specification
31 * http://xiph.org/vorbis/doc/v-comment.html
32 */
33const AVMetadataConv ff_vorbiscomment_metadata_conv[] = {
34 { "ALBUMARTIST", "album_artist"},
35 { "TRACKNUMBER", "track" },
ec4913a8 36 { "DISCNUMBER", "disc" },
66061a12
JD
37 { 0 }
38};
39
d2d67e42 40int ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string,
66061a12
JD
41 unsigned *count)
42{
43 int len = 8;
44 len += strlen(vendor_string);
45 *count = 0;
46 if (m) {
d2d67e42
AK
47 AVDictionaryEntry *tag = NULL;
48 while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
66061a12
JD
49 len += 4 +strlen(tag->key) + 1 + strlen(tag->value);
50 (*count)++;
51 }
52 }
53 return len;
54}
55
d2d67e42 56int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m,
66061a12
JD
57 const char *vendor_string, const unsigned count)
58{
59 bytestream_put_le32(p, strlen(vendor_string));
60 bytestream_put_buffer(p, vendor_string, strlen(vendor_string));
81e5ff7a 61 if (*m) {
d2d67e42 62 AVDictionaryEntry *tag = NULL;
66061a12 63 bytestream_put_le32(p, count);
d2d67e42 64 while ((tag = av_dict_get(*m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
66061a12
JD
65 unsigned int len1 = strlen(tag->key);
66 unsigned int len2 = strlen(tag->value);
67 bytestream_put_le32(p, len1+1+len2);
68 bytestream_put_buffer(p, tag->key, len1);
69 bytestream_put_byte(p, '=');
70 bytestream_put_buffer(p, tag->value, len2);
71 }
72 } else
73 bytestream_put_le32(p, 0);
74 return 0;
75}