Mercurial > libavformat.hg
annotate metadata_compat.c @ 6470:5d5fbab4d608 libavformat
adts demuxer: Set the time base to be the LCM of all ADTS sample rates.
| author | alexc |
|---|---|
| date | Thu, 09 Sep 2010 23:15:17 +0000 |
| parents | 4974b3d4992b |
| children |
| 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 | 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 | 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 | 109 |
| 110 #define FILL_METADATA(s, key, value) { \ | |
| 6206 | 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 | 113 } |
| 6206 | 114 #define FILL_METADATA_STR(s, key) { \ |
| 115 if (s->key && *s->key) FILL_METADATA(s, key, s->key); } | |
| 4180 | 116 #define FILL_METADATA_INT(s, key) { \ |
| 117 char number[10]; \ | |
| 118 snprintf(number, sizeof(number), "%d", s->key); \ | |
| 119 if(s->key) FILL_METADATA(s, key, number) } | |
| 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 | 122 { |
| 123 int i; | |
| 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 | 128 FILL_METADATA_STR(ctx, title); |
| 129 FILL_METADATA_STR(ctx, author); | |
| 130 FILL_METADATA_STR(ctx, copyright); | |
| 131 FILL_METADATA_STR(ctx, comment); | |
| 132 FILL_METADATA_STR(ctx, album); | |
| 133 FILL_METADATA_INT(ctx, year); | |
| 134 FILL_METADATA_INT(ctx, track); | |
| 135 FILL_METADATA_STR(ctx, genre); | |
| 136 for (i=0; i<ctx->nb_chapters; i++) | |
| 137 FILL_METADATA_STR(ctx->chapters[i], title); | |
| 138 for (i=0; i<ctx->nb_programs; i++) { | |
| 139 FILL_METADATA_STR(ctx->programs[i], name); | |
| 140 FILL_METADATA_STR(ctx->programs[i], provider_name); | |
| 141 } | |
| 142 for (i=0; i<ctx->nb_streams; i++) { | |
| 143 FILL_METADATA_STR(ctx->streams[i], language); | |
| 144 FILL_METADATA_STR(ctx->streams[i], filename); | |
| 145 } | |
| 146 } | |
| 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 */ |
