Mercurial > libavformat.hg
annotate apetag.c @ 5402:99aeb2e385df libavformat
Full-header RTMP packets contain real timestamp, others contain timestamp
difference, so make all read packets store absolute timestamp.
As a consequence, we don't need to track audio/video timestamps separately
any longer in protocol handler.
author | kostya |
---|---|
date | Tue, 01 Dec 2009 16:08:44 +0000 |
parents | 08c073da6553 |
children | 4211f91f69b1 |
rev | line source |
---|---|
2548 | 1 /* |
5134 | 2 * APE tag handling |
2548 | 3 * Copyright (c) 2007 Benjamin Zores <ben@geexbox.org> |
4 * based upon libdemac from Dave Chapman. | |
5 * | |
6 * This file is part of FFmpeg. | |
7 * | |
8 * FFmpeg is free software; you can redistribute it and/or | |
9 * modify it under the terms of the GNU Lesser General Public | |
10 * License as published by the Free Software Foundation; either | |
11 * version 2.1 of the License, or (at your option) any later version. | |
12 * | |
13 * FFmpeg is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
19 * License along with FFmpeg; if not, write to the Free Software | |
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
21 */ | |
22 | |
4201
7d2f3f1b68d8
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
3908
diff
changeset
|
23 #include "libavutil/intreadwrite.h" |
2548 | 24 #include "avformat.h" |
25 | |
2556
cb131102b256
disable loads of debug messages to reduce object size
aurel
parents:
2554
diff
changeset
|
26 #define ENABLE_DEBUG 0 |
cb131102b256
disable loads of debug messages to reduce object size
aurel
parents:
2554
diff
changeset
|
27 |
2554 | 28 #define APE_TAG_VERSION 2000 |
29 #define APE_TAG_FOOTER_BYTES 32 | |
30 #define APE_TAG_FLAG_CONTAINS_HEADER (1 << 31) | |
31 #define APE_TAG_FLAG_IS_HEADER (1 << 29) | |
32 | |
5133
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
33 static int ape_tag_read_field(AVFormatContext *s) |
2554 | 34 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2568
diff
changeset
|
35 ByteIOContext *pb = s->pb; |
4517 | 36 uint8_t key[1024], value[1024]; |
5133
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
37 uint32_t size, flags; |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
38 int i, l, c; |
2554 | 39 |
40 size = get_le32(pb); /* field size */ | |
5133
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
41 flags = get_le32(pb); /* field flags */ |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
42 for (i = 0; i < sizeof(key) - 1; i++) { |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
43 c = get_byte(pb); |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
44 if (c < 0x20 || c > 0x7E) |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
45 break; |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
46 else |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
47 key[i] = c; |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
48 } |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
49 key[i] = 0; |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
50 if (c != 0) { |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
51 av_log(s, AV_LOG_WARNING, "Invalid APE tag key '%s'.\n", key); |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
52 return -1; |
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
53 } |
4517 | 54 l = FFMIN(size, sizeof(value)-1); |
55 get_buffer(pb, value, l); | |
56 value[l] = 0; | |
57 url_fskip(pb, size-l); | |
4521
51119f565c6c
apedec: display a warning when truncating a metadata tag
aurel
parents:
4517
diff
changeset
|
58 if (l < size) |
51119f565c6c
apedec: display a warning when truncating a metadata tag
aurel
parents:
4517
diff
changeset
|
59 av_log(s, AV_LOG_WARNING, "Too long '%s' tag was truncated.\n", key); |
4517 | 60 av_metadata_set(&s->metadata, key, value); |
5133
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
61 return 0; |
2554 | 62 } |
63 | |
5134 | 64 void ff_ape_parse_tag(AVFormatContext *s) |
2554 | 65 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2568
diff
changeset
|
66 ByteIOContext *pb = s->pb; |
2554 | 67 int file_size = url_fsize(pb); |
68 uint32_t val, fields, tag_bytes; | |
69 uint8_t buf[8]; | |
70 int i; | |
71 | |
72 if (file_size < APE_TAG_FOOTER_BYTES) | |
73 return; | |
74 | |
75 url_fseek(pb, file_size - APE_TAG_FOOTER_BYTES, SEEK_SET); | |
76 | |
77 get_buffer(pb, buf, 8); /* APETAGEX */ | |
78 if (strncmp(buf, "APETAGEX", 8)) { | |
79 return; | |
80 } | |
81 | |
82 val = get_le32(pb); /* APE tag version */ | |
83 if (val > APE_TAG_VERSION) { | |
4506
dfb8f047b552
Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents:
4201
diff
changeset
|
84 av_log(s, AV_LOG_ERROR, "Unsupported tag version. (>=%d)\n", APE_TAG_VERSION); |
2554 | 85 return; |
86 } | |
87 | |
88 tag_bytes = get_le32(pb); /* tag size */ | |
89 if (tag_bytes - APE_TAG_FOOTER_BYTES > (1024 * 1024 * 16)) { | |
4506
dfb8f047b552
Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents:
4201
diff
changeset
|
90 av_log(s, AV_LOG_ERROR, "Tag size is way too big\n"); |
2554 | 91 return; |
92 } | |
93 | |
94 fields = get_le32(pb); /* number of fields */ | |
95 if (fields > 65536) { | |
4506
dfb8f047b552
Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents:
4201
diff
changeset
|
96 av_log(s, AV_LOG_ERROR, "Too many tag fields (%d)\n", fields); |
2554 | 97 return; |
98 } | |
99 | |
100 val = get_le32(pb); /* flags */ | |
101 if (val & APE_TAG_FLAG_IS_HEADER) { | |
4506
dfb8f047b552
Add a context to av_log() calls and extend ape_dumpinfo prototype to do that.
benoit
parents:
4201
diff
changeset
|
102 av_log(s, AV_LOG_ERROR, "APE Tag is a header\n"); |
2554 | 103 return; |
104 } | |
105 | |
106 url_fseek(pb, file_size - tag_bytes, SEEK_SET); | |
107 | |
108 for (i=0; i<fields; i++) | |
5133
1df917933244
Do not use internals of ByteIOContext during APE tags parsing.
kostya
parents:
5132
diff
changeset
|
109 if (ape_tag_read_field(s) < 0) break; |
2554 | 110 } |