1 /*****************************************************************************
2 * tcp.c: TCP input module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
29 #include <vlc_access.h>
31 #include <vlc_network.h>
33 /*****************************************************************************
35 *****************************************************************************/
36 #define CACHING_TEXT N_("Caching value in ms")
37 #define CACHING_LONGTEXT N_( \
38 "Caching value for TCP streams. This " \
39 "value should be set in milliseconds." )
41 static int Open ( vlc_object_t * );
42 static void Close( vlc_object_t * );
45 set_shortname( _("TCP") );
46 set_description( _("TCP input") );
47 set_category( CAT_INPUT );
48 set_subcategory( SUBCAT_INPUT_ACCESS );
50 add_integer( "tcp-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT,
51 CACHING_LONGTEXT, VLC_TRUE );
54 set_capability( "access2", 0 );
55 add_shortcut( "tcp" );
56 set_callbacks( Open, Close );
59 /*****************************************************************************
61 *****************************************************************************/
68 static ssize_t Read( access_t *, uint8_t *, size_t );
69 static int Control( access_t *, int, va_list );
71 /*****************************************************************************
72 * Open: open the socket
73 *****************************************************************************/
74 static int Open( vlc_object_t *p_this )
76 access_t *p_access = (access_t *)p_this;
79 char *psz_dup = strdup(p_access->psz_path);
80 char *psz_parser = psz_dup;
82 /* Parse server:port */
83 if( *psz_parser == '[' )
85 psz_parser = strchr( psz_parser, ']' );
86 if( psz_parser == NULL )
89 psz_parser = strchr( psz_parser, ':' );
91 if( psz_parser == NULL )
93 msg_Err( p_access, "missing port number : %s", psz_dup );
101 access_InitFields( p_access ); \
102 ACCESS_SET_CALLBACKS( Read, NULL, Control, NULL ); \
103 MALLOC_ERR( p_access->p_sys, access_sys_t ); \
104 p_sys = p_access->p_sys; memset( p_sys, 0, sizeof( access_sys_t ) );
106 p_sys->fd = net_ConnectTCP( p_access, psz_dup, atoi( psz_parser ) );
115 /* Update default_pts to a suitable value for udp access */
116 var_Create( p_access, "tcp-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
121 /*****************************************************************************
122 * Close: free unused data structures
123 *****************************************************************************/
124 static void Close( vlc_object_t *p_this )
126 access_t *p_access = (access_t *)p_this;
127 access_sys_t *p_sys = p_access->p_sys;
129 net_Close( p_sys->fd );
133 /*****************************************************************************
134 * Read: read on a file descriptor, checking b_die periodically
135 *****************************************************************************/
136 static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
138 access_sys_t *p_sys = p_access->p_sys;
141 if( p_access->info.b_eof )
144 i_read = net_Read( p_access, p_sys->fd, NULL, p_buffer, i_len,
147 p_access->info.b_eof = VLC_TRUE;
148 else if( i_read > 0 )
149 p_access->info.i_pos += i_read;
154 /*****************************************************************************
156 *****************************************************************************/
157 static int Control( access_t *p_access, int i_query, va_list args )
166 case ACCESS_CAN_SEEK:
167 case ACCESS_CAN_FASTSEEK:
168 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
169 *pb_bool = VLC_FALSE;
171 case ACCESS_CAN_PAUSE:
172 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
173 *pb_bool = VLC_TRUE; /* FIXME */
175 case ACCESS_CAN_CONTROL_PACE:
176 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
177 *pb_bool = VLC_TRUE; /* FIXME */
182 pi_int = (int*)va_arg( args, int * );
186 case ACCESS_GET_PTS_DELAY:
187 pi_64 = (int64_t*)va_arg( args, int64_t * );
188 *pi_64 = (int64_t)var_GetInteger( p_access, "tcp-caching" ) * I64C(1000);
192 case ACCESS_SET_PAUSE_STATE:
196 case ACCESS_GET_TITLE_INFO:
197 case ACCESS_SET_TITLE:
198 case ACCESS_SET_SEEKPOINT:
199 case ACCESS_SET_PRIVATE_ID_STATE:
200 case ACCESS_GET_CONTENT_TYPE:
204 msg_Warn( p_access, "unimplemented query in control" );