| @@ -3278,116 +3278,279 @@ static void vc1_decode_blocks(VC1Context *v) · 3277 unmodified lines |
| 3278 | 3278 | } |
| 3279 | 3279 | } |
| 3280 | 3280 | |
| 3281 | | −static inline float get_float_val(GetBitContext* gb) |
| 3281 | +#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER |
| 3282 | + |
| 3283 | +typedef struct { |
| 3284 | + /** |
| 3285 | + * Transform coefficients for both sprites in 16.16 fixed point format, |
| 3286 | + * in the order they appear in the bitstream: |
| 3287 | + * x scale |
| 3288 | + * rotation 1 (unused) |
| 3289 | + * x offset |
| 3290 | + * rotation 2 (unused) |
| 3291 | + * y scale |
| 3292 | + * y offset |
| 3293 | + * alpha |
| 3294 | + */ |
| 3295 | + int coefs[2][7]; |
| 3296 | + |
| 3297 | + int effect_type, effect_flag; |
| 3298 | + int effect_pcount1, effect_pcount2; ///< amount of effect parameters stored in effect_params |
| 3299 | + int effect_params1[15], effect_params2[10]; ///< effect parameters in 16.16 fixed point format |
| 3300 | +} SpriteData; |
| 3301 | + |
| 3302 | +static inline int get_fp_val(GetBitContext* gb) |
| 3282 | 3303 | { |
| 3283 | | − return (float)get_bits_long(gb, 30) / (1<<15) - (1<<14); |
| 3304 | + return (get_bits_long(gb, 30) - (1<<29)) << 1; |
| 3284 | 3305 | } |
| 3285 | 3306 | |
| 3286 | | −static void vc1_sprite_parse_transform(VC1Context *v, GetBitContext* gb, float c[7]) |
| 3307 | +static void vc1_sprite_parse_transform(GetBitContext* gb, int c[7]) |
| 3287 | 3308 | { |
| 3288 | | − c[1] = c[3] = 0.0f; |
| 3309 | + c[1] = c[3] = 0; |
| 3289 | 3310 | |
| 3290 | 3311 | switch (get_bits(gb, 2)) { |
| 3291 | 3312 | case 0: |
| 3292 | | − c[0] = 1.0f; |
| 3293 | | − c[2] = get_float_val(gb); |
| 3294 | | − c[4] = 1.0f; |
| 3313 | + c[0] = 1<<16; |
| 3314 | + c[2] = get_fp_val(gb); |
| 3315 | + c[4] = 1<<16; |
| 3295 | 3316 | break; |
| 3296 | 3317 | case 1: |
| 3297 | | − c[0] = c[4] = get_float_val(gb); |
| 3298 | | − c[2] = get_float_val(gb); |
| 3318 | + c[0] = c[4] = get_fp_val(gb); |
| 3319 | + c[2] = get_fp_val(gb); |
| 3299 | 3320 | break; |
| 3300 | 3321 | case 2: |
| 3301 | | − c[0] = get_float_val(gb); |
| 3302 | | − c[2] = get_float_val(gb); |
| 3303 | | − c[4] = get_float_val(gb); |
| 3322 | + c[0] = get_fp_val(gb); |
| 3323 | + c[2] = get_fp_val(gb); |
| 3324 | + c[4] = get_fp_val(gb); |
| 3304 | 3325 | break; |
| 3305 | 3326 | case 3: |
| 3306 | | − av_log_ask_for_sample(v->s.avctx, NULL); |
| 3307 | | − c[0] = get_float_val(gb); |
| 3308 | | − c[1] = get_float_val(gb); |
| 3309 | | − c[2] = get_float_val(gb); |
| 3310 | | − c[3] = get_float_val(gb); |
| 3311 | | − c[4] = get_float_val(gb); |
| 3327 | + c[0] = get_fp_val(gb); |
| 3328 | + c[1] = get_fp_val(gb); |
| 3329 | + c[2] = get_fp_val(gb); |
| 3330 | + c[3] = get_fp_val(gb); |
| 3331 | + c[4] = get_fp_val(gb); |
| 3312 | 3332 | break; |
| 3313 | 3333 | } |
| 3314 | | − c[5] = get_float_val(gb); |
| 3334 | + c[5] = get_fp_val(gb); |
| 3315 | 3335 | if (get_bits1(gb)) |
| 3316 | | − c[6] = get_float_val(gb); |
| 3336 | + c[6] = get_fp_val(gb); |
| 3317 | 3337 | else |
| 3318 | | − c[6] = 1.0f; |
| 3338 | + c[6] = 1<<16; |
| 3319 | 3339 | } |
| 3320 | 3340 | |
| 3321 | | −static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb) |
| 3341 | +static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb, SpriteData* sd) |
| 3322 | 3342 | { |
| 3323 | | − int effect_type, effect_flag, effect_pcount1, effect_pcount2, i; |
| 3324 | | − float effect_params1[14], effect_params2[10]; |
| 3325 | | − |
| 3326 | | − float coefs[2][7]; |
| 3327 | | − vc1_sprite_parse_transform(v, gb, coefs[0]); |
| 3328 | | − av_log(v->s.avctx, AV_LOG_DEBUG, "S1:"); |
| 3329 | | − for (i = 0; i < 7; i++) |
| 3330 | | − av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", coefs[0][i]); |
| 3331 | | − av_log(v->s.avctx, AV_LOG_DEBUG, "\n"); |
| 3332 | | − |
| 3333 | | − if (v->two_sprites) { |
| 3334 | | − vc1_sprite_parse_transform(v, gb, coefs[1]); |
| 3335 | | − av_log(v->s.avctx, AV_LOG_DEBUG, "S2:"); |
| 3343 | + AVCodecContext *avctx = v->s.avctx; |
| 3344 | + int sprite, i; |
| 3345 | + |
| 3346 | + for (sprite = 0; sprite <= v->two_sprites; sprite++) { |
| 3347 | + vc1_sprite_parse_transform(gb, sd->coefs[sprite]); |
| 3348 | + if (sd->coefs[sprite][1] || sd->coefs[sprite][3]) |
| 3349 | + av_log_ask_for_sample(avctx, "Rotation coefficients are not zero"); |
| 3350 | + av_log(avctx, AV_LOG_DEBUG, sprite ? "S2:" : "S1:"); |
| 3336 | 3351 | for (i = 0; i < 7; i++) |
| 3337 | | − av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", coefs[1][i]); |
| 3338 | | − av_log(v->s.avctx, AV_LOG_DEBUG, "\n"); |
| 3352 | + av_log(avctx, AV_LOG_DEBUG, " %d.%.3d", |
| 3353 | + sd->coefs[sprite][i] / (1<<16), |
| 3354 | + (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1<<16)); |
| 3355 | + av_log(avctx, AV_LOG_DEBUG, "\n"); |
| 3339 | 3356 | } |
| 3357 | + |
| 3340 | 3358 | skip_bits(gb, 2); |
| 3341 | | − if (effect_type = get_bits_long(gb, 30)){ |
| 3342 | | − switch (effect_pcount1 = get_bits(gb, 4)) { |
| 3343 | | − case 2: |
| 3344 | | − effect_params1[0] = get_float_val(gb); |
| 3345 | | − effect_params1[1] = get_float_val(gb); |
| 3346 | | − break; |
| 3359 | + if (sd->effect_type = get_bits_long(gb, 30)) { |
| 3360 | + switch (sd->effect_pcount1 = get_bits(gb, 4)) { |
| 3347 | 3361 | case 7: |
| 3348 | | − vc1_sprite_parse_transform(v, gb, effect_params1); |
| 3362 | + vc1_sprite_parse_transform(gb, sd->effect_params1); |
| 3349 | 3363 | break; |
| 3350 | 3364 | case 14: |
| 3351 | | − vc1_sprite_parse_transform(v, gb, effect_params1); |
| 3352 | | − vc1_sprite_parse_transform(v, gb, &effect_params1[7]); |
| 3365 | + vc1_sprite_parse_transform(gb, sd->effect_params1); |
| 3366 | + vc1_sprite_parse_transform(gb, sd->effect_params1 + 7); |
| 3353 | 3367 | break; |
| 3354 | 3368 | default: |
| 3355 | | − av_log_ask_for_sample(v->s.avctx, NULL); |
| 3356 | | − return; |
| 3369 | + for (i = 0; i < sd->effect_pcount1; i++) |
| 3370 | + sd->effect_params1[i] = get_fp_val(gb); |
| 3357 | 3371 | } |
| 3358 | | − if (effect_type != 13 || effect_params1[0] != coefs[0][6]) { |
| 3372 | + if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) { |
| 3359 | 3373 | // effect 13 is simple alpha blending and matches the opacity above |
| 3360 | | − av_log(v->s.avctx, AV_LOG_DEBUG, "Effect: %d; params: ", effect_type); |
| 3361 | | − for (i = 0; i < effect_pcount1; i++) |
| 3362 | | − av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", effect_params1[i]); |
| 3363 | | − av_log(v->s.avctx, AV_LOG_DEBUG, "\n"); |
| 3374 | + av_log(avctx, AV_LOG_DEBUG, "Effect: %d; params: ", sd->effect_type); |
| 3375 | + for (i = 0; i < sd->effect_pcount1; i++) |
| 3376 | + av_log(avctx, AV_LOG_DEBUG, " %d.%.2d", |
| 3377 | + sd->effect_params1[i] / (1<<16), |
| 3378 | + (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1<<16)); |
| 3379 | + av_log(avctx, AV_LOG_DEBUG, "\n"); |
| 3364 | 3380 | } |
| 3365 | 3381 | |
| 3366 | | − effect_pcount2 = get_bits(gb, 16); |
| 3367 | | − if (effect_pcount2 > 10) { |
| 3368 | | − av_log(v->s.avctx, AV_LOG_ERROR, "Too many effect parameters\n"); |
| 3382 | + sd->effect_pcount2 = get_bits(gb, 16); |
| 3383 | + if (sd->effect_pcount2 > 10) { |
| 3384 | + av_log(avctx, AV_LOG_ERROR, "Too many effect parameters\n"); |
| 3369 | 3385 | return; |
| 3370 | | − } else if (effect_pcount2) { |
| 3371 | | − i = 0; |
| 3372 | | − av_log(v->s.avctx, AV_LOG_DEBUG, "Effect params 2: "); |
| 3373 | | − while (i < effect_pcount2){ |
| 3374 | | − effect_params2[i] = get_float_val(gb); |
| 3375 | | − av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", effect_params2[i]); |
| 3376 | | − i++; |
| 3386 | + } else if (sd->effect_pcount2) { |
| 3387 | + i = -1; |
| 3388 | + av_log(avctx, AV_LOG_DEBUG, "Effect params 2: "); |
| 3389 | + while (++i < sd->effect_pcount2){ |
| 3390 | + sd->effect_params2[i] = get_fp_val(gb); |
| 3391 | + av_log(avctx, AV_LOG_DEBUG, " %d.%.2d", |
| 3392 | + sd->effect_params2[i] / (1<<16), |
| 3393 | + (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1<<16)); |
| 3377 | 3394 | } |
| 3378 | | − av_log(v->s.avctx, AV_LOG_DEBUG, "\n"); |
| 3395 | + av_log(avctx, AV_LOG_DEBUG, "\n"); |
| 3379 | 3396 | } |
| 3380 | 3397 | } |
| 3381 | | − if (effect_flag = get_bits1(gb)) |
| 3382 | | − av_log(v->s.avctx, AV_LOG_DEBUG, "Effect flag set\n"); |
| 3398 | + if (sd->effect_flag = get_bits1(gb)) |
| 3399 | + av_log(avctx, AV_LOG_DEBUG, "Effect flag set\n"); |
| 3383 | 3400 | |
| 3384 | 3401 | if (get_bits_count(gb) >= gb->size_in_bits + |
| 3385 | | − (v->s.avctx->codec_id == CODEC_ID_WMV3 ? 64 : 0)) |
| 3386 | | − av_log(v->s.avctx, AV_LOG_ERROR, "Buffer overrun\n"); |
| 3402 | + (avctx->codec_id == CODEC_ID_WMV3IMAGE ? 64 : 0)) |
| 3403 | + av_log(avctx, AV_LOG_ERROR, "Buffer overrun\n"); |
| 3387 | 3404 | if (get_bits_count(gb) < gb->size_in_bits - 8) |
| 3388 | | − av_log(v->s.avctx, AV_LOG_WARNING, "Buffer not fully read\n"); |
| 3405 | + av_log(avctx, AV_LOG_WARNING, "Buffer not fully read\n"); |
| 3406 | +} |
| 3407 | + |
| 3408 | +static void vc1_draw_sprites(VC1Context *v, SpriteData* sd) |
| 3409 | +{ |
| 3410 | + int i, plane, row, sprite; |
| 3411 | + int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } }; |
| 3412 | + uint8_t* src_h[2][2]; |
| 3413 | + int xoff[2], xadv[2], yoff[2], yadv[2], alpha; |
| 3414 | + int ysub[2]; |
| 3415 | + MpegEncContext *s = &v->s; |
| 3416 | + |
| 3417 | + for (i = 0; i < 2; i++) { |
| 3418 | + xoff[i] = av_clip(sd->coefs[i][2], 0, v->sprite_width-1 << 16); |
| 3419 | + xadv[i] = sd->coefs[i][0]; |
| 3420 | + if (xadv[i] != 1<<16 || (v->sprite_width<<16) - (v->output_width<<16) - xoff[i]) |
| 3421 | + xadv[i] = av_clip(xadv[i], 0, ((v->sprite_width<<16) - xoff[i] - 1) / v->output_width); |
| 3422 | + |
| 3423 | + yoff[i] = av_clip(sd->coefs[i][5], 0, v->sprite_height-1 << 16); |
| 3424 | + yadv[i] = av_clip(sd->coefs[i][4], 0, ((v->sprite_height<<16) - yoff[i]) / v->output_height); |
| 3425 | + } |
| 3426 | + alpha = av_clip(sd->coefs[1][6], 0, (1<<16) - 1); |
| 3427 | + |
| 3428 | + for (plane = 0; plane < (s->flags&CODEC_FLAG_GRAY ? 1 : 3); plane++) { |
| 3429 | + int width = v->output_width>>!!plane; |
| 3430 | + |
| 3431 | + for (row = 0; row < v->output_height>>!!plane; row++) { |
| 3432 | + uint8_t *dst = v->sprite_output_frame.data[plane] + |
| 3433 | + v->sprite_output_frame.linesize[plane] * row; |
| 3434 | + |
| 3435 | + for (sprite = 0; sprite <= v->two_sprites; sprite++) { |
| 3436 | + uint8_t *iplane = s->current_picture.f.data[plane]; |
| 3437 | + int iline = s->current_picture.f.linesize[plane]; |
| 3438 | + int ycoord = yoff[sprite] + yadv[sprite]*row; |
| 3439 | + int yline = ycoord>>16; |
| 3440 | + ysub[sprite] = ycoord&0xFFFF; |
| 3441 | + if (sprite) { |
| 3442 | + iplane = s->last_picture.f.data[plane]; |
| 3443 | + iline = s->last_picture.f.linesize[plane]; |
| 3444 | + } |
| 3445 | + if (!(xoff[sprite]&0xFFFF) && xadv[sprite] == 1<<16) { |
| 3446 | + src_h[sprite][0] = iplane+(xoff[sprite]>>16)+ yline *iline; |
| 3447 | + if (ysub[sprite]) |
| 3448 | + src_h[sprite][1] = iplane+(xoff[sprite]>>16)+(yline+1)*iline; |
| 3449 | + } else { |
| 3450 | + if (sr_cache[sprite][0] != yline) { |
| 3451 | + if (sr_cache[sprite][1] == yline) { |
| 3452 | + FFSWAP(uint8_t*, v->sr_rows[sprite][0], v->sr_rows[sprite][1]); |
| 3453 | + FFSWAP(int, sr_cache[sprite][0], sr_cache[sprite][1]); |
| 3454 | + } else { |
| 3455 | + v->vc1dsp.sprite_h(v->sr_rows[sprite][0], iplane+yline*iline, xoff[sprite], xadv[sprite], width); |
| 3456 | + sr_cache[sprite][0] = yline; |
| 3457 | + } |
| 3458 | + } |
| 3459 | + if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) { |
| 3460 | + v->vc1dsp.sprite_h(v->sr_rows[sprite][1], iplane+(yline+1)*iline, xoff[sprite], xadv[sprite], width); |
| 3461 | + sr_cache[sprite][1] = yline + 1; |
| 3462 | + } |
| 3463 | + src_h[sprite][0] = v->sr_rows[sprite][0]; |
| 3464 | + src_h[sprite][1] = v->sr_rows[sprite][1]; |
| 3465 | + } |
| 3466 | + } |
| 3467 | + |
| 3468 | + if (!v->two_sprites) { |
| 3469 | + if (ysub[0]) { |
| 3470 | + v->vc1dsp.sprite_v_single(dst, src_h[0][0], src_h[0][1], ysub[0], width); |
| 3471 | + } else { |
| 3472 | + memcpy(dst, src_h[0][0], width); |
| 3473 | + } |
| 3474 | + } else { |
| 3475 | + if (ysub[0] && ysub[1]) { |
| 3476 | + v->vc1dsp.sprite_v_double_twoscale(dst, src_h[0][0], src_h[0][1], ysub[0], |
| 3477 | + src_h[1][0], src_h[1][1], ysub[1], alpha, width); |
| 3478 | + } else if (ysub[0]) { |
| 3479 | + v->vc1dsp.sprite_v_double_onescale(dst, src_h[0][0], src_h[0][1], ysub[0], |
| 3480 | + src_h[1][0], alpha, width); |
| 3481 | + } else if (ysub[1]) { |
| 3482 | + v->vc1dsp.sprite_v_double_onescale(dst, src_h[1][0], src_h[1][1], ysub[1], |
| 3483 | + src_h[0][0], (1<<16)-1-alpha, width); |
| 3484 | + } else { |
| 3485 | + v->vc1dsp.sprite_v_double_noscale(dst, src_h[0][0], src_h[1][0], alpha, width); |
| 3486 | + } |
| 3487 | + } |
| 3488 | + } |
| 3489 | + |
| 3490 | + if (!plane) { |
| 3491 | + for (i = 0; i < 2; i++) { |
| 3492 | + xoff[i] >>= 1; |
| 3493 | + yoff[i] >>= 1; |
| 3494 | + } |
| 3495 | + } |
| 3496 | + |
| 3497 | + } |
| 3498 | +} |
| 3499 | + |
| 3500 | + |
| 3501 | +static int vc1_decode_sprites(VC1Context *v, GetBitContext* gb) |
| 3502 | +{ |
| 3503 | + MpegEncContext *s = &v->s; |
| 3504 | + AVCodecContext *avctx = s->avctx; |
| 3505 | + SpriteData sd; |
| 3506 | + |
| 3507 | + vc1_parse_sprites(v, gb, &sd); |
| 3508 | + |
| 3509 | + if (!s->current_picture.f.data[0]) { |
| 3510 | + av_log(avctx, AV_LOG_ERROR, "Got no sprites\n"); |
| 3511 | + return -1; |
| 3512 | + } |
| 3513 | + |
| 3514 | + if (v->two_sprites && (!s->last_picture_ptr || !s->last_picture.f.data[0])) { |
| 3515 | + av_log(avctx, AV_LOG_WARNING, "Need two sprites, only got one\n"); |
| 3516 | + v->two_sprites = 0; |
| 3517 | + } |
| 3518 | + |
| 3519 | + if (v->sprite_output_frame.data[0]) |
| 3520 | + avctx->release_buffer(avctx, &v->sprite_output_frame); |
| 3521 | + |
| 3522 | + v->sprite_output_frame.buffer_hints = FF_BUFFER_HINTS_VALID; |
| 3523 | + v->sprite_output_frame.reference = 0; |
| 3524 | + if (avctx->get_buffer(avctx, &v->sprite_output_frame) < 0) { |
| 3525 | + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
| 3526 | + return -1; |
| 3527 | + } |
| 3528 | + |
| 3529 | + vc1_draw_sprites(v, &sd); |
| 3530 | + |
| 3531 | + return 0; |
| 3532 | +} |
| 3533 | + |
| 3534 | +static void vc1_sprite_flush(AVCodecContext *avctx) |
| 3535 | +{ |
| 3536 | + VC1Context *v = avctx->priv_data; |
| 3537 | + MpegEncContext *s = &v->s; |
| 3538 | + AVFrame *f = &s->current_picture.f; |
| 3539 | + int plane, i; |
| 3540 | + |
| 3541 | + /* Windows Media Image codecs have a convergence interval of two keyframes. |
| 3542 | + Since we can't enforce it, clear to black the missing sprite. This is |
| 3543 | + wrong but it looks better than doing nothing. */ |
| 3544 | + |
| 3545 | + if (f->data[0]) |
| 3546 | + for (plane = 0; plane < (s->flags&CODEC_FLAG_GRAY ? 1 : 3); plane++) |
| 3547 | + for (i = 0; i < v->sprite_height>>!!plane; i++) |
| 3548 | + memset(f->data[plane]+i*f->linesize[plane], |
| 3549 | + plane ? 128 : 0, f->linesize[plane]); |
| 3389 | 3550 | } |
| 3390 | 3551 | |
| 3552 | +#endif |
| 3553 | + |
| 3391 | 3554 | /** Initialize a VC1/WMV3 decoder |
| 3392 | 3555 | * @todo TODO: Handle VC-1 IDUs (Transport level?) |
| 3393 | 3556 | * @todo TODO: Decypher remaining bits in extra_data |
| @@ -3399,6 +3562,10 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx) · 5 unmodified lines |
| 3399 | 3562 | GetBitContext gb; |
| 3400 | 3563 | int i, cur_width, cur_height; |
| 3401 | 3564 | |
| 3565 | + /* save the container output size for WMImage */ |
| 3566 | + v->output_width = avctx->width; |
| 3567 | + v->output_height = avctx->height; |
| 3568 | + |
| 3402 | 3569 | if (!avctx->extradata_size || !avctx->extradata) return -1; |
| 3403 | 3570 | if (!(avctx->flags & CODEC_FLAG_GRAY)) |
| 3404 | 3571 | avctx->pix_fmt = avctx->get_format(avctx, avctx->codec->pix_fmts); |
| @@ -3420,7 +3587,7 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx) · 15 unmodified lines |
| 3420 | 3587 | |
| 3421 | 3588 | cur_width = avctx->coded_width = avctx->width; |
| 3422 | 3589 | cur_height = avctx->coded_height = avctx->height; |
| 3423 | | − if (avctx->codec_id == CODEC_ID_WMV3) |
| 3590 | + if (avctx->codec_id == CODEC_ID_WMV3 || avctx->codec_id == CODEC_ID_WMV3IMAGE) |
| 3424 | 3591 | { |
| 3425 | 3592 | int count = 0; |
| 3426 | 3593 | |
| @@ -3562,6 +3729,25 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx) · 135 unmodified lines |
| 3562 | 3729 | } |
| 3563 | 3730 | |
| 3564 | 3731 | ff_intrax8_common_init(&v->x8,s); |
| 3732 | + |
| 3733 | + if (avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) { |
| 3734 | + for (i = 0; i < 4; i++) |
| 3735 | + if (!(v->sr_rows[i>>1][i%2] = av_malloc(v->output_width))) return -1; |
| 3736 | + |
| 3737 | + s->low_delay = 1; |
| 3738 | + |
| 3739 | + v->sprite_width = avctx->coded_width; |
| 3740 | + v->sprite_height = avctx->coded_height; |
| 3741 | + |
| 3742 | + avctx->coded_width = avctx->width = v->output_width; |
| 3743 | + avctx->coded_height = avctx->height = v->output_height; |
| 3744 | + |
| 3745 | + // prevent 16.16 overflows |
| 3746 | + if (v->sprite_width > 1<<14 || |
| 3747 | + v->sprite_height > 1<<14 || |
| 3748 | + v->output_width > 1<<14 || |
| 3749 | + v->output_height > 1<<14) return -1; |
| 3750 | + } |
| 3565 | 3751 | return 0; |
| 3566 | 3752 | } |
| 3567 | 3753 | |
| @@ -3614,7 +3800,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, · 46 unmodified lines |
| 3614 | 3800 | } |
| 3615 | 3801 | |
| 3616 | 3802 | //for advanced profile we may need to parse and unescape data |
| 3617 | | − if (avctx->codec_id == CODEC_ID_VC1) { |
| 3803 | + if (avctx->codec_id == CODEC_ID_VC1 || avctx->codec_id == CODEC_ID_VC1IMAGE) { |
| 3618 | 3804 | int buf_size2 = 0; |
| 3619 | 3805 | buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); |
| 3620 | 3806 | |
| @@ -3679,8 +3865,19 @@ static int vc1_decode_frame(AVCodecContext *avctx, · 58 unmodified lines |
| 3679 | 3865 | if (v->res_sprite) { |
| 3680 | 3866 | v->new_sprite = !get_bits1(&s->gb); |
| 3681 | 3867 | v->two_sprites = get_bits1(&s->gb); |
| 3682 | | − if (!v->new_sprite) |
| 3683 | | − goto end; |
| 3868 | + /* res_sprite means a Windows Media Image stream, CODEC_ID_*IMAGE means |
| 3869 | + we're using the sprite compositor. These are intentionally kept separate |
| 3870 | + so you can get the raw sprites by using the wmv3 decoder for WMVP or |
| 3871 | + the vc1 one for WVP2 */ |
| 3872 | + if (avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) { |
| 3873 | + if (v->new_sprite) { |
| 3874 | + // switch AVCodecContext parameters to those of the sprites |
| 3875 | + avctx->width = avctx->coded_width = v->sprite_width; |
| 3876 | + avctx->height = avctx->coded_height = v->sprite_height; |
| 3877 | + } else { |
| 3878 | + goto image; |
| 3879 | + } |
| 3880 | + } |
| 3684 | 3881 | } |
| 3685 | 3882 | |
| 3686 | 3883 | // do parse frame header |
| @@ -3694,8 +3891,10 @@ static int vc1_decode_frame(AVCodecContext *avctx, · 7 unmodified lines |
| 3694 | 3891 | } |
| 3695 | 3892 | } |
| 3696 | 3893 | |
| 3697 | | − if (v->res_sprite && s->pict_type!=AV_PICTURE_TYPE_I) { |
| 3698 | | − av_log(v->s.avctx, AV_LOG_WARNING, "Sprite decoder: expected I-frame\n"); |
| 3894 | + if ((avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) |
| 3895 | + && s->pict_type!=AV_PICTURE_TYPE_I) { |
| 3896 | + av_log(v->s.avctx, AV_LOG_ERROR, "Sprite decoder: expected I-frame\n"); |
| 3897 | + goto err; |
| 3699 | 3898 | } |
| 3700 | 3899 | |
| 3701 | 3900 | // for skipping the frame |
| @@ -3758,6 +3957,19 @@ static int vc1_decode_frame(AVCodecContext *avctx, · 56 unmodified lines |
| 3758 | 3957 | |
| 3759 | 3958 | assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type); |
| 3760 | 3959 | assert(s->current_picture.f.pict_type == s->pict_type); |
| 3960 | + |
| 3961 | + if (avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) { |
| 3962 | +image: |
| 3963 | + avctx->width = avctx->coded_width = v->output_width; |
| 3964 | + avctx->height = avctx->coded_height = v->output_height; |
| 3965 | + if (avctx->skip_frame >= AVDISCARD_NONREF) goto end; |
| 3966 | +#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER |
| 3967 | + if (vc1_decode_sprites(v, &s->gb)) goto err; |
| 3968 | +#endif |
| 3969 | + *pict = v->sprite_output_frame; |
| 3970 | + *data_size = sizeof(AVFrame); |
| 3971 | + } else { |
| 3972 | + |
| 3761 | 3973 | if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { |
| 3762 | 3974 | *pict= *(AVFrame*)s->current_picture_ptr; |
| 3763 | 3975 | } else if (s->last_picture_ptr != NULL) { |
| @@ -3769,9 +3981,9 @@ assert(s->current_picture.f.pict_type == s->pict_type); · 5 unmodified lines |
| 3769 | 3981 | ff_print_debug_info(s, pict); |
| 3770 | 3982 | } |
| 3771 | 3983 | |
| 3984 | + } |
| 3985 | + |
| 3772 | 3986 | end: |
| 3773 | | − if (v->res_sprite) |
| 3774 | | − vc1_parse_sprites(v, &s->gb); |
| 3775 | 3987 | av_free(buf2); |
| 3776 | 3988 | for (i = 0; i < n_slices; i++) |
| 3777 | 3989 | av_free(slices[i].buf); |
| @@ -3793,7 +4005,13 @@ err: · 15 unmodified lines |
| 3793 | 4005 | static av_cold int vc1_decode_end(AVCodecContext *avctx) |
| 3794 | 4006 | { |
| 3795 | 4007 | VC1Context *v = avctx->priv_data; |
| 4008 | + int i; |
| 3796 | 4009 | |
| 4010 | + if ((avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) |
| 4011 | + && v->sprite_output_frame.data[0]) |
| 4012 | + avctx->release_buffer(avctx, &v->sprite_output_frame); |
| 4013 | + for (i = 0; i < 4; i++) |
| 4014 | + av_freep(&v->sr_rows[i>>1][i%2]); |
| 3797 | 4015 | av_freep(&v->hrd_rate); |
| 3798 | 4016 | av_freep(&v->hrd_buffer); |
| 3799 | 4017 | MPV_common_end(&v->s); |
| @@ -3880,3 +4098,35 @@ AVCodec ff_vc1_vdpau_decoder = { · 80 unmodified lines |
| 3880 | 4098 | .profiles = NULL_IF_CONFIG_SMALL(profiles) |
| 3881 | 4099 | }; |
| 3882 | 4100 | #endif |
| 4101 | + |
| 4102 | +#if CONFIG_WMV3IMAGE_DECODER |
| 4103 | +AVCodec ff_wmv3image_decoder = { |
| 4104 | + .name = "wmv3image", |
| 4105 | + .type = AVMEDIA_TYPE_VIDEO, |
| 4106 | + .id = CODEC_ID_WMV3IMAGE, |
| 4107 | + .priv_data_size = sizeof(VC1Context), |
| 4108 | + .init = vc1_decode_init, |
| 4109 | + .close = vc1_decode_end, |
| 4110 | + .decode = vc1_decode_frame, |
| 4111 | + .capabilities = CODEC_CAP_DR1, |
| 4112 | + .flush = vc1_sprite_flush, |
| 4113 | + .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image"), |
| 4114 | + .pix_fmts = ff_pixfmt_list_420 |
| 4115 | +}; |
| 4116 | +#endif |
| 4117 | + |
| 4118 | +#if CONFIG_VC1IMAGE_DECODER |
| 4119 | +AVCodec ff_vc1image_decoder = { |
| 4120 | + .name = "vc1image", |
| 4121 | + .type = AVMEDIA_TYPE_VIDEO, |
| 4122 | + .id = CODEC_ID_VC1IMAGE, |
| 4123 | + .priv_data_size = sizeof(VC1Context), |
| 4124 | + .init = vc1_decode_init, |
| 4125 | + .close = vc1_decode_end, |
| 4126 | + .decode = vc1_decode_frame, |
| 4127 | + .capabilities = CODEC_CAP_DR1, |
| 4128 | + .flush = vc1_sprite_flush, |
| 4129 | + .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image v2"), |
| 4130 | + .pix_fmts = ff_pixfmt_list_420 |
| 4131 | +}; |
| 4132 | +#endif |