~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to libmpdemux/stream_vstream.c

  • Committer: Reinhard Tartler
  • Date: 2006-07-08 08:45:33 UTC
  • Revision ID: siretart@tauware.de-20060708084533-dbc155bde7122e78
imported mplayer_0.99+1.0pre7try2+cvs20060117

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  stream_vstream.c
 
3
 *
 
4
 *      Copyright (C) Joey Parrish
 
5
 *
 
6
 *  This file is part of MPlayer, a free movie player.
 
7
 *      
 
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)
 
11
 *  any later version.
 
12
 *   
 
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.
 
17
 *   
 
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. 
 
21
 *
 
22
 *
 
23
 */
 
24
 
 
25
/*
 
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 .
 
32
 *
 
33
 */
 
34
 
 
35
 
 
36
#include "config.h"
 
37
 
 
38
#ifdef HAVE_VSTREAM
 
39
 
 
40
#include <sys/types.h>
 
41
#include <sys/stat.h>
 
42
#include <fcntl.h>
 
43
#include <unistd.h>
 
44
#include <stdarg.h>
 
45
 
 
46
#include <stdlib.h>
 
47
#include <stdio.h>
 
48
#include <inttypes.h>
 
49
#include <errno.h>
 
50
 
 
51
#include "mp_msg.h"
 
52
#include "stream.h"
 
53
#include "help_mp.h"
 
54
#include "m_option.h"
 
55
#include "m_struct.h"
 
56
 
 
57
#include <vstream-client.h>
 
58
 
 
59
void vstream_error(const char *format, ...) {
 
60
    char buf[1024];
 
61
    va_list va;
 
62
    va_start(va, format);
 
63
    vsnprintf(buf, 1024, format, va);
 
64
    va_end(va);
 
65
    mp_msg(MSGT_STREAM, MSGL_ERR, buf);
 
66
}
 
67
 
 
68
static struct stream_priv_s {
 
69
  char* host;
 
70
  char* fsid;
 
71
} stream_priv_dflts = {
 
72
  NULL,
 
73
  NULL
 
74
};
 
75
 
 
76
#define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
 
77
/// URL definition
 
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 }
 
82
};
 
83
 
 
84
static struct m_struct_st stream_opts = {
 
85
  "vstream",
 
86
  sizeof(struct stream_priv_s),
 
87
  &stream_priv_dflts,
 
88
  stream_opts_fields
 
89
};
 
90
 
 
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;
 
95
  return len;
 
96
}
 
97
 
 
98
static int seek(stream_t *s,off_t newpos) {
 
99
  s->pos = newpos;
 
100
  return 1;
 
101
}
 
102
 
 
103
static int control(struct stream_st *s,int cmd,void* arg) {
 
104
  return STREAM_UNSUPORTED;
 
105
}
 
106
 
 
107
static void close_s(struct stream_st *s) {
 
108
}
 
109
 
 
110
static int open_s(stream_t *stream, int mode, void* opts, int* file_format) {
 
111
  int f;
 
112
  struct stream_priv_s* p = (struct stream_priv_s*)opts;
 
113
 
 
114
  if(mode != STREAM_READ)
 
115
    return STREAM_UNSUPORTED;
 
116
 
 
117
  if(!p->host) {
 
118
    mp_msg(MSGT_OPEN, MSGL_ERR, "We need a host name (ex: tivo://hostname/fsid)\n");
 
119
    m_struct_free(&stream_opts, opts);
 
120
    return STREAM_ERROR;
 
121
  }
 
122
 
 
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);
 
126
    return STREAM_ERROR;
 
127
  }
 
128
 
 
129
  f = connect2Server(p->host, VSERVER_PORT, 1);
 
130
 
 
131
  if(f < 0) {
 
132
    mp_msg(MSGT_OPEN, MSGL_ERR, "Connection to %s failed\n", p->host);
 
133
    m_struct_free(&stream_opts, opts);
 
134
    return STREAM_ERROR;
 
135
  }
 
136
  stream->fd = f;
 
137
 
 
138
  vstream_set_socket_fd(f);
 
139
 
 
140
  if (!strcmp(p->fsid, "list")) {
 
141
    vstream_list_streams(0);
 
142
    return STREAM_ERROR;
 
143
  } else if (!strcmp(p->fsid, "llist")) {
 
144
    vstream_list_streams(1);
 
145
    return STREAM_ERROR;
 
146
  }
 
147
 
 
148
  if (vstream_start()) {
 
149
    mp_msg(MSGT_OPEN, MSGL_ERR, "Cryptic internal error #1\n");
 
150
    m_struct_free(&stream_opts, opts);
 
151
    return STREAM_ERROR;
 
152
  }
 
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);
 
156
    return STREAM_ERROR;
 
157
  }
 
158
  
 
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);
 
162
 
 
163
  stream->priv = p;
 
164
  stream->fill_buffer = fill_buffer;
 
165
  stream->control = control;
 
166
  stream->seek = seek;
 
167
  stream->close = close_s;
 
168
  stream->type = STREAMTYPE_VSTREAM;
 
169
 
 
170
  return STREAM_OK;
 
171
}
 
172
 
 
173
stream_info_t stream_info_vstream = {
 
174
  "vstream client",
 
175
  "vstream",
 
176
  "Joey",
 
177
  "",
 
178
  open_s,
 
179
  { "tivo", NULL },
 
180
  &stream_opts,
 
181
  1 // Url is an option string
 
182
};
 
183
 
 
184
#endif