annotate metadata.c @ 5194:ead0d47f2fb7 libavformat

Make probing for VC1 test bitstream format stricter
author kostya
date Tue, 15 Sep 2009 15:22:36 +0000
parents 1874d71f6b19
children c6028d6c93b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4150
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
1 /*
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
2 * copyright (c) 2009 Michael Niedermayer
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
3 *
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
4 * This file is part of FFmpeg.
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
5 *
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
10 *
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
14 * Lesser General Public License for more details.
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
15 *
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
19 */
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
20
4617
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
21 #include <strings.h>
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
22 #include "avformat.h"
4150
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
23 #include "metadata.h"
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
24
4154
bd4d3fee45d0 rename AVMetaData to AVMetadata and meta_data to metadata
aurel
parents: 4150
diff changeset
25 AVMetadataTag *
4157
017e68062073 add a typedef for AVMetadata
aurel
parents: 4154
diff changeset
26 av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags)
4150
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
27 {
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
28 unsigned int i, j;
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
29
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
30 if(!m)
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
31 return NULL;
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
32
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
33 if(prev) i= prev - m->elems + 1;
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
34 else i= 0;
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
35
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
36 for(; i<m->count; i++){
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
37 const char *s= m->elems[i].key;
4250
2fc899894f5e replace AV_METADATA_IGNORE_CASE flag by a new AV_METADATA_MATCH_CASE flag
aurel
parents: 4180
diff changeset
38 if(flags & AV_METADATA_MATCH_CASE) for(j=0; s[j] == key[j] && key[j]; j++);
2fc899894f5e replace AV_METADATA_IGNORE_CASE flag by a new AV_METADATA_MATCH_CASE flag
aurel
parents: 4180
diff changeset
39 else for(j=0; toupper(s[j]) == toupper(key[j]) && key[j]; j++);
4150
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
40 if(key[j])
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
41 continue;
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
42 if(s[j] && !(flags & AV_METADATA_IGNORE_SUFFIX))
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
43 continue;
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
44 return &m->elems[i];
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
45 }
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
46 return NULL;
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
47 }
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
48
4353
e4a1b568b313 modify the way to pass parameters to av_metadata_set()
aurel
parents: 4250
diff changeset
49 int av_metadata_set(AVMetadata **pm, const char *key, const char *value)
4150
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
50 {
4157
017e68062073 add a typedef for AVMetadata
aurel
parents: 4154
diff changeset
51 AVMetadata *m= *pm;
4353
e4a1b568b313 modify the way to pass parameters to av_metadata_set()
aurel
parents: 4250
diff changeset
52 AVMetadataTag *tag= av_metadata_get(m, key, NULL, AV_METADATA_MATCH_CASE);
4150
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
53
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
54 if(!m)
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
55 m=*pm= av_mallocz(sizeof(*m));
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
56
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
57 if(tag){
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
58 av_free(tag->value);
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
59 av_free(tag->key);
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
60 *tag= m->elems[--m->count];
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
61 }else{
4154
bd4d3fee45d0 rename AVMetaData to AVMetadata and meta_data to metadata
aurel
parents: 4150
diff changeset
62 AVMetadataTag *tmp= av_realloc(m->elems, (m->count+1) * sizeof(*m->elems));
4150
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
63 if(tmp){
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
64 m->elems= tmp;
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
65 }else
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
66 return AVERROR(ENOMEM);
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
67 }
4353
e4a1b568b313 modify the way to pass parameters to av_metadata_set()
aurel
parents: 4250
diff changeset
68 if(value){
e4a1b568b313 modify the way to pass parameters to av_metadata_set()
aurel
parents: 4250
diff changeset
69 m->elems[m->count].key = av_strdup(key );
e4a1b568b313 modify the way to pass parameters to av_metadata_set()
aurel
parents: 4250
diff changeset
70 m->elems[m->count].value= av_strdup(value);
e4a1b568b313 modify the way to pass parameters to av_metadata_set()
aurel
parents: 4250
diff changeset
71 m->count++;
4150
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
72 }
4591
e62a61d3e591 fix a memleak in av_metadata_set()
aurel
parents: 4353
diff changeset
73 if(!m->count) {
e62a61d3e591 fix a memleak in av_metadata_set()
aurel
parents: 4353
diff changeset
74 av_free(m->elems);
4150
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
75 av_freep(pm);
4591
e62a61d3e591 fix a memleak in av_metadata_set()
aurel
parents: 4353
diff changeset
76 }
4150
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
77
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
78 return 0;
6f4c0d5f1e23 Move metadata API from avcodec to avformat.
michael
parents:
diff changeset
79 }
4158
ea1e24175669 Add a metadata compatibility layer, so that when a user application set
aurel
parents: 4157
diff changeset
80
4161
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
81 void av_metadata_free(AVMetadata **pm)
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
82 {
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
83 AVMetadata *m= *pm;
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
84
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
85 if(m){
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
86 while(m->count--){
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
87 av_free(m->elems[m->count].key);
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
88 av_free(m->elems[m->count].value);
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
89 }
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
90 av_free(m->elems);
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
91 }
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
92 av_freep(pm);
6a7275621c02 free all allocated metadata structures
aurel
parents: 4159
diff changeset
93 }
4617
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
94
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
95 static void metadata_conv(AVMetadata **pm, const AVMetadataConv *d_conv,
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
96 const AVMetadataConv *s_conv)
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
97 {
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
98 /* TODO: use binary search to look up the two conversion tables
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
99 if the tables are getting big enough that it would matter speed wise */
4621
1874d71f6b19 simplify metadata conversion and fixes gcc-2.95 at the same time
aurel
parents: 4617
diff changeset
100 const AVMetadataConv *sc, *dc;
4617
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
101 AVMetadataTag *mtag = NULL;
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
102 AVMetadata *dst = NULL;
4621
1874d71f6b19 simplify metadata conversion and fixes gcc-2.95 at the same time
aurel
parents: 4617
diff changeset
103 const char *key;
4617
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
104
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
105 while((mtag=av_metadata_get(*pm, "", mtag, AV_METADATA_IGNORE_SUFFIX))) {
4621
1874d71f6b19 simplify metadata conversion and fixes gcc-2.95 at the same time
aurel
parents: 4617
diff changeset
106 key = mtag->key;
4617
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
107 if (s_conv != d_conv) {
4621
1874d71f6b19 simplify metadata conversion and fixes gcc-2.95 at the same time
aurel
parents: 4617
diff changeset
108 if (s_conv)
1874d71f6b19 simplify metadata conversion and fixes gcc-2.95 at the same time
aurel
parents: 4617
diff changeset
109 for (sc=s_conv; sc->native; sc++)
4617
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
110 if (!strcasecmp(key, sc->native)) {
4621
1874d71f6b19 simplify metadata conversion and fixes gcc-2.95 at the same time
aurel
parents: 4617
diff changeset
111 key = sc->generic;
4617
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
112 break;
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
113 }
4621
1874d71f6b19 simplify metadata conversion and fixes gcc-2.95 at the same time
aurel
parents: 4617
diff changeset
114 if (d_conv)
1874d71f6b19 simplify metadata conversion and fixes gcc-2.95 at the same time
aurel
parents: 4617
diff changeset
115 for (dc=d_conv; dc->native; dc++)
1874d71f6b19 simplify metadata conversion and fixes gcc-2.95 at the same time
aurel
parents: 4617
diff changeset
116 if (!strcasecmp(key, dc->generic)) {
4617
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
117 key = dc->native;
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
118 break;
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
119 }
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
120 }
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
121 av_metadata_set(&dst, key, mtag->value);
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
122 }
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
123 av_metadata_free(pm);
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
124 *pm = dst;
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
125 }
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
126
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
127 void av_metadata_conv(AVFormatContext *ctx, const AVMetadataConv *d_conv,
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
128 const AVMetadataConv *s_conv)
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
129 {
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
130 int i;
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
131 metadata_conv(&ctx->metadata, d_conv, s_conv);
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
132 for (i=0; i<ctx->nb_streams ; i++)
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
133 metadata_conv(&ctx->streams [i]->metadata, d_conv, s_conv);
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
134 for (i=0; i<ctx->nb_chapters; i++)
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
135 metadata_conv(&ctx->chapters[i]->metadata, d_conv, s_conv);
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
136 for (i=0; i<ctx->nb_programs; i++)
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
137 metadata_conv(&ctx->programs[i]->metadata, d_conv, s_conv);
f04bc8b70940 add a metadata conversion API
aurel
parents: 4591
diff changeset
138 }