static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string ) { intptr_t size = (intptr_t)opt_string; /* upon a <= 0 cache request, do nothing */ if( size <= 0 ) return 0; cache_hnd_t *h = calloc( 1, sizeof(cache_hnd_t) ); if( !h ) return -1; h->max_size = size; h->cache = malloc( (h->max_size+1) * sizeof(cli_pic_t*) ); if( !h->cache ) return -1; for( int i = 0; i < h->max_size; i++ ) { h->cache[i] = malloc( sizeof(cli_pic_t) ); if( !h->cache[i] || x264_cli_pic_alloc( h->cache[i], info->csp, info->width, info->height ) ) return -1; } h->cache[h->max_size] = NULL; /* require null terminator for list methods */ h->prev_filter = *filter; h->prev_hnd = *handle; *handle = h; *filter = cache_filter; return 0; }
static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string ) { int ret = 0; int change_fmt = (info->csp ^ param->i_csp) & X264_CSP_HIGH_DEPTH; int csp = ~(~info->csp ^ change_fmt); int bit_depth = 8*x264_cli_csp_depth_factor( csp ); if( opt_string ) { static const char * const optlist[] = { "bit_depth", NULL }; char **opts = x264_split_options( opt_string, optlist ); if( opts ) { char *str_bit_depth = x264_get_option( "bit_depth", opts ); bit_depth = x264_otoi( str_bit_depth, -1 ); ret = bit_depth < 8 || bit_depth > 16; csp = bit_depth > 8 ? csp | X264_CSP_HIGH_DEPTH : csp & ~X264_CSP_HIGH_DEPTH; change_fmt = (info->csp ^ csp) & X264_CSP_HIGH_DEPTH; free( opts ); } else ret = 1; } FAIL_IF_ERROR( bit_depth != BIT_DEPTH, "this filter supports only bit depth %d\n", BIT_DEPTH ); FAIL_IF_ERROR( ret, "unsupported bit depth conversion.\n" ); /* only add the filter to the chain if it's needed */ if( change_fmt || bit_depth != 8 * x264_cli_csp_depth_factor( csp ) ) { FAIL_IF_ERROR( !depth_filter_csp_is_supported(csp), "unsupported colorspace.\n" ); depth_hnd_t *h = x264_malloc( sizeof(depth_hnd_t) + (info->width+1)*sizeof(int16_t) ); if( !h ) return -1; h->error_buf = (int16_t*)(h + 1); h->dst_csp = csp; h->bit_depth = bit_depth; h->prev_hnd = *handle; h->prev_filter = *filter; if( x264_cli_pic_alloc( &h->buffer, h->dst_csp, info->width, info->height ) ) { x264_free( h ); return -1; } *handle = h; *filter = depth_filter; info->csp = h->dst_csp; } return 0; }
static int get_frame( hnd_t handle, cli_pic_t *output, int frame ) { fix_vfr_pts_hnd_t *h = handle; /* if we want the holder picture and it errored, return the error. */ if( frame == h->holder_frame ) { if( h->holder_ret ) return h->holder_ret; } else { /* if we have a holder frame and we don't want it, release the frame */ if( h->holder_frame > 0 && h->holder_frame < frame && h->prev_filter.release_frame( h->prev_hnd, &h->holder, h->holder_frame ) ) return -1; h->holder_frame = -1; if( h->prev_filter.get_frame( h->prev_hnd, &h->holder, frame ) ) return -1; } /* if the frame's duration is not set already, read the next frame to set it. */ if( !h->holder.duration ) { /* allocate a buffer picture if we didn't already */ if( !h->buffer_allocated ) { if( x264_cli_pic_alloc( &h->buffer, h->holder.img.csp, h->holder.img.width, h->holder.img.height ) ) return -1; h->buffer_allocated = 1; } h->holder_frame = frame+1; /* copy the current frame to the buffer, release it, and then read in the next frame to the placeholder */ if( x264_cli_pic_copy( &h->buffer, &h->holder ) || h->prev_filter.release_frame( h->prev_hnd, &h->holder, frame ) ) return -1; h->holder_ret = h->prev_filter.get_frame( h->prev_hnd, &h->holder, h->holder_frame ); /* suppress non-monotonic pts warnings by setting the duration to be at least 1 */ if( !h->holder_ret ) h->last_duration = X264_MAX( h->holder.pts - h->buffer.pts, 1 ); h->buffer.duration = h->last_duration; *output = h->buffer; } else *output = h->holder; output->pts = h->pts; h->pts += output->duration; return 0; }
static int picture_alloc( cli_pic_t *pic, hnd_t handle, int csp, int width, int height ) { if( x264_cli_pic_alloc( pic, X264_CSP_NONE, width, height ) ) return -1; pic->img.csp = csp; const x264_cli_csp_t *cli_csp = x264_cli_get_csp( csp ); if( cli_csp ) pic->img.planes = cli_csp->planes; #if HAVE_SWSCALE else if( csp == (AV_PIX_FMT_YUV411P | X264_CSP_OTHER) ) pic->img.planes = 3; else pic->img.planes = 1; //y8 and yuy2 are one plane #endif return 0; }
static int picture_alloc( cli_pic_t *pic, hnd_t handle, int csp, int width, int height ) { return x264_cli_pic_alloc( pic, csp, width, height ); }