qt: playlist: use item title if available
[vlc.git] / modules / access / tcp.c
blob214a5853be7201753ee2c4dd31d0c69f7ee40a3c
1 /*****************************************************************************
2 * tcp.c: TCP input module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 VLC authors and VideoLAN
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <errno.h>
29 #include <vlc_common.h>
30 #include <vlc_plugin.h>
31 #include <vlc_access.h>
32 #include <vlc_url.h>
33 #include <vlc_tls.h>
35 static ssize_t Read(stream_t *access, void *buf, size_t len)
37 return vlc_tls_Read(access->p_sys, buf, len, false);
40 static int Control( stream_t *p_access, int i_query, va_list args )
42 bool *pb_bool;
44 switch( i_query )
46 case STREAM_CAN_SEEK:
47 case STREAM_CAN_FASTSEEK:
48 pb_bool = va_arg( args, bool * );
49 *pb_bool = false;
50 break;
51 case STREAM_CAN_PAUSE:
52 pb_bool = va_arg( args, bool * );
53 *pb_bool = true; /* FIXME */
54 break;
55 case STREAM_CAN_CONTROL_PACE:
56 pb_bool = va_arg( args, bool * );
57 *pb_bool = true; /* FIXME */
58 break;
60 case STREAM_GET_PTS_DELAY:
61 *va_arg( args, vlc_tick_t * ) =
62 VLC_TICK_FROM_MS(var_InheritInteger( p_access, "network-caching" ));
63 break;
65 case STREAM_SET_PAUSE_STATE:
66 /* Nothing to do */
67 break;
69 default:
70 return VLC_EGENERIC;
72 return VLC_SUCCESS;
75 static int Open(vlc_object_t *obj)
77 stream_t *access = (stream_t *)obj;
78 vlc_tls_t *sock;
79 vlc_url_t url;
81 if (vlc_UrlParse(&url, access->psz_url)
82 || url.psz_host == NULL || url.i_port == 0)
84 msg_Err(access, "invalid location: %s", access->psz_location);
85 vlc_UrlClean(&url);
86 return VLC_EGENERIC;
89 sock = vlc_tls_SocketOpenTCP(obj, url.psz_host, url.i_port);
90 vlc_UrlClean(&url);
91 if (sock == NULL)
92 return VLC_EGENERIC;
94 access->p_sys = sock;
95 access->pf_read = Read;
96 access->pf_block = NULL;
97 access->pf_control = Control;
98 access->pf_seek = NULL;
99 return VLC_SUCCESS;
102 static void Close( vlc_object_t *p_this )
104 stream_t *access = (stream_t *)p_this;
106 vlc_tls_SessionDelete(access->p_sys);
109 /*****************************************************************************
110 * Module descriptor
111 *****************************************************************************/
112 vlc_module_begin ()
113 set_shortname( N_("TCP") )
114 set_description( N_("TCP input") )
115 set_category( CAT_INPUT )
116 set_subcategory( SUBCAT_INPUT_ACCESS )
118 set_capability( "access", 0 )
119 add_shortcut( "tcp" )
120 set_callbacks( Open, Close )
121 vlc_module_end ()