1 /*****************************************************************************
2 * tcp.c: TCP input module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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 *****************************************************************************/
30 #include <vlc/input.h>
34 /*****************************************************************************
36 *****************************************************************************/
37 #define CACHING_TEXT N_("Caching value in ms")
38 #define CACHING_LONGTEXT N_( \
39 "Allows you to modify the default caching value for TCP streams. This " \
40 "value should be set in millisecond units." )
42 static int Open ( vlc_object_t * );
43 static void Close( vlc_object_t * );
46 set_description( _("TCP input") );
48 add_integer( "tcp-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT,
49 CACHING_LONGTEXT, VLC_TRUE );
51 set_capability( "access2", 0 );
52 add_shortcut( "tcp" );
53 set_callbacks( Open, Close );
56 /*****************************************************************************
58 *****************************************************************************/
65 static int Read( access_t *, uint8_t *, int );
66 static int Control( access_t *, int, va_list );
68 /*****************************************************************************
69 * Open: open the socket
70 *****************************************************************************/
71 static int Open( vlc_object_t *p_this )
73 access_t *p_access = (access_t *)p_this;
76 char *psz_dup = strdup(p_access->psz_path);
77 char *psz_parser = psz_dup;
79 /* Parse server:port */
80 while( *psz_parser && *psz_parser != ':' )
82 if( *psz_parser == '[' )
85 while( *psz_parser && *psz_parser != ']' )
92 if( *psz_parser != ':' || psz_parser == psz_dup )
94 msg_Err( p_access, "you have to provide server:port addresse" );
100 if( atoi( psz_parser ) <= 0 )
102 msg_Err( p_access, "invalid port number (%d)", atoi( psz_parser ) );
108 p_access->pf_read = Read;
109 p_access->pf_block = NULL;
110 p_access->pf_control = Control;
111 p_access->pf_seek = NULL;
112 p_access->info.i_update = 0;
113 p_access->info.i_size = 0;
114 p_access->info.i_pos = 0;
115 p_access->info.b_eof = VLC_FALSE;
116 p_access->info.i_title = 0;
117 p_access->info.i_seekpoint = 0;
118 p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
120 p_sys->fd = net_OpenTCP( p_access, psz_dup, atoi( psz_parser ) );
129 /* Update default_pts to a suitable value for udp access */
130 var_Create( p_access, "tcp-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
135 /*****************************************************************************
136 * Close: free unused data structures
137 *****************************************************************************/
138 static void Close( vlc_object_t *p_this )
140 access_t *p_access = (access_t *)p_this;
141 access_sys_t *p_sys = p_access->p_sys;
143 net_Close( p_sys->fd );
147 /*****************************************************************************
148 * Read: read on a file descriptor, checking b_die periodically
149 *****************************************************************************/
150 static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
152 access_sys_t *p_sys = p_access->p_sys;
155 if( p_access->info.b_eof )
158 i_read = net_Read( p_access, p_sys->fd, p_buffer, i_len, VLC_FALSE );
160 p_access->info.b_eof = VLC_TRUE;
161 else if( i_read > 0 )
162 p_access->info.i_pos += i_read;
167 /*****************************************************************************
169 *****************************************************************************/
170 static int Control( access_t *p_access, int i_query, va_list args )
180 case ACCESS_CAN_SEEK:
181 case ACCESS_CAN_FASTSEEK:
182 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
183 *pb_bool = VLC_FALSE;
185 case ACCESS_CAN_PAUSE:
186 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
187 *pb_bool = VLC_TRUE; /* FIXME */
189 case ACCESS_CAN_CONTROL_PACE:
190 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
191 *pb_bool = VLC_TRUE; /* FIXME */
196 pi_int = (int*)va_arg( args, int * );
200 case ACCESS_GET_PTS_DELAY:
201 pi_64 = (int64_t*)va_arg( args, int64_t * );
202 var_Get( p_access, "tcp-caching", &val );
203 *pi_64 = val.i_int * 1000;
207 case ACCESS_SET_PAUSE_STATE:
211 case ACCESS_GET_TITLE_INFO:
212 case ACCESS_SET_TITLE:
213 case ACCESS_SET_SEEKPOINT:
217 msg_Err( p_access, "unimplemented query in control" );