Revision d375c104 libavcodec/h264_direct.c

View differences:

libavcodec/h264_direct.c
31 31
#include "mpegvideo.h"
32 32
#include "h264.h"
33 33
#include "rectangle.h"
34
#include "thread.h"
34 35

  
35 36
//#undef NDEBUG
36 37
#include <assert.h>
......
126 127
        h->col_parity= (FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc));
127 128
        ref1sidx=sidx= h->col_parity;
128 129
    }else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){ // FL -> FL & differ parity
129
        h->col_fieldoff= s->mb_stride*(2*(h->ref_list[1][0].reference) - 3);
130
        h->col_fieldoff= 2*(h->ref_list[1][0].reference) - 3;
130 131
    }
131 132

  
132 133
    if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred)
......
140 141
    }
141 142
}
142 143

  
144
static void await_reference_mb_row(H264Context * const h, Picture *ref, int mb_y)
145
{
146
    int ref_field = ref->reference - 1;
147
    int ref_field_picture = ref->field_picture;
148
    int ref_height = 16*h->s.mb_height >> ref_field_picture;
149

  
150
    if(!HAVE_PTHREADS || !(h->s.avctx->active_thread_type&FF_THREAD_FRAME))
151
        return;
152

  
153
    //FIXME it can be safe to access mb stuff
154
    //even if pixels aren't deblocked yet
155

  
156
    ff_thread_await_progress((AVFrame*)ref, FFMIN(16*mb_y >> ref_field_picture, ref_height-1),
157
                             ref_field_picture && ref_field);
158
}
159

  
143 160
static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
144 161
    MpegEncContext * const s = &h->s;
145 162
    int b8_stride = 2;
146 163
    int b4_stride = h->b_stride;
147
    int mb_xy = h->mb_xy;
164
    int mb_xy = h->mb_xy, mb_y = s->mb_y;
148 165
    int mb_type_col[2];
149 166
    const int16_t (*l1mv0)[2], (*l1mv1)[2];
150 167
    const int8_t *l1ref0, *l1ref1;
......
157 174

  
158 175
    assert(h->ref_list[1][0].reference&3);
159 176

  
177
    await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));
178

  
160 179
#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
161 180

  
162 181

  
......
217 236

  
218 237
    if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL
219 238
        if(!IS_INTERLACED(*mb_type)){                    //     AFR/FR    -> AFL/FL
239
            mb_y = (s->mb_y&~1) + h->col_parity;
220 240
            mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;
221 241
            b8_stride = 0;
222 242
        }else{
223
            mb_xy += h->col_fieldoff; // non zero for FL -> FL & differ parity
243
            mb_y  += h->col_fieldoff;
244
            mb_xy += s->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity
224 245
        }
225 246
        goto single_col;
226 247
    }else{                                               // AFL/AFR/FR/FL -> AFR/FR
227 248
        if(IS_INTERLACED(*mb_type)){                     // AFL       /FL -> AFR/FR
249
            mb_y = s->mb_y&~1;
228 250
            mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
229 251
            mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
230 252
            mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
......
260 282
        }
261 283
    }
262 284

  
285
    await_reference_mb_row(h, &h->ref_list[1][0], mb_y);
286

  
263 287
    l1mv0  = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
264 288
    l1mv1  = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
265 289
    l1ref0 = &h->ref_list[1][0].ref_index [0][4*mb_xy];
......
384 408
    MpegEncContext * const s = &h->s;
385 409
    int b8_stride = 2;
386 410
    int b4_stride = h->b_stride;
387
    int mb_xy = h->mb_xy;
411
    int mb_xy = h->mb_xy, mb_y = s->mb_y;
388 412
    int mb_type_col[2];
389 413
    const int16_t (*l1mv0)[2], (*l1mv1)[2];
390 414
    const int8_t *l1ref0, *l1ref1;
......
394 418

  
395 419
    assert(h->ref_list[1][0].reference&3);
396 420

  
421
    await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));
422

  
397 423
    if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL
398 424
        if(!IS_INTERLACED(*mb_type)){                    //     AFR/FR    -> AFL/FL
425
            mb_y = (s->mb_y&~1) + h->col_parity;
399 426
            mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;
400 427
            b8_stride = 0;
401 428
        }else{
402
            mb_xy += h->col_fieldoff; // non zero for FL -> FL & differ parity
429
            mb_y  += h->col_fieldoff;
430
            mb_xy += s->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity
403 431
        }
404 432
        goto single_col;
405 433
    }else{                                               // AFL/AFR/FR/FL -> AFR/FR
406 434
        if(IS_INTERLACED(*mb_type)){                     // AFL       /FL -> AFR/FR
435
            mb_y = s->mb_y&~1;
407 436
            mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
408 437
            mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
409 438
            mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
......
440 469
        }
441 470
    }
442 471

  
472
    await_reference_mb_row(h, &h->ref_list[1][0], mb_y);
473

  
443 474
    l1mv0  = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
444 475
    l1mv1  = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
445 476
    l1ref0 = &h->ref_list[1][0].ref_index [0][4*mb_xy];

Also available in: Unified diff