annotate metadata_compat.c @ 6434:ca5676c4563d libavformat

cosmetic
author aurel
date Sun, 29 Aug 2010 21:23:52 +0000
parents 4974b3d4992b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4179
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
1 /*
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
2 * Copyright (c) 2009 Aurelien Jacobs <aurel@gnuage.org>
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
3 *
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
4 * This file is part of FFmpeg.
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
5 *
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
10 *
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
14 * Lesser General Public License for more details.
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
15 *
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
19 */
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
20
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
21 #include <strings.h>
4204
66dacc060918 fix version protection
aurel
parents: 4181
diff changeset
22 #include "avformat.h"
4179
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
23 #include "metadata.h"
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
24 #include "libavutil/avstring.h"
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
25
6387
4974b3d4992b rename LAVF_API_* defines to FF_API_* to clarify that it is not public API
aurel
parents: 6384
diff changeset
26 #if FF_API_OLD_METADATA
4204
66dacc060918 fix version protection
aurel
parents: 4181
diff changeset
27
4179
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
28 #define SIZE_OFFSET(x) sizeof(((AVFormatContext*)0)->x),offsetof(AVFormatContext,x)
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
29
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
30 static const struct {
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
31 const char name[16];
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
32 int size;
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
33 int offset;
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
34 } compat_tab[] = {
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
35 { "title", SIZE_OFFSET(title) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
36 { "author", SIZE_OFFSET(author) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
37 { "copyright", SIZE_OFFSET(copyright) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
38 { "comment", SIZE_OFFSET(comment) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
39 { "album", SIZE_OFFSET(album) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
40 { "year", SIZE_OFFSET(year) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
41 { "track", SIZE_OFFSET(track) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
42 { "genre", SIZE_OFFSET(genre) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
43
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
44 { "artist", SIZE_OFFSET(author) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
45 { "creator", SIZE_OFFSET(author) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
46 { "written_by", SIZE_OFFSET(author) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
47 { "lead_performer", SIZE_OFFSET(author) },
5618
27fd77f20a89 Add a list of generic tags and change demuxers to follow it.
pross
parents: 4583
diff changeset
48 { "composer", SIZE_OFFSET(author) },
27fd77f20a89 Add a list of generic tags and change demuxers to follow it.
pross
parents: 4583
diff changeset
49 { "performer", SIZE_OFFSET(author) },
4179
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
50 { "description", SIZE_OFFSET(comment) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
51 { "albumtitle", SIZE_OFFSET(album) },
5618
27fd77f20a89 Add a list of generic tags and change demuxers to follow it.
pross
parents: 4583
diff changeset
52 { "date", SIZE_OFFSET(year) },
4179
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
53 { "date_written", SIZE_OFFSET(year) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
54 { "date_released", SIZE_OFFSET(year) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
55 { "tracknumber", SIZE_OFFSET(track) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
56 { "part_number", SIZE_OFFSET(track) },
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
57 };
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
58
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
59 void ff_metadata_demux_compat(AVFormatContext *ctx)
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
60 {
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
61 AVMetadata *m;
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
62 int i, j;
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
63
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
64 if ((m = ctx->metadata))
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
65 for (j=0; j<m->count; j++)
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
66 for (i=0; i<FF_ARRAY_ELEMS(compat_tab); i++)
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
67 if (!strcasecmp(m->elems[j].key, compat_tab[i].name)) {
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
68 int *ptr = (int *)((char *)ctx+compat_tab[i].offset);
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
69 if (*ptr) continue;
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
70 if (compat_tab[i].size > sizeof(int))
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
71 av_strlcpy((char *)ptr, m->elems[j].value, compat_tab[i].size);
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
72 else
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
73 *ptr = atoi(m->elems[j].value);
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
74 }
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
75
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
76 for (i=0; i<ctx->nb_chapters; i++)
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
77 if ((m = ctx->chapters[i]->metadata))
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
78 for (j=0; j<m->count; j++)
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
79 if (!strcasecmp(m->elems[j].key, "title")) {
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
80 av_free(ctx->chapters[i]->title);
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
81 ctx->chapters[i]->title = av_strdup(m->elems[j].value);
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
82 }
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
83
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
84 for (i=0; i<ctx->nb_programs; i++)
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
85 if ((m = ctx->programs[i]->metadata))
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
86 for (j=0; j<m->count; j++) {
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
87 if (!strcasecmp(m->elems[j].key, "name")) {
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
88 av_free(ctx->programs[i]->name);
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
89 ctx->programs[i]->name = av_strdup(m->elems[j].value);
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
90 }
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
91 if (!strcasecmp(m->elems[j].key, "provider_name")) {
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
92 av_free(ctx->programs[i]->provider_name);
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
93 ctx->programs[i]->provider_name = av_strdup(m->elems[j].value);
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
94 }
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
95 }
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
96
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
97 for (i=0; i<ctx->nb_streams; i++)
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
98 if ((m = ctx->streams[i]->metadata))
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
99 for (j=0; j<m->count; j++) {
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
100 if (!strcasecmp(m->elems[j].key, "language"))
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
101 av_strlcpy(ctx->streams[i]->language, m->elems[j].value, 4);
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
102 if (!strcasecmp(m->elems[j].key, "filename")) {
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
103 av_free(ctx->streams[i]->filename);
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
104 ctx->streams[i]->filename= av_strdup(m->elems[j].value);
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
105 }
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
106 }
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
107 }
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
108
4180
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
109
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
110 #define FILL_METADATA(s, key, value) { \
6206
8515b7b4fe87 fix warning in ff_metadata_mux_compat()
aurel
parents: 5982
diff changeset
111 if (!av_metadata_get(s->metadata, #key, NULL, 0)) \
5982
f74198942337 Mark av_metadata_set() as deprecated, and use av_metadata_set2()
stefano
parents: 5618
diff changeset
112 av_metadata_set2(&s->metadata, #key, value, 0); \
4180
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
113 }
6206
8515b7b4fe87 fix warning in ff_metadata_mux_compat()
aurel
parents: 5982
diff changeset
114 #define FILL_METADATA_STR(s, key) { \
8515b7b4fe87 fix warning in ff_metadata_mux_compat()
aurel
parents: 5982
diff changeset
115 if (s->key && *s->key) FILL_METADATA(s, key, s->key); }
4180
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
116 #define FILL_METADATA_INT(s, key) { \
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
117 char number[10]; \
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
118 snprintf(number, sizeof(number), "%d", s->key); \
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
119 if(s->key) FILL_METADATA(s, key, number) }
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
120
4181
17a8a3696ee1 rename ff_metadata_sync_compat to ff_metadata_mux_compat
aurel
parents: 4180
diff changeset
121 void ff_metadata_mux_compat(AVFormatContext *ctx)
4180
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
122 {
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
123 int i;
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
124
4583
8d5d5bcf76c9 don't trigger metadata compatibility code when user app already set metadata
aurel
parents: 4353
diff changeset
125 if (ctx->metadata && ctx->metadata->count > 0)
8d5d5bcf76c9 don't trigger metadata compatibility code when user app already set metadata
aurel
parents: 4353
diff changeset
126 return;
8d5d5bcf76c9 don't trigger metadata compatibility code when user app already set metadata
aurel
parents: 4353
diff changeset
127
4180
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
128 FILL_METADATA_STR(ctx, title);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
129 FILL_METADATA_STR(ctx, author);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
130 FILL_METADATA_STR(ctx, copyright);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
131 FILL_METADATA_STR(ctx, comment);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
132 FILL_METADATA_STR(ctx, album);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
133 FILL_METADATA_INT(ctx, year);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
134 FILL_METADATA_INT(ctx, track);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
135 FILL_METADATA_STR(ctx, genre);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
136 for (i=0; i<ctx->nb_chapters; i++)
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
137 FILL_METADATA_STR(ctx->chapters[i], title);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
138 for (i=0; i<ctx->nb_programs; i++) {
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
139 FILL_METADATA_STR(ctx->programs[i], name);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
140 FILL_METADATA_STR(ctx->programs[i], provider_name);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
141 }
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
142 for (i=0; i<ctx->nb_streams; i++) {
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
143 FILL_METADATA_STR(ctx->streams[i], language);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
144 FILL_METADATA_STR(ctx->streams[i], filename);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
145 }
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
146 }
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
147
6387
4974b3d4992b rename LAVF_API_* defines to FF_API_* to clarify that it is not public API
aurel
parents: 6384
diff changeset
148 #endif /* FF_API_OLD_METADATA */