1 /*****************************************************************************
2 * tcp.c: TCP access plug-in
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: tcp.c,v 1.3 2004/01/05 15:07:16 fenrir Exp $
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 udp streams. This " \
40 "value should be set in miliseconds units." )
42 static int Open ( vlc_object_t * );
43 static void Close( vlc_object_t * );
46 set_description( _("TCP input") );
47 add_category_hint( N_("TCP"), NULL , VLC_TRUE );
48 add_integer( "tcp-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
49 set_capability( "access", 0 );
50 add_shortcut( "tcp" );
51 set_callbacks( Open, Close );
55 /*****************************************************************************
57 *****************************************************************************/
63 static ssize_t Read ( input_thread_t *, byte_t *, size_t );
65 /*****************************************************************************
66 * Open: open the socket
67 *****************************************************************************/
68 static int Open( vlc_object_t *p_this )
70 input_thread_t *p_input = (input_thread_t *)p_this;
73 char *psz_dup = strdup(p_input->psz_name);
74 char *psz_parser = psz_dup;
78 /* Parse server:port */
79 while( *psz_parser && *psz_parser != ':' )
81 if( *psz_parser == '[' )
84 while( *psz_parser && *psz_parser != ']' )
91 if( *psz_parser != ':' || psz_parser == psz_dup )
93 msg_Err( p_input, "you have to provide server:port addresse" );
99 if( atoi( psz_parser ) <= 0 )
101 msg_Err( p_input, "invalid port number (%d)", atoi( psz_parser ) );
107 p_input->p_access_data = p_sys = malloc( sizeof( access_sys_t ) );
108 p_sys->fd = net_OpenTCP( p_input, psz_dup, atoi( psz_parser ) );
117 p_input->pf_read = Read;
118 p_input->pf_set_program = input_SetProgram;
119 p_input->pf_set_area = NULL;
120 p_input->pf_seek = NULL;
122 vlc_mutex_lock( &p_input->stream.stream_lock );
123 p_input->stream.b_pace_control = VLC_TRUE; /* FIXME ? */
124 p_input->stream.b_seekable = 0;
125 p_input->stream.p_selected_area->i_tell = 0;
126 p_input->stream.i_method = INPUT_METHOD_NETWORK;
128 vlc_mutex_unlock( &p_input->stream.stream_lock );
130 /* Update default_pts to a suitable value for udp access */
131 var_Create( p_input, "tcp-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
132 var_Get( p_input, "tcp-caching", &val );
133 p_input->i_pts_delay = val.i_int * 1000;
138 /*****************************************************************************
139 * Close: free unused data structures
140 *****************************************************************************/
141 static void Close( vlc_object_t *p_this )
143 input_thread_t *p_input = (input_thread_t *)p_this;
144 access_sys_t *p_sys = p_input->p_access_data;
146 msg_Info( p_input, "closing TCP target `%s'", p_input->psz_source );
148 net_Close( p_sys->fd );
152 /*****************************************************************************
153 * Read: read on a file descriptor, checking b_die periodically
154 *****************************************************************************/
155 static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
157 access_sys_t *p_sys = p_input->p_access_data;
159 return net_Read( p_input, p_sys->fd, p_buffer, i_len, VLC_FALSE );