Commit d08e725f authored by Christophe Massiot's avatar Christophe Massiot
Browse files

* modules/codec/fake.c: New obscure options to allow for maximum width

   and height while keeping the aspect ratio of the original picture. New
   options to deinterlace the picture on loading.
parent e7cde2e6
......@@ -28,14 +28,7 @@
#include <vlc/decoder.h>
#include "vlc_image.h"
/*****************************************************************************
* decoder_sys_t : fake decoder descriptor
*****************************************************************************/
struct decoder_sys_t
{
picture_t *p_image;
};
#include "vlc_filter.h"
/*****************************************************************************
* Local prototypes
......@@ -51,9 +44,29 @@ static picture_t *DecodeBlock ( decoder_t *, block_t ** );
#define FILE_TEXT N_("Image file")
#define FILE_LONGTEXT N_( \
"Path of the image file when using the fake input." )
#define WIDTH_TEXT N_("Video width")
#define WIDTH_LONGTEXT N_( \
"Allows you to specify the output video width." )
#define HEIGHT_TEXT N_("Video height")
#define HEIGHT_LONGTEXT N_( \
"Allows you to specify the output video height." )
#define KEEP_AR_TEXT N_("Keep aspect ratio")
#define KEEP_AR_LONGTEXT N_( \
"If selected, width and height will be considered as maximum values." )
#define ASPECT_RATIO_TEXT N_("Background aspect ratio")
#define ASPECT_RATIO_LONGTEXT N_( \
"Aspect ratio of the image file (4:3, 16:9)." )
"Aspect ratio of the image file (4:3, 16:9). Default is square pixels." )
#define DEINTERLACE_TEXT N_("Deinterlace video")
#define DEINTERLACE_LONGTEXT N_( \
"Allows you to deinterlace the image after loading." )
#define DEINTERLACE_MODULE_TEXT N_("Deinterlace module")
#define DEINTERLACE_MODULE_LONGTEXT N_( \
"Specifies the deinterlace module to use." )
static char *ppsz_deinterlace_type[] =
{
"deinterlace", "ffmpeg-deinterlace"
};
vlc_module_begin();
set_category( CAT_INPUT );
......@@ -66,8 +79,20 @@ vlc_module_begin();
add_file( "fake-file", "", NULL, FILE_TEXT,
FILE_LONGTEXT, VLC_FALSE );
add_string( "fake-aspect-ratio", "4:3", NULL,
add_integer( "fake-width", 0, NULL, WIDTH_TEXT,
WIDTH_LONGTEXT, VLC_TRUE );
add_integer( "fake-height", 0, NULL, HEIGHT_TEXT,
HEIGHT_LONGTEXT, VLC_TRUE );
add_bool( "fake-keep-ar", 0, NULL, KEEP_AR_TEXT, KEEP_AR_LONGTEXT,
VLC_TRUE );
add_string( "fake-aspect-ratio", "", NULL,
ASPECT_RATIO_TEXT, ASPECT_RATIO_LONGTEXT, VLC_TRUE );
add_bool( "fake-deinterlace", 0, NULL, DEINTERLACE_TEXT,
DEINTERLACE_LONGTEXT, VLC_FALSE );
add_string( "fake-deinterlace-module", "deinterlace", NULL,
DEINTERLACE_MODULE_TEXT, DEINTERLACE_MODULE_LONGTEXT,
VLC_FALSE );
change_string_list( ppsz_deinterlace_type, 0, 0 );
vlc_module_end();
/*****************************************************************************
......@@ -76,49 +101,42 @@ vlc_module_end();
static int OpenDecoder( vlc_object_t *p_this )
{
decoder_t *p_dec = (decoder_t*)p_this;
decoder_sys_t *p_sys;
vlc_value_t val;
image_handler_t *p_handler;
video_format_t fmt_in, fmt_out;
picture_t *p_image;
char *psz_file;
vlc_bool_t b_keep_ar;
int i_aspect = 0;
if( p_dec->fmt_in.i_codec != VLC_FOURCC('f','a','k','e') )
{
return VLC_EGENERIC;
}
/* Allocate the memory needed to store the decoder's structure */
if( ( p_dec->p_sys = p_sys =
(decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
var_Create( p_dec, "fake-file", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
var_Get( p_dec, "fake-file", &val );
if( val.psz_string == NULL || !*val.psz_string )
{
msg_Err( p_dec, "out of memory" );
if( val.psz_string ) free( val.psz_string );
msg_Err( p_dec, "specify a file with --fake-file=..." );
return VLC_EGENERIC;
}
psz_file = val.psz_string;
var_Create( p_dec, "fake-file", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
var_Get( p_dec, "fake-file", &val );
if( val.psz_string != NULL && *val.psz_string )
{
image_handler_t *p_handler = image_HandlerCreate( p_dec );
video_format_t fmt_in, fmt_out;
memset( &fmt_in, 0, sizeof(fmt_in) );
memset( &fmt_out, 0, sizeof(fmt_out) );
fmt_out.i_chroma = VLC_FOURCC('Y', 'V', '1', '2');
p_sys->p_image = image_ReadUrl( p_handler, val.psz_string,
&fmt_in, &fmt_out );
image_HandlerDelete( p_handler );
memset( &fmt_in, 0, sizeof(fmt_in) );
memset( &fmt_out, 0, sizeof(fmt_out) );
fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
if( p_sys->p_image == NULL )
{
msg_Err( p_dec, "unable to read image file %s", val.psz_string );
free( p_dec->p_sys );
return VLC_EGENERIC;
}
msg_Dbg( p_dec, "file %s loaded successfully", val.psz_string );
p_dec->fmt_out.video = fmt_out;
}
if( val.psz_string ) free( val.psz_string );
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 )
{
......@@ -127,28 +145,131 @@ static int OpenDecoder( vlc_object_t *p_this )
if( psz_parser )
{
*psz_parser++ = '\0';
p_dec->fmt_out.video.i_aspect = atoi( val.psz_string )
i_aspect = atoi( val.psz_string )
* VOUT_ASPECT_FACTOR / atoi( psz_parser );
}
else
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 );
return VLC_EGENERIC;
}
msg_Dbg( p_dec, "file %s loaded successfully", psz_file );
if ( 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 )
{
msg_Warn( p_dec, "bad aspect ratio %s", val.psz_string );
p_dec->fmt_out.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
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
{
p_old->pf_release( p_old );
}
}
}
free( val.psz_string );
if ( i_aspect )
{
p_dec->fmt_out.video.i_aspect = i_aspect;
}
else
{
p_dec->fmt_out.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
p_dec->fmt_out.video.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 );
if ( val.psz_string != NULL ) free( val.psz_string );
if ( p_image == NULL )
{
msg_Warn( p_dec, "couldn't load deinterlace module" );
p_image = p_old;
}
else
{
p_old->pf_release( p_old );
}
}
/* Set output properties */
p_dec->fmt_out.i_cat = VIDEO_ES;
p_dec->fmt_out.i_codec = VLC_FOURCC('Y','V','1','2');
p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0');
p_dec->fmt_out.video = fmt_out;
/* Set callbacks */
p_dec->pf_decode_video = DecodeBlock;
p_dec->p_sys = (decoder_sys_t *)p_image;
return VLC_SUCCESS;
}
......@@ -158,7 +279,7 @@ static int OpenDecoder( vlc_object_t *p_this )
****************************************************************************/
static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
{
decoder_sys_t *p_sys = p_dec->p_sys;
picture_t *p_image = (picture_t *)p_dec->p_sys;
picture_t *p_pic;
if( pp_block == NULL || !*pp_block ) return NULL;
......@@ -169,7 +290,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
goto error;
}
vout_CopyPicture( p_dec, p_pic, p_sys->p_image );
vout_CopyPicture( p_dec, p_pic, p_image );
p_pic->date = (*pp_block)->i_pts;
error:
......@@ -185,9 +306,8 @@ error:
static void CloseDecoder( vlc_object_t *p_this )
{
decoder_t *p_dec = (decoder_t *)p_this;
decoder_sys_t *p_sys = p_dec->p_sys;
picture_t *p_image = (picture_t *)p_dec->p_sys;
if( p_sys->p_image != NULL )
p_sys->p_image->pf_release( p_sys->p_image );
free( p_sys );
if( p_image != NULL )
p_image->pf_release( p_image );
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment