| @@ -3097,6 +3097,116 @@ static void vc1_decode_blocks(VC1Context *v, int mby_start, int mby_end) · 3096 unmodified lines |
| 3097 | } | 3097 | } |
| 3098 | } | 3098 | } |
| 3099 | | 3099 | |
| | 3100 | static inline float get_float_val(GetBitContext* gb) |
| | 3101 | { |
| | 3102 | return (float)get_bits_long(gb, 30) / (1<<15) - (1<<14); |
| | 3103 | } |
| | 3104 | |
| | 3105 | static void vc1_sprite_parse_transform(VC1Context *v, GetBitContext* gb, float c[7]) |
| | 3106 | { |
| | 3107 | c[1] = c[3] = 0.0f; |
| | 3108 | |
| | 3109 | switch (get_bits(gb, 2)) { |
| | 3110 | case 0: |
| | 3111 | c[0] = 1.0f; |
| | 3112 | c[2] = get_float_val(gb); |
| | 3113 | c[4] = 1.0f; |
| | 3114 | break; |
| | 3115 | case 1: |
| | 3116 | c[0] = c[4] = get_float_val(gb); |
| | 3117 | c[2] = get_float_val(gb); |
| | 3118 | break; |
| | 3119 | case 2: |
| | 3120 | c[0] = get_float_val(gb); |
| | 3121 | c[2] = get_float_val(gb); |
| | 3122 | c[4] = get_float_val(gb); |
| | 3123 | break; |
| | 3124 | case 3: |
| | 3125 | av_log_ask_for_sample(v->s.avctx, NULL); |
| | 3126 | c[0] = get_float_val(gb); |
| | 3127 | c[1] = get_float_val(gb); |
| | 3128 | c[2] = get_float_val(gb); |
| | 3129 | c[3] = get_float_val(gb); |
| | 3130 | c[4] = get_float_val(gb); |
| | 3131 | break; |
| | 3132 | } |
| | 3133 | c[5] = get_float_val(gb); |
| | 3134 | if (get_bits1(gb)) |
| | 3135 | c[6] = get_float_val(gb); |
| | 3136 | else |
| | 3137 | c[6] = 1.0f; |
| | 3138 | } |
| | 3139 | |
| | 3140 | static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb) |
| | 3141 | { |
| | 3142 | int effect_type, effect_flag, effect_pcount1, effect_pcount2, i; |
| | 3143 | float effect_params1[14], effect_params2[10]; |
| | 3144 | |
| | 3145 | float coefs[2][7]; |
| | 3146 | vc1_sprite_parse_transform(v, gb, coefs[0]); |
| | 3147 | av_log(v->s.avctx, AV_LOG_DEBUG, "S1:"); |
| | 3148 | for (i = 0; i < 7; i++) |
| | 3149 | av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", coefs[0][i]); |
| | 3150 | av_log(v->s.avctx, AV_LOG_DEBUG, "\n"); |
| | 3151 | |
| | 3152 | if (v->two_sprites) { |
| | 3153 | vc1_sprite_parse_transform(v, gb, coefs[1]); |
| | 3154 | av_log(v->s.avctx, AV_LOG_DEBUG, "S2:"); |
| | 3155 | for (i = 0; i < 7; i++) |
| | 3156 | av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", coefs[1][i]); |
| | 3157 | av_log(v->s.avctx, AV_LOG_DEBUG, "\n"); |
| | 3158 | } |
| | 3159 | skip_bits(gb, 2); |
| | 3160 | if (effect_type = get_bits_long(gb, 30)){ |
| | 3161 | switch (effect_pcount1 = get_bits(gb, 4)) { |
| | 3162 | case 2: |
| | 3163 | effect_params1[0] = get_float_val(gb); |
| | 3164 | effect_params1[1] = get_float_val(gb); |
| | 3165 | break; |
| | 3166 | case 7: |
| | 3167 | vc1_sprite_parse_transform(v, gb, effect_params1); |
| | 3168 | break; |
| | 3169 | case 14: |
| | 3170 | vc1_sprite_parse_transform(v, gb, effect_params1); |
| | 3171 | vc1_sprite_parse_transform(v, gb, &effect_params1[7]); |
| | 3172 | break; |
| | 3173 | default: |
| | 3174 | av_log_ask_for_sample(v->s.avctx, NULL); |
| | 3175 | return; |
| | 3176 | } |
| | 3177 | if (effect_type != 13 || effect_params1[0] != coefs[0][6]) { |
| | 3178 | // effect 13 is simple alpha blending and matches the opacity above |
| | 3179 | av_log(v->s.avctx, AV_LOG_DEBUG, "Effect: %d; params: ", effect_type); |
| | 3180 | for (i = 0; i < effect_pcount1; i++) |
| | 3181 | av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", effect_params1[i]); |
| | 3182 | av_log(v->s.avctx, AV_LOG_DEBUG, "\n"); |
| | 3183 | } |
| | 3184 | |
| | 3185 | effect_pcount2 = get_bits(gb, 16); |
| | 3186 | if (effect_pcount2 > 10) { |
| | 3187 | av_log(v->s.avctx, AV_LOG_ERROR, "Too many effect parameters\n"); |
| | 3188 | return; |
| | 3189 | } else if (effect_pcount2) { |
| | 3190 | i = 0; |
| | 3191 | av_log(v->s.avctx, AV_LOG_DEBUG, "Effect params 2: "); |
| | 3192 | while (i < effect_pcount2){ |
| | 3193 | effect_params2[i] = get_float_val(gb); |
| | 3194 | av_log(v->s.avctx, AV_LOG_DEBUG, " %.3f", effect_params2[i]); |
| | 3195 | i++; |
| | 3196 | } |
| | 3197 | av_log(v->s.avctx, AV_LOG_DEBUG, "\n"); |
| | 3198 | } |
| | 3199 | } |
| | 3200 | if (effect_flag = get_bits1(gb)) |
| | 3201 | av_log(v->s.avctx, AV_LOG_DEBUG, "Effect flag set\n"); |
| | 3202 | |
| | 3203 | if (get_bits_count(gb) >= gb->size_in_bits + |
| | 3204 | (v->s.avctx->codec_id == CODEC_ID_WMV3 ? 64 : 0)) |
| | 3205 | av_log(v->s.avctx, AV_LOG_ERROR, "Buffer overrun\n"); |
| | 3206 | if (get_bits_count(gb) < gb->size_in_bits - 8) |
| | 3207 | av_log(v->s.avctx, AV_LOG_WARNING, "Buffer not fully read\n"); |
| | 3208 | } |
| | 3209 | |
| 3100 | /** Initialize a VC1/WMV3 decoder | 3210 | /** Initialize a VC1/WMV3 decoder |
| 3101 | * @todo TODO: Handle VC-1 IDUs (Transport level?) | 3211 | * @todo TODO: Handle VC-1 IDUs (Transport level?) |
| 3102 | * @todo TODO: Decypher remaining bits in extra_data | 3212 | * @todo TODO: Decypher remaining bits in extra_data |
| @@ -3160,7 +3270,7 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx) · 57 unmodified lines |
| 3160 | { | 3270 | { |
| 3161 | av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count); | 3271 | av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count); |
| 3162 | } | 3272 | } |
| 3163 | } else { // VC1/WVC1 | 3273 | } else { // VC1/WVC1/WVP2 |
| 3164 | const uint8_t *start = avctx->extradata; | 3274 | const uint8_t *start = avctx->extradata; |
| 3165 | uint8_t *end = avctx->extradata + avctx->extradata_size; | 3275 | uint8_t *end = avctx->extradata + avctx->extradata_size; |
| 3166 | const uint8_t *next; | 3276 | const uint8_t *next; |
| @@ -3204,6 +3314,7 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx) · 37 unmodified lines |
| 3204 | av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n"); | 3314 | av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n"); |
| 3205 | return -1; | 3315 | return -1; |
| 3206 | } | 3316 | } |
| | 3317 | v->res_sprite = (avctx->codec_tag == MKTAG('W','V','P','2')); |
| 3207 | } | 3318 | } |
| 3208 | avctx->profile = v->profile; | 3319 | avctx->profile = v->profile; |
| 3209 | if (v->profile == PROFILE_ADVANCED) | 3320 | if (v->profile == PROFILE_ADVANCED) |
| @@ -3359,6 +3470,14 @@ static int vc1_decode_frame(AVCodecContext *avctx, · 149 unmodified lines |
| 3359 | init_get_bits(&s->gb, buf2, buf_size2*8); | 3470 | init_get_bits(&s->gb, buf2, buf_size2*8); |
| 3360 | } else | 3471 | } else |
| 3361 | init_get_bits(&s->gb, buf, buf_size*8); | 3472 | init_get_bits(&s->gb, buf, buf_size*8); |
| | 3473 | |
| | 3474 | if (v->res_sprite) { |
| | 3475 | v->new_sprite = !get_bits1(&s->gb); |
| | 3476 | v->two_sprites = get_bits1(&s->gb); |
| | 3477 | if (!v->new_sprite) |
| | 3478 | goto end; |
| | 3479 | } |
| | 3480 | |
| 3362 | // do parse frame header | 3481 | // do parse frame header |
| 3363 | if(v->profile < PROFILE_ADVANCED) { | 3482 | if(v->profile < PROFILE_ADVANCED) { |
| 3364 | if(vc1_parse_frame_header(v, &s->gb) == -1) { | 3483 | if(vc1_parse_frame_header(v, &s->gb) == -1) { |
| @@ -3370,8 +3489,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, · 5 unmodified lines |
| 3370 | } | 3489 | } |
| 3371 | } | 3490 | } |
| 3372 | | 3491 | |
| 3373 | if(v->res_sprite && (s->pict_type!=FF_I_TYPE)){ | 3492 | if (v->res_sprite && s->pict_type!=FF_I_TYPE) { |
| 3374 | goto err; | 3493 | av_log(v->s.avctx, AV_LOG_WARNING, "Sprite decoder: expected I-frame\n"); |
| 3375 | } | 3494 | } |
| 3376 | | 3495 | |
| 3377 | s->current_picture_ptr->repeat_pict = 0; | 3496 | s->current_picture_ptr->repeat_pict = 0; |
| @@ -3464,6 +3583,8 @@ assert(s->current_picture.pict_type == s->pict_type); · 86 unmodified lines |
| 3464 | } | 3583 | } |
| 3465 | | 3584 | |
| 3466 | end: | 3585 | end: |
| | 3586 | if (v->res_sprite) |
| | 3587 | vc1_parse_sprites(v, &s->gb); |
| 3467 | av_free(buf2); | 3588 | av_free(buf2); |
| 3468 | for (i = 0; i < n_slices; i++) | 3589 | for (i = 0; i < n_slices; i++) |
| 3469 | av_free(slices[i].buf); | 3590 | av_free(slices[i].buf); |