static int Init( filter_t *p_filter ) { filter_sys_t *p_sys = p_filter->p_sys; if( IsFmtSimilar( &p_filter->fmt_in.video, &p_sys->fmt_in ) && IsFmtSimilar( &p_filter->fmt_out.video, &p_sys->fmt_out ) && p_sys->ctx ) { return VLC_SUCCESS; } if( ( p_filter->fmt_in.video.i_chroma != VLC_CODEC_I420 && p_filter->fmt_in.video.i_chroma != VLC_CODEC_YV12 ) || p_filter->fmt_out.video.i_chroma != VLC_FOURCC('Y','4','2','0') ) { msg_Err( p_filter, "format not supported" ); return VLC_EGENERIC; } if( p_sys->ctx ) sws_arm_jit_free( p_sys->ctx ); p_sys->ctx = sws_arm_jit_create_omapfb_yuv420_scaler_armv6( p_filter->fmt_in.video.i_width, p_filter->fmt_in.video.i_height, p_filter->fmt_out.video.i_width, p_filter->fmt_out.video.i_height, 2 ); if( !p_sys->ctx ) { msg_Err( p_filter, "could not init SwScaler" ); return VLC_EGENERIC; } p_sys->fmt_in = p_filter->fmt_in; p_sys->fmt_out = p_filter->fmt_out; return VLC_SUCCESS; }
static int Init( filter_t *p_filter ) { filter_sys_t *p_sys = p_filter->p_sys; const video_format_t *p_fmti = &p_filter->fmt_in.video; video_format_t *p_fmto = &p_filter->fmt_out.video; if( IsFmtSimilar( p_fmti, &p_sys->fmt_in ) && IsFmtSimilar( p_fmto, &p_sys->fmt_out ) && p_sys->ctx ) { return VLC_SUCCESS; } Clean( p_filter ); /* Init with new parameters */ ScalerConfiguration cfg; if( GetParameters( &cfg, p_fmti, p_fmto, p_sys->i_sws_flags ) ) { msg_Err( p_filter, "format not supported" ); return VLC_EGENERIC; } if( p_fmti->i_width <= 0 || p_fmto->i_width <= 0 ) { msg_Err( p_filter, "0 width not supported" ); return VLC_EGENERIC; } /* swscale does not like too small width */ p_sys->i_extend_factor = 1; while( __MIN( p_fmti->i_width, p_fmto->i_width ) * p_sys->i_extend_factor < MINIMUM_WIDTH) p_sys->i_extend_factor++; const unsigned i_fmti_width = p_fmti->i_width * p_sys->i_extend_factor; const unsigned i_fmto_width = p_fmto->i_width * p_sys->i_extend_factor; for( int n = 0; n < (cfg.b_has_a ? 2 : 1); n++ ) { const int i_fmti = n == 0 ? cfg.i_fmti : PIX_FMT_GRAY8; const int i_fmto = n == 0 ? cfg.i_fmto : PIX_FMT_GRAY8; struct SwsContext *ctx; ctx = sws_getContext( i_fmti_width, p_fmti->i_height, i_fmti, i_fmto_width, p_fmto->i_height, i_fmto, cfg.i_sws_flags | p_sys->i_cpu_mask, p_sys->p_src_filter, p_sys->p_dst_filter, 0 ); if( n == 0 ) p_sys->ctx = ctx; else p_sys->ctxA = ctx; } if( p_sys->ctxA ) { p_sys->p_src_a = picture_New( VLC_CODEC_GREY, i_fmti_width, p_fmti->i_height, 0, 1 ); p_sys->p_dst_a = picture_New( VLC_CODEC_GREY, i_fmto_width, p_fmto->i_height, 0, 1 ); } if( p_sys->i_extend_factor != 1 ) { p_sys->p_src_e = picture_New( p_fmti->i_chroma, i_fmti_width, p_fmti->i_height, 0, 1 ); p_sys->p_dst_e = picture_New( p_fmto->i_chroma, i_fmto_width, p_fmto->i_height, 0, 1 ); if( p_sys->p_src_e ) memset( p_sys->p_src_e->p[0].p_pixels, 0, p_sys->p_src_e->p[0].i_pitch * p_sys->p_src_e->p[0].i_lines ); if( p_sys->p_dst_e ) memset( p_sys->p_dst_e->p[0].p_pixels, 0, p_sys->p_dst_e->p[0].i_pitch * p_sys->p_dst_e->p[0].i_lines ); } if( !p_sys->ctx || ( cfg.b_has_a && ( !p_sys->ctxA || !p_sys->p_src_a || !p_sys->p_dst_a ) ) || ( p_sys->i_extend_factor != 1 && ( !p_sys->p_src_e || !p_sys->p_dst_e ) ) ) { msg_Err( p_filter, "could not init SwScaler and/or allocate memory" ); Clean( p_filter ); return VLC_EGENERIC; } p_sys->b_add_a = cfg.b_add_a; p_sys->b_copy = cfg.b_copy; p_sys->fmt_in = *p_fmti; p_sys->fmt_out = *p_fmto; p_sys->b_swap_uvi = cfg.b_swap_uvi; p_sys->b_swap_uvo = cfg.b_swap_uvo; video_format_ScaleCropAr( p_fmto, p_fmti ); #if 0 msg_Dbg( p_filter, "%ix%i chroma: %4.4s -> %ix%i chroma: %4.4s extend by %d", p_fmti->i_width, p_fmti->i_height, (char *)&p_fmti->i_chroma, p_fmto->i_width, p_fmto->i_height, (char *)&p_fmto->i_chroma, p_sys->i_extend_factor ); #endif return VLC_SUCCESS; }