X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Finvmem.c;h=7e96d27b00aaf967d5ed64991a24a09a6c304cc0;hb=852f0db978ded9e96adff1165bba5b6fe025775d;hp=2990644f16584d2b5b0a6157e52bb36f124f5167;hpb=78d87996ccb92d1dc91c9987685f976ed3be08a6;p=vlc diff --git a/modules/codec/invmem.c b/modules/codec/invmem.c index 2990644f16..7e96d27b00 100644 --- a/modules/codec/invmem.c +++ b/modules/codec/invmem.c @@ -67,27 +67,25 @@ static picture_t *DecodeBlock ( decoder_t *, block_t ** ); #define T_DATA N_( "Callback data" ) #define LT_DATA N_( "Data for the locking and unlocking functions" ) -#define INVMEM_HELP N_( "This module make possible making video stream from raw-image " \ - "generating (to memory) from rendering program uses libvlc. " \ - "To use this module from libvlc set --codec to invmem, "\ - "set all --invmem-* options in vlc_argv an use " \ - "libvlc_media_new(libvlc, \"fake://\", &ex);. " \ - "Besides is simillar to vmem video output module." ) +#define T_CHROMA N_("Chroma") +#define LT_CHROMA N_("Output chroma for the memory image as a 4-character " \ + "string, eg. \"RV32\".") + vlc_module_begin() set_category( CAT_INPUT ) set_subcategory( SUBCAT_INPUT_VCODEC ) set_shortname( N_("Memory video decoder") ) set_description( N_("Memory video decoder") ) - set_help( INVMEM_HELP ) set_capability( "decoder", 50 ) set_callbacks( OpenDecoder, CloseDecoder ) add_shortcut( "invmem" ) - add_integer( "invmem-width", "0", NULL, T_WIDTH, LT_WIDTH, false ) - add_integer( "invmem-height", "0", NULL, T_HEIGHT, LT_HEIGHT, false ) + add_integer( "invmem-width", 0, NULL, T_WIDTH, LT_WIDTH, false ) + add_integer( "invmem-height", 0, NULL, T_HEIGHT, LT_HEIGHT, false ) add_string( "invmem-lock", "0", NULL, T_LOCK, LT_LOCK, true ) add_string( "invmem-unlock", "0", NULL, T_UNLOCK, LT_UNLOCK, true ) add_string( "invmem-data", "0", NULL, T_DATA, LT_DATA, true ) + add_string( "invmem-chroma", "RV24", NULL, T_CHROMA, LT_CHROMA, true) vlc_module_end() @@ -101,7 +99,7 @@ struct decoder_sys_t int i_height; int i_pitch; - picture_t *p_pic; + vlc_fourcc_t i_chroma; }; @@ -113,6 +111,7 @@ static int OpenDecoder( vlc_object_t *p_this ) decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; char *psz_tmp; + int pitch; if( p_dec->fmt_in.i_codec != VLC_FOURCC('f','a','k','e')) { @@ -120,16 +119,17 @@ static int OpenDecoder( vlc_object_t *p_this ) } /* 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 ) + if( ( p_dec->p_sys = p_sys = malloc(sizeof(decoder_sys_t)) ) == NULL ) return VLC_ENOMEM; - // get parametrs + // get parameters + char* chromaStr = var_CreateGetString( p_dec, "invmem-chroma" ); p_sys->i_width = var_CreateGetInteger( p_this, "invmem-width" ); p_sys->i_height = var_CreateGetInteger( p_this, "invmem-height" ); - if (p_sys->i_width == 0 || p_sys->i_height == 0) { - msg_Err( p_dec, "--vmem-width and --vmem-height must be > 0" ); - return VLC_EGENERIC; + if( p_sys->i_width == 0 || p_sys->i_height == 0 ) + { + msg_Err( p_dec, "--invmem-width and --invmem-height must be > 0" ); + goto error; } psz_tmp = var_CreateGetString( p_dec, "invmem-lock" ); @@ -147,28 +147,77 @@ static int OpenDecoder( vlc_object_t *p_this ) if( !p_sys->pf_lock || !p_sys->pf_unlock ) { msg_Err( p_dec, "Invalid lock or unlock callbacks" ); - return VLC_EGENERIC; + goto error; + } + + if ( chromaStr == NULL ) + { + msg_Err( p_dec, "Invalid invmem-chroma string." ); + goto error; + } + const vlc_fourcc_t chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, chromaStr ); + + if ( !chroma ) + { + msg_Err( p_dec, "invmem-chroma should be 4 characters long." ); + goto error; } /* Set output properties */ - //p_dec->fmt_out.i_codec = VLC_CODEC_RGBA; - p_dec->fmt_out.i_codec = VLC_CODEC_RGB24; + switch (chroma) + { + case VLC_CODEC_RGB15: + p_dec->fmt_out.video.i_rmask = 0x001f; + p_dec->fmt_out.video.i_gmask = 0x03e0; + p_dec->fmt_out.video.i_bmask = 0x7c00; + pitch = p_sys->i_width * 2; + break; + case VLC_CODEC_RGB16: + p_dec->fmt_out.video.i_rmask = 0x001f; + p_dec->fmt_out.video.i_gmask = 0x07e0; + p_dec->fmt_out.video.i_bmask = 0xf800; + pitch = p_sys->i_width * 2; + break; + case VLC_CODEC_RGB24: + p_dec->fmt_out.video.i_rmask = 0xff0000; + p_dec->fmt_out.video.i_gmask = 0x00ff00; + p_dec->fmt_out.video.i_bmask = 0x0000ff; + pitch = p_sys->i_width * 3; + break; + case VLC_CODEC_RGB32: + p_dec->fmt_out.video.i_rmask = 0xff0000; + p_dec->fmt_out.video.i_gmask = 0x00ff00; + p_dec->fmt_out.video.i_bmask = 0x0000ff; + pitch = p_sys->i_width * 4; + break; + default: + p_dec->fmt_out.video.i_rmask = 0; + p_dec->fmt_out.video.i_gmask = 0; + p_dec->fmt_out.video.i_bmask = 0; + pitch = 0; + msg_Warn( p_dec, "Unknown chroma %s", chromaStr ); + goto error; + } + + free( chromaStr ); + + p_dec->fmt_out.i_codec = chroma; p_dec->fmt_out.video.i_width = p_dec->p_sys->i_width; p_dec->fmt_out.video.i_height = p_dec->p_sys->i_height; - p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * p_dec->p_sys->i_width / p_dec->p_sys->i_height; - p_dec->fmt_out.video.i_rmask = 0xff0000; - p_dec->fmt_out.video.i_gmask = 0x00ff00; - p_dec->fmt_out.video.i_bmask = 0x0000ff; + p_dec->fmt_out.video.i_sar_num = 1; + p_dec->fmt_out.video.i_sar_den = 1; p_dec->fmt_out.i_cat = VIDEO_ES; - p_sys->i_pitch = p_sys->i_width*3 + p_sys->i_width%4; - - p_sys->p_pic = NULL; + p_sys->i_pitch = pitch; /* Set callbacks */ p_dec->pf_decode_video = DecodeBlock; return VLC_SUCCESS; +error: + free( p_sys ); + free( chromaStr ); + return VLC_EGENERIC; } /**************************************************************************** @@ -180,27 +229,27 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) { decoder_sys_t *p_sys = p_dec->p_sys; block_t *p_block; + picture_t* p_pic; if( !pp_block || !*pp_block ) return NULL; p_block = *pp_block; // create new picture - if( p_sys->p_pic != NULL ) - picture_Release( p_sys->p_pic ); - p_sys->p_pic = decoder_NewPicture( p_dec ); - p_sys->p_pic->b_force = true; - p_sys->p_pic->p->i_pitch = p_dec->p_sys->i_pitch; - p_sys->p_pic->date = p_block->i_pts > 0 ? p_block->i_pts : p_block->i_dts; + p_pic = decoder_NewPicture( p_dec ); + if ( !p_pic ) return NULL; + p_pic->b_force = true; + p_pic->p->i_pitch = p_dec->p_sys->i_pitch; + p_pic->date = p_block->i_pts > VLC_TS_INVALID ? p_block->i_pts : p_block->i_dts; // lock input and copy to picture - p_sys->p_pic->p->p_pixels = p_sys->pf_lock( p_dec->p_sys->p_data ); + p_pic->p->p_pixels = p_sys->pf_lock( p_dec->p_sys->p_data ); // unlock input p_sys->pf_unlock( p_dec->p_sys->p_data ); block_Release( *pp_block ); *pp_block = NULL; - return p_sys->p_pic; + return p_pic; } /***************************************************************************** @@ -211,8 +260,5 @@ 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; - if( p_sys->p_pic != NULL ) - picture_Release( p_sys->p_pic ); - free( p_sys ); }