Libav
vorbiscomment.c
Go to the documentation of this file.
1 /*
2  * VorbisComment writer
3  * Copyright (c) 2009 James Darnley
4  *
5  * This file is part of Libav.
6  *
7  * Libav 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.
11  *
12  * Libav 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.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
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"
26 #include "libavutil/dict.h"
27 
34  { "ALBUMARTIST", "album_artist"},
35  { "TRACKNUMBER", "track" },
36  { "DISCNUMBER", "disc" },
37  { 0 }
38 };
39 
40 int ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string)
41 {
42  int len = 8;
43  len += strlen(vendor_string);
44  if (m) {
46  while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
47  len += 4 +strlen(tag->key) + 1 + strlen(tag->value);
48  }
49  }
50  return len;
51 }
52 
54  const char *vendor_string)
55 {
56  bytestream_put_le32(p, strlen(vendor_string));
57  bytestream_put_buffer(p, vendor_string, strlen(vendor_string));
58  if (*m) {
59  int count = av_dict_count(*m);
61  bytestream_put_le32(p, count);
62  while ((tag = av_dict_get(*m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
63  unsigned int len1 = strlen(tag->key);
64  unsigned int len2 = strlen(tag->value);
65  bytestream_put_le32(p, len1+1+len2);
66  bytestream_put_buffer(p, tag->key, len1);
67  bytestream_put_byte(p, '=');
68  bytestream_put_buffer(p, tag->value, len2);
69  }
70  } else
71  bytestream_put_le32(p, 0);
72  return 0;
73 }
char * key
Definition: dict.h:75
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
Definition: dict.c:33
int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m, const char *vendor_string)
Write a VorbisComment into a buffer.
Definition: vorbiscomment.c:53
internal metadata API header see avformat.h or the public API!
uint8_t
uint32_t tag
Definition: movenc.c:844
int ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string)
Calculate the length in bytes of a VorbisComment.
Definition: vorbiscomment.c:40
const AVMetadataConv ff_vorbiscomment_metadata_conv[]
VorbisComment metadata conversion mapping.
Definition: vorbiscomment.c:33
char * value
Definition: dict.h:76
NULL
Definition: eval.c:55
Main libavformat public API header.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:38
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:363
int len
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:62