cabac_context_init = &x264_cabac_context_init_PB[i_model];
}
- for( i = 0; i < 436; i++ )
+ for( i = 0; i < 460; i++ )
{
cb->state[i] = x264_clip3( (((*cabac_context_init)[i][0] * i_qp) >> 4) + (*cabac_context_init)[i][1], 1, 126 );
}
typedef struct
{
/* context */
- /* #436-459 are for interlacing, so are omitted for now */
- uint8_t state[436];
+ uint8_t state[460];
/* state */
int i_low;
p->b_cabac = atobool(value);
OPT("cabac-idc")
p->i_cabac_init_idc = atoi(value);
+ OPT("interlaced")
+ p->b_interlaced = atobool(value);
OPT("cqm")
{
if( strstr( value, "flat" ) )
#endif
#include <stdarg.h>
#include <stdlib.h>
+#include <assert.h>
#ifdef _MSC_VER
#define snprintf _snprintf
int i_frame_num;
+ int b_mbaff;
int b_field_pic;
int b_bottom_field;
int b_trellis;
int b_noise_reduction;
+ int b_interlaced;
+
/* Allowed qpel MV range to stay within the picture + emulated edge pixels */
int mv_min[2];
int mv_max[2];
int i_mb_type_left;
int i_mb_type_topleft;
int i_mb_type_topright;
+ int i_mb_prev_xy;
+ int i_mb_top_xy;
/* mb table */
int8_t *type; /* mb type */
int16_t (*mv[2])[2]; /* mb mv. set to 0 for intra mb */
int16_t (*mvd[2])[2]; /* mb mv difference with predict. set to 0 if intra. cabac only */
int8_t *ref[2]; /* mb ref. set to -1 if non used (intra or Lx only) */
- int16_t (*mvr[2][16])[2]; /* 16x16 mv for each possible ref */
+ int16_t (*mvr[2][32])[2]; /* 16x16 mv for each possible ref */
int8_t *skipbp; /* block pattern for SKIP or DIRECT (sub)mbs. B-frames + cabac only */
int8_t *mb_transform_size; /* transform_size_8x8_flag of each mb */
uint8_t *p_fdec[3];
/* pointer over mb of the references */
- uint8_t *p_fref[2][16][4+2]; /* last: lN, lH, lV, lHV, cU, cV */
+ int i_fref[2];
+ uint8_t *p_fref[2][32][4+2]; /* last: lN, lH, lV, lHV, cU, cV */
uint16_t *p_integral[2][16];
/* fref stride */
/* number of neighbors (top and left) that used 8x8 dct */
int i_neighbour_transform_size;
int b_transform_8x8_allowed;
+ int i_neighbour_interlaced;
} cache;
/* */
int b_direct_auto_write; /* analyse direct modes, to use and/or save */
/* B_direct and weighted prediction */
- int dist_scale_factor[16][16];
- int bipred_weight[16][16];
+ int dist_scale_factor[16][2];
+ int bipred_weight[32][4];
/* maps fref1[0]'s ref indices into the current list0 */
int map_col_to_list0_buf[2]; // for negative indices
int map_col_to_list0[16];
int i_mb_count_skip;
int i_mb_count_8x8dct[2];
int i_mb_count_size[7];
- int i_mb_count_ref[16];
+ int i_mb_count_ref[32];
/* Estimated (SATD) cost as Intra/Predicted frame */
/* XXX: both omit the cost of MBs coded as P_SKIP */
int i_intra_cost;
int64_t i_mb_count[5][19];
int64_t i_mb_count_8x8dct[2];
int64_t i_mb_count_size[2][7];
- int64_t i_mb_count_ref[2][16];
+ int64_t i_mb_count_ref[2][32];
/* */
int i_direct_score[2];
int i_direct_frames[2];
# include "ppc/dct.h"
#endif
+int x264_dct4_weight2_zigzag[2][16];
+int x264_dct8_weight2_zigzag[2][64];
static inline int clip_uint8( int a )
{
#endif
}
+void x264_dct_init_weights( void )
+{
+ int i, j;
+ for( j=0; j<2; j++ )
+ {
+ for( i=0; i<16; i++ )
+ x264_dct4_weight2_zigzag[j][i] = x264_dct4_weight2_tab[ x264_zigzag_scan4[j][i] ];
+ for( i=0; i<64; i++ )
+ x264_dct8_weight2_zigzag[j][i] = x264_dct8_weight2_tab[ x264_zigzag_scan8[j][i] ];
+ }
+}
+
W(0), W(1), W(0), W(1),
W(1), W(2), W(1), W(2)
};
-static const int x264_dct4_weight2_zigzag[16] = {
- W(0), W(1), W(1), W(0), W(2), W(0), W(1), W(1),
- W(1), W(1), W(2), W(0), W(2), W(1), W(1), W(2)
-};
#undef W
#define W(i) (i==0 ? FIX8(1.00000) :\
W(4), W(5), W(2), W(5), W(4), W(5), W(2), W(5),
W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1)
};
-static const int x264_dct8_weight2_zigzag[64] = {
- W(0), W(3), W(3), W(4), W(1), W(4), W(3), W(5),
- W(5), W(3), W(0), W(1), W(2), W(1), W(0), W(3),
- W(3), W(5), W(5), W(3), W(3), W(4), W(1), W(4),
- W(1), W(4), W(1), W(4), W(3), W(5), W(5), W(3),
- W(3), W(5), W(5), W(3), W(1), W(2), W(1), W(0),
- W(1), W(2), W(1), W(5), W(5), W(3), W(3), W(5),
- W(5), W(1), W(4), W(1), W(4), W(1), W(3), W(5),
- W(5), W(3), W(1), W(2), W(1), W(5), W(5), W(1)
-};
#undef W
+extern int x264_dct4_weight2_zigzag[2][16]; // [2] = {frame, field}
+extern int x264_dct8_weight2_zigzag[2][64];
+
typedef struct
{
// pix1 stride = FENC_STRIDE
} x264_dct_function_t;
void x264_dct_init( int cpu, x264_dct_function_t *dctf );
+void x264_dct_init_weights( void );
#endif
#include "common.h"
+#define PADH 32
+#define PADV 32
+
x264_frame_t *x264_frame_new( x264_t *h )
{
x264_frame_t *frame = x264_malloc( sizeof(x264_frame_t) );
int i_mb_count = h->mb.i_mb_count;
int i_stride;
int i_lines;
+ int i_padv = PADV << h->param.b_interlaced;
if( !frame ) return NULL;
memset( frame, 0, sizeof(x264_frame_t) );
/* allocate frame data (+64 for extra data for me) */
- i_stride = ( ( h->param.i_width + 15 )&0xfffff0 )+ 64;
- i_lines = ( ( h->param.i_height + 15 )&0xfffff0 );
+ i_stride = ( ( h->param.i_width + 15 ) & -16 )+ 2*PADH;
+ i_lines = ( ( h->param.i_height + 15 ) & -16 );
+ if( h->param.b_interlaced )
+ i_lines = ( i_lines + 31 ) & -32;
frame->i_plane = 3;
for( i = 0; i < 3; i++ )
frame->i_stride[i] = i_stride / i_divw;
frame->i_lines[i] = i_lines / i_divh;
CHECKED_MALLOC( frame->buffer[i],
- frame->i_stride[i] * ( frame->i_lines[i] + 64 / i_divh ) );
+ frame->i_stride[i] * ( frame->i_lines[i] + 2*i_padv / i_divh ) );
+
frame->plane[i] = ((uint8_t*)frame->buffer[i]) +
- frame->i_stride[i] * 32 / i_divh + 32 / i_divw;
+ frame->i_stride[i] * i_padv / i_divh + PADH / i_divw;
}
frame->i_stride[3] = 0;
frame->i_lines[3] = 0;
for( i = 0; i < 3; i++ )
{
CHECKED_MALLOC( frame->buffer[4+i],
- frame->i_stride[0] * ( frame->i_lines[0] + 64 ) );
+ frame->i_stride[0] * ( frame->i_lines[0] + 2*i_padv ) );
frame->filtered[i+1] = ((uint8_t*)frame->buffer[4+i]) +
- frame->i_stride[0] * 32 + 32;
+ frame->i_stride[0] * i_padv + PADH;
}
if( h->frames.b_have_lowres )
{
- frame->i_stride_lowres = frame->i_stride[0]/2 + 32;
+ frame->i_stride_lowres = frame->i_stride[0]/2 + PADH;
frame->i_lines_lowres = frame->i_lines[0]/2;
for( i = 0; i < 4; i++ )
{
- CHECKED_MALLOC( frame->buffer[7+i],
- frame->i_stride_lowres * ( frame->i_lines[0]/2 + 64 ) );
- frame->lowres[i] = ((uint8_t*)frame->buffer[7+i]) +
- frame->i_stride_lowres * 32 + 32;
+ CHECKED_MALLOC( frame->buffer_lowres[i],
+ frame->i_stride_lowres * ( frame->i_lines[0]/2 + 2*i_padv ) );
+ frame->lowres[i] = ((uint8_t*)frame->buffer_lowres[i]) +
+ frame->i_stride_lowres * i_padv + PADH;
}
}
if( h->param.analyse.i_me_method == X264_ME_ESA )
{
- CHECKED_MALLOC( frame->buffer[11],
- 2 * frame->i_stride[0] * (frame->i_lines[0] + 64) * sizeof(uint16_t) );
- frame->integral = (uint16_t*)frame->buffer[11] + frame->i_stride[0] * 32 + 32;
+ CHECKED_MALLOC( frame->buffer[7],
+ 2 * frame->i_stride[0] * (frame->i_lines[0] + 2*i_padv) * sizeof(uint16_t) );
+ frame->integral = (uint16_t*)frame->buffer[7] + frame->i_stride[0] * i_padv + PADH;
}
frame->i_poc = -1;
void x264_frame_delete( x264_frame_t *frame )
{
int i, j;
- for( i = 0; i < 12; i++ )
+ for( i = 0; i < 8; i++ )
x264_free( frame->buffer[i] );
+ for( i = 0; i < 4; i++ )
+ x264_free( frame->buffer_lowres[i] );
for( i = 0; i < X264_BFRAME_MAX+2; i++ )
for( j = 0; j < X264_BFRAME_MAX+2; j++ )
x264_free( frame->i_row_satds[i][j] );
-static void plane_expand_border( uint8_t *pix, int i_stride, int i_height, int i_pad )
+static void plane_expand_border( uint8_t *pix, int i_stride, int i_width, int i_height, int i_padh, int i_padv )
{
#define PPIXEL(x, y) ( pix + (x) + (y)*i_stride )
- const int i_width = i_stride - 2*i_pad;
int y;
-
for( y = 0; y < i_height; y++ )
{
/* left band */
- memset( PPIXEL(-i_pad, y), PPIXEL(0, y)[0], i_pad );
+ memset( PPIXEL(-i_padh, y), PPIXEL(0, y)[0], i_padh );
/* right band */
- memset( PPIXEL(i_width, y), PPIXEL(i_width-1, y)[0], i_pad );
+ memset( PPIXEL(i_width, y), PPIXEL(i_width-1, y)[0], i_padh );
}
/* upper band */
- for( y = 0; y < i_pad; y++ )
- memcpy( PPIXEL(-i_pad, -y-1), PPIXEL(-i_pad, 0), i_stride );
+ for( y = 0; y < i_padv; y++ )
+ memcpy( PPIXEL(-i_padh, -y-1), PPIXEL(-i_padh, 0), i_width+2*i_padh );
/* lower band */
- for( y = 0; y < i_pad; y++ )
- memcpy( PPIXEL(-i_pad, i_height+y), PPIXEL(-i_pad, i_height-1), i_stride );
+ for( y = 0; y < i_padv; y++ )
+ memcpy( PPIXEL(-i_padh, i_height+y), PPIXEL(-i_padh, i_height-1), i_width+2*i_padh );
#undef PPIXEL
}
-void x264_frame_expand_border( x264_frame_t *frame )
+void x264_frame_expand_border( x264_t *h, x264_frame_t *frame )
{
int i;
for( i = 0; i < frame->i_plane; i++ )
{
- int i_pad = i ? 16 : 32;
- plane_expand_border( frame->plane[i], frame->i_stride[i], frame->i_lines[i], i_pad );
+ int stride = frame->i_stride[i];
+ int width = 16*h->sps->i_mb_width >> !!i;
+ int height = 16*h->sps->i_mb_height >> !!i;
+ int padh = PADH >> !!i;
+ int padv = PADV >> !!i;
+ if( h->param.b_interlaced )
+ {
+ plane_expand_border( frame->plane[i], stride*2, width, height>>1, padh, padv );
+ plane_expand_border( frame->plane[i]+stride, stride*2, width, height>>1, padh, padv );
+ }
+ else
+ {
+ plane_expand_border( frame->plane[i], stride, width, height, padh, padv );
+ }
}
}
-void x264_frame_expand_border_filtered( x264_frame_t *frame )
+void x264_frame_expand_border_filtered( x264_t *h, x264_frame_t *frame )
{
/* during filtering, 8 extra pixels were filtered on each edge.
we want to expand border from the last filtered pixel */
+ int stride = frame->i_stride[0];
+ int width = 16*h->sps->i_mb_width;
+ int height = 16*h->sps->i_mb_height;
+ int padh = PADH - 8;
+ int padv = PADV - 8;
int i;
for( i = 1; i < 4; i++ )
- plane_expand_border( frame->filtered[i] - 8*frame->i_stride[0] - 8, frame->i_stride[0], frame->i_lines[0]+2*8, 24 );
+ {
+ if( h->param.b_interlaced )
+ {
+ plane_expand_border( frame->filtered[i] - 16*stride - 8, stride*2, width+16, (height>>1)+16, padh, padv );
+ plane_expand_border( frame->filtered[i] - 15*stride - 8, stride*2, width+16, (height>>1)+16, padh, padv );
+ }
+ else
+ {
+ plane_expand_border( frame->filtered[i] - 8*stride - 8, stride, width+16, height+16, padh, padv );
+ }
+ }
}
void x264_frame_expand_border_lowres( x264_frame_t *frame )
{
int i;
for( i = 0; i < 4; i++ )
- plane_expand_border( frame->lowres[i], frame->i_stride_lowres, frame->i_lines_lowres, 32 );
+ plane_expand_border( frame->lowres[i], frame->i_stride_lowres, frame->i_stride_lowres - 2*PADH, frame->i_lines_lowres, PADH, PADV );
}
void x264_frame_expand_border_mod16( x264_t *h, x264_frame_t *frame )
}
if( i_pady )
{
+ //FIXME interlace? or just let it pad using the wrong field
for( y = i_height; y < i_height + i_pady; y++ )
memcpy( &frame->plane[i][y*frame->i_stride[i]],
&frame->plane[i][(i_height-1)*frame->i_stride[i]],
{
const int s8x8 = 2 * h->mb.i_mb_stride;
const int s4x4 = 4 * h->mb.i_mb_stride;
-
+ const int b_interlaced = h->param.b_interlaced;
+ const int mvy_limit = 4 >> b_interlaced;
int mb_y, mb_x;
+ int i_stride2[3] = { h->fdec->i_stride[0] << b_interlaced,
+ h->fdec->i_stride[1] << b_interlaced,
+ h->fdec->i_stride[2] << b_interlaced };
+
for( mb_y = 0, mb_x = 0; mb_y < h->sps->i_mb_height; )
{
const int mb_xy = mb_y * h->mb.i_mb_stride + mb_x;
const int i_edge_end = (h->mb.type[mb_xy] == P_SKIP) ? 1 : 4;
int i_edge, i_dir;
+ int i_pix_y[3] = { 16*mb_y*h->fdec->i_stride[0] + 16*mb_x,
+ 8*mb_y*h->fdec->i_stride[1] + 8*mb_x,
+ 8*mb_y*h->fdec->i_stride[2] + 8*mb_x };
+ if( b_interlaced && (mb_y&1) )
+ {
+ i_pix_y[0] -= 15*h->fdec->i_stride[0];
+ i_pix_y[1] -= 7*h->fdec->i_stride[1];
+ i_pix_y[2] -= 7*h->fdec->i_stride[2];
+ }
+
/* cavlc + 8x8 transform stores nnz per 16 coeffs for the purpose of
* entropy coding, but per 64 coeffs for the purpose of deblocking */
if( !h->param.b_cabac && b_8x8_transform )
* i_dir == 1 -> horizontal edge */
for( i_dir = 0; i_dir < 2; i_dir++ )
{
- int i_start = (i_dir ? mb_y : mb_x) ? 0 : 1;
+ int i_start = (i_dir ? (mb_y <= b_interlaced) : (mb_x == 0));
int i_qp, i_qpn;
for( i_edge = i_start; i_edge < i_edge_end; i_edge++ )
mbn_8x8 = i_edge > 0 ? mb_8x8 : ( i_dir == 0 ? mb_8x8 - 2 : mb_8x8 - 2 * s8x8 );
mbn_4x4 = i_edge > 0 ? mb_4x4 : ( i_dir == 0 ? mb_4x4 - 4 : mb_4x4 - 4 * s4x4 );
+ if( b_interlaced && i_edge == 0 && i_dir == 1 )
+ {
+ mbn_xy -= h->mb.i_mb_stride;
+ mbn_8x8 -= 2 * s8x8;
+ mbn_4x4 -= 4 * s4x4;
+ }
+
/* *** Get bS for each 4px for the current edge *** */
if( IS_INTRA( h->mb.type[mb_xy] ) || IS_INTRA( h->mb.type[mbn_xy] ) )
{
- bS[0] = bS[1] = bS[2] = bS[3] = ( i_edge == 0 ? 4 : 3 );
+ bS[0] = bS[1] = bS[2] = bS[3] = ( i_edge == 0 && !(b_interlaced && i_dir) ? 4 : 3 );
}
else
{
{
if( h->mb.ref[l][i8p] != h->mb.ref[l][i8q] ||
abs( h->mb.mv[l][i4p][0] - h->mb.mv[l][i4q][0] ) >= 4 ||
- abs( h->mb.mv[l][i4p][1] - h->mb.mv[l][i4q][1] ) >= 4 )
+ abs( h->mb.mv[l][i4p][1] - h->mb.mv[l][i4q][1] ) >= mvy_limit )
{
bS[i] = 1;
break;
if( i_dir == 0 )
{
/* vertical edge */
- deblock_edge( h, &h->fdec->plane[0][16*mb_y * h->fdec->i_stride[0] + 16*mb_x + 4*i_edge],
- h->fdec->i_stride[0], bS, (i_qp+i_qpn+1) >> 1, 0,
+ deblock_edge( h, &h->fdec->plane[0][i_pix_y[0] + 4*i_edge],
+ i_stride2[0], bS, (i_qp+i_qpn+1) >> 1, 0,
h->loopf.deblock_h_luma, h->loopf.deblock_h_luma_intra );
if( !(i_edge & 1) )
{
/* U/V planes */
int i_qpc = ( i_chroma_qp_table[x264_clip3( i_qp + h->pps->i_chroma_qp_index_offset, 0, 51 )] +
i_chroma_qp_table[x264_clip3( i_qpn + h->pps->i_chroma_qp_index_offset, 0, 51 )] + 1 ) >> 1;
- 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], bS, i_qpc, 1,
+ deblock_edge( h, &h->fdec->plane[1][i_pix_y[1] + 2*i_edge],
+ i_stride2[1], bS, i_qpc, 1,
h->loopf.deblock_h_chroma, h->loopf.deblock_h_chroma_intra );
- 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], bS, i_qpc, 1,
+ deblock_edge( h, &h->fdec->plane[2][i_pix_y[2] + 2*i_edge],
+ i_stride2[2], bS, i_qpc, 1,
h->loopf.deblock_h_chroma, h->loopf.deblock_h_chroma_intra );
}
}
else
{
/* horizontal edge */
- deblock_edge( h, &h->fdec->plane[0][(16*mb_y + 4*i_edge) * h->fdec->i_stride[0] + 16*mb_x],
- h->fdec->i_stride[0], bS, (i_qp+i_qpn+1) >> 1, 0,
+ deblock_edge( h, &h->fdec->plane[0][i_pix_y[0] + 4*i_edge*i_stride2[0]],
+ i_stride2[0], bS, (i_qp+i_qpn+1) >> 1, 0,
h->loopf.deblock_v_luma, h->loopf.deblock_v_luma_intra );
/* U/V planes */
if( !(i_edge & 1) )
{
int i_qpc = ( i_chroma_qp_table[x264_clip3( i_qp + h->pps->i_chroma_qp_index_offset, 0, 51 )] +
i_chroma_qp_table[x264_clip3( i_qpn + h->pps->i_chroma_qp_index_offset, 0, 51 )] + 1 ) >> 1;
- 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]],
- h->fdec->i_stride[1], bS, i_qpc, 1,
+ deblock_edge( h, &h->fdec->plane[1][i_pix_y[1] + 2*i_edge*i_stride2[1]],
+ i_stride2[1], bS, i_qpc, 1,
h->loopf.deblock_v_chroma, h->loopf.deblock_v_chroma_intra );
- 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]],
- h->fdec->i_stride[2], bS, i_qpc, 1,
+ deblock_edge( h, &h->fdec->plane[2][i_pix_y[2] + 2*i_edge*i_stride2[2]],
+ i_stride2[2], bS, i_qpc, 1,
h->loopf.deblock_v_chroma, h->loopf.deblock_v_chroma_intra );
}
}
}
}
- /* newt mb */
- mb_x++;
+ /* next mb */
+ if( !b_interlaced || (mb_y&1) )
+ mb_x++;
if( mb_x >= h->sps->i_mb_width )
{
mb_x = 0;
mb_y++;
}
+ else
+ mb_y ^= b_interlaced;
}
}
/* for unrestricted mv we allocate more data than needed
* allocated data are stored in buffer */
- void *buffer[12];
+ void *buffer[8];
+ void *buffer_lowres[4];
/* motion data */
int8_t *mb_type;
void x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src );
-void x264_frame_expand_border( x264_frame_t *frame );
-void x264_frame_expand_border_filtered( x264_frame_t *frame );
+void x264_frame_expand_border( x264_t *h, x264_frame_t *frame );
+void x264_frame_expand_border_filtered( x264_t *h, x264_frame_t *frame );
void x264_frame_expand_border_lowres( x264_frame_t *frame );
void x264_frame_expand_border_mod16( x264_t *h, x264_frame_t *frame );
void x264_frame_deblocking_filter( x264_t *h, int i_slice_type );
-void x264_frame_filter( int cpu, x264_frame_t *frame );
+void x264_frame_filter( int cpu, x264_frame_t *frame, int b_interlaced );
void x264_frame_init_lowres( int cpu, x264_frame_t *frame );
void x264_deblock_init( int cpu, x264_deblock_function_t *pf );
}
if( h->mb.i_neighbour & MB_TOP )
{
- int i_mb_t = h->mb.i_mb_xy - h->mb.i_mb_stride;
+ int i_mb_t = h->mb.i_mb_top_xy;
if( !IS_SKIP( h->mb.type[i_mb_t] ) )
SET_MVP( mvr[i_mb_t] );
#undef SET_MVP
/* temporal predictors */
- if( h->fref0[0]->i_ref[0] > 0 )
+ /* FIXME temporal scaling w/ interlace */
+ if( h->fref0[0]->i_ref[0] > 0 && !h->sh.b_mbaff )
{
x264_frame_t *l0 = h->fref0[0];
int ref_col_cur, ref_col_prev = -1;
const int i8 = x264_scan8[0]+x+8*y;
const int i_ref = h->mb.cache.ref[0][i8];
const int mvx = x264_clip3( h->mb.cache.mv[0][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] );
- const int mvy = x264_clip3( h->mb.cache.mv[0][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] );
+ int mvy = x264_clip3( h->mb.cache.mv[0][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] );
h->mc.mc_luma( h->mb.pic.p_fref[0][i_ref], h->mb.pic.i_stride[0],
&h->mb.pic.p_fdec[0][4*y*FDEC_STRIDE+4*x], FDEC_STRIDE,
mvx + 4*4*x, mvy + 4*4*y, 4*width, 4*height );
+ // chroma is offset if MCing from a field of opposite parity
+ if( h->mb.b_interlaced & i_ref )
+ mvy += (h->mb.i_mb_y & 1)*4 - 2;
+
h->mc.mc_chroma( &h->mb.pic.p_fref[0][i_ref][4][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
&h->mb.pic.p_fdec[1][2*y*FDEC_STRIDE+2*x], FDEC_STRIDE,
mvx, mvy, 2*width, 2*height );
const int i8 = x264_scan8[0]+x+8*y;
const int i_ref = h->mb.cache.ref[1][i8];
const int mvx = x264_clip3( h->mb.cache.mv[1][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] );
- const int mvy = x264_clip3( h->mb.cache.mv[1][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] );
+ int mvy = x264_clip3( h->mb.cache.mv[1][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] );
h->mc.mc_luma( h->mb.pic.p_fref[1][i_ref], h->mb.pic.i_stride[0],
&h->mb.pic.p_fdec[0][4*y*FDEC_STRIDE+4*x], FDEC_STRIDE,
mvx + 4*4*x, mvy + 4*4*y, 4*width, 4*height );
+ if( h->mb.b_interlaced & i_ref )
+ mvy += (h->mb.i_mb_y & 1)*4 - 2;
+
h->mc.mc_chroma( &h->mb.pic.p_fref[1][i_ref][4][2*y*h->mb.pic.i_stride[1]+2*x], h->mb.pic.i_stride[1],
&h->mb.pic.p_fdec[1][2*y*FDEC_STRIDE+2*x], FDEC_STRIDE,
mvx, mvy, 2*width, 2*height );
const int i_ref1 = h->mb.cache.ref[1][i8];
const int mvx1 = x264_clip3( h->mb.cache.mv[1][i8][0], h->mb.mv_min[0], h->mb.mv_max[0] );
- const int mvy1 = x264_clip3( h->mb.cache.mv[1][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] );
+ int mvy1 = x264_clip3( h->mb.cache.mv[1][i8][1], h->mb.mv_min[1], h->mb.mv_max[1] );
DECLARE_ALIGNED( uint8_t, tmp[16*16], 16 );
int i_mode = x264_size2pixel[height][width];
h->mc.mc_luma( h->mb.pic.p_fref[1][i_ref1], h->mb.pic.i_stride[0],
tmp, 16, mvx1 + 4*4*x, mvy1 + 4*4*y, 4*width, 4*height );
+ if( h->mb.b_interlaced & i_ref1 )
+ mvy1 += (h->mb.i_mb_y & 1)*4 - 2;
+
if( h->param.analyse.b_weighted_bipred )
{
const int i_ref0 = h->mb.cache.ref[0][i8];
h->mb.i_b8_stride = h->sps->i_mb_width * 2;
h->mb.i_b4_stride = h->sps->i_mb_width * 4;
+ h->mb.b_interlaced = h->param.b_interlaced;
+
CHECKED_MALLOC( h->mb.qp, i_mb_count * sizeof(int8_t) );
CHECKED_MALLOC( h->mb.cbp, i_mb_count * sizeof(int16_t) );
CHECKED_MALLOC( h->mb.skipbp, i_mb_count * sizeof(int8_t) );
for( i=0; i<2; i++ )
{
- int i_refs = (i ? 1 : h->param.i_frame_reference) + h->param.b_bframe_pyramid;
- for( j=0; j < i_refs && j < 16; j++ )
+ int i_refs = X264_MIN(16, (i ? 1 : h->param.i_frame_reference) + h->param.b_bframe_pyramid) << h->param.b_interlaced;
+ for( j=0; j < i_refs; j++ )
CHECKED_MALLOC( h->mb.mvr[i][j], 2 * i_mb_count * sizeof(int16_t) );
}
void x264_macroblock_cache_load( x264_t *h, int i_mb_x, int i_mb_y )
{
- const int i_mb_4x4 = 4*(i_mb_y * h->mb.i_b4_stride + i_mb_x);
- const int i_mb_8x8 = 2*(i_mb_y * h->mb.i_b8_stride + i_mb_x);
-
int i_mb_xy = i_mb_y * h->mb.i_mb_stride + i_mb_x;
- int i_top_xy = i_mb_xy - h->mb.i_mb_stride;
+ int i_mb_4x4 = 4*(i_mb_y * h->mb.i_b4_stride + i_mb_x);
+ int i_mb_8x8 = 2*(i_mb_y * h->mb.i_b8_stride + i_mb_x);
+ int i_top_y = i_mb_y - (1 << h->mb.b_interlaced);
+ int i_top_xy = i_top_y * h->mb.i_mb_stride + i_mb_x;
+ int i_top_4x4 = (4*i_top_y+3) * h->mb.i_b4_stride + 4*i_mb_x;
+ int i_top_8x8 = (2*i_top_y+1) * h->mb.i_b8_stride + 2*i_mb_x;
int i_left_xy = -1;
int i_top_type = -1; /* gcc warn */
int i_left_type= -1;
int i;
+ assert( h->mb.i_b8_stride == 2*h->mb.i_mb_stride );
+ assert( h->mb.i_b4_stride == 4*h->mb.i_mb_stride );
+
/* init index */
h->mb.i_mb_x = i_mb_x;
h->mb.i_mb_y = i_mb_y;
h->mb.i_mb_xy = i_mb_xy;
h->mb.i_b8_xy = i_mb_8x8;
h->mb.i_b4_xy = i_mb_4x4;
+ h->mb.i_mb_top_xy = i_top_xy;
h->mb.i_neighbour = 0;
- /* fdec: fenc:
- * yyyyyyy
- * yYYYY YYYY
- * yYYYY YYYY
- * yYYYY YYYY
- * yYYYY YYYY
- * uuu vvv UUVV
- * uUU vVV UUVV
- * uUU vVV
- */
- h->mb.pic.p_fenc[0] = h->mb.pic.fenc_buf;
- h->mb.pic.p_fenc[1] = h->mb.pic.fenc_buf + 16*FENC_STRIDE;
- h->mb.pic.p_fenc[2] = h->mb.pic.fenc_buf + 16*FENC_STRIDE + 8;
- h->mb.pic.p_fdec[0] = h->mb.pic.fdec_buf + 2*FDEC_STRIDE;
- h->mb.pic.p_fdec[1] = h->mb.pic.fdec_buf + 19*FDEC_STRIDE;
- h->mb.pic.p_fdec[2] = h->mb.pic.fdec_buf + 19*FDEC_STRIDE + 16;
-
- /* load picture pointers */
- for( i = 0; i < 3; i++ )
- {
- const int w = (i == 0 ? 16 : 8);
- const int i_stride = h->fdec->i_stride[i];
- const uint8_t *plane_fdec = &h->fdec->plane[i][ w * (i_mb_x + i_mb_y * i_stride) ];
- int j;
-
- h->mb.pic.i_stride[i] = i_stride;
-
- h->mc.copy[i?PIXEL_8x8:PIXEL_16x16]( h->mb.pic.p_fenc[i], FENC_STRIDE,
- &h->fenc->plane[i][ w * (i_mb_x + i_mb_y * i_stride) ], i_stride, w );
- memcpy( &h->mb.pic.p_fdec[i][-1-FDEC_STRIDE], &plane_fdec[-1-i_stride], w*3/2+1 );
- for( j = 0; j < w; j++ )
- h->mb.pic.p_fdec[i][-1+j*FDEC_STRIDE] = plane_fdec[-1+j*i_stride];
-
- for( j = 0; j < h->i_ref0; j++ )
- {
- h->mb.pic.p_fref[0][j][i==0 ? 0:i+3] = &h->fref0[j]->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
- h->mb.pic.p_fref[0][j][i+1] = &h->fref0[j]->filtered[i+1][ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )];
- }
- for( j = 0; j < h->i_ref1; j++ )
- {
- h->mb.pic.p_fref[1][j][i==0 ? 0:i+3] = &h->fref1[j]->plane[i][ w * ( i_mb_x + i_mb_y * i_stride )];
- h->mb.pic.p_fref[1][j][i+1] = &h->fref1[j]->filtered[i+1][ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )];
- }
- }
-
- if( h->fdec->integral )
- {
- for( i = 0; i < h->i_ref0; i++ )
- h->mb.pic.p_integral[0][i] = &h->fref0[i]->integral[ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )];
- for( i = 0; i < h->i_ref1; i++ )
- h->mb.pic.p_integral[1][i] = &h->fref1[i]->integral[ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )];
- }
-
/* load cache */
- if( i_mb_xy >= h->sh.i_first_mb + h->mb.i_mb_stride )
+ if( i_top_xy >= h->sh.i_first_mb )
{
h->mb.i_mb_type_top =
i_top_type= h->mb.type[i_top_xy];
+ ( i_top_type >= 0 && h->mb.mb_transform_size[i_top_xy] );
}
+ if( h->sh.b_mbaff )
+ {
+ h->mb.pic.i_fref[0] = h->i_ref0 << h->mb.b_interlaced;
+ h->mb.pic.i_fref[1] = h->i_ref1 << h->mb.b_interlaced;
+ h->mb.cache.i_neighbour_interlaced =
+ !!(h->mb.i_neighbour & MB_LEFT)
+ + !!(h->mb.i_neighbour & MB_TOP);
+ }
+
+ /* fdec: fenc:
+ * yyyyyyy
+ * yYYYY YYYY
+ * yYYYY YYYY
+ * yYYYY YYYY
+ * yYYYY YYYY
+ * uuu vvv UUVV
+ * uUU vVV UUVV
+ * uUU vVV
+ */
+ h->mb.pic.p_fenc[0] = h->mb.pic.fenc_buf;
+ h->mb.pic.p_fenc[1] = h->mb.pic.fenc_buf + 16*FENC_STRIDE;
+ h->mb.pic.p_fenc[2] = h->mb.pic.fenc_buf + 16*FENC_STRIDE + 8;
+ h->mb.pic.p_fdec[0] = h->mb.pic.fdec_buf + 2*FDEC_STRIDE;
+ h->mb.pic.p_fdec[1] = h->mb.pic.fdec_buf + 19*FDEC_STRIDE;
+ h->mb.pic.p_fdec[2] = h->mb.pic.fdec_buf + 19*FDEC_STRIDE + 16;
+
+ /* load picture pointers */
+ for( i = 0; i < 3; i++ )
+ {
+ const int w = (i == 0 ? 16 : 8);
+ const int i_stride = h->fdec->i_stride[i];
+ const int i_stride2 = i_stride << h->mb.b_interlaced;
+ const int i_pix_offset = h->mb.b_interlaced
+ ? w * (i_mb_x + (i_mb_y&~1) * i_stride) + (i_mb_y&1) * i_stride
+ : w * (i_mb_x + i_mb_y * i_stride);
+ int ref_pix_offset[2] = { i_pix_offset, i_pix_offset };
+ const uint8_t *plane_fdec = &h->fdec->plane[i][i_pix_offset];
+ x264_frame_t **fref[2] = { h->fref0, h->fref1 };
+ int j, k, l;
+
+ if( h->mb.b_interlaced )
+ ref_pix_offset[1] += (1-2*(i_mb_y&1)) * i_stride;
+
+ h->mb.pic.i_stride[i] = i_stride2;
+
+ h->mc.copy[i?PIXEL_8x8:PIXEL_16x16]( h->mb.pic.p_fenc[i], FENC_STRIDE,
+ &h->fenc->plane[i][i_pix_offset], i_stride2, w );
+ memcpy( &h->mb.pic.p_fdec[i][-1-FDEC_STRIDE], &plane_fdec[-1-i_stride2], w*3/2+1 );
+ for( j = 0; j < w; j++ )
+ h->mb.pic.p_fdec[i][-1+j*FDEC_STRIDE] = plane_fdec[-1+j*i_stride2];
+
+ for( l=0; l<2; l++ )
+ {
+ for( j=0; j<h->mb.pic.i_fref[l]; j++ )
+ {
+ h->mb.pic.p_fref[l][j][i==0 ? 0:i+3] = &fref[l][j >> h->mb.b_interlaced]->plane[i][ref_pix_offset[j&1]];
+ if( i == 0 )
+ for( k = 1; k < 4; k++ )
+ h->mb.pic.p_fref[l][j][k] = &fref[l][j >> h->mb.b_interlaced]->filtered[k][ref_pix_offset[j&1]];
+ }
+ }
+ }
+
+ if( h->fdec->integral )
+ {
+ assert( !h->mb.b_interlaced );
+ for( i = 0; i < h->mb.pic.i_fref[0]; i++ )
+ h->mb.pic.p_integral[0][i] = &h->fref0[i]->integral[ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )];
+ for( i = 0; i < h->mb.pic.i_fref[1]; i++ )
+ h->mb.pic.p_integral[1][i] = &h->fref1[i]->integral[ 16 * ( i_mb_x + i_mb_y * h->fdec->i_stride[0] )];
+ }
+
/* load ref/mv/mvd */
if( h->sh.i_type != SLICE_TYPE_I )
{
if( h->mb.i_neighbour & MB_TOPLEFT )
{
const int i8 = x264_scan8[0] - 1 - 1*8;
- const int ir = i_mb_8x8 - s8x8 - 1;
- const int iv = i_mb_4x4 - s4x4 - 1;
+ const int ir = i_top_8x8 - 1;
+ const int iv = i_top_4x4 - 1;
h->mb.cache.ref[i_list][i8] = h->mb.ref[i_list][ir];
h->mb.cache.mv[i_list][i8][0] = h->mb.mv[i_list][iv][0];
h->mb.cache.mv[i_list][i8][1] = h->mb.mv[i_list][iv][1];
if( h->mb.i_neighbour & MB_TOP )
{
const int i8 = x264_scan8[0] - 8;
- const int ir = i_mb_8x8 - s8x8;
- const int iv = i_mb_4x4 - s4x4;
-
+ const int ir = i_top_8x8;
+ const int iv = i_top_4x4;
h->mb.cache.ref[i_list][i8+0] =
h->mb.cache.ref[i_list][i8+1] = h->mb.ref[i_list][ir + 0];
h->mb.cache.ref[i_list][i8+2] =
if( h->mb.i_neighbour & MB_TOPRIGHT )
{
const int i8 = x264_scan8[0] + 4 - 1*8;
- const int ir = i_mb_8x8 - s8x8 + 2;
- const int iv = i_mb_4x4 - s4x4 + 4;
-
+ const int ir = i_top_8x8 + 2;
+ const int iv = i_top_4x4 + 4;
h->mb.cache.ref[i_list][i8] = h->mb.ref[i_list][ir];
h->mb.cache.mv[i_list][i8][0] = h->mb.mv[i_list][iv][0];
h->mb.cache.mv[i_list][i8][1] = h->mb.mv[i_list][iv][1];
const int i8 = x264_scan8[0] - 1;
const int ir = i_mb_8x8 - 1;
const int iv = i_mb_4x4 - 1;
-
h->mb.cache.ref[i_list][i8+0*8] =
h->mb.cache.ref[i_list][i8+1*8] = h->mb.ref[i_list][ir + 0*s8x8];
h->mb.cache.ref[i_list][i8+2*8] =
if( i_top_type >= 0 )
{
const int i8 = x264_scan8[0] - 8;
- const int iv = i_mb_4x4 - s4x4;
+ const int iv = i_top_4x4;
for( i = 0; i < 4; i++ )
{
h->mb.cache.mvd[i_list][i8+i][0] = h->mb.mvd[i_list][iv + i][0];
for( i = 0; i < 3; i++ )
{
int w = i ? 8 : 16;
+ int i_stride = h->fdec->i_stride[i];
+ int i_stride2 = i_stride << h->mb.b_interlaced;
+ int i_pix_offset = h->mb.b_interlaced
+ ? w * (h->mb.i_mb_x + (h->mb.i_mb_y&~1) * i_stride) + (h->mb.i_mb_y&1) * i_stride
+ : w * (h->mb.i_mb_x + h->mb.i_mb_y * i_stride);
h->mc.copy[i?PIXEL_8x8:PIXEL_16x16](
- &h->fdec->plane[i][ w * (h->mb.i_mb_x + h->mb.i_mb_y * h->fdec->i_stride[i]) ],
- h->fdec->i_stride[i],
+ &h->fdec->plane[i][i_pix_offset], i_stride2,
h->mb.pic.p_fdec[i], FDEC_STRIDE, w );
}
h->mb.i_last_dqp = h->mb.i_qp - h->mb.i_last_qp;
h->mb.i_last_qp = h->mb.i_qp;
+ h->mb.i_mb_prev_xy = h->mb.i_mb_xy;
/* save intra4x4 */
if( i_mb_type == I_4x4 )
h->mb.bipred_weight[i_ref0][i_ref1] = 32;
}
}
+ if( h->sh.b_mbaff )
+ {
+ for( i_ref0 = 2*h->i_ref0-1; i_ref0 >= 0; i_ref0-- )
+ for( i_ref1 = 2*h->i_ref1-1; i_ref1 >= 0; i_ref1-- )
+ h->mb.bipred_weight[i_ref0][i_ref1] = h->mb.bipred_weight[i_ref0>>1][i_ref1>>1];
+ }
}
};
/* zigzags are transposed with respect to the tables in the standard */
-static const int x264_zigzag_scan4[16] =
-{
+static const int x264_zigzag_scan4[2][16] =
+{{ // frame
0, 4, 1, 2, 5, 8, 12, 9, 6, 3, 7, 10, 13, 14, 11, 15
-};
-static const int x264_zigzag_scan8[64] =
-{
+},
+{ // field
+ 0, 1, 4, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+}};
+static const int x264_zigzag_scan8[2][64] =
+{{
0, 8, 1, 2, 9, 16, 24, 17, 10, 3, 4, 11, 18, 25, 32, 40,
33, 26, 19, 12, 5, 6, 13, 20, 27, 34, 41, 48, 56, 49, 42, 35,
28, 21, 14, 7, 15, 22, 29, 36, 43, 50, 57, 58, 51, 44, 37, 30,
23, 31, 38, 45, 52, 59, 60, 53, 46, 39, 47, 54, 61, 62, 55, 63
-};
+},
+{
+ 0, 1, 2, 8, 9, 3, 4, 10, 16, 11, 5, 6, 7, 12, 17, 24,
+ 18, 13, 14, 15, 19, 25, 32, 26, 20, 21, 22, 23, 27, 33, 40, 34,
+ 28, 29, 30, 31, 35, 41, 48, 42, 36, 37, 38, 39, 43, 49, 50, 44,
+ 45, 46, 47, 51, 56, 57, 52, 53, 54, 55, 58, 59, 60, 61, 62, 63
+}};
static const uint8_t block_idx_x[16] =
{
uint8_t *src, int i_src_stride,
int i_width, int i_height );
-void x264_frame_filter( int cpu, x264_frame_t *frame )
+void x264_frame_filter( int cpu, x264_frame_t *frame, int b_interlaced )
{
const int x_inc = 16, y_inc = 16;
- const int stride = frame->i_stride[0];
+ const int stride = frame->i_stride[0] << b_interlaced;
+ const int height = frame->i_lines[0] >> b_interlaced;
int x, y;
pf_mc_t int_h = mc_hh;
{
x264_horizontal_filter_mmxext(frame->filtered[1] - 8 * stride - 8, stride,
frame->plane[0] - 8 * stride - 8, stride,
- stride - 48, frame->i_lines[0] + 16);
+ stride - 48, height + 16);
x264_center_filter_mmxext(frame->filtered[2] - 8 * stride - 8, stride,
frame->filtered[3] - 8 * stride - 8, stride,
frame->plane[0] - 8 * stride - 8, stride,
- stride - 48, frame->i_lines[0] + 16);
+ stride - 48, height + 16);
}
else
#endif
{
- for( y = -8; y < frame->i_lines[0]+8; y += y_inc )
+ for( y = -8; y < height + 8; y += y_inc )
{
uint8_t *p_in = frame->plane[0] + y * stride - 8;
uint8_t *p_h = frame->filtered[1] + y * stride - 8;
h->mb.mv_max_spel[0] = 4*( h->mb.mv_max_fpel[0] + 16 );
if( h->mb.i_mb_x == 0)
{
- h->mb.mv_min[1] = 4*( -16*h->mb.i_mb_y - 24 );
- h->mb.mv_max[1] = 4*( 16*( h->sps->i_mb_height - h->mb.i_mb_y - 1 ) + 24 );
- h->mb.mv_min_fpel[1] = CLIP_FMV( -16*h->mb.i_mb_y - 8 );
- h->mb.mv_max_fpel[1] = CLIP_FMV( 16*( h->sps->i_mb_height - h->mb.i_mb_y - 1 ) + 8 );
+ int mb_y = h->mb.i_mb_y >> h->sh.b_mbaff;
+ int mb_height = h->sps->i_mb_height >> h->sh.b_mbaff;
+ h->mb.mv_min[1] = 4*( -16*mb_y - 24 );
+ h->mb.mv_max[1] = 4*( 16*( mb_height - mb_y - 1 ) + 24 );
+ h->mb.mv_min_fpel[1] = CLIP_FMV( -16*mb_y - 8 );
+ h->mb.mv_max_fpel[1] = CLIP_FMV( 16*( mb_height - mb_y - 1 ) + 8 );
h->mb.mv_min_spel[1] = 4*( h->mb.mv_min_fpel[1] - 16 );
h->mb.mv_max_spel[1] = 4*( h->mb.mv_max_fpel[1] + 16 );
}
int i_ref;
int mvc[7][2], i_mvc;
int i_halfpel_thresh = INT_MAX;
- int *p_halfpel_thresh = h->i_ref0>1 ? &i_halfpel_thresh : NULL;
+ int *p_halfpel_thresh = h->mb.pic.i_fref[0]>1 ? &i_halfpel_thresh : NULL;
/* 16x16 Search on all ref frame */
m.i_pixel = PIXEL_16x16;
LOAD_FENC( &m, h->mb.pic.p_fenc, 0, 0 );
a->l0.me16x16.cost = INT_MAX;
- for( i_ref = 0; i_ref < h->i_ref0; i_ref++ )
+ for( i_ref = 0; i_ref < h->mb.pic.i_fref[0]; i_ref++ )
{
const int i_ref_cost = REF_COST( 0, i_ref );
i_halfpel_thresh -= i_ref_cost;
int i_ref;
uint8_t **p_fenc = h->mb.pic.p_fenc;
int i_halfpel_thresh = INT_MAX;
- int *p_halfpel_thresh = /*h->i_ref0>1 ? &i_halfpel_thresh : */NULL;
+ int *p_halfpel_thresh = /*h->mb.pic.i_fref[0]>1 ? &i_halfpel_thresh : */NULL;
int i;
- int i_maxref = h->i_ref0-1;
+ int i_maxref = h->mb.pic.i_fref[0]-1;
h->mb.i_partition = D_8x8;
int i_ref;
int mvc[8][2], i_mvc;
int i_halfpel_thresh = INT_MAX;
- int *p_halfpel_thresh = h->i_ref0>1 ? &i_halfpel_thresh : NULL;
+ int *p_halfpel_thresh = h->mb.pic.i_fref[0]>1 ? &i_halfpel_thresh : NULL;
/* 16x16 Search on all ref frame */
m.i_pixel = PIXEL_16x16;
/* ME for List 0 */
a->l0.me16x16.cost = INT_MAX;
- for( i_ref = 0; i_ref < h->i_ref0; i_ref++ )
+ for( i_ref = 0; i_ref < h->mb.pic.i_fref[0]; i_ref++ )
{
/* search with ref */
LOAD_HPELS( &m, h->mb.pic.p_fref[0][i_ref], 0, i_ref, 0, 0 );
/* ME for list 1 */
i_halfpel_thresh = INT_MAX;
- p_halfpel_thresh = h->i_ref1>1 ? &i_halfpel_thresh : NULL;
+ p_halfpel_thresh = h->mb.pic.i_fref[1]>1 ? &i_halfpel_thresh : NULL;
a->l1.me16x16.cost = INT_MAX;
- for( i_ref = 0; i_ref < h->i_ref1; i_ref++ )
+ for( i_ref = 0; i_ref < h->mb.pic.i_fref[1]; i_ref++ )
{
/* search with ref */
LOAD_HPELS( &m, h->mb.pic.p_fref[1][i_ref], 1, i_ref, 0, 0 );
{
const int i_mb_type = h->mb.i_type;
+ if( h->sh.b_mbaff &&
+ (!(h->mb.i_mb_y & 1) || IS_SKIP(h->mb.type[h->mb.i_mb_xy - h->mb.i_mb_stride])) )
+ {
+ x264_cabac_encode_decision( cb, 70 + h->mb.cache.i_neighbour_interlaced, h->mb.b_interlaced );
+ }
+
if( h->sh.i_type == SLICE_TYPE_I )
{
int ctx = 0;
{
ctx++;
}
- if( (h->mb.i_neighbour & MB_TOP) && h->mb.chroma_pred_mode[h->mb.i_mb_xy - h->mb.i_mb_stride] != 0 )
+ if( (h->mb.i_neighbour & MB_TOP) && h->mb.chroma_pred_mode[h->mb.i_mb_top_xy] != 0 )
{
ctx++;
}
if( y > 0 )
i_mbb_xy = h->mb.i_mb_xy;
else if( h->mb.i_neighbour & MB_TOP )
- i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
+ i_mbb_xy = h->mb.i_mb_top_xy;
/* No need to test for PCM and SKIP */
if( h->mb.i_neighbour & MB_TOP )
{
- cbp_b = (h->mb.cbp[h->mb.i_mb_xy - h->mb.i_mb_stride] >> 4)&0x3;
+ cbp_b = (h->mb.cbp[h->mb.i_mb_top_xy] >> 4)&0x3;
}
ctx = 0;
/* TODO check it with != qp per mb */
static void x264_cabac_mb_qp_delta( x264_t *h, x264_cabac_t *cb )
{
- int i_mbn_xy = h->mb.i_mb_xy - 1;
+ int i_mbn_xy = h->mb.i_mb_prev_xy;
int i_dqp = h->mb.i_qp - h->mb.i_last_qp;
int ctx;
/* No need to test for PCM / SKIP */
- if( i_mbn_xy >= h->sh.i_first_mb && h->mb.i_last_dqp != 0 &&
+ if( h->mb.i_neighbour && h->mb.i_last_dqp != 0 &&
( h->mb.type[i_mbn_xy] == I_16x16 || (h->mb.cbp[i_mbn_xy]&0x3f) ) )
ctx = 1;
else
if( h->mb.i_neighbour & MB_LEFT )
{
i_mba_xy = h->mb.i_mb_xy - 1;
- if( h->mb.type[i_mba_xy] == I_16x16 )
+ if( h->mb.i_mb_type_left == I_16x16 )
i_nza = h->mb.cbp[i_mba_xy] & 0x100;
}
if( h->mb.i_neighbour & MB_TOP )
{
- i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
- if( h->mb.type[i_mbb_xy] == I_16x16 )
+ i_mbb_xy = h->mb.i_mb_top_xy;
+ if( h->mb.i_mb_type_top == I_16x16 )
i_nzb = h->mb.cbp[i_mbb_xy] & 0x100;
}
}
if( i_idx & ~5 ) // block_idx_y > 0
i_mbb_xy = h->mb.i_mb_xy;
else if( h->mb.i_neighbour & MB_TOP )
- i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
+ i_mbb_xy = h->mb.i_mb_top_xy;
/* no need to test for skip/pcm */
if( i_mba_xy >= 0 )
}
if( h->mb.i_neighbour & MB_TOP )
{
- i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
+ i_mbb_xy = h->mb.i_mb_top_xy;
i_nzb = h->mb.cbp[i_mbb_xy] & (0x200 << i_idx);
}
}
if( i_idx & 2 )
i_mbb_xy = h->mb.i_mb_xy;
else if( h->mb.i_neighbour & MB_TOP )
- i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride;
+ i_mbb_xy = h->mb.i_mb_top_xy;
/* no need to test skip/pcm */
if( i_mba_xy >= 0 )
}
-static const int significant_coeff_flag_offset[6] = { 105, 120, 134, 149, 152, 402 };
-static const int last_coeff_flag_offset[6] = { 166, 181, 195, 210, 213, 417 };
-static const int coeff_abs_level_m1_offset[6] = { 227, 237, 247, 257, 266, 426 };
-static const int significant_coeff_flag_offset_8x8[63] = {
+static const int significant_coeff_flag_offset[2][6] = {
+ { 105, 120, 134, 149, 152, 402 },
+ { 277, 292, 306, 321, 324, 436 }
+};
+static const int last_coeff_flag_offset[2][6] = {
+ { 166, 181, 195, 210, 213, 417 },
+ { 338, 353, 367, 382, 385, 451 }
+};
+static const int coeff_abs_level_m1_offset[6] =
+ { 227, 237, 247, 257, 266, 426 };
+static const int significant_coeff_flag_offset_8x8[2][63] =
+{{
0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5,
4, 4, 4, 4, 3, 3, 6, 7, 7, 7, 8, 9,10, 9, 8, 7,
7, 6,11,12,13,11, 6, 7, 8, 9,14,10, 9, 8, 6,11,
12,13,11, 6, 9,14,10, 9,11,12,13,11,14,10,12
-};
+},{
+ 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 4, 5,
+ 6, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,11,12,11,
+ 9, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,13,13, 9,
+ 9,10,10, 8,13,13, 9, 9,10,10,14,14,14,14,14
+}};
static const int last_coeff_flag_offset_8x8[63] = {
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8
};
+static const int identity[16] =
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
static void block_residual_write_cabac( x264_t *h, x264_cabac_t *cb, int i_ctxBlockCat, int i_idx, int *l, int i_count )
{
- const int i_ctx_sig = significant_coeff_flag_offset[i_ctxBlockCat];
- const int i_ctx_last = last_coeff_flag_offset[i_ctxBlockCat];
+ const int i_ctx_sig = significant_coeff_flag_offset[h->mb.b_interlaced][i_ctxBlockCat];
+ const int i_ctx_last = last_coeff_flag_offset[h->mb.b_interlaced][i_ctxBlockCat];
const int i_ctx_level = coeff_abs_level_m1_offset[i_ctxBlockCat];
int i_coeff_abs_m1[64];
int i;
+ const int *significant_coeff_flag_offset;
+ const int *last_coeff_flag_offset;
+
/* i_ctxBlockCat: 0-> DC 16x16 i_idx = 0
* 1-> AC 16x16 i_idx = luma4x4idx
* 2-> Luma4x4 i_idx = luma4x4idx
return;
}
+ significant_coeff_flag_offset = (i_ctxBlockCat == DCT_LUMA_8x8)
+ ? significant_coeff_flag_offset_8x8[h->mb.b_interlaced]
+ : identity;
+ last_coeff_flag_offset = (i_ctxBlockCat == DCT_LUMA_8x8)
+ ? last_coeff_flag_offset_8x8 : identity;
+
i_sigmap_size = X264_MIN( i_last+1, i_count-1 );
for( i = 0; i < i_sigmap_size; i++ )
{
- int i_sig_ctxIdxInc;
- int i_last_ctxIdxInc;
-
- if( i_ctxBlockCat == DCT_LUMA_8x8 )
- {
- i_sig_ctxIdxInc = significant_coeff_flag_offset_8x8[i];
- i_last_ctxIdxInc = last_coeff_flag_offset_8x8[i];
- }
- else
- i_sig_ctxIdxInc = i_last_ctxIdxInc = i;
-
- x264_cabac_encode_decision( cb, i_ctx_sig + i_sig_ctxIdxInc, l[i] != 0 );
+ x264_cabac_encode_decision( cb, i_ctx_sig + significant_coeff_flag_offset[i], l[i] != 0 );
if( l[i] != 0 )
- x264_cabac_encode_decision( cb, i_ctx_last + i_last_ctxIdxInc, i == i_last );
+ x264_cabac_encode_decision( cb, i_ctx_last + last_coeff_flag_offset[i], i == i_last );
}
for( i = i_coeff - 1; i >= 0; i-- )
{
if( h->mb.i_partition == D_16x16 )
{
- if( h->sh.i_num_ref_idx_l0_active > 1 )
+ if( h->mb.pic.i_fref[0] > 1 )
{
x264_cabac_mb_ref( h, cb, 0, 0 );
}
}
else if( h->mb.i_partition == D_16x8 )
{
- if( h->sh.i_num_ref_idx_l0_active > 1 )
+ if( h->mb.pic.i_fref[0] > 1 )
{
x264_cabac_mb_ref( h, cb, 0, 0 );
x264_cabac_mb_ref( h, cb, 0, 8 );
}
else if( h->mb.i_partition == D_8x16 )
{
- if( h->sh.i_num_ref_idx_l0_active > 1 )
+ if( h->mb.pic.i_fref[0] > 1 )
{
x264_cabac_mb_ref( h, cb, 0, 0 );
x264_cabac_mb_ref( h, cb, 0, 4 );
x264_cabac_mb_sub_p_partition( cb, h->mb.i_sub_partition[3] );
/* ref 0 */
- if( h->sh.i_num_ref_idx_l0_active > 1 )
+ if( h->mb.pic.i_fref[0] > 1 )
{
x264_cabac_mb_ref( h, cb, 0, 0 );
x264_cabac_mb_ref( h, cb, 0, 4 );
/* ref */
for( i_list = 0; i_list < 2; i_list++ )
{
- if( ( i_list ? h->sh.i_num_ref_idx_l1_active : h->sh.i_num_ref_idx_l0_active ) == 1 )
+ if( ( i_list ? h->mb.pic.i_fref[1] : h->mb.pic.i_fref[0] ) == 1 )
continue;
for( i = 0; i < 4; i++ )
if( x264_mb_partition_listX_table[i_list][ h->mb.i_sub_partition[i] ] )
for( i_list = 0; i_list < 2; i_list++ )
{
- const int i_ref_max = i_list == 0 ? h->sh.i_num_ref_idx_l0_active : h->sh.i_num_ref_idx_l1_active;
+ const int i_ref_max = i_list == 0 ? h->mb.pic.i_fref[0] : h->mb.pic.i_fref[1];
if( i_ref_max > 1 )
{
if( i_mb_type == P_8x8 )
{
x264_cabac_mb_sub_p_partition( cb, h->mb.i_sub_partition[i8] );
- if( h->sh.i_num_ref_idx_l0_active > 1 )
+ if( h->mb.pic.i_fref[0] > 1 )
x264_cabac_mb_ref( h, cb, 0, 4*i8 );
x264_cabac_mb8x8_mvd( h, cb, 0, i8 );
}
else if( i_mb_type == P_L0 )
{
- if( h->sh.i_num_ref_idx_l0_active > 1 )
+ if( h->mb.pic.i_fref[0] > 1 )
x264_cabac_mb_ref( h, cb, 0, 4*i8 );
if( h->mb.i_partition == D_16x8 )
x264_cabac_mb_mvd( h, cb, 0, 4*i8, 4, 2 );
{
x264_cabac_mb_sub_b_partition( cb, h->mb.i_sub_partition[i8] );
- if( h->sh.i_num_ref_idx_l0_active > 1
+ if( h->mb.pic.i_fref[0] > 1
&& x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i8] ] )
x264_cabac_mb_ref( h, cb, 0, 4*i8 );
- if( h->sh.i_num_ref_idx_l1_active > 1
+ if( h->mb.pic.i_fref[1] > 1
&& x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i8] ] )
x264_cabac_mb_ref( h, cb, 1, 4*i8 );
return;
}
+ if( h->sh.b_mbaff
+ && (!(h->mb.i_mb_y & 1) || IS_SKIP(h->mb.type[h->mb.i_mb_xy - h->mb.i_mb_stride])) )
+ {
+ bs_write1( s, h->mb.b_interlaced );
+ }
+
/* Write:
- type
- prediction
{
bs_write_ue( s, 0 );
- if( h->sh.i_num_ref_idx_l0_active > 1 )
+ if( h->mb.pic.i_fref[0] > 1 )
{
- bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[0]] );
+ bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[0]] );
}
x264_mb_predict_mv( h, 0, 0, 4, mvp );
bs_write_se( s, h->mb.cache.mv[0][x264_scan8[0]][0] - mvp[0] );
else if( h->mb.i_partition == D_16x8 )
{
bs_write_ue( s, 1 );
- if( h->sh.i_num_ref_idx_l0_active > 1 )
+ if( h->mb.pic.i_fref[0] > 1 )
{
- bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[0]] );
- bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[8]] );
+ bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[0]] );
+ bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[8]] );
}
x264_mb_predict_mv( h, 0, 0, 4, mvp );
else if( h->mb.i_partition == D_8x16 )
{
bs_write_ue( s, 2 );
- if( h->sh.i_num_ref_idx_l0_active > 1 )
+ if( h->mb.pic.i_fref[0] > 1 )
{
- bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[0]] );
- bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[4]] );
+ bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[0]] );
+ bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[4]] );
}
x264_mb_predict_mv( h, 0, 0, 2, mvp );
bs_write_ue( s, sub_mb_type_p_to_golomb[ h->mb.i_sub_partition[i] ] );
}
/* ref0 */
- if( h->sh.i_num_ref_idx_l0_active > 1 && b_sub_ref0 )
+ if( h->mb.pic.i_fref[0] > 1 && b_sub_ref0 )
{
- bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[0]] );
- bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[4]] );
- bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[8]] );
- bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[12]] );
+ bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[0]] );
+ bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[4]] );
+ bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[8]] );
+ bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[12]] );
}
for( i = 0; i < 4; i++ )
{
if( x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i] ] )
{
- bs_write_te( s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[i*4]] );
+ bs_write_te( s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[i*4]] );
}
}
for( i = 0; i < 4; i++ )
{
if( x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i] ] )
{
- bs_write_te( s, h->sh.i_num_ref_idx_l1_active - 1, h->mb.cache.ref[1][x264_scan8[i*4]] );
+ bs_write_te( s, h->mb.pic.i_fref[1] - 1, h->mb.cache.ref[1][x264_scan8[i*4]] );
}
}
/* mvd */
for( i_list = 0; i_list < 2; i_list++ )
{
- const int i_ref_max = i_list == 0 ? h->sh.i_num_ref_idx_l0_active : h->sh.i_num_ref_idx_l1_active;
+ const int i_ref_max = i_list == 0 ? h->mb.pic.i_fref[0] : h->mb.pic.i_fref[1];
if( i_ref_max > 1 )
{
if( i_mb_type == P_8x8 )
{
bs_write_ue( &s, sub_mb_type_p_to_golomb[ h->mb.i_sub_partition[i8] ] );
- if( h->sh.i_num_ref_idx_l0_active > 1 )
- bs_write_te( &s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[4*i8]] );
+ if( h->mb.pic.i_fref[0] > 1 )
+ bs_write_te( &s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[4*i8]] );
cavlc_mb8x8_mvd( h, &s, 0, i8 );
}
else if( i_mb_type == P_L0 )
{
- if( h->sh.i_num_ref_idx_l0_active > 1 )
- bs_write_te( &s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[4*i8]] );
+ if( h->mb.pic.i_fref[0] > 1 )
+ bs_write_te( &s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[4*i8]] );
if( h->mb.i_partition == D_16x8 )
cavlc_mb_mvd( h, &s, 0, 4*i8, 4 );
else //8x16
{
bs_write_ue( &s, sub_mb_type_b_to_golomb[ h->mb.i_sub_partition[i8] ] );
- if( h->sh.i_num_ref_idx_l0_active > 1
+ if( h->mb.pic.i_fref[0] > 1
&& x264_mb_partition_listX_table[0][ h->mb.i_sub_partition[i8] ] )
- bs_write_te( &s, h->sh.i_num_ref_idx_l0_active - 1, h->mb.cache.ref[0][x264_scan8[4*i8]] );
- if( h->sh.i_num_ref_idx_l1_active > 1
+ bs_write_te( &s, h->mb.pic.i_fref[0] - 1, h->mb.cache.ref[0][x264_scan8[4*i8]] );
+ if( h->mb.pic.i_fref[1] > 1
&& x264_mb_partition_listX_table[1][ h->mb.i_sub_partition[i8] ] )
- bs_write_te( &s, h->sh.i_num_ref_idx_l1_active - 1, h->mb.cache.ref[1][x264_scan8[4*i8]] );
+ bs_write_te( &s, h->mb.pic.i_fref[1] - 1, h->mb.cache.ref[1][x264_scan8[4*i8]] );
cavlc_mb8x8_mvd( h, &s, 0, i8 );
cavlc_mb8x8_mvd( h, &s, 1, i8 );
sh->i_frame_num = i_frame;
- sh->b_field_pic = 0; /* Not field support for now */
- sh->b_bottom_field = 1; /* not yet used */
+ sh->b_mbaff = h->param.b_interlaced;
+ sh->b_field_pic = 0; /* no field support for now */
+ sh->b_bottom_field = 0; /* not yet used */
sh->i_idr_pic_id = i_idr_pic_id;
{
int i;
- bs_write_ue( s, sh->i_first_mb );
+ if( sh->b_mbaff )
+ {
+ assert( sh->i_first_mb % (2*sh->sps->i_mb_width) == 0 );
+ bs_write_ue( s, sh->i_first_mb >> 1 );
+ }
+ else
+ bs_write_ue( s, sh->i_first_mb );
+
bs_write_ue( s, sh->i_type + 5 ); /* same type things */
bs_write_ue( s, sh->i_pps_id );
bs_write( s, sh->sps->i_log2_max_frame_num, sh->i_frame_num );
+ if( !sh->sps->b_frame_mbs_only )
+ {
+ bs_write1( s, sh->b_field_pic );
+ if ( sh->b_field_pic )
+ bs_write1( s, sh->b_bottom_field );
+ }
+
if( sh->i_idr_pic_id >= 0 ) /* NAL IDR */
{
bs_write_ue( s, sh->i_idr_pic_id );
if( h->param.i_threads == 0 )
h->param.i_threads = x264_cpu_num_processors();
h->param.i_threads = x264_clip3( h->param.i_threads, 1, X264_SLICE_MAX );
- h->param.i_threads = X264_MIN( h->param.i_threads, (h->param.i_height + 15) / 16 );
+ h->param.i_threads = X264_MIN( h->param.i_threads, (h->param.i_height + 15) >> (4 + h->param.b_interlaced) );
#ifndef HAVE_PTHREAD
if( h->param.i_threads > 1 )
{
}
#endif
+ if( h->param.b_interlaced )
+ {
+ if( h->param.analyse.i_me_method == X264_ME_ESA )
+ {
+ x264_log( h, X264_LOG_WARNING, "interlace + me=esa is not implemented\n" );
+ h->param.analyse.i_me_method = X264_ME_UMH;
+ }
+ if( h->param.analyse.i_direct_mv_pred > X264_DIRECT_PRED_SPATIAL )
+ {
+ x264_log( h, X264_LOG_WARNING, "interlace + direct=temporal is not implemented\n" );
+ h->param.analyse.i_direct_mv_pred = X264_DIRECT_PRED_SPATIAL;
+ }
+ }
+
if( h->param.rc.i_rc_method < 0 || h->param.rc.i_rc_method > 2 )
{
x264_log( h, X264_LOG_ERROR, "invalid RC method\n" );
#define BOOLIFY(x) h->param.x = !!h->param.x
BOOLIFY( b_cabac );
BOOLIFY( b_deblocking_filter );
+ BOOLIFY( b_interlaced );
BOOLIFY( analyse.b_transform_8x8 );
BOOLIFY( analyse.b_bidir_me );
BOOLIFY( analyse.b_chroma_me );
x264_csp_init( h->param.cpu, h->param.i_csp, &h->csp );
x264_quant_init( h, h->param.cpu, &h->quantf );
x264_deblock_init( h->param.cpu, &h->loopf );
+ x264_dct_init_weights();
mbcmp_init( h );
h->i_ref0 = X264_MIN( h->i_ref0, h->frames.i_max_ref0 );
h->i_ref0 = X264_MIN( h->i_ref0, h->param.i_frame_reference ); // if reconfig() has lowered the limit
h->i_ref0 = X264_MIN( h->i_ref0, 16 - h->i_ref1 );
+ h->mb.pic.i_fref[0] = h->i_ref0;
+ h->mb.pic.i_fref[1] = h->i_ref1;
}
static inline void x264_fdec_deblock( x264_t *h )
x264_fdec_deblock( h );
/* expand border */
- x264_frame_expand_border( h->fdec );
+ x264_frame_expand_border( h, h->fdec );
/* create filtered images */
- x264_frame_filter( h->param.cpu, h->fdec );
+ x264_frame_filter( h->param.cpu, h->fdec, h->sh.b_mbaff );
/* expand border of filtered images */
- x264_frame_expand_border_filtered( h->fdec );
+ x264_frame_expand_border_filtered( h, h->fdec );
/* move lowres copy of the image to the ref frame */
for( i = 0; i < 4; i++)
+ {
XCHG( uint8_t*, h->fdec->lowres[i], h->fenc->lowres[i] );
+ XCHG( uint8_t*, h->fdec->buffer_lowres[i], h->fenc->buffer_lowres[i] );
+ }
/* adaptive B decision needs a pointer, since it can't use the ref lists */
if( h->sh.i_type != SLICE_TYPE_B )
h->mb.i_last_qp = h->sh.i_qp;
h->mb.i_last_dqp = 0;
- for( mb_xy = h->sh.i_first_mb, i_skip = 0; mb_xy < h->sh.i_last_mb; mb_xy++ )
+ for( mb_xy = h->sh.i_first_mb, i_skip = 0; mb_xy < h->sh.i_last_mb; )
{
const int i_mb_y = mb_xy / h->sps->i_mb_width;
const int i_mb_x = mb_xy % h->sps->i_mb_width;
TIMER_START( i_mtime_write );
if( h->param.b_cabac )
{
- if( mb_xy > h->sh.i_first_mb )
+ if( mb_xy > h->sh.i_first_mb && !(h->sh.b_mbaff && (i_mb_y&1)) )
x264_cabac_encode_terminal( &h->cabac, 0 );
if( IS_SKIP( h->mb.i_type ) )
if( h->mb.b_variable_qp )
x264_ratecontrol_mb(h, bs_pos(&h->out.bs) - mb_spos);
+
+ if( h->sh.b_mbaff )
+ {
+ if( (i_mb_y&1) && i_mb_x == h->sps->i_mb_width - 1 )
+ mb_xy++;
+ else if( i_mb_y&1 )
+ mb_xy += 1 - h->sps->i_mb_width;
+ else
+ mb_xy += h->sps->i_mb_width;
+ }
+ else
+ mb_xy++;
}
if( h->param.b_cabac )
for( i = 0; i < h->param.i_threads; i++ )
{
x264_t *t = h->thread[i];
+ int mb_height = h->sps->i_mb_height >> h->sh.b_mbaff;
+ int mb_width = h->sps->i_mb_width << h->sh.b_mbaff;
if( i > 0 )
{
memcpy( t, h, sizeof(x264_t) );
bs_init( &t->out.bs, t->out.p_bitstream, i_bs_size );
t->i_thread_num = i;
}
- t->sh.i_first_mb = (i * h->sps->i_mb_height / h->param.i_threads) * h->sps->i_mb_width;
- t->sh.i_last_mb = ((i+1) * h->sps->i_mb_height / h->param.i_threads) * h->sps->i_mb_width;
+ t->sh.i_first_mb = (i * mb_height / h->param.i_threads) * mb_width;
+ t->sh.i_last_mb = ((i+1) * mb_height / h->param.i_threads) * mb_width;
t->out.i_nal = i_nal + i;
}
x264_ratecontrol_threads_start( h );
x264_frame_copy_picture( h, fenc, pic_in );
- if( h->param.i_width % 16 || h->param.i_height % 16 )
+ if( h->param.i_width != 16 * h->sps->i_mb_width ||
+ h->param.i_height != 16 * h->sps->i_mb_height )
x264_frame_expand_border_mod16( h, fenc );
fenc->i_frame = h->frames.i_input++;
{
for( i = 0; i < 7; i++ )
h->stat.i_mb_count_size[h->sh.i_type][i] += h->stat.frame.i_mb_count_size[i];
- for( i = 0; i < 16; i++ )
+ for( i = 0; i < 32; i++ )
h->stat.i_mb_count_ref[h->sh.i_type][i] += h->stat.frame.i_mb_count_ref[i];
}
if( i_slice_type == SLICE_TYPE_B )
char *p = buf;
int64_t i_den = 0;
int i_max = 0;
- for( i = 0; i < h->frames.i_max_ref0; i++ )
+ for( i = 0; i < h->frames.i_max_ref0 << h->param.b_interlaced; i++ )
if( h->stat.i_mb_count_ref[i_slice][i] )
{
i_den += h->stat.i_mb_count_ref[i_slice][i];
****************************************************************************/
#define ZIG(i,y,x) level[i] = dct[x][y];
-static inline void scan_zigzag_8x8full( int level[64], int16_t dct[8][8] )
+
+static inline void scan_zigzag_8x8full( int level[64], int16_t dct[8][8], int b_interlaced )
{
+ if( b_interlaced )
+ {
+ ZIG( 0,0,0) ZIG( 1,1,0) ZIG( 2,2,0) ZIG( 3,0,1)
+ ZIG( 4,1,1) ZIG( 5,3,0) ZIG( 6,4,0) ZIG( 7,2,1)
+ ZIG( 8,0,2) ZIG( 9,3,1) ZIG(10,5,0) ZIG(11,6,0)
+ ZIG(12,7,0) ZIG(13,4,1) ZIG(14,1,2) ZIG(15,0,3)
+ ZIG(16,2,2) ZIG(17,5,1) ZIG(18,6,1) ZIG(19,7,1)
+ ZIG(20,3,2) ZIG(21,1,3) ZIG(22,0,4) ZIG(23,2,3)
+ ZIG(24,4,2) ZIG(25,5,2) ZIG(26,6,2) ZIG(27,7,2)
+ ZIG(28,3,3) ZIG(29,1,4) ZIG(30,0,5) ZIG(31,2,4)
+ ZIG(32,4,3) ZIG(33,5,3) ZIG(34,6,3) ZIG(35,7,3)
+ ZIG(36,3,4) ZIG(37,1,5) ZIG(38,0,6) ZIG(39,2,5)
+ ZIG(40,4,4) ZIG(41,5,4) ZIG(42,6,4) ZIG(43,7,4)
+ ZIG(44,3,5) ZIG(45,1,6) ZIG(46,2,6) ZIG(47,4,5)
+ ZIG(48,5,5) ZIG(49,6,5) ZIG(50,7,5) ZIG(51,3,6)
+ ZIG(52,0,7) ZIG(53,1,7) ZIG(54,4,6) ZIG(55,5,6)
+ ZIG(56,6,6) ZIG(57,7,6) ZIG(58,2,7) ZIG(59,3,7)
+ ZIG(60,4,7) ZIG(61,5,7) ZIG(62,6,7) ZIG(63,7,7)
+ }
+ else
+ {
ZIG( 0,0,0) ZIG( 1,0,1) ZIG( 2,1,0) ZIG( 3,2,0)
ZIG( 4,1,1) ZIG( 5,0,2) ZIG( 6,0,3) ZIG( 7,1,2)
ZIG( 8,2,1) ZIG( 9,3,0) ZIG(10,4,0) ZIG(11,3,1)
ZIG(52,4,6) ZIG(53,3,7) ZIG(54,4,7) ZIG(55,5,6)
ZIG(56,6,5) ZIG(57,7,4) ZIG(58,7,5) ZIG(59,6,6)
ZIG(60,5,7) ZIG(61,6,7) ZIG(62,7,6) ZIG(63,7,7)
+ }
}
-static inline void scan_zigzag_4x4full( int level[16], int16_t dct[4][4] )
+
+static inline void scan_zigzag_4x4full( int level[16], int16_t dct[4][4], int b_interlaced )
{
+ if( b_interlaced )
+ {
+ ZIG( 0,0,0) ZIG( 1,1,0) ZIG( 2,0,1) ZIG( 3,2,0)
+ ZIG( 4,3,0) ZIG( 5,1,1) ZIG( 6,2,1) ZIG( 7,3,1)
+ ZIG( 8,0,2) ZIG( 9,1,2) ZIG(10,2,2) ZIG(11,3,2)
+ ZIG(12,0,3) ZIG(13,1,3) ZIG(14,2,3) ZIG(15,3,3)
+ }
+ else
+ {
ZIG( 0,0,0) ZIG( 1,0,1) ZIG( 2,1,0) ZIG( 3,2,0)
ZIG( 4,1,1) ZIG( 5,0,2) ZIG( 6,0,3) ZIG( 7,1,2)
ZIG( 8,2,1) ZIG( 9,3,0) ZIG(10,3,1) ZIG(11,2,2)
ZIG(12,1,3) ZIG(13,2,3) ZIG(14,3,2) ZIG(15,3,3)
+ }
}
-static inline void scan_zigzag_4x4( int level[15], int16_t dct[4][4] )
+
+static inline void scan_zigzag_4x4( int level[15], int16_t dct[4][4], int b_interlaced )
{
+ if( b_interlaced )
+ {
+ ZIG( 0,1,0) ZIG( 1,0,1) ZIG( 2,2,0)
+ ZIG( 3,3,0) ZIG( 4,1,1) ZIG( 5,2,1) ZIG( 6,3,1)
+ ZIG( 7,0,2) ZIG( 8,1,2) ZIG( 9,2,2) ZIG(10,3,2)
+ ZIG(11,0,3) ZIG(12,1,3) ZIG(13,2,3) ZIG(14,3,3)
+ }
+ else
+ {
ZIG( 0,0,1) ZIG( 1,1,0) ZIG( 2,2,0)
ZIG( 3,1,1) ZIG( 4,0,2) ZIG( 5,0,3) ZIG( 6,1,2)
ZIG( 7,2,1) ZIG( 8,3,0) ZIG( 9,3,1) ZIG(10,2,2)
ZIG(11,1,3) ZIG(12,2,3) ZIG(13,3,2) ZIG(14,3,3)
+ }
}
+
static inline void scan_zigzag_2x2_dc( int level[4], int16_t dct[2][2] )
{
ZIG(0,0,0)
level[i] = p_src[oe] - p_dst[od];\
p_dst[od] = p_src[oe];\
}
-static inline void sub_zigzag_4x4full( int level[16], const uint8_t *p_src, uint8_t *p_dst )
+
+static inline void sub_zigzag_4x4full( int level[16], const uint8_t *p_src, uint8_t *p_dst, int b_interlaced )
{
+ if( b_interlaced )
+ {
+ ZIG( 0,0,0) ZIG( 1,1,0) ZIG( 2,0,1) ZIG( 3,2,0)
+ ZIG( 4,3,0) ZIG( 5,1,1) ZIG( 6,2,1) ZIG( 7,3,1)
+ ZIG( 8,0,2) ZIG( 9,1,2) ZIG(10,2,2) ZIG(11,3,2)
+ ZIG(12,0,3) ZIG(13,1,3) ZIG(14,2,3) ZIG(15,3,3)
+ }
+ else
+ {
ZIG( 0,0,0) ZIG( 1,0,1) ZIG( 2,1,0) ZIG( 3,2,0)
ZIG( 4,1,1) ZIG( 5,0,2) ZIG( 6,0,3) ZIG( 7,1,2)
ZIG( 8,2,1) ZIG( 9,3,0) ZIG(10,3,1) ZIG(11,2,2)
ZIG(12,1,3) ZIG(13,2,3) ZIG(14,3,2) ZIG(15,3,3)
+ }
}
-static inline void sub_zigzag_4x4( int level[15], const uint8_t *p_src, uint8_t *p_dst )
+
+static inline void sub_zigzag_4x4( int level[15], const uint8_t *p_src, uint8_t *p_dst, int b_interlaced )
{
+ if( b_interlaced )
+ {
+ ZIG( 0,1,0) ZIG( 1,0,1) ZIG( 2,2,0)
+ ZIG( 3,3,0) ZIG( 4,1,1) ZIG( 5,2,1) ZIG( 6,3,1)
+ ZIG( 7,0,2) ZIG( 8,1,2) ZIG( 9,2,2) ZIG(10,3,2)
+ ZIG(11,0,3) ZIG(12,1,3) ZIG(13,2,3) ZIG(14,3,3)
+ }
+ else
+ {
ZIG( 0,0,1) ZIG( 1,1,0) ZIG( 2,2,0)
ZIG( 3,1,1) ZIG( 4,0,2) ZIG( 5,0,3) ZIG( 6,1,2)
ZIG( 7,2,1) ZIG( 8,3,0) ZIG( 9,3,1) ZIG(10,2,2)
ZIG(11,1,3) ZIG(12,2,3) ZIG(13,3,2) ZIG(14,3,3)
+ }
}
#undef ZIG
if( h->mb.b_lossless )
{
- sub_zigzag_4x4full( h->dct.block[idx].luma4x4, p_src, p_dst );
+ sub_zigzag_4x4full( h->dct.block[idx].luma4x4, p_src, p_dst, h->mb.b_interlaced );
return;
}
else
quant_4x4( h, dct4x4, h->quant4_mf[CQM_4IY], i_qscale, 1 );
- scan_zigzag_4x4full( h->dct.block[idx].luma4x4, dct4x4 );
+ scan_zigzag_4x4full( h->dct.block[idx].luma4x4, dct4x4, h->mb.b_interlaced );
h->quantf.dequant_4x4( dct4x4, h->dequant4_mf[CQM_4IY], i_qscale );
/* output samples to fdec */
else
quant_8x8( h, dct8x8, h->quant8_mf[CQM_8IY], i_qscale, 1 );
- scan_zigzag_8x8full( h->dct.luma8x8[idx], dct8x8 );
+ scan_zigzag_8x8full( h->dct.luma8x8[idx], dct8x8, h->mb.b_interlaced );
h->quantf.dequant_8x8( dct8x8, h->dequant8_mf[CQM_8IY], i_qscale );
h->dctf.add8x8_idct8( p_dst, dct8x8 );
}
{
int oe = block_idx_x[i]*4 + block_idx_y[i]*4*FENC_STRIDE;
int od = block_idx_x[i]*4 + block_idx_y[i]*4*FDEC_STRIDE;
- sub_zigzag_4x4( h->dct.block[i].residual_ac, p_src+oe, p_dst+od );
+ sub_zigzag_4x4( h->dct.block[i].residual_ac, p_src+oe, p_dst+od, h->mb.b_interlaced );
dct4x4[0][block_idx_x[i]][block_idx_y[i]] = p_src[oe] - p_dst[od];
p_dst[od] = p_src[oe];
}
- scan_zigzag_4x4full( h->dct.luma16x16_dc, dct4x4[0] );
+ scan_zigzag_4x4full( h->dct.luma16x16_dc, dct4x4[0], h->mb.b_interlaced );
return;
}
else
quant_4x4( h, dct4x4[1+i], h->quant4_mf[CQM_4IY], i_qscale, 1 );
- scan_zigzag_4x4( h->dct.block[i].residual_ac, dct4x4[1+i] );
+ scan_zigzag_4x4( h->dct.block[i].residual_ac, dct4x4[1+i], h->mb.b_interlaced );
h->quantf.dequant_4x4( dct4x4[1+i], h->dequant4_mf[CQM_4IY], i_qscale );
}
h->dctf.dct4x4dc( dct4x4[0] );
quant_4x4_dc( h, dct4x4[0], h->quant4_mf[CQM_4IY], i_qscale );
- scan_zigzag_4x4full( h->dct.luma16x16_dc, dct4x4[0] );
+ scan_zigzag_4x4full( h->dct.luma16x16_dc, dct4x4[0], h->mb.b_interlaced );
/* output samples to fdec */
h->dctf.idct4x4dc( dct4x4[0] );
{
int oe = block_idx_x[i]*4 + block_idx_y[i]*4*FENC_STRIDE;
int od = block_idx_x[i]*4 + block_idx_y[i]*4*FDEC_STRIDE;
- sub_zigzag_4x4( h->dct.block[16+i+ch*4].residual_ac, p_src+oe, p_dst+od );
+ sub_zigzag_4x4( h->dct.block[16+i+ch*4].residual_ac, p_src+oe, p_dst+od, h->mb.b_interlaced );
h->dct.chroma_dc[ch][i] = p_src[oe] - p_dst[od];
p_dst[od] = p_src[oe];
}
/* no trellis; it doesn't seem to help chroma noticeably */
quant_4x4( h, dct4x4[i], h->quant4_mf[CQM_4IC + b_inter], i_qscale, !b_inter );
- scan_zigzag_4x4( h->dct.block[16+i+ch*4].residual_ac, dct4x4[i] );
+ scan_zigzag_4x4( h->dct.block[16+i+ch*4].residual_ac, dct4x4[i], h->mb.b_interlaced );
if( b_decimate )
{
int i_cbp_dc = 0;
int i_qp = h->mb.i_qp;
int b_decimate = h->sh.i_type == SLICE_TYPE_B || h->param.analyse.b_dct_decimate;
+ int b_force_no_skip = 0;
int i;
+ if( h->sh.b_mbaff
+ && h->mb.i_mb_xy == h->sh.i_first_mb + h->mb.i_mb_stride
+ && IS_SKIP(h->mb.type[h->sh.i_first_mb]) )
+ {
+ /* The first skip is predicted to be a frame mb pair.
+ * We don't yet support the aff part of mbaff, so force it to non-skip
+ * so that we can pick the aff flag. */
+ b_force_no_skip = 1;
+ if( IS_SKIP(h->mb.i_type) )
+ {
+ if( h->mb.i_type == P_SKIP )
+ h->mb.i_type = P_L0;
+ else if( h->mb.i_type == B_SKIP )
+ h->mb.i_type = B_DIRECT;
+ }
+ }
+
if( h->mb.i_type == P_SKIP )
{
/* A bit special */
int y = 4*block_idx_y[i4x4];
sub_zigzag_4x4full( h->dct.block[i4x4].luma4x4,
h->mb.pic.p_fenc[0]+x+y*FENC_STRIDE,
- h->mb.pic.p_fdec[0]+x+y*FDEC_STRIDE );
+ h->mb.pic.p_fdec[0]+x+y*FDEC_STRIDE,
+ h->mb.b_interlaced );
}
}
else if( h->mb.b_transform_8x8 )
else
quant_8x8( h, dct8x8[idx], h->quant8_mf[CQM_8PY], i_qp, 0 );
- scan_zigzag_8x8full( h->dct.luma8x8[idx], dct8x8[idx] );
+ scan_zigzag_8x8full( h->dct.luma8x8[idx], dct8x8[idx], h->mb.b_interlaced );
if( b_decimate )
{
else
quant_4x4( h, dct4x4[idx], h->quant4_mf[CQM_4PY], i_qp, 0 );
- scan_zigzag_4x4full( h->dct.block[idx].luma4x4, dct4x4[idx] );
+ scan_zigzag_4x4full( h->dct.block[idx].luma4x4, dct4x4[idx], h->mb.b_interlaced );
if( b_decimate )
i_decimate_8x8 += x264_mb_decimate_score( h->dct.block[idx].luma4x4, 16 );
/* Check for P_SKIP
* XXX: in the me perhaps we should take x264_mb_predict_mv_pskip into account
* (if multiple mv give same result)*/
- if( h->mb.i_type == P_L0 && h->mb.i_partition == D_16x16 &&
- h->mb.i_cbp_luma == 0x00 && h->mb.i_cbp_chroma== 0x00 &&
- h->mb.cache.ref[0][x264_scan8[0]] == 0 )
+ if( !b_force_no_skip )
{
- int mvp[2];
-
- x264_mb_predict_mv_pskip( h, mvp );
- if( h->mb.cache.mv[0][x264_scan8[0]][0] == mvp[0] &&
- h->mb.cache.mv[0][x264_scan8[0]][1] == mvp[1] )
+ if( h->mb.i_type == P_L0 && h->mb.i_partition == D_16x16 &&
+ h->mb.i_cbp_luma == 0x00 && h->mb.i_cbp_chroma== 0x00 &&
+ h->mb.cache.ref[0][x264_scan8[0]] == 0 )
{
- h->mb.i_type = P_SKIP;
+ int mvp[2];
+
+ x264_mb_predict_mv_pskip( h, mvp );
+ if( h->mb.cache.mv[0][x264_scan8[0]][0] == mvp[0] &&
+ h->mb.cache.mv[0][x264_scan8[0]][1] == mvp[1] )
+ {
+ h->mb.i_type = P_SKIP;
+ }
}
- }
- /* Check for B_SKIP */
- if( h->mb.i_type == B_DIRECT &&
- h->mb.i_cbp_luma == 0x00 && h->mb.i_cbp_chroma== 0x00 )
- {
- h->mb.i_type = B_SKIP;
+ /* Check for B_SKIP */
+ if( h->mb.i_type == B_DIRECT &&
+ h->mb.i_cbp_luma == 0x00 && h->mb.i_cbp_chroma== 0x00 )
+ {
+ h->mb.i_type = B_SKIP;
+ }
}
}
const int idx = i8x8 * 4 + i4x4;
quant_4x4( h, dct4x4[idx], (int(*)[4][4])def_quant4_mf, i_qp, 0 );
- scan_zigzag_4x4full( dctscan, dct4x4[idx] );
+ scan_zigzag_4x4full( dctscan, dct4x4[idx], h->mb.b_interlaced );
i_decimate_mb += x264_mb_decimate_score( dctscan, 16 );
for( i4x4 = 0, i_decimate_mb = 0; i4x4 < 4; i4x4++ )
{
quant_4x4( h, dct4x4[i4x4], (int(*)[4][4])def_quant4_mf, i_qp, 0 );
- scan_zigzag_4x4( dctscan, dct4x4[i4x4] );
+ scan_zigzag_4x4( dctscan, dct4x4[i4x4], h->mb.b_interlaced );
i_decimate_mb += x264_mb_decimate_score( dctscan, 15 );
if( i_decimate_mb >= 7 )
int16_t dct8x8[8][8];
h->dctf.sub8x8_dct8( dct8x8, p_fenc, p_fdec );
quant_8x8( h, dct8x8, h->quant8_mf[CQM_8PY], i_qp, 0 );
- scan_zigzag_8x8full( h->dct.luma8x8[i8], dct8x8 );
+ scan_zigzag_8x8full( h->dct.luma8x8[i8], dct8x8, h->mb.b_interlaced );
if( b_decimate )
nnz8x8 = 4 <= x264_mb_decimate_score( h->dct.luma8x8[i8], 64 );
quant_4x4( h, dct4x4[2], h->quant4_mf[CQM_4PY], i_qp, 0 );
quant_4x4( h, dct4x4[3], h->quant4_mf[CQM_4PY], i_qp, 0 );
for( i4 = 0; i4 < 4; i4++ )
- scan_zigzag_4x4full( h->dct.block[i8*4+i4].luma4x4, dct4x4[i4] );
+ scan_zigzag_4x4full( h->dct.block[i8*4+i4].luma4x4, dct4x4[i4], h->mb.b_interlaced );
if( b_decimate )
{
h->dctf.sub4x4_dct( dct4x4, p_fenc, p_fdec );
quant_4x4( h, dct4x4, h->quant4_mf[CQM_4PC], i_qp, 0 );
- scan_zigzag_4x4( h->dct.block[16+i8+ch*4].residual_ac, dct4x4 );
+ scan_zigzag_4x4( h->dct.block[16+i8+ch*4].residual_ac, dct4x4, h->mb.b_interlaced );
if( array_non_zero( (int*)dct4x4, sizeof(dct4x4)/sizeof(int) ) )
{
h->quantf.dequant_4x4( dct4x4, h->dequant4_mf[CQM_4PC], i_qp );
trellis_node_t *bnode;
uint8_t cabac_state_sig[64];
uint8_t cabac_state_last[64];
+ const int b_interlaced = h->mb.b_interlaced;
const int f = 1 << (i_qbits-1); // no deadzone
int i_last_nnz = -1;
int i, j;
if( i_coefs == 64 )
{
- const uint8_t *ctx_sig = &h->cabac.state[ significant_coeff_flag_offset[i_ctxBlockCat] ];
- const uint8_t *ctx_last = &h->cabac.state[ last_coeff_flag_offset[i_ctxBlockCat] ];
+ const uint8_t *ctx_sig = &h->cabac.state[ significant_coeff_flag_offset[b_interlaced][i_ctxBlockCat] ];
+ const uint8_t *ctx_last = &h->cabac.state[ last_coeff_flag_offset[b_interlaced][i_ctxBlockCat] ];
for( i = 0; i < 63; i++ )
{
- cabac_state_sig[i] = ctx_sig[ significant_coeff_flag_offset_8x8[i] ];
+ cabac_state_sig[i] = ctx_sig[ significant_coeff_flag_offset_8x8[b_interlaced][i] ];
cabac_state_last[i] = ctx_last[ last_coeff_flag_offset_8x8[i] ];
}
}
else
{
- memcpy( cabac_state_sig, &h->cabac.state[ significant_coeff_flag_offset[i_ctxBlockCat] ], 15 );
- memcpy( cabac_state_last, &h->cabac.state[ last_coeff_flag_offset[i_ctxBlockCat] ], 15 );
+ memcpy( cabac_state_sig, &h->cabac.state[ significant_coeff_flag_offset[b_interlaced][i_ctxBlockCat] ], 15 );
+ memcpy( cabac_state_last, &h->cabac.state[ last_coeff_flag_offset[b_interlaced][i_ctxBlockCat] ], 15 );
}
memcpy( nodes_cur[0].cabac_state, &h->cabac.state[ coeff_abs_level_m1_offset[i_ctxBlockCat] ], 10 );
quant_trellis_cabac( h, (int16_t*)dct,
(int*)h->quant4_mf[i_quant_cat][i_mf], h->unquant4_mf[i_quant_cat][i_qp],
- x264_dct4_weight2_zigzag, x264_zigzag_scan4,
+ x264_dct4_weight2_zigzag[h->mb.b_interlaced],
+ x264_zigzag_scan4[h->mb.b_interlaced],
i_ctxBlockCat, 15+i_qbits, i_lambda2, b_ac, 16 );
}
quant_trellis_cabac( h, (int16_t*)dct,
(int*)h->quant8_mf[i_quant_cat][i_mf], h->unquant8_mf[i_quant_cat][i_qp],
- x264_dct8_weight2_zigzag, x264_zigzag_scan8,
+ x264_dct8_weight2_zigzag[h->mb.b_interlaced],
+ x264_zigzag_scan8[h->mb.b_interlaced],
DCT_LUMA_8x8, 16+i_qbits, i_lambda2, 0, 64 );
}
static void scaling_list_write( bs_t *s, x264_pps_t *pps, int idx )
{
const int len = idx<4 ? 16 : 64;
- const int *zigzag = idx<4 ? x264_zigzag_scan4 : x264_zigzag_scan8;
+ const int *zigzag = idx<4 ? x264_zigzag_scan4[0] : x264_zigzag_scan8[0];
const uint8_t *list = pps->scaling_list[idx];
const uint8_t *def_list = (idx==CQM_4IC) ? pps->scaling_list[CQM_4IY]
: (idx==CQM_4PC) ? pps->scaling_list[CQM_4PY]
sps->b_gaps_in_frame_num_value_allowed = 0;
sps->i_mb_width = ( param->i_width + 15 ) / 16;
- sps->i_mb_height= ( param->i_height + 15 )/ 16;
- sps->b_frame_mbs_only = 1;
- sps->b_mb_adaptive_frame_field = 0;
+ sps->i_mb_height= ( param->i_height + 15 ) / 16;
+ if( param->b_interlaced )
+ sps->i_mb_height = ( sps->i_mb_height + 1 ) & ~1;
+ sps->b_frame_mbs_only = ! param->b_interlaced;
+ sps->b_mb_adaptive_frame_field = param->b_interlaced;
sps->b_direct8x8_inference = 0;
- if( sps->b_frame_mbs_only == 0 ||
+ if( ! sps->b_frame_mbs_only ||
!(param->analyse.inter & X264_ANALYSE_PSUB8x8) )
{
sps->b_direct8x8_inference = 1;
sps->crop.i_left = 0;
sps->crop.i_top = 0;
- sps->crop.i_right = (- param->i_width) & 15;
- sps->crop.i_bottom = (- param->i_height) & 15;
+ sps->crop.i_right = sps->i_mb_width*16 - param->i_width;
+ sps->crop.i_bottom = (sps->i_mb_height*16 - param->i_height) >> param->b_interlaced;
sps->b_crop = sps->crop.i_left || sps->crop.i_top ||
sps->crop.i_right || sps->crop.i_bottom;
bs_write_ue( s, sps->i_num_ref_frames );
bs_write( s, 1, sps->b_gaps_in_frame_num_value_allowed );
bs_write_ue( s, sps->i_mb_width - 1 );
- bs_write_ue( s, sps->i_mb_height - 1);
+ if (sps->b_frame_mbs_only)
+ {
+ bs_write_ue( s, sps->i_mb_height - 1);
+ }
+ else // interlaced
+ {
+ bs_write_ue( s, sps->i_mb_height/2 - 1);
+ }
bs_write( s, 1, sps->b_frame_mbs_only );
if( !sps->b_frame_mbs_only )
{
H1( " --nf Disable loop filter\n" );
H0( " -f, --filter <alpha:beta> Loop filter AlphaC0 and Beta parameters [%d:%d]\n",
defaults->i_deblocking_filter_alphac0, defaults->i_deblocking_filter_beta );
+ H0( " --interlaced Enable pure-interlaced mode\n" );
H0( "\n" );
H0( "Ratecontrol:\n" );
H0( "\n" );
{ "scenecut",required_argument, NULL, 0 },
{ "nf", no_argument, NULL, 0 },
{ "filter", required_argument, NULL, 'f' },
+ { "interlaced", no_argument, NULL, 0 },
{ "no-cabac",no_argument, NULL, 0 },
{ "qp", required_argument, NULL, 'q' },
{ "qpmin", required_argument, NULL, 0 },
int b_cabac;
int i_cabac_init_idc;
+ int b_interlaced;
+
int i_cqm_preset;
char *psz_cqm_file; /* JM format */
uint8_t cqm_4iy[16]; /* used only if i_cqm_preset == X264_CQM_CUSTOM */