Libav 0.7.1
|
00001 /* 00002 * copyright (c) 2009 Michael Niedermayer 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #include <strings.h> 00022 #include "avformat.h" 00023 #include "metadata.h" 00024 #include "libavutil/dict.h" 00025 00026 #if FF_API_OLD_METADATA2 00027 AVDictionaryEntry * 00028 av_metadata_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags) 00029 { 00030 return av_dict_get(m, key, prev, flags); 00031 } 00032 00033 int av_metadata_set2(AVDictionary **pm, const char *key, const char *value, int flags) 00034 { 00035 return av_dict_set(pm, key, value, flags); 00036 } 00037 00038 void av_metadata_conv(AVFormatContext *ctx, const AVMetadataConv *d_conv, 00039 const AVMetadataConv *s_conv) 00040 { 00041 return; 00042 } 00043 00044 void av_metadata_free(AVDictionary **pm) 00045 { 00046 av_dict_free(pm); 00047 } 00048 00049 void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags) 00050 { 00051 av_dict_copy(dst, src, flags); 00052 } 00053 #endif 00054 00055 void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, 00056 const AVMetadataConv *s_conv) 00057 { 00058 /* TODO: use binary search to look up the two conversion tables 00059 if the tables are getting big enough that it would matter speed wise */ 00060 const AVMetadataConv *sc, *dc; 00061 AVDictionaryEntry *mtag = NULL; 00062 AVDictionary *dst = NULL; 00063 const char *key; 00064 00065 if (d_conv == s_conv) 00066 return; 00067 00068 while ((mtag = av_dict_get(*pm, "", mtag, AV_DICT_IGNORE_SUFFIX))) { 00069 key = mtag->key; 00070 if (s_conv) 00071 for (sc=s_conv; sc->native; sc++) 00072 if (!strcasecmp(key, sc->native)) { 00073 key = sc->generic; 00074 break; 00075 } 00076 if (d_conv) 00077 for (dc=d_conv; dc->native; dc++) 00078 if (!strcasecmp(key, dc->generic)) { 00079 key = dc->native; 00080 break; 00081 } 00082 av_dict_set(&dst, key, mtag->value, 0); 00083 } 00084 av_dict_free(pm); 00085 *pm = dst; 00086 } 00087 00088 void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv, 00089 const AVMetadataConv *s_conv) 00090 { 00091 int i; 00092 ff_metadata_conv(&ctx->metadata, d_conv, s_conv); 00093 for (i=0; i<ctx->nb_streams ; i++) 00094 ff_metadata_conv(&ctx->streams [i]->metadata, d_conv, s_conv); 00095 for (i=0; i<ctx->nb_chapters; i++) 00096 ff_metadata_conv(&ctx->chapters[i]->metadata, d_conv, s_conv); 00097 for (i=0; i<ctx->nb_programs; i++) 00098 ff_metadata_conv(&ctx->programs[i]->metadata, d_conv, s_conv); 00099 } 00100