1 /*****************************************************************************
2 * sap.c : SAP interface module
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
32 #include <vlc/input.h>
36 #include <errno.h> /* ENOMEM */
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
49 /************************************************************************
50 * Macros and definitions
51 ************************************************************************/
53 #define MAX_LINE_LENGTH 256
55 /* SAP is always on that port */
57 #define SAP_V4_ADDRESS "224.2.127.254"
60 #define IPV6_ADDR_1 "FF0" /* Scope is inserted between them */
61 #define IPV6_ADDR_2 "::2:7FFE"
64 /*****************************************************************************
66 *****************************************************************************/
67 #define SAP_ADDR_TEXT N_( "SAP multicast address" )
68 #define SAP_ADDR_LONGTEXT N_( "SAP multicast address" )
69 #define SAP_IPV4_TEXT N_( "IPv4-SAP listening" )
70 #define SAP_IPV4_LONGTEXT N_( \
71 "Set this if you want the SAP module to listen to IPv4 announces" )
72 #define SAP_IPV6_TEXT N_( "IPv6-SAP listening" )
73 #define SAP_IPV6_LONGTEXT N_( \
74 "Set this if you want the SAP module to listen to IPv6 announces" )
75 #define SAP_SCOPE_TEXT N_( "IPv6 SAP scope" )
76 #define SAP_SCOPE_LONGTEXT N_( \
77 "Sets the scope for IPv6 announces (default is 8)" )
78 #define SAP_TIMEOUT_TEXT N_( "SAP timeout (seconds)" )
79 #define SAP_TIMEOUT_LONGTEXT N_( \
80 "Sets the time before SAP items get deleted if no new announce " \
82 #define SAP_PARSE_TEXT N_( "Try to parse the SAP" )
83 #define SAP_PARSE_LONGTEXT N_( \
84 "When SAP can it will try to parse the SAP. If you don't select " \
85 "this, all announces will be parsed by the livedotcom module" )
88 static int Open ( vlc_object_t * );
89 static void Close( vlc_object_t * );
90 static int OpenDemux ( vlc_object_t * );
91 static void CloseDemux ( vlc_object_t * );
94 set_description( _("SAP interface") );
96 add_string( "sap-addr", NULL, NULL,
97 SAP_ADDR_TEXT, SAP_ADDR_LONGTEXT, VLC_TRUE );
98 add_bool( "sap-ipv4", 1 , NULL,
99 SAP_IPV4_TEXT,SAP_IPV4_LONGTEXT, VLC_TRUE );
100 add_bool( "sap-ipv6", 0 , NULL,
101 SAP_IPV6_TEXT, SAP_IPV6_LONGTEXT, VLC_TRUE );
102 add_string( "sap-ipv6-scope", "8" , NULL,
103 SAP_SCOPE_TEXT, SAP_SCOPE_LONGTEXT, VLC_TRUE);
104 add_integer( "sap-timeout", 1800, NULL,
105 SAP_TIMEOUT_TEXT, SAP_TIMEOUT_LONGTEXT, VLC_TRUE );
106 add_bool( "sap-parse", 1 , NULL,
107 SAP_PARSE_TEXT,SAP_PARSE_LONGTEXT, VLC_TRUE );
109 set_capability( "interface", 0 );
110 set_callbacks( Open, Close );
113 set_description( _("SDP file parser for UDP") );
114 add_shortcut( "sdp" );
115 set_capability( "demux2", 51 );
116 set_callbacks( OpenDemux, CloseDemux );
120 /*****************************************************************************
122 *****************************************************************************/
124 typedef struct sdp_t sdp_t;
125 typedef struct attribute_t attribute_t;
126 typedef struct sap_announce_t sap_announce_t;
128 /* The structure that contains sdp information */
134 char *psz_sessionname;
136 /* Raw m= and c= fields */
137 char *psz_connection;
143 int i_in; /* IP version */
148 attribute_t **pp_attributes;
157 struct sap_announce_t
162 uint32_t i_source[4];
164 /* SAP annnounces must only contain one SDP */
167 playlist_item_t *p_item;
172 /* Socket descriptors */
177 playlist_item_t *p_node;
179 /* Table of announces */
181 struct sap_announce_t **pp_announces;
190 /*****************************************************************************
192 *****************************************************************************/
196 static int Demux( demux_t *p_demux );
197 static int Control( demux_t *, int, va_list );
198 static void Run ( intf_thread_t *p_intf );
200 /* Main parsing functions */
201 static int ParseConnection( vlc_object_t *p_obj, sdp_t *p_sdp );
202 static int ParseSAP( intf_thread_t *p_intf, uint8_t *p_buffer, int i_read );
203 static sdp_t * ParseSDP( vlc_object_t *p_intf, char* psz_sdp );
204 static sap_announce_t *CreateAnnounce( intf_thread_t *, uint16_t, sdp_t * );
207 static void CacheLoad( intf_thread_t *p_intf );
208 static void CacheSave( intf_thread_t *p_intf );
209 /* Helper functions */
210 static char *GetAttribute( sdp_t *p_sdp, const char *psz_search );
211 static int InitSocket( intf_thread_t *p_intf, char *psz_address, int i_port );
213 static int Decompress( unsigned char *psz_src, unsigned char **_dst, int i_len );
214 static void FreeSDP( sdp_t *p_sdp );
217 /* Detect multicast addresses */
218 static int ismult( char * );
221 if( p ) { free( p ); (p) = NULL; }
222 /*****************************************************************************
223 * Open: initialize and create stuff
224 *****************************************************************************/
225 static int Open( vlc_object_t *p_this )
227 intf_thread_t *p_intf = ( intf_thread_t* )p_this;
228 intf_sys_t *p_sys = malloc( sizeof( intf_sys_t ) );
230 playlist_t *p_playlist;
231 playlist_view_t *p_view;
233 p_sys->i_timeout = config_GetInt( p_intf,"sap-timeout" );
236 p_intf->pf_run = Run;
237 p_intf->p_sys = p_sys;
243 p_sys->b_strict = VLC_FALSE;
245 if( config_GetInt( p_intf, "sap-use-cache" ) )
250 if( config_GetInt( p_intf, "sap-ipv4" ) )
252 InitSocket( p_intf, SAP_V4_ADDRESS, SAP_PORT );
254 if( config_GetInt( p_intf, "sap-ipv6" ) )
259 /* TODO : Handle additionnal adresses */
261 if( p_sys->i_fd == 0 )
263 msg_Err( p_intf, "unable to read on any address");
267 /* Create our playlist node */
268 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
272 msg_Warn( p_intf, "unable to find playlist, cancelling SAP listening");
276 p_view = playlist_ViewFind( p_playlist, VIEW_CATEGORY );
277 p_sys->p_node = playlist_NodeCreate( p_playlist, VIEW_CATEGORY,
278 _("SAP"), p_view->p_root );
280 vlc_object_release( p_playlist );
282 p_sys->i_announces = 0;
283 p_sys->pp_announces = NULL;
288 /*****************************************************************************
289 * OpenDemux: initialize and create stuff
290 *****************************************************************************/
291 static int OpenDemux( vlc_object_t *p_this )
293 demux_t *p_demux = (demux_t *)p_this;
299 if( stream_Peek( p_demux->s, &p_peek, 7 ) < 7 )
301 msg_Err( p_demux, "cannot peek" );
304 if( strncmp( (char*)p_peek, "v=0\r\n", 5 ) &&
305 strncmp( (char*)p_peek, "v=0\n", 4 ) &&
306 ( p_peek[0] < 'a' || p_peek[0] > 'z' || p_peek[1] != '=' ) )
308 msg_Warn( p_demux, "SDP (UDP) module discarded" );
313 p_demux->pf_control = Control;
314 p_demux->pf_demux = Demux;
319 /*****************************************************************************
321 *****************************************************************************/
322 static void Close( vlc_object_t *p_this )
324 intf_thread_t *p_intf = ( intf_thread_t* )p_this;
325 intf_sys_t *p_sys = p_intf->p_sys;
328 for( i = p_sys->i_fd-1 ; i >= 0 ; i-- )
330 net_Close( p_sys->pi_fd[i] );
333 if( config_GetInt( p_intf, "sap-use-cache" ) )
338 for( i = p_sys->i_announces - 1; i>= 0; i-- )
340 RemoveAnnounce( p_intf, p_sys->pp_announces[i] );
346 /*****************************************************************************
347 * CloseDemux: Close the demuxer
348 *****************************************************************************/
349 static void CloseDemux( vlc_object_t *p_this )
354 /*****************************************************************************
355 * Run: main SAP thread
356 *****************************************************************************
357 * Listens to SAP packets, and sends them to packet_handle
358 *****************************************************************************/
359 #define MAX_SAP_BUFFER 5000
361 static void Run( intf_thread_t *p_intf )
364 /* Dirty hack to slow down the startup of the sap interface */
365 /* Unneeded now : our node is in no_select mode */
368 /* read SAP packets */
369 while( !p_intf->b_die )
371 p_buffer = (uint8_t *)malloc( MAX_SAP_BUFFER );
375 msg_Err( p_intf, "out of memory");
376 p_intf->b_die = VLC_TRUE;
380 int i_read = net_Select( p_intf, p_intf->p_sys->pi_fd, NULL,
381 p_intf->p_sys->i_fd, p_buffer,
382 MAX_SAP_BUFFER, 500000 );
384 /* Check for items that need deletion */
385 for( i = 0 ; i< p_intf->p_sys->i_announces ; i++ )
387 struct sap_announce_t *p_announce;
388 mtime_t i_timeout = ( mtime_t ) 1000000*p_sys->i_timeout;
389 if( mdate() - p_intf->p_sys->pp_announces[i]->i_last > i_timeout )
391 msg_Dbg( p_intf,"Time out for %s, deleting (%i/%i)",
392 p_intf->p_sys->pp_announces[i]->psz_name,
393 i , p_intf->p_sys->i_announces );
395 /* Remove the playlist item */
396 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
400 int i_pos = playlist_GetPositionById( p_playlist,
401 p_intf->p_sys->pp_announces[i]->i_id );
402 playlist_Delete( p_playlist, i_pos );
403 vlc_object_release( p_playlist );
406 /* Free the p_announce */
407 p_announce = p_intf->p_sys->pp_announces[i];
408 if( p_announce->psz_name )
409 free( p_announce->psz_name );
410 if( p_announce->psz_uri )
411 free( p_announce->psz_uri );
413 /* Remove the sap_announce from the array */
414 REMOVE_ELEM( p_intf->p_sys->pp_announces,
415 p_intf->p_sys->i_announces,
424 /* Minimum length is > 6 */
429 msg_Warn( p_intf, "socket read error" );
434 p_buffer[i_read] = '\0';
436 /* Parse the packet */
437 ParseSAP( p_intf, p_buffer, i_read );
443 /**********************************************************************
444 * Demux: reads and demuxes data packets
445 * Return -1 if error, 0 if EOF, 1 else
446 **********************************************************************/
447 static int Demux( demux_t *p_demux )
449 int i_max_sdp = 1024;
451 char *psz_sdp = (char *)malloc( i_max_sdp );
454 playlist_t *p_playlist;
456 /* Gather the complete sdp file */
459 int i_read = stream_Read( p_demux->s,
460 &psz_sdp[i_sdp], i_max_sdp - i_sdp - 1 );
466 msg_Err( p_demux, "failed to read SDP" );
472 if( i_read < i_max_sdp - i_sdp - 1 )
474 psz_sdp[i_sdp] = '\0';
479 psz_sdp = (uint8_t*)realloc( psz_sdp, i_max_sdp );
482 p_sdp = ParseSDP( VLC_OBJECT(p_demux), psz_sdp );
484 if( !p_sdp ) return -1;
486 if( p_sdp->i_media > 1 )
491 if( ParseConnection( VLC_OBJECT( p_demux ), p_sdp ) )
493 p_sdp->psz_uri = NULL;
496 if( p_sdp->psz_uri == NULL ) return VLC_EGENERIC;
498 p_playlist = (playlist_t *)vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST,
501 p_playlist->status.p_item->i_flags |= PLAYLIST_DEL_FLAG;
503 playlist_Add( p_playlist, p_sdp->psz_uri, p_sdp->psz_sessionname,
504 PLAYLIST_APPEND, PLAYLIST_END );
506 vlc_object_release( p_playlist );
514 static int Control( demux_t *p_demux, int i_query, va_list args )
519 /**************************************************************
521 **************************************************************/
523 static int ParseSAP( intf_thread_t *p_intf, uint8_t *p_buffer, int i_read )
525 int i_version, i_address_type, i_hash, i;
528 vlc_bool_t b_compressed;
529 vlc_bool_t b_need_delete = VLC_FALSE;
531 int i_decompressed_size;
532 uint8_t *p_decompressed_buffer;
535 /* First, check the sap announce is correct */
536 i_version = p_buffer[0] >> 5;
540 msg_Dbg( p_intf, "strange sap version %d found", i_version );
543 i_address_type = p_buffer[0] & 0x10;
545 if( (p_buffer[0] & 0x08) != 0 )
547 msg_Dbg( p_intf, "reserved bit incorrectly set" );
551 if( (p_buffer[0] & 0x04) != 0 )
553 msg_Dbg( p_intf, "session deletion packet" );
554 b_need_delete = VLC_TRUE;
557 if( p_buffer[0] & 0x02 )
559 msg_Dbg( p_intf, "encrypted packet, unsupported" );
563 b_compressed = p_buffer[0] & 0x01;
565 i_hash = ( p_buffer[2] << 8 ) + p_buffer[3];
567 if( p_intf->p_sys->b_strict && i_hash == 0 )
569 msg_Dbg( p_intf, "strict mode, discarding announce with null id hash");
573 psz_sdp = &p_buffer[4];
575 if( i_address_type == 0 ) /* ipv4 source address */
579 else /* ipv6 source address */
587 i_decompressed_size = Decompress( psz_sdp,
588 &p_decompressed_buffer,i_read - ( psz_sdp - p_buffer ) );
589 if( i_decompressed_size > 0 && i_decompressed_size < MAX_SAP_BUFFER )
591 memcpy( psz_sdp, p_decompressed_buffer, i_decompressed_size );
592 psz_sdp[i_decompressed_size] = '\0';
593 free( p_decompressed_buffer );
596 msg_Warn( p_intf, "Ignoring compressed sap packet" );
601 /* Add the size of authentification info */
602 psz_sdp += p_buffer[1];
604 /* Skip payload type */
605 /* Handle announces without \0 between SAP and SDP */
606 while( *psz_sdp != '\0' && ( psz_sdp[0] != 'v' && psz_sdp[1] != '=' ) )
611 if( *psz_sdp == '\0' )
617 p_sdp = ParseSDP( VLC_OBJECT(p_intf), psz_sdp );
624 /* Decide whether we should add a playlist item for this SDP */
626 /* Multi-media or no-parse -> pass to LIVE.COM */
627 if( p_sdp->i_media > 1 || p_intf->p_sys->b_parse == VLC_FALSE )
629 asprintf( &p_sdp->psz_uri, "sdp://%s", p_sdp->psz_sdp );
633 /* Parse connection information (c= & m= ) */
634 if( ParseConnection( VLC_OBJECT(p_intf), p_sdp ) )
636 p_sdp->psz_uri = NULL;
640 if( p_sdp->psz_uri == NULL ) return VLC_EGENERIC;
642 for( i = 0 ; i< p_intf->p_sys->i_announces ; i++ )
645 /* FIXME: we create a new announce each time the sdp changes */
646 if( !strcmp( p_intf->p_sys->pp_announces[i]->p_sdp->psz_sdp,
651 RemoveAnnounce( p_intf, p_intf->p_sys->pp_announces[i]);
656 p_intf->p_sys->pp_announces[i]->i_last = mdate();
663 if( p_sdp->i_media > 1 )
665 msg_Dbg( p_intf, "passing to LIVE.COM" );
668 CreateAnnounce( p_intf, i_hash, p_sdp );
673 sap_announce_t *CreateAnnounce( intf_thread_t *p_intf, uint16_t i_hash,
676 playlist_t *p_playlist;
677 playlist_item_t *p_item, *p_child;
679 sap_announce_t *p_sap = (sap_announce_t *)malloc(
680 sizeof(sap_announce_t ) );
683 msg_Err( p_intf, "out of memory");
684 p_intf->b_die = VLC_TRUE;
687 p_sap->i_last = mdate();
688 p_sap->i_hash = i_hash;
689 p_sap->p_sdp = p_sdp;
690 p_sap->p_item = NULL;
692 /* Create the playlist item here */
693 p_item = playlist_ItemNew( p_intf, p_sap->p_sdp->psz_uri,
694 p_sap->p_sdp->psz_sessionname );
701 psz_value = GetAttribute( p_sap->p_sdp, "x-plgroup" );
703 if( psz_value == NULL )
705 psz_value = GetAttribute( p_sap->p_sdp, "plgroup" );
708 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
712 msg_Err( p_intf, "playlist not found" );
718 if( psz_value != NULL )
720 p_child = playlist_ChildSearchName( p_intf->p_sys->p_node, psz_value );
722 if( p_child == NULL )
724 p_child = playlist_NodeCreate( p_playlist, VIEW_CATEGORY,
725 psz_value, p_intf->p_sys->p_node );
730 p_child = p_intf->p_sys->p_node;
733 p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
735 playlist_NodeAddItem( p_playlist, p_item, VIEW_CATEGORY, p_child,
736 PLAYLIST_APPEND, PLAYLIST_END );
738 vlc_object_release( p_playlist );
740 p_sap->p_item = p_item;
742 TAB_APPEND( p_intf->p_sys->i_announces,
743 p_intf->p_sys->pp_announces,
749 static char *GetAttribute( sdp_t *p_sdp, const char *psz_search )
753 for( i = 0 ; i< p_sdp->i_attributes; i++ )
755 if( !strncmp( p_sdp->pp_attributes[i]->psz_field, psz_search,
756 strlen( p_sdp->pp_attributes[i]->psz_field ) ) )
758 return p_sdp->pp_attributes[i]->psz_value;
765 /* Fill p_sdp->psz_uri */
766 static int ParseConnection( vlc_object_t *p_obj, sdp_t *p_sdp )
770 char *psz_uri = NULL;
771 char *psz_proto = NULL;
775 if( p_sdp->psz_connection )
777 psz_parse = p_sdp->psz_connection;
779 psz_eof = strchr( psz_parse, ' ' );
784 psz_parse = psz_eof + 1;
788 msg_Warn( p_obj, "unable to parse c field (1)");
792 psz_eof = strchr( psz_parse, ' ' );
797 if( !strncmp( psz_parse, "IP4", 3 ) )
801 else if( !strncmp( psz_parse, "IP6", 3 ) )
809 psz_parse = psz_eof + 1;
813 msg_Warn( p_obj, "unable to parse c field (2)");
817 psz_eof = strchr( psz_parse, '/' );
822 psz_uri = strdup( psz_parse );
827 msg_Warn( p_obj, "unable to parse c field (3)");
834 if( p_sdp->psz_media )
836 psz_parse = p_sdp->psz_media;
838 psz_eof = strchr( psz_parse, ' ' );
844 if( strncmp( psz_parse, "audio", 5 ) &&
845 strncmp( psz_parse, "video",5 ) )
847 msg_Warn( p_obj, "unhandled media type -%s-", psz_parse );
851 psz_parse = psz_eof + 1;
855 msg_Warn( p_obj, "unable to parse m field (1)");
859 psz_eof = strchr( psz_parse, ' ' );
865 /* FIXME : multiple port ! */
866 i_port = atoi( psz_parse );
868 if( i_port <= 0 || i_port >= 65536 )
870 msg_Warn( p_obj, "invalid transport port %i", i_port );
873 psz_parse = psz_eof + 1;
877 msg_Warn( p_obj, "unable to parse m field (2)");
881 psz_eof = strchr( psz_parse, ' ' );
887 psz_proto = strdup( psz_parse );
891 msg_Warn( p_obj, "unable to parse m field (3)");
896 /* FIXME: HTTP support */
903 if( ismult( psz_uri ) )
905 asprintf( &p_sdp->psz_uri, "%s://@%s:%i", psz_proto, psz_uri, i_port );
909 asprintf( &p_sdp->psz_uri, "%s://%s:%i", psz_proto, psz_uri, i_port );
916 /***********************************************************************
917 * ParseSDP : SDP parsing
918 * *********************************************************************
919 * Validate SDP and parse all fields
920 ***********************************************************************/
921 static sdp_t * ParseSDP( vlc_object_t *p_obj, char* psz_sdp )
925 if( psz_sdp[0] != 'v' || psz_sdp[1] != '=' )
927 msg_Warn( p_obj, "bad SDP packet" );
931 p_sdp = (sdp_t *)malloc( sizeof( sdp_t ) );
933 p_sdp->psz_sdp = strdup( psz_sdp );
935 p_sdp->psz_sessionname = NULL;
936 p_sdp->psz_media = NULL;
937 p_sdp->psz_connection = NULL;
940 p_sdp->i_attributes = 0;
941 p_sdp->pp_attributes = NULL;
943 while( *psz_sdp != '\0' )
946 while( *psz_sdp == '\r' || *psz_sdp == '\n' || *psz_sdp == ' ' || *psz_sdp == '\t' )
951 if( ( psz_eol = strchr( psz_sdp, '\n' ) ) == NULL )
953 psz_eol = psz_sdp + strlen( psz_sdp );
955 if( psz_eol > psz_sdp && *( psz_eol - 1 ) == '\r' )
960 if( psz_eol <= psz_sdp )
966 /* no space allowed between fields */
967 if( psz_sdp[1] != '=' )
969 msg_Warn( p_obj, "invalid packet" ) ;
974 /* Now parse each line */
980 p_sdp->psz_sessionname = strdup( &psz_sdp[2] );
990 case( 'a' ): /* attribute */
992 char *psz_eon = strchr( &psz_sdp[2], ':' );
994 attribute_t *p_attr = (attribute_t *)malloc(
995 sizeof( attribute_t ) );
997 /* Attribute with value */
1002 p_attr->psz_field = strdup( &psz_sdp[2] );
1003 p_attr->psz_value = strdup( psz_eon );
1005 else /* Attribute without value */
1007 p_attr->psz_field = strdup( &psz_sdp[2] );
1008 p_attr->psz_value = NULL;
1011 TAB_APPEND( p_sdp->i_attributes, p_sdp->pp_attributes, p_attr );
1015 case( 'm' ): /* Media announcement */
1017 /* If we have several medias, we pass the announcement to
1018 * LIVE.COM, so just count them */
1020 if( p_sdp->i_media == 1 )
1022 p_sdp->psz_media = strdup( &psz_sdp[2] );
1029 if( p_sdp->i_media > 1 )
1032 p_sdp->psz_connection = strdup( &psz_sdp[2] );
1047 /***********************************************************************
1048 * ismult: returns true if we have a multicast address
1049 ***********************************************************************/
1051 static int ismult( char *psz_uri )
1056 i_value = strtol( psz_uri, &psz_end, 0 );
1059 if( psz_uri[0] == '[')
1061 if( strncasecmp( &psz_uri[1], "FF0" , 3) ||
1062 strncasecmp( &psz_uri[2], "FF0" , 3))
1065 return( VLC_FALSE );
1068 if( *psz_end != '.' ) { return( VLC_FALSE ); }
1070 return( i_value < 224 ? VLC_FALSE : VLC_TRUE );
1073 static int InitSocket( intf_thread_t *p_intf, char *psz_address, int i_port )
1075 int i_fd = net_OpenUDP( p_intf, psz_address, i_port, "", 0 );
1079 INSERT_ELEM( p_intf->p_sys->pi_fd,
1080 p_intf->p_sys->i_fd,
1081 p_intf->p_sys->i_fd,
1086 return VLC_EGENERIC;
1090 static int Decompress( unsigned char *psz_src, unsigned char **_dst, int i_len )
1092 int i_result, i_dstsize, n;
1093 unsigned char *psz_dst;
1096 d_stream.zalloc = (alloc_func)0;
1097 d_stream.zfree = (free_func)0;
1098 d_stream.opaque = (voidpf)0;
1100 i_result = inflateInit(&d_stream);
1101 if( i_result != Z_OK )
1103 printf( "inflateInit() failed. Result: %d\n", i_result );
1107 p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
1108 i_position = p_playlist->i_index;
1110 /* Gather the complete sdp file */
1113 int i_read = stream_Read( p_demux->s, &p_sdp[i_sdp], i_sdp_max - i_sdp - 1 );
1115 d_stream.next_in = (Bytef *)psz_src;
1116 d_stream.avail_in = i_len;
1124 psz_dst = (unsigned char *)realloc( psz_dst, n * 1000 );
1125 d_stream.next_out = (Bytef *)&psz_dst[(n - 1) * 1000];
1126 d_stream.avail_out = 1000;
1128 i_result = inflate(&d_stream, Z_NO_FLUSH);
1129 if( ( i_result != Z_OK ) && ( i_result != Z_STREAM_END ) )
1131 printf( "Zlib decompression failed. Result: %d\n", i_result );
1135 while( ( d_stream.avail_out == 0 ) && ( d_stream.avail_in != 0 ) &&
1136 ( i_result != Z_STREAM_END ) );
1138 i_dstsize = d_stream.total_out;
1139 inflateEnd( &d_stream );
1141 *_dst = (unsigned char *)realloc( psz_dst, i_dstsize );
1148 static void FreeSDP( sdp_t *p_sdp )
1151 FREE( p_sdp->psz_sdp );
1152 FREE( p_sdp->psz_sessionname );
1153 FREE( p_sdp->psz_connection );
1154 FREE( p_sdp->psz_media );
1155 FREE( p_sdp->psz_uri );
1156 for( i= 0 ; i< p_sdp->i_attributes; i++ )
1158 FREE( p_sdp->pp_attributes[i] );
1163 static int RemoveAnnounce( intf_thread_t *p_intf, sap_announce_t *p_announce )
1165 msg_Err( p_intf, "remove not implemented");
1170 static void CacheLoad( intf_thread_t *p_intf )
1172 msg_Warn( p_intf, "Cache not implemented") ;
1174 static void CacheSave( intf_thread_t *p_intf )
1176 msg_Warn( p_intf, "Cache not implemented") ;