~ubuntu-branches/ubuntu/saucy/x264/saucy-updates

« back to all changes in this revision

Viewing changes to common/frame.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2007-01-17 22:00:05 UTC
  • mto: (12.1.1 sid) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20070117220005-4cesfv31lq3inbdp
Tags: upstream-0.cvs20070117
ImportĀ upstreamĀ versionĀ 0.cvs20070117

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include <stdio.h>
25
25
#include <string.h>
 
26
#include <unistd.h>
26
27
 
27
28
#include "common.h"
28
29
 
 
30
#define PADH 32
 
31
#define PADV 32
 
32
 
29
33
x264_frame_t *x264_frame_new( x264_t *h )
30
34
{
31
35
    x264_frame_t *frame = x264_malloc( sizeof(x264_frame_t) );
34
38
    int i_mb_count = h->mb.i_mb_count;
35
39
    int i_stride;
36
40
    int i_lines;
 
41
    int i_padv = PADV << h->param.b_interlaced;
37
42
 
38
43
    if( !frame ) return NULL;
39
44
 
40
45
    memset( frame, 0, sizeof(x264_frame_t) );
41
46
 
42
47
    /* allocate frame data (+64 for extra data for me) */
43
 
    i_stride = ( ( h->param.i_width  + 15 )&0xfffff0 )+ 64;
44
 
    i_lines  = ( ( h->param.i_height + 15 )&0xfffff0 );
 
48
    i_stride = ( ( h->param.i_width  + 15 ) & -16 )+ 2*PADH;
 
49
    i_lines  = ( ( h->param.i_height + 15 ) & -16 );
 
50
    if( h->param.b_interlaced )
 
51
        i_lines = ( i_lines + 31 ) & -32;
45
52
 
46
53
    frame->i_plane = 3;
47
54
    for( i = 0; i < 3; i++ )
58
65
        frame->i_stride[i] = i_stride / i_divw;
59
66
        frame->i_lines[i] = i_lines / i_divh;
60
67
        CHECKED_MALLOC( frame->buffer[i],
61
 
                        frame->i_stride[i] * ( frame->i_lines[i] + 64 / i_divh ) );
 
68
                        frame->i_stride[i] * ( frame->i_lines[i] + 2*i_padv / i_divh ) );
 
69
 
62
70
        frame->plane[i] = ((uint8_t*)frame->buffer[i]) +
63
 
                          frame->i_stride[i] * 32 / i_divh + 32 / i_divw;
 
71
                          frame->i_stride[i] * i_padv / i_divh + PADH / i_divw;
64
72
    }
65
73
    frame->i_stride[3] = 0;
66
74
    frame->i_lines[3] = 0;
71
79
    for( i = 0; i < 3; i++ )
72
80
    {
73
81
        CHECKED_MALLOC( frame->buffer[4+i],
74
 
                        frame->i_stride[0] * ( frame->i_lines[0] + 64 ) );
 
82
                        frame->i_stride[0] * ( frame->i_lines[0] + 2*i_padv ) );
75
83
        frame->filtered[i+1] = ((uint8_t*)frame->buffer[4+i]) +
76
 
                                frame->i_stride[0] * 32 + 32;
 
84
                                frame->i_stride[0] * i_padv + PADH;
77
85
    }
78
86
 
79
87
    if( h->frames.b_have_lowres )
80
88
    {
81
 
        frame->i_stride_lowres = frame->i_stride[0]/2 + 32;
 
89
        frame->i_stride_lowres = frame->i_stride[0]/2 + PADH;
82
90
        frame->i_lines_lowres = frame->i_lines[0]/2;
83
91
        for( i = 0; i < 4; i++ )
84
92
        {
85
 
            CHECKED_MALLOC( frame->buffer[7+i],
86
 
                            frame->i_stride_lowres * ( frame->i_lines[0]/2 + 64 ) );
87
 
            frame->lowres[i] = ((uint8_t*)frame->buffer[7+i]) +
88
 
                                frame->i_stride_lowres * 32 + 32;
 
93
            CHECKED_MALLOC( frame->buffer_lowres[i],
 
94
                            frame->i_stride_lowres * ( frame->i_lines[0]/2 + 2*i_padv ) );
 
95
            frame->lowres[i] = ((uint8_t*)frame->buffer_lowres[i]) +
 
96
                                frame->i_stride_lowres * i_padv + PADH;
89
97
        }
90
98
    }
91
99
 
92
100
    if( h->param.analyse.i_me_method == X264_ME_ESA )
93
101
    {
94
 
        CHECKED_MALLOC( frame->buffer[11],
95
 
                        2 * frame->i_stride[0] * (frame->i_lines[0] + 64) * sizeof(uint16_t) );
96
 
        frame->integral = (uint16_t*)frame->buffer[11] + frame->i_stride[0] * 32 + 32;
 
102
        CHECKED_MALLOC( frame->buffer[7],
 
103
                        2 * frame->i_stride[0] * (frame->i_lines[0] + 2*i_padv) * sizeof(uint16_t) );
 
104
        frame->integral = (uint16_t*)frame->buffer[7] + frame->i_stride[0] * i_padv + PADH;
97
105
    }
98
106
 
99
107
    frame->i_poc = -1;
102
110
    frame->i_pts = -1;
103
111
    frame->i_frame = -1;
104
112
    frame->i_frame_num = -1;
 
113
    frame->i_lines_completed = -1;
105
114
 
106
115
    CHECKED_MALLOC( frame->mb_type, i_mb_count * sizeof(int8_t));
107
116
    CHECKED_MALLOC( frame->mv[0], 2*16 * i_mb_count * sizeof(int16_t) );
123
132
        for( j = 0; j < h->param.i_bframe + 2; j++ )
124
133
            CHECKED_MALLOC( frame->i_row_satds[i][j], i_lines/16 * sizeof(int) );
125
134
 
 
135
    pthread_mutex_init( &frame->mutex, NULL );
 
136
    pthread_cond_init( &frame->cv, NULL );
 
137
 
126
138
    return frame;
127
139
 
128
140
fail:
133
145
void x264_frame_delete( x264_frame_t *frame )
134
146
{
135
147
    int i, j;
136
 
    for( i = 0; i < 12; i++ )
 
148
    for( i = 0; i < 8; i++ )
137
149
        x264_free( frame->buffer[i] );
 
150
    for( i = 0; i < 4; i++ )
 
151
        x264_free( frame->buffer_lowres[i] );
138
152
    for( i = 0; i < X264_BFRAME_MAX+2; i++ )
139
153
        for( j = 0; j < X264_BFRAME_MAX+2; j++ )
140
154
            x264_free( frame->i_row_satds[i][j] );
145
159
    x264_free( frame->mv[1] );
146
160
    x264_free( frame->ref[0] );
147
161
    x264_free( frame->ref[1] );
 
162
    pthread_mutex_destroy( &frame->mutex );
 
163
    pthread_cond_destroy( &frame->cv );
148
164
    x264_free( frame );
149
165
}
150
166
 
151
167
void x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src )
152
168
{
 
169
    int i_csp = src->img.i_csp & X264_CSP_MASK;
153
170
    dst->i_type     = src->i_type;
154
171
    dst->i_qpplus1  = src->i_qpplus1;
155
172
    dst->i_pts      = src->i_pts;
156
173
 
157
 
    switch( src->img.i_csp & X264_CSP_MASK )
158
 
    {
159
 
        case X264_CSP_I420:
160
 
            h->csp.i420( dst, &src->img, h->param.i_width, h->param.i_height );
161
 
            break;
162
 
        case X264_CSP_YV12:
163
 
            h->csp.yv12( dst, &src->img, h->param.i_width, h->param.i_height );
164
 
            break;
165
 
        case X264_CSP_I422:
166
 
            h->csp.i422( dst, &src->img, h->param.i_width, h->param.i_height );
167
 
            break;
168
 
        case X264_CSP_I444:
169
 
            h->csp.i444( dst, &src->img, h->param.i_width, h->param.i_height );
170
 
            break;
171
 
        case X264_CSP_YUYV:
172
 
            h->csp.yuyv( dst, &src->img, h->param.i_width, h->param.i_height );
173
 
            break;
174
 
        case X264_CSP_RGB:
175
 
            h->csp.rgb( dst, &src->img, h->param.i_width, h->param.i_height );
176
 
            break;
177
 
        case X264_CSP_BGR:
178
 
            h->csp.bgr( dst, &src->img, h->param.i_width, h->param.i_height );
179
 
            break;
180
 
        case X264_CSP_BGRA:
181
 
            h->csp.bgra( dst, &src->img, h->param.i_width, h->param.i_height );
182
 
            break;
183
 
 
184
 
        default:
185
 
            x264_log( h, X264_LOG_ERROR, "Arg invalid CSP\n" );
186
 
            break;
187
 
    }
 
174
    if( i_csp <= X264_CSP_NONE  || i_csp >= X264_CSP_MAX )
 
175
        x264_log( h, X264_LOG_ERROR, "Arg invalid CSP\n" );
 
176
    else
 
177
        h->csp.convert[i_csp]( &h->mc, dst, &src->img, h->param.i_width, h->param.i_height );
188
178
}
189
179
 
190
180
 
191
181
 
192
 
static void plane_expand_border( uint8_t *pix, int i_stride, int i_height, int i_pad )
 
182
static void plane_expand_border( uint8_t *pix, int i_stride, int i_width, int i_height, int i_padh, int i_padv, int b_pad_top, int b_pad_bottom )
193
183
{
194
184
#define PPIXEL(x, y) ( pix + (x) + (y)*i_stride )
195
 
    const int i_width = i_stride - 2*i_pad;
196
185
    int y;
197
 
 
198
186
    for( y = 0; y < i_height; y++ )
199
187
    {
200
188
        /* left band */
201
 
        memset( PPIXEL(-i_pad, y), PPIXEL(0, y)[0], i_pad );
 
189
        memset( PPIXEL(-i_padh, y), PPIXEL(0, y)[0], i_padh );
202
190
        /* right band */
203
 
        memset( PPIXEL(i_width, y), PPIXEL(i_width-1, y)[0], i_pad );
 
191
        memset( PPIXEL(i_width, y), PPIXEL(i_width-1, y)[0], i_padh );
204
192
    }
205
193
    /* upper band */
206
 
    for( y = 0; y < i_pad; y++ )
207
 
        memcpy( PPIXEL(-i_pad, -y-1), PPIXEL(-i_pad, 0), i_stride );
 
194
    if( b_pad_top )
 
195
    for( y = 0; y < i_padv; y++ )
 
196
        memcpy( PPIXEL(-i_padh, -y-1), PPIXEL(-i_padh, 0), i_width+2*i_padh );
208
197
    /* lower band */
209
 
    for( y = 0; y < i_pad; y++ )
210
 
        memcpy( PPIXEL(-i_pad, i_height+y), PPIXEL(-i_pad, i_height-1), i_stride );
 
198
    if( b_pad_bottom )
 
199
    for( y = 0; y < i_padv; y++ )
 
200
        memcpy( PPIXEL(-i_padh, i_height+y), PPIXEL(-i_padh, i_height-1), i_width+2*i_padh );
211
201
#undef PPIXEL
212
202
}
213
203
 
214
 
void x264_frame_expand_border( x264_frame_t *frame )
 
204
void x264_frame_expand_border( x264_t *h, x264_frame_t *frame, int mb_y, int b_end )
215
205
{
216
206
    int i;
 
207
    int b_start = !mb_y;
 
208
    if( mb_y & h->sh.b_mbaff )
 
209
        return;
217
210
    for( i = 0; i < frame->i_plane; i++ )
218
211
    {
219
 
        int i_pad = i ? 16 : 32;
220
 
        plane_expand_border( frame->plane[i], frame->i_stride[i], frame->i_lines[i], i_pad );
 
212
        int stride = frame->i_stride[i];
 
213
        int width = 16*h->sps->i_mb_width >> !!i;
 
214
        int height = (b_end ? 16*(h->sps->i_mb_height - mb_y) >> h->sh.b_mbaff : 16) >> !!i;
 
215
        int padh = PADH >> !!i;
 
216
        int padv = PADV >> !!i;
 
217
        // buffer: 2 chroma, 3 luma (rounded to 4) because deblocking goes beyond the top of the mb
 
218
        uint8_t *pix = frame->plane[i] + X264_MAX(0, (16*mb_y-4)*stride >> !!i);
 
219
        if( b_end && !b_start )
 
220
            height += 4 >> (!!i + h->sh.b_mbaff);
 
221
        if( h->sh.b_mbaff )
 
222
        {
 
223
            plane_expand_border( pix, stride*2, width, height, padh, padv, b_start, b_end );
 
224
            plane_expand_border( pix+stride, stride*2, width, height, padh, padv, b_start, b_end );
 
225
        }
 
226
        else
 
227
        {
 
228
            plane_expand_border( pix, stride, width, height, padh, padv, b_start, b_end );
 
229
        }
221
230
    }
222
231
}
223
232
 
224
 
void x264_frame_expand_border_filtered( x264_frame_t *frame )
 
233
void x264_frame_expand_border_filtered( x264_t *h, x264_frame_t *frame, int mb_y, int b_end )
225
234
{
226
235
    /* during filtering, 8 extra pixels were filtered on each edge. 
227
236
       we want to expand border from the last filtered pixel */
 
237
    int b_start = !mb_y;
 
238
    int stride = frame->i_stride[0];
 
239
    int width = 16*h->sps->i_mb_width + 16;
 
240
    int height = b_end ? (16*(h->sps->i_mb_height - mb_y) >> h->sh.b_mbaff) + 16 : 16;
 
241
    int padh = PADH - 8;
 
242
    int padv = PADV - 8;
228
243
    int i;
229
244
    for( i = 1; i < 4; i++ )
230
 
        plane_expand_border( frame->filtered[i] - 8*frame->i_stride[0] - 8, frame->i_stride[0], frame->i_lines[0]+2*8, 24 );
 
245
    {
 
246
        // buffer: 8 luma, to match the hpel filter
 
247
        uint8_t *pix = frame->filtered[i] + (16*mb_y - (8 << h->sh.b_mbaff)) * stride - 8;
 
248
        if( h->sh.b_mbaff )
 
249
        {
 
250
            plane_expand_border( pix, stride*2, width, height, padh, padv, b_start, b_end );
 
251
            plane_expand_border( pix+stride, stride*2, width, height, padh, padv, b_start, b_end );
 
252
        }
 
253
        else
 
254
        {
 
255
            plane_expand_border( pix, stride, width, height, padh, padv, b_start, b_end );
 
256
        }
 
257
    }
231
258
}
232
259
 
233
260
void x264_frame_expand_border_lowres( x264_frame_t *frame )
234
261
{
235
262
    int i;
236
263
    for( i = 0; i < 4; i++ )
237
 
        plane_expand_border( frame->lowres[i], frame->i_stride_lowres, frame->i_lines_lowres, 32 );
 
264
        plane_expand_border( frame->lowres[i], frame->i_stride_lowres, frame->i_stride_lowres - 2*PADH, frame->i_lines_lowres, PADH, PADV, 1, 1 );
238
265
}
239
266
 
240
267
void x264_frame_expand_border_mod16( x264_t *h, x264_frame_t *frame )
257
284
        }
258
285
        if( i_pady )
259
286
        {
 
287
            //FIXME interlace? or just let it pad using the wrong field
260
288
            for( y = i_height; y < i_height + i_pady; y++ )
261
289
                memcpy( &frame->plane[i][y*frame->i_stride[i]],
262
290
                        &frame->plane[i][(i_height-1)*frame->i_stride[i]],
496
524
    }
497
525
}
498
526
 
499
 
void x264_frame_deblocking_filter( x264_t *h, int i_slice_type )
 
527
void x264_frame_deblock_row( x264_t *h, int mb_y )
500
528
{
501
529
    const int s8x8 = 2 * h->mb.i_mb_stride;
502
530
    const int s4x4 = 4 * h->mb.i_mb_stride;
503
 
 
504
 
    int mb_y, mb_x;
505
 
 
506
 
    for( mb_y = 0, mb_x = 0; mb_y < h->sps->i_mb_height; )
 
531
    const int b_interlaced = h->sh.b_mbaff;
 
532
    const int mvy_limit = 4 >> b_interlaced;
 
533
    int mb_x;
 
534
 
 
535
    int i_stride2[3] = { h->fdec->i_stride[0] << b_interlaced,
 
536
                         h->fdec->i_stride[1] << b_interlaced,
 
537
                         h->fdec->i_stride[2] << b_interlaced };
 
538
 
 
539
    for( mb_x = 0; mb_x < h->sps->i_mb_width; )
507
540
    {
508
541
        const int mb_xy  = mb_y * h->mb.i_mb_stride + mb_x;
509
542
        const int mb_8x8 = 2 * s8x8 * mb_y + 2 * mb_x;
512
545
        const int i_edge_end = (h->mb.type[mb_xy] == P_SKIP) ? 1 : 4;
513
546
        int i_edge, i_dir;
514
547
 
 
548
        int i_pix_y[3] = { 16*mb_y*h->fdec->i_stride[0] + 16*mb_x,
 
549
                            8*mb_y*h->fdec->i_stride[1] +  8*mb_x,
 
550
                            8*mb_y*h->fdec->i_stride[2] +  8*mb_x };
 
551
        if( b_interlaced && (mb_y&1) )
 
552
        {
 
553
            i_pix_y[0] -= 15*h->fdec->i_stride[0];
 
554
            i_pix_y[1] -=  7*h->fdec->i_stride[1];
 
555
            i_pix_y[2] -=  7*h->fdec->i_stride[2];
 
556
        }
 
557
 
 
558
        x264_prefetch_fenc( h, h->fdec, mb_x, mb_y );
 
559
 
515
560
        /* cavlc + 8x8 transform stores nnz per 16 coeffs for the purpose of
516
561
         * entropy coding, but per 64 coeffs for the purpose of deblocking */
517
562
        if( !h->param.b_cabac && b_8x8_transform )
527
572
         * i_dir == 1 -> horizontal edge */
528
573
        for( i_dir = 0; i_dir < 2; i_dir++ )
529
574
        {
530
 
            int i_start = (i_dir ? mb_y : mb_x) ? 0 : 1;
 
575
            int i_start = (i_dir ? (mb_y <= b_interlaced) : (mb_x == 0));
531
576
            int i_qp, i_qpn;
532
577
 
533
578
            for( i_edge = i_start; i_edge < i_edge_end; i_edge++ )
542
587
                mbn_8x8 = i_edge > 0 ? mb_8x8 : ( i_dir == 0 ? mb_8x8 - 2 : mb_8x8 - 2 * s8x8 );
543
588
                mbn_4x4 = i_edge > 0 ? mb_4x4 : ( i_dir == 0 ? mb_4x4 - 4 : mb_4x4 - 4 * s4x4 );
544
589
 
 
590
                if( b_interlaced && i_edge == 0 && i_dir == 1 )
 
591
                {
 
592
                    mbn_xy -= h->mb.i_mb_stride;
 
593
                    mbn_8x8 -= 2 * s8x8;
 
594
                    mbn_4x4 -= 4 * s4x4;
 
595
                }
 
596
 
545
597
                /* *** Get bS for each 4px for the current edge *** */
546
598
                if( IS_INTRA( h->mb.type[mb_xy] ) || IS_INTRA( h->mb.type[mbn_xy] ) )
547
599
                {
548
 
                    bS[0] = bS[1] = bS[2] = bS[3] = ( i_edge == 0 ? 4 : 3 );
 
600
                    bS[0] = bS[1] = bS[2] = bS[3] = ( i_edge == 0 && !(b_interlaced && i_dir) ? 4 : 3 );
549
601
                }
550
602
                else
551
603
                {
577
629
 
578
630
                            bS[i] = 0;
579
631
 
580
 
                            for( l = 0; l < 1 + (i_slice_type == SLICE_TYPE_B); l++ )
 
632
                            for( l = 0; l < 1 + (h->sh.i_type == SLICE_TYPE_B); l++ )
581
633
                            {
582
634
                                if( h->mb.ref[l][i8p] != h->mb.ref[l][i8q] ||
583
635
                                    abs( h->mb.mv[l][i4p][0] - h->mb.mv[l][i4q][0] ) >= 4 ||
584
 
                                    abs( h->mb.mv[l][i4p][1] - h->mb.mv[l][i4q][1] ) >= 4 )
 
636
                                    abs( h->mb.mv[l][i4p][1] - h->mb.mv[l][i4q][1] ) >= mvy_limit )
585
637
                                {
586
638
                                    bS[i] = 1;
587
639
                                    break;
599
651
                if( i_dir == 0 )
600
652
                {
601
653
                    /* vertical edge */
602
 
                    deblock_edge( h, &h->fdec->plane[0][16*mb_y * h->fdec->i_stride[0] + 16*mb_x + 4*i_edge],
603
 
                                  h->fdec->i_stride[0], bS, (i_qp+i_qpn+1) >> 1, 0,
 
654
                    deblock_edge( h, &h->fdec->plane[0][i_pix_y[0] + 4*i_edge],
 
655
                                  i_stride2[0], bS, (i_qp+i_qpn+1) >> 1, 0,
604
656
                                  h->loopf.deblock_h_luma, h->loopf.deblock_h_luma_intra );
605
657
                    if( !(i_edge & 1) )
606
658
                    {
607
659
                        /* U/V planes */
608
660
                        int i_qpc = ( i_chroma_qp_table[x264_clip3( i_qp + h->pps->i_chroma_qp_index_offset, 0, 51 )] +
609
661
                                      i_chroma_qp_table[x264_clip3( i_qpn + h->pps->i_chroma_qp_index_offset, 0, 51 )] + 1 ) >> 1;
610
 
                        deblock_edge( h, &h->fdec->plane[1][8*(mb_y*h->fdec->i_stride[1]+mb_x)+2*i_edge],
611
 
                                      h->fdec->i_stride[1], bS, i_qpc, 1,
 
662
                        deblock_edge( h, &h->fdec->plane[1][i_pix_y[1] + 2*i_edge],
 
663
                                      i_stride2[1], bS, i_qpc, 1,
612
664
                                      h->loopf.deblock_h_chroma, h->loopf.deblock_h_chroma_intra );
613
 
                        deblock_edge( h, &h->fdec->plane[2][8*(mb_y*h->fdec->i_stride[2]+mb_x)+2*i_edge],
614
 
                                      h->fdec->i_stride[2], bS, i_qpc, 1,
 
665
                        deblock_edge( h, &h->fdec->plane[2][i_pix_y[2] + 2*i_edge],
 
666
                                      i_stride2[2], bS, i_qpc, 1,
615
667
                                      h->loopf.deblock_h_chroma, h->loopf.deblock_h_chroma_intra );
616
668
                    }
617
669
                }
618
670
                else
619
671
                {
620
672
                    /* horizontal edge */
621
 
                    deblock_edge( h, &h->fdec->plane[0][(16*mb_y + 4*i_edge) * h->fdec->i_stride[0] + 16*mb_x],
622
 
                                  h->fdec->i_stride[0], bS, (i_qp+i_qpn+1) >> 1, 0,
 
673
                    deblock_edge( h, &h->fdec->plane[0][i_pix_y[0] + 4*i_edge*i_stride2[0]],
 
674
                                  i_stride2[0], bS, (i_qp+i_qpn+1) >> 1, 0,
623
675
                                  h->loopf.deblock_v_luma, h->loopf.deblock_v_luma_intra );
624
676
                    /* U/V planes */
625
677
                    if( !(i_edge & 1) )
626
678
                    {
627
679
                        int i_qpc = ( i_chroma_qp_table[x264_clip3( i_qp + h->pps->i_chroma_qp_index_offset, 0, 51 )] +
628
680
                                      i_chroma_qp_table[x264_clip3( i_qpn + h->pps->i_chroma_qp_index_offset, 0, 51 )] + 1 ) >> 1;
629
 
                        deblock_edge( h, &h->fdec->plane[1][8*(mb_y*h->fdec->i_stride[1]+mb_x)+2*i_edge*h->fdec->i_stride[1]],
630
 
                                      h->fdec->i_stride[1], bS, i_qpc, 1,
 
681
                        deblock_edge( h, &h->fdec->plane[1][i_pix_y[1] + 2*i_edge*i_stride2[1]],
 
682
                                      i_stride2[1], bS, i_qpc, 1,
631
683
                                      h->loopf.deblock_v_chroma, h->loopf.deblock_v_chroma_intra );
632
 
                        deblock_edge( h, &h->fdec->plane[2][8*(mb_y*h->fdec->i_stride[2]+mb_x)+2*i_edge*h->fdec->i_stride[2]],
633
 
                                      h->fdec->i_stride[2], bS, i_qpc, 1,
 
684
                        deblock_edge( h, &h->fdec->plane[2][i_pix_y[2] + 2*i_edge*i_stride2[2]],
 
685
                                      i_stride2[2], bS, i_qpc, 1,
634
686
                                      h->loopf.deblock_v_chroma, h->loopf.deblock_v_chroma_intra );
635
687
                    }
636
688
                }
637
689
            }
638
690
        }
639
691
 
640
 
        /* newt mb */
641
 
        mb_x++;
642
 
        if( mb_x >= h->sps->i_mb_width )
643
 
        {
644
 
            mb_x = 0;
645
 
            mb_y++;
646
 
        }
 
692
        /* next mb */
 
693
        if( !b_interlaced || (mb_y&1) )
 
694
            mb_x++;
 
695
        mb_y ^= b_interlaced;
647
696
    }
648
697
}
649
698
 
 
699
void x264_frame_deblock( x264_t *h )
 
700
{
 
701
    int mb_y;
 
702
    for( mb_y = 0; mb_y < h->sps->i_mb_height; mb_y += 1 + h->sh.b_mbaff )
 
703
        x264_frame_deblock_row( h, mb_y );
 
704
}
 
705
 
650
706
#ifdef HAVE_MMXEXT
651
707
void x264_deblock_v_chroma_mmxext( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 );
652
708
void x264_deblock_h_chroma_mmxext( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 );
701
757
#endif
702
758
}
703
759
 
 
760
 
 
761
/* threading */
 
762
 
 
763
#ifdef HAVE_PTHREAD
 
764
void x264_frame_cond_broadcast( x264_frame_t *frame, int i_lines_completed )
 
765
{
 
766
    pthread_mutex_lock( &frame->mutex );
 
767
    frame->i_lines_completed = i_lines_completed;
 
768
    pthread_cond_broadcast( &frame->cv );
 
769
    pthread_mutex_unlock( &frame->mutex );
 
770
}
 
771
 
 
772
void x264_frame_cond_wait( x264_frame_t *frame, int i_lines_completed )
 
773
{
 
774
    pthread_mutex_lock( &frame->mutex );
 
775
    while( frame->i_lines_completed < i_lines_completed )
 
776
        pthread_cond_wait( &frame->cv, &frame->mutex );
 
777
    pthread_mutex_unlock( &frame->mutex );
 
778
}
 
779
 
 
780
#else
 
781
void x264_frame_cond_broadcast( x264_frame_t *frame, int i_lines_completed )
 
782
{}
 
783
void x264_frame_cond_wait( x264_frame_t *frame, int i_lines_completed )
 
784
{}
 
785
#endif
 
786
 
 
787
 
 
788
/* list operators */
 
789
 
 
790
void x264_frame_push( x264_frame_t **list, x264_frame_t *frame )
 
791
{
 
792
    int i = 0;
 
793
    while( list[i] ) i++;
 
794
    list[i] = frame;
 
795
}
 
796
 
 
797
x264_frame_t *x264_frame_pop( x264_frame_t **list )
 
798
{
 
799
    x264_frame_t *frame;
 
800
    int i = 0;
 
801
    assert( list[0] );
 
802
    while( list[i+1] ) i++;
 
803
    frame = list[i];
 
804
    list[i] = NULL;
 
805
    return frame;
 
806
}
 
807
 
 
808
void x264_frame_unshift( x264_frame_t **list, x264_frame_t *frame )
 
809
{
 
810
    int i = 0;
 
811
    while( list[i] ) i++;
 
812
    while( i-- )
 
813
        list[i+1] = list[i];
 
814
    list[0] = frame;
 
815
}
 
816
 
 
817
x264_frame_t *x264_frame_shift( x264_frame_t **list )
 
818
{
 
819
    x264_frame_t *frame = list[0];
 
820
    int i;
 
821
    for( i = 0; list[i]; i++ )
 
822
        list[i] = list[i+1];
 
823
    assert(frame);
 
824
    return frame;
 
825
}
 
826
 
 
827
void x264_frame_push_unused( x264_t *h, x264_frame_t *frame )
 
828
{
 
829
    assert( frame->i_reference_count > 0 );
 
830
    frame->i_reference_count--;
 
831
    if( frame->i_reference_count == 0 )
 
832
        x264_frame_push( h->frames.unused, frame );
 
833
    assert( h->frames.unused[ sizeof(h->frames.unused) / sizeof(*h->frames.unused) - 1 ] == NULL );
 
834
}
 
835
 
 
836
x264_frame_t *x264_frame_pop_unused( x264_t *h )
 
837
{
 
838
    x264_frame_t *frame;
 
839
    if( h->frames.unused[0] )
 
840
        frame = x264_frame_pop( h->frames.unused );
 
841
    else
 
842
        frame = x264_frame_new( h );
 
843
    assert( frame->i_reference_count == 0 );
 
844
    frame->i_reference_count = 1;
 
845
    return frame;
 
846
}
 
847
 
 
848
void x264_frame_sort( x264_frame_t **list, int b_dts )
 
849
{
 
850
    int i, b_ok;
 
851
    do {
 
852
        b_ok = 1;
 
853
        for( i = 0; list[i+1]; i++ )
 
854
        {
 
855
            int dtype = list[i]->i_type - list[i+1]->i_type;
 
856
            int dtime = list[i]->i_frame - list[i+1]->i_frame;
 
857
            int swap = b_dts ? dtype > 0 || ( dtype == 0 && dtime > 0 )
 
858
                             : dtime > 0;
 
859
            if( swap )
 
860
            {
 
861
                XCHG( x264_frame_t*, list[i], list[i+1] );
 
862
                b_ok = 0;
 
863
            }
 
864
        }
 
865
    } while( !b_ok );
 
866
}