• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavformat/metadata.c

Go to the documentation of this file.
00001 /*
00002  * copyright (c) 2009 Michael Niedermayer
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 #endif
00038 #if FF_API_OLD_METADATA
00039 int av_metadata_set(AVMetadata **pm, const char *key, const char *value)
00040 {
00041     return av_metadata_set2(pm, key, value, 0);
00042 }
00043 #endif
00044 
00045 #if FF_API_OLD_METADATA2
00046 
00047 void av_metadata_conv(AVFormatContext *ctx, const AVMetadataConv *d_conv,
00048                                             const AVMetadataConv *s_conv)
00049 {
00050     return;
00051 }
00052 
00053 void av_metadata_free(AVDictionary **pm)
00054 {
00055     av_dict_free(pm);
00056 }
00057 
00058 void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags)
00059 {
00060     av_dict_copy(dst, src, flags);
00061 }
00062 #endif
00063 
00064 void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv,
00065                                        const AVMetadataConv *s_conv)
00066 {
00067     /* TODO: use binary search to look up the two conversion tables
00068        if the tables are getting big enough that it would matter speed wise */
00069     const AVMetadataConv *sc, *dc;
00070     AVDictionaryEntry *mtag = NULL;
00071     AVDictionary *dst = NULL;
00072     const char *key;
00073 
00074     if (d_conv == s_conv)
00075         return;
00076 
00077     while ((mtag = av_dict_get(*pm, "", mtag, AV_DICT_IGNORE_SUFFIX))) {
00078         key = mtag->key;
00079         if (s_conv)
00080             for (sc=s_conv; sc->native; sc++)
00081                 if (!strcasecmp(key, sc->native)) {
00082                     key = sc->generic;
00083                     break;
00084                 }
00085         if (d_conv)
00086             for (dc=d_conv; dc->native; dc++)
00087                 if (!strcasecmp(key, dc->generic)) {
00088                     key = dc->native;
00089                     break;
00090                 }
00091         av_dict_set(&dst, key, mtag->value, 0);
00092     }
00093     av_dict_free(pm);
00094     *pm = dst;
00095 }
00096 
00097 void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv,
00098                                                 const AVMetadataConv *s_conv)
00099 {
00100     int i;
00101     ff_metadata_conv(&ctx->metadata, d_conv, s_conv);
00102     for (i=0; i<ctx->nb_streams ; i++)
00103         ff_metadata_conv(&ctx->streams [i]->metadata, d_conv, s_conv);
00104     for (i=0; i<ctx->nb_chapters; i++)
00105         ff_metadata_conv(&ctx->chapters[i]->metadata, d_conv, s_conv);
00106     for (i=0; i<ctx->nb_programs; i++)
00107         ff_metadata_conv(&ctx->programs[i]->metadata, d_conv, s_conv);
00108 }
00109 

Generated on Fri Feb 22 2013 07:24:31 for FFmpeg by  doxygen 1.7.1