annotate ffmpeg/libavformat/metadata.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * copyright (c) 2009 Michael Niedermayer
yading@11 3 *
yading@11 4 * This file is part of FFmpeg.
yading@11 5 *
yading@11 6 * FFmpeg is free software; you can redistribute it and/or
yading@11 7 * modify it under the terms of the GNU Lesser General Public
yading@11 8 * License as published by the Free Software Foundation; either
yading@11 9 * version 2.1 of the License, or (at your option) any later version.
yading@11 10 *
yading@11 11 * FFmpeg is distributed in the hope that it will be useful,
yading@11 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 14 * Lesser General Public License for more details.
yading@11 15 *
yading@11 16 * You should have received a copy of the GNU Lesser General Public
yading@11 17 * License along with FFmpeg; if not, write to the Free Software
yading@11 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 19 */
yading@11 20
yading@11 21 #include "avformat.h"
yading@11 22 #include "metadata.h"
yading@11 23 #include "libavutil/dict.h"
yading@11 24 #include "libavutil/avstring.h"
yading@11 25
yading@11 26 void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv,
yading@11 27 const AVMetadataConv *s_conv)
yading@11 28 {
yading@11 29 /* TODO: use binary search to look up the two conversion tables
yading@11 30 if the tables are getting big enough that it would matter speed wise */
yading@11 31 const AVMetadataConv *sc, *dc;
yading@11 32 AVDictionaryEntry *mtag = NULL;
yading@11 33 AVDictionary *dst = NULL;
yading@11 34 const char *key;
yading@11 35
yading@11 36 if (d_conv == s_conv)
yading@11 37 return;
yading@11 38
yading@11 39 while ((mtag = av_dict_get(*pm, "", mtag, AV_DICT_IGNORE_SUFFIX))) {
yading@11 40 key = mtag->key;
yading@11 41 if (s_conv)
yading@11 42 for (sc=s_conv; sc->native; sc++)
yading@11 43 if (!av_strcasecmp(key, sc->native)) {
yading@11 44 key = sc->generic;
yading@11 45 break;
yading@11 46 }
yading@11 47 if (d_conv)
yading@11 48 for (dc=d_conv; dc->native; dc++)
yading@11 49 if (!av_strcasecmp(key, dc->generic)) {
yading@11 50 key = dc->native;
yading@11 51 break;
yading@11 52 }
yading@11 53 av_dict_set(&dst, key, mtag->value, 0);
yading@11 54 }
yading@11 55 av_dict_free(pm);
yading@11 56 *pm = dst;
yading@11 57 }
yading@11 58
yading@11 59 void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv,
yading@11 60 const AVMetadataConv *s_conv)
yading@11 61 {
yading@11 62 int i;
yading@11 63 ff_metadata_conv(&ctx->metadata, d_conv, s_conv);
yading@11 64 for (i=0; i<ctx->nb_streams ; i++)
yading@11 65 ff_metadata_conv(&ctx->streams [i]->metadata, d_conv, s_conv);
yading@11 66 for (i=0; i<ctx->nb_chapters; i++)
yading@11 67 ff_metadata_conv(&ctx->chapters[i]->metadata, d_conv, s_conv);
yading@11 68 for (i=0; i<ctx->nb_programs; i++)
yading@11 69 ff_metadata_conv(&ctx->programs[i]->metadata, d_conv, s_conv);
yading@11 70 }