metadata.c 2.46 KB
Newer Older
1 2 3
/*
 * copyright (c) 2009 Michael Niedermayer
 *
4
 * This file is part of Libav.
5
 *
6
 * Libav is free software; you can redistribute it and/or
7 8 9 10
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
11
 * Libav is distributed in the hope that it will be useful,
12 13 14 15 16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with Libav; if not, write to the Free Software
18 19 20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

21
#include "avformat.h"
22
#include "metadata.h"
23
#include "libavutil/dict.h"
24
#include "libavutil/avstring.h"
25

26
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv,
27
                                       const AVMetadataConv *s_conv)
28 29 30
{
    /* TODO: use binary search to look up the two conversion tables
       if the tables are getting big enough that it would matter speed wise */
31
    const AVMetadataConv *sc, *dc;
32 33
    AVDictionaryEntry *mtag = NULL;
    AVDictionary *dst = NULL;
34
    const char *key;
35

36 37 38
    if (d_conv == s_conv)
        return;

39
    while ((mtag = av_dict_get(*pm, "", mtag, AV_DICT_IGNORE_SUFFIX))) {
40
        key = mtag->key;
41 42
        if (s_conv)
            for (sc=s_conv; sc->native; sc++)
43
                if (!av_strcasecmp(key, sc->native)) {
44 45 46 47 48
                    key = sc->generic;
                    break;
                }
        if (d_conv)
            for (dc=d_conv; dc->native; dc++)
49
                if (!av_strcasecmp(key, dc->generic)) {
50 51 52
                    key = dc->native;
                    break;
                }
53
        av_dict_set(&dst, key, mtag->value, 0);
54
    }
55
    av_dict_free(pm);
56 57 58
    *pm = dst;
}

59 60
void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv,
                                                const AVMetadataConv *s_conv)
61 62
{
    int i;
63
    ff_metadata_conv(&ctx->metadata, d_conv, s_conv);
64
    for (i=0; i<ctx->nb_streams ; i++)
65
        ff_metadata_conv(&ctx->streams [i]->metadata, d_conv, s_conv);
66
    for (i=0; i<ctx->nb_chapters; i++)
67
        ff_metadata_conv(&ctx->chapters[i]->metadata, d_conv, s_conv);
68
    for (i=0; i<ctx->nb_programs; i++)
69
        ff_metadata_conv(&ctx->programs[i]->metadata, d_conv, s_conv);
70
}