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
54int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)54int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc)
55{55{
56 int bps, blkalign, bytespersec, frame_size;56 int bps, blkalign, bytespersec, frame_size;
57 int hdrsize = 18;57 int hdrsize;
58 int64_t hdrstart = avio_tell(pb);
58 int waveformatextensible;59 int waveformatextensible;
59 uint8_t temp[256];60 uint8_t temp[256];
60 uint8_t *riff_extradata = temp;61 uint8_t *riff_extradata = temp;
@@ -135,14 +136,12 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) · 74 unmodified lines
135 avio_wl16(pb, blkalign); /* block align */136 avio_wl16(pb, blkalign); /* block align */
136 avio_wl16(pb, bps); /* bits per sample */137 avio_wl16(pb, bps); /* bits per sample */
137 if (enc->codec_id == AV_CODEC_ID_MP3) {138 if (enc->codec_id == AV_CODEC_ID_MP3) {
138 hdrsize += 12;
139 bytestream_put_le16(&riff_extradata, 1); /* wID */139 bytestream_put_le16(&riff_extradata, 1); /* wID */
140 bytestream_put_le32(&riff_extradata, 2); /* fdwFlags */140 bytestream_put_le32(&riff_extradata, 2); /* fdwFlags */
141 bytestream_put_le16(&riff_extradata, 1152); /* nBlockSize */141 bytestream_put_le16(&riff_extradata, 1152); /* nBlockSize */
142 bytestream_put_le16(&riff_extradata, 1); /* nFramesPerBlock */142 bytestream_put_le16(&riff_extradata, 1); /* nFramesPerBlock */
143 bytestream_put_le16(&riff_extradata, 1393); /* nCodecDelay */143 bytestream_put_le16(&riff_extradata, 1393); /* nCodecDelay */
144 } else if (enc->codec_id == AV_CODEC_ID_MP2) {144 } else if (enc->codec_id == AV_CODEC_ID_MP2) {
145 hdrsize += 22;
146 /* fwHeadLayer */145 /* fwHeadLayer */
147 bytestream_put_le16(&riff_extradata, 2);146 bytestream_put_le16(&riff_extradata, 2);
148 /* dwHeadBitrate */147 /* dwHeadBitrate */
@@ -160,23 +159,19 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) · 11 unmodified lines
160 /* dwPTSHigh */159 /* dwPTSHigh */
161 bytestream_put_le32(&riff_extradata, 0);160 bytestream_put_le32(&riff_extradata, 0);
162 } else if (enc->codec_id == AV_CODEC_ID_G723_1) {161 } else if (enc->codec_id == AV_CODEC_ID_G723_1) {
163 hdrsize += 20;
164 bytestream_put_le32(&riff_extradata, 0x9ace0002); /* extradata needed for msacm g723.1 codec */162 bytestream_put_le32(&riff_extradata, 0x9ace0002); /* extradata needed for msacm g723.1 codec */
165 bytestream_put_le32(&riff_extradata, 0xaea2f732);163 bytestream_put_le32(&riff_extradata, 0xaea2f732);
166 bytestream_put_le16(&riff_extradata, 0xacde);164 bytestream_put_le16(&riff_extradata, 0xacde);
167 } else if (enc->codec_id == AV_CODEC_ID_GSM_MS ||165 } else if (enc->codec_id == AV_CODEC_ID_GSM_MS ||
168 enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) {166 enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) {
169 hdrsize += 2;
170 /* wSamplesPerBlock */167 /* wSamplesPerBlock */
171 bytestream_put_le16(&riff_extradata, frame_size);168 bytestream_put_le16(&riff_extradata, frame_size);
172 } else if (enc->extradata_size) {169 } else if (enc->extradata_size) {
173 riff_extradata_start = enc->extradata;170 riff_extradata_start = enc->extradata;
174 riff_extradata = enc->extradata + enc->extradata_size;171 riff_extradata = enc->extradata + enc->extradata_size;
175 hdrsize += enc->extradata_size;
176 }172 }
177 /* write WAVEFORMATEXTENSIBLE extensions */173 /* write WAVEFORMATEXTENSIBLE extensions */
178 if (waveformatextensible) {174 if (waveformatextensible) {
179 hdrsize += 22;
180 /* 22 is WAVEFORMATEXTENSIBLE size */175 /* 22 is WAVEFORMATEXTENSIBLE size */
181 avio_wl16(pb, riff_extradata - riff_extradata_start + 22);176 avio_wl16(pb, riff_extradata - riff_extradata_start + 22);
182 /* ValidBitsPerSample || SamplesPerBlock || Reserved */177 /* ValidBitsPerSample || SamplesPerBlock || Reserved */
@@ -196,6 +191,7 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) · 13 unmodified lines
196 avio_wl16(pb, riff_extradata - riff_extradata_start); /* cbSize */191 avio_wl16(pb, riff_extradata - riff_extradata_start); /* cbSize */
197 }192 }
198 avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start);193 avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start);
194 hdrsize = avio_tell(pb) - hdrstart;
199 if (hdrsize & 1) {195 if (hdrsize & 1) {
200 hdrsize++;196 hdrsize++;
201 avio_w8(pb, 0);197 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