| 184 | } |
| 185 | |
| 186 | static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header_size) |
| 187 | { |
| 188 | GetBitContext hb; |
| 189 | int len; |
| 190 | int chunk_size; |
| 191 | short wave_format; |
| 192 | |
| 193 | init_get_bits(&hb, header, header_size*8); |
| 194 | if (get_le32(&hb) != MKTAG('R','I','F','F')) { |
| 195 | av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n"); |
| 196 | return -1; |
| 197 | } |
| 198 | |
| 199 | chunk_size = get_le32(&hb); |
| 200 | |
| 201 | if (get_le32(&hb) != MKTAG('W','A','V','E')) { |
| 202 | av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n"); |
| 203 | return -1; |
| 204 | } |
| 205 | |
| 206 | while (get_le32(&hb) != MKTAG('f','m','t',' ')) { |
| 207 | len = get_le32(&hb); |
| 208 | skip_bits(&hb, 8*len); |
| 209 | } |
| 210 | len = get_le32(&hb); |
| 211 | |
| 212 | if (len < 16) { |
| 213 | av_log(avctx, AV_LOG_ERROR, "fmt chunk was too short\n"); |
| 214 | return -1; |
| 215 | } |
| 216 | |
| 217 | wave_format = get_le16(&hb); |
| 218 | |
| 219 | switch (wave_format) { |
| 220 | case WAVE_FORMAT_PCM: |
| 221 | break; |
| 222 | default: |
| 223 | av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n"); |
| 224 | return -1; |
| 225 | } |
| 226 | |
| 227 | avctx->channels = get_le16(&hb); |
| 228 | avctx->sample_rate = get_le32(&hb); |
| 229 | avctx->bit_rate = get_le32(&hb) * 8; |
| 230 | avctx->block_align = get_le16(&hb); |
| 231 | avctx->bits_per_coded_sample = get_le16(&hb); |
| 232 | |
| 233 | if (avctx->bits_per_coded_sample != 16) { |
| 234 | av_log(avctx, AV_LOG_ERROR, "unsupported number of bits per sample\n"); |
| 235 | return -1; |
| 236 | } |
| 237 | |
| 238 | len -= 16; |
| 239 | if (len > 0) |
| 240 | av_log(avctx, AV_LOG_INFO, "%d header bytes unparsed\n", len); |
| 241 | |
| 242 | return 0; |
| 243 | } |
no test coverage detected