comparison wmadec.c @ 964:6e6773512288 libavcodec

oops : better error resilience - should fix most wma decoding problems
author bellard
date Mon, 06 Jan 2003 22:47:42 +0000
parents ae89deb3a97d
children 19419cb268fe
comparison
equal deleted inserted replaced
963:1936a177d482 964:6e6773512288
1238 if (s->last_superframe_len > 0) { 1238 if (s->last_superframe_len > 0) {
1239 // printf("skip=%d\n", s->last_bitoffset); 1239 // printf("skip=%d\n", s->last_bitoffset);
1240 /* add bit_offset bits to last frame */ 1240 /* add bit_offset bits to last frame */
1241 if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) > 1241 if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) >
1242 MAX_CODED_SUPERFRAME_SIZE) 1242 MAX_CODED_SUPERFRAME_SIZE)
1243 return -1; 1243 goto fail;
1244 q = s->last_superframe + s->last_superframe_len; 1244 q = s->last_superframe + s->last_superframe_len;
1245 len = bit_offset; 1245 len = bit_offset;
1246 while (len > 0) { 1246 while (len > 0) {
1247 *q++ = (get_bits)(&s->gb, 8); 1247 *q++ = (get_bits)(&s->gb, 8);
1248 len -= 8; 1248 len -= 8;
1257 if (s->last_bitoffset > 0) 1257 if (s->last_bitoffset > 0)
1258 skip_bits(&s->gb, s->last_bitoffset); 1258 skip_bits(&s->gb, s->last_bitoffset);
1259 /* this frame is stored in the last superframe and in the 1259 /* this frame is stored in the last superframe and in the
1260 current one */ 1260 current one */
1261 if (wma_decode_frame(s, samples) < 0) 1261 if (wma_decode_frame(s, samples) < 0)
1262 return -1; 1262 goto fail;
1263 samples += s->nb_channels * s->frame_len; 1263 samples += s->nb_channels * s->frame_len;
1264 } 1264 }
1265 1265
1266 /* read each frame starting from bit_offset */ 1266 /* read each frame starting from bit_offset */
1267 pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3; 1267 pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
1271 skip_bits(&s->gb, len); 1271 skip_bits(&s->gb, len);
1272 1272
1273 s->reset_block_lengths = 1; 1273 s->reset_block_lengths = 1;
1274 for(i=0;i<nb_frames;i++) { 1274 for(i=0;i<nb_frames;i++) {
1275 if (wma_decode_frame(s, samples) < 0) 1275 if (wma_decode_frame(s, samples) < 0)
1276 return -1; 1276 goto fail;
1277 samples += s->nb_channels * s->frame_len; 1277 samples += s->nb_channels * s->frame_len;
1278 } 1278 }
1279 1279
1280 /* we copy the end of the frame in the last frame buffer */ 1280 /* we copy the end of the frame in the last frame buffer */
1281 pos = get_bits_count(&s->gb) + ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7); 1281 pos = get_bits_count(&s->gb) + ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7);
1282 s->last_bitoffset = pos & 7; 1282 s->last_bitoffset = pos & 7;
1283 pos >>= 3; 1283 pos >>= 3;
1284 len = buf_size - pos; 1284 len = buf_size - pos;
1285 if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) { 1285 if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) {
1286 return -1; 1286 goto fail;
1287 } 1287 }
1288 s->last_superframe_len = len; 1288 s->last_superframe_len = len;
1289 memcpy(s->last_superframe, buf + pos, len); 1289 memcpy(s->last_superframe, buf + pos, len);
1290 } else { 1290 } else {
1291 /* single frame decode */ 1291 /* single frame decode */
1292 if (wma_decode_frame(s, samples) < 0) 1292 if (wma_decode_frame(s, samples) < 0)
1293 return -1; 1293 goto fail;
1294 samples += s->nb_channels * s->frame_len; 1294 samples += s->nb_channels * s->frame_len;
1295 } 1295 }
1296 *data_size = (int8_t *)samples - (int8_t *)data; 1296 *data_size = (int8_t *)samples - (int8_t *)data;
1297 return s->block_align; 1297 return s->block_align;
1298 fail:
1299 /* when error, we reset the bit reservoir */
1300 s->last_superframe_len = 0;
1301 return -1;
1298 } 1302 }
1299 1303
1300 static int wma_decode_end(AVCodecContext *avctx) 1304 static int wma_decode_end(AVCodecContext *avctx)
1301 { 1305 {
1302 WMADecodeContext *s = avctx->priv_data; 1306 WMADecodeContext *s = avctx->priv_data;