yading@11: /* yading@11: * copyright (c) 2009 Michael Niedermayer yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #include "avformat.h" yading@11: #include "metadata.h" yading@11: #include "libavutil/dict.h" yading@11: #include "libavutil/avstring.h" yading@11: yading@11: void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, yading@11: const AVMetadataConv *s_conv) yading@11: { yading@11: /* TODO: use binary search to look up the two conversion tables yading@11: if the tables are getting big enough that it would matter speed wise */ yading@11: const AVMetadataConv *sc, *dc; yading@11: AVDictionaryEntry *mtag = NULL; yading@11: AVDictionary *dst = NULL; yading@11: const char *key; yading@11: yading@11: if (d_conv == s_conv) yading@11: return; yading@11: yading@11: while ((mtag = av_dict_get(*pm, "", mtag, AV_DICT_IGNORE_SUFFIX))) { yading@11: key = mtag->key; yading@11: if (s_conv) yading@11: for (sc=s_conv; sc->native; sc++) yading@11: if (!av_strcasecmp(key, sc->native)) { yading@11: key = sc->generic; yading@11: break; yading@11: } yading@11: if (d_conv) yading@11: for (dc=d_conv; dc->native; dc++) yading@11: if (!av_strcasecmp(key, dc->generic)) { yading@11: key = dc->native; yading@11: break; yading@11: } yading@11: av_dict_set(&dst, key, mtag->value, 0); yading@11: } yading@11: av_dict_free(pm); yading@11: *pm = dst; yading@11: } yading@11: yading@11: void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv, yading@11: const AVMetadataConv *s_conv) yading@11: { yading@11: int i; yading@11: ff_metadata_conv(&ctx->metadata, d_conv, s_conv); yading@11: for (i=0; inb_streams ; i++) yading@11: ff_metadata_conv(&ctx->streams [i]->metadata, d_conv, s_conv); yading@11: for (i=0; inb_chapters; i++) yading@11: ff_metadata_conv(&ctx->chapters[i]->metadata, d_conv, s_conv); yading@11: for (i=0; inb_programs; i++) yading@11: ff_metadata_conv(&ctx->programs[i]->metadata, d_conv, s_conv); yading@11: }