/***************************************************************************** * OpenDecoder: probe the decoder and return score *****************************************************************************/ static int OpenDecoder( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; vlc_value_t val; image_handler_t *p_handler; video_format_t fmt_in, fmt_out; picture_t *p_image; char *psz_file, *psz_chroma; bool b_keep_ar; int i_aspect = 0; if( p_dec->fmt_in.i_codec != VLC_FOURCC('f','a','k','e') ) { return VLC_EGENERIC; } p_dec->p_sys = calloc( 1, sizeof( *p_dec->p_sys ) ); if( !p_dec->p_sys ) return VLC_ENOMEM; psz_file = var_CreateGetNonEmptyStringCommand( p_dec, "fake-file" ); if( !psz_file ) { msg_Err( p_dec, "specify a file with --fake-file=..." ); free( p_dec->p_sys ); return VLC_EGENERIC; } var_AddCallback( p_dec, "fake-file", FakeCallback, p_dec ); memset( &fmt_in, 0, sizeof(fmt_in) ); memset( &fmt_out, 0, sizeof(fmt_out) ); val.i_int = var_CreateGetIntegerCommand( p_dec, "fake-file-reload" ); if( val.i_int > 0) { p_dec->p_sys->b_reload = true; p_dec->p_sys->i_reload = (mtime_t)(val.i_int * 1000000); p_dec->p_sys->i_next = (mtime_t)(p_dec->p_sys->i_reload + mdate()); } var_AddCallback( p_dec, "fake-file-reload", FakeCallback , p_dec ); psz_chroma = var_CreateGetString( p_dec, "fake-chroma" ); fmt_out.i_chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_chroma ); if( !fmt_out.i_chroma ) { msg_Warn( p_dec, "Invalid chroma (%s). Using I420.", psz_chroma ); fmt_out.i_chroma = VLC_CODEC_I420; } free( psz_chroma ); var_Create( p_dec, "fake-keep-ar", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_Get( p_dec, "fake-keep-ar", &val ); b_keep_ar = val.b_bool; var_Create( p_dec, "fake-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Create( p_dec, "fake-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Create( p_dec, "fake-aspect-ratio", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Get( p_dec, "fake-aspect-ratio", &val ); if ( val.psz_string ) { char *psz_parser = strchr( val.psz_string, ':' ); if( psz_parser ) { *psz_parser++ = '\0'; i_aspect = atoi( val.psz_string ) * VOUT_ASPECT_FACTOR / atoi( psz_parser ); } free( val.psz_string ); } if ( !b_keep_ar ) { var_Get( p_dec, "fake-width", &val ); fmt_out.i_width = val.i_int; var_Get( p_dec, "fake-height", &val ); fmt_out.i_height = val.i_int; } p_handler = image_HandlerCreate( p_dec ); p_image = image_ReadUrl( p_handler, psz_file, &fmt_in, &fmt_out ); image_HandlerDelete( p_handler ); if ( p_image == NULL ) { msg_Err( p_dec, "unable to read image file %s", psz_file ); free( psz_file ); free( p_dec->p_sys ); return VLC_EGENERIC; } msg_Dbg( p_dec, "file %s loaded successfully", psz_file ); free( psz_file ); if ( b_keep_ar ) { picture_t *p_old = p_image; int i_width, i_height; var_Get( p_dec, "fake-width", &val ); i_width = val.i_int; var_Get( p_dec, "fake-height", &val ); i_height = val.i_int; if ( i_width && i_height ) { int i_image_ar = fmt_out.i_width * VOUT_ASPECT_FACTOR / fmt_out.i_height; int i_region_ar = i_width * VOUT_ASPECT_FACTOR / i_height; fmt_in = fmt_out; if ( i_aspect == i_image_ar ) { fmt_out.i_width = i_width; fmt_out.i_height = i_height; } else if ( i_image_ar > i_region_ar ) { fmt_out.i_width = i_width; fmt_out.i_height = i_width * VOUT_ASPECT_FACTOR / i_image_ar; i_aspect = i_image_ar; } else { fmt_out.i_height = i_height; fmt_out.i_width = i_height * i_image_ar / VOUT_ASPECT_FACTOR; i_aspect = i_image_ar; } p_handler = image_HandlerCreate( p_dec ); p_image = image_Convert( p_handler, p_old, &fmt_in, &fmt_out ); image_HandlerDelete( p_handler ); if ( p_image == NULL ) { msg_Warn( p_dec, "couldn't load resizing module" ); p_image = p_old; fmt_out = fmt_in; } else { picture_Release( p_old ); } } } if ( i_aspect ) { fmt_out.i_aspect = i_aspect; } else { fmt_out.i_aspect = fmt_out.i_width * VOUT_ASPECT_FACTOR / fmt_out.i_height; } var_Create( p_dec, "fake-deinterlace", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_Get( p_dec, "fake-deinterlace", &val ); if ( val.b_bool ) { picture_t *p_old = p_image; var_Create( p_dec, "fake-deinterlace-module", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Get( p_dec, "fake-deinterlace-module", &val ); p_handler = image_HandlerCreate( p_dec ); p_image = image_Filter( p_handler, p_old, &fmt_out, val.psz_string ); image_HandlerDelete( p_handler ); free( val.psz_string ); if ( p_image == NULL ) { msg_Warn( p_dec, "couldn't load deinterlace module" ); p_image = p_old; } else { picture_Release( p_old ); } } /* Set output properties */ p_dec->fmt_out.i_cat = VIDEO_ES; p_dec->fmt_out.i_codec = fmt_out.i_chroma; p_dec->fmt_out.video = fmt_out; /* Set callbacks */ p_dec->pf_decode_video = DecodeBlock; p_dec->p_sys->p_image = p_image; vlc_mutex_init( &p_dec->p_sys->lock ); return VLC_SUCCESS; }
/***************************************************************************** * Create: allocates Transform video thread output method ***************************************************************************** * This function allocates and initializes a Transform vout method. *****************************************************************************/ static int Create( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; char *psz_method; /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) return VLC_ENOMEM; p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = NULL; p_vout->pf_render = Render; p_vout->pf_display = NULL; p_vout->pf_control = Control; config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options, p_vout->p_cfg ); /* Look what method was requested */ psz_method = var_CreateGetNonEmptyStringCommand( p_vout, "transform-type" ); switch( p_vout->fmt_in.i_chroma ) { CASE_PLANAR_YUV_SQUARE case VLC_CODEC_GREY: p_vout->p_sys->pf_filter = FilterPlanar; break; case VLC_CODEC_I422: case VLC_CODEC_J422: p_vout->p_sys->pf_filter = FilterI422; break; CASE_PACKED_YUV_422 p_vout->p_sys->pf_filter = FilterYUYV; break; default: msg_Err( p_vout, "Unsupported chroma" ); free( p_vout->p_sys ); return VLC_EGENERIC; } if( psz_method == NULL ) { msg_Err( p_vout, "configuration variable %s empty", "transform-type" ); msg_Err( p_vout, "no valid transform mode provided, using '90'" ); p_vout->p_sys->i_mode = TRANSFORM_MODE_90; p_vout->p_sys->b_rotation = 1; } else { if( !strcmp( psz_method, "hflip" ) ) { p_vout->p_sys->i_mode = TRANSFORM_MODE_HFLIP; p_vout->p_sys->b_rotation = 0; } else if( !strcmp( psz_method, "vflip" ) ) { p_vout->p_sys->i_mode = TRANSFORM_MODE_VFLIP; p_vout->p_sys->b_rotation = 0; } else if( !strcmp( psz_method, "90" ) ) { p_vout->p_sys->i_mode = TRANSFORM_MODE_90; p_vout->p_sys->b_rotation = 1; } else if( !strcmp( psz_method, "180" ) ) { p_vout->p_sys->i_mode = TRANSFORM_MODE_180; p_vout->p_sys->b_rotation = 0; } else if( !strcmp( psz_method, "270" ) ) { p_vout->p_sys->i_mode = TRANSFORM_MODE_270; p_vout->p_sys->b_rotation = 1; } else { msg_Err( p_vout, "no valid transform mode provided, using '90'" ); p_vout->p_sys->i_mode = TRANSFORM_MODE_90; p_vout->p_sys->b_rotation = 1; } free( psz_method ); } return VLC_SUCCESS; }