]> git.sesse.net Git - vlc/blob - src/stream_output/announce.c
* INSTALL.win32: added a small note about running vlc under the msvc debugger.
[vlc] / src / stream_output / announce.c
1 /*****************************************************************************
2  * announce.c : Session announcement
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  *
6  * Authors: Christophe Massiot <massiot@via.ecp.fr>
7  *          Laurent Aimar <fenrir@via.ecp.fr>
8  *          Eric Petit <titer@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                                /* free() */
29 #include <stdio.h>                                              /* sprintf() */
30 #include <string.h>                                            /* strerror() */
31
32 #include <vlc/vlc.h>
33
34 #include <vlc/sout.h>
35 #undef DEBUG_BUFFER
36
37 #include <announce.h>
38 #include <network.h>
39
40 #define SAP_ADDR "224.2.127.254"
41 #define SAP_PORT 9875
42
43 /*****************************************************************************
44  * sout_SAPNew: Creates a SAP Session
45  *****************************************************************************/
46 sap_session_t * sout_SAPNew ( sout_instance_t *p_sout , char * psz_url_arg , char * psz_name_arg )
47 {
48         sap_session_t           *p_new;
49         module_t                *p_network;
50         network_socket_t        socket_desc;
51         char                    psz_network[12];       
52         struct                  sockaddr_in addr;
53         int                     ttl=15;
54               
55         p_new = (sap_session_t *)malloc( sizeof ( sap_session_t ) ) ;
56         
57         sprintf ( p_new->psz_url , "%s" , psz_url_arg );
58         sprintf ( p_new->psz_name , "%s" , psz_name_arg );
59         
60         msg_Dbg (p_sout , "Creating SAP Socket" );
61         
62         socket_desc.i_type        = NETWORK_UDP;
63         socket_desc.psz_bind_addr = SAP_ADDR;
64         socket_desc.i_bind_port   = SAP_PORT;
65         socket_desc.psz_server_addr   = "";
66         socket_desc.i_server_port     = 0;
67         socket_desc.i_handle          = 0;
68         
69         sprintf ( psz_network,"ipv4" ); 
70
71         p_sout->p_private=(void*) &socket_desc;
72         
73         if( !( p_network = module_Need( p_sout, "network", psz_network ) ) )
74         {
75             msg_Warn( p_sout, "failed to open a connection (udp)" );
76         }
77
78         module_Unneed( p_sout, p_network );
79                
80         p_new->socket   =       socket_desc.i_handle;
81
82         memset( &addr , 0 , sizeof(addr) );
83         addr.sin_family      = AF_INET;
84         addr.sin_addr.s_addr = inet_addr(SAP_ADDR);
85         addr.sin_port        = htons( SAP_PORT );
86     
87         setsockopt( p_new->socket, IPPROTO_IP, IP_MULTICAST_TTL,
88                     (void*)&ttl, sizeof(ttl) );
89      
90         p_new->addr = addr;
91     
92         return(p_new);
93 }
94
95 /*****************************************************************************
96  * sout_SAPDelete: Deletes a SAP Session 
97  *****************************************************************************/
98 void sout_SAPDelete( sap_session_t * p_this )
99 {
100         shutdown(p_this->socket,0);
101         free(p_this);        
102 }       
103
104 /*****************************************************************************
105  * sout_SAPSend: Sends a SAP packet 
106  *****************************************************************************/
107 void sout_SAPSend( sout_instance_t *p_sout, sap_session_t * p_this )
108
109       char sap_msg[2048];
110       char *user="VideoLAN";
111       char *machine="VideoLAN";
112       char *site="VideoLAN";
113       int i_send_result;
114      
115     if(p_this->sendnow == 24)
116     {      
117       sprintf(sap_msg,"         ***øv=0 \n\
118       o=%s 3247692199 3247895918 IN IP4 %s \n\
119       s=%s\n\
120       u=%s \n\
121       t=3247691400 3250117800 \n\
122       a=type:test   \n\
123       m=audio 1234 udp 14 \n\
124       c=IN IP4 %s/15  \n\
125       xxxxxxxxxxxxxxxxxxxxx \n ",user,machine,p_this->psz_name,site,p_this->psz_url);
126         
127      i_send_result =  sendto( p_this->socket , sap_msg , strlen(sap_msg) , 0 , (struct sockaddr *)&p_this->addr , sizeof(p_this->addr) );
128      
129      if(i_send_result == -1)
130      {
131               msg_Warn(p_sout , "SAP Send failed on socket %i. " , p_this->socket );
132              perror("send"); 
133      }
134      p_this->sendnow=0;
135     }
136      p_this->sendnow++;  
137 }