static int blendbench_LoadImage( vlc_object_t *p_this, picture_t **pp_pic, vlc_fourcc_t i_chroma, char *psz_file, const char *psz_name ) { image_handler_t *p_image; video_format_t fmt_out; video_format_Init( &fmt_out, i_chroma ); p_image = image_HandlerCreate( p_this ); *pp_pic = image_ReadUrl( p_image, psz_file, &fmt_out ); video_format_Clean( &fmt_out ); image_HandlerDelete( p_image ); if( *pp_pic == NULL ) { msg_Err( p_this, "Unable to load %s image", psz_name ); return VLC_EGENERIC; } msg_Dbg( p_this, "%s image has dim %d x %d (Y plane)", psz_name, (*pp_pic)->p[Y_PLANE].i_visible_pitch, (*pp_pic)->p[Y_PLANE].i_visible_lines ); return VLC_SUCCESS; }
/***************************************************************************** * Wrappers for loading and unloading osd parser modules. *****************************************************************************/ static bool osd_ParserLoad( osd_menu_t *p_menu, const char *psz_file ) { /* Stuff needed for Parser */ p_menu->psz_file = strdup( psz_file ); p_menu->p_image = image_HandlerCreate( p_menu ); if( !p_menu->p_image || !p_menu->psz_file ) { msg_Err( p_menu, "unable to load images, aborting .." ); return false; } else { const char *psz_type; const char *psz_ext = strrchr( p_menu->psz_file, '.' ); if( psz_ext && !strcmp( psz_ext, ".cfg") ) psz_type = "import-osd"; else psz_type = "import-osd-xml"; p_menu->p_parser = module_need( p_menu, "osd parser", psz_type, true ); if( !p_menu->p_parser ) { return false; } } return true; }
/***************************************************************************** * FakeCallback: Image source change callback. *****************************************************************************/ static int FakeCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { VLC_UNUSED(p_this); VLC_UNUSED(oldval); decoder_t *p_dec = (decoder_t *)p_data; if( !strcmp( psz_var, "fake-file" ) ) { image_handler_t *p_handler; picture_t *p_new_image; video_format_t fmt_in, fmt_out; char *psz_file = newval.psz_string; picture_t *p_image; vlc_mutex_lock( &p_dec->p_sys->lock ); p_image = p_dec->p_sys->p_image; if( !psz_file || !*psz_file ) { msg_Err( p_dec, "fake-file value must be non empty." ); vlc_mutex_unlock( &p_dec->p_sys->lock ); return VLC_EGENERIC; } msg_Dbg( p_dec, "Changing fake-file to %s.", psz_file ); memset( &fmt_in, 0, sizeof(fmt_in) ); fmt_out = p_dec->fmt_out.video; p_handler = image_HandlerCreate( p_dec ); p_new_image = image_ReadUrl( p_handler, psz_file, &fmt_in, &fmt_out ); image_HandlerDelete( p_handler ); if( !p_new_image ) { msg_Err( p_dec, "error while reading image (%s)", psz_file ); vlc_mutex_unlock( &p_dec->p_sys->lock ); return VLC_EGENERIC; } p_dec->p_sys->p_image = p_new_image; picture_Release( p_image ); vlc_mutex_unlock( &p_dec->p_sys->lock ); } else if( !strcmp( psz_var, "fake-file-reload" ) ) { if( newval.i_int > 0) { p_dec->p_sys->b_reload = true; p_dec->p_sys->i_reload = (mtime_t)(newval.i_int * 1000000); p_dec->p_sys->i_next = (mtime_t)(p_dec->p_sys->i_reload + mdate()); } else { p_dec->p_sys->b_reload = false; } } return VLC_SUCCESS; }
ArtManager::ArtManager( intf_thread_t* pIntf ) : SkinObject( pIntf ) { // initialize handler m_pImageHandler = image_HandlerCreate( pIntf ); if( !m_pImageHandler ) msg_Err( getIntf(), "initialization of art manager failed" ); }
/***************************************************************************** * Create: initialize and set pf_video_filter() *****************************************************************************/ static int Create( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; filter_sys_t *p_sys; const vlc_chroma_description_t *p_chroma = vlc_fourcc_GetChromaDescription( p_filter->fmt_in.video.i_chroma ); if( p_chroma == NULL || p_chroma->plane_count == 0 ) return VLC_EGENERIC; config_ChainParse( p_filter, CFG_PREFIX, ppsz_vfilter_options, p_filter->p_cfg ); p_filter->p_sys = p_sys = calloc( 1, sizeof( filter_sys_t ) ); if( p_filter->p_sys == NULL ) return VLC_ENOMEM; p_sys->p_image = image_HandlerCreate( p_this ); if( !p_sys->p_image ) { msg_Err( p_this, "Couldn't get handle to image conversion routines." ); free( p_sys ); return VLC_EGENERIC; } p_sys->psz_format = var_CreateGetString( p_this, CFG_PREFIX "format" ); p_sys->i_format = image_Type2Fourcc( p_sys->psz_format ); if( !p_sys->i_format ) { msg_Err( p_filter, "Could not find FOURCC for image type '%s'", p_sys->psz_format ); image_HandlerDelete( p_sys->p_image ); free( p_sys->psz_format ); free( p_sys ); return VLC_EGENERIC; } p_sys->i_width = var_CreateGetInteger( p_this, CFG_PREFIX "width" ); p_sys->i_height = var_CreateGetInteger( p_this, CFG_PREFIX "height" ); p_sys->i_ratio = var_CreateGetInteger( p_this, CFG_PREFIX "ratio" ); if( p_sys->i_ratio <= 0) p_sys->i_ratio = 1; p_sys->b_replace = var_CreateGetBool( p_this, CFG_PREFIX "replace" ); p_sys->psz_prefix = var_CreateGetString( p_this, CFG_PREFIX "prefix" ); p_sys->psz_path = var_GetNonEmptyString( p_this, CFG_PREFIX "path" ); if( p_sys->psz_path == NULL ) p_sys->psz_path = config_GetUserDir( VLC_PICTURES_DIR ); p_filter->pf_video_filter = Filter; return VLC_SUCCESS; }
/* copied from video_filters/erase.c . Gruik ? */ static void LoadMask( filter_t *p_filter, const char *psz_filename ) { image_handler_t *p_image; video_format_t fmt_in, fmt_out; memset( &fmt_in, 0, sizeof( video_format_t ) ); memset( &fmt_out, 0, sizeof( video_format_t ) ); fmt_out.i_chroma = VLC_CODEC_YUVA; if( p_filter->p_sys->p_mask ) picture_Release( p_filter->p_sys->p_mask ); p_image = image_HandlerCreate( p_filter ); p_filter->p_sys->p_mask = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out ); image_HandlerDelete( p_image ); }
subpicture_t *subpicture_NewFromPicture( vlc_object_t *p_obj, picture_t *p_picture, vlc_fourcc_t i_chroma ) { /* */ video_format_t fmt_in = p_picture->format; /* */ video_format_t fmt_out; fmt_out = fmt_in; fmt_out.i_chroma = i_chroma; /* */ image_handler_t *p_image = image_HandlerCreate( p_obj ); if( !p_image ) return NULL; picture_t *p_pip = image_Convert( p_image, p_picture, &fmt_in, &fmt_out ); image_HandlerDelete( p_image ); if( !p_pip ) return NULL; subpicture_t *p_subpic = subpicture_New( NULL ); if( !p_subpic ) { picture_Release( p_pip ); return NULL; } p_subpic->i_original_picture_width = fmt_out.i_width; p_subpic->i_original_picture_height = fmt_out.i_height; fmt_out.i_sar_num = fmt_out.i_sar_den = 0; p_subpic->p_region = subpicture_region_New( &fmt_out ); if( p_subpic->p_region ) { picture_Release( p_subpic->p_region->p_picture ); p_subpic->p_region->p_picture = p_pip; } else { picture_Release( p_pip ); } return p_subpic; }
static int WidthCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(psz_var); sout_stream_t *p_stream = (sout_stream_t *)p_data; sout_stream_sys_t *p_sys = p_stream->p_sys; /* We create the handler before updating the value in p_sys * so we don't have to worry about locking */ if( !p_sys->p_image && newval.i_int ) p_sys->p_image = image_HandlerCreate( p_stream ); p_sys->i_width = newval.i_int; return VLC_SUCCESS; }
/* copied from video_filters/erase.c . Gruik ? */ static void LoadMask( filter_t *p_filter, const char *psz_filename ) { image_handler_t *p_image; video_format_t fmt_in, fmt_out; video_format_Init( &fmt_in, 0 ); video_format_Init( &fmt_out, VLC_CODEC_YUVA ); if( p_filter->p_sys->p_mask ) picture_Release( p_filter->p_sys->p_mask ); p_image = image_HandlerCreate( p_filter ); char *psz_url = vlc_path2uri( psz_filename, NULL ); p_filter->p_sys->p_mask = image_ReadUrl( p_image, psz_url, &fmt_in, &fmt_out ); free( psz_url ); video_format_Clean( &fmt_in ); video_format_Clean( &fmt_out ); image_HandlerDelete( p_image ); }
static block_t *Decode(demux_t *demux, video_format_t *fmt, vlc_fourcc_t chroma, block_t *data) { image_handler_t *handler = image_HandlerCreate(demux); if (!handler) { block_Release(data); return NULL; } video_format_t decoded; video_format_Init(&decoded, chroma); picture_t *image = image_Read(handler, data, fmt, &decoded); image_HandlerDelete(handler); if (!image) return NULL; video_format_Clean(fmt); *fmt = decoded; size_t size = 0; for (int i = 0; i < image->i_planes; i++) size += image->p[i].i_pitch * image->p[i].i_lines; data = block_Alloc(size); if (!data) { picture_Release(image); return NULL; } size_t offset = 0; for (int i = 0; i < image->i_planes; i++) { const plane_t *src = &image->p[i]; for (int y = 0; y < src->i_visible_lines; y++) { memcpy(&data->p_buffer[offset], &src->p_pixels[y * src->i_pitch], src->i_visible_pitch); offset += src->i_visible_pitch; } } picture_Release(image); return data; }
/**************************************************************************** * download and resize image located at psz_url ***************************************************************************/ static picture_t *LoadImage( filter_t *p_filter, const char *psz_url ) { filter_sys_t *p_sys = p_filter->p_sys; video_format_t fmt_in; video_format_t fmt_out; picture_t *p_orig; picture_t *p_pic = NULL; image_handler_t *p_handler = image_HandlerCreate( p_filter ); memset( &fmt_in, 0, sizeof(video_format_t) ); memset( &fmt_out, 0, sizeof(video_format_t) ); fmt_out.i_chroma = VLC_CODEC_YUVA; p_orig = image_ReadUrl( p_handler, psz_url, &fmt_in, &fmt_out ); if( !p_orig ) { msg_Warn( p_filter, "Unable to read image %s", psz_url ); } else if( p_sys->p_style->i_font_size > 0 ) { fmt_in.i_chroma = VLC_CODEC_YUVA; fmt_in.i_height = p_orig->p[Y_PLANE].i_visible_lines; fmt_in.i_width = p_orig->p[Y_PLANE].i_visible_pitch; fmt_out.i_width = p_orig->p[Y_PLANE].i_visible_pitch *p_sys->p_style->i_font_size/p_orig->p[Y_PLANE].i_visible_lines; fmt_out.i_height = p_sys->p_style->i_font_size; p_pic = image_Convert( p_handler, p_orig, &fmt_in, &fmt_out ); picture_Release( p_orig ); if( !p_pic ) { msg_Warn( p_filter, "Error while converting %s", psz_url ); } } else { p_pic = p_orig; } image_HandlerDelete( p_handler ); return p_pic; }
static int OpenCommon(vlc_object_t* p_this, bool b_packetizer) { decoder_t* p_dec = (decoder_t*)p_this; decoder_sys_t* p_sys; if (p_dec->fmt_in.i_codec != VLC_CODEC_OGGSPOTS) { return VLC_EGENERIC; } /* Allocate the memory needed to store the decoder's structure */ p_sys = malloc(sizeof(*p_sys)); if (p_sys == NULL) { return VLC_ENOMEM; } p_dec->p_sys = p_sys; p_sys->b_packetizer = b_packetizer; p_sys->b_has_headers = false; p_sys->i_pts = VLC_TICK_INVALID; /* Initialize image handler */ p_sys->p_image = image_HandlerCreate(p_dec); if (p_sys->p_image == NULL) { free(p_sys); return VLC_ENOMEM; } if( b_packetizer ) { p_dec->fmt_out.i_codec = VLC_CODEC_OGGSPOTS; p_dec->pf_packetize = Packetize; } else { p_dec->fmt_out.i_codec = VLC_CODEC_RGBA; p_dec->pf_decode = DecodeVideo; } p_dec->pf_flush = Flush; return VLC_SUCCESS; }
/***************************************************************************** * Create: allocates video thread ***************************************************************************** * This function allocates and initializes a vout method. *****************************************************************************/ static int Create( vlc_object_t *p_this ) { vout_thread_t *p_vout = ( vout_thread_t * )p_this; /* Allocate instance and initialize some members */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( ! p_vout->p_sys ) return VLC_ENOMEM; p_vout->p_sys->psz_prefix = var_CreateGetString( p_this, "image-out-prefix" ); p_vout->p_sys->psz_format = var_CreateGetString( p_this, "image-out-format" ); p_vout->p_sys->i_width = var_CreateGetInteger( p_this, "image-width" ); p_vout->p_sys->i_height = var_CreateGetInteger( p_this, "image-height" ); p_vout->p_sys->i_ratio = var_CreateGetInteger( p_this, "image-out-ratio" ); p_vout->p_sys->b_replace = var_CreateGetBool( p_this, "image-out-replace" ); p_vout->p_sys->i_current = 0; p_vout->p_sys->p_image = image_HandlerCreate( p_vout ); if( !p_vout->p_sys->p_image ) { msg_Err( p_this, "unable to create image handler") ; FREE( p_vout->p_sys->psz_prefix ); FREE( p_vout->p_sys ); return VLC_EGENERIC; } p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = NULL; p_vout->pf_render = Display; p_vout->pf_display = NULL; return VLC_SUCCESS; }
/** * It loads the logo image into memory. */ static picture_t *LoadImage( vlc_object_t *p_this, const char *psz_filename ) { if( !psz_filename ) return NULL; video_format_t fmt_in; video_format_Init( &fmt_in, 0 ); video_format_t fmt_out; video_format_Init( &fmt_out, VLC_CODEC_YUVA ); image_handler_t *p_image = image_HandlerCreate( p_this ); if( !p_image ) return NULL; char *psz_url = make_URI( psz_filename, NULL ); picture_t *p_pic = image_ReadUrl( p_image, psz_url, &fmt_in, &fmt_out ); free( psz_url ); image_HandlerDelete( p_image ); return p_pic; }
static int ParseImageAttachments( decoder_t *p_dec ) { decoder_sys_t *p_sys = p_dec->p_sys; input_attachment_t **pp_attachments; int i_attachments_cnt; int k = 0; if( VLC_SUCCESS != decoder_GetInputAttachments( p_dec, &pp_attachments, &i_attachments_cnt )) return VLC_EGENERIC; for( k = 0; k < i_attachments_cnt; k++ ) { input_attachment_t *p_attach = pp_attachments[k]; vlc_fourcc_t type = image_Mime2Fourcc( p_attach->psz_mime ); if( ( type != 0 ) && ( p_attach->i_data > 0 ) && ( p_attach->p_data != NULL ) ) { picture_t *p_pic = NULL; image_handler_t *p_image; p_image = image_HandlerCreate( p_dec ); if( p_image != NULL ) { block_t *p_block; p_block = block_Alloc( p_attach->i_data ); if( p_block != NULL ) { video_format_t fmt_in; video_format_t fmt_out; memcpy( p_block->p_buffer, p_attach->p_data, p_attach->i_data ); memset( &fmt_in, 0, sizeof( video_format_t)); memset( &fmt_out, 0, sizeof( video_format_t)); fmt_in.i_chroma = type; fmt_out.i_chroma = VLC_CODEC_YUVA; /* Find a suitable decoder module */ if( module_exists( "sdl_image" ) ) { /* ffmpeg thinks it can handle bmp properly but it can't (at least * not all of them), so use sdl_image if it is available */ var_Create( p_dec, "codec", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_SetString( p_dec, "codec", "sdl_image" ); } p_pic = image_Read( p_image, p_block, &fmt_in, &fmt_out ); var_Destroy( p_dec, "codec" ); } image_HandlerDelete( p_image ); } if( p_pic ) { image_attach_t *p_picture = malloc( sizeof(image_attach_t) ); if( p_picture ) { p_picture->psz_filename = strdup( p_attach->psz_name ); p_picture->p_pic = p_pic; TAB_APPEND( (image_attach_t **), p_sys->i_images, p_sys->pp_images, p_picture ); // sunqueen modify } } } vlc_input_attachment_Delete( pp_attachments[ k ] ); }
/***************************************************************************** * Render: displays previously rendered output ***************************************************************************** * This function send the currently rendered image to Distort image, waits * until it is displayed and switch the two rendering buffers, preparing next * frame. *****************************************************************************/ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) { picture_t *p_outpic; unsigned int w, h; int x,y; uint8_t u,v; picture_t *p_converted; video_format_t fmt_out; memset( &fmt_out, 0, sizeof(video_format_t) ); fmt_out.p_palette = NULL; if( !p_pic ) return NULL; p_outpic = filter_NewPicture( p_filter ); if( !p_outpic ) { picture_Release( p_pic ); return NULL; } if( !p_filter->p_sys->p_image ) p_filter->p_sys->p_image = image_HandlerCreate( p_filter ); /* chrominance */ u = p_filter->p_sys->u; v = p_filter->p_sys->v; for( y = 0; y<p_outpic->p[U_PLANE].i_lines; y++) { vlc_memset( p_outpic->p[U_PLANE].p_pixels+y*p_outpic->p[U_PLANE].i_pitch, u, p_outpic->p[U_PLANE].i_pitch ); vlc_memset( p_outpic->p[V_PLANE].p_pixels+y*p_outpic->p[V_PLANE].i_pitch, v, p_outpic->p[V_PLANE].i_pitch ); if( v == 0 && u != 0 ) u --; else if( u == 0xff ) v --; else if( v == 0xff ) u ++; else if( u == 0 ) v ++; } /* luminance */ vlc_memcpy( p_outpic->p[Y_PLANE].p_pixels, p_pic->p[Y_PLANE].p_pixels, p_outpic->p[Y_PLANE].i_lines * p_outpic->p[Y_PLANE].i_pitch ); /* image visualization */ fmt_out = p_filter->fmt_out.video; fmt_out.i_width = p_filter->fmt_out.video.i_width*p_filter->p_sys->scale/150; fmt_out.i_height = p_filter->fmt_out.video.i_height*p_filter->p_sys->scale/150; p_converted = image_Convert( p_filter->p_sys->p_image, p_pic, &(p_pic->format), &fmt_out ); if( p_converted ) { #define copyimage( plane, b ) \ for( y=0; y<p_converted->p[plane].i_visible_lines; y++) { \ for( x=0; x<p_converted->p[plane].i_visible_pitch; x++) { \ int nx, ny; \ if( p_filter->p_sys->yinc == 1 ) \ ny= y; \ else \ ny = p_converted->p[plane].i_visible_lines-y; \ if( p_filter->p_sys->xinc == 1 ) \ nx = x; \ else \ nx = p_converted->p[plane].i_visible_pitch-x; \ p_outpic->p[plane].p_pixels[(p_filter->p_sys->x*b+nx)+(ny+p_filter->p_sys->y*b)*p_outpic->p[plane].i_pitch ] = p_converted->p[plane].p_pixels[y*p_converted->p[plane].i_pitch+x]; \ } } copyimage( Y_PLANE, 2 ); copyimage( U_PLANE, 1 ); copyimage( V_PLANE, 1 ); #undef copyimage picture_Release( p_converted ); } else { msg_Err( p_filter, "Image scaling failed miserably." ); } p_filter->p_sys->x += p_filter->p_sys->xinc; p_filter->p_sys->y += p_filter->p_sys->yinc; p_filter->p_sys->scale += p_filter->p_sys->scaleinc; if( p_filter->p_sys->scale >= 50 ) p_filter->p_sys->scaleinc = -1; if( p_filter->p_sys->scale <= 1 ) p_filter->p_sys->scaleinc = 1; w = p_filter->fmt_out.video.i_width*p_filter->p_sys->scale/150; h = p_filter->fmt_out.video.i_height*p_filter->p_sys->scale/150; if( p_filter->p_sys->x*2 + w >= p_filter->fmt_out.video.i_width ) p_filter->p_sys->xinc = -1; if( p_filter->p_sys->x <= 0 ) p_filter->p_sys->xinc = 1; if( p_filter->p_sys->x*2 + w >= p_filter->fmt_out.video.i_width ) p_filter->p_sys->x = (p_filter->fmt_out.video.i_width-w)/2; if( p_filter->p_sys->y*2 + h >= p_filter->fmt_out.video.i_height ) p_filter->p_sys->y = (p_filter->fmt_out.video.i_height-h)/2; if( p_filter->p_sys->y*2 + h >= p_filter->fmt_out.video.i_height ) p_filter->p_sys->yinc = -1; if( p_filter->p_sys->y <= 0 ) p_filter->p_sys->yinc = 1; for( y = 0; y< 16; y++ ) { if( p_filter->p_sys->v == 0 && p_filter->p_sys->u != 0 ) p_filter->p_sys->u -= 1; else if( p_filter->p_sys->u == 0xff ) p_filter->p_sys->v -= 1; else if( p_filter->p_sys->v == 0xff ) p_filter->p_sys->u += 1; else if( p_filter->p_sys->u == 0 ) p_filter->p_sys->v += 1; } return CopyInfoAndRelease( p_outpic, p_pic ); }
/***************************************************************************** * 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; }
/***************************************************************************** * CreateFiler: allocate mosaic video filter *****************************************************************************/ static int CreateFilter( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; filter_sys_t *p_sys; libvlc_t *p_libvlc = p_filter->p_libvlc; char *psz_order; int i_index; vlc_value_t val; /* The mosaic thread is more important than the decoder threads */ vlc_thread_set_priority( p_this, VLC_THREAD_PRIORITY_OUTPUT ); /* Allocate structure */ p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); if( p_sys == NULL ) { msg_Err( p_filter, "out of memory" ); return VLC_ENOMEM; } p_filter->pf_sub_filter = Filter; p_sys->p_pic = NULL; vlc_mutex_init( p_filter, &p_sys->lock ); vlc_mutex_lock( &p_sys->lock ); var_Get( p_libvlc, "mosaic-lock", &val ); p_sys->p_lock = val.p_address; #define GET_VAR( name, min, max ) \ p_sys->i_##name = __MIN( max, __MAX( min, \ var_CreateGetInteger( p_filter, "mosaic-" #name ) ) ); \ var_Destroy( p_filter, "mosaic-" #name ); \ var_Create( p_libvlc, "mosaic-" #name, VLC_VAR_INTEGER ); \ var_SetInteger( p_libvlc, "mosaic-" #name, p_sys->i_##name ); \ var_AddCallback( p_libvlc, "mosaic-" #name, MosaicCallback, p_sys ); GET_VAR( width, 0, INT_MAX ); GET_VAR( height, 0, INT_MAX ); GET_VAR( xoffset, 0, INT_MAX ); GET_VAR( yoffset, 0, INT_MAX ); p_sys->i_align = __MIN( 10, __MAX( 0, var_CreateGetInteger( p_filter, "mosaic-align" ) ) ); if( p_sys->i_align == 3 || p_sys->i_align == 7 ) p_sys->i_align = 5; var_Destroy( p_filter, "mosaic-align" ); var_Create( p_libvlc, "mosaic-align", VLC_VAR_INTEGER ); var_SetInteger( p_libvlc, "mosaic-align", p_sys->i_align ); var_AddCallback( p_libvlc, "mosaic-align", MosaicCallback, p_sys ); GET_VAR( borderw, 0, INT_MAX ); GET_VAR( borderh, 0, INT_MAX ); GET_VAR( rows, 1, INT_MAX ); GET_VAR( cols, 1, INT_MAX ); GET_VAR( alpha, 0, 255 ); GET_VAR( position, 0, 1 ); GET_VAR( delay, 100, INT_MAX ); p_sys->i_delay *= 1000; p_sys->b_ar = var_CreateGetBool( p_filter, "mosaic-keep-aspect-ratio" ); var_Destroy( p_filter, "mosaic-keep-aspect-ratio" ); var_Create( p_libvlc, "mosaic-keep-aspect-ratio", VLC_VAR_INTEGER ); var_SetBool( p_libvlc, "mosaic-keep-aspect-ratio", p_sys->b_ar ); var_AddCallback( p_libvlc, "mosaic-keep-aspect-ratio", MosaicCallback, p_sys ); p_sys->b_keep = var_CreateGetBool( p_filter, "mosaic-keep-picture" ); if ( !p_sys->b_keep ) { p_sys->p_image = image_HandlerCreate( p_filter ); } p_sys->i_order_length = 0; p_sys->ppsz_order = NULL; psz_order = var_CreateGetString( p_filter, "mosaic-order" ); if( psz_order[0] != 0 ) { char *psz_end = NULL; i_index = 0; do { psz_end = strchr( psz_order, ',' ); i_index++; p_sys->ppsz_order = realloc( p_sys->ppsz_order, i_index * sizeof(char *) ); p_sys->ppsz_order[i_index - 1] = strndup( psz_order, psz_end - psz_order ); psz_order = psz_end+1; } while( NULL != psz_end ); p_sys->i_order_length = i_index; } /* Bluescreen specific stuff */ GET_VAR( bsu, 0x00, 0xff ); GET_VAR( bsv, 0x00, 0xff ); GET_VAR( bsut, 0x00, 0xff ); GET_VAR( bsvt, 0x00, 0xff ); p_sys->b_bs = var_CreateGetBool( p_filter, "mosaic-bs" ); var_Destroy( p_filter, "mosaic-bs" ); var_Create( p_libvlc, "mosaic-bs", VLC_VAR_INTEGER ); var_SetBool( p_libvlc, "mosaic-bs", p_sys->b_bs ); var_AddCallback( p_libvlc, "mosaic-bs", MosaicCallback, p_sys ); if( p_sys->b_bs && p_sys->b_keep ) { msg_Warn( p_filter, "mosaic-keep-picture needs to be disabled for" " bluescreen to work" ); } vlc_mutex_unlock( &p_sys->lock ); return VLC_SUCCESS; }
static sout_stream_id_sys_t * Add( sout_stream_t *p_stream, const es_format_t *p_fmt ) { sout_stream_sys_t *p_sys = p_stream->p_sys; bridge_t *p_bridge; bridged_es_t *p_es; char *psz_chain; int i; if( p_sys->b_inited || p_fmt->i_cat != VIDEO_ES ) return NULL; /* Create decoder object */ p_sys->p_decoder = vlc_object_create( p_stream, sizeof( decoder_t ) ); if( !p_sys->p_decoder ) return NULL; p_sys->p_decoder->p_module = NULL; p_sys->p_decoder->fmt_in = *p_fmt; p_sys->p_decoder->b_frame_drop_allowed = true; p_sys->p_decoder->fmt_out = p_sys->p_decoder->fmt_in; p_sys->p_decoder->fmt_out.i_extra = 0; p_sys->p_decoder->fmt_out.p_extra = 0; p_sys->p_decoder->pf_decode_video = 0; p_sys->p_decoder->pf_vout_format_update = video_update_format_decoder; p_sys->p_decoder->pf_vout_buffer_new = video_new_buffer_decoder; p_sys->p_decoder->p_owner = malloc( sizeof(decoder_owner_sys_t) ); if( !p_sys->p_decoder->p_owner ) { vlc_object_release( p_sys->p_decoder ); return NULL; } p_sys->p_decoder->p_owner->video = p_fmt->video; //p_sys->p_decoder->p_cfg = p_sys->p_video_cfg; p_sys->p_decoder->p_module = module_need( p_sys->p_decoder, "decoder", "$codec", false ); if( !p_sys->p_decoder->p_module || !p_sys->p_decoder->pf_decode_video ) { if( p_sys->p_decoder->p_module ) { msg_Err( p_stream, "instanciated a non video decoder" ); module_unneed( p_sys->p_decoder, p_sys->p_decoder->p_module ); } else { msg_Err( p_stream, "cannot find decoder" ); } free( p_sys->p_decoder->p_owner ); vlc_object_release( p_sys->p_decoder ); return NULL; } p_sys->b_inited = true; vlc_global_lock( VLC_MOSAIC_MUTEX ); p_bridge = GetBridge( p_stream ); if ( p_bridge == NULL ) { vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->obj.libvlc ); vlc_value_t val; p_bridge = xmalloc( sizeof( bridge_t ) ); var_Create( p_libvlc, "mosaic-struct", VLC_VAR_ADDRESS ); val.p_address = p_bridge; var_Set( p_libvlc, "mosaic-struct", val ); p_bridge->i_es_num = 0; p_bridge->pp_es = NULL; } for ( i = 0; i < p_bridge->i_es_num; i++ ) { if ( p_bridge->pp_es[i]->b_empty ) break; } if ( i == p_bridge->i_es_num ) { p_bridge->pp_es = xrealloc( p_bridge->pp_es, (p_bridge->i_es_num + 1) * sizeof(bridged_es_t *) ); p_bridge->i_es_num++; p_bridge->pp_es[i] = xmalloc( sizeof(bridged_es_t) ); } p_sys->p_es = p_es = p_bridge->pp_es[i]; p_es->i_alpha = var_GetInteger( p_stream, CFG_PREFIX "alpha" ); p_es->i_x = var_GetInteger( p_stream, CFG_PREFIX "x" ); p_es->i_y = var_GetInteger( p_stream, CFG_PREFIX "y" ); //p_es->fmt = *p_fmt; p_es->psz_id = p_sys->psz_id; p_es->p_picture = NULL; p_es->pp_last = &p_es->p_picture; p_es->b_empty = false; vlc_global_unlock( VLC_MOSAIC_MUTEX ); if ( p_sys->i_height || p_sys->i_width ) { p_sys->p_image = image_HandlerCreate( p_stream ); } else { p_sys->p_image = NULL; } msg_Dbg( p_stream, "mosaic bridge id=%s pos=%d", p_es->psz_id, i ); /* Create user specified video filters */ psz_chain = var_GetNonEmptyString( p_stream, CFG_PREFIX "vfilter" ); msg_Dbg( p_stream, "psz_chain: %s", psz_chain ); if( psz_chain ) { filter_owner_t owner = { .sys = p_sys->p_decoder->p_owner, .video = { .buffer_new = video_new_buffer_filter, }, }; p_sys->p_vf2 = filter_chain_NewVideo( p_stream, false, &owner ); es_format_t fmt; es_format_Copy( &fmt, &p_sys->p_decoder->fmt_out ); if( p_sys->i_chroma ) fmt.video.i_chroma = p_sys->i_chroma; filter_chain_Reset( p_sys->p_vf2, &fmt, &fmt ); filter_chain_AppendFromString( p_sys->p_vf2, psz_chain ); free( psz_chain ); } else {
static int OpenVideo(vlc_object_t *p_this) { vout_display_t *vd = (vout_display_t *)p_this; vout_display_sys_t *sys; struct decklink_sys_t *decklink_sys; vd->sys = sys = (vout_display_sys_t*)malloc(sizeof(*sys)); if (!sys) return VLC_ENOMEM; sys->tenbits = var_InheritBool(p_this, VIDEO_CFG_PREFIX "tenbits"); sys->nosignal_delay = var_InheritInteger(p_this, VIDEO_CFG_PREFIX "nosignal-delay"); sys->pic_nosignal = NULL; decklink_sys = OpenDecklink(vd); if (!decklink_sys) { if (sys->pic_nosignal) picture_Release(sys->pic_nosignal); free(sys); return VLC_EGENERIC; } sys->pool = NULL; vd->fmt.i_chroma = sys->tenbits ? VLC_CODEC_I422_10L /* we will convert to v210 */ : VLC_CODEC_UYVY; //video_format_FixRgb(&(vd->fmt)); vd->fmt.i_width = decklink_sys->i_width; vd->fmt.i_height = decklink_sys->i_height; char *pic_file = var_InheritString(p_this, VIDEO_CFG_PREFIX "nosignal-image"); if (pic_file) { image_handler_t *img = image_HandlerCreate(p_this); if (!img) { msg_Err(p_this, "Could not create image converter"); } else { video_format_t in, dummy; video_format_Init(&in, 0); video_format_Setup(&in, 0, vd->fmt.i_width, vd->fmt.i_height, vd->fmt.i_width, vd->fmt.i_height, 1, 1); video_format_Init(&dummy, 0); picture_t *png = image_ReadUrl(img, pic_file, &dummy, &in); if (png) { msg_Err(p_this, "Converting"); sys->pic_nosignal = image_Convert(img, png, &in, &vd->fmt); picture_Release(png); } image_HandlerDelete(img); } free(pic_file); if (!sys->pic_nosignal) { CloseVideo(p_this); msg_Err(p_this, "Could not create no signal picture"); return VLC_EGENERIC; } } vd->info.has_hide_mouse = true; vd->pool = PoolVideo; vd->prepare = NULL; vd->display = DisplayVideo; vd->control = ControlVideo; vd->manage = NULL; vout_display_SendEventFullscreen(vd, false); return VLC_SUCCESS; }
/***************************************************************************** * Create: allocates opencv_wrapper video thread output method ***************************************************************************** * This function allocates and initializes a opencv_wrapper vout method. *****************************************************************************/ static int Create( vlc_object_t *p_this ) { filter_t* p_filter = (filter_t*)p_this; char *psz_chroma, *psz_output; /* Allocate structure */ p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); if( p_filter->p_sys == NULL ) return VLC_ENOMEM; /* Load the internal OpenCV filter. * * This filter object is needed to call the internal OpenCV filter * for processing, the wrapper just converts into an IplImage* for * the other filter. * * We don't need to set up video formats for this filter as it not * actually using a picture_t. */ p_filter->p_sys->p_opencv = vlc_object_create( p_filter, sizeof(filter_t) ); if( !p_filter->p_sys->p_opencv ) { free( p_filter->p_sys ); return VLC_ENOMEM; } p_filter->p_sys->psz_inner_name = var_InheritString( p_filter, "opencv-filter-name" ); if( p_filter->p_sys->psz_inner_name ) p_filter->p_sys->p_opencv->p_module = module_need( p_filter->p_sys->p_opencv, "opencv internal filter", p_filter->p_sys->psz_inner_name, true ); if( !p_filter->p_sys->p_opencv->p_module ) { msg_Err( p_filter, "can't open internal opencv filter: %s", p_filter->p_sys->psz_inner_name ); free( p_filter->p_sys->psz_inner_name ); p_filter->p_sys->psz_inner_name = NULL; vlc_object_release( p_filter->p_sys->p_opencv ); free( p_filter->p_sys ); return VLC_ENOMOD; } /* Init structure */ p_filter->p_sys->p_image = image_HandlerCreate( p_filter ); for( int i = 0; i < VOUT_MAX_PLANES; i++ ) p_filter->p_sys->p_cv_image[i] = NULL; p_filter->p_sys->p_proc_image = NULL; p_filter->p_sys->p_to_be_freed = NULL; p_filter->p_sys->i_cv_image_size = 0; /* Retrieve and apply config */ psz_chroma = var_InheritString( p_filter, "opencv-chroma" ); if( psz_chroma == NULL ) { msg_Err( p_filter, "configuration variable %s empty, using 'grey'", "opencv-chroma" ); p_filter->p_sys->i_internal_chroma = GREY; } else if( !strcmp( psz_chroma, "input" ) ) p_filter->p_sys->i_internal_chroma = CINPUT; else if( !strcmp( psz_chroma, "I420" ) ) p_filter->p_sys->i_internal_chroma = GREY; else if( !strcmp( psz_chroma, "RGB32" ) ) p_filter->p_sys->i_internal_chroma = RGB; else { msg_Err( p_filter, "no valid opencv-chroma provided, using 'grey'" ); p_filter->p_sys->i_internal_chroma = GREY; } free( psz_chroma ); psz_output = var_InheritString( p_filter, "opencv-output" ); if( psz_output == NULL ) { msg_Err( p_filter, "configuration variable %s empty, using 'input'", "opencv-output" ); p_filter->p_sys->i_wrapper_output = VINPUT; } else if( !strcmp( psz_output, "none" ) ) p_filter->p_sys->i_wrapper_output = NONE; else if( !strcmp( psz_output, "input" ) ) p_filter->p_sys->i_wrapper_output = VINPUT; else if( !strcmp( psz_output, "processed" ) ) p_filter->p_sys->i_wrapper_output = PROCESSED; else { msg_Err( p_filter, "no valid opencv-output provided, using 'input'" ); p_filter->p_sys->i_wrapper_output = VINPUT; } free( psz_output ); p_filter->p_sys->f_scale = var_InheritFloat( p_filter, "opencv-scale" ); msg_Info(p_filter, "Configuration: opencv-scale: %f, opencv-chroma: %d, " "opencv-output: %d, opencv-filter %s", p_filter->p_sys->f_scale, p_filter->p_sys->i_internal_chroma, p_filter->p_sys->i_wrapper_output, p_filter->p_sys->psz_inner_name); #ifndef NDEBUG msg_Dbg( p_filter, "opencv_wrapper successfully started" ); #endif p_filter->pf_video_filter = Filter; return VLC_SUCCESS; }
int vout_Snapshot( vout_thread_t *p_vout, picture_t *p_pic ) { image_handler_t *p_image = image_HandlerCreate( p_vout ); video_format_t fmt_in, fmt_out; char *psz_filename = NULL; vlc_value_t val, format; DIR *path; int i_ret; bool b_embedded_snapshot; int i_id = 0; /* */ val.psz_string = var_GetNonEmptyString( p_vout, "snapshot-path" ); /* Embedded snapshot : if snapshot-path == object:id */ if( val.psz_string && sscanf( val.psz_string, "object:%d", &i_id ) > 0 ) b_embedded_snapshot = true; else b_embedded_snapshot = false; /* */ memset( &fmt_in, 0, sizeof(video_format_t) ); fmt_in = p_vout->fmt_in; if( fmt_in.i_sar_num <= 0 || fmt_in.i_sar_den <= 0 ) { fmt_in.i_sar_num = fmt_in.i_sar_den = 1; } /* */ memset( &fmt_out, 0, sizeof(video_format_t) ); fmt_out.i_sar_num = fmt_out.i_sar_den = 1; fmt_out.i_chroma = b_embedded_snapshot ? VLC_FOURCC('p','n','g',' ') : 0; fmt_out.i_width = var_GetInteger( p_vout, "snapshot-width" ); fmt_out.i_height = var_GetInteger( p_vout, "snapshot-height" ); if( b_embedded_snapshot && fmt_out.i_width == 0 && fmt_out.i_height == 0 ) { /* If snapshot-width and/or snapshot height were not specified, use a default snapshot width of 320 */ fmt_out.i_width = 320; } if( fmt_out.i_height == 0 && fmt_out.i_width > 0 ) { fmt_out.i_height = fmt_in.i_height * fmt_out.i_width / fmt_in.i_width; const int i_height = fmt_out.i_height * fmt_in.i_sar_den / fmt_in.i_sar_num; if( i_height > 0 ) fmt_out.i_height = i_height; } else { if( fmt_out.i_width == 0 && fmt_out.i_height > 0 ) { fmt_out.i_width = fmt_in.i_width * fmt_out.i_height / fmt_in.i_height; } else { fmt_out.i_width = fmt_in.i_width; fmt_out.i_height = fmt_in.i_height; } const int i_width = fmt_out.i_width * fmt_in.i_sar_num / fmt_in.i_sar_den; if( i_width > 0 ) fmt_out.i_width = i_width; } /* Embedded snapshot create a snapshot_t* and store it in object(object-id)->p_private, then unlock and signal the waiting object. */ if( b_embedded_snapshot ) { vlc_object_t* p_dest; block_t *p_block; snapshot_t *p_snapshot; size_t i_size; /* Destination object-id is following object: */ p_dest = ( vlc_object_t* )vlc_object_get( i_id ); if( !p_dest ) { msg_Err( p_vout, "Cannot find calling object" ); image_HandlerDelete( p_image ); return VLC_EGENERIC; } /* Object must be locked. We will unlock it once we get the snapshot and written it to p_private */ p_dest->p_private = NULL; /* Save the snapshot to a memory zone */ p_block = image_Write( p_image, p_pic, &fmt_in, &fmt_out ); if( !p_block ) { msg_Err( p_vout, "Could not get snapshot" ); image_HandlerDelete( p_image ); vlc_object_signal( p_dest ); vlc_object_release( p_dest ); return VLC_EGENERIC; } /* Copy the p_block data to a snapshot structure */ /* FIXME: get the timestamp */ p_snapshot = malloc( sizeof( snapshot_t ) ); if( !p_snapshot ) { block_Release( p_block ); image_HandlerDelete( p_image ); vlc_object_signal( p_dest ); vlc_object_release( p_dest ); return VLC_ENOMEM; } i_size = p_block->i_buffer; p_snapshot->i_width = fmt_out.i_width; p_snapshot->i_height = fmt_out.i_height; p_snapshot->i_datasize = i_size; p_snapshot->date = p_block->i_pts; /* FIXME ?? */ p_snapshot->p_data = malloc( i_size ); if( !p_snapshot->p_data ) { block_Release( p_block ); free( p_snapshot ); image_HandlerDelete( p_image ); vlc_object_signal( p_dest ); vlc_object_release( p_dest ); return VLC_ENOMEM; } memcpy( p_snapshot->p_data, p_block->p_buffer, p_block->i_buffer ); p_dest->p_private = p_snapshot; block_Release( p_block ); /* Unlock the object */ vlc_object_signal( p_dest ); vlc_object_release( p_dest ); image_HandlerDelete( p_image ); return VLC_SUCCESS; } /* Get default directory if none provided */ if( !val.psz_string ) val.psz_string = VoutSnapshotGetDefaultDirectory( p_vout ); if( !val.psz_string ) { msg_Err( p_vout, "no path specified for snapshots" ); image_HandlerDelete( p_image ); return VLC_EGENERIC; } /* Get snapshot format, default being "png" */ format.psz_string = var_GetNonEmptyString( p_vout, "snapshot-format" ); if( !format.psz_string ) format.psz_string = strdup( "png" ); if( !format.psz_string ) { free( val.psz_string ); image_HandlerDelete( p_image ); return VLC_ENOMEM; } /* * Did the user specify a directory? If not, path = NULL. */ path = utf8_opendir ( (const char *)val.psz_string ); if( path != NULL ) { char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" ); if( psz_prefix == NULL ) psz_prefix = strdup( "vlcsnap-" ); else { char *psz_tmp = str_format( p_vout, psz_prefix ); filename_sanitize( psz_tmp ); free( psz_prefix ); psz_prefix = psz_tmp; } closedir( path ); if( var_GetBool( p_vout, "snapshot-sequential" ) == true ) { int i_num = var_GetInteger( p_vout, "snapshot-num" ); struct stat st; do { free( psz_filename ); if( asprintf( &psz_filename, "%s" DIR_SEP "%s%05d.%s", val.psz_string, psz_prefix, i_num++, format.psz_string ) == -1 ) { msg_Err( p_vout, "could not create snapshot" ); image_HandlerDelete( p_image ); return VLC_EGENERIC; } } while( utf8_stat( psz_filename, &st ) == 0 ); var_SetInteger( p_vout, "snapshot-num", i_num ); } else { if( asprintf( &psz_filename, "%s" DIR_SEP "%s%u.%s", val.psz_string, psz_prefix, (unsigned int)(p_pic->date / 100000) & 0xFFFFFF, format.psz_string ) == -1 ) { msg_Err( p_vout, "could not create snapshot" ); image_HandlerDelete( p_image ); return VLC_EGENERIC; } } free( psz_prefix ); } else // The user specified a full path name (including file name) { psz_filename = str_format( p_vout, val.psz_string ); path_sanitize( psz_filename ); } free( val.psz_string ); free( format.psz_string ); /* Save the snapshot */ i_ret = image_WriteUrl( p_image, p_pic, &fmt_in, &fmt_out, psz_filename ); if( i_ret != VLC_SUCCESS ) { msg_Err( p_vout, "could not create snapshot %s", psz_filename ); free( psz_filename ); image_HandlerDelete( p_image ); return VLC_EGENERIC; } /* */ msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename ); vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN, "%s", psz_filename ); free( psz_filename ); /* */ if( var_GetBool( p_vout, "snapshot-preview" ) ) { if( VoutSnapshotPip( p_vout, p_image, p_pic, &fmt_in ) ) msg_Warn( p_vout, "Failed to display snapshot" ); } image_HandlerDelete( p_image ); return VLC_SUCCESS; }
/***************************************************************************** * Callback to update params on the fly *****************************************************************************/ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { VLC_UNUSED(oldval); filter_sys_t *p_sys = (filter_sys_t *) p_data; #define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a ) if( VAR_IS( "alpha" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing alpha from %d/255 to %d/255", p_sys->i_alpha, (int)newval.i_int); p_sys->i_alpha = __MIN( __MAX( newval.i_int, 0 ), 255 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "height" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing height from %dpx to %dpx", p_sys->i_height, (int)newval.i_int ); p_sys->i_height = __MAX( newval.i_int, 0 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "width" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing width from %dpx to %dpx", p_sys->i_width, (int)newval.i_int ); p_sys->i_width = __MAX( newval.i_int, 0 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "xoffset" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing x offset from %dpx to %dpx", p_sys->i_xoffset, (int)newval.i_int ); p_sys->i_xoffset = __MAX( newval.i_int, 0 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "yoffset" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing y offset from %dpx to %dpx", p_sys->i_yoffset, (int)newval.i_int ); p_sys->i_yoffset = __MAX( newval.i_int, 0 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "align" ) ) { int i_old = 0, i_new = 0; vlc_mutex_lock( &p_sys->lock ); newval.i_int = __MIN( __MAX( newval.i_int, 0 ), 10 ); if( newval.i_int == 3 || newval.i_int == 7 ) newval.i_int = 5; while( pi_align_values[i_old] != p_sys->i_align ) i_old++; while( pi_align_values[i_new] != newval.i_int ) i_new++; msg_Dbg( p_this, "changing alignment from %d (%s) to %d (%s)", p_sys->i_align, ppsz_align_descriptions[i_old], (int)newval.i_int, ppsz_align_descriptions[i_new] ); p_sys->i_align = newval.i_int; vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "borderw" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing border width from %dpx to %dpx", p_sys->i_borderw, (int)newval.i_int ); p_sys->i_borderw = __MAX( newval.i_int, 0 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "borderh" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing border height from %dpx to %dpx", p_sys->i_borderh, (int)newval.i_int ); p_sys->i_borderh = __MAX( newval.i_int, 0 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "position" ) ) { if( newval.i_int > 2 || newval.i_int < 0 ) { msg_Err( p_this, "Position is either 0 (%s), 1 (%s) or 2 (%s)", ppsz_pos_descriptions[0], ppsz_pos_descriptions[1], ppsz_pos_descriptions[2] ); } else { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing position method from %d (%s) to %d (%s)", p_sys->i_position, ppsz_pos_descriptions[p_sys->i_position], (int)newval.i_int, ppsz_pos_descriptions[newval.i_int]); p_sys->i_position = newval.i_int; vlc_mutex_unlock( &p_sys->lock ); } } else if( VAR_IS( "rows" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing number of rows from %d to %d", p_sys->i_rows, (int)newval.i_int ); p_sys->i_rows = __MAX( newval.i_int, 1 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "cols" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "changing number of columns from %d to %d", p_sys->i_cols, (int)newval.i_int ); p_sys->i_cols = __MAX( newval.i_int, 1 ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "order" ) ) { char *psz_order; int i_index; vlc_mutex_lock( &p_sys->lock ); msg_Dbg( p_this, "Changing mosaic order to %s", newval.psz_string ); psz_order = newval.psz_string; while( p_sys->i_order_length-- ) { free( p_sys->ppsz_order[p_sys->i_order_length] ); } free( p_sys->ppsz_order ); p_sys->ppsz_order = NULL; if( *psz_order ) { char *psz_end = NULL; i_index = 0; do { psz_end = strchr( psz_order, ',' ); i_index++; p_sys->ppsz_order = xrealloc( p_sys->ppsz_order, i_index * sizeof(char *) ); p_sys->ppsz_order[i_index - 1] = strndup( psz_order, psz_end - psz_order ); psz_order = psz_end+1; } while( psz_end ); p_sys->i_order_length = i_index; } vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "offsets" ) ) { vlc_mutex_lock( &p_sys->lock ); msg_Info( p_this, "Changing mosaic-offsets to %s", newval.psz_string ); if( p_sys->i_offsets_length != 0 ) { p_sys->i_offsets_length = 0; free( p_sys->pi_x_offsets ); free( p_sys->pi_y_offsets ); p_sys->pi_x_offsets = NULL; p_sys->pi_y_offsets = NULL; } mosaic_ParseSetOffsets( p_this, p_sys, newval.psz_string ); vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "keep-aspect-ratio" ) ) { vlc_mutex_lock( &p_sys->lock ); if( newval.i_int ) { msg_Dbg( p_this, "keeping aspect ratio" ); p_sys->b_ar = 1; } else { msg_Dbg( p_this, "won't keep aspect ratio" ); p_sys->b_ar = 0; } vlc_mutex_unlock( &p_sys->lock ); } else if( VAR_IS( "keep-picture" ) ) { vlc_mutex_lock( &p_sys->lock ); p_sys->b_keep = newval.b_bool; if ( !p_sys->b_keep && !p_sys->p_image ) { p_sys->p_image = image_HandlerCreate( p_this ); } vlc_mutex_unlock( &p_sys->lock ); } return VLC_SUCCESS; }
/***************************************************************************** * CreateFiler: allocate mosaic video filter *****************************************************************************/ static int CreateFilter( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; filter_sys_t *p_sys; vlc_object_t *p_libvlc = VLC_OBJECT( p_filter->p_libvlc ); char *psz_order, *_psz_order; char *psz_offsets; int i_index; vlc_value_t val; int i_command; /* Allocate structure */ p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); if( p_sys == NULL ) return VLC_ENOMEM; p_filter->pf_sub_source = Filter; vlc_mutex_init( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock ); config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options, p_filter->p_cfg ); #define GET_VAR( name, min, max ) \ i_command = var_CreateGetIntegerCommand( p_filter, CFG_PREFIX #name ); \ p_sys->i_##name = __MIN( max, __MAX( min, i_command ) ); \ var_AddCallback( p_filter, CFG_PREFIX #name, MosaicCallback, p_sys ); GET_VAR( width, 0, INT_MAX ); GET_VAR( height, 0, INT_MAX ); GET_VAR( xoffset, 0, INT_MAX ); GET_VAR( yoffset, 0, INT_MAX ); GET_VAR( align, 0, 10 ); if( p_sys->i_align == 3 || p_sys->i_align == 7 ) p_sys->i_align = 5; GET_VAR( borderw, 0, INT_MAX ); GET_VAR( borderh, 0, INT_MAX ); GET_VAR( rows, 1, INT_MAX ); GET_VAR( cols, 1, INT_MAX ); GET_VAR( alpha, 0, 255 ); GET_VAR( position, 0, 2 ); GET_VAR( delay, 100, INT_MAX ); #undef GET_VAR p_sys->i_delay *= 1000; p_sys->b_ar = var_CreateGetBoolCommand( p_filter, CFG_PREFIX "keep-aspect-ratio" ); var_AddCallback( p_filter, CFG_PREFIX "keep-aspect-ratio", MosaicCallback, p_sys ); p_sys->b_keep = var_CreateGetBoolCommand( p_filter, CFG_PREFIX "keep-picture" ); if ( !p_sys->b_keep ) { p_sys->p_image = image_HandlerCreate( p_filter ); } p_sys->i_order_length = 0; p_sys->ppsz_order = NULL; psz_order = var_CreateGetStringCommand( p_filter, CFG_PREFIX "order" ); _psz_order = psz_order; var_AddCallback( p_filter, CFG_PREFIX "order", MosaicCallback, p_sys ); if( *psz_order ) { char *psz_end = NULL; i_index = 0; do { psz_end = strchr( psz_order, ',' ); i_index++; p_sys->ppsz_order = xrealloc( p_sys->ppsz_order, i_index * sizeof(char *) ); p_sys->ppsz_order[i_index - 1] = strndup( psz_order, psz_end - psz_order ); psz_order = psz_end+1; } while( psz_end ); p_sys->i_order_length = i_index; } free( _psz_order ); /* Manage specific offsets for substreams */ psz_offsets = var_CreateGetStringCommand( p_filter, CFG_PREFIX "offsets" ); p_sys->i_offsets_length = 0; p_sys->pi_x_offsets = NULL; p_sys->pi_y_offsets = NULL; mosaic_ParseSetOffsets( p_filter, p_sys, psz_offsets ); free( psz_offsets ); var_AddCallback( p_filter, CFG_PREFIX "offsets", MosaicCallback, p_sys ); vlc_mutex_unlock( &p_sys->lock ); return VLC_SUCCESS; }
int picture_Export( vlc_object_t *p_obj, block_t **pp_image, video_format_t *p_fmt, picture_t *p_picture, vlc_fourcc_t i_format, int i_override_width, int i_override_height ) { /* */ video_format_t fmt_in = p_picture->format; if( fmt_in.i_sar_num <= 0 || fmt_in.i_sar_den <= 0 ) { fmt_in.i_sar_num = fmt_in.i_sar_den = 1; } /* */ video_format_t fmt_out; memset( &fmt_out, 0, sizeof(fmt_out) ); fmt_out.i_sar_num = fmt_out.i_sar_den = 1; fmt_out.i_chroma = i_format; /* compute original width/height */ unsigned int i_original_width; unsigned int i_original_height; if( fmt_in.i_sar_num >= fmt_in.i_sar_den ) { i_original_width = (int64_t)fmt_in.i_width * fmt_in.i_sar_num / fmt_in.i_sar_den; i_original_height = fmt_in.i_height; } else { i_original_width = fmt_in.i_width; i_original_height = (int64_t)fmt_in.i_height * fmt_in.i_sar_den / fmt_in.i_sar_num; } /* */ fmt_out.i_width = ( i_override_width < 0 ) ? i_original_width : (unsigned)i_override_width; fmt_out.i_height = ( i_override_height < 0 ) ? i_original_height : (unsigned)i_override_height; /* scale if only one direction is provided */ if( fmt_out.i_height == 0 && fmt_out.i_width > 0 ) { fmt_out.i_height = fmt_in.i_height * fmt_out.i_width * fmt_in.i_sar_den / fmt_in.i_width / fmt_in.i_sar_num; } else if( fmt_out.i_width == 0 && fmt_out.i_height > 0 ) { fmt_out.i_width = fmt_in.i_width * fmt_out.i_height * fmt_in.i_sar_num / fmt_in.i_height / fmt_in.i_sar_den; } image_handler_t *p_image = image_HandlerCreate( p_obj ); block_t *p_block = image_Write( p_image, p_picture, &fmt_in, &fmt_out ); image_HandlerDelete( p_image ); if( !p_block ) return VLC_EGENERIC; p_block->i_pts = p_block->i_dts = p_picture->date; if( p_fmt ) *p_fmt = fmt_out; *pp_image = p_block; return VLC_SUCCESS; }
/***************************************************************************** * Create: allocates opencv_wrapper video thread output method ***************************************************************************** * This function allocates and initializes a opencv_wrapper vout method. *****************************************************************************/ static int Create( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; char *psz_chroma, *psz_output, *psz_verbosity; int i = 0; /* Allocate structure */ p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_vout->p_sys == NULL ) return VLC_ENOMEM; /* Init structure */ p_vout->p_sys->p_image = image_HandlerCreate( p_vout ); for (i = 0; i < VOUT_MAX_PLANES; i++) p_vout->p_sys->p_cv_image[i] = NULL; p_vout->p_sys->p_proc_image = NULL; p_vout->p_sys->p_to_be_freed = NULL; p_vout->p_sys->i_cv_image_size = 0; 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; /* Retrieve and apply config */ psz_chroma = var_InheritString( p_vout, "opencv-chroma" ); if( psz_chroma == NULL ) { msg_Err( p_vout, "configuration variable %s empty, using 'grey'", "opencv-chroma" ); p_vout->p_sys->i_internal_chroma = GREY; } else { if( !strcmp( psz_chroma, "input" ) ) p_vout->p_sys->i_internal_chroma = CINPUT; else if( !strcmp( psz_chroma, "I420" ) ) p_vout->p_sys->i_internal_chroma = GREY; else if( !strcmp( psz_chroma, "RGB32" ) ) p_vout->p_sys->i_internal_chroma = RGB; else { msg_Err( p_vout, "no valid opencv-chroma provided, using 'grey'" ); p_vout->p_sys->i_internal_chroma = GREY; } } free( psz_chroma); psz_output = var_InheritString( p_vout, "opencv-output" ); if( psz_output == NULL ) { msg_Err( p_vout, "configuration variable %s empty, using 'input'", "opencv-output" ); p_vout->p_sys->i_wrapper_output = VINPUT; } else { if( !strcmp( psz_output, "none" ) ) p_vout->p_sys->i_wrapper_output = NONE; else if( !strcmp( psz_output, "input" ) ) p_vout->p_sys->i_wrapper_output = VINPUT; else if( !strcmp( psz_output, "processed" ) ) p_vout->p_sys->i_wrapper_output = PROCESSED; else { msg_Err( p_vout, "no valid opencv-output provided, using 'input'" ); p_vout->p_sys->i_wrapper_output = VINPUT; } } free( psz_output); psz_verbosity = var_InheritString( p_vout, "opencv-verbosity" ); if( psz_verbosity == NULL ) { msg_Err( p_vout, "configuration variable %s empty, using 'input'", "opencv-verbosity" ); p_vout->p_sys->i_verbosity = VERB_ERROR; } else { if( !strcmp( psz_verbosity, "error" ) ) p_vout->p_sys->i_verbosity = VERB_ERROR; else if( !strcmp( psz_verbosity, "warning" ) ) p_vout->p_sys->i_verbosity = VERB_WARN; else if( !strcmp( psz_verbosity, "debug" ) ) p_vout->p_sys->i_verbosity = VERB_DEBUG; else { msg_Err( p_vout, "no valid opencv-verbosity provided, using 'error'" ); p_vout->p_sys->i_verbosity = VERB_ERROR; } } free( psz_verbosity); p_vout->p_sys->psz_inner_name = var_InheritString( p_vout, "opencv-filter-name" ); p_vout->p_sys->f_scale = var_InheritFloat( p_vout, "opencv-scale" ); if (p_vout->p_sys->i_verbosity > VERB_WARN) msg_Info(p_vout, "Configuration: opencv-scale: %f, opencv-chroma: %d, " "opencv-output: %d, opencv-verbosity %d, opencv-filter %s", p_vout->p_sys->f_scale, p_vout->p_sys->i_internal_chroma, p_vout->p_sys->i_wrapper_output, p_vout->p_sys->i_verbosity, p_vout->p_sys->psz_inner_name); return VLC_SUCCESS; }