Mercurial > libavformat.hg
annotate wav.c @ 6365:c8ba3c854868 libavformat
Add documentation for the pm parameter of the av_metadata_set*
functions.
author | stefano |
---|---|
date | Wed, 11 Aug 2010 14:38:19 +0000 |
parents | 67c36f475c54 |
children | 4aaed59641ff |
rev | line source |
---|---|
885 | 1 /* |
1415
3b00fb8ef8e4
replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents:
1358
diff
changeset
|
2 * WAV muxer and demuxer |
4251
77e0c7511d41
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
4206
diff
changeset
|
3 * Copyright (c) 2001, 2002 Fabrice Bellard |
0 | 4 * |
5126 | 5 * Sony Wave64 demuxer |
5267 | 6 * RF64 demuxer |
5126 | 7 * Copyright (c) 2009 Daniel Verkamp |
8 * | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
9 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
10 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
11 * FFmpeg is free software; you can redistribute it and/or |
0 | 12 * modify it under the terms of the GNU Lesser General Public |
13 * 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:
1172
diff
changeset
|
14 * version 2.1 of the License, or (at your option) any later version. |
0 | 15 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1172
diff
changeset
|
16 * FFmpeg is distributed in the hope that it will be useful, |
0 | 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 * Lesser General Public License for more details. | |
20 * | |
21 * 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:
1172
diff
changeset
|
22 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
893
diff
changeset
|
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 24 */ |
25 #include "avformat.h" | |
2545
213268d7594e
move unrelated functions declarations out of allformats.h
aurel
parents:
2274
diff
changeset
|
26 #include "raw.h" |
1172
6a5e58d2114b
move common stuff from avienc.c and wav.c to new file riff.c
mru
parents:
1169
diff
changeset
|
27 #include "riff.h" |
0 | 28 |
29 typedef struct { | |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3934
diff
changeset
|
30 int64_t data; |
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3934
diff
changeset
|
31 int64_t data_end; |
1781 | 32 int64_t minpts; |
33 int64_t maxpts; | |
34 int last_duration; | |
5126 | 35 int w64; |
0 | 36 } WAVContext; |
37 | |
4206 | 38 #if CONFIG_WAV_MUXER |
0 | 39 static int wav_write_header(AVFormatContext *s) |
40 { | |
41 WAVContext *wav = s->priv_data; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2545
diff
changeset
|
42 ByteIOContext *pb = s->pb; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3934
diff
changeset
|
43 int64_t fmt, fact; |
0 | 44 |
45 put_tag(pb, "RIFF"); | |
46 put_le32(pb, 0); /* file length */ | |
47 put_tag(pb, "WAVE"); | |
48 | |
49 /* format header */ | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5001
diff
changeset
|
50 fmt = ff_start_tag(pb, "fmt "); |
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5001
diff
changeset
|
51 if (ff_put_wav_header(pb, s->streams[0]->codec) < 0) { |
3925 | 52 av_log(s, AV_LOG_ERROR, "%s codec not supported in WAVE format\n", |
3934 | 53 s->streams[0]->codec->codec ? s->streams[0]->codec->codec->name : "NONE"); |
0 | 54 av_free(wav); |
55 return -1; | |
56 } | |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5001
diff
changeset
|
57 ff_end_tag(pb, fmt); |
0 | 58 |
5127
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
59 if (s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */ |
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
60 && !url_is_streamed(s->pb)) { |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5001
diff
changeset
|
61 fact = ff_start_tag(pb, "fact"); |
1781 | 62 put_le32(pb, 0); |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5001
diff
changeset
|
63 ff_end_tag(pb, fact); |
1781 | 64 } |
65 | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
817
diff
changeset
|
66 av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); |
1781 | 67 wav->maxpts = wav->last_duration = 0; |
68 wav->minpts = INT64_MAX; | |
645
9fc2d2cc4608
wav timestamp truncation fix by (Wolfram Gloger <wmglo dent.med.uni-muenchen de>)
michael
parents:
587
diff
changeset
|
69 |
0 | 70 /* data header */ |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5001
diff
changeset
|
71 wav->data = ff_start_tag(pb, "data"); |
885 | 72 |
0 | 73 put_flush_packet(pb); |
74 | |
75 return 0; | |
76 } | |
77 | |
468 | 78 static int wav_write_packet(AVFormatContext *s, AVPacket *pkt) |
0 | 79 { |
5127
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
80 ByteIOContext *pb = s->pb; |
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
81 WAVContext *wav = s->priv_data; |
468 | 82 put_buffer(pb, pkt->data, pkt->size); |
1781 | 83 if(pkt->pts != AV_NOPTS_VALUE) { |
5127
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
84 wav->minpts = FFMIN(wav->minpts, pkt->pts); |
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
85 wav->maxpts = FFMAX(wav->maxpts, pkt->pts); |
1781 | 86 wav->last_duration = pkt->duration; |
87 } else | |
88 av_log(s, AV_LOG_ERROR, "wav_write_packet: NOPTS\n"); | |
0 | 89 return 0; |
90 } | |
91 | |
92 static int wav_write_trailer(AVFormatContext *s) | |
93 { | |
5127
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
94 ByteIOContext *pb = s->pb; |
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
95 WAVContext *wav = s->priv_data; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3934
diff
changeset
|
96 int64_t file_size; |
0 | 97 |
6334
67c36f475c54
In wav muxer, always flush in write_trailer, fix pipe output
bcoudurier
parents:
5649
diff
changeset
|
98 put_flush_packet(pb); |
67c36f475c54
In wav muxer, always flush in write_trailer, fix pipe output
bcoudurier
parents:
5649
diff
changeset
|
99 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2545
diff
changeset
|
100 if (!url_is_streamed(s->pb)) { |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5001
diff
changeset
|
101 ff_end_tag(pb, wav->data); |
0 | 102 |
103 /* update file size */ | |
104 file_size = url_ftell(pb); | |
105 url_fseek(pb, 4, SEEK_SET); | |
65 | 106 put_le32(pb, (uint32_t)(file_size - 8)); |
0 | 107 url_fseek(pb, file_size, SEEK_SET); |
108 | |
109 put_flush_packet(pb); | |
1781 | 110 |
111 if(s->streams[0]->codec->codec_tag != 0x01) { | |
112 /* Update num_samps in fact chunk */ | |
113 int number_of_samples; | |
114 number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration, | |
115 s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num, | |
116 s->streams[0]->time_base.den); | |
117 url_fseek(pb, wav->data-12, SEEK_SET); | |
118 put_le32(pb, number_of_samples); | |
119 url_fseek(pb, file_size, SEEK_SET); | |
120 put_flush_packet(pb); | |
121 } | |
0 | 122 } |
123 return 0; | |
124 } | |
5225
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
125 |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
126 AVOutputFormat wav_muxer = { |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
127 "wav", |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
128 NULL_IF_CONFIG_SMALL("WAV format"), |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
129 "audio/x-wav", |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
130 "wav", |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
131 sizeof(WAVContext), |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
132 CODEC_ID_PCM_S16LE, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
133 CODEC_ID_NONE, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
134 wav_write_header, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
135 wav_write_packet, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
136 wav_write_trailer, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
137 .codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0}, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
138 }; |
3871
e6aeb2733e34
Replace generic CONFIG_MUXERS preprocessor conditionals by more specific
diego
parents:
3766
diff
changeset
|
139 #endif /* CONFIG_WAV_MUXER */ |
0 | 140 |
5225
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
141 |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
142 #if CONFIG_WAV_DEMUXER |
0 | 143 /* return the size of the found tag */ |
5001
4da68099d180
Change find_tag return type to int64_t, fix a bug
bcoudurier
parents:
4251
diff
changeset
|
144 static int64_t find_tag(ByteIOContext *pb, uint32_t tag1) |
0 | 145 { |
146 unsigned int tag; | |
5001
4da68099d180
Change find_tag return type to int64_t, fix a bug
bcoudurier
parents:
4251
diff
changeset
|
147 int64_t size; |
0 | 148 |
5127
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
149 for (;;) { |
0 | 150 if (url_feof(pb)) |
151 return -1; | |
5127
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
152 tag = get_le32(pb); |
0 | 153 size = get_le32(pb); |
154 if (tag == tag1) | |
155 break; | |
156 url_fseek(pb, size, SEEK_CUR); | |
157 } | |
158 return size; | |
159 } | |
160 | |
161 static int wav_probe(AVProbeData *p) | |
162 { | |
163 /* check file header */ | |
164 if (p->buf_size <= 32) | |
165 return 0; | |
5267 | 166 if (!memcmp(p->buf + 8, "WAVE", 4)) { |
167 if (!memcmp(p->buf, "RIFF", 4)) | |
5268 | 168 /* |
169 Since ACT demuxer has standard WAV header at top of it's own, | |
170 returning score is decreased to avoid probe conflict | |
171 between ACT and WAV. | |
172 */ | |
173 return AVPROBE_SCORE_MAX - 1; | |
5267 | 174 else if (!memcmp(p->buf, "RF64", 4) && |
175 !memcmp(p->buf + 12, "ds64", 4)) | |
176 return AVPROBE_SCORE_MAX; | |
177 } | |
5268 | 178 return 0; |
0 | 179 } |
180 | |
181 /* wav input */ | |
182 static int wav_read_header(AVFormatContext *s, | |
183 AVFormatParameters *ap) | |
184 { | |
5267 | 185 int64_t size, av_uninit(data_size); |
186 int rf64; | |
0 | 187 unsigned int tag; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2545
diff
changeset
|
188 ByteIOContext *pb = s->pb; |
0 | 189 AVStream *st; |
1136
d65cd7c3573e
dont read over the end of a data chunk and at the end search for the next
michael
parents:
1122
diff
changeset
|
190 WAVContext *wav = s->priv_data; |
0 | 191 |
192 /* check RIFF header */ | |
193 tag = get_le32(pb); | |
194 | |
5267 | 195 rf64 = tag == MKTAG('R', 'F', '6', '4'); |
196 if (!rf64 && tag != MKTAG('R', 'I', 'F', 'F')) | |
0 | 197 return -1; |
198 get_le32(pb); /* file size */ | |
199 tag = get_le32(pb); | |
200 if (tag != MKTAG('W', 'A', 'V', 'E')) | |
201 return -1; | |
885 | 202 |
5267 | 203 if (rf64) { |
204 if (get_le32(pb) != MKTAG('d', 's', '6', '4')) | |
205 return -1; | |
206 size = get_le32(pb); | |
207 if (size < 16) | |
208 return -1; | |
209 get_le64(pb); /* RIFF size */ | |
210 data_size = get_le64(pb); | |
211 url_fskip(pb, size - 16); /* skip rest of ds64 chunk */ | |
212 } | |
213 | |
0 | 214 /* parse fmt header */ |
215 size = find_tag(pb, MKTAG('f', 'm', 't', ' ')); | |
216 if (size < 0) | |
217 return -1; | |
218 st = av_new_stream(s, 0); | |
219 if (!st) | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2023
diff
changeset
|
220 return AVERROR(ENOMEM); |
0 | 221 |
5058
33a244b7ca65
Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents:
5001
diff
changeset
|
222 ff_get_wav_header(pb, st->codec, size); |
2023 | 223 st->need_parsing = AVSTREAM_PARSE_FULL; |
567 | 224 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
817
diff
changeset
|
225 av_set_pts_info(st, 64, 1, st->codec->sample_rate); |
567 | 226 |
0 | 227 size = find_tag(pb, MKTAG('d', 'a', 't', 'a')); |
5267 | 228 if (rf64) |
229 size = data_size; | |
0 | 230 if (size < 0) |
231 return -1; | |
5648 | 232 if (!size) { |
233 wav->data_end = INT64_MAX; | |
234 } else | |
5649 | 235 wav->data_end= url_ftell(pb) + size; |
0 | 236 return 0; |
237 } | |
238 | |
5126 | 239 /** Find chunk with w64 GUID by skipping over other chunks |
240 * @return the size of the found chunk | |
241 */ | |
242 static int64_t find_guid(ByteIOContext *pb, const uint8_t guid1[16]) | |
243 { | |
244 uint8_t guid[16]; | |
245 int64_t size; | |
246 | |
247 while (!url_feof(pb)) { | |
248 get_buffer(pb, guid, 16); | |
249 size = get_le64(pb); | |
250 if (size <= 24) | |
251 return -1; | |
252 if (!memcmp(guid, guid1, 16)) | |
253 return size; | |
254 url_fskip(pb, FFALIGN(size, INT64_C(8)) - 24); | |
255 } | |
256 return -1; | |
257 } | |
258 | |
5224
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
259 static const uint8_t guid_data[16] = { 'd', 'a', 't', 'a', |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
260 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A }; |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
261 |
5225
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
262 #define MAX_SIZE 4096 |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
263 |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
264 static int wav_read_packet(AVFormatContext *s, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
265 AVPacket *pkt) |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
266 { |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
267 int ret, size; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
268 int64_t left; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
269 AVStream *st; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
270 WAVContext *wav = s->priv_data; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
271 |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
272 st = s->streams[0]; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
273 |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
274 left = wav->data_end - url_ftell(s->pb); |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
275 if (left <= 0){ |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
276 if (CONFIG_W64_DEMUXER && wav->w64) |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
277 left = find_guid(s->pb, guid_data) - 24; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
278 else |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
279 left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a')); |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
280 if (left < 0) |
5259
1c4c83a0fd96
wav demuxer: return AVERROR_EOF instead of AVERROR(EIO) when the end of
reimar
parents:
5258
diff
changeset
|
281 return AVERROR_EOF; |
5225
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
282 wav->data_end= url_ftell(s->pb) + left; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
283 } |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
284 |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
285 size = MAX_SIZE; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
286 if (st->codec->block_align > 1) { |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
287 if (size < st->codec->block_align) |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
288 size = st->codec->block_align; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
289 size = (size / st->codec->block_align) * st->codec->block_align; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
290 } |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
291 size = FFMIN(size, left); |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
292 ret = av_get_packet(s->pb, pkt, size); |
5258 | 293 if (ret < 0) |
294 return ret; | |
5225
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
295 pkt->stream_index = 0; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
296 |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
297 return ret; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
298 } |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
299 |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
300 static int wav_read_seek(AVFormatContext *s, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
301 int stream_index, int64_t timestamp, int flags) |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
302 { |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
303 AVStream *st; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
304 |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
305 st = s->streams[0]; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
306 switch (st->codec->codec_id) { |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
307 case CODEC_ID_MP2: |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
308 case CODEC_ID_MP3: |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
309 case CODEC_ID_AC3: |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
310 case CODEC_ID_DTS: |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
311 /* use generic seeking with dynamically generated indexes */ |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
312 return -1; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
313 default: |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
314 break; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
315 } |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
316 return pcm_read_seek(s, stream_index, timestamp, flags); |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
317 } |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
318 |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
319 AVInputFormat wav_demuxer = { |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
320 "wav", |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
321 NULL_IF_CONFIG_SMALL("WAV format"), |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
322 sizeof(WAVContext), |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
323 wav_probe, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
324 wav_read_header, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
325 wav_read_packet, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
326 NULL, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
327 wav_read_seek, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
328 .flags= AVFMT_GENERIC_INDEX, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
329 .codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0}, |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
330 }; |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
331 #endif /* CONFIG_WAV_DEMUXER */ |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
332 |
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
333 |
5224
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
334 #if CONFIG_W64_DEMUXER |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
335 static const uint8_t guid_riff[16] = { 'r', 'i', 'f', 'f', |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
336 0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00 }; |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
337 |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
338 static const uint8_t guid_wave[16] = { 'w', 'a', 'v', 'e', |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
339 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A }; |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
340 |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
341 static const uint8_t guid_fmt [16] = { 'f', 'm', 't', ' ', |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
342 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A }; |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
343 |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
344 static int w64_probe(AVProbeData *p) |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
345 { |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
346 if (p->buf_size <= 40) |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
347 return 0; |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
348 if (!memcmp(p->buf, guid_riff, 16) && |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
349 !memcmp(p->buf + 24, guid_wave, 16)) |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
350 return AVPROBE_SCORE_MAX; |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
351 else |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
352 return 0; |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
353 } |
c2881eee05b7
Move find_guid function and guid_data array to a globally available place.
diego
parents:
5127
diff
changeset
|
354 |
5126 | 355 static int w64_read_header(AVFormatContext *s, AVFormatParameters *ap) |
356 { | |
357 int64_t size; | |
5127
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
358 ByteIOContext *pb = s->pb; |
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
359 WAVContext *wav = s->priv_data; |
5126 | 360 AVStream *st; |
361 uint8_t guid[16]; | |
362 | |
363 get_buffer(pb, guid, 16); | |
364 if (memcmp(guid, guid_riff, 16)) | |
365 return -1; | |
366 | |
367 if (get_le64(pb) < 16 + 8 + 16 + 8 + 16 + 8) /* riff + wave + fmt + sizes */ | |
368 return -1; | |
369 | |
370 get_buffer(pb, guid, 16); | |
371 if (memcmp(guid, guid_wave, 16)) { | |
372 av_log(s, AV_LOG_ERROR, "could not find wave guid\n"); | |
373 return -1; | |
374 } | |
375 | |
376 size = find_guid(pb, guid_fmt); | |
377 if (size < 0) { | |
378 av_log(s, AV_LOG_ERROR, "could not find fmt guid\n"); | |
379 return -1; | |
380 } | |
381 | |
382 st = av_new_stream(s, 0); | |
383 if (!st) | |
384 return AVERROR(ENOMEM); | |
385 | |
386 /* subtract chunk header size - normal wav file doesn't count it */ | |
387 ff_get_wav_header(pb, st->codec, size - 24); | |
388 url_fskip(pb, FFALIGN(size, INT64_C(8)) - size); | |
389 | |
390 st->need_parsing = AVSTREAM_PARSE_FULL; | |
391 | |
392 av_set_pts_info(st, 64, 1, st->codec->sample_rate); | |
393 | |
394 size = find_guid(pb, guid_data); | |
395 if (size < 0) { | |
396 av_log(s, AV_LOG_ERROR, "could not find data guid\n"); | |
397 return -1; | |
398 } | |
399 wav->data_end = url_ftell(pb) + size - 24; | |
5127
e73c5f33463b
cosmetics: whitespace, prettyprinting, coding style fixes
diego
parents:
5126
diff
changeset
|
400 wav->w64 = 1; |
5126 | 401 |
402 return 0; | |
403 } | |
404 | |
405 AVInputFormat w64_demuxer = { | |
406 "w64", | |
407 NULL_IF_CONFIG_SMALL("Sony Wave64 format"), | |
408 sizeof(WAVContext), | |
409 w64_probe, | |
410 w64_read_header, | |
411 wav_read_packet, | |
412 NULL, | |
413 wav_read_seek, | |
414 .flags = AVFMT_GENERIC_INDEX, | |
415 .codec_tag = (const AVCodecTag* const []){ff_codec_wav_tags, 0}, | |
416 }; | |
5225
117ab940d1b9
Rearrange wav_muxer and {wav|w64}_demuxer blocks to be under proper #ifdefs.
diego
parents:
5224
diff
changeset
|
417 #endif /* CONFIG_W64_DEMUXER */ |