1/*
2 * copyright (c) 2009 Michael Niedermayer
3 *
4 * This file is part of Libav.
5 *
6 * Libav is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * Libav is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * 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 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "avformat.h"
22#include "metadata.h"
23#include "libavutil/dict.h"
24#include "libavutil/avstring.h"
25
26#if FF_API_OLD_METADATA2
27AVDictionaryEntry *
28av_metadata_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
29{
30    return av_dict_get(m, key, prev, flags);
31}
32
33int av_metadata_set2(AVDictionary **pm, const char *key, const char *value, int flags)
34{
35    return av_dict_set(pm, key, value, flags);
36}
37
38void av_metadata_conv(AVFormatContext *ctx, const AVMetadataConv *d_conv,
39                                            const AVMetadataConv *s_conv)
40{
41    return;
42}
43
44void av_metadata_free(AVDictionary **pm)
45{
46    av_dict_free(pm);
47}
48
49void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags)
50{
51    av_dict_copy(dst, src, flags);
52}
53#endif
54
55void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv,
56                                       const AVMetadataConv *s_conv)
57{
58    /* TODO: use binary search to look up the two conversion tables
59       if the tables are getting big enough that it would matter speed wise */
60    const AVMetadataConv *sc, *dc;
61    AVDictionaryEntry *mtag = NULL;
62    AVDictionary *dst = NULL;
63    const char *key;
64
65    if (d_conv == s_conv)
66        return;
67
68    while ((mtag = av_dict_get(*pm, "", mtag, AV_DICT_IGNORE_SUFFIX))) {
69        key = mtag->key;
70        if (s_conv)
71            for (sc=s_conv; sc->native; sc++)
72                if (!av_strcasecmp(key, sc->native)) {
73                    key = sc->generic;
74                    break;
75                }
76        if (d_conv)
77            for (dc=d_conv; dc->native; dc++)
78                if (!av_strcasecmp(key, dc->generic)) {
79                    key = dc->native;
80                    break;
81                }
82        av_dict_set(&dst, key, mtag->value, 0);
83    }
84    av_dict_free(pm);
85    *pm = dst;
86}
87
88void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv,
89                                                const AVMetadataConv *s_conv)
90{
91    int i;
92    ff_metadata_conv(&ctx->metadata, d_conv, s_conv);
93    for (i=0; i<ctx->nb_streams ; i++)
94        ff_metadata_conv(&ctx->streams [i]->metadata, d_conv, s_conv);
95    for (i=0; i<ctx->nb_chapters; i++)
96        ff_metadata_conv(&ctx->chapters[i]->metadata, d_conv, s_conv);
97    for (i=0; i<ctx->nb_programs; i++)
98        ff_metadata_conv(&ctx->programs[i]->metadata, d_conv, s_conv);
99}
100
101