contrib: theora: do not run autoreconf
[vlc/gmpfix.git] / modules / access / tcp.c
blob3fbf7f26c553461d233b4ab0ae90148d2270ff1e
1 /*****************************************************************************
2 * tcp.c: TCP input module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_access.h>
36 #include <vlc_network.h>
38 /*****************************************************************************
39 * Module descriptor
40 *****************************************************************************/
41 static int Open ( vlc_object_t * );
42 static void Close( vlc_object_t * );
44 vlc_module_begin ()
45 set_shortname( N_("TCP") )
46 set_description( N_("TCP input") )
47 set_category( CAT_INPUT )
48 set_subcategory( SUBCAT_INPUT_ACCESS )
50 set_capability( "access", 0 )
51 add_shortcut( "tcp" )
52 set_callbacks( Open, Close )
53 vlc_module_end ()
55 /*****************************************************************************
56 * Local prototypes
57 *****************************************************************************/
58 struct access_sys_t
60 int fd;
64 static ssize_t Read( access_t *, uint8_t *, size_t );
65 static int Control( access_t *, int, va_list );
67 /*****************************************************************************
68 * Open: open the socket
69 *****************************************************************************/
70 static int Open( vlc_object_t *p_this )
72 access_t *p_access = (access_t *)p_this;
73 access_sys_t *p_sys;
75 char *psz_dup = strdup(p_access->psz_location);
76 char *psz_parser = psz_dup;
78 /* Parse server:port */
79 if( *psz_parser == '[' )
81 psz_parser = strchr( psz_parser, ']' );
82 if( psz_parser == NULL )
83 psz_parser = psz_dup;
85 psz_parser = strchr( psz_parser, ':' );
87 if( psz_parser == NULL )
89 msg_Err( p_access, "missing port number : %s", psz_dup );
90 free( psz_dup );
91 return VLC_EGENERIC;
94 *psz_parser++ = '\0';
96 /* Init p_access */
97 access_InitFields( p_access );
98 ACCESS_SET_CALLBACKS( Read, NULL, Control, NULL );
99 p_sys = p_access->p_sys = calloc( 1, sizeof( access_sys_t ) );
100 if( !p_sys )
102 free( psz_dup );
103 return VLC_ENOMEM;
106 p_sys->fd = net_ConnectTCP( p_access, psz_dup, atoi( psz_parser ) );
107 free( psz_dup );
109 if( p_sys->fd < 0 )
111 free( p_sys );
112 return VLC_EGENERIC;
115 return VLC_SUCCESS;
118 /*****************************************************************************
119 * Close: free unused data structures
120 *****************************************************************************/
121 static void Close( vlc_object_t *p_this )
123 access_t *p_access = (access_t *)p_this;
124 access_sys_t *p_sys = p_access->p_sys;
126 net_Close( p_sys->fd );
127 free( p_sys );
130 /*****************************************************************************
131 * Read: read on a file descriptor
132 *****************************************************************************/
133 static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
135 access_sys_t *p_sys = p_access->p_sys;
136 int i_read;
138 if( p_access->info.b_eof )
139 return 0;
141 i_read = net_Read( p_access, p_sys->fd, NULL, p_buffer, i_len,
142 false );
143 if( i_read == 0 )
144 p_access->info.b_eof = true;
145 else if( i_read > 0 )
146 p_access->info.i_pos += i_read;
148 return i_read;
151 /*****************************************************************************
152 * Control:
153 *****************************************************************************/
154 static int Control( access_t *p_access, int i_query, va_list args )
156 bool *pb_bool;
157 int64_t *pi_64;
159 switch( i_query )
161 case ACCESS_CAN_SEEK:
162 case ACCESS_CAN_FASTSEEK:
163 pb_bool = (bool*)va_arg( args, bool* );
164 *pb_bool = false;
165 break;
166 case ACCESS_CAN_PAUSE:
167 pb_bool = (bool*)va_arg( args, bool* );
168 *pb_bool = true; /* FIXME */
169 break;
170 case ACCESS_CAN_CONTROL_PACE:
171 pb_bool = (bool*)va_arg( args, bool* );
172 *pb_bool = true; /* FIXME */
173 break;
175 case ACCESS_GET_PTS_DELAY:
176 pi_64 = (int64_t*)va_arg( args, int64_t * );
177 *pi_64 = INT64_C(1000)
178 * var_InheritInteger( p_access, "network-caching" );
179 break;
181 case ACCESS_SET_PAUSE_STATE:
182 /* Nothing to do */
183 break;
185 default:
186 return VLC_EGENERIC;
188 return VLC_SUCCESS;