* vlc_playlist.h : Playlist functions
*****************************************************************************
* Copyright (C) 1999, 2000, 2001, 2002 VideoLAN
- * $Id: vlc_playlist.h,v 1.5 2002/11/12 21:20:36 gbazin Exp $
+ * $Id: vlc_playlist.h,v 1.6 2002/12/03 23:36:41 gitan Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
struct playlist_item_t
{
char * psz_name;
+ char * psz_uri;
int i_type; /* unused yet */
int i_status; /* unused yet */
vlc_bool_t b_autodeletion;
VLC_EXPORT( void, playlist_Command, ( playlist_t *, int, int ) );
VLC_EXPORT( int, playlist_Add, ( playlist_t *, const char *, int, int ) );
+VLC_EXPORT( int, playlist_AddItem, ( playlist_t *, playlist_item_t *, int, int ) );
VLC_EXPORT( int, playlist_Delete, ( playlist_t *, int ) );
* sap.c : SAP interface module
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: sap.c,v 1.1 2002/12/03 16:29:04 gitan Exp $
+ * $Id: sap.c,v 1.2 2002/12/03 23:36:41 gitan Exp $
*
* Authors: Arnaud Schauly <gitan@via.ecp.fr>
*
#define MAX_LINE_LENGTH 256
-#define HELLO_PORT 9875 // SAP is aloways on that port
-#define HELLO_GROUP "239.255.255.255" // FIX ME !!!!!!!!!!!!!!!
+#define HELLO_PORT 9875 /* SAP is always on that port */
+#define HELLO_GROUP "239.255.255.255"
#define ADD_SESSION 1;
/*****************************************************************************
static ssize_t NetRead ( intf_thread_t*, int , byte_t *, size_t );
typedef struct sess_descr_s {
-/* char *psz_version; // v field (protocol version) */
char *psz_origin; /* o field (username sess-id sess-version
nettype addrtype addr*/
char *psz_sessionname;
static int parse_sap ( char ** );
static int packet_handle ( char **, intf_thread_t * );
-static sess_descr_t * parse_sdp(char * psz_pct) ;
-
-
+static sess_descr_t * parse_sdp( char *,intf_thread_t * ) ;
+static playlist_item_t * sess_toitem( sess_descr_t * );
/*****************************************************************************
char *psz_addr;
char *psz_network = NULL;
struct sockaddr_in addr;
- struct ip_mreq mreq;
int fd,addrlen;
char *psz_buf;
if( i_read < 0 )
{
- msg_Err( p_intf, "argggg" );
+ msg_Err( p_intf, "Cannot read in the socket" );
}
if( i_read == 0 )
{
}
- msg_Dbg( p_intf, "New packet arrived" );
packet_handle( &psz_buf, p_intf );
}
return VLC_SUCCESS;
}
-
+/*******************************************************************
+ * sess_toitem : changes a sess_descr_t into a playlist_item_t
+ *******************************************************************/
+
+static playlist_item_t * sess_toitem( sess_descr_t * p_sd )
+{
+ playlist_item_t * p_item;
+
+ p_item = malloc( sizeof( playlist_item_t ) );
+ p_item->psz_name = p_sd->psz_sessionname;
+ p_item->psz_uri = p_sd->psz_uri;
+ p_item->i_type = 0;
+ p_item->i_status = 0;
+ p_item->b_autodeletion = VLC_FALSE;
+
+ return p_item;
+
+}
+
/********************************************************************
* parse_sap : Takes care of the SAP headers
********************************************************************
static int packet_handle( char ** ppsz_packet, intf_thread_t * p_intf ) {
int j=0;
- sess_descr_t * sd;
- playlist_t *p_playlist;
+ sess_descr_t * p_sd;
+ playlist_t *p_playlist;
+ playlist_item_t *p_item;
char * psz_enqueue;
- char * psz_udp = "udp://@\0";
int i;
j=parse_sap( ppsz_packet );
if(j != 0) {
- msg_Dbg( p_intf, "SAP packet parsed");
- sd = parse_sdp( * ppsz_packet );
+ p_sd = parse_sdp( *ppsz_packet, p_intf );
- i = strlen( psz_udp ) + strlen( sd->psz_uri )+1 ;
+ i = strlen( "udp://@\0" ) + strlen( p_sd->psz_uri )+1 ;
psz_enqueue = malloc ( i * sizeof (char) );
memset( psz_enqueue, '\0',i );
- strcat ( psz_enqueue,psz_udp );
- strcat ( psz_enqueue,sd->psz_uri );
+ strcat ( psz_enqueue,"udp://@\0" );
+ strcat ( psz_enqueue,p_sd->psz_uri );
+ free( p_sd->psz_uri );
+ p_sd->psz_uri = psz_enqueue;
+ p_item = sess_toitem ( p_sd );
p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
- playlist_Add ( p_playlist, psz_enqueue, PLAYLIST_CHECK_INSERT, PLAYLIST_END);
- msg_Dbg(p_intf,"SAP packet : End of treatment");
+
+ playlist_AddItem ( p_playlist, p_item, PLAYLIST_CHECK_INSERT, PLAYLIST_END);
vlc_object_release( p_playlist );
+ free ( p_sd );
return 1;
}
- free ( sd );
return 0; // Invalid Packet
}
* Make a sess_descr_t with a psz
******************************************************/
-static sess_descr_t * parse_sdp(char * psz_pct)
+static sess_descr_t * parse_sdp( char * psz_pct, intf_thread_t * p_intf )
{
int j,k;
char ** ppsz_fill;
{
switch(psz_pct[(j-1)]) {
/* case ('v') : {
-// ppsz_fill = & sd->psz_version;
-// break;
+ ppsz_fill = & sd->psz_version;
+ break;
} */
case ('o') : {
ppsz_fill = & sd->psz_origin;
}
default : {
- fprintf( stderr,"Warning : Ignored field \"%c\" \n",psz_pct[j-1] );
+/* msg_Dbg( p_intf, "Warning : Ignored field \"%c\" \n",psz_pct[j-1] ); */
ppsz_fill = NULL;
}
* playlist.c : Playlist management functions
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: playlist.c,v 1.24 2002/12/03 16:29:04 gitan Exp $
+ * $Id: playlist.c,v 1.25 2002/12/03 23:36:41 gitan Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
int playlist_Add( playlist_t *p_playlist, const char * psz_target,
int i_mode, int i_pos )
{
- playlist_item_t *p_item;
+ playlist_item_t * p_item;
+
+ p_item = malloc( sizeof( playlist_item_t ) );
+ if( p_item == NULL )
+ {
+ msg_Err( p_playlist, "out of memory" );
+ }
+
+ p_item->psz_name = strdup( psz_target );
+ p_item->psz_uri = strdup( psz_target );
+ p_item->i_type = 0;
+ p_item->i_status = 0;
+ p_item->b_autodeletion = VLC_FALSE;
+
+ return playlist_AddItem( p_playlist, p_item, i_mode, i_pos );
+}
+int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item,
+ int i_mode, int i_pos)
+{
+
vlc_mutex_lock( &p_playlist->object_lock );
/*
{
for ( j = 0; j < p_playlist->i_size; j++ )
{
- if ( !strcmp( p_playlist->pp_items[j]->psz_name, psz_target ) )
+ if ( !strcmp( p_playlist->pp_items[j]->psz_uri, p_item->psz_uri ) )
{
- msg_Dbg( p_playlist, "item « %s » already enqued",
- psz_target );
+ if( p_item->psz_name )
+ {
+ free( p_item->psz_name );
+ }
+ if( p_item->psz_uri )
+ {
+ free( p_item->psz_uri );
+ }
+ free( p_item );
vlc_mutex_unlock( &p_playlist->object_lock );
return 0;
}
}
- msg_Dbg( p_playlist, "adding playlist item « %s »", psz_target );
+ msg_Dbg( p_playlist, "adding playlist item « %s »", p_item->psz_name );
/* Create the new playlist item */
- p_item = malloc( sizeof( playlist_item_t ) );
- if( p_item == NULL )
- {
- msg_Err( p_playlist, "out of memory" );
- }
-
- p_item->psz_name = strdup( psz_target );
- p_item->i_type = 0;
- p_item->i_status = 0;
- p_item->b_autodeletion = VLC_FALSE;
/* Do a few boundary checks and allocate space for the item */