/***************************************************************************** * DestroyFilter: destroy mosaic video filter *****************************************************************************/ static void DestroyFilter( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t*)p_this; filter_sys_t *p_sys = p_filter->p_sys; /* FIXME: destroy callbacks first! */ if( !p_sys->b_keep ) { image_HandlerDelete( p_sys->p_image ); } if( p_sys->i_order_length ) { for( int i_index = 0; i_index < p_sys->i_order_length; i_index++ ) { free( p_sys->ppsz_order[i_index] ); } free( p_sys->ppsz_order ); } if( p_sys->i_offsets_length ) { free( p_sys->pi_x_offsets ); free( p_sys->pi_y_offsets ); p_sys->i_offsets_length = 0; } vlc_mutex_destroy( &p_sys->lock ); free( p_sys ); }
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; }
/***************************************************************************** * 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; }
/***************************************************************************** * CloseDecoder: OggSpots decoder destruction *****************************************************************************/ 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; image_HandlerDelete(p_sys->p_image); free(p_sys); }
static void osd_ParserUnload( osd_menu_t *p_menu ) { if( p_menu->p_image ) image_HandlerDelete( p_menu->p_image ); if( p_menu->p_parser ) module_unneed( p_menu, p_menu->p_parser ); free( p_menu->psz_file ); }
/***************************************************************************** * Destroy: destroy Distort video thread output method ***************************************************************************** * Terminate an output method created by DistortCreateOutputMethod *****************************************************************************/ static void Destroy( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; if( p_filter->p_sys->p_image ) image_HandlerDelete( p_filter->p_sys->p_image ); p_filter->p_sys->p_image = NULL; free( p_filter->p_sys ); }
/***************************************************************************** * Destroy: destroy opencv_wrapper video thread output method ***************************************************************************** * Terminate an output method created by opencv_wrapperCreateOutputMethod *****************************************************************************/ static void Destroy( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; ReleaseImages(p_vout); if( p_vout->p_sys->p_image ) image_HandlerDelete( p_vout->p_sys->p_image ); free( p_vout->p_sys ); }
ArtManager::~ArtManager( ) { if( m_pImageHandler ) { image_HandlerDelete( m_pImageHandler ); m_pImageHandler = NULL; } std::list<ArtBitmap*>::const_iterator it; for( it = m_listBitmap.begin(); it != m_listBitmap.end(); ++it ) delete *it; m_listBitmap.clear(); }
/***************************************************************************** * 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 ); }
/***************************************************************************** * Destroy: destroy video filter method *****************************************************************************/ static void Destroy( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; filter_sys_t *p_sys = (filter_sys_t *) p_filter->p_sys; image_HandlerDelete( p_sys->p_image ); if( p_sys->scene.p_pic ) picture_Release( p_sys->scene.p_pic ); free( p_sys->psz_format ); free( p_sys->psz_prefix ); free( p_sys->psz_path ); free( p_sys ); }
/***************************************************************************** * DestroyFilter: destroy mosaic video filter *****************************************************************************/ static void DestroyFilter( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t*)p_this; filter_sys_t *p_sys = p_filter->p_sys; #define DEL_CB( name ) \ var_DelCallback( p_filter, CFG_PREFIX #name, MosaicCallback, p_sys ) DEL_CB( width ); DEL_CB( height ); DEL_CB( xoffset ); DEL_CB( yoffset ); DEL_CB( align ); DEL_CB( borderw ); DEL_CB( borderh ); DEL_CB( rows ); DEL_CB( cols ); DEL_CB( alpha ); DEL_CB( position ); DEL_CB( delay ); DEL_CB( keep-aspect-ratio ); DEL_CB( order ); #undef DEL_CB if( !p_sys->b_keep ) { image_HandlerDelete( p_sys->p_image ); } if( p_sys->i_order_length ) { for( int i_index = 0; i_index < p_sys->i_order_length; i_index++ ) { free( p_sys->ppsz_order[i_index] ); } free( p_sys->ppsz_order ); } if( p_sys->i_offsets_length ) { free( p_sys->pi_x_offsets ); free( p_sys->pi_y_offsets ); p_sys->i_offsets_length = 0; } vlc_mutex_destroy( &p_sys->lock ); free( p_sys ); }
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; }
/***************************************************************************** * Destroy: destroy video thread ***************************************************************************** * Terminate an output method created by Create *****************************************************************************/ static void Destroy( vlc_object_t *p_this ) { int i_index; vout_thread_t *p_vout = ( vout_thread_t * )p_this; for( i_index = I_OUTPUTPICTURES-1; i_index >= 0; i_index-- ) { free( PP_OUTPUTPICTURE[ i_index ]->p_data ); } /* Destroy structure */ image_HandlerDelete( p_vout->p_sys->p_image ); FREE( p_vout->p_sys->psz_prefix ); FREE( p_vout->p_sys->psz_format ); FREE( p_vout->p_sys ); }
/***************************************************************************** * DestroyFilter: destroy mosaic video filter *****************************************************************************/ static void DestroyFilter( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t*)p_this; filter_sys_t *p_sys = p_filter->p_sys; libvlc_t *p_libvlc = p_filter->p_libvlc; int i_index; vlc_mutex_lock( &p_sys->lock ); if( !p_sys->b_keep ) { image_HandlerDelete( p_sys->p_image ); } if( p_sys->i_order_length ) { for( i_index = 0; i_index < p_sys->i_order_length; i_index++ ) { free( p_sys->ppsz_order[i_index] ); } free( p_sys->ppsz_order ); } var_Destroy( p_libvlc, "mosaic-alpha" ); var_Destroy( p_libvlc, "mosaic-height" ); var_Destroy( p_libvlc, "mosaic-align" ); var_Destroy( p_libvlc, "mosaic-width" ); var_Destroy( p_libvlc, "mosaic-xoffset" ); var_Destroy( p_libvlc, "mosaic-yoffset" ); var_Destroy( p_libvlc, "mosaic-borderw" ); var_Destroy( p_libvlc, "mosaic-borderh" ); var_Destroy( p_libvlc, "mosaic-position" ); var_Destroy( p_libvlc, "mosaic-rows" ); var_Destroy( p_libvlc, "mosaic-cols" ); var_Destroy( p_libvlc, "mosaic-keep-aspect-ratio" ); var_Destroy( p_libvlc, "mosaic-bsu" ); var_Destroy( p_libvlc, "mosaic-bsv" ); var_Destroy( p_libvlc, "mosaic-bsut" ); var_Destroy( p_libvlc, "mosaic-bsvt" ); var_Destroy( p_libvlc, "mosaic-bs" ); if( p_sys->p_pic ) p_sys->p_pic->pf_release( p_sys->p_pic ); vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_destroy( &p_sys->lock ); free( p_sys ); }
/* 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 ); }
/**************************************************************************** * 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 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; }
/** * 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; }
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; }
static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ) { VLC_UNUSED(id); sout_stream_sys_t *p_sys = p_stream->p_sys; bridge_t *p_bridge; bridged_es_t *p_es; bool b_last_es = true; int i; if( !p_sys->b_inited ) return VLC_SUCCESS; if( p_sys->p_decoder != NULL ) { decoder_owner_sys_t *p_owner = p_sys->p_decoder->p_owner; if( p_sys->p_decoder->p_module ) module_unneed( p_sys->p_decoder, p_sys->p_decoder->p_module ); if( p_sys->p_decoder->p_description ) vlc_meta_Delete( p_sys->p_decoder->p_description ); vlc_object_release( p_sys->p_decoder ); free( p_owner ); } /* Destroy user specified video filters */ if( p_sys->p_vf2 ) filter_chain_Delete( p_sys->p_vf2 ); vlc_global_lock( VLC_MOSAIC_MUTEX ); p_bridge = GetBridge( p_stream ); p_es = p_sys->p_es; p_es->b_empty = true; while ( p_es->p_picture ) { picture_t *p_next = p_es->p_picture->p_next; picture_Release( p_es->p_picture ); p_es->p_picture = p_next; } for ( i = 0; i < p_bridge->i_es_num; i++ ) { if ( !p_bridge->pp_es[i]->b_empty ) { b_last_es = false; break; } } if ( b_last_es ) { vlc_object_t *p_libvlc = VLC_OBJECT( p_stream->p_libvlc ); for ( i = 0; i < p_bridge->i_es_num; i++ ) free( p_bridge->pp_es[i] ); free( p_bridge->pp_es ); free( p_bridge ); var_Destroy( p_libvlc, "mosaic-struct" ); } vlc_global_unlock( VLC_MOSAIC_MUTEX ); if ( p_sys->p_image ) { image_HandlerDelete( p_sys->p_image ); } p_sys->b_inited = false; return VLC_SUCCESS; }
/***************************************************************************** * 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; }
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; }
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 ] ); }
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; }