x264_frame_t *x264_frame_new( x264_t *h )
{
- x264_frame_t *frame = x264_malloc( sizeof( x264_frame_t ) );
+ x264_frame_t *frame = x264_malloc( sizeof(x264_frame_t) );
int i, j;
int i_mb_count = h->mb.i_mb_count;
int i_stride;
int i_lines;
+ if( !frame ) return NULL;
+
memset( frame, 0, sizeof(x264_frame_t) );
/* allocate frame data (+64 for extra data for me) */
}
frame->i_stride[i] = i_stride / i_divw;
frame->i_lines[i] = i_lines / i_divh;
- frame->buffer[i] = x264_malloc( frame->i_stride[i] *
- ( frame->i_lines[i] + 64 / i_divh ) );
-
+ CHECKED_MALLOC( frame->buffer[i],
+ frame->i_stride[i] * ( frame->i_lines[i] + 64 / i_divh ) );
frame->plane[i] = ((uint8_t*)frame->buffer[i]) +
frame->i_stride[i] * 32 / i_divh + 32 / i_divw;
}
frame->filtered[0] = frame->plane[0];
for( i = 0; i < 3; i++ )
{
- frame->buffer[4+i] = x264_malloc( frame->i_stride[0] *
- ( frame->i_lines[0] + 64 ) );
-
+ CHECKED_MALLOC( frame->buffer[4+i],
+ frame->i_stride[0] * ( frame->i_lines[0] + 64 ) );
frame->filtered[i+1] = ((uint8_t*)frame->buffer[4+i]) +
frame->i_stride[0] * 32 + 32;
}
frame->i_lines_lowres = frame->i_lines[0]/2;
for( i = 0; i < 4; i++ )
{
- frame->buffer[7+i] = x264_malloc( frame->i_stride_lowres *
- ( frame->i_lines[0]/2 + 64 ) );
+ 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;
}
if( h->param.analyse.i_me_method == X264_ME_ESA )
{
- frame->buffer[11] = x264_malloc( frame->i_stride[0] * (frame->i_lines[0] + 64) * sizeof(uint16_t) );
+ CHECKED_MALLOC( frame->buffer[11],
+ 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;
}
frame->i_frame = -1;
frame->i_frame_num = -1;
- frame->mb_type= x264_malloc( i_mb_count * sizeof( int8_t) );
- frame->mv[0] = x264_malloc( 2*16 * i_mb_count * sizeof( int16_t ) );
- frame->ref[0] = x264_malloc( 4 * i_mb_count * sizeof( int8_t ) );
+ CHECKED_MALLOC( frame->mb_type, i_mb_count * sizeof(int8_t));
+ CHECKED_MALLOC( frame->mv[0], 2*16 * i_mb_count * sizeof(int16_t) );
+ CHECKED_MALLOC( frame->ref[0], 4 * i_mb_count * sizeof(int8_t) );
if( h->param.i_bframe )
{
- frame->mv[1] = x264_malloc( 2*16 * i_mb_count * sizeof( int16_t ) );
- frame->ref[1] = x264_malloc( 4 * i_mb_count * sizeof( int8_t ) );
+ CHECKED_MALLOC( frame->mv[1], 2*16 * i_mb_count * sizeof(int16_t) );
+ CHECKED_MALLOC( frame->ref[1], 4 * i_mb_count * sizeof(int8_t) );
}
else
{
frame->ref[1] = NULL;
}
- frame->i_row_bits = x264_malloc( i_lines/16 * sizeof( int ) );
- frame->i_row_qp = x264_malloc( i_lines/16 * sizeof( int ) );
+ CHECKED_MALLOC( frame->i_row_bits, i_lines/16 * sizeof(int) );
+ CHECKED_MALLOC( frame->i_row_qp, i_lines/16 * sizeof(int) );
for( i = 0; i < h->param.i_bframe + 2; i++ )
for( j = 0; j < h->param.i_bframe + 2; j++ )
- frame->i_row_satds[i][j] = x264_malloc( i_lines/16 * sizeof( int ) );
+ CHECKED_MALLOC( frame->i_row_satds[i][j], i_lines/16 * sizeof(int) );
return frame;
+
+fail:
+ x264_frame_delete( frame );
+ return NULL;
}
void x264_frame_delete( x264_frame_t *frame )
{
int i, j;
- for( i = 0; i < frame->i_plane; i++ )
- x264_free( frame->buffer[i] );
- for( i = 4; i < 12; i++ ) /* filtered planes */
+ for( i = 0; i < 12; i++ )
x264_free( frame->buffer[i] );
for( i = 0; i < X264_BFRAME_MAX+2; i++ )
for( j = 0; j < X264_BFRAME_MAX+2; j++ )
}
}
-void x264_macroblock_cache_init( x264_t *h )
+int x264_macroblock_cache_init( x264_t *h )
{
int i, j;
int i_mb_count = h->mb.i_mb_count;
h->mb.i_b8_stride = h->sps->i_mb_width * 2;
h->mb.i_b4_stride = h->sps->i_mb_width * 4;
- h->mb.qp = x264_malloc( i_mb_count * sizeof(int8_t) );
- h->mb.cbp = x264_malloc( i_mb_count * sizeof(int16_t) );
- h->mb.skipbp = x264_malloc( i_mb_count * sizeof(int8_t) );
- h->mb.mb_transform_size = x264_malloc( i_mb_count * sizeof(int8_t) );
+ 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) );
+ CHECKED_MALLOC( h->mb.mb_transform_size, i_mb_count * sizeof(int8_t) );
/* 0 -> 3 top(4), 4 -> 6 : left(3) */
- h->mb.intra4x4_pred_mode = x264_malloc( i_mb_count * 7 * sizeof( int8_t ) );
+ CHECKED_MALLOC( h->mb.intra4x4_pred_mode, i_mb_count * 7 * sizeof(int8_t) );
/* all coeffs */
- h->mb.non_zero_count = x264_malloc( i_mb_count * 24 * sizeof( uint8_t ) );
+ CHECKED_MALLOC( h->mb.non_zero_count, i_mb_count * 24 * sizeof(uint8_t) );
if( h->param.b_cabac )
{
- h->mb.chroma_pred_mode = x264_malloc( i_mb_count * sizeof( int8_t) );
- h->mb.mvd[0] = x264_malloc( 2*16 * i_mb_count * sizeof( int16_t ) );
- h->mb.mvd[1] = x264_malloc( 2*16 * i_mb_count * sizeof( int16_t ) );
+ CHECKED_MALLOC( h->mb.chroma_pred_mode, i_mb_count * sizeof(int8_t) );
+ CHECKED_MALLOC( h->mb.mvd[0], 2*16 * i_mb_count * sizeof(int16_t) );
+ CHECKED_MALLOC( h->mb.mvd[1], 2*16 * i_mb_count * sizeof(int16_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++ )
- h->mb.mvr[i][j] = x264_malloc( 2 * i_mb_count * sizeof( int16_t ) );
+ CHECKED_MALLOC( h->mb.mvr[i][j], 2 * i_mb_count * sizeof(int16_t) );
}
/* init with not avaiable (for top right idx=7,15) */
memset( h->mb.cache.ref[0], -2, X264_SCAN8_SIZE * sizeof( int8_t ) );
memset( h->mb.cache.ref[1], -2, X264_SCAN8_SIZE * sizeof( int8_t ) );
+
+ return 0;
+fail: return -1;
}
void x264_macroblock_cache_end( x264_t *h )
{