]> git.sesse.net Git - vlc/blob - src/stream_output/sap.c
ALL: compile fixes
[vlc] / src / stream_output / sap.c
1 /*****************************************************************************
2  * sap.c : SAP announce handler
3  *****************************************************************************
4  * Copyright (C) 2002-2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Rémi Denis-Courmont <rem # 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 #include <ctype.h>                                  /* tolower(), isxdigit() */
32
33 #include <vlc/vlc.h>
34 #include <vlc/sout.h>
35
36 #include "network.h"
37 #if defined( WIN32 ) || defined( UNDER_CE )
38 #   if defined(UNDER_CE) && defined(sockaddr_storage)
39 #       undef sockaddr_storage
40 #   endif
41 #   include <winsock2.h>
42 #   include <ws2tcpip.h>
43 #else
44 #   include <netdb.h>
45 #   ifdef HAVE_ARPA_INET_H
46 #       include <arpa/inet.h>
47 #   endif
48 #endif
49 #include "charset.h"
50
51 /* SAP is always on that port */
52 #define SAP_PORT 9875
53
54 #define DEFAULT_PORT "1234"
55
56 #undef EXTRA_DEBUG
57
58 /* SAP Specific structures */
59
60 /* 100ms */
61 #define SAP_IDLE ((mtime_t)(0.100*CLOCK_FREQ))
62 #define SAP_MAX_BUFFER 65534
63 #define MIN_INTERVAL 2
64 #define MAX_INTERVAL 300
65
66 /* A SAP announce address. For each of these, we run the
67  * control flow algorithm */
68 struct sap_address_t
69 {
70     char *psz_address;
71     char psz_machine[NI_MAXNUMERICHOST];
72     int i_port;
73     int i_rfd; /* Read socket */
74     int i_wfd; /* Write socket */
75
76     /* Used for flow control */
77     mtime_t t1;
78     vlc_bool_t b_enabled;
79     vlc_bool_t b_ready;
80     int i_interval;
81     int i_buff;
82     int i_limit;
83 };
84
85 /*****************************************************************************
86  * Local prototypes
87  *****************************************************************************/
88 static void RunThread( vlc_object_t *p_this);
89 static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address );
90 static char *SDPGenerate( sap_handler_t *p_sap,
91                           const session_descriptor_t *p_session,
92                           const sap_address_t *p_addr );
93
94 static int announce_SendSAPAnnounce( sap_handler_t *p_sap,
95                                      sap_session_t *p_session );
96
97
98 static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
99                              session_descriptor_t *p_session );
100
101 static int announce_SAPAnnounceDel( sap_handler_t *p_sap,
102                              session_descriptor_t *p_session );
103
104 #define FREE( p ) if( p ) { free( p ); (p) = NULL; }
105
106
107 /**
108  * Create the SAP handler
109  *
110  * \param p_announce the parent announce_handler
111  * \return the newly created SAP handler or NULL on error
112  */
113 sap_handler_t *announce_SAPHandlerCreate( announce_handler_t *p_announce )
114 {
115     sap_handler_t *p_sap;
116
117     p_sap = vlc_object_create( p_announce, sizeof( sap_handler_t ) );
118
119     if( !p_sap )
120     {
121         msg_Err( p_announce, "out of memory" );
122         return NULL;
123     }
124
125     vlc_mutex_init( p_sap, &p_sap->object_lock );
126
127     p_sap->pf_add = announce_SAPAnnounceAdd;
128     p_sap->pf_del = announce_SAPAnnounceDel;
129
130     p_sap->i_sessions = 0;
131     p_sap->i_addresses = 0;
132     p_sap->i_current_session = 0;
133
134     p_sap->b_control = config_GetInt( p_sap, "sap-flow-control");
135
136     if( vlc_thread_create( p_sap, "sap handler", RunThread,
137                        VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
138     {
139         msg_Dbg( p_announce, "Unable to spawn SAP handler thread");
140         free( p_sap );
141         return NULL;
142     };
143     msg_Dbg( p_announce, "thread created, %i sessions", p_sap->i_sessions);
144     return p_sap;
145 }
146
147 /**
148  *  Destroy the SAP handler
149  *  \param p_this the SAP Handler to destroy
150  *  \return nothing
151  */
152 void announce_SAPHandlerDestroy( sap_handler_t *p_sap )
153 {
154     int i;
155
156     vlc_mutex_destroy( &p_sap->object_lock );
157
158     /* Free the remaining sessions */
159     for( i = 0 ; i< p_sap->i_sessions ; i++)
160     {
161         sap_session_t *p_session = p_sap->pp_sessions[i];
162         FREE( p_session->psz_sdp );
163         FREE( p_session->psz_data );
164         REMOVE_ELEM( p_sap->pp_sessions, p_sap->i_sessions , i );
165         FREE( p_session );
166     }
167
168     /* Free the remaining addresses */
169     for( i = 0 ; i< p_sap->i_addresses ; i++)
170     {
171         sap_address_t *p_address = p_sap->pp_addresses[i];
172         FREE( p_address->psz_address );
173         if( p_address->i_rfd > -1 )
174         {
175             net_Close( p_address->i_rfd );
176         }
177         if( p_address->i_wfd > -1 && p_sap->b_control )
178         {
179             net_Close( p_address->i_wfd );
180         }
181         REMOVE_ELEM( p_sap->pp_addresses, p_sap->i_addresses, i );
182         FREE( p_address );
183     }
184
185     /* Free the structure */
186     vlc_object_destroy( p_sap );
187 }
188
189 /**
190  * main SAP handler thread
191  * \param p_this the SAP Handler object
192  * \return nothing
193  */
194 static void RunThread( vlc_object_t *p_this)
195 {
196     sap_handler_t *p_sap = (sap_handler_t*)p_this;
197     sap_session_t *p_session;
198
199     while( !p_sap->b_die )
200     {
201         int i;
202
203         /* If needed, get the rate info */
204         if( p_sap->b_control == VLC_TRUE )
205         {
206             for( i = 0 ; i< p_sap->i_addresses ; i++)
207             {
208                 if( p_sap->pp_addresses[i]->b_enabled == VLC_TRUE )
209                 {
210                     CalculateRate( p_sap, p_sap->pp_addresses[i] );
211                 }
212             }
213         }
214
215         /* Find the session to announce */
216         vlc_mutex_lock( &p_sap->object_lock );
217         if( p_sap->i_sessions > p_sap->i_current_session + 1)
218         {
219             p_sap->i_current_session++;
220         }
221         else if( p_sap->i_sessions > 0)
222         {
223             p_sap->i_current_session = 0;
224         }
225         else
226         {
227             vlc_mutex_unlock( &p_sap->object_lock );
228             msleep( SAP_IDLE );
229             continue;
230         }
231         p_session = p_sap->pp_sessions[p_sap->i_current_session];
232         vlc_mutex_unlock( &p_sap->object_lock );
233
234         /* And announce it */
235         if( p_session->p_address->b_enabled == VLC_TRUE &&
236             p_session->p_address->b_ready == VLC_TRUE )
237         {
238             announce_SendSAPAnnounce( p_sap, p_session );
239         }
240
241         msleep( SAP_IDLE );
242     }
243 }
244
245 /* Add a SAP announce */
246 static int announce_SAPAnnounceAdd( sap_handler_t *p_sap,
247                              session_descriptor_t *p_session )
248 {
249     int i_header_size, i;
250     char *psz_head, psz_addr[NI_MAXNUMERICHOST];
251     vlc_bool_t b_ipv6 = VLC_FALSE;
252     sap_session_t *p_sap_session;
253     mtime_t i_hash;
254     struct addrinfo hints, *res;
255     struct sockaddr_storage addr;
256
257     vlc_mutex_lock( &p_sap->object_lock );
258
259     if( p_session->psz_uri == NULL )
260     {
261         vlc_mutex_unlock( &p_sap->object_lock );
262         msg_Err( p_sap, "*FIXME* Unexpected NULL URI for SAP announce" );
263         msg_Err( p_sap, "This should not happen. VLC needs fixing." );
264         return VLC_EGENERIC;
265     }
266
267     /* Determine SAP multicast address automatically */
268     memset( &hints, 0, sizeof( hints ) );
269     hints.ai_socktype = SOCK_DGRAM;
270     hints.ai_flags = AI_NUMERICHOST;
271
272     i = vlc_getaddrinfo( (vlc_object_t *)p_sap, p_session->psz_uri, 0,
273                          &hints, &res );
274     if( i )
275     {
276         vlc_mutex_unlock( &p_sap->object_lock );
277         msg_Err( p_sap, "Invalid URI for SAP announce: %s: %s",
278                  p_session->psz_uri, vlc_gai_strerror( i ) );
279         return VLC_EGENERIC;
280     }
281
282     if( (unsigned)res->ai_addrlen > sizeof( addr ) )
283     {
284         vlc_mutex_unlock( &p_sap->object_lock );
285         vlc_freeaddrinfo( res );
286         msg_Err( p_sap, "Unsupported address family of size %d > %u",
287                  res->ai_addrlen, sizeof( addr ) );
288         return VLC_EGENERIC;
289     }
290
291     memcpy( &addr, res->ai_addr, res->ai_addrlen );
292
293     switch( addr.ss_family )
294     {
295 #if defined (HAVE_INET_PTON) || defined (WIN32)
296         case AF_INET6:
297         {
298             /* See RFC3513 for list of valid IPv6 scopes */
299             struct in6_addr *a6 = &((struct sockaddr_in6 *)&addr)->sin6_addr;
300
301             memcpy( a6->s6_addr + 2, "\x00\x00\x00\x00\x00\x00"
302                    "\x00\x00\x00\x00\x00\x02\x7f\xfe", 14 );
303             if( IN6_IS_ADDR_MULTICAST( a6 ) )
304                  /* force flags to zero, preserve scope */
305                 a6->s6_addr[1] &= 0xf;
306             else
307                 /* Unicast IPv6 - assume global scope */
308                 memcpy( a6->s6_addr, "\xff\x0e", 2 );
309
310             b_ipv6 = VLC_TRUE;
311             break;
312         }
313 #endif
314
315         case AF_INET:
316         {
317             /* See RFC2365 for IPv4 scopes */
318             uint32_t ipv4;
319
320             ipv4 = ntohl( ((struct sockaddr_in *)&addr)->sin_addr.s_addr );
321             /* 224.0.0.0/24 => 224.0.0.255 */
322             if ((ipv4 & 0xffffff00) == 0xe0000000)
323                 ipv4 =  0xe00000ff;
324             else
325             /* 239.255.0.0/16 => 239.255.255.255 */
326             if ((ipv4 & 0xffff0000) == 0xefff0000)
327                 ipv4 =  0xefffffff;
328             else
329             /* 239.192.0.0/14 => 239.195.255.255 */
330             if ((ipv4 & 0xfffc0000) == 0xefc00000)
331                 ipv4 =  0xefc3ffff;
332             else
333             /* other addresses => 224.2.127.254 */
334                 ipv4 = 0xe0027ffe;
335             break;
336         }
337         
338         default:
339             vlc_mutex_unlock( &p_sap->object_lock );
340             vlc_freeaddrinfo( res );
341             msg_Err( p_sap, "Address family %d not supported by SAP",
342                      addr.ss_family );
343             return VLC_EGENERIC;
344     }
345
346     i = vlc_getnameinfo( (struct sockaddr *)&addr, res->ai_addrlen,
347                          psz_addr, sizeof( psz_addr ), NULL, NI_NUMERICHOST );
348     vlc_freeaddrinfo( res );
349
350     if( i )
351     {
352         vlc_mutex_unlock( &p_sap->object_lock );
353         msg_Err( p_sap, "%s", vlc_gai_strerror( i ) );
354         return VLC_EGENERIC;
355     }
356
357     msg_Dbg( p_sap, "using SAP address: %s", psz_addr);
358
359     /* XXX: Check for dupes */
360     p_sap_session = (sap_session_t*)malloc(sizeof(sap_session_t));
361     p_sap_session->p_address = NULL;
362
363     /* Add the address to the buffer */
364     for( i = 0; i < p_sap->i_addresses; i++)
365     {
366         if( !strcmp( psz_addr, p_sap->pp_addresses[i]->psz_address ) )
367         {
368             p_sap_session->p_address = p_sap->pp_addresses[i];
369             break;
370         }
371     }
372
373     if( p_sap_session->p_address == NULL )
374     {
375         sap_address_t *p_address = (sap_address_t *)
376                                     malloc( sizeof(sap_address_t) );
377         if( !p_address )
378         {
379             msg_Err( p_sap, "out of memory" );
380             return VLC_ENOMEM;
381         }
382         p_address->psz_address = strdup( psz_addr );
383         p_address->i_port  =  9875;
384         p_address->i_wfd = net_OpenUDP( p_sap, "", 0, psz_addr,
385                                         p_address->i_port );
386         if( p_address->i_wfd != -1 )
387         {
388             char *ptr;
389
390             net_StopRecv( p_address->i_wfd );
391             net_GetSockAddress( p_address->i_wfd, p_address->psz_machine,
392                                 NULL );
393
394             /* removes scope if present */
395             ptr = strchr( p_address->psz_machine, '%' );
396             if( ptr != NULL )
397                 *ptr = '\0';
398         }
399
400         if( p_sap->b_control == VLC_TRUE )
401         {
402             p_address->i_rfd = net_OpenUDP( p_sap, psz_addr,
403                                             p_address->i_port, "", 0 );
404             if( p_address->i_rfd != -1 )
405                 net_StopSend( p_address->i_rfd );
406             p_address->i_buff = 0;
407             p_address->b_enabled = VLC_TRUE;
408             p_address->b_ready = VLC_FALSE;
409             p_address->i_limit = 10000; /* 10000 bps */
410             p_address->t1 = 0;
411         }
412         else
413         {
414             p_address->b_enabled = VLC_TRUE;
415             p_address->b_ready = VLC_TRUE;
416             p_address->i_interval = config_GetInt( p_sap,"sap-interval");
417             p_address->i_rfd = -1;
418         }
419
420         if( p_address->i_wfd == -1 || (p_address->i_rfd == -1
421                                         && p_sap->b_control ) )
422         {
423             msg_Warn( p_sap, "disabling address" );
424             p_address->b_enabled = VLC_FALSE;
425         }
426
427         INSERT_ELEM( p_sap->pp_addresses,
428                      p_sap->i_addresses,
429                      p_sap->i_addresses,
430                      p_address );
431         p_sap_session->p_address = p_address;
432     }
433
434
435     /* Build the SAP Headers */
436     i_header_size = ( b_ipv6 ? 16 : 4 ) + 20;
437     psz_head = (char *) malloc( i_header_size * sizeof( char ) );
438     if( psz_head == NULL )
439     {
440         msg_Err( p_sap, "out of memory" );
441         return VLC_ENOMEM;
442     }
443
444     /* SAPv1, not encrypted, not compressed */
445     psz_head[0] = b_ipv6 ? 0x30 : 0x20;
446     psz_head[1] = 0x00; /* No authentification length */
447
448     i_hash = mdate();
449     psz_head[2] = (i_hash & 0xFF00) >> 8; /* Msg id hash */
450     psz_head[3] = (i_hash & 0xFF);        /* Msg id hash 2 */
451
452 #if defined (HAVE_INET_PTON) || defined (WIN32)
453     if( b_ipv6 )
454     {
455         inet_pton( AF_INET6, /* can't fail */
456                    p_sap_session->p_address->psz_machine,
457                    psz_head + 4 );
458     }
459     else
460 #else
461     {
462         inet_pton( AF_INET, /* can't fail */
463                    p_sap_session->p_address->psz_machine,
464                    psz_head + 4 );
465     }
466 #endif
467
468     memcpy( psz_head + (b_ipv6 ? 20 : 8), "application/sdp", 15 );
469
470     /* If needed, build the SDP */
471     if( p_session->psz_sdp == NULL )
472     {
473         p_session->psz_sdp = SDPGenerate( p_sap, p_session,
474                                           p_sap_session->p_address );
475         if( p_session->psz_sdp == NULL )
476         {
477             vlc_mutex_unlock( &p_sap->object_lock );
478             return VLC_ENOMEM;
479         }
480     }
481
482     p_sap_session->psz_sdp = strdup( p_session->psz_sdp );
483     p_sap_session->i_last = 0;
484
485     psz_head[ i_header_size-1 ] = '\0';
486     p_sap_session->i_length = i_header_size + strlen( p_sap_session->psz_sdp);
487
488     p_sap_session->psz_data = (uint8_t *)malloc( sizeof(char)*
489                                                  p_sap_session->i_length );
490
491     /* Build the final message */
492     memcpy( p_sap_session->psz_data, psz_head, i_header_size );
493     memcpy( p_sap_session->psz_data+i_header_size, p_sap_session->psz_sdp,
494             strlen( p_sap_session->psz_sdp) );
495
496     free( psz_head );
497
498     /* Enqueue the announce */
499     INSERT_ELEM( p_sap->pp_sessions,
500                  p_sap->i_sessions,
501                  p_sap->i_sessions,
502                  p_sap_session );
503     msg_Dbg( p_sap,"Addresses: %i  Sessions: %i",
504                    p_sap->i_addresses,p_sap->i_sessions);
505
506     /* Remember the SAP session for later deletion */
507     p_session->p_sap = p_sap_session;
508
509     vlc_mutex_unlock( &p_sap->object_lock );
510
511     return VLC_SUCCESS;
512 }
513
514 /* Remove a SAP Announce */
515 static int announce_SAPAnnounceDel( sap_handler_t *p_sap,
516                              session_descriptor_t *p_session )
517 {
518     int i;
519     vlc_mutex_lock( &p_sap->object_lock );
520
521     msg_Dbg( p_sap,"removing SAP announce %p",p_session->p_sap);
522
523     /* Dequeue the announce */
524     for( i = 0; i< p_sap->i_sessions; i++)
525     {
526         if( p_session->p_sap == p_sap->pp_sessions[i] )
527         {
528             REMOVE_ELEM( p_sap->pp_sessions,
529                          p_sap->i_sessions,
530                          i );
531
532             FREE( p_session->p_sap->psz_sdp );
533             FREE( p_session->p_sap->psz_data );
534             free( p_session->p_sap );
535             break;
536         }
537     }
538
539     /* XXX: Dequeue the address too if it is not used anymore
540      * TODO: - address refcount
541              - send a SAP deletion packet */
542
543     msg_Dbg( p_sap,"%i announces remaining", p_sap->i_sessions );
544
545     vlc_mutex_unlock( &p_sap->object_lock );
546
547     return VLC_SUCCESS;
548 }
549
550 static int announce_SendSAPAnnounce( sap_handler_t *p_sap,
551                                      sap_session_t *p_session )
552 {
553     int i_ret;
554
555     /* This announce has never been sent yet */
556     if( p_session->i_last == 0 )
557     {
558         p_session->i_next = mdate()+ p_session->p_address->i_interval*1000000;
559         p_session->i_last = 1;
560         return VLC_SUCCESS;
561     }
562
563     if( p_session->i_next < mdate() )
564     {
565 #ifdef EXTRA_DEBUG
566         msg_Dbg( p_sap, "Sending announce");
567 #endif
568         i_ret = net_Write( p_sap, p_session->p_address->i_wfd, NULL,
569                            p_session->psz_data,
570                            p_session->i_length );
571         if( i_ret != (int)p_session->i_length )
572         {
573             msg_Warn( p_sap, "SAP send failed on address %s (%i %i)",
574                    p_session->p_address->psz_address,
575                    i_ret, p_session->i_length );
576         }
577         p_session->i_last = p_session->i_next;
578         p_session->i_next = p_session->i_last
579                             + p_session->p_address->i_interval*1000000;
580     }
581     else
582     {
583         return VLC_SUCCESS;
584     }
585     return VLC_SUCCESS;
586 }
587
588 static char *SDPGenerate( sap_handler_t *p_sap,
589                           const session_descriptor_t *p_session,
590                           const sap_address_t *p_addr )
591 {
592     int64_t i_sdp_id = mdate();
593     int     i_sdp_version = 1 + p_sap->i_sessions + (rand()&0xfff);
594     char *psz_group, *psz_name, psz_uribuf[NI_MAXNUMERICHOST], *psz_uri,
595          *psz_sdp;
596     char ipv;
597
598     psz_group = p_session->psz_group;
599     psz_name = p_session->psz_name;
600
601     /* FIXME: really check that psz_uri is a real IP address
602      * FIXME: make a common function to obtain a canonical IP address */
603     ipv = ( strchr( p_session->psz_uri, ':' )  != NULL) ? '6' : '4';
604     if( *p_session->psz_uri == '[' )
605     {
606         char *ptr;
607
608         strncpy( psz_uribuf, p_session->psz_uri + 1, sizeof( psz_uribuf ) );
609         psz_uribuf[sizeof( psz_uribuf ) - 1] = '\0';
610         ptr = strchr( psz_uribuf, '%' );
611         if( ptr != NULL)
612             *ptr = '\0';
613         ptr = strchr( psz_uribuf, ']' );
614         if( ptr != NULL)
615             *ptr = '\0';
616         psz_uri = psz_uribuf;
617     }
618     else
619         psz_uri = p_session->psz_uri;
620
621     /* see the lists in modules/stream_out/rtp.c for compliance stuff */
622     if( asprintf( &psz_sdp,
623                             "v=0\r\n"
624                             "o=- "I64Fd" %d IN IP%c %s\r\n"
625                             "s=%s\r\n"
626                             "t=0 0\r\n"
627                             "c=IN IP%c %s/%d\r\n"
628                             "m=video %d udp %d\r\n"
629                             "a=tool:"PACKAGE_STRING"\r\n"
630                             "a=type:broadcast\r\n"
631                             "%s%s%s",
632                             i_sdp_id, i_sdp_version,
633                             ipv, p_addr->psz_machine,
634                             psz_name, ipv,
635                             psz_uri, p_session->i_ttl,
636                             p_session->i_port, p_session->i_payload,
637                             psz_group ? "a=x-plgroup:" : "",
638                             psz_group ? psz_group : "", psz_group ? "\r\n" : "" ) == -1 )
639         return NULL;
640     
641     msg_Dbg( p_sap, "Generated SDP (%i bytes):\n%s", strlen(psz_sdp),
642              psz_sdp );
643     return psz_sdp;
644 }
645
646 static int CalculateRate( sap_handler_t *p_sap, sap_address_t *p_address )
647 {
648     int i_read;
649     uint8_t buffer[SAP_MAX_BUFFER];
650     int i_tot = 0;
651     mtime_t i_temp;
652     int i_rate;
653
654     if( p_address->t1 == 0 )
655     {
656         p_address->t1 = mdate();
657         return VLC_SUCCESS;
658     }
659     do
660     {
661         /* Might be too slow if we have huge data */
662         i_read = net_ReadNonBlock( p_sap, p_address->i_rfd, NULL, buffer,
663                                    SAP_MAX_BUFFER, 0 );
664         i_tot += i_read;
665     } while( i_read > 0 && i_tot < SAP_MAX_BUFFER );
666
667     i_temp = mdate();
668
669     /* We calculate the rate every 5 seconds */
670     if( i_temp - p_address->t1 < 5000000 )
671     {
672         p_address->i_buff += i_tot;
673         return VLC_SUCCESS;
674     }
675
676     /* Bits/second */
677     i_rate = (int)(8*1000000*((mtime_t)p_address->i_buff + (mtime_t)i_tot ) /
678                         (i_temp - p_address->t1 ));
679
680     p_address->i_limit = 10000;
681
682     p_address->i_interval = ((1000*i_rate / p_address->i_limit) *
683                             (MAX_INTERVAL - MIN_INTERVAL))/1000 + MIN_INTERVAL;
684
685     if( p_address->i_interval > MAX_INTERVAL || p_address->i_interval < 0 )
686     {
687         p_address->i_interval = MAX_INTERVAL;
688     }
689 #ifdef EXTRA_DEBUG
690     msg_Dbg( p_sap,"%s:%i : Rate=%i, Interval = %i s",
691                     p_address->psz_address,p_address->i_port,
692                     i_rate,
693                     p_address->i_interval );
694 #endif
695
696     p_address->b_ready = VLC_TRUE;
697
698     p_address->t1 = i_temp;
699     p_address->i_buff = 0;
700
701     return VLC_SUCCESS;
702 }