Mercurial > libavcodec.hg
comparison ac3dec.c @ 11049:e26ea20d293a libavcodec
Simplify error handling by processing header errors separate from CRC and
buffer size vs. frame size errors.
| author | jbr |
|---|---|
| date | Thu, 28 Jan 2010 23:19:33 +0000 |
| parents | 621268959a5c |
| children | 444f4b594fdb |
comparison
equal
deleted
inserted
replaced
| 11048:9db9a81cc220 | 11049:e26ea20d293a |
|---|---|
| 1234 | 1234 |
| 1235 /* parse the syncinfo */ | 1235 /* parse the syncinfo */ |
| 1236 *data_size = 0; | 1236 *data_size = 0; |
| 1237 err = parse_frame_header(s); | 1237 err = parse_frame_header(s); |
| 1238 | 1238 |
| 1239 /* check that reported frame size fits in input buffer */ | 1239 if (err) { |
| 1240 if(!err && s->frame_size > buf_size) { | |
| 1241 av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); | |
| 1242 err = AAC_AC3_PARSE_ERROR_FRAME_SIZE; | |
| 1243 } | |
| 1244 | |
| 1245 /* check for crc mismatch */ | |
| 1246 if(err != AAC_AC3_PARSE_ERROR_FRAME_SIZE && avctx->error_recognition >= FF_ER_CAREFUL) { | |
| 1247 if(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], s->frame_size-2)) { | |
| 1248 av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n"); | |
| 1249 err = AAC_AC3_PARSE_ERROR_CRC; | |
| 1250 } | |
| 1251 } | |
| 1252 | |
| 1253 if(err && err != AAC_AC3_PARSE_ERROR_CRC) { | |
| 1254 switch(err) { | 1240 switch(err) { |
| 1255 case AAC_AC3_PARSE_ERROR_SYNC: | 1241 case AAC_AC3_PARSE_ERROR_SYNC: |
| 1256 av_log(avctx, AV_LOG_ERROR, "frame sync error\n"); | 1242 av_log(avctx, AV_LOG_ERROR, "frame sync error\n"); |
| 1257 return -1; | 1243 return -1; |
| 1258 case AAC_AC3_PARSE_ERROR_BSID: | 1244 case AAC_AC3_PARSE_ERROR_BSID: |
| 1276 break; | 1262 break; |
| 1277 default: | 1263 default: |
| 1278 av_log(avctx, AV_LOG_ERROR, "invalid header\n"); | 1264 av_log(avctx, AV_LOG_ERROR, "invalid header\n"); |
| 1279 break; | 1265 break; |
| 1280 } | 1266 } |
| 1267 } else { | |
| 1268 /* check that reported frame size fits in input buffer */ | |
| 1269 if (s->frame_size > buf_size) { | |
| 1270 av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); | |
| 1271 err = AAC_AC3_PARSE_ERROR_FRAME_SIZE; | |
| 1272 } else if (avctx->error_recognition >= FF_ER_CAREFUL) { | |
| 1273 /* check for crc mismatch */ | |
| 1274 if (av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], s->frame_size-2)) { | |
| 1275 av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n"); | |
| 1276 err = AAC_AC3_PARSE_ERROR_CRC; | |
| 1277 } | |
| 1278 } | |
| 1281 } | 1279 } |
| 1282 | 1280 |
| 1283 /* if frame is ok, set audio parameters */ | 1281 /* if frame is ok, set audio parameters */ |
| 1284 if (!err) { | 1282 if (!err) { |
| 1285 avctx->sample_rate = s->sample_rate; | 1283 avctx->sample_rate = s->sample_rate; |
