Get rid of nonsensical limits on -geometry x, y,w and h values, they only
[mplayer/glamo.git] / stream / stream_vstream.c
blob4d0d972ebf18f968a1905a82b0fdd81bbbe13e1d
1 /*
2 * Copyright (C) Joey Parrish
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * If you have a tivo with the vstream server installed, (and most tivo
23 * hackers do,) then you can connect to it and stream ty files using
24 * this module. The url syntax is tivo://host/fsid or tivo://host/list
25 * to list the available recordings and their fsid's.
26 * This module depends on libvstream-client, which is available from
27 * http://armory.nicewarrior.org/projects/vstream-client .
32 #include "config.h"
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37 #include <unistd.h>
38 #include <stdarg.h>
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <inttypes.h>
43 #include <errno.h>
45 #include "mp_msg.h"
46 #include "stream.h"
47 #include "help_mp.h"
48 #include "m_option.h"
49 #include "m_struct.h"
50 #include "tcp.h"
52 #include <vstream-client.h>
54 void vstream_error(const char *format, ...) {
55 char buf[1024];
56 va_list va;
57 va_start(va, format);
58 vsnprintf(buf, 1024, format, va);
59 va_end(va);
60 mp_msg(MSGT_STREAM, MSGL_ERR, buf);
63 static struct stream_priv_s {
64 char* host;
65 char* fsid;
66 } stream_priv_dflts = {
67 NULL,
68 NULL
71 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
72 /// URL definition
73 static const m_option_t stream_opts_fields[] = {
74 {"hostname", ST_OFF(host), CONF_TYPE_STRING, 0, 0 ,0, NULL},
75 {"filename", ST_OFF(fsid), CONF_TYPE_STRING, 0, 0 ,0, NULL},
76 { NULL, NULL, 0, 0, 0, 0, NULL }
79 static const struct m_struct_st stream_opts = {
80 "vstream",
81 sizeof(struct stream_priv_s),
82 &stream_priv_dflts,
83 stream_opts_fields
86 static int fill_buffer(stream_t *s, char* buffer, int max_len){
87 struct stream_priv_s* p = (struct stream_priv_s*)s->priv;
88 int len = vstream_load_chunk(p->fsid, buffer, max_len, s->pos);
89 if (len <= 0) return 0;
90 return len;
93 static int seek(stream_t *s,off_t newpos) {
94 s->pos = newpos;
95 return 1;
98 static int control(struct stream_st *s,int cmd,void* arg) {
99 return STREAM_UNSUPPORTED;
102 static void close_s(struct stream_st *s) {
105 static int open_s(stream_t *stream, int mode, void* opts, int* file_format) {
106 int f;
107 struct stream_priv_s* p = (struct stream_priv_s*)opts;
109 if(mode != STREAM_READ)
110 return STREAM_UNSUPPORTED;
112 if(!p->host) {
113 mp_msg(MSGT_OPEN, MSGL_ERR, "We need a host name (ex: tivo://hostname/fsid)\n");
114 m_struct_free(&stream_opts, opts);
115 return STREAM_ERROR;
118 if(!p->fsid || strlen(p->fsid) == 0) {
119 mp_msg(MSGT_OPEN, MSGL_ERR, "We need an fsid (ex: tivo://hostname/fsid)\n");
120 m_struct_free(&stream_opts, opts);
121 return STREAM_ERROR;
124 f = connect2Server(p->host, VSERVER_PORT, 1);
126 if(f < 0) {
127 mp_msg(MSGT_OPEN, MSGL_ERR, "Connection to %s failed\n", p->host);
128 m_struct_free(&stream_opts, opts);
129 return STREAM_ERROR;
131 stream->fd = f;
133 vstream_set_socket_fd(f);
135 if (!strcmp(p->fsid, "list")) {
136 vstream_list_streams(0);
137 return STREAM_ERROR;
138 } else if (!strcmp(p->fsid, "llist")) {
139 vstream_list_streams(1);
140 return STREAM_ERROR;
143 if (vstream_start()) {
144 mp_msg(MSGT_OPEN, MSGL_ERR, "Cryptic internal error #1\n");
145 m_struct_free(&stream_opts, opts);
146 return STREAM_ERROR;
148 if (vstream_startstream(p->fsid)) {
149 mp_msg(MSGT_OPEN, MSGL_ERR, "Cryptic internal error #2\n");
150 m_struct_free(&stream_opts, opts);
151 return STREAM_ERROR;
154 stream->start_pos = 0;
155 stream->end_pos = vstream_streamsize();
156 mp_msg(MSGT_OPEN, MSGL_DBG2, "Tivo stream size is %d\n", stream->end_pos);
158 stream->priv = p;
159 stream->fill_buffer = fill_buffer;
160 stream->control = control;
161 stream->seek = seek;
162 stream->close = close_s;
163 stream->type = STREAMTYPE_VSTREAM;
165 return STREAM_OK;
168 const stream_info_t stream_info_vstream = {
169 "vstream client",
170 "vstream",
171 "Joey",
173 open_s,
174 { "tivo", NULL },
175 &stream_opts,
176 1 // Url is an option string