]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/sap.c
Fix a bunch of gcc warnings
[vlc] / modules / services_discovery / sap.c
index 656037652c3f7991b56820bfbc33e5aa22405e77..f700926f621debe53cbd664c310a9751592e8d20 100644 (file)
@@ -24,6 +24,7 @@
 /*****************************************************************************
  * Includes
  *****************************************************************************/
+#define _GNU_SOURCE
 #include <stdlib.h>                                      /* malloc(), free() */
 
 #include <vlc/vlc.h>
@@ -224,7 +225,6 @@ struct services_discovery_sys_t
     /* playlist node */
     playlist_item_t *p_node_cat;
     playlist_item_t *p_node_one;
-    playlist_t *p_playlist;
 
     /* Table of announces */
     int i_announces;
@@ -272,9 +272,6 @@ struct demux_sys_t
 #endif
     static void FreeSDP( sdp_t *p_sdp );
 
-
-#define FREE( p ) \
-    if( p ) { free( p ); (p) = NULL; }
 /*****************************************************************************
  * Open: initialize and create stuff
  *****************************************************************************/
@@ -307,17 +304,11 @@ static int Open( vlc_object_t *p_this )
             ? VLC_TRUE : VLC_FALSE;
 
     /* Create our playlist node */
-    p_sys->p_playlist = (playlist_t *)vlc_object_find( p_sd,
-                                                       VLC_OBJECT_PLAYLIST,
-                                                       FIND_ANYWHERE );
-    if( !p_sys->p_playlist )
-    {
-        msg_Warn( p_sd, "unable to find playlist, cancelling SAP listening");
-        return VLC_EGENERIC;
-    }
+    pl_Yield( p_sd );
 
-    playlist_NodesCreateForSD( p_sys->p_playlist, _("SAP sessions"),
-                               &p_sys->p_node_cat, &p_sys->p_node_one );
+    playlist_NodesPairCreate( pl_Get( p_sd ), _("SAP sessions"),
+                              &p_sys->p_node_cat, &p_sys->p_node_one,
+                              VLC_TRUE );
 
     p_sys->i_announces = 0;
     p_sys->pp_announces = NULL;
@@ -411,11 +402,11 @@ static int OpenDemux( vlc_object_t *p_this )
     p_demux->pf_control = Control;
     p_demux->pf_demux = Demux;
 
-    FREE( psz_sdp );
+    FREENULL( psz_sdp );
     return VLC_SUCCESS;
 
 error:
-    FREE( psz_sdp );
+    FREENULL( psz_sdp );
     if( p_sdp ) FreeSDP( p_sdp ); p_sdp = NULL;
     stream_Seek( p_demux->s, 0 );
     return VLC_EGENERIC;
@@ -435,7 +426,7 @@ static void Close( vlc_object_t *p_this )
     {
         net_Close( p_sys->pi_fd[i] );
     }
-    FREE( p_sys->pi_fd );
+    FREENULL( p_sys->pi_fd );
 
 #if 0
     if( config_GetInt( p_sd, "sap-cache" ) )
@@ -448,17 +439,13 @@ static void Close( vlc_object_t *p_this )
     {
         RemoveAnnounce( p_sd, p_sys->pp_announces[i] );
     }
-    FREE( p_sys->pp_announces );
-
-    if( p_sys->p_playlist )
-    {
-        playlist_NodeDelete( p_sys->p_playlist, p_sys->p_node_cat, VLC_TRUE,
-                             VLC_TRUE );
-        playlist_NodeDelete( p_sys->p_playlist, p_sys->p_node_one, VLC_TRUE,
-                             VLC_TRUE );
-        vlc_object_release( p_sys->p_playlist );
-    }
+    FREENULL( p_sys->pp_announces );
 
+    playlist_NodeDelete( pl_Get(p_sd), p_sys->p_node_cat, VLC_TRUE,
+                         VLC_TRUE );
+    playlist_NodeDelete( pl_Get(p_sd), p_sys->p_node_one, VLC_TRUE,
+                         VLC_TRUE );
+    pl_Release( p_sd );
     free( p_sys );
 }
 
@@ -570,20 +557,13 @@ static void Run( services_discovery_t *p_sd )
 static int Demux( demux_t *p_demux )
 {
     sdp_t *p_sdp = p_demux->p_sys->p_sdp;
-    playlist_t *p_playlist;
     input_thread_t *p_input;
     input_item_t *p_parent_input;
 
-    p_playlist = (playlist_t *)vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST,
-                                               FIND_ANYWHERE );
-    if( !p_playlist )
-    {
-        msg_Err( p_demux, "playlist could not be found" );
-        return VLC_EGENERIC;
-    }
-
+    playlist_t *p_playlist = pl_Yield( p_demux );
     p_input = (input_thread_t *)vlc_object_find( p_demux, VLC_OBJECT_INPUT,
-                                               FIND_PARENT );
+                                                 FIND_PARENT );
+    assert( p_input );
     if( !p_input )
     {
         msg_Err( p_demux, "parent input could not be found" );
@@ -593,9 +573,9 @@ static int Demux( demux_t *p_demux )
     p_parent_input = p_input->input.p_item;
 
     vlc_mutex_lock( &p_parent_input->lock );
-    FREE( p_parent_input->psz_uri );
+    FREENULL( p_parent_input->psz_uri );
     p_parent_input->psz_uri = strdup( p_sdp->psz_uri );
-    FREE( p_parent_input->psz_name );
+    FREENULL( p_parent_input->psz_name );
     p_parent_input->psz_name = strdup( EnsureUTF8( p_sdp->psz_sessionname ) );
     p_parent_input->i_type = ITEM_TYPE_NET;
 
@@ -802,7 +782,7 @@ static int ParseSAP( services_discovery_t *p_sd, uint8_t *p_buffer, int i_read )
 
     CreateAnnounce( p_sd, i_hash, p_sdp );
 
-    FREE( p_decompressed_buffer );
+    FREENULL( p_decompressed_buffer );
     return VLC_SUCCESS;
 }
 
@@ -838,16 +818,16 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash,
     }
 
     if( p_sys->b_timeshift )
-        vlc_input_item_AddOption( p_input, ":access-filter=timeshift" );
+        input_ItemAddOption( p_input, ":access-filter=timeshift" );
 
     psz_value = GetAttribute( p_sap->p_sdp, "tool" );
     if( psz_value != NULL )
     {
-        vlc_input_item_AddInfo( p_input, _("Session"),_("Tool"), psz_value );
+        input_ItemAddInfo( p_input, _("Session"),_("Tool"), psz_value );
     }
     if( strcmp( p_sdp->psz_username, "-" ) )
     {
-        vlc_input_item_AddInfo( p_input, _("Session"),
+        input_ItemAddInfo( p_input, _("Session"),
                                 _("User"), p_sdp->psz_username );
     }
 
@@ -864,7 +844,7 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash,
 
         if( p_child == NULL )
         {
-            p_child = playlist_NodeCreate( p_sys->p_playlist, psz_value,
+            p_child = playlist_NodeCreate( pl_Get( p_sd ), psz_value,
                                            p_sys->p_node_cat );
             p_child->i_flags &= ~PLAYLIST_SKIP_FLAG;
         }
@@ -874,13 +854,13 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash,
         p_child = p_sys->p_node_cat;
     }
 
-    p_item = playlist_NodeAddInput( p_sys->p_playlist, p_input, p_child,
+    p_item = playlist_NodeAddInput( pl_Get( p_sd ), p_input, p_child,
                                     PLAYLIST_APPEND, PLAYLIST_END );
     p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
     p_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
     p_sap->i_item_id_cat = p_item->i_id;
 
-    p_item = playlist_NodeAddInput( p_sys->p_playlist, p_input,
+    p_item = playlist_NodeAddInput( pl_Get( p_sd ), p_input,
                         p_sys->p_node_one, PLAYLIST_APPEND, PLAYLIST_END );
     p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
     p_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
@@ -993,7 +973,7 @@ static int ParseConnection( vlc_object_t *p_obj, sdp_t *p_sdp )
                 strncmp( psz_parse, "video", 5 ) )
             {
                 msg_Warn( p_obj, "unhandled media type -%s-", psz_parse );
-                FREE( psz_uri );
+                FREENULL( psz_uri );
                 return VLC_EGENERIC;
             }
 
@@ -1002,7 +982,7 @@ static int ParseConnection( vlc_object_t *p_obj, sdp_t *p_sdp )
         else
         {
             msg_Warn( p_obj, "unable to parse m field (1)");
-            FREE( psz_uri );
+            FREENULL( psz_uri );
             return VLC_EGENERIC;
         }
 
@@ -1025,7 +1005,7 @@ static int ParseConnection( vlc_object_t *p_obj, sdp_t *p_sdp )
         else
         {
             msg_Warn( p_obj, "unable to parse m field (2)");
-            FREE( psz_uri );
+            FREENULL( psz_uri );
             return VLC_EGENERIC;
         }
 
@@ -1075,8 +1055,8 @@ static int ParseConnection( vlc_object_t *p_obj, sdp_t *p_sdp )
     asprintf( &p_sdp->psz_uri, "%s://%s@%s:%i", psz_proto, psz_source,
               psz_uri, i_port );
 
-    FREE( psz_uri );
-    FREE( psz_proto );
+    FREENULL( psz_uri );
+    FREENULL( psz_proto );
     return VLC_SUCCESS;
 }
 
@@ -1200,10 +1180,10 @@ static sdp_t *  ParseSDP( vlc_object_t *p_obj, char* psz_sdp )
 
                 p_sdp->i_session_id = atoll( psz_sess_id );
 
-                FREE( psz_sess_id );
+                FREENULL( psz_sess_id );
 
                 GET_FIELD( psz_sess_id );
-                FREE( psz_sess_id );
+                FREENULL( psz_sess_id );
 
                 GET_FIELD( p_sdp->psz_network_type );
                 GET_FIELD( p_sdp->psz_address_type );
@@ -1347,26 +1327,26 @@ static int Decompress( unsigned char *psz_src, unsigned char **_dst, int i_len )
 static void FreeSDP( sdp_t *p_sdp )
 {
     int i;
-    FREE( p_sdp->psz_sdp );
-    FREE( p_sdp->psz_sessionname );
-    FREE( p_sdp->psz_connection );
-    FREE( p_sdp->psz_media );
-    FREE( p_sdp->psz_uri );
-    FREE( p_sdp->psz_username );
-    FREE( p_sdp->psz_network_type );
+    FREENULL( p_sdp->psz_sdp );
+    FREENULL( p_sdp->psz_sessionname );
+    FREENULL( p_sdp->psz_connection );
+    FREENULL( p_sdp->psz_media );
+    FREENULL( p_sdp->psz_uri );
+    FREENULL( p_sdp->psz_username );
+    FREENULL( p_sdp->psz_network_type );
 
-    FREE( p_sdp->psz_address );
-    FREE( p_sdp->psz_address_type );
+    FREENULL( p_sdp->psz_address );
+    FREENULL( p_sdp->psz_address_type );
 
     for( i= p_sdp->i_attributes - 1; i >= 0 ; i-- )
     {
         struct attribute_t *p_attr = p_sdp->pp_attributes[i];
-        FREE( p_sdp->pp_attributes[i]->psz_field );
-        FREE( p_sdp->pp_attributes[i]->psz_value );
+        FREENULL( p_sdp->pp_attributes[i]->psz_field );
+        FREENULL( p_sdp->pp_attributes[i]->psz_value );
         REMOVE_ELEM( p_sdp->pp_attributes, p_sdp->i_attributes, i);
-        FREE( p_attr );
+        FREENULL( p_attr );
     }
-    FREE( p_sdp );
+    FREENULL( p_sdp );
 }
 
 static int RemoveAnnounce( services_discovery_t *p_sd,
@@ -1381,10 +1361,7 @@ static int RemoveAnnounce( services_discovery_t *p_sd,
     }
 
     if( p_announce->i_input_id > -1 )
-    {
-        playlist_LockDeleteAllFromInput(
-                        p_sd->p_sys->p_playlist, p_announce->i_input_id );
-    }
+        playlist_LockDeleteAllFromInput( pl_Get(p_sd), p_announce->i_input_id );
 
     for( i = 0; i< p_sd->p_sys->i_announces; i++)
     {