• 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     { "description",     SIZE_OFFSET(comment)   },
00049     { "albumtitle",      SIZE_OFFSET(album)     },
00050     { "date_written",    SIZE_OFFSET(year)      },
00051     { "date_released",   SIZE_OFFSET(year)      },
00052     { "tracknumber",     SIZE_OFFSET(track)     },
00053     { "part_number",     SIZE_OFFSET(track)     },
00054 };
00055 
00056 void ff_metadata_demux_compat(AVFormatContext *ctx)
00057 {
00058     AVMetadata *m;
00059     int i, j;
00060 
00061     if ((m = ctx->metadata))
00062         for (j=0; j<m->count; j++)
00063             for (i=0; i<FF_ARRAY_ELEMS(compat_tab); i++)
00064                 if (!strcasecmp(m->elems[j].key, compat_tab[i].name)) {
00065                     int *ptr = (int *)((char *)ctx+compat_tab[i].offset);
00066                     if (*ptr)  continue;
00067                     if (compat_tab[i].size > sizeof(int))
00068                         av_strlcpy((char *)ptr, m->elems[j].value, compat_tab[i].size);
00069                     else
00070                         *ptr = atoi(m->elems[j].value);
00071                 }
00072 
00073     for (i=0; i<ctx->nb_chapters; i++)
00074         if ((m = ctx->chapters[i]->metadata))
00075             for (j=0; j<m->count; j++)
00076                 if (!strcasecmp(m->elems[j].key, "title")) {
00077                     av_free(ctx->chapters[i]->title);
00078                     ctx->chapters[i]->title = av_strdup(m->elems[j].value);
00079                 }
00080 
00081     for (i=0; i<ctx->nb_programs; i++)
00082         if ((m = ctx->programs[i]->metadata))
00083             for (j=0; j<m->count; j++) {
00084                 if (!strcasecmp(m->elems[j].key, "name")) {
00085                     av_free(ctx->programs[i]->name);
00086                     ctx->programs[i]->name = av_strdup(m->elems[j].value);
00087                 }
00088                 if (!strcasecmp(m->elems[j].key, "provider_name")) {
00089                     av_free(ctx->programs[i]->provider_name);
00090                     ctx->programs[i]->provider_name = av_strdup(m->elems[j].value);
00091                 }
00092             }
00093 
00094     for (i=0; i<ctx->nb_streams; i++)
00095         if ((m = ctx->streams[i]->metadata))
00096             for (j=0; j<m->count; j++) {
00097                 if (!strcasecmp(m->elems[j].key, "language"))
00098                     av_strlcpy(ctx->streams[i]->language, m->elems[j].value, 4);
00099                 if (!strcasecmp(m->elems[j].key, "filename")) {
00100                     av_free(ctx->streams[i]->filename);
00101                     ctx->streams[i]->filename= av_strdup(m->elems[j].value);
00102                 }
00103             }
00104 }
00105 
00106 
00107 #define FILL_METADATA(s, key, value) {                                        \
00108     if (value && *value && !av_metadata_get(s->metadata, #key, NULL, 0))      \
00109         av_metadata_set(&s->metadata, #key, value);                           \
00110     }
00111 #define FILL_METADATA_STR(s, key)  FILL_METADATA(s, key, s->key)
00112 #define FILL_METADATA_INT(s, key) {                                           \
00113     char number[10];                                                          \
00114     snprintf(number, sizeof(number), "%d", s->key);                           \
00115     if(s->key)  FILL_METADATA(s, key, number) }
00116 
00117 void ff_metadata_mux_compat(AVFormatContext *ctx)
00118 {
00119     int i;
00120 
00121     if (ctx->metadata && ctx->metadata->count > 0)
00122         return;
00123 
00124     FILL_METADATA_STR(ctx, title);
00125     FILL_METADATA_STR(ctx, author);
00126     FILL_METADATA_STR(ctx, copyright);
00127     FILL_METADATA_STR(ctx, comment);
00128     FILL_METADATA_STR(ctx, album);
00129     FILL_METADATA_INT(ctx, year);
00130     FILL_METADATA_INT(ctx, track);
00131     FILL_METADATA_STR(ctx, genre);
00132     for (i=0; i<ctx->nb_chapters; i++)
00133         FILL_METADATA_STR(ctx->chapters[i], title);
00134     for (i=0; i<ctx->nb_programs; i++) {
00135         FILL_METADATA_STR(ctx->programs[i], name);
00136         FILL_METADATA_STR(ctx->programs[i], provider_name);
00137     }
00138     for (i=0; i<ctx->nb_streams; i++) {
00139         FILL_METADATA_STR(ctx->streams[i], language);
00140         FILL_METADATA_STR(ctx->streams[i], filename);
00141     }
00142 }
00143 
00144 #endif /* LIBAVFORMAT_VERSION_MAJOR < 53 */

Generated on Sat Feb 16 2013 09:23:14 for ffmpeg by  doxygen 1.7.1