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 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_access.h>
36 #include <vlc_network.h>
38 /*****************************************************************************
40 *****************************************************************************/
41 #define CACHING_TEXT N_("Caching value in ms")
42 #define CACHING_LONGTEXT N_( \
43 "Caching value for TCP streams. This " \
44 "value should be set in milliseconds." )
46 static int Open ( vlc_object_t * );
47 static void Close( vlc_object_t * );
50 set_shortname( N_("TCP") );
51 set_description( N_("TCP input") );
52 set_category( CAT_INPUT );
53 set_subcategory( SUBCAT_INPUT_ACCESS );
55 add_integer( "tcp-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT,
56 CACHING_LONGTEXT, true );
58 set_capability( "access", 0 );
59 add_shortcut( "tcp" );
60 set_callbacks( Open, Close );
63 /*****************************************************************************
65 *****************************************************************************/
72 static ssize_t Read( access_t *, uint8_t *, size_t );
73 static int Control( access_t *, int, va_list );
75 /*****************************************************************************
76 * Open: open the socket
77 *****************************************************************************/
78 static int Open( vlc_object_t *p_this )
80 access_t *p_access = (access_t *)p_this;
83 char *psz_dup = strdup(p_access->psz_path);
84 char *psz_parser = psz_dup;
86 /* Parse server:port */
87 if( *psz_parser == '[' )
89 psz_parser = strchr( psz_parser, ']' );
90 if( psz_parser == NULL )
93 psz_parser = strchr( psz_parser, ':' );
95 if( psz_parser == NULL )
97 msg_Err( p_access, "missing port number : %s", psz_dup );
102 *psz_parser++ = '\0';
105 access_InitFields( p_access ); \
106 ACCESS_SET_CALLBACKS( Read, NULL, Control, NULL ); \
107 MALLOC_ERR( p_access->p_sys, access_sys_t ); \
108 p_sys = p_access->p_sys; memset( p_sys, 0, sizeof( access_sys_t ) );
110 p_sys->fd = net_ConnectTCP( p_access, psz_dup, atoi( psz_parser ) );
119 /* Update default_pts to a suitable value for udp access */
120 var_Create( p_access, "tcp-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
125 /*****************************************************************************
126 * Close: free unused data structures
127 *****************************************************************************/
128 static void Close( vlc_object_t *p_this )
130 access_t *p_access = (access_t *)p_this;
131 access_sys_t *p_sys = p_access->p_sys;
133 net_Close( p_sys->fd );
137 /*****************************************************************************
138 * Read: read on a file descriptor
139 *****************************************************************************/
140 static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
142 access_sys_t *p_sys = p_access->p_sys;
145 if( p_access->info.b_eof )
148 i_read = net_Read( p_access, p_sys->fd, NULL, p_buffer, i_len,
151 p_access->info.b_eof = true;
152 else if( i_read > 0 )
153 p_access->info.i_pos += i_read;
158 /*****************************************************************************
160 *****************************************************************************/
161 static int Control( access_t *p_access, int i_query, va_list args )
170 case ACCESS_CAN_SEEK:
171 case ACCESS_CAN_FASTSEEK:
172 pb_bool = (bool*)va_arg( args, bool* );
175 case ACCESS_CAN_PAUSE:
176 pb_bool = (bool*)va_arg( args, bool* );
177 *pb_bool = true; /* FIXME */
179 case ACCESS_CAN_CONTROL_PACE:
180 pb_bool = (bool*)va_arg( args, bool* );
181 *pb_bool = true; /* FIXME */
186 pi_int = (int*)va_arg( args, int * );
190 case ACCESS_GET_PTS_DELAY:
191 pi_64 = (int64_t*)va_arg( args, int64_t * );
192 *pi_64 = (int64_t)var_GetInteger( p_access, "tcp-caching" ) * INT64_C(1000);
196 case ACCESS_SET_PAUSE_STATE:
200 case ACCESS_GET_TITLE_INFO:
201 case ACCESS_SET_TITLE:
202 case ACCESS_SET_SEEKPOINT:
203 case ACCESS_SET_PRIVATE_ID_STATE:
204 case ACCESS_GET_CONTENT_TYPE:
208 msg_Warn( p_access, "unimplemented query in control" );