Commit c7f9e3ce authored by Romain Vimont's avatar Romain Vimont Committed by Jean-Baptiste Kempf

core: replace service_discovery_sys_t* by void*

See #17078
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 4319ab8d
......@@ -66,7 +66,7 @@ struct services_discovery_t
*/
int ( *pf_control ) ( services_discovery_t *, int, va_list );
services_discovery_sys_t *p_sys; /**< Custom private data */
void *p_sys; /**< Custom private data */
struct services_discovery_owner_t owner; /**< Owner callbacks */
};
......
......@@ -391,7 +391,8 @@ static void
new_entries_sd_cb( void *p_this, int i_status, const struct rr_entry *p_entries )
{
services_discovery_t *p_sd = (services_discovery_t *)p_this;
struct discovery_sys *p_sys = &p_sd->p_sys->s;
services_discovery_sys_t *p_sdsys = p_sd->p_sys;
struct discovery_sys *p_sys = &p_sdsys->s;
if( i_status < 0 )
{
print_error( VLC_OBJECT( p_sd ), "entry callback", i_status );
......@@ -434,7 +435,8 @@ static bool
stop_sd_cb( void *p_this )
{
services_discovery_t *p_sd = ( services_discovery_t* )p_this;
struct discovery_sys *p_sys = &p_sd->p_sys->s;
services_discovery_sys_t *p_sdsys = p_sd->p_sys;
struct discovery_sys *p_sys = &p_sdsys->s;
if( atomic_load( &p_sys->stop ) )
return true;
......@@ -449,7 +451,8 @@ static void *
RunSD( void *p_this )
{
services_discovery_t *p_sd = ( services_discovery_t* )p_this;
struct discovery_sys *p_sys = &p_sd->p_sys->s;
services_discovery_sys_t *p_sdsys = p_sd->p_sys;
struct discovery_sys *p_sys = &p_sdsys->s;
int i_status = mdns_listen( p_sys->p_microdns,
p_sys->ppsz_service_names,
......@@ -637,23 +640,25 @@ OpenSD( vlc_object_t *p_obj )
{
services_discovery_t *p_sd = (services_discovery_t *)p_obj;
p_sd->p_sys = calloc( 1, sizeof(services_discovery_sys_t) );
if( !p_sd->p_sys )
services_discovery_sys_t *p_sys = calloc( 1, sizeof(services_discovery_sys_t) );
if( !p_sys )
return VLC_ENOMEM;
p_sd->p_sys = p_sys;
p_sd->description = _("mDNS Network Discovery");
config_ChainParse( p_sd, CFG_PREFIX, ppsz_options, p_sd->p_cfg );
return OpenCommon( p_obj, &p_sd->p_sys->s, false );
return OpenCommon( p_obj, &p_sys->s, false );
}
static void
CloseSD( 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;
CleanCommon( &p_sd->p_sys->s );
free( p_sd->p_sys );
CleanCommon( &p_sys->s );
free( p_sys );
}
static int
......
......@@ -118,11 +118,12 @@ static int Open( vlc_object_t *p_this )
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;
free( p_sd->p_sys->psz_name );
vlc_cancel( p_sd->p_sys->thread );
vlc_join( p_sd->p_sys->thread, NULL );
free( p_sd->p_sys );
free( p_sys->psz_name );
vlc_cancel( p_sys->thread );
vlc_join( p_sys->thread, NULL );
free( p_sys );
}
/*****************************************************************************
......@@ -180,6 +181,7 @@ static void *Run( void *data )
static int AddDevice( services_discovery_t *p_sd,
LIBMTP_raw_device_t *p_raw_device )
{
services_discovery_sys_t *p_sys = p_sd->p_sys;
char *psz_name = NULL;
LIBMTP_mtpdevice_t *p_device;
LIBMTP_track_t *p_track, *p_tmp;
......@@ -191,24 +193,24 @@ static int AddDevice( services_discovery_t *p_sd,
if( !( psz_name = strdup( N_( "MTP Device" ) ) ) )
return VLC_ENOMEM;
msg_Info( p_sd, "Found device: %s", psz_name );
p_sd->p_sys->i_bus = p_raw_device->bus_location;
p_sd->p_sys->i_dev = p_raw_device->devnum;
p_sd->p_sys->i_product_id = p_raw_device->device_entry.product_id;
p_sys->i_bus = p_raw_device->bus_location;
p_sys->i_dev = p_raw_device->devnum;
p_sys->i_product_id = p_raw_device->device_entry.product_id;
if( ( p_track = LIBMTP_Get_Tracklisting_With_Callback( p_device,
CountTracks, p_sd ) ) == NULL )
{
msg_Warn( p_sd, "No tracks on the device" );
p_sd->p_sys->pp_items = NULL;
p_sys->pp_items = NULL;
}
else
{
if( !( p_sd->p_sys->pp_items = calloc( p_sd->p_sys->i_tracks_num,
if( !( p_sys->pp_items = calloc( p_sys->i_tracks_num,
sizeof( input_item_t * ) ) ) )
{
free( psz_name );
return VLC_ENOMEM;
}
p_sd->p_sys->i_count = 0;
p_sys->i_count = 0;
while( p_track != NULL )
{
msg_Dbg( p_sd, "Track found: %s - %s", p_track->artist,
......@@ -219,7 +221,7 @@ static int AddDevice( services_discovery_t *p_sd,
LIBMTP_destroy_track_t( p_tmp );
}
}
p_sd->p_sys->psz_name = psz_name;
p_sys->psz_name = psz_name;
LIBMTP_Release_Device( p_device );
return VLC_SUCCESS;
}
......@@ -232,14 +234,15 @@ static int AddDevice( services_discovery_t *p_sd,
static void AddTrack( services_discovery_t *p_sd, LIBMTP_track_t *p_track )
{
services_discovery_sys_t *p_sys = p_sd->p_sys;
input_item_t *p_input;
char *psz_string;
char *extension;
extension = rindex( p_track->filename, '.' );
if( asprintf( &psz_string, "mtp://%"PRIu32":%"PRIu8":%"PRIu16":%d%s",
p_sd->p_sys->i_bus, p_sd->p_sys->i_dev,
p_sd->p_sys->i_product_id, p_track->item_id,
p_sys->i_bus, p_sys->i_dev,
p_sys->i_product_id, p_track->item_id,
extension ) == -1 )
{
msg_Err( p_sd, "Error adding %s, skipping it", p_track->filename );
......@@ -269,16 +272,17 @@ static void AddTrack( services_discovery_t *p_sd, LIBMTP_track_t *p_track )
input_item_SetDate( p_input, p_track->date );
p_input->i_duration = p_track->duration * INT64_C(1000);
services_discovery_AddItem( p_sd, p_input );
p_sd->p_sys->pp_items[p_sd->p_sys->i_count++] = p_input;
p_sys->pp_items[p_sys->i_count++] = p_input;
}
static void CloseDevice( services_discovery_t *p_sd )
{
input_item_t **pp_items = p_sd->p_sys->pp_items;
services_discovery_sys_t *p_sys = p_sd->p_sys;
input_item_t **pp_items = p_sys->pp_items;
if( pp_items != NULL )
{
for( int i_i = 0; i_i < p_sd->p_sys->i_count; i_i++ )
for( int i_i = 0; i_i < p_sys->i_count; i_i++ )
{
if( pp_items[i_i] != NULL )
{
......@@ -295,6 +299,7 @@ static int CountTracks( uint64_t const sent, uint64_t const total,
{
VLC_UNUSED( sent );
services_discovery_t *p_sd = (services_discovery_t *)data;
p_sd->p_sys->i_tracks_num = total;
services_discovery_sys_t *p_sys = p_sd->p_sys;
p_sys->i_tracks_num = total;
return 0;
}
......@@ -184,16 +184,16 @@ static void Close( vlc_object_t *p_this )
for( int i = 0; i < p_sys->i_input; i++ )
{
input_thread_t *p_input = p_sd->p_sys->pp_input[i];
input_thread_t *p_input = p_sys->pp_input[i];
if( !p_input )
continue;
input_Stop( p_input );
input_Close( p_input );
p_sd->p_sys->pp_input[i] = NULL;
p_sys->pp_input[i] = NULL;
}
free( p_sd->p_sys->pp_input );
free( p_sys->pp_input );
for( int i = 0; i < p_sys->i_urls; i++ )
free( p_sys->ppsz_urls[i] );
......@@ -237,9 +237,9 @@ noreturn static void *Run( void *data )
p_sys->b_update = false;
for( int i = 0; i < p_sd->p_sys->i_input; i++ )
for( int i = 0; i < p_sys->i_input; i++ )
{
input_thread_t *p_input = p_sd->p_sys->pp_input[i];
input_thread_t *p_input = p_sys->pp_input[i];
int state = var_GetInteger( p_input, "state" );
if( state == END_S || state == ERROR_S )
......@@ -247,7 +247,7 @@ noreturn static void *Run( void *data )
input_Stop( p_input );
input_Close( p_input );
p_sd->p_sys->pp_input[i] = NULL;
p_sys->pp_input[i] = NULL;
TAB_ERASE(p_sys->i_input, p_sys->pp_input, i);
i--;
}
......
......@@ -458,6 +458,7 @@ static void CloseDemux( vlc_object_t *p_this )
static void *Run( void *data )
{
services_discovery_t *p_sd = data;
services_discovery_sys_t *p_sys = p_sd->p_sys;
char *psz_addr;
int timeout = -1;
int canc = vlc_savecancel ();
......@@ -524,7 +525,7 @@ static void *Run( void *data )
InitSocket( p_sd, psz_addr, SAP_PORT );
free( psz_addr );
if( p_sd->p_sys->i_fd == 0 )
if( p_sys->i_fd == 0 )
{
msg_Err( p_sd, "unable to listen on any address" );
return NULL;
......@@ -534,12 +535,12 @@ static void *Run( void *data )
for (;;)
{
vlc_restorecancel (canc);
unsigned n = p_sd->p_sys->i_fd;
unsigned n = p_sys->i_fd;
struct pollfd ufd[n];
for (unsigned i = 0; i < n; i++)
{
ufd[i].fd = p_sd->p_sys->pi_fd[i];
ufd[i].fd = p_sys->pi_fd[i];
ufd[i].events = POLLIN;
ufd[i].revents = 0;
}
......@@ -576,10 +577,10 @@ static void *Run( void *data )
timeout = 1000 * 60 * 60;
/* Check for items that need deletion */
for( int i = 0; i < p_sd->p_sys->i_announces; i++ )
for( int i = 0; i < p_sys->i_announces; i++ )
{
mtime_t i_timeout = ( mtime_t ) 1000000 * p_sd->p_sys->i_timeout;
sap_announce_t * p_announce = p_sd->p_sys->pp_announces[i];
mtime_t i_timeout = ( mtime_t ) 1000000 * p_sys->i_timeout;
sap_announce_t * p_announce = p_sys->pp_announces[i];
mtime_t i_last_period = now - p_announce->i_last;
/* Remove the announcement, if the last announcement was 1 hour ago
......@@ -599,7 +600,7 @@ static void *Run( void *data )
}
}
if( !p_sd->p_sys->i_announces )
if( !p_sys->i_announces )
timeout = -1; /* We can safely poll indefinitely. */
else if( timeout < 200 )
timeout = 200; /* Don't wakeup too fast. */
......@@ -663,6 +664,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
static int ParseSAP( services_discovery_t *p_sd, const uint8_t *buf,
size_t len )
{
services_discovery_sys_t *p_sys = p_sd->p_sys;
const char *psz_sdp;
const uint8_t *end = buf + len;
sdp_t *p_sdp;
......@@ -693,7 +695,7 @@ static int ParseSAP( services_discovery_t *p_sd, const uint8_t *buf,
uint16_t i_hash = U16_AT (buf + 2);
if( p_sd->p_sys->b_strict && i_hash == 0 )
if( p_sys->b_strict && i_hash == 0 )
{
msg_Dbg( p_sd, "strict mode, discarding announce with null id hash");
return VLC_EGENERIC;
......@@ -774,7 +776,7 @@ static int ParseSAP( services_discovery_t *p_sd, const uint8_t *buf,
p_sdp->psz_uri = NULL;
/* Multi-media or no-parse -> pass to LIVE.COM */
if( !IsWellKnownPayload( p_sdp->i_media_type ) || !p_sd->p_sys->b_parse )
if( !IsWellKnownPayload( p_sdp->i_media_type ) || !p_sys->b_parse )
{
free( p_sdp->psz_uri );
if (asprintf( &p_sdp->psz_uri, "sdp://%s", p_sdp->psz_sdp ) == -1)
......@@ -787,9 +789,9 @@ static int ParseSAP( services_discovery_t *p_sd, const uint8_t *buf,
goto error;
}
for( int i = 0 ; i< p_sd->p_sys->i_announces ; i++ )
for( int i = 0 ; i < p_sys->i_announces ; i++ )
{
sap_announce_t * p_announce = p_sd->p_sys->pp_announces[i];
sap_announce_t * p_announce = p_sys->pp_announces[i];
/* FIXME: slow */
if( ( !i_hash && IsSameSession( p_announce->p_sdp, p_sdp ) )
|| ( i_hash && p_announce->i_hash == i_hash
......@@ -800,7 +802,7 @@ static int ParseSAP( services_discovery_t *p_sd, const uint8_t *buf,
* Instead we cleverly implement Implicit Announcement removal.
*
* if( b_need_delete )
* RemoveAnnounce( p_sd, p_sd->p_sys->pp_announces[i]);
* RemoveAnnounce( p_sd, p_sys->pp_announces[i]);
* else
*/
......@@ -1481,7 +1483,8 @@ static int InitSocket( services_discovery_t *p_sd, const char *psz_address,
return VLC_EGENERIC;
shutdown( i_fd, SHUT_WR );
TAB_APPEND(p_sd->p_sys->i_fd, p_sd->p_sys->pi_fd, i_fd);
services_discovery_sys_t *p_sys = p_sd->p_sys;
TAB_APPEND(p_sys->i_fd, p_sys->pi_fd, i_fd);
return VLC_SUCCESS;
}
......@@ -1572,8 +1575,8 @@ static int RemoveAnnounce( services_discovery_t *p_sd,
p_announce->p_item = NULL;
}
TAB_REMOVE(p_sd->p_sys->i_announces, p_sd->p_sys->pp_announces,
p_announce);
services_discovery_sys_t *p_sys = p_sd->p_sys;
TAB_REMOVE(p_sys->i_announces, p_sys->pp_announces, p_announce);
free( p_announce );
return VLC_SUCCESS;
......
......@@ -223,7 +223,7 @@ static void *
SearchThread( void *p_data )
{
services_discovery_t *p_sd = ( services_discovery_t* )p_data;
services_discovery_sys_t *p_sys = p_sd->p_sys;
services_discovery_sys_t *p_sys = reinterpret_cast<services_discovery_sys_t *>( p_sd->p_sys );
/* Search for media servers */
int i_res = UpnpSearchAsync( p_sys->p_upnp->handle(), 5,
......@@ -283,7 +283,7 @@ static int Open( vlc_object_t *p_this )
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;
services_discovery_sys_t *p_sys = reinterpret_cast<services_discovery_sys_t *>( p_sd->p_sys );
vlc_join( p_sys->thread, NULL );
p_sys->p_upnp->release( true );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment