add_savefile: remove callback parameter
[vlc/asuraparaju-public.git] / modules / access / tcp.c
blob7b111f0ca055c7d77c1d4450cf569626e1e91365
1 /*****************************************************************************
2 * tcp.c: TCP input module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
5 * $Id$
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 /*****************************************************************************
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 #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 * );
49 vlc_module_begin ()
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 )
57 change_safe()
59 set_capability( "access", 0 )
60 add_shortcut( "tcp" )
61 set_callbacks( Open, Close )
62 vlc_module_end ()
64 /*****************************************************************************
65 * Local prototypes
66 *****************************************************************************/
67 struct access_sys_t
69 int fd;
73 static ssize_t Read( access_t *, uint8_t *, size_t );
74 static int Control( access_t *, int, va_list );
76 /*****************************************************************************
77 * Open: open the socket
78 *****************************************************************************/
79 static int Open( vlc_object_t *p_this )
81 access_t *p_access = (access_t *)p_this;
82 access_sys_t *p_sys;
84 char *psz_dup = strdup(p_access->psz_location);
85 char *psz_parser = psz_dup;
87 /* Parse server:port */
88 if( *psz_parser == '[' )
90 psz_parser = strchr( psz_parser, ']' );
91 if( psz_parser == NULL )
92 psz_parser = psz_dup;
94 psz_parser = strchr( psz_parser, ':' );
96 if( psz_parser == NULL )
98 msg_Err( p_access, "missing port number : %s", psz_dup );
99 free( psz_dup );
100 return VLC_EGENERIC;
103 *psz_parser++ = '\0';
105 /* Init p_access */
106 access_InitFields( p_access );
107 ACCESS_SET_CALLBACKS( Read, NULL, Control, NULL );
108 p_sys = p_access->p_sys = calloc( 1, sizeof( access_sys_t ) );
109 if( !p_sys )
111 free( psz_dup );
112 return VLC_ENOMEM;
115 p_sys->fd = net_ConnectTCP( p_access, psz_dup, atoi( psz_parser ) );
116 free( psz_dup );
118 if( p_sys->fd < 0 )
120 free( p_sys );
121 return VLC_EGENERIC;
124 /* Update default_pts to a suitable value for udp access */
125 var_Create( p_access, "tcp-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
127 return VLC_SUCCESS;
130 /*****************************************************************************
131 * Close: free unused data structures
132 *****************************************************************************/
133 static void Close( vlc_object_t *p_this )
135 access_t *p_access = (access_t *)p_this;
136 access_sys_t *p_sys = p_access->p_sys;
138 net_Close( p_sys->fd );
139 free( p_sys );
142 /*****************************************************************************
143 * Read: read on a file descriptor
144 *****************************************************************************/
145 static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
147 access_sys_t *p_sys = p_access->p_sys;
148 int i_read;
150 if( p_access->info.b_eof )
151 return 0;
153 i_read = net_Read( p_access, p_sys->fd, NULL, p_buffer, i_len,
154 false );
155 if( i_read == 0 )
156 p_access->info.b_eof = true;
157 else if( i_read > 0 )
158 p_access->info.i_pos += i_read;
160 return i_read;
163 /*****************************************************************************
164 * Control:
165 *****************************************************************************/
166 static int Control( access_t *p_access, int i_query, va_list args )
168 bool *pb_bool;
169 int64_t *pi_64;
171 switch( i_query )
173 /* */
174 case ACCESS_CAN_SEEK:
175 case ACCESS_CAN_FASTSEEK:
176 pb_bool = (bool*)va_arg( args, bool* );
177 *pb_bool = false;
178 break;
179 case ACCESS_CAN_PAUSE:
180 pb_bool = (bool*)va_arg( args, bool* );
181 *pb_bool = true; /* FIXME */
182 break;
183 case ACCESS_CAN_CONTROL_PACE:
184 pb_bool = (bool*)va_arg( args, bool* );
185 *pb_bool = true; /* FIXME */
186 break;
188 case ACCESS_GET_PTS_DELAY:
189 pi_64 = (int64_t*)va_arg( args, int64_t * );
190 *pi_64 = var_GetInteger( p_access, "tcp-caching" ) * INT64_C(1000);
191 break;
193 /* */
194 case ACCESS_SET_PAUSE_STATE:
195 /* Nothing to do */
196 break;
198 case ACCESS_GET_TITLE_INFO:
199 case ACCESS_SET_TITLE:
200 case ACCESS_SET_SEEKPOINT:
201 case ACCESS_SET_PRIVATE_ID_STATE:
202 case ACCESS_GET_CONTENT_TYPE:
203 return VLC_EGENERIC;
205 default:
206 msg_Warn( p_access, "unimplemented query in control" );
207 return VLC_EGENERIC;
210 return VLC_SUCCESS;