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

libavformat/metadata_compat.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009  Aurelien Jacobs <aurel@gnuage.org>
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/avstring.h"
00025 
00026 #if LIBAVFORMAT_VERSION_MAJOR < 53
00027 
00028 #define SIZE_OFFSET(x) sizeof(((AVFormatContext*)0)->x),offsetof(AVFormatContext,x)
00029 
00030 static const struct {
00031     const char name[16];
00032     int   size;
00033     int   offset;
00034 } compat_tab[] = {
00035     { "title",           SIZE_OFFSET(title)     },
00036     { "author",          SIZE_OFFSET(author)    },
00037     { "copyright",       SIZE_OFFSET(copyright) },
00038     { "comment",         SIZE_OFFSET(comment)   },
00039     { "album",           SIZE_OFFSET(album)     },
00040     { "year",            SIZE_OFFSET(year)      },
00041     { "track",           SIZE_OFFSET(track)     },
00042     { "genre",           SIZE_OFFSET(genre)     },
00043 
00044     { "artist",          SIZE_OFFSET(author)    },
00045     { "creator",         SIZE_OFFSET(author)    },
00046     { "written_by",      SIZE_OFFSET(author)    },
00047     { "lead_performer",  SIZE_OFFSET(author)    },
00048     { "composer",        SIZE_OFFSET(author)    },
00049     { "performer",       SIZE_OFFSET(author)    },
00050     { "description",     SIZE_OFFSET(comment)   },
00051     { "albumtitle",      SIZE_OFFSET(album)     },
00052     { "date",            SIZE_OFFSET(year)      },
00053     { "date_written",    SIZE_OFFSET(year)      },
00054     { "date_released",   SIZE_OFFSET(year)      },
00055     { "tracknumber",     SIZE_OFFSET(track)     },
00056     { "part_number",     SIZE_OFFSET(track)     },
00057 };
00058 
00059 void ff_metadata_demux_compat(AVFormatContext *ctx)
00060 {
00061     AVMetadata *m;
00062     int i, j;
00063 
00064     if ((m = ctx->metadata))
00065         for (j=0; j<m->count; j++)
00066             for (i=0; i<FF_ARRAY_ELEMS(compat_tab); i++)
00067                 if (!strcasecmp(m->elems[j].key, compat_tab[i].name)) {
00068                     int *ptr = (int *)((char *)ctx+compat_tab[i].offset);
00069                     if (*ptr)  continue;
00070                     if (compat_tab[i].size > sizeof(int))
00071                         av_strlcpy((char *)ptr, m->elems[j].value, compat_tab[i].size);
00072                     else
00073                         *ptr = atoi(m->elems[j].value);
00074                 }
00075 
00076     for (i=0; i<ctx->nb_chapters; i++)
00077         if ((m = ctx->chapters[i]->metadata))
00078             for (j=0; j<m->count; j++)
00079                 if (!strcasecmp(m->elems[j].key, "title")) {
00080                     av_free(ctx->chapters[i]->title);
00081                     ctx->chapters[i]->title = av_strdup(m->elems[j].value);
00082                 }
00083 
00084     for (i=0; i<ctx->nb_programs; i++)
00085         if ((m = ctx->programs[i]->metadata))
00086             for (j=0; j<m->count; j++) {
00087                 if (!strcasecmp(m->elems[j].key, "name")) {
00088                     av_free(ctx->programs[i]->name);
00089                     ctx->programs[i]->name = av_strdup(m->elems[j].value);
00090                 }
00091                 if (!strcasecmp(m->elems[j].key, "provider_name")) {
00092                     av_free(ctx->programs[i]->provider_name);
00093                     ctx->programs[i]->provider_name = av_strdup(m->elems[j].value);
00094                 }
00095             }
00096 
00097     for (i=0; i<ctx->nb_streams; i++)
00098         if ((m = ctx->streams[i]->metadata))
00099             for (j=0; j<m->count; j++) {
00100                 if (!strcasecmp(m->elems[j].key, "language"))
00101                     av_strlcpy(ctx->streams[i]->language, m->elems[j].value, 4);
00102                 if (!strcasecmp(m->elems[j].key, "filename")) {
00103                     av_free(ctx->streams[i]->filename);
00104                     ctx->streams[i]->filename= av_strdup(m->elems[j].value);
00105                 }
00106             }
00107 }
00108 
00109 
00110 #define FILL_METADATA(s, key, value) {                                        \
00111     if (value && *value && !av_metadata_get(s->metadata, #key, NULL, 0))      \
00112         av_metadata_set2(&s->metadata, #key, value, 0);                       \
00113     }
00114 #define FILL_METADATA_STR(s, key)  FILL_METADATA(s, key, s->key)
00115 #define FILL_METADATA_INT(s, key) {                                           \
00116     char number[10];                                                          \
00117     snprintf(number, sizeof(number), "%d", s->key);                           \
00118     if(s->key)  FILL_METADATA(s, key, number) }
00119 
00120 void ff_metadata_mux_compat(AVFormatContext *ctx)
00121 {
00122     int i;
00123 
00124     if (ctx->metadata && ctx->metadata->count > 0)
00125         return;
00126 
00127     FILL_METADATA_STR(ctx, title);
00128     FILL_METADATA_STR(ctx, author);
00129     FILL_METADATA_STR(ctx, copyright);
00130     FILL_METADATA_STR(ctx, comment);
00131     FILL_METADATA_STR(ctx, album);
00132     FILL_METADATA_INT(ctx, year);
00133     FILL_METADATA_INT(ctx, track);
00134     FILL_METADATA_STR(ctx, genre);
00135     for (i=0; i<ctx->nb_chapters; i++)
00136         FILL_METADATA_STR(ctx->chapters[i], title);
00137     for (i=0; i<ctx->nb_programs; i++) {
00138         FILL_METADATA_STR(ctx->programs[i], name);
00139         FILL_METADATA_STR(ctx->programs[i], provider_name);
00140     }
00141     for (i=0; i<ctx->nb_streams; i++) {
00142         FILL_METADATA_STR(ctx->streams[i], language);
00143         FILL_METADATA_STR(ctx->streams[i], filename);
00144     }
00145 }
00146 
00147 #endif /* LIBAVFORMAT_VERSION_MAJOR < 53 */

Generated on Fri Sep 16 2011 17:17:49 for FFmpeg by  doxygen 1.7.1