* Decode a slice. * Mpeg12SliceContext.c.mb_y must be set to the MB row from the startcode. * @return DECODE_SLICE_ERROR if the slice is damaged, * DECODE_SLICE_OK if this slice is OK */
| 1357 | * DECODE_SLICE_OK if this slice is OK |
| 1358 | */ |
| 1359 | static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y, |
| 1360 | const uint8_t **buf, int buf_size) |
| 1361 | { |
| 1362 | AVCodecContext *avctx = s->c.avctx; |
| 1363 | const int lowres = s->c.avctx->lowres; |
| 1364 | const int field_pic = s->c.picture_structure != PICT_FRAME; |
| 1365 | int ret; |
| 1366 | |
| 1367 | s->c.resync_mb_x = |
| 1368 | s->c.resync_mb_y = -1; |
| 1369 | |
| 1370 | av_assert0(mb_y < s->c.mb_height); |
| 1371 | |
| 1372 | ret = init_get_bits8(&s->gb, *buf, buf_size); |
| 1373 | if (ret < 0) |
| 1374 | return ret; |
| 1375 | |
| 1376 | if (s->c.codec_id != AV_CODEC_ID_MPEG1VIDEO && s->c.mb_height > 2800/16) |
| 1377 | skip_bits(&s->gb, 3); |
| 1378 | |
| 1379 | s->c.interlaced_dct = 0; |
| 1380 | |
| 1381 | s->c.qscale = mpeg_get_qscale(&s->gb, s->c.q_scale_type); |
| 1382 | |
| 1383 | if (s->c.qscale == 0) { |
| 1384 | av_log(s->c.avctx, AV_LOG_ERROR, "qscale == 0\n"); |
| 1385 | return AVERROR_INVALIDDATA; |
| 1386 | } |
| 1387 | |
| 1388 | /* extra slice info */ |
| 1389 | if (skip_1stop_8data_bits(&s->gb) < 0) |
| 1390 | return AVERROR_INVALIDDATA; |
| 1391 | |
| 1392 | s->c.mb_x = 0; |
| 1393 | |
| 1394 | if (mb_y == 0 && s->c.codec_tag == AV_RL32("SLIF")) { |
| 1395 | skip_bits1(&s->gb); |
| 1396 | } else { |
| 1397 | while (get_bits_left(&s->gb) > 0) { |
| 1398 | int code = get_vlc2(&s->gb, ff_mbincr_vlc, |
| 1399 | MBINCR_VLC_BITS, 2); |
| 1400 | if (code < 0) { |
| 1401 | av_log(s->c.avctx, AV_LOG_ERROR, "first mb_incr damaged\n"); |
| 1402 | return AVERROR_INVALIDDATA; |
| 1403 | } |
| 1404 | if (code >= 33) { |
| 1405 | if (code == 33) |
| 1406 | s->c.mb_x += 33; |
| 1407 | /* otherwise, stuffing, nothing to do */ |
| 1408 | } else { |
| 1409 | s->c.mb_x += code; |
| 1410 | break; |
| 1411 | } |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | if (s->c.mb_x >= (unsigned) s->c.mb_width) { |
| 1416 | av_log(s->c.avctx, AV_LOG_ERROR, "initial skip overflow\n"); |
no test coverage detected