| 361 | } |
| 362 | |
| 363 | static int msmpeg4_decode_picture_header(H263DecContext *const h) |
| 364 | { |
| 365 | MSMP4DecContext *const ms = mpv_to_msmpeg4(h); |
| 366 | int code; |
| 367 | |
| 368 | // at minimum one bit per macroblock is required at least in a valid frame, |
| 369 | // we discard frames much smaller than this. Frames smaller than 1/8 of the |
| 370 | // smallest "black/skip" frame generally contain not much recoverable content |
| 371 | // while at the same time they have the highest computational requirements |
| 372 | // per byte |
| 373 | if (get_bits_left(&h->gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16)) |
| 374 | return AVERROR_INVALIDDATA; |
| 375 | |
| 376 | if (h->c.msmpeg4_version == MSMP4_V1) { |
| 377 | int start_code = get_bits_long(&h->gb, 32); |
| 378 | if(start_code!=0x00000100){ |
| 379 | av_log(h->c.avctx, AV_LOG_ERROR, "invalid startcode\n"); |
| 380 | return -1; |
| 381 | } |
| 382 | |
| 383 | skip_bits(&h->gb, 5); // frame number */ |
| 384 | } |
| 385 | |
| 386 | h->c.pict_type = get_bits(&h->gb, 2) + 1; |
| 387 | if (h->c.pict_type != AV_PICTURE_TYPE_I && |
| 388 | h->c.pict_type != AV_PICTURE_TYPE_P){ |
| 389 | av_log(h->c.avctx, AV_LOG_ERROR, "invalid picture type\n"); |
| 390 | return -1; |
| 391 | } |
| 392 | h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5); |
| 393 | if (h->c.qscale == 0) { |
| 394 | av_log(h->c.avctx, AV_LOG_ERROR, "invalid qscale\n"); |
| 395 | return -1; |
| 396 | } |
| 397 | |
| 398 | if (h->c.pict_type == AV_PICTURE_TYPE_I) { |
| 399 | code = get_bits(&h->gb, 5); |
| 400 | if (h->c.msmpeg4_version == MSMP4_V1) { |
| 401 | if(code==0 || code>h->c.mb_height) { |
| 402 | av_log(h->c.avctx, AV_LOG_ERROR, "invalid slice height %d\n", code); |
| 403 | return -1; |
| 404 | } |
| 405 | |
| 406 | h->slice_height = code; |
| 407 | }else{ |
| 408 | /* 0x17: one slice, 0x18: two slices, ... */ |
| 409 | if (code < 0x17){ |
| 410 | av_log(h->c.avctx, AV_LOG_ERROR, "error, slice code was %X\n", code); |
| 411 | return -1; |
| 412 | } |
| 413 | |
| 414 | h->slice_height = h->c.mb_height / (code - 0x16); |
| 415 | } |
| 416 | |
| 417 | switch (h->c.msmpeg4_version) { |
| 418 | case MSMP4_V1: |
| 419 | case MSMP4_V2: |
| 420 | ms->rl_chroma_table_index = 2; |
nothing calls this directly
no test coverage detected