1 /*****************************************************************************
2 * tcp.c: TCP input module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 VLC authors and VideoLAN
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 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_access.h>
36 #include <vlc_network.h>
38 /*****************************************************************************
40 *****************************************************************************/
41 static int Open ( vlc_object_t
* );
42 static void Close( vlc_object_t
* );
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 )
52 set_callbacks( Open
, Close
)
55 /*****************************************************************************
57 *****************************************************************************/
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
;
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
)
85 psz_parser
= strchr( psz_parser
, ':' );
87 if( psz_parser
== NULL
)
89 msg_Err( p_access
, "missing port number : %s", psz_dup
);
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
) );
106 p_sys
->fd
= net_ConnectTCP( p_access
, psz_dup
, atoi( psz_parser
) );
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
);
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
;
138 if( p_access
->info
.b_eof
)
141 i_read
= net_Read( p_access
, p_sys
->fd
, NULL
, p_buffer
, i_len
,
144 p_access
->info
.b_eof
= true;
145 else if( i_read
> 0 )
146 p_access
->info
.i_pos
+= i_read
;
151 /*****************************************************************************
153 *****************************************************************************/
154 static int Control( access_t
*p_access
, int i_query
, va_list args
)
161 case ACCESS_CAN_SEEK
:
162 case ACCESS_CAN_FASTSEEK
:
163 pb_bool
= (bool*)va_arg( args
, bool* );
166 case ACCESS_CAN_PAUSE
:
167 pb_bool
= (bool*)va_arg( args
, bool* );
168 *pb_bool
= true; /* FIXME */
170 case ACCESS_CAN_CONTROL_PACE
:
171 pb_bool
= (bool*)va_arg( args
, bool* );
172 *pb_bool
= true; /* FIXME */
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" );
181 case ACCESS_SET_PAUSE_STATE
: