annotate wav.c @ 3795:ccddbe22fa8f libavformat

speex in flv demuxing
author bcoudurier
date Fri, 29 Aug 2008 17:06:35 +0000
parents f062deeedb8d
children e6aeb2733e34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 874
diff changeset
1 /*
1415
3b00fb8ef8e4 replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents: 1358
diff changeset
2 * WAV muxer and demuxer
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2001, 2002 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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: 1172
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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: 1172
diff changeset
18 * 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
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include "avformat.h"
2545
213268d7594e move unrelated functions declarations out of allformats.h
aurel
parents: 2274
diff changeset
22 #include "raw.h"
1172
6a5e58d2114b move common stuff from avienc.c and wav.c to new file riff.c
mru
parents: 1169
diff changeset
23 #include "riff.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 offset_t data;
1136
d65cd7c3573e dont read over the end of a data chunk and at the end search for the next
michael
parents: 1122
diff changeset
27 offset_t data_end;
1781
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
28 int64_t minpts;
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
29 int64_t maxpts;
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
30 int last_duration;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 } WAVContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32
1149
02e10bcc0e0d Fix compilation with --disable-muxers.
diego
parents: 1142
diff changeset
33 #ifdef CONFIG_MUXERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 static int wav_write_header(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 WAVContext *wav = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
37 ByteIOContext *pb = s->pb;
1781
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
38 offset_t fmt, fact;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 put_tag(pb, "RIFF");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 put_le32(pb, 0); /* file length */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 put_tag(pb, "WAVE");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 /* format header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 fmt = start_tag(pb, "fmt ");
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 817
diff changeset
46 if (put_wav_header(pb, s->streams[0]->codec) < 0) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 av_free(wav);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 end_tag(pb, fmt);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51
1781
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
52 if(s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
53 && !url_is_streamed(s->pb)) {
1781
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
54 fact = start_tag(pb, "fact");
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
55 put_le32(pb, 0);
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
56 end_tag(pb, fact);
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
57 }
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
58
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 817
diff changeset
59 av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
1781
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
60 wav->maxpts = wav->last_duration = 0;
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
61 wav->minpts = INT64_MAX;
645
9fc2d2cc4608 wav timestamp truncation fix by (Wolfram Gloger <wmglo dent.med.uni-muenchen de>)
michael
parents: 587
diff changeset
62
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 /* data header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 wav->data = start_tag(pb, "data");
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 874
diff changeset
65
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 put_flush_packet(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 413
diff changeset
71 static int wav_write_packet(AVFormatContext *s, AVPacket *pkt)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
73 ByteIOContext *pb = s->pb;
1781
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
74 WAVContext *wav = s->priv_data;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 413
diff changeset
75 put_buffer(pb, pkt->data, pkt->size);
1781
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
76 if(pkt->pts != AV_NOPTS_VALUE) {
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
77 wav->minpts = FFMIN(wav->minpts, pkt->pts);
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
78 wav->maxpts = FFMAX(wav->maxpts, pkt->pts);
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
79 wav->last_duration = pkt->duration;
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
80 } else
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
81 av_log(s, AV_LOG_ERROR, "wav_write_packet: NOPTS\n");
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 static int wav_write_trailer(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
87 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 WAVContext *wav = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 offset_t file_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
91 if (!url_is_streamed(s->pb)) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 end_tag(pb, wav->data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 /* update file size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 file_size = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 url_fseek(pb, 4, SEEK_SET);
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
97 put_le32(pb, (uint32_t)(file_size - 8));
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 url_fseek(pb, file_size, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 put_flush_packet(pb);
1781
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
101
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
102 if(s->streams[0]->codec->codec_tag != 0x01) {
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
103 /* Update num_samps in fact chunk */
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
104 int number_of_samples;
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
105 number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration,
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
106 s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num,
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
107 s->streams[0]->time_base.den);
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
108 url_fseek(pb, wav->data-12, SEEK_SET);
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
109 put_le32(pb, number_of_samples);
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
110 url_fseek(pb, file_size, SEEK_SET);
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
111 put_flush_packet(pb);
ce4617062f7b Add FACT chunk for non-PCM wav formats
mbardiaux
parents: 1756
diff changeset
112 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 }
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 846
diff changeset
116 #endif //CONFIG_MUXERS
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 /* return the size of the found tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 /* XXX: > 2GB ? */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
120 static int find_tag(ByteIOContext *pb, uint32_t tag1)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 unsigned int tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 int size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 if (url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 tag = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 size = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 if (tag == tag1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 url_fseek(pb, size, SEEK_CUR);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 if (size < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 size = 0x7fffffff;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 return size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 static int wav_probe(AVProbeData *p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 /* check file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 if (p->buf_size <= 32)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 if (p->buf[0] == 'R' && p->buf[1] == 'I' &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 p->buf[2] == 'F' && p->buf[3] == 'F' &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 p->buf[8] == 'W' && p->buf[9] == 'A' &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 p->buf[10] == 'V' && p->buf[11] == 'E')
3233
e2bdb989f7da Decrease returning probe score for WAV demuxer to avoid
voroshil
parents: 2771
diff changeset
148 /*
e2bdb989f7da Decrease returning probe score for WAV demuxer to avoid
voroshil
parents: 2771
diff changeset
149 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
150 returning score is decreased to avoid probe conflict
e2bdb989f7da Decrease returning probe score for WAV demuxer to avoid
voroshil
parents: 2771
diff changeset
151 between ACT and WAV.
e2bdb989f7da Decrease returning probe score for WAV demuxer to avoid
voroshil
parents: 2771
diff changeset
152 */
e2bdb989f7da Decrease returning probe score for WAV demuxer to avoid
voroshil
parents: 2771
diff changeset
153 return AVPROBE_SCORE_MAX - 1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 /* wav input */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 static int wav_read_header(AVFormatContext *s,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 int size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 unsigned int tag;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
164 ByteIOContext *pb = s->pb;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 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
166 WAVContext *wav = s->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 /* check RIFF header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 tag = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 if (tag != MKTAG('R', 'I', 'F', 'F'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 get_le32(pb); /* file size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 tag = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 if (tag != MKTAG('W', 'A', 'V', 'E'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 return -1;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 874
diff changeset
177
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 /* parse fmt header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 size = find_tag(pb, MKTAG('f', 'm', 't', ' '));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 if (size < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 st = av_new_stream(s, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2023
diff changeset
184 return AVERROR(ENOMEM);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 817
diff changeset
186 get_wav_header(pb, st->codec, size);
2023
a3e79d6e4e3c add an enum for need_parsing
aurel
parents: 1781
diff changeset
187 st->need_parsing = AVSTREAM_PARSE_FULL;
567
23b915bb10f5 set correct timebase
michael
parents: 564
diff changeset
188
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 817
diff changeset
189 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
567
23b915bb10f5 set correct timebase
michael
parents: 564
diff changeset
190
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 size = find_tag(pb, MKTAG('d', 'a', 't', 'a'));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 if (size < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 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
194 wav->data_end= url_ftell(pb) + size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 #define MAX_SIZE 4096
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 static int wav_read_packet(AVFormatContext *s,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 {
1136
d65cd7c3573e dont read over the end of a data chunk and at the end search for the next
michael
parents: 1122
diff changeset
203 int ret, size, left;
309
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
204 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
205 WAVContext *wav = s->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
207 if (url_feof(s->pb))
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
208 return AVERROR(EIO);
309
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
209 st = s->streams[0];
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
210
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
211 left= wav->data_end - url_ftell(s->pb);
1136
d65cd7c3573e dont read over the end of a data chunk and at the end search for the next
michael
parents: 1122
diff changeset
212 if(left <= 0){
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
213 left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a'));
1136
d65cd7c3573e dont read over the end of a data chunk and at the end search for the next
michael
parents: 1122
diff changeset
214 if (left < 0) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
215 return AVERROR(EIO);
1136
d65cd7c3573e dont read over the end of a data chunk and at the end search for the next
michael
parents: 1122
diff changeset
216 }
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
217 wav->data_end= url_ftell(s->pb) + left;
1136
d65cd7c3573e dont read over the end of a data chunk and at the end search for the next
michael
parents: 1122
diff changeset
218 }
d65cd7c3573e dont read over the end of a data chunk and at the end search for the next
michael
parents: 1122
diff changeset
219
309
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
220 size = MAX_SIZE;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 817
diff changeset
221 if (st->codec->block_align > 1) {
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 817
diff changeset
222 if (size < st->codec->block_align)
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 817
diff changeset
223 size = st->codec->block_align;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 817
diff changeset
224 size = (size / st->codec->block_align) * st->codec->block_align;
309
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
225 }
1136
d65cd7c3573e dont read over the end of a data chunk and at the end search for the next
michael
parents: 1122
diff changeset
226 size= FFMIN(size, left);
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
227 ret= av_get_packet(s->pb, pkt, size);
1756
5d72afc6c8aa better generic index building and seeking code
michael
parents: 1679
diff changeset
228 if (ret <= 0)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
229 return AVERROR(EIO);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 pkt->stream_index = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 /* note: we need to modify the packet size here to handle the last
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 packet */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 pkt->size = ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 874
diff changeset
238 static int wav_read_seek(AVFormatContext *s,
558
89bd76208427 100l (forgoten seeking functions)
michael
parents: 550
diff changeset
239 int stream_index, int64_t timestamp, int flags)
309
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
240 {
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
241 AVStream *st;
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
242
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
243 st = s->streams[0];
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 817
diff changeset
244 switch(st->codec->codec_id) {
309
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
245 case CODEC_ID_MP2:
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
246 case CODEC_ID_MP3:
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
247 case CODEC_ID_AC3:
496
112057e05179 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents: 482
diff changeset
248 case CODEC_ID_DTS:
309
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
249 /* use generic seeking with dynamically generated indexes */
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
250 return -1;
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
251 default:
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
252 break;
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
253 }
558
89bd76208427 100l (forgoten seeking functions)
michael
parents: 550
diff changeset
254 return pcm_read_seek(s, stream_index, timestamp, flags);
309
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
255 }
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
256
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
257 #ifdef CONFIG_WAV_DEMUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
258 AVInputFormat wav_demuxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 "wav",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3233
diff changeset
260 NULL_IF_CONFIG_SMALL("WAV format"),
1136
d65cd7c3573e dont read over the end of a data chunk and at the end search for the next
michael
parents: 1122
diff changeset
261 sizeof(WAVContext),
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 wav_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 wav_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 wav_read_packet,
3484
31a0f3b99ef7 remove useless close funcs
bcoudurier
parents: 3424
diff changeset
265 NULL,
309
6c9fddf8458c seeking support - fixed some ADPCM decoding cases
bellard
parents: 277
diff changeset
266 wav_read_seek,
1756
5d72afc6c8aa better generic index building and seeking code
michael
parents: 1679
diff changeset
267 .flags= AVFMT_GENERIC_INDEX,
3766
f062deeedb8d Change codec_tag type from const struct AVCodecTag ** to const struct AVCodecTag * const *
reimar
parents: 3484
diff changeset
268 .codec_tag= (const AVCodecTag* const []){codec_wav_tags, 0},
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
270 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
271 #ifdef CONFIG_WAV_MUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
272 AVOutputFormat wav_muxer = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 "wav",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3233
diff changeset
274 NULL_IF_CONFIG_SMALL("WAV format"),
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 "audio/x-wav",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 "wav",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 sizeof(WAVContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 CODEC_ID_PCM_S16LE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 CODEC_ID_NONE,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 wav_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 wav_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 wav_write_trailer,
3766
f062deeedb8d Change codec_tag type from const struct AVCodecTag ** to const struct AVCodecTag * const *
reimar
parents: 3484
diff changeset
283 .codec_tag= (const AVCodecTag* const []){codec_wav_tags, 0},
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
285 #endif