]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/sap.c
avformat: set the "duration/length/ of a packet if known.
[vlc] / modules / services_discovery / sap.c
index d0d1144e99bf74ba613769876a6b7fa40e6cf20f..85f5f9bd9420f263a0d3874bf991cd2ae95c7ed1 100644 (file)
@@ -212,7 +212,7 @@ struct  sdp_t
 struct attribute_t
 {
     const char *value;
-    char name[0];
+    char name[];
 };
 
 struct sap_announce_t
@@ -481,6 +481,7 @@ static void Run( services_discovery_t *p_sd )
     char *psz_addr;
     int i;
     int timeout = -1;
+    int canc = vlc_savecancel ();
 
     /* Braindead Winsock DNS resolver will get stuck over 2 seconds per failed
      * DNS queries, even if the DNS server returns an error with milliseconds.
@@ -556,13 +557,12 @@ static void Run( services_discovery_t *p_sd )
         return;
     }
 
-    vlc_object_lock( p_sd );
-
     /* read SAP packets */
-    while( vlc_object_alive( p_sd ) )
+    for (;;)
     {
+        vlc_restorecancel (canc);
         unsigned n = p_sd->p_sys->i_fd;
-        struct pollfd ufd[n+1];
+        struct pollfd ufd[n];
 
         for (unsigned i = 0; i < n; i++)
         {
@@ -571,23 +571,9 @@ static void Run( services_discovery_t *p_sd )
             ufd[i].revents = 0;
         }
 
-        /* Make sure we track vlc_object_signal() */
-        ufd[n].fd = vlc_object_waitpipe( p_sd );
-        ufd[n].events = POLLIN | POLLHUP;
-        ufd[n].revents = 0;
-
-        if( ufd[n].fd == -1 )
-        {
-            /* On windows, fd will be -1, as we can't select on a pipe()-ed
-             * fildes. Because we have no other solution to track that
-             * object is killed, we make sure the timeout won't be to long. */
-            if( timeout > 1000 || timeout == -1 )
-                timeout = 1000;
-        }
-
-        vlc_object_unlock( p_sd );
-
-        if (poll (ufd, n+1, timeout) > 0)
+        int val = poll (ufd, n, timeout);
+        canc = vlc_savecancel ();
+        if (val > 0)
         {
             for (unsigned i = 0; i < n; i++)
             {
@@ -644,10 +630,7 @@ static void Run( services_discovery_t *p_sd )
             timeout = -1; /* We can safely poll indefinitly. */
         else if( timeout < 200 )
             timeout = 200; /* Don't wakeup too fast. */
-
-        vlc_object_lock( p_sd );
     }
-    vlc_object_unlock( p_sd );
 }
 
 /**********************************************************************
@@ -836,8 +819,9 @@ static int ParseSAP( services_discovery_t *p_sd, const uint8_t *buf,
                     p_announce->i_period_trust++;
 
                 /* Compute the average period */
-                p_announce->i_period = (p_announce->i_period + (mdate() - p_announce->i_last)) / 2;
-                p_announce->i_last = mdate();
+                mtime_t now = mdate();
+                p_announce->i_period = (p_announce->i_period + (now - p_announce->i_last)) / 2;
+                p_announce->i_last = now;
             }
             FreeSDP( p_sdp ); p_sdp = NULL;
             return VLC_SUCCESS;
@@ -870,7 +854,7 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash,
     p_sap->p_sdp = p_sdp;
 
     /* Released in RemoveAnnounce */
-    p_input = input_ItemNewWithType( VLC_OBJECT(p_sd),
+    p_input = input_item_NewWithType( VLC_OBJECT(p_sd),
                                      p_sap->p_sdp->psz_uri,
                                      p_sdp->psz_sessionname,
                                      0, NULL, -1, ITEM_TYPE_NET );
@@ -882,16 +866,16 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash,
     }
 
     if( p_sys->b_timeshift )
-        input_ItemAddOption( p_input, ":access-filter=timeshift" );
+        input_item_AddOption( p_input, ":access-filter=timeshift" );
 
     psz_value = GetAttribute( p_sap->p_sdp->pp_attributes, p_sap->p_sdp->i_attributes, "tool" );
     if( psz_value != NULL )
     {
-        input_ItemAddInfo( p_input, _("Session"), _("Tool"), "%s", psz_value );
+        input_item_AddInfo( p_input, _("Session"), _("Tool"), "%s", psz_value );
     }
     if( strcmp( p_sdp->username, "-" ) )
     {
-        input_ItemAddInfo( p_input, _("Session"), _("User"), "%s",
+        input_item_AddInfo( p_input, _("Session"), _("User"), "%s",
                            p_sdp->username );
     }