00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 #include "avformat.h"
00023 #include "metadata.h"
00024 #include "vorbiscomment.h"
00025 #include "libavcodec/bytestream.h"
00026 #include "libavutil/dict.h"
00027 
00033 const AVMetadataConv ff_vorbiscomment_metadata_conv[] = {
00034     { "ALBUMARTIST", "album_artist"},
00035     { "TRACKNUMBER", "track"  },
00036     { "DISCNUMBER",  "disc"   },
00037     { 0 }
00038 };
00039 
00040 int ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string,
00041                             unsigned *count)
00042 {
00043     int len = 8;
00044     len += strlen(vendor_string);
00045     *count = 0;
00046     if (m) {
00047         AVDictionaryEntry *tag = NULL;
00048         while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
00049             len += 4 +strlen(tag->key) + 1 + strlen(tag->value);
00050             (*count)++;
00051         }
00052     }
00053     return len;
00054 }
00055 
00056 int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m,
00057                            const char *vendor_string, const unsigned count)
00058 {
00059     bytestream_put_le32(p, strlen(vendor_string));
00060     bytestream_put_buffer(p, vendor_string, strlen(vendor_string));
00061     if (*m) {
00062         AVDictionaryEntry *tag = NULL;
00063         bytestream_put_le32(p, count);
00064         while ((tag = av_dict_get(*m, "", tag, AV_DICT_IGNORE_SUFFIX))) {
00065             unsigned int len1 = strlen(tag->key);
00066             unsigned int len2 = strlen(tag->value);
00067             bytestream_put_le32(p, len1+1+len2);
00068             bytestream_put_buffer(p, tag->key, len1);
00069             bytestream_put_byte(p, '=');
00070             bytestream_put_buffer(p, tag->value, len2);
00071         }
00072     } else
00073         bytestream_put_le32(p, 0);
00074     return 0;
00075 }