int main (void) { static const char * our_keys[] = { "Hello", "Hella", "flowmeter", "Frostnipped", "frostnipped", "remiform", "quadrifoliolate", "singularity", "unafflicted" }; const int size = sizeof(our_keys)/sizeof(our_keys[0]); char ** keys; int i = 0; vlc_dictionary_t dict; vlc_dictionary_init( &dict, 0 ); assert( vlc_dictionary_keys_count( &dict ) == 0 ); keys = vlc_dictionary_all_keys( &dict ); assert( keys && !keys[0] ); free(keys); /* Insert some values */ for( i = 0; i < size; i++ ) vlc_dictionary_insert( &dict, our_keys[i], (void*)i ); test_dictionary_validity( &dict, our_keys, size ); vlc_dictionary_remove_value_for_key( &dict, our_keys[size-1], NULL, NULL ); test_dictionary_validity( &dict, our_keys, size-1 ); vlc_dictionary_clear( &dict, NULL, NULL ); assert( vlc_dictionary_keys_count( &dict ) == 0 ); return 0; }
/***************************************************************************** * Open: initialize and create stuff *****************************************************************************/ static int Open( vlc_object_t *p_this ) { services_discovery_t *p_sd = ( services_discovery_t* )p_this; services_discovery_sys_t *p_sys; int err; p_sd->p_sys = p_sys = calloc( 1, sizeof( services_discovery_sys_t ) ); if( !p_sys ) return VLC_ENOMEM; p_sd->description = _("Zeroconf network services"); vlc_dictionary_init( &p_sys->services_name_to_input_item, 1 ); p_sys->poll = avahi_threaded_poll_new(); if( p_sys->poll == NULL ) { msg_Err( p_sd, "failed to create Avahi threaded poll" ); goto error; } p_sys->client = avahi_client_new( avahi_threaded_poll_get(p_sys->poll), 0, client_callback, p_sd, &err ); if( p_sys->client == NULL ) { msg_Err( p_sd, "failed to create avahi client: %s", avahi_strerror( err ) ); goto error; } for( unsigned i = 0; i < NB_PROTOCOLS; i++ ) { AvahiServiceBrowser *sb; sb = avahi_service_browser_new( p_sys->client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, protocols[i].psz_service_name, NULL, 0, browse_callback, p_sd ); if( sb == NULL ) { msg_Err( p_sd, "failed to create avahi service browser %s", avahi_strerror( avahi_client_errno(p_sys->client) ) ); goto error; } } avahi_threaded_poll_start( p_sys->poll ); return VLC_SUCCESS; error: if( p_sys->client != NULL ) avahi_client_free( p_sys->client ); if( p_sys->poll != NULL ) avahi_threaded_poll_free( p_sys->poll ); vlc_dictionary_clear( &p_sys->services_name_to_input_item, NULL, NULL ); free( p_sys ); return VLC_EGENERIC; }
void vlc_meta_Delete( vlc_meta_t *m ) { int i; for( i = 0; i < VLC_META_TYPE_COUNT ; i++ ) free( m->ppsz_meta[i] ); vlc_dictionary_clear( &m->extra_tags, vlc_meta_FreeExtraKey, NULL ); free( m ); }
/***************************************************************************** * Close: cleanup *****************************************************************************/ static void Close( vlc_object_t *p_this ) { services_discovery_t *p_sd = ( services_discovery_t* )p_this; services_discovery_sys_t *p_sys = p_sd->p_sys; avahi_service_browser_free( p_sys->sb ); avahi_client_free( p_sys->client ); avahi_threaded_poll_free( p_sys->poll ); vlc_dictionary_clear( &p_sys->services_name_to_input_item, NULL, NULL ); free( p_sys ); }
/***************************************************************************** * Open: initialize and create stuff *****************************************************************************/ static int Open( vlc_object_t *p_this ) { services_discovery_t *p_sd = ( services_discovery_t* )p_this; services_discovery_sys_t *p_sys; int err; p_sd->p_sys = p_sys = calloc( 1, sizeof( services_discovery_sys_t ) ); if( !p_sys ) return VLC_ENOMEM; vlc_dictionary_init( &p_sys->services_name_to_input_item, 1 ); p_sys->poll = avahi_threaded_poll_new(); if( p_sys->poll == NULL ) { msg_Err( p_sd, "failed to create Avahi threaded poll" ); goto error; } p_sys->client = avahi_client_new( avahi_threaded_poll_get(p_sys->poll), 0, client_callback, p_sd, &err ); if( p_sys->client == NULL ) { msg_Err( p_sd, "failed to create avahi client: %s", avahi_strerror( err ) ); goto error; } p_sys->sb = avahi_service_browser_new( p_sys->client, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_vlc-http._tcp", NULL, 0, browse_callback, p_sd ); if( p_sys->sb == NULL ) { msg_Err( p_sd, "failed to create avahi service browser" ); goto error; } return VLC_SUCCESS; error: if( p_sys->sb != NULL ) avahi_service_browser_free( p_sys->sb ); if( p_sys->client != NULL ) avahi_client_free( p_sys->client ); if( p_sys->poll != NULL ) avahi_threaded_poll_free( p_sys->poll ); vlc_dictionary_clear( &p_sys->services_name_to_input_item, NULL, NULL ); free( p_sys ); return VLC_EGENERIC; }
static int vlc_sd_probe_Open( vlc_object_t *obj ) { vlc_dictionary_t name_d; char **ppsz_dir_list; if( vlclua_dir_list( "sd", &ppsz_dir_list ) ) return VLC_ENOMEM; vlc_dictionary_init( &name_d, 32 ); for( char **ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ ) { char **ppsz_filelist; int i_files = vlc_scandir( *ppsz_dir, &ppsz_filelist, file_select, file_compare ); if( i_files < 1 ) continue; for( char **ppsz_file = ppsz_filelist; ppsz_file < ppsz_filelist + i_files; ppsz_file++ ) { char *temp = strchr( *ppsz_file, '.' ); if( temp ) *temp = '\0'; if( vlc_dictionary_value_for_key( &name_d, *ppsz_file ) == kVLCDictionaryNotFound ) vlc_dictionary_insert( &name_d, *ppsz_file, &name_d ); free( *ppsz_file ); } free( ppsz_filelist ); } vlclua_dir_list_free( ppsz_dir_list ); int r = VLC_PROBE_CONTINUE; char **names = vlc_dictionary_all_keys( &name_d ); if( names != NULL ) { for( char **name = names; *name; ++name ) { r = vlclua_probe_sd( obj, *name ); if( r != VLC_PROBE_CONTINUE ) break; } for( char **name = names; *name; ++name ) free( *name ); free( names ); } vlc_dictionary_clear( &name_d, NULL, NULL ); return r; }
/** * Destroy the message queues * * This functions prints all messages remaining in the queues, * then frees all the allocated resources * No other messages interface functions should be called after this one. */ void msg_Destroy (msg_bank_t *bank) { if (unlikely(bank->i_sub != 0)) fputs ("stale interface subscribers (LibVLC might crash)\n", stderr); if (bank->locale != (locale_t)0) freelocale (bank->locale); vlc_dictionary_clear (&bank->enabled_objects, NULL, NULL); vlc_rwlock_destroy (&bank->lock); free (bank); }
/************************************************************************** * release (Public) **************************************************************************/ void libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis ) { int i; vlc_event_detach( services_discovery_EventManager( p_mdis->p_sd ), vlc_ServicesDiscoveryItemAdded, services_discovery_item_added, p_mdis ); vlc_event_detach( services_discovery_EventManager( p_mdis->p_sd ), vlc_ServicesDiscoveryItemRemoved, services_discovery_item_removed, p_mdis ); vlc_event_detach( services_discovery_EventManager( p_mdis->p_sd ), vlc_ServicesDiscoveryStarted, services_discovery_started, p_mdis ); vlc_event_detach( services_discovery_EventManager( p_mdis->p_sd ), vlc_ServicesDiscoveryEnded, services_discovery_ended, p_mdis ); vlc_event_detach( services_discovery_EventManager( p_mdis->p_sd ), vlc_ServicesDiscoveryItemRemoveAll, services_discovery_removeall, p_mdis ); libvlc_media_list_release( p_mdis->p_mlist ); if( p_mdis->running ) vlc_sd_Stop( p_mdis->p_sd ); vlc_sd_Destroy( p_mdis->p_sd ); /* Free catname_to_submedialist and all the mlist */ char ** all_keys = vlc_dictionary_all_keys( &p_mdis->catname_to_submedialist ); for( i = 0; all_keys[i]; i++ ) { libvlc_media_list_t * p_catmlist = vlc_dictionary_value_for_key( &p_mdis->catname_to_submedialist, all_keys[i] ); libvlc_media_list_release( p_catmlist ); free( all_keys[i] ); } free( all_keys ); vlc_dictionary_clear( &p_mdis->catname_to_submedialist, NULL, NULL ); libvlc_event_manager_release( p_mdis->p_event_manager ); libvlc_release( p_mdis->p_libvlc_instance ); free( p_mdis ); }
void libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis ) { if( p_mdis->p_sd != NULL ) libvlc_media_discoverer_stop( p_mdis ); libvlc_media_list_release( p_mdis->p_mlist ); vlc_dictionary_clear( &p_mdis->catname_to_submedialist, MediaListDictValueRelease, NULL ); libvlc_event_manager_destroy( &p_mdis->event_manager ); libvlc_release( p_mdis->p_libvlc_instance ); free( p_mdis ); }
/** * Destroy the message queues * * This functions prints all messages remaining in the queues, * then frees all the allocated resources * No other messages interface functions should be called after this one. */ void msg_Destroy (msg_bank_t *bank) { if (unlikely(bank->i_sub != 0)) fputs ("stale interface subscribers (LibVLC might crash)\n", stderr); vlc_mutex_lock( &msg_stack_lock ); assert(banks > 0); if( --banks == 0 ) vlc_threadvar_delete( &msg_context ); vlc_mutex_unlock( &msg_stack_lock ); if (bank->locale != (locale_t)0) freelocale (bank->locale); vlc_dictionary_clear (&bank->enabled_objects, NULL, NULL); vlc_rwlock_destroy (&bank->lock); free (bank); }
/************************************************************************** * release (Public) **************************************************************************/ void libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis ) { int i; libvlc_media_list_release( p_mdis->p_mlist ); services_discovery_Destroy( p_mdis->p_sd ); /* Free catname_to_submedialist and all the mlist */ char ** all_keys = vlc_dictionary_all_keys( &p_mdis->catname_to_submedialist ); for( i = 0; all_keys[i]; i++ ) { libvlc_media_list_t * p_catmlist = vlc_dictionary_value_for_key( &p_mdis->catname_to_submedialist, all_keys[i] ); libvlc_media_list_release( p_catmlist ); free( all_keys[i] ); } free( all_keys ); vlc_dictionary_clear( &p_mdis->catname_to_submedialist ); free( p_mdis ); }
/** * Destroy the message queues * * This functions prints all messages remaining in the queues, * then frees all the allocated resources * No other messages interface functions should be called after this one. */ void msg_Destroy (libvlc_int_t *p_libvlc) { libvlc_priv_t *priv = libvlc_priv (p_libvlc); msg_bank_t *bank = libvlc_bank (p_libvlc); if( QUEUE.i_sub ) msg_Err( p_libvlc, "stale interface subscribers (VLC might crash)" ); vlc_mutex_lock( &msg_stack_lock ); assert(banks > 0); if( --banks == 0 ) vlc_threadvar_delete( &msg_context ); vlc_mutex_unlock( &msg_stack_lock ); #ifdef UNDER_CE CloseHandle( QUEUE.logfile ); #endif vlc_dictionary_clear( &priv->msg_enabled_objects, NULL, NULL ); vlc_cond_destroy (&bank->wait); vlc_mutex_destroy (&bank->lock); }
static void tt_node_Delete( tt_node_t *p_node ) { free( p_node->psz_node_name ); vlc_dictionary_clear( &p_node->attr_dict, tt_node_FreeDictValue, NULL ); free( p_node ); }
/** * ProcessEvents() reacts to a list of events originating from other VLC threads * * This function must be called with p_sys->lock unlocked * * @param intf_thread_t *p_intf This interface thread state * @param callback_info_t *p_events the list of events to process */ static void ProcessEvents( intf_thread_t *p_intf, callback_info_t **p_events, int i_events ) { playlist_t *p_playlist = p_intf->p_sys->p_playlist; bool b_can_play = p_intf->p_sys->b_can_play; vlc_dictionary_t player_properties, tracklist_properties; vlc_dictionary_init( &player_properties, 0 ); vlc_dictionary_init( &tracklist_properties, 0 ); for( int i = 0; i < i_events; i++ ) { switch( p_events[i]->signal ) { case SIGNAL_ITEM_CURRENT: TrackChange( p_intf ); vlc_dictionary_insert( &player_properties, "Metadata", NULL ); break; case SIGNAL_INTF_CHANGE: case SIGNAL_PLAYLIST_ITEM_APPEND: case SIGNAL_PLAYLIST_ITEM_DELETED: PL_LOCK; b_can_play = playlist_CurrentSize( p_playlist ) > 0; PL_UNLOCK; if( b_can_play != p_intf->p_sys->b_can_play ) { p_intf->p_sys->b_can_play = b_can_play; vlc_dictionary_insert( &player_properties, "CanPlay", NULL ); } if( !vlc_dictionary_has_key( &tracklist_properties, "Tracks" ) ) vlc_dictionary_insert( &tracklist_properties, "Tracks", NULL ); break; case SIGNAL_VOLUME_MUTED: case SIGNAL_VOLUME_CHANGE: vlc_dictionary_insert( &player_properties, "Volume", NULL ); break; case SIGNAL_RANDOM: vlc_dictionary_insert( &player_properties, "Shuffle", NULL ); break; case SIGNAL_REPEAT: case SIGNAL_LOOP: vlc_dictionary_insert( &player_properties, "LoopStatus", NULL ); break; case SIGNAL_STATE: vlc_dictionary_insert( &player_properties, "PlaybackStatus", NULL ); break; case SIGNAL_RATE: vlc_dictionary_insert( &player_properties, "Rate", NULL ); break; case SIGNAL_INPUT_METADATA: { input_thread_t *p_input = playlist_CurrentInput( p_playlist ); input_item_t *p_item; if( p_input ) { p_item = input_GetItem( p_input ); vlc_object_release( p_input ); if( p_item ) vlc_dictionary_insert( &player_properties, "Metadata", NULL ); } break; } case SIGNAL_CAN_SEEK: vlc_dictionary_insert( &player_properties, "CanSeek", NULL ); break; case SIGNAL_CAN_PAUSE: vlc_dictionary_insert( &player_properties, "CanPause", NULL ); break; case SIGNAL_SEEK: { input_thread_t *p_input; input_item_t *p_item; p_input = playlist_CurrentInput( p_intf->p_sys->p_playlist ); if( p_input ) { p_item = input_GetItem( p_input ); vlc_object_release( p_input ); if( p_item && ( p_item->i_id == p_events[i]->i_item ) ) SeekedEmit( p_intf ); } break; } default: assert(0); } free( p_events[i] ); } if( vlc_dictionary_keys_count( &player_properties ) ) PlayerPropertiesChangedEmit( p_intf, &player_properties ); if( vlc_dictionary_keys_count( &tracklist_properties ) ) TrackListPropertiesChangedEmit( p_intf, &tracklist_properties ); vlc_dictionary_clear( &player_properties, NULL, NULL ); vlc_dictionary_clear( &tracklist_properties, NULL, NULL ); }