00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028
00029 #include <vlc/vlc.h>
00030 #include <vlc/input.h>
00031
00032 #include "network.h"
00033
00034
00035
00036
00037 #define CACHING_TEXT N_("Caching value in ms")
00038 #define CACHING_LONGTEXT N_( \
00039 "Allows you to modify the default caching value for TCP streams. This " \
00040 "value should be set in millisecond units." )
00041
00042 static int Open ( vlc_object_t * );
00043 static void Close( vlc_object_t * );
00044
00045 vlc_module_begin();
00046 set_shortname( _("TCP") );
00047 set_description( _("TCP input") );
00048 set_category( CAT_INPUT );
00049 set_subcategory( SUBCAT_INPUT_ACCESS );
00050
00051 add_integer( "tcp-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT,
00052 CACHING_LONGTEXT, VLC_TRUE );
00053
00054 set_capability( "access2", 0 );
00055 add_shortcut( "tcp" );
00056 set_callbacks( Open, Close );
00057 vlc_module_end();
00058
00059
00060
00061
00062 struct access_sys_t
00063 {
00064 int fd;
00065 };
00066
00067
00068 static int Read( access_t *, uint8_t *, int );
00069 static int Control( access_t *, int, va_list );
00070
00071
00072
00073
00074 static int Open( vlc_object_t *p_this )
00075 {
00076 access_t *p_access = (access_t *)p_this;
00077 access_sys_t *p_sys;
00078
00079 char *psz_dup = strdup(p_access->psz_path);
00080 char *psz_parser = psz_dup;
00081
00082
00083 if( *psz_parser == '[' )
00084 {
00085 psz_parser = strchr( psz_parser, ']' );
00086 if( psz_parser == NULL )
00087 psz_parser = psz_dup;
00088 }
00089 psz_parser = strchr( psz_parser, ':' );
00090
00091 if( psz_parser == NULL )
00092 {
00093 msg_Err( p_access, "missing port number : %s", psz_dup );
00094 free( psz_dup );
00095 return VLC_EGENERIC;
00096 }
00097
00098 *psz_parser++ = '\0';
00099
00100
00101 p_access->pf_read = Read;
00102 p_access->pf_block = NULL;
00103 p_access->pf_control = Control;
00104 p_access->pf_seek = NULL;
00105 p_access->info.i_update = 0;
00106 p_access->info.i_size = 0;
00107 p_access->info.i_pos = 0;
00108 p_access->info.b_eof = VLC_FALSE;
00109 p_access->info.i_title = 0;
00110 p_access->info.i_seekpoint = 0;
00111 p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
00112
00113 p_sys->fd = net_OpenTCP( p_access, psz_dup, atoi( psz_parser ) );
00114 free( psz_dup );
00115
00116 if( p_sys->fd < 0 )
00117 {
00118 free( p_sys );
00119 return VLC_EGENERIC;
00120 }
00121
00122
00123 var_Create( p_access, "tcp-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00124
00125 return VLC_SUCCESS;
00126 }
00127
00128
00129
00130
00131 static void Close( vlc_object_t *p_this )
00132 {
00133 access_t *p_access = (access_t *)p_this;
00134 access_sys_t *p_sys = p_access->p_sys;
00135
00136 net_Close( p_sys->fd );
00137 free( p_sys );
00138 }
00139
00140
00141
00142
00143 static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
00144 {
00145 access_sys_t *p_sys = p_access->p_sys;
00146 int i_read;
00147
00148 if( p_access->info.b_eof )
00149 return 0;
00150
00151 i_read = net_Read( p_access, p_sys->fd, NULL, p_buffer, i_len,
00152 VLC_FALSE );
00153 if( i_read == 0 )
00154 p_access->info.b_eof = VLC_TRUE;
00155 else if( i_read > 0 )
00156 p_access->info.i_pos += i_read;
00157
00158 return i_read;
00159 }
00160
00161
00162
00163
00164 static int Control( access_t *p_access, int i_query, va_list args )
00165 {
00166 vlc_bool_t *pb_bool;
00167 int *pi_int;
00168 int64_t *pi_64;
00169
00170 switch( i_query )
00171 {
00172
00173 case ACCESS_CAN_SEEK:
00174 case ACCESS_CAN_FASTSEEK:
00175 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
00176 *pb_bool = VLC_FALSE;
00177 break;
00178 case ACCESS_CAN_PAUSE:
00179 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
00180 *pb_bool = VLC_TRUE;
00181 break;
00182 case ACCESS_CAN_CONTROL_PACE:
00183 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
00184 *pb_bool = VLC_TRUE;
00185 break;
00186
00187
00188 case ACCESS_GET_MTU:
00189 pi_int = (int*)va_arg( args, int * );
00190 *pi_int = 0;
00191 break;
00192
00193 case ACCESS_GET_PTS_DELAY:
00194 pi_64 = (int64_t*)va_arg( args, int64_t * );
00195 *pi_64 = (int64_t)var_GetInteger( p_access, "tcp-caching" ) * I64C(1000);
00196 break;
00197
00198
00199 case ACCESS_SET_PAUSE_STATE:
00200
00201 break;
00202
00203 case ACCESS_GET_TITLE_INFO:
00204 case ACCESS_SET_TITLE:
00205 case ACCESS_SET_SEEKPOINT:
00206 case ACCESS_SET_PRIVATE_ID_STATE:
00207 return VLC_EGENERIC;
00208
00209 default:
00210 msg_Warn( p_access, "unimplemented query in control" );
00211 return VLC_EGENERIC;
00212
00213 }
00214 return VLC_SUCCESS;
00215 }