Mercurial > libavformat.hg
annotate wv.c @ 5333:715913c5514f libavformat
Support 3xx redirection in rtsp
All the error codes 3xx got managed the same way.
After setup/early play redirection will not be managed
REDIRECT method is yet to be supported (if somebody knows a server implementing
it please contact me)
author | lu_zero |
---|---|
date | Sun, 25 Oct 2009 00:06:31 +0000 |
parents | e5c9ae62af86 |
children | d2cdd13aacff |
rev | line source |
---|---|
1324 | 1 /* |
2 * WavPack demuxer | |
4251
77e0c7511d41
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
4237
diff
changeset
|
3 * Copyright (c) 2006 Konstantin Shishkov |
1324 | 4 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1324
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1324
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1324
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
1324 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1324
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
1324 | 11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1324
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
1324 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1324
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
1324 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 */ | |
21 | |
4201
7d2f3f1b68d8
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
3908
diff
changeset
|
22 #include "libavutil/intreadwrite.h" |
1324 | 23 #include "avformat.h" |
5300 | 24 #include "apetag.h" |
25 #include "id3v1.h" | |
1324 | 26 |
27 // specs say that maximum block size is 1Mb | |
28 #define WV_BLOCK_LIMIT 1047576 | |
29 | |
30 #define WV_EXTRA_SIZE 12 | |
31 | |
32 enum WV_FLAGS{ | |
33 WV_MONO = 0x0004, | |
34 WV_HYBRID = 0x0008, | |
35 WV_JOINT = 0x0010, | |
36 WV_CROSSD = 0x0020, | |
37 WV_HSHAPE = 0x0040, | |
38 WV_FLOAT = 0x0080, | |
39 WV_INT32 = 0x0100, | |
40 WV_HBR = 0x0200, | |
41 WV_HBAL = 0x0400, | |
42 WV_MCINIT = 0x0800, | |
43 WV_MCEND = 0x1000, | |
44 }; | |
45 | |
46 static const int wv_rates[16] = { | |
47 6000, 8000, 9600, 11025, 12000, 16000, 22050, 24000, | |
48 32000, 44100, 48000, 64000, 88200, 96000, 192000, -1 | |
49 }; | |
50 | |
51 typedef struct{ | |
52 uint32_t blksize, flags; | |
53 int rate, chan, bpp; | |
1743 | 54 uint32_t samples, soff; |
1324 | 55 int block_parsed; |
56 uint8_t extra[WV_EXTRA_SIZE]; | |
1743 | 57 int64_t pos; |
1324 | 58 }WVContext; |
59 | |
60 static int wv_probe(AVProbeData *p) | |
61 { | |
62 /* check file header */ | |
63 if (p->buf_size <= 32) | |
64 return 0; | |
65 if (p->buf[0] == 'w' && p->buf[1] == 'v' && | |
66 p->buf[2] == 'p' && p->buf[3] == 'k') | |
67 return AVPROBE_SCORE_MAX; | |
68 else | |
69 return 0; | |
70 } | |
71 | |
72 static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb) | |
73 { | |
74 WVContext *wc = ctx->priv_data; | |
75 uint32_t tag, ver; | |
76 int size; | |
77 int rate, bpp, chan; | |
78 | |
1743 | 79 wc->pos = url_ftell(pb); |
1324 | 80 tag = get_le32(pb); |
81 if (tag != MKTAG('w', 'v', 'p', 'k')) | |
82 return -1; | |
83 size = get_le32(pb); | |
84 if(size < 24 || size > WV_BLOCK_LIMIT){ | |
85 av_log(ctx, AV_LOG_ERROR, "Incorrect block size %i\n", size); | |
86 return -1; | |
87 } | |
88 wc->blksize = size; | |
89 ver = get_le16(pb); | |
2380
41c9871ea3c4
Support for WavPack version 0x410 (false stereo chunks)
kostya
parents:
2314
diff
changeset
|
90 if(ver < 0x402 || ver > 0x410){ |
1324 | 91 av_log(ctx, AV_LOG_ERROR, "Unsupported version %03X\n", ver); |
92 return -1; | |
93 } | |
94 get_byte(pb); // track no | |
95 get_byte(pb); // track sub index | |
1743 | 96 wc->samples = get_le32(pb); // total samples in file |
97 wc->soff = get_le32(pb); // offset in samples of current block | |
1324 | 98 get_buffer(pb, wc->extra, WV_EXTRA_SIZE); |
1673 | 99 wc->flags = AV_RL32(wc->extra + 4); |
1324 | 100 //parse flags |
101 bpp = ((wc->flags & 3) + 1) << 3; | |
102 chan = 1 + !(wc->flags & WV_MONO); | |
103 rate = wv_rates[(wc->flags >> 23) & 0xF]; | |
104 if(rate == -1){ | |
105 av_log(ctx, AV_LOG_ERROR, "Unknown sampling rate\n"); | |
106 return -1; | |
107 } | |
108 if(!wc->bpp) wc->bpp = bpp; | |
109 if(!wc->chan) wc->chan = chan; | |
110 if(!wc->rate) wc->rate = rate; | |
111 | |
1389
9ed80abc8eb7
Ignore blocks with no samples and flags (but usually with MD5 sum)
kostya
parents:
1387
diff
changeset
|
112 if(wc->flags && bpp != wc->bpp){ |
1324 | 113 av_log(ctx, AV_LOG_ERROR, "Bits per sample differ, this block: %i, header block: %i\n", bpp, wc->bpp); |
114 return -1; | |
115 } | |
1389
9ed80abc8eb7
Ignore blocks with no samples and flags (but usually with MD5 sum)
kostya
parents:
1387
diff
changeset
|
116 if(wc->flags && chan != wc->chan){ |
1324 | 117 av_log(ctx, AV_LOG_ERROR, "Channels differ, this block: %i, header block: %i\n", chan, wc->chan); |
118 return -1; | |
119 } | |
1389
9ed80abc8eb7
Ignore blocks with no samples and flags (but usually with MD5 sum)
kostya
parents:
1387
diff
changeset
|
120 if(wc->flags && rate != wc->rate){ |
1324 | 121 av_log(ctx, AV_LOG_ERROR, "Sampling rate differ, this block: %i, header block: %i\n", rate, wc->rate); |
122 return -1; | |
123 } | |
124 wc->blksize = size - 24; | |
125 return 0; | |
126 } | |
127 | |
128 static int wv_read_header(AVFormatContext *s, | |
129 AVFormatParameters *ap) | |
130 { | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2555
diff
changeset
|
131 ByteIOContext *pb = s->pb; |
1324 | 132 WVContext *wc = s->priv_data; |
133 AVStream *st; | |
134 | |
135 if(wv_read_block_header(s, pb) < 0) | |
136 return -1; | |
137 | |
138 wc->block_parsed = 0; | |
139 /* now we are ready: build format streams */ | |
140 st = av_new_stream(s, 0); | |
141 if (!st) | |
142 return -1; | |
143 st->codec->codec_type = CODEC_TYPE_AUDIO; | |
144 st->codec->codec_id = CODEC_ID_WAVPACK; | |
145 st->codec->channels = wc->chan; | |
146 st->codec->sample_rate = wc->rate; | |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3482
diff
changeset
|
147 st->codec->bits_per_coded_sample = wc->bpp; |
1324 | 148 av_set_pts_info(st, 64, 1, wc->rate); |
1743 | 149 s->start_time = 0; |
150 s->duration = (int64_t)wc->samples * AV_TIME_BASE / st->codec->sample_rate; | |
5300 | 151 |
152 if(!url_is_streamed(s->pb)) { | |
153 int64_t cur = url_ftell(s->pb); | |
154 ff_ape_parse_tag(s); | |
155 if(!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) | |
156 ff_id3v1_read(s); | |
157 url_fseek(s->pb, cur, SEEK_SET); | |
158 } | |
159 | |
1324 | 160 return 0; |
161 } | |
162 | |
163 static int wv_read_packet(AVFormatContext *s, | |
164 AVPacket *pkt) | |
165 { | |
166 WVContext *wc = s->priv_data; | |
1391 | 167 int ret; |
1324 | 168 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2555
diff
changeset
|
169 if (url_feof(s->pb)) |
1787
eb16c64144ee
This fixes error handling for BeOS, removing the need for some ifdefs.
mmu_man
parents:
1743
diff
changeset
|
170 return AVERROR(EIO); |
1324 | 171 if(wc->block_parsed){ |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2555
diff
changeset
|
172 if(wv_read_block_header(s, s->pb) < 0) |
1324 | 173 return -1; |
174 } | |
175 | |
176 if(av_new_packet(pkt, wc->blksize + WV_EXTRA_SIZE) < 0) | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
1787
diff
changeset
|
177 return AVERROR(ENOMEM); |
1324 | 178 memcpy(pkt->data, wc->extra, WV_EXTRA_SIZE); |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2555
diff
changeset
|
179 ret = get_buffer(s->pb, pkt->data + WV_EXTRA_SIZE, wc->blksize); |
1324 | 180 if(ret != wc->blksize){ |
181 av_free_packet(pkt); | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
182 return AVERROR(EIO); |
1324 | 183 } |
184 pkt->stream_index = 0; | |
185 wc->block_parsed = 1; | |
186 pkt->size = ret + WV_EXTRA_SIZE; | |
1743 | 187 pkt->pts = wc->soff; |
188 av_add_index_entry(s->streams[0], wc->pos, pkt->pts, 0, 0, AVINDEX_KEYFRAME); | |
1324 | 189 return 0; |
190 } | |
191 | |
1743 | 192 static int wv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) |
193 { | |
194 AVStream *st = s->streams[stream_index]; | |
195 WVContext *wc = s->priv_data; | |
196 AVPacket pkt1, *pkt = &pkt1; | |
197 int ret; | |
198 int index = av_index_search_timestamp(st, timestamp, flags); | |
199 int64_t pos, pts; | |
200 | |
201 /* if found, seek there */ | |
202 if (index >= 0){ | |
203 wc->block_parsed = 1; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2555
diff
changeset
|
204 url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET); |
1743 | 205 return 0; |
206 } | |
207 /* if timestamp is out of bounds, return error */ | |
208 if(timestamp < 0 || timestamp >= s->duration) | |
209 return -1; | |
210 | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2555
diff
changeset
|
211 pos = url_ftell(s->pb); |
1743 | 212 do{ |
213 ret = av_read_frame(s, pkt); | |
214 if (ret < 0){ | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2555
diff
changeset
|
215 url_fseek(s->pb, pos, SEEK_SET); |
1743 | 216 return -1; |
217 } | |
218 pts = pkt->pts; | |
219 av_free_packet(pkt); | |
220 }while(pts < timestamp); | |
221 return 0; | |
222 } | |
223 | |
1324 | 224 AVInputFormat wv_demuxer = { |
225 "wv", | |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3286
diff
changeset
|
226 NULL_IF_CONFIG_SMALL("WavPack"), |
1324 | 227 sizeof(WVContext), |
228 wv_probe, | |
229 wv_read_header, | |
230 wv_read_packet, | |
3482 | 231 NULL, |
1743 | 232 wv_read_seek, |
1324 | 233 }; |