annotate metadata_compat.c @ 5507:5ebeb34e4456 libavformat

Use the correct ByteIOContext in extradata parsing.Fixes half of issue 1658.
author rbultje
date Fri, 08 Jan 2010 17:15:46 +0000
parents 8d5d5bcf76c9
children 27fd77f20a89
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
4204
66dacc060918 fix version protection
aurel
parents: 4181
diff changeset
26 #if LIBAVFORMAT_VERSION_MAJOR < 53
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) },
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
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
106
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
107 #define FILL_METADATA(s, key, value) { \
4250
2fc899894f5e replace AV_METADATA_IGNORE_CASE flag by a new AV_METADATA_MATCH_CASE flag
aurel
parents: 4204
diff changeset
108 if (value && *value && !av_metadata_get(s->metadata, #key, NULL, 0)) \
4353
e4a1b568b313 modify the way to pass parameters to av_metadata_set()
aurel
parents: 4250
diff changeset
109 av_metadata_set(&s->metadata, #key, value); \
4180
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
110 }
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
111 #define FILL_METADATA_STR(s, key) FILL_METADATA(s, key, s->key)
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
112 #define FILL_METADATA_INT(s, key) { \
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
113 char number[10]; \
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
114 snprintf(number, sizeof(number), "%d", s->key); \
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
115 if(s->key) FILL_METADATA(s, key, number) }
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
116
4181
17a8a3696ee1 rename ff_metadata_sync_compat to ff_metadata_mux_compat
aurel
parents: 4180
diff changeset
117 void ff_metadata_mux_compat(AVFormatContext *ctx)
4180
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
118 {
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
119 int i;
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
120
4583
8d5d5bcf76c9 don't trigger metadata compatibility code when user app already set metadata
aurel
parents: 4353
diff changeset
121 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
122 return;
8d5d5bcf76c9 don't trigger metadata compatibility code when user app already set metadata
aurel
parents: 4353
diff changeset
123
4180
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
124 FILL_METADATA_STR(ctx, title);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
125 FILL_METADATA_STR(ctx, author);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
126 FILL_METADATA_STR(ctx, copyright);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
127 FILL_METADATA_STR(ctx, comment);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
128 FILL_METADATA_STR(ctx, album);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
129 FILL_METADATA_INT(ctx, year);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
130 FILL_METADATA_INT(ctx, track);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
131 FILL_METADATA_STR(ctx, genre);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
132 for (i=0; i<ctx->nb_chapters; i++)
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
133 FILL_METADATA_STR(ctx->chapters[i], title);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
134 for (i=0; i<ctx->nb_programs; i++) {
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
135 FILL_METADATA_STR(ctx->programs[i], name);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
136 FILL_METADATA_STR(ctx->programs[i], provider_name);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
137 }
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
138 for (i=0; i<ctx->nb_streams; i++) {
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
139 FILL_METADATA_STR(ctx->streams[i], language);
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
140 FILL_METADATA_STR(ctx->streams[i], filename);
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 }
0df2e345a1a8 move ff_metadata_sync_compat to metadata_compat.c
aurel
parents: 4179
diff changeset
143
4179
c32a783ff374 Add a second metadata compatibility layer, so that metadata that gets
aurel
parents:
diff changeset
144 #endif /* LIBAVFORMAT_VERSION_MAJOR < 53 */