]> git.sesse.net Git - vlc/blob - src/input/input.c
* Fixed the BeOS compile typo.
[vlc] / src / input / input.c
1 /*****************************************************************************
2  * input.c: input thread
3  * Read an MPEG2 stream, demultiplex and parse it before sending it to
4  * decoders.
5  *****************************************************************************
6  * Copyright (C) 1998, 1999, 2000 VideoLAN
7  * $Id: input.c,v 1.113 2001/05/30 17:03:12 sam Exp $
8  *
9  * Authors: Christophe Massiot <massiot@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include "defs.h"
30
31 #include <stdlib.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <unistd.h>
36 #include <string.h>
37 #ifdef STRNCASECMP_IN_STRINGS_H
38 #   include <strings.h>
39 #endif
40 #include <errno.h>
41
42 /* WinSock Includes */
43
44 #ifdef WIN32
45 #include <winsock2.h>
46 #endif
47
48
49 /* Network functions */
50
51 #if !defined( SYS_BEOS ) && !defined( SYS_NTO ) && !defined( WIN32 )
52 #include <netdb.h>                                            /* hostent ... */
53 #include <sys/socket.h>
54 #include <netinet/in.h>
55 #include <arpa/inet.h>
56 #include <sys/types.h>
57 #include <sys/socket.h>
58 #endif
59
60 #ifdef STATS
61 #   include <sys/times.h>
62 #endif
63
64 #include "config.h"
65 #include "common.h"
66 #include "threads.h"
67 #include "mtime.h"
68 #include "netutils.h"
69 #include "modules.h"
70
71 #include "intf_msg.h"
72 #include "intf_playlist.h"
73
74 #include "stream_control.h"
75 #include "input_ext-intf.h"
76 #include "input_ext-dec.h"
77
78 #include "input.h"
79 #include "interface.h"
80
81 #include "main.h"
82
83
84 /*****************************************************************************
85  * Local prototypes
86  *****************************************************************************/
87 static void RunThread       ( input_thread_t *p_input );
88 static  int InitThread      ( input_thread_t *p_input );
89 static void ErrorThread     ( input_thread_t *p_input );
90 static void DestroyThread   ( input_thread_t *p_input );
91 static void EndThread       ( input_thread_t *p_input );
92
93 static void FileOpen        ( input_thread_t *p_input );
94 static void FileClose       ( input_thread_t *p_input );
95 static void NetworkOpen     ( input_thread_t *p_input );
96 static void NetworkClose    ( input_thread_t *p_input );
97
98 /*****************************************************************************
99  * input_CreateThread: creates a new input thread
100  *****************************************************************************
101  * This function creates a new input, and returns a pointer
102  * to its description. On error, it returns NULL.
103  * If pi_status is NULL, then the function will block until the thread is ready.
104  * If not, it will be updated using one of the THREAD_* constants.
105  *****************************************************************************/
106 input_thread_t *input_CreateThread ( playlist_item_t *p_item, int *pi_status )
107 {
108     input_thread_t *    p_input;                        /* thread descriptor */
109     int                 i_status;                           /* thread status */
110
111     /* Allocate descriptor */
112     p_input = (input_thread_t *)malloc( sizeof(input_thread_t) );
113     if( p_input == NULL )
114     {
115         intf_ErrMsg( "input error: can't allocate input thread (%s)",
116                      strerror(errno) );
117         return( NULL );
118     }
119
120     /* Packets read once */
121     p_input->i_read_once = INPUT_READ_ONCE;
122
123     /* Initialize thread properties */
124     p_input->b_die              = 0;
125     p_input->b_error            = 0;
126     p_input->b_eof              = 0;
127
128     /* Set target */
129     p_input->p_source           = p_item->psz_name;
130
131     /* I have never understood that stuff --Meuuh */
132     p_input->pi_status          = (pi_status != NULL) ? pi_status : &i_status;
133     *p_input->pi_status         = THREAD_CREATE;
134
135     /* Initialize stream description */
136     p_input->stream.i_es_number = 0;
137     p_input->stream.i_selected_es_number = 0;
138     p_input->stream.i_pgrm_number = 0;
139     p_input->stream.i_new_status = p_input->stream.i_new_rate = 0;
140     p_input->stream.i_mux_rate = 0;
141
142     /* no stream, no area */
143     p_input->stream.i_area_nb = 0;
144     p_input->stream.pp_areas = NULL;
145     p_input->stream.p_selected_area = NULL;
146     p_input->stream.p_new_area = NULL;
147     /* By default there is one areas in a stream */
148     input_AddArea( p_input );
149     p_input->stream.p_selected_area = p_input->stream.pp_areas[0];
150
151     /* Initialize stream control properties. */
152     p_input->stream.control.i_status = PLAYING_S;
153     p_input->stream.control.i_rate = DEFAULT_RATE;
154     p_input->stream.control.b_mute = 0;
155     p_input->stream.control.b_bw = 0;
156
157     /* Setup callbacks */
158     p_input->pf_file_open     = FileOpen;
159     p_input->pf_file_close    = FileClose;
160 #if !defined( SYS_BEOS ) && !defined( SYS_NTO )
161     p_input->pf_network_open  = NetworkOpen;
162     p_input->pf_network_close = NetworkClose;
163 #endif
164
165     /* Create thread and set locks. */
166     vlc_mutex_init( &p_input->stream.stream_lock );
167     vlc_cond_init( &p_input->stream.stream_wait );
168     vlc_mutex_init( &p_input->stream.control.control_lock );
169     if( vlc_thread_create( &p_input->thread_id, "input", (void *) RunThread,
170                            (void *) p_input ) )
171     {
172         intf_ErrMsg( "input error: can't create input thread (%s)",
173                      strerror(errno) );
174         free( p_input );
175         return( NULL );
176     }
177
178     /* If status is NULL, wait until the thread is created */
179     if( pi_status == NULL )
180     {
181         do
182         {
183             msleep( THREAD_SLEEP );
184         } while( (i_status != THREAD_READY) && (i_status != THREAD_ERROR)
185                 && (i_status != THREAD_FATAL) );
186         if( i_status != THREAD_READY )
187         {
188             return( NULL );
189         }
190     }
191     return( p_input );
192 }
193
194 /*****************************************************************************
195  * input_DestroyThread: mark an input thread as zombie
196  *****************************************************************************
197  * This function should not return until the thread is effectively cancelled.
198  *****************************************************************************/
199 void input_DestroyThread( input_thread_t *p_input, int *pi_status )
200 {
201     int         i_status;                                   /* thread status */
202
203     /* Set status */
204     p_input->pi_status = (pi_status != NULL) ? pi_status : &i_status;
205     *p_input->pi_status = THREAD_DESTROY;
206
207     /* Request thread destruction */
208     p_input->b_die = 1;
209
210     /* Make the thread exit of an eventual vlc_cond_wait() */
211     vlc_mutex_lock( &p_input->stream.stream_lock );
212     vlc_cond_signal( &p_input->stream.stream_wait );
213     vlc_mutex_unlock( &p_input->stream.stream_lock );
214
215     /* If status is NULL, wait until thread has been destroyed */
216     if( pi_status == NULL )
217     {
218         do
219         {
220             msleep( THREAD_SLEEP );
221         } while ( (i_status != THREAD_OVER) && (i_status != THREAD_ERROR)
222                   && (i_status != THREAD_FATAL) );
223     }
224 }
225
226 /*****************************************************************************
227  * RunThread: main thread loop
228  *****************************************************************************
229  * Thread in charge of processing the network packets and demultiplexing.
230  *****************************************************************************/
231 static void RunThread( input_thread_t *p_input )
232 {
233     int                     i_error, i;
234
235     if( InitThread( p_input ) )
236     {
237
238         /* If we failed, wait before we are killed, and exit */
239         *p_input->pi_status = THREAD_ERROR;
240         p_input->b_error = 1;
241         ErrorThread( p_input );
242         DestroyThread( p_input );
243         return;
244     }
245
246     /* initialization is completed */
247     vlc_mutex_lock( &p_input->stream.stream_lock );
248     p_input->stream.b_changed = 1;
249     vlc_mutex_unlock( &p_input->stream.stream_lock );
250
251     while( !p_input->b_die && !p_input->b_error && !p_input->b_eof )
252     {
253         data_packet_t *         pp_packets[p_input->i_read_once];
254
255 #ifdef STATS
256         p_input->c_loops++;
257 #endif
258
259         vlc_mutex_lock( &p_input->stream.stream_lock );
260
261         if( p_input->stream.p_new_area )
262         {
263             p_input->pf_set_area( p_input, p_input->stream.p_new_area );
264             p_input->stream.p_new_area = NULL;
265         }
266
267         if( p_input->stream.p_selected_area->i_seek != NO_SEEK )
268         {
269             if( p_input->stream.b_seekable && p_input->pf_seek != NULL )
270             {
271                 p_input->pf_seek( p_input,
272                                   p_input->stream.p_selected_area->i_seek );
273
274                 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
275                 {
276                     pgrm_descriptor_t * p_pgrm
277                                             = p_input->stream.pp_programs[i];
278                     /* Escape all decoders for the stream discontinuity they
279                      * will encounter. */
280                     input_EscapeDiscontinuity( p_input, p_pgrm );
281
282                     /* Reinitialize synchro. */
283                     p_pgrm->i_synchro_state = SYNCHRO_REINIT;
284                 }
285             }
286             p_input->stream.p_selected_area->i_seek = NO_SEEK;
287         }
288
289         if( p_input->stream.p_removed_es )
290         {
291             input_UnselectES( p_input, p_input->stream.p_removed_es );
292             p_input->stream.p_removed_es = NULL;
293         }
294
295         if( p_input->stream.p_newly_selected_es )
296         {
297             input_SelectES( p_input, p_input->stream.p_newly_selected_es );
298             p_input->stream.p_newly_selected_es = NULL;
299         }
300
301         vlc_mutex_unlock( &p_input->stream.stream_lock );
302
303         i_error = p_input->pf_read( p_input, pp_packets );
304
305         /* Demultiplex read packets. */
306         for( i = 0; i < p_input->i_read_once && pp_packets[i] != NULL; i++ )
307         {
308             p_input->pf_demux( p_input, pp_packets[i] );
309         }
310
311         if( i_error )
312         {
313             if( i_error == 1 )
314             {
315                 /* End of file - we do not set b_die because only the
316                  * interface is allowed to do so. */
317                 intf_WarnMsg( 3, "input: EOF reached" );
318                 p_input->b_eof = 1;
319             }
320             else
321             {
322                 p_input->b_error = 1;
323             }
324         }
325     }
326
327     if( p_input->b_error || p_input->b_eof )
328     {
329         ErrorThread( p_input );
330     }
331
332     EndThread( p_input );
333
334     DestroyThread( p_input );
335
336     intf_DbgMsg("input: Thread end");
337 }
338
339 /*****************************************************************************
340  * InitThread: init the input Thread
341  *****************************************************************************/
342 static int InitThread( input_thread_t * p_input )
343 {
344
345 #ifdef STATS
346     /* Initialize statistics */
347     p_input->c_loops                    = 0;
348     p_input->c_bytes                    = 0;
349     p_input->c_payload_bytes            = 0;
350     p_input->c_packets_read             = 0;
351     p_input->c_packets_trashed          = 0;
352 #endif
353
354     p_input->p_input_module = module_Need( MODULE_CAPABILITY_INPUT,
355                                            (probedata_t *)p_input );
356
357     if( p_input->p_input_module == NULL )
358     {
359         intf_ErrMsg( "input error: no suitable input module for `%s'",
360                      p_input->p_source );
361         return( -1 );
362     }
363
364 #define f p_input->p_input_module->p_functions->input.functions.input
365     p_input->pf_init          = f.pf_init;
366     p_input->pf_open          = f.pf_open;
367     p_input->pf_close         = f.pf_close;
368     p_input->pf_end           = f.pf_end;
369     p_input->pf_read          = f.pf_read;
370     p_input->pf_set_area      = f.pf_set_area;
371     p_input->pf_demux         = f.pf_demux;
372     p_input->pf_new_packet    = f.pf_new_packet;
373     p_input->pf_new_pes       = f.pf_new_pes;
374     p_input->pf_delete_packet = f.pf_delete_packet;
375     p_input->pf_delete_pes    = f.pf_delete_pes;
376     p_input->pf_rewind        = f.pf_rewind;
377     p_input->pf_seek          = f.pf_seek;
378 #undef f
379     p_input->pf_open( p_input );
380
381     if( p_input->b_error )
382     {
383         /* We barfed -- exit nicely */
384         p_input->pf_close( p_input );
385         module_Unneed( p_input->p_input_module );
386         return( -1 );
387     }
388
389     p_input->pf_init( p_input );
390
391     if( p_input->b_error )
392     {
393         /* We barfed -- exit nicely */
394         p_input->pf_close( p_input );
395         module_Unneed( p_input->p_input_module );
396         return( -1 );
397     }
398
399     *p_input->pi_status = THREAD_READY;
400
401     return( 0 );
402 }
403
404 /*****************************************************************************
405  * ErrorThread: RunThread() error loop
406  *****************************************************************************
407  * This function is called when an error occured during thread main's loop.
408  *****************************************************************************/
409 static void ErrorThread( input_thread_t *p_input )
410 {
411     while( !p_input->b_die )
412     {
413         /* Sleep a while */
414         msleep( INPUT_IDLE_SLEEP );
415     }
416 }
417
418 /*****************************************************************************
419  * EndThread: end the input thread
420  *****************************************************************************/
421 static void EndThread( input_thread_t * p_input )
422 {
423     int *       pi_status;                                  /* thread status */
424
425     /* Store status */
426     pi_status = p_input->pi_status;
427     *pi_status = THREAD_END;
428
429 #ifdef STATS
430     {
431         struct tms cpu_usage;
432         times( &cpu_usage );
433
434         intf_Msg("input stats: cpu usage (user: %d, system: %d)",
435                  cpu_usage.tms_utime, cpu_usage.tms_stime);
436     }
437 #endif
438
439     /* Free all ES and destroy all decoder threads */
440     input_EndStream( p_input );
441
442     /* Free demultiplexer's data */
443     p_input->pf_end( p_input );
444
445     /* Close stream */
446     p_input->pf_close( p_input );
447
448     /* Release modules */
449     module_Unneed( p_input->p_input_module );
450
451 }
452
453 /*****************************************************************************
454  * DestroyThread: destroy the input thread
455  *****************************************************************************/
456 static void DestroyThread( input_thread_t * p_input )
457 {
458     int *       pi_status;                                  /* thread status */
459
460     /* Store status */
461     pi_status = p_input->pi_status;
462
463     /* Destroy Mutex locks */
464     vlc_mutex_destroy( &p_input->stream.control.control_lock );
465     vlc_mutex_destroy( &p_input->stream.stream_lock );
466     
467     /* Free input structure */
468     free( p_input );
469
470     /* Update status */
471     *pi_status = THREAD_OVER;
472 }
473
474 /*****************************************************************************
475  * FileOpen : open a file descriptor
476  *****************************************************************************/
477 static void FileOpen( input_thread_t * p_input )
478 {
479     struct stat         stat_info;
480     int                 i_stat;
481
482     char *psz_name = p_input->p_source;
483
484     /* FIXME: this code ought to be in the plugin so that code can
485      * be shared with the *_Probe function */
486     if( ( i_stat = stat( psz_name, &stat_info ) ) == (-1) )
487     {
488         int i_size = strlen( psz_name );
489
490         if( ( i_size > 4 )
491             && !strncasecmp( psz_name, "dvd:", 4 ) )
492         {
493             /* get rid of the 'dvd:' stuff and try again */
494             psz_name += 4;
495             i_stat = stat( psz_name, &stat_info );
496         }
497         else if( ( i_size > 5 )
498                  && !strncasecmp( psz_name, "file:", 5 ) )
499         {
500             /* get rid of the 'file:' stuff and try again */
501             psz_name += 5;
502             i_stat = stat( psz_name, &stat_info );
503         }
504
505         if( i_stat == (-1) )
506         {
507             intf_ErrMsg( "input error: cannot stat() file `%s' (%s)",
508                          psz_name, strerror(errno));
509             p_input->b_error = 1;
510             return;
511         }
512     }
513
514     vlc_mutex_lock( &p_input->stream.stream_lock );
515
516     /* If we are here we can control the pace... */
517     p_input->stream.b_pace_control = 1;
518
519     if( S_ISREG(stat_info.st_mode) || S_ISCHR(stat_info.st_mode)
520          || S_ISBLK(stat_info.st_mode) )
521     {
522         p_input->stream.b_seekable = 1;
523         p_input->stream.p_selected_area->i_size = stat_info.st_size;
524     }
525     else if( S_ISFIFO(stat_info.st_mode)
526 #if !defined( SYS_BEOS ) && !defined( WIN32 )
527              || S_ISSOCK(stat_info.st_mode)
528 #endif
529              )
530     {
531         p_input->stream.b_seekable = 0;
532         p_input->stream.p_selected_area->i_size = 0;
533     }
534     else
535     {
536         vlc_mutex_unlock( &p_input->stream.stream_lock );
537         intf_ErrMsg( "input error: unknown file type for `%s'",
538                      psz_name );
539         p_input->b_error = 1;
540         return;
541     }
542
543     p_input->stream.p_selected_area->i_tell = 0;
544     vlc_mutex_unlock( &p_input->stream.stream_lock );
545
546     intf_WarnMsg( 1, "input: opening file `%s'", p_input->p_source );
547 #ifndef WIN32
548     if( (p_input->i_handle = open( psz_name,
549                                    /*O_NONBLOCK | O_LARGEFILE*/0 )) == (-1) )
550 #else
551     if( (p_input->i_handle = open( psz_name, O_BINARY
552                                    /*O_NONBLOCK | O_LARGEFILE*/ )) == (-1) )
553 #endif
554     {
555         intf_ErrMsg( "input error: cannot open file (%s)", strerror(errno) );
556         p_input->b_error = 1;
557         return;
558     }
559
560 }
561
562 /*****************************************************************************
563  * FileClose : close a file descriptor
564  *****************************************************************************/
565 static void FileClose( input_thread_t * p_input )
566 {
567     intf_WarnMsg( 1, "input: closing file `%s'", p_input->p_source );
568     close( p_input->i_handle );
569
570     return;
571 }
572
573
574 #if !defined( SYS_BEOS ) && !defined( SYS_NTO )
575 /*****************************************************************************
576  * NetworkOpen : open a network socket 
577  *****************************************************************************/
578 static void NetworkOpen( input_thread_t * p_input )
579 {
580     char                *psz_server = NULL;
581     char                *psz_broadcast = NULL;
582     int                 i_port = 0;
583     int                 i_opt;
584     struct sockaddr_in  sock;
585
586 #ifdef WIN32
587     /* WinSock Library Init. */
588     WSADATA Data;
589     int i_err = WSAStartup( MAKEWORD( 1, 1 ), &Data );
590
591     if( i_err )
592     {
593         intf_ErrMsg( "input: can't initiate WinSocks, error %i", i_err );
594         return ;
595     }
596 #endif
597     
598     /* Get the remote server */
599     if( p_input->p_source != NULL )
600     {
601         psz_server = p_input->p_source;
602
603         /* Skip the protocol name */
604         while( *psz_server && *psz_server != ':' )
605         {
606             psz_server++;
607         }
608
609         /* Skip the "://" part */
610         while( *psz_server && (*psz_server == ':' || *psz_server == '/') )
611         {
612             psz_server++;
613         }
614
615         /* Found a server name */
616         if( *psz_server )
617         {
618             char *psz_port = psz_server;
619
620             /* Skip the hostname part */
621             while( *psz_port && *psz_port != ':' )
622             {
623                 psz_port++;
624             }
625
626             /* Found a port name */
627             if( *psz_port )
628             {
629                 /* Replace ':' with '\0' */
630                 *psz_port = '\0';
631                 psz_port++;
632
633                 psz_broadcast = psz_port;
634                 while( *psz_broadcast && *psz_broadcast != ':' )
635                 {
636                     psz_broadcast++;
637                 }
638
639                 if( *psz_broadcast )
640                 {
641                     *psz_broadcast = '\0';
642                     psz_broadcast++;
643                     while( *psz_broadcast && *psz_broadcast == ':' )
644                     {
645                         psz_broadcast++;
646                     }
647                 }
648                 else
649                 {
650                     psz_broadcast = NULL;
651                 }
652
653                 /* port before broadcast address */
654                 if( *psz_port != ':' )
655                 {
656                     i_port = atoi( psz_port );
657                 }
658             }
659         }
660         else
661         {
662             psz_server = NULL;
663         }
664     }
665
666     /* Check that we got a valid server */
667     if( psz_server == NULL )
668     {
669         psz_server = main_GetPszVariable( INPUT_SERVER_VAR, 
670                                           INPUT_SERVER_DEFAULT );
671     }
672
673     /* Check that we got a valid port */
674     if( i_port == 0 )
675     {
676         i_port = main_GetIntVariable( INPUT_PORT_VAR, INPUT_PORT_DEFAULT );
677     }
678
679     if( psz_broadcast == NULL )
680     {
681         /* Are we broadcasting ? */
682         if( main_GetIntVariable( INPUT_BROADCAST_VAR,
683                                  INPUT_BROADCAST_DEFAULT ) )
684         {
685             psz_broadcast = main_GetPszVariable( INPUT_BCAST_ADDR_VAR,
686                                                  INPUT_BCAST_ADDR_DEFAULT );
687         }
688         else
689         {
690            psz_broadcast = NULL; 
691         }
692     }
693
694     intf_WarnMsg( 2, "input: server: %s port: %d broadcast: %s",
695                      psz_server, i_port, psz_broadcast );
696
697     /* Open a SOCK_DGRAM (UDP) socket, in the AF_INET domain, automatic (0)
698      * protocol */
699     p_input->i_handle = socket( AF_INET, SOCK_DGRAM, 0 );
700     if( p_input->i_handle == -1 )
701     {
702         intf_ErrMsg("input error: can't create socket : %s", strerror(errno));
703         p_input->b_error = 1;
704         return;
705     }
706
707     /* We may want to reuse an already used socket */
708     i_opt = 1;
709     if( setsockopt( p_input->i_handle, SOL_SOCKET, SO_REUSEADDR,
710                     &i_opt, sizeof( i_opt ) ) == -1 )
711     {
712         intf_ErrMsg( "input error: can't configure socket (SO_REUSEADDR: %s)",
713                      strerror(errno));
714         close( p_input->i_handle );
715         p_input->b_error = 1;
716         return;
717     }
718
719     /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to avoid
720      * packet loss caused by scheduling problems */
721     i_opt = 0x80000;
722     if( setsockopt( p_input->i_handle, SOL_SOCKET, SO_RCVBUF,
723                     &i_opt, sizeof( i_opt ) ) == -1 )
724     {
725         intf_ErrMsg( "input error: can't configure socket (SO_RCVBUF: %s)", 
726                      strerror(errno));
727         close( p_input->i_handle );
728         p_input->b_error = 1;
729         return;
730     }
731
732     /* Build the local socket */
733     if ( network_BuildLocalAddr( &sock, i_port, psz_broadcast ) == -1 )
734     {
735         intf_ErrMsg( "input error: can't build local address" );
736         close( p_input->i_handle );
737         p_input->b_error = 1;
738         return;
739     }
740     
741     /* Bind it */
742     if( bind( p_input->i_handle, (struct sockaddr *)&sock, 
743               sizeof( sock ) ) < 0 )
744     {
745         intf_ErrMsg("input error: can't bind socket (%s)", strerror(errno));
746         close( p_input->i_handle );
747         p_input->b_error = 1;
748         return;
749     }
750
751     /* Build socket for remote connection */
752     if ( network_BuildRemoteAddr( &sock, psz_server ) == -1 )
753     {
754         intf_ErrMsg( "input error: can't build remote address" );
755         close( p_input->i_handle );
756         p_input->b_error = 1;
757         return;
758     }
759
760     /* And connect it ... should we really connect ? */
761     if( connect( p_input->i_handle, (struct sockaddr *) &sock,
762                  sizeof( sock ) ) == (-1) )
763     {
764         intf_ErrMsg( "input error: can't connect socket, %s", 
765                      strerror(errno) );
766         close( p_input->i_handle );
767         p_input->b_error = 1;
768         return;
769     }
770
771     /* We can't pace control, but FIXME : bug in meuuh's code to sync PCR
772      * with the server. */
773     p_input->stream.b_pace_control = 0;
774     p_input->stream.b_seekable = 0;
775
776     intf_WarnMsg( 3, "input: successfully opened network mode" );
777     
778     return;
779 }
780
781 /*****************************************************************************
782  * NetworkClose : close a network socket
783  *****************************************************************************/
784 static void NetworkClose( input_thread_t * p_input )
785 {
786     close( p_input->i_handle );
787
788 #ifdef WIN32 
789     WSACleanup();
790 #endif
791
792 }
793 #endif
794