4
* Copyright (C) Joey Parrish
6
* This file is part of MPlayer, a free movie player.
8
* MPlayer is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2, or (at your option)
13
* MPlayer 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 General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with GNU Make; see the file COPYING. If not, write to
20
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26
* If you have a tivo with the vstream server installed, (and most tivo
27
* hackers do,) then you can connect to it and stream ty files using
28
* this module. The url syntax is tivo://host/fsid or tivo://host/list
29
* to list the available recordings and their fsid's.
30
* This module depends on libvstream-client, which is available from
31
* http://armory.nicewarrior.org/projects/vstream-client .
40
#include <sys/types.h>
57
#include <vstream-client.h>
59
void vstream_error(const char *format, ...) {
63
vsnprintf(buf, 1024, format, va);
65
mp_msg(MSGT_STREAM, MSGL_ERR, buf);
68
static struct stream_priv_s {
71
} stream_priv_dflts = {
76
#define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
78
static m_option_t stream_opts_fields[] = {
79
{"hostname", ST_OFF(host), CONF_TYPE_STRING, 0, 0 ,0, NULL},
80
{"filename", ST_OFF(fsid), CONF_TYPE_STRING, 0, 0 ,0, NULL},
81
{ NULL, NULL, 0, 0, 0, 0, NULL }
84
static struct m_struct_st stream_opts = {
86
sizeof(struct stream_priv_s),
91
static int fill_buffer(stream_t *s, char* buffer, int max_len){
92
struct stream_priv_s* p = (struct stream_priv_s*)s->priv;
93
int len = vstream_load_chunk(p->fsid, buffer, max_len, s->pos);
94
if (len <= 0) return 0;
98
static int seek(stream_t *s,off_t newpos) {
103
static int control(struct stream_st *s,int cmd,void* arg) {
104
return STREAM_UNSUPORTED;
107
static void close_s(struct stream_st *s) {
110
static int open_s(stream_t *stream, int mode, void* opts, int* file_format) {
112
struct stream_priv_s* p = (struct stream_priv_s*)opts;
114
if(mode != STREAM_READ)
115
return STREAM_UNSUPORTED;
118
mp_msg(MSGT_OPEN, MSGL_ERR, "We need a host name (ex: tivo://hostname/fsid)\n");
119
m_struct_free(&stream_opts, opts);
123
if(!p->fsid || strlen(p->fsid) == 0) {
124
mp_msg(MSGT_OPEN, MSGL_ERR, "We need an fsid (ex: tivo://hostname/fsid)\n");
125
m_struct_free(&stream_opts, opts);
129
f = connect2Server(p->host, VSERVER_PORT, 1);
132
mp_msg(MSGT_OPEN, MSGL_ERR, "Connection to %s failed\n", p->host);
133
m_struct_free(&stream_opts, opts);
138
vstream_set_socket_fd(f);
140
if (!strcmp(p->fsid, "list")) {
141
vstream_list_streams(0);
143
} else if (!strcmp(p->fsid, "llist")) {
144
vstream_list_streams(1);
148
if (vstream_start()) {
149
mp_msg(MSGT_OPEN, MSGL_ERR, "Cryptic internal error #1\n");
150
m_struct_free(&stream_opts, opts);
153
if (vstream_startstream(p->fsid)) {
154
mp_msg(MSGT_OPEN, MSGL_ERR, "Cryptic internal error #2\n");
155
m_struct_free(&stream_opts, opts);
159
stream->start_pos = 0;
160
stream->end_pos = vstream_streamsize();
161
mp_msg(MSGT_OPEN, MSGL_DBG2, "Tivo stream size is %d\n", stream->end_pos);
164
stream->fill_buffer = fill_buffer;
165
stream->control = control;
167
stream->close = close_s;
168
stream->type = STREAMTYPE_VSTREAM;
173
stream_info_t stream_info_vstream = {
181
1 // Url is an option string