yading@11
|
1 /*
|
yading@11
|
2 * VorbisComment writer
|
yading@11
|
3 * Copyright (c) 2009 James Darnley
|
yading@11
|
4 *
|
yading@11
|
5 * This file is part of FFmpeg.
|
yading@11
|
6 *
|
yading@11
|
7 * FFmpeg is free software; you can redistribute it and/or
|
yading@11
|
8 * modify it under the terms of the GNU Lesser General Public
|
yading@11
|
9 * License as published by the Free Software Foundation; either
|
yading@11
|
10 * version 2.1 of the License, or (at your option) any later version.
|
yading@11
|
11 *
|
yading@11
|
12 * FFmpeg is distributed in the hope that it will be useful,
|
yading@11
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@11
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@11
|
15 * Lesser General Public License for more details.
|
yading@11
|
16 *
|
yading@11
|
17 * You should have received a copy of the GNU Lesser General Public
|
yading@11
|
18 * License along with FFmpeg; if not, write to the Free Software
|
yading@11
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@11
|
20 */
|
yading@11
|
21
|
yading@11
|
22 #include "avformat.h"
|
yading@11
|
23 #include "metadata.h"
|
yading@11
|
24 #include "vorbiscomment.h"
|
yading@11
|
25 #include "libavcodec/bytestream.h"
|
yading@11
|
26 #include "libavutil/dict.h"
|
yading@11
|
27
|
yading@11
|
28 /**
|
yading@11
|
29 * VorbisComment metadata conversion mapping.
|
yading@11
|
30 * from Ogg Vorbis I format specification: comment field and header specification
|
yading@11
|
31 * http://xiph.org/vorbis/doc/v-comment.html
|
yading@11
|
32 */
|
yading@11
|
33 const AVMetadataConv ff_vorbiscomment_metadata_conv[] = {
|
yading@11
|
34 { "ALBUMARTIST", "album_artist"},
|
yading@11
|
35 { "TRACKNUMBER", "track" },
|
yading@11
|
36 { "DISCNUMBER", "disc" },
|
yading@11
|
37 { 0 }
|
yading@11
|
38 };
|
yading@11
|
39
|
yading@11
|
40 int ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string,
|
yading@11
|
41 unsigned *count)
|
yading@11
|
42 {
|
yading@11
|
43 int len = 8;
|
yading@11
|
44 len += strlen(vendor_string);
|
yading@11
|
45 *count = 0;
|
yading@11
|
46 if (m) {
|
yading@11
|
47 AVDictionaryEntry *tag = NULL;
|
yading@11
|
48 while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
|
yading@11
|
49 len += 4 +strlen(tag->key) + 1 + strlen(tag->value);
|
yading@11
|
50 (*count)++;
|
yading@11
|
51 }
|
yading@11
|
52 }
|
yading@11
|
53 return len;
|
yading@11
|
54 }
|
yading@11
|
55
|
yading@11
|
56 int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m,
|
yading@11
|
57 const char *vendor_string, const unsigned count)
|
yading@11
|
58 {
|
yading@11
|
59 bytestream_put_le32(p, strlen(vendor_string));
|
yading@11
|
60 bytestream_put_buffer(p, vendor_string, strlen(vendor_string));
|
yading@11
|
61 if (*m) {
|
yading@11
|
62 AVDictionaryEntry *tag = NULL;
|
yading@11
|
63 bytestream_put_le32(p, count);
|
yading@11
|
64 while ((tag = av_dict_get(*m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
|
yading@11
|
65 unsigned int len1 = strlen(tag->key);
|
yading@11
|
66 unsigned int len2 = strlen(tag->value);
|
yading@11
|
67 bytestream_put_le32(p, len1+1+len2);
|
yading@11
|
68 bytestream_put_buffer(p, tag->key, len1);
|
yading@11
|
69 bytestream_put_byte(p, '=');
|
yading@11
|
70 bytestream_put_buffer(p, tag->value, len2);
|
yading@11
|
71 }
|
yading@11
|
72 } else
|
yading@11
|
73 bytestream_put_le32(p, 0);
|
yading@11
|
74 return 0;
|
yading@11
|
75 }
|