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