Changeset 0697a96a2cc92d600a66b34f5e1c28e0dbe80c36

Show
Ignore:
Timestamp:
05/01/04 13:59:54 (5 years ago)
Author:
Clément Stenac <zorglub@videolan.org>
git-committer:
Clément Stenac <zorglub@videolan.org> 1073307594 +0000
git-parent:

[17557ea64382428560a75ecef753e88f39158834]

git-author:
Clément Stenac <zorglub@videolan.org> 1073307594 +0000
Message:

* modules/misc/sap.c :

  • Use the new playlist API
  • Track title changes
  • Timeout. Delete an item if we haven't heard about it for too long.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/misc/sap.c

    r0f03eb9 r0697a96  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001 VideoLAN 
    5  * $Id: sap.c,v 1.43 2003/12/12 15:37:23 zorglub Exp $ 
     5 * $Id: sap.c,v 1.44 2004/01/05 12:59:54 zorglub Exp $ 
    66 * 
    77 * Authors: Arnaud Schauly <gitan@via.ecp.fr> 
     
    167167struct sap_announce_t 
    168168{ 
     169    mtime_t i_last; 
     170    int i_id; 
    169171    char *psz_name; 
    170172    char *psz_uri; 
     
    280282            psz_scope = strdup( "8" ); 
    281283        } 
    282         snprintf( psz_address, 100, "[%s%c%s]",IPV6_ADDR_1, psz_scope[0], IPV6_ADDR_2 ); 
     284        snprintf( psz_address, 100, "[%s%c%s]",IPV6_ADDR_1, 
     285                  psz_scope[0], IPV6_ADDR_2 ); 
    283286        free( psz_scope ); 
    284287 
     
    374377    while( !p_intf->b_die ) 
    375378    { 
     379        playlist_t *p_playlist= NULL; 
     380        int i; 
    376381        int i_read = NetRead( p_intf, p_sys->fd, buffer, MAX_SAP_BUFFER ); 
    377382        uint8_t *p_sdp; 
     
    384389        unsigned char *p_decompressed_buffer; 
    385390        int i_decompressed_size; 
    386          
     391 
     392        /* Check for items that need deletion */ 
     393        for( i = 0 ; i< p_intf->p_sys->i_announces ; i++ ) 
     394        { 
     395           struct sap_announce_t *p_announce; 
     396           if( mdate() - p_intf->p_sys->pp_announces[i]->i_last > 10000000 ) 
     397           { 
     398              msg_Dbg(p_intf,"Time out for %s, deleting (%i/%i)", 
     399                             p_intf->p_sys->pp_announces[i]->psz_name, 
     400                             i , p_intf->p_sys->i_announces ); 
     401 
     402              /* Remove the playlist item */ 
     403               p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 
     404                              FIND_ANYWHERE ); 
     405               if( p_playlist ) 
     406               { 
     407                   int i_pos = playlist_GetPositionById( p_playlist, 
     408                              p_intf->p_sys->pp_announces[i]->i_id ); 
     409                   playlist_Delete( p_playlist, i_pos ); 
     410               } 
     411 
     412               vlc_object_release( p_playlist ); 
     413 
     414               /* Free the p_announce */ 
     415               p_announce =  p_intf->p_sys->pp_announces[i]; 
     416               if( p_announce->psz_name ) 
     417                  free(  p_announce->psz_name ); 
     418               if( p_announce->psz_uri ) 
     419                  free(  p_announce->psz_uri ); 
     420 
     421              /* Remove the sap_announce from the array */ 
     422              REMOVE_ELEM( p_intf->p_sys->pp_announces, 
     423                           p_intf->p_sys->i_announces, 
     424                           i ); 
     425 
     426              free( p_announce ); 
     427 
     428           } 
     429        } 
     430 
    387431        /* Minimum length is > 6 */ 
    388432        if( i_read <= 6 ) 
     
    468512            msg_Warn( p_intf, "ditching sap packet" ); 
    469513        } 
     514 
    470515    } 
    471516} 
     
    588633static void sess_toitem( intf_thread_t * p_intf, sess_descr_t * p_sd ) 
    589634{ 
    590     playlist_item_t * p_item; 
    591635    struct sap_announce_t *p_announce; 
    592     char *psz_uri, *psz_proto
     636    char *psz_uri, *psz_proto, *psz_item_uri
    593637    char *psz_port; 
    594638    char *psz_uri_default; 
    595     int i_count , i
     639    int i_count , i , i_pos , i_id = 0
    596640    vlc_bool_t b_http = VLC_FALSE; 
    597641    char *psz_http_path = NULL; 
     
    601645    if( p_sd->i_media > 1 ) 
    602646    { 
    603         p_item = malloc( sizeof( playlist_item_t ) ); 
    604         if( p_item == NULL ) 
     647        psz_uri = malloc( strlen( p_sd->psz_sdp ) + 7 ); 
     648        if( psz_uri == NULL ) 
    605649        { 
    606650            msg_Warn( p_intf, "out of memory" ); 
    607651            return; 
    608652        } 
    609         p_item->psz_name    = strdup( p_sd->psz_sessionname ); 
    610         p_item->psz_uri     = NULL; 
    611         p_item->i_duration  = -1; 
    612         p_item->ppsz_options= NULL; 
    613         p_item->i_options   = 0; 
    614  
    615         p_item->i_type      = 0; 
    616         p_item->i_status    = 0; 
    617         p_item->b_autodeletion = VLC_FALSE; 
    618         p_item->b_enabled   = VLC_TRUE; 
    619         p_item->i_group     = p_intf->p_sys->i_group; 
    620         p_item->psz_author  = strdup( "" ); 
    621         psz_uri = malloc( strlen( p_sd->psz_sdp ) + 7 ); 
    622         if( psz_uri == NULL ) 
    623         { 
    624             msg_Warn( p_intf, "out of memory" ); 
    625             free( p_item->psz_name ); 
    626             free( p_item->psz_author ); 
    627             free( p_item ); 
    628             return; 
    629         } 
    630         p_item->psz_uri = psz_uri; 
    631653        memcpy( psz_uri, "sdp://", 6 ); 
    632654        psz_uri += 6; 
    633655        memcpy( psz_uri, p_sd->psz_sdp, strlen( p_sd->psz_sdp ) + 1 ); 
    634         /* Enqueueing p_item in the playlist */ 
    635  
     656 
     657        /* Check if we have already added the item */ 
    636658        for( i = 0 ; i< p_intf->p_sys->i_announces ; i++ ) 
    637659        { 
    638660            if( !strcmp(p_intf->p_sys->pp_announces[i]->psz_uri, 
    639                         p_item->psz_uri ) ) 
    640             { 
    641                 return; 
    642             } 
    643         } 
    644         p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); 
    645         playlist_AddItem ( p_playlist, p_item, PLAYLIST_CHECK_INSERT, PLAYLIST_END ); 
    646         vlc_object_release( p_playlist ); 
     661                        psz_uri ) ) 
     662            { 
     663                    return; 
     664            } 
     665        } 
     666        /* Add it to the playlist */ 
     667        p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 
     668                                      FIND_ANYWHERE ); 
     669        i_id = playlist_Add( p_playlist, psz_uri, p_sd->psz_sessionname , 
     670                      PLAYLIST_CHECK_INSERT, PLAYLIST_END ); 
     671 
     672        i_pos = playlist_GetPositionById( p_playlist, i_id ); 
     673        playlist_SetGroup( p_playlist, i_pos, p_intf->p_sys->i_group ); 
     674 
     675        /* Remember it */ 
    647676        p_announce = (struct sap_announce_t *)malloc( 
    648677                      sizeof(struct sap_announce_t) ); 
    649         if( p_item->psz_name ) 
    650         { 
    651             p_announce->psz_name = strdup( p_item->psz_name ); 
     678        if( p_sd->psz_sessionname ) 
     679        { 
     680            p_announce->psz_name = strdup( p_sd->psz_sessionname ); 
    652681        } 
    653682        else 
     
    655684            p_announce->psz_name = strdup( "" ); 
    656685        } 
    657         if( p_item->psz_uri ) 
    658         { 
    659             p_announce->psz_uri  = strdup( p_item->psz_uri ); 
     686        if( psz_uri ) 
     687        { 
     688            p_announce->psz_uri  = strdup( psz_uri ); 
    660689        } 
    661690        else 
     
    663692            p_announce->psz_uri = strdup( "" ); 
    664693        } 
     694        p_announce->i_id = i_id; 
    665695 
    666696        INSERT_ELEM( p_intf->p_sys->pp_announces, 
     
    668698                     p_intf->p_sys->i_announces, 
    669699                     p_announce ); 
     700 
     701        vlc_object_release( p_playlist ); 
    670702        return; 
    671703    } 
     
    675707    for( i_count = 0 ; i_count < p_sd->i_media ; i_count++ ) 
    676708    { 
    677         p_item = malloc( sizeof( playlist_item_t ) ); 
    678         p_item->psz_name    = strdup( p_sd->psz_sessionname ); 
    679         p_item->psz_uri     = NULL; 
    680         p_item->i_duration  = -1; 
    681         p_item->ppsz_options= NULL; 
    682         p_item->i_options   = 0; 
    683  
    684         p_item->i_type      = 0; 
    685         p_item->i_status    = 0; 
    686         p_item->b_autodeletion = VLC_FALSE; 
    687         p_item->b_enabled   = VLC_TRUE; 
    688         p_item->i_group     = p_intf->p_sys->i_group; 
    689         p_item->psz_author  = strdup( "" ); 
    690  
    691         psz_uri = NULL; 
    692  
    693         /* Build what we have to put in p_item->psz_uri, with the m and 
    694          *  c fields  */ 
     709        int i_group = p_intf->p_sys->i_group; 
     710 
     711        /* Build what we have to put in psz_item_uri, with the m and 
     712         * c fields  */ 
    695713 
    696714        if( !p_sd->pp_media[i_count] ) 
     
    735753            if(!strcasecmp( p_sd->pp_attributes[i]->psz_field , "plgroup")) 
    736754            { 
    737                 int i_id; 
     755                int i_group_id; 
    738756                p_playlist = 
    739757                (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 
     
    744762                } 
    745763 
    746                 i_id = playlist_GroupToId( p_playlist, 
    747                                            p_sd->pp_attributes[i]->psz_value); 
    748                 if( i_id != 0 ) 
     764                i_group_id = playlist_GroupToId( p_playlist, 
     765                                 p_sd->pp_attributes[i]->psz_value); 
     766                if( i_group_id != 0 ) 
    749767                { 
    750                     p_item->i_group = i_id; 
     768                    i_group = i_group_id; 
    751769                } 
    752770                else 
     
    755773                            playlist_CreateGroup( p_playlist, 
    756774                                       p_sd->pp_attributes[i]->psz_value); 
    757                     p_item->i_group = p_group->i_id; 
     775                    i_group = p_group->i_id; 
    758776                } 
    759777                vlc_object_release( p_playlist ); 
     
    761779        } 
    762780 
    763         /* Filling p_item->psz_uri */ 
     781        /* Filling psz_uri */ 
    764782        if( b_http == VLC_FALSE ) 
    765783        { 
    766             p_item->psz_uri = malloc( strlen( psz_proto ) + strlen( psz_uri ) + 
    767                                       strlen( psz_port ) + 7 ); 
     784            psz_item_uri = malloc( strlen( psz_proto ) + strlen( psz_uri ) + 
     785                                 strlen( psz_port ) + 7 ); 
    768786            if( ismult( psz_uri ) ) 
    769787            { 
    770                 sprintf( p_item->psz_uri, "%s://@%s:%s", 
     788                sprintf( psz_item_uri, "%s://@%s:%s", 
    771789                         psz_proto, psz_uri, psz_port ); 
    772790            } 
    773791            else 
    774792            { 
    775                 sprintf( p_item->psz_uri, "%s://%s:%s", 
     793                sprintf( psz_item_uri, "%s://%s:%s", 
    776794                         psz_proto, psz_uri, psz_port ); 
    777795            } 
     
    784802            } 
    785803 
    786             p_item->psz_uri = malloc( strlen( psz_proto ) + strlen( psz_uri ) + 
    787                                       strlen( psz_port ) + strlen(psz_http_path) + 5 ); 
    788             sprintf( p_item->psz_uri, "%s://%s:%s%s", psz_proto, 
     804            psz_item_uri = malloc( strlen( psz_proto ) + strlen( psz_uri ) + 
     805                                   strlen( psz_port ) + strlen(psz_http_path) + 
     806                                    5 ); 
     807            sprintf( psz_item_uri, "%s://%s:%s%s", psz_proto, 
    789808                            psz_uri, psz_port,psz_http_path ); 
    790809 
     
    795814        } 
    796815 
     816        /* Check if we already know this item */ 
    797817         for( i = 0 ; i< p_intf->p_sys->i_announces ; i++ ) 
    798818         { 
    799             if( !strcmp(p_intf->p_sys->pp_announces[i]->psz_uri, 
    800                         p_item->psz_uri ) ) 
    801             { 
     819            if( !strcmp( p_intf->p_sys->pp_announces[i]->psz_uri, 
     820                         psz_item_uri ) ) 
     821            { 
     822                p_intf->p_sys->pp_announces[i]->i_last = mdate(); 
     823 
     824                /* Check if the name changed */ 
     825                if( strcmp( p_intf->p_sys->pp_announces[i]->psz_name, 
     826                             p_sd->psz_sessionname ) ) 
     827                { 
     828                    playlist_item_t *p_item; 
     829                    p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 
     830                                                  FIND_ANYWHERE ); 
     831 
     832                    msg_Dbg(p_intf, "Name changed (%s -> %s) for %s", 
     833                            p_intf->p_sys->pp_announces[i]->psz_name, 
     834                            p_sd->psz_sessionname, 
     835                            psz_item_uri ); 
     836 
     837                    p_item = playlist_GetItemById( p_playlist, 
     838                                    p_intf->p_sys->pp_announces[i]->i_id ); 
     839 
     840                    /* Change the name in the item */ 
     841                    if( p_item->psz_name ) 
     842                        free( p_item->psz_name ); 
     843                    p_item->psz_name = strdup( p_sd->psz_sessionname); 
     844 
     845                    /* Update the stored name */ 
     846                    if( p_intf->p_sys->pp_announces[i]->psz_name ) 
     847                        free( p_intf->p_sys->pp_announces[i]->psz_name ); 
     848                    p_intf->p_sys->pp_announces[i]->psz_name = 
     849                                   strdup( p_sd->psz_sessionname ); 
     850 
     851                    vlc_object_release( p_playlist ); 
     852                } 
    802853                return; 
    803854            } 
    804855        } 
    805856 
    806         /* Enqueueing p_item in the playlist */ 
     857        /* Add the item in the playlist */ 
    807858        p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 
    808859                                      FIND_ANYWHERE ); 
    809         playlist_AddItem ( p_playlist, p_item, 
    810                            PLAYLIST_CHECK_INSERT, PLAYLIST_END ); 
    811  
    812         /* Store it in the list */ 
     860        i_id = playlist_Add ( p_playlist, psz_item_uri , 
     861                               p_sd->psz_sessionname, 
     862                               PLAYLIST_CHECK_INSERT, PLAYLIST_END ); 
     863        i_pos = playlist_GetPositionById( p_playlist, i_id ); 
     864        playlist_SetGroup( p_playlist, i_pos, i_group ); 
     865 
     866        /* Then remember it */ 
    813867        p_announce = (struct sap_announce_t *)malloc( 
    814868                      sizeof(struct sap_announce_t) ); 
    815         if( p_item->psz_name ) 
    816         { 
    817             p_announce->psz_name = strdup( p_item->psz_name ); 
     869        if( p_sd->psz_sessionname ) 
     870        { 
     871            p_announce->psz_name = strdup( p_sd->psz_sessionname ); 
    818872        } 
    819873        else 
     
    821875            p_announce->psz_name = strdup( "" ); 
    822876        } 
    823         if( p_item->psz_uri ) 
    824         { 
    825             p_announce->psz_uri  = strdup( p_item->psz_uri ); 
     877        if( psz_item_uri ) 
     878        { 
     879            p_announce->psz_uri  = strdup( psz_item_uri ); 
    826880        } 
    827881        else 
     
    829883            p_announce->psz_uri = strdup( "" ); 
    830884        } 
     885        p_announce->i_id = i_id; 
     886 
     887        p_announce->i_last = mdate(); 
     888 
     889        vlc_object_release( p_playlist ); 
    831890 
    832891        INSERT_ELEM( p_intf->p_sys->pp_announces, 
     
    834893                     p_intf->p_sys->i_announces, 
    835894                     p_announce ); 
    836         vlc_object_release( p_playlist ); 
    837895    } 
    838896}