History

ff_put_wav_header: remove manual byte counting

Daniel Verkamp committed 12 years ago

Commit cf3fccc1 parent 7c8bf091 file · +3 −7Browse files

Unified · Split

libavformat/riffenc.c+3−7
@@ -54,7 +54,8 @@ void ff_end_tag(AVIOContext *pb, int64_t start) · 53 unmodified lines
5454 int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
5555 {
5656 int bps, blkalign, bytespersec, frame_size;
57− int hdrsize = 18;
57+ int hdrsize;
58+ int64_t hdrstart = avio_tell(pb);
5859 int waveformatextensible;
5960 uint8_t temp[256];
6061 uint8_t *riff_extradata = temp;
@@ -135,14 +136,12 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) · 74 unmodified lines
135136 avio_wl16(pb, blkalign); /* block align */
136137 avio_wl16(pb, bps); /* bits per sample */
137138 if (enc->codec_id == AV_CODEC_ID_MP3) {
138− hdrsize += 12;
139139 bytestream_put_le16(&riff_extradata, 1); /* wID */
140140 bytestream_put_le32(&riff_extradata, 2); /* fdwFlags */
141141 bytestream_put_le16(&riff_extradata, 1152); /* nBlockSize */
142142 bytestream_put_le16(&riff_extradata, 1); /* nFramesPerBlock */
143143 bytestream_put_le16(&riff_extradata, 1393); /* nCodecDelay */
144144 } else if (enc->codec_id == AV_CODEC_ID_MP2) {
145− hdrsize += 22;
146145 /* fwHeadLayer */
147146 bytestream_put_le16(&riff_extradata, 2);
148147 /* dwHeadBitrate */
@@ -160,23 +159,19 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) · 11 unmodified lines
160159 /* dwPTSHigh */
161160 bytestream_put_le32(&riff_extradata, 0);
162161 } else if (enc->codec_id == AV_CODEC_ID_G723_1) {
163− hdrsize += 20;
164162 bytestream_put_le32(&riff_extradata, 0x9ace0002); /* extradata needed for msacm g723.1 codec */
165163 bytestream_put_le32(&riff_extradata, 0xaea2f732);
166164 bytestream_put_le16(&riff_extradata, 0xacde);
167165 } else if (enc->codec_id == AV_CODEC_ID_GSM_MS ||
168166 enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) {
169− hdrsize += 2;
170167 /* wSamplesPerBlock */
171168 bytestream_put_le16(&riff_extradata, frame_size);
172169 } else if (enc->extradata_size) {
173170 riff_extradata_start = enc->extradata;
174171 riff_extradata = enc->extradata + enc->extradata_size;
175− hdrsize += enc->extradata_size;
176172 }
177173 /* write WAVEFORMATEXTENSIBLE extensions */
178174 if (waveformatextensible) {
179− hdrsize += 22;
180175 /* 22 is WAVEFORMATEXTENSIBLE size */
181176 avio_wl16(pb, riff_extradata - riff_extradata_start + 22);
182177 /* ValidBitsPerSample || SamplesPerBlock || Reserved */
@@ -196,6 +191,7 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) · 13 unmodified lines
196191 avio_wl16(pb, riff_extradata - riff_extradata_start); /* cbSize */
197192 }
198193 avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start);
194+ hdrsize = avio_tell(pb) - hdrstart;
199195 if (hdrsize & 1) {
200196 hdrsize++;
201197 avio_w8(pb, 0);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t