Mercurial > libavformat.hg
annotate metadata_compat.c @ 4248:6e4ce186db2e libavformat
matroskadec: parse the WAVEFORMATEX header and discard it from extradata
author | aurel |
---|---|
date | Sun, 18 Jan 2009 17:13:12 +0000 |
parents | 66dacc060918 |
children | 2fc899894f5e |
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 |
4204 | 26 #if LIBAVFORMAT_VERSION_MAJOR < 53 |
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) }, |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
48 { "description", SIZE_OFFSET(comment) }, |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
49 { "albumtitle", SIZE_OFFSET(album) }, |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
50 { "date_written", SIZE_OFFSET(year) }, |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
51 { "date_released", SIZE_OFFSET(year) }, |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
52 { "tracknumber", SIZE_OFFSET(track) }, |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
53 { "part_number", SIZE_OFFSET(track) }, |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
54 }; |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
55 |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
56 void ff_metadata_demux_compat(AVFormatContext *ctx) |
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 AVMetadata *m; |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
59 int i, j; |
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 if ((m = ctx->metadata)) |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
62 for (j=0; j<m->count; j++) |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 if (*ptr) continue; |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
67 if (compat_tab[i].size > sizeof(int)) |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
68 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
|
69 else |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
70 *ptr = atoi(m->elems[j].value); |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
71 } |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
72 |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
73 for (i=0; i<ctx->nb_chapters; i++) |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
74 if ((m = ctx->chapters[i]->metadata)) |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
75 for (j=0; j<m->count; j++) |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
76 if (!strcasecmp(m->elems[j].key, "title")) { |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
77 av_free(ctx->chapters[i]->title); |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
78 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
|
79 } |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
80 |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
81 for (i=0; i<ctx->nb_programs; i++) |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
82 if ((m = ctx->programs[i]->metadata)) |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
83 for (j=0; j<m->count; j++) { |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
84 if (!strcasecmp(m->elems[j].key, "name")) { |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
85 av_free(ctx->programs[i]->name); |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
86 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
|
87 } |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
88 if (!strcasecmp(m->elems[j].key, "provider_name")) { |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
89 av_free(ctx->programs[i]->provider_name); |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
90 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
|
91 } |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
92 } |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
93 |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
94 for (i=0; i<ctx->nb_streams; i++) |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
95 if ((m = ctx->streams[i]->metadata)) |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
96 for (j=0; j<m->count; j++) { |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
97 if (!strcasecmp(m->elems[j].key, "language")) |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
98 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
|
99 if (!strcasecmp(m->elems[j].key, "filename")) { |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
100 av_free(ctx->streams[i]->filename); |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
101 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
|
102 } |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
103 } |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
104 } |
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
105 |
4180 | 106 |
107 #define FILL_METADATA(s, key, value) { \ | |
108 if (value && *value && \ | |
109 !av_metadata_get(s->metadata, #key, NULL, AV_METADATA_IGNORE_CASE)) \ | |
110 av_metadata_set(&s->metadata, (const AVMetadataTag){#key, value}); \ | |
111 } | |
112 #define FILL_METADATA_STR(s, key) FILL_METADATA(s, key, s->key) | |
113 #define FILL_METADATA_INT(s, key) { \ | |
114 char number[10]; \ | |
115 snprintf(number, sizeof(number), "%d", s->key); \ | |
116 if(s->key) FILL_METADATA(s, key, number) } | |
117 | |
4181
17a8a3696ee1
rename ff_metadata_sync_compat to ff_metadata_mux_compat
aurel
parents:
4180
diff
changeset
|
118 void ff_metadata_mux_compat(AVFormatContext *ctx) |
4180 | 119 { |
120 int i; | |
121 | |
122 FILL_METADATA_STR(ctx, title); | |
123 FILL_METADATA_STR(ctx, author); | |
124 FILL_METADATA_STR(ctx, copyright); | |
125 FILL_METADATA_STR(ctx, comment); | |
126 FILL_METADATA_STR(ctx, album); | |
127 FILL_METADATA_INT(ctx, year); | |
128 FILL_METADATA_INT(ctx, track); | |
129 FILL_METADATA_STR(ctx, genre); | |
130 for (i=0; i<ctx->nb_chapters; i++) | |
131 FILL_METADATA_STR(ctx->chapters[i], title); | |
132 for (i=0; i<ctx->nb_programs; i++) { | |
133 FILL_METADATA_STR(ctx->programs[i], name); | |
134 FILL_METADATA_STR(ctx->programs[i], provider_name); | |
135 } | |
136 for (i=0; i<ctx->nb_streams; i++) { | |
137 FILL_METADATA_STR(ctx->streams[i], language); | |
138 FILL_METADATA_STR(ctx->streams[i], filename); | |
139 } | |
140 } | |
141 | |
4179
c32a783ff374
Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff
changeset
|
142 #endif /* LIBAVFORMAT_VERSION_MAJOR < 53 */ |