Revision f44d6445 libavcodec/vc1dec.c

View differences:

libavcodec/vc1dec.c
2686 2686

  
2687 2687
/** Decode blocks of I-frame for advanced profile
2688 2688
 */
2689
static void vc1_decode_i_blocks_adv(VC1Context *v)
2689
static void vc1_decode_i_blocks_adv(VC1Context *v, int mby_start, int mby_end)
2690 2690
{
2691 2691
    int k;
2692 2692
    MpegEncContext *s = &v->s;
......
2728 2728
    s->mb_x = s->mb_y = 0;
2729 2729
    s->mb_intra = 1;
2730 2730
    s->first_slice_line = 1;
2731
    s->mb_y = mby_start;
2732
    if (mby_start) {
2733
        s->mb_x = 0;
2734
        ff_init_block_index(s);
2735
        memset(&s->coded_block[s->block_index[0]-s->b8_stride], 0,
2736
               s->b8_stride * sizeof(*s->coded_block));
2737
    }
2731 2738
    idct8x8_fn = v->vc1dsp.vc1_inv_trans_8x8_put_signed[0];
2732
    for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
2739
    for(; s->mb_y < mby_end; s->mb_y++) {
2733 2740
        s->mb_x = 0;
2734 2741
        ff_init_block_index(s);
2735 2742
        for(;s->mb_x < s->mb_width; s->mb_x++) {
......
2815 2822
            if(v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq);
2816 2823

  
2817 2824
            if(get_bits_count(&s->gb) > v->bits) {
2818
                ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
2825
                ff_er_add_slice(s, 0, mby_start, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
2819 2826
                av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits);
2820 2827
                return;
2821 2828
            }
......
2828 2835
    }
2829 2836
    if (v->s.loop_filter)
2830 2837
        ff_draw_horiz_band(s, (s->mb_height-1)*16, 16);
2831
    ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
2838
    ff_er_add_slice(s, 0, mby_start, s->mb_width - 1, mby_end - 1, (AC_END|DC_END|MV_END));
2832 2839
}
2833 2840

  
2834
static void vc1_decode_p_blocks(VC1Context *v)
2841
static void vc1_decode_p_blocks(VC1Context *v, int mby_start, int mby_end)
2835 2842
{
2836 2843
    MpegEncContext *s = &v->s;
2837 2844

  
......
2862 2869

  
2863 2870
    s->first_slice_line = 1;
2864 2871
    memset(v->cbp_base, 0, sizeof(v->cbp_base[0])*2*s->mb_stride);
2865
    for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
2872
    for(s->mb_y = mby_start; s->mb_y < mby_end; s->mb_y++) {
2866 2873
        s->mb_x = 0;
2867 2874
        ff_init_block_index(s);
2868 2875
        for(; s->mb_x < s->mb_width; s->mb_x++) {
......
2870 2877

  
2871 2878
            vc1_decode_p_mb(v);
2872 2879
            if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
2873
                ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
2880
                ff_er_add_slice(s, 0, mby_start, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
2874 2881
                av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y);
2875 2882
                return;
2876 2883
            }
......
2879 2886
        ff_draw_horiz_band(s, s->mb_y * 16, 16);
2880 2887
        s->first_slice_line = 0;
2881 2888
    }
2882
    ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
2889
    ff_er_add_slice(s, 0, mby_start, s->mb_width - 1, mby_end - 1, (AC_END|DC_END|MV_END));
2883 2890
}
2884 2891

  
2885
static void vc1_decode_b_blocks(VC1Context *v)
2892
static void vc1_decode_b_blocks(VC1Context *v, int mby_start, int mby_end)
2886 2893
{
2887 2894
    MpegEncContext *s = &v->s;
2888 2895

  
......
2912 2919
    }
2913 2920

  
2914 2921
    s->first_slice_line = 1;
2915
    for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
2922
    for(s->mb_y = mby_start; s->mb_y < mby_end; s->mb_y++) {
2916 2923
        s->mb_x = 0;
2917 2924
        ff_init_block_index(s);
2918 2925
        for(; s->mb_x < s->mb_width; s->mb_x++) {
......
2920 2927

  
2921 2928
            vc1_decode_b_mb(v);
2922 2929
            if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
2923
                ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
2930
                ff_er_add_slice(s, 0, mby_start, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END));
2924 2931
                av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y);
2925 2932
                return;
2926 2933
            }
......
2934 2941
    }
2935 2942
    if (v->s.loop_filter)
2936 2943
        ff_draw_horiz_band(s, (s->mb_height-1)*16, 16);
2937
    ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END));
2944
    ff_er_add_slice(s, 0, mby_start, s->mb_width - 1, mby_end - 1, (AC_END|DC_END|MV_END));
2938 2945
}
2939 2946

  
2940 2947
static void vc1_decode_skip_blocks(VC1Context *v)
......
2956 2963
    s->pict_type = FF_P_TYPE;
2957 2964
}
2958 2965

  
2959
static void vc1_decode_blocks(VC1Context *v)
2966
static void vc1_decode_blocks(VC1Context *v, int mby_start, int mby_end)
2960 2967
{
2961 2968

  
2962 2969
    v->s.esc3_level_length = 0;
2963 2970
    if(v->x8_type){
2964 2971
        ff_intrax8_decode_picture(&v->x8, 2*v->pq+v->halfpq, v->pq*(!v->pquantizer) );
2965 2972
    }else{
2966

  
2967 2973
        switch(v->s.pict_type) {
2968 2974
        case FF_I_TYPE:
2969 2975
            if(v->profile == PROFILE_ADVANCED)
2970
                vc1_decode_i_blocks_adv(v);
2976
                vc1_decode_i_blocks_adv(v, mby_start, mby_end);
2971 2977
            else
2972 2978
                vc1_decode_i_blocks(v);
2973 2979
            break;
......
2975 2981
            if(v->p_frame_skipped)
2976 2982
                vc1_decode_skip_blocks(v);
2977 2983
            else
2978
                vc1_decode_p_blocks(v);
2984
                vc1_decode_p_blocks(v, mby_start, mby_end);
2979 2985
            break;
2980 2986
        case FF_B_TYPE:
2981 2987
            if(v->bi_type){
2982 2988
                if(v->profile == PROFILE_ADVANCED)
2983
                    vc1_decode_i_blocks_adv(v);
2989
                    vc1_decode_i_blocks_adv(v, mby_start, mby_end);
2984 2990
                else
2985 2991
                    vc1_decode_i_blocks(v);
2986 2992
            }else
2987
                vc1_decode_b_blocks(v);
2993
                vc1_decode_b_blocks(v, mby_start, mby_end);
2988 2994
            break;
2989 2995
        }
2990 2996
    }
......
3145 3151
                            AVPacket *avpkt)
3146 3152
{
3147 3153
    const uint8_t *buf = avpkt->data;
3148
    int buf_size = avpkt->size;
3154
    int buf_size = avpkt->size, n_slices = 0, i;
3149 3155
    VC1Context *v = avctx->priv_data;
3150 3156
    MpegEncContext *s = &v->s;
3151 3157
    AVFrame *pict = data;
3152 3158
    uint8_t *buf2 = NULL;
3153 3159
    const uint8_t *buf_start = buf;
3160
    struct {
3161
        uint8_t *buf;
3162
        GetBitContext gb;
3163
        int mby_start;
3164
    } *slices = NULL;
3154 3165

  
3155 3166
    /* no supplementary picture */
3156 3167
    if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) {
......
3205 3216
                    init_get_bits(&s->gb, buf2, buf_size2*8);
3206 3217
                    vc1_decode_entry_point(avctx, v, &s->gb);
3207 3218
                    break;
3208
                case VC1_CODE_SLICE:
3209
                    av_log(avctx, AV_LOG_ERROR, "Sliced decoding is not implemented (yet)\n");
3210
                    av_free(buf2);
3211
                    return -1;
3219
                case VC1_CODE_SLICE: {
3220
                    int buf_size3;
3221
                    slices = av_realloc(slices, sizeof(*slices) * (n_slices+1));
3222
                    if (!slices) goto err;
3223
                    slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
3224
                    if (!slices[n_slices].buf) goto err;
3225
                    buf_size3 = vc1_unescape_buffer(start + 4, size,
3226
                                                    slices[n_slices].buf);
3227
                    init_get_bits(&slices[n_slices].gb, slices[n_slices].buf,
3228
                                  buf_size3 << 3);
3229
                    slices[n_slices].mby_start = get_bits(&slices[n_slices].gb, 9);
3230
                    n_slices++;
3231
                    break;
3232
                }
3212 3233
                }
3213 3234
            }
3214 3235
        }else if(v->interlace && ((buf[0] & 0xC0) == 0xC0)){ /* WVC1 interlaced stores both fields divided by marker */
......
3294 3315
        ff_er_frame_start(s);
3295 3316

  
3296 3317
        v->bits = buf_size * 8;
3297
        vc1_decode_blocks(v);
3318
        for (i = 0; i <= n_slices; i++) {
3319
            if (i && get_bits1(&s->gb))
3320
                vc1_parse_frame_header_adv(v, &s->gb);
3321
            vc1_decode_blocks(v, i == 0 ? 0 : FFMAX(0, slices[i-1].mby_start),
3322
                i == n_slices ? s->mb_height : FFMIN(s->mb_height, slices[i].mby_start));
3323
            if (i != n_slices) s->gb = slices[i].gb;
3324
        }
3298 3325
//av_log(s->avctx, AV_LOG_INFO, "Consumed %i/%i bits\n", get_bits_count(&s->gb), s->gb.size_in_bits);
3299 3326
//  if(get_bits_count(&s->gb) > buf_size * 8)
3300 3327
//      return -1;
......
3318 3345

  
3319 3346
end:
3320 3347
    av_free(buf2);
3348
    for (i = 0; i < n_slices; i++)
3349
        av_free(slices[i].buf);
3350
    av_free(slices);
3321 3351
    return buf_size;
3322 3352

  
3323 3353
err:
3324 3354
    av_free(buf2);
3355
    for (i = 0; i < n_slices; i++)
3356
        av_free(slices[i].buf);
3357
    av_free(slices);
3325 3358
    return -1;
3326 3359
}
3327 3360

  

Also available in: Unified diff