tcp.c 3.56 KB
Newer Older
1
/*****************************************************************************
2
 * tcp.c: TCP input module
3
 *****************************************************************************
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2003-2004 VLC authors and VideoLAN
5
 * $Id$
6 7 8
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
9 10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12 13 14 15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
19 20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23
 *****************************************************************************/

24 25 26 27
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

28 29
#include <errno.h>

30
#include <vlc_common.h>
31
#include <vlc_plugin.h>
32
#include <vlc_access.h>
33 34
#include <vlc_url.h>
#include <vlc_tls.h>
35

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
36
static ssize_t Read(stream_t *access, void *buf, size_t len)
37
{
38
    return vlc_tls_Read(access->p_sys, buf, len, false);
39 40
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
41
static int Control( stream_t *p_access, int i_query, va_list args )
42
{
43 44
    bool    *pb_bool;
    int64_t *pi_64;
45

46 47
    switch( i_query )
    {
48 49
        case STREAM_CAN_SEEK:
        case STREAM_CAN_FASTSEEK:
50
            pb_bool = va_arg( args, bool * );
51
            *pb_bool = false;
52
            break;
53
        case STREAM_CAN_PAUSE:
54
            pb_bool = va_arg( args, bool * );
55
            *pb_bool = true;    /* FIXME */
56
            break;
57
        case STREAM_CAN_CONTROL_PACE:
58
            pb_bool = va_arg( args, bool * );
59
            *pb_bool = true;    /* FIXME */
60 61
            break;

62
        case STREAM_GET_PTS_DELAY:
63
            pi_64 = va_arg( args, int64_t * );
64 65
            *pi_64 = INT64_C(1000)
                   * var_InheritInteger( p_access, "network-caching" );
66 67
            break;

68
        case STREAM_SET_PAUSE_STATE:
69 70 71 72 73 74 75
            /* Nothing to do */
            break;

        default:
            return VLC_EGENERIC;
    }
    return VLC_SUCCESS;
76
}
77 78 79

static int Open(vlc_object_t *obj)
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
80
    stream_t *access = (stream_t *)obj;
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    vlc_tls_t *sock;
    vlc_url_t url;

    if (vlc_UrlParse(&url, access->psz_url)
     || url.psz_host == NULL || url.i_port == 0)
    {
        msg_Err(access, "invalid location: %s", access->psz_location);
        vlc_UrlClean(&url);
        return VLC_EGENERIC;
    }

    sock = vlc_tls_SocketOpenTCP(obj, url.psz_host, url.i_port);
    vlc_UrlClean(&url);
    if (sock == NULL)
        return VLC_EGENERIC;

    access->p_sys = sock;
    access->pf_read = Read;
    access->pf_block = NULL;
    access->pf_control = Control;
    access->pf_seek = NULL;
    return VLC_SUCCESS;
}

static void Close( vlc_object_t *p_this )
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
107
    stream_t *access = (stream_t *)p_this;
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124

    vlc_tls_SessionDelete(access->p_sys);
}

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
vlc_module_begin ()
    set_shortname( N_("TCP") )
    set_description( N_("TCP input") )
    set_category( CAT_INPUT )
    set_subcategory( SUBCAT_INPUT_ACCESS )

    set_capability( "access", 0 )
    add_shortcut( "tcp" )
    set_callbacks( Open, Close )
vlc_module_end ()