9886
|
1
|
|
2 #include "config.h"
|
|
3
|
|
4 #ifdef HAVE_VCD
|
|
5 #include "mp_msg.h"
|
|
6 #include "stream.h"
|
|
7 #include "help_mp.h"
|
|
8 #include "../m_option.h"
|
|
9 #include "../m_struct.h"
|
|
10
|
|
11 #include <stdlib.h>
|
|
12 #include <unistd.h>
|
|
13 #include <sys/ioctl.h>
|
|
14 #include <errno.h>
|
|
15
|
|
16 #ifdef __FreeBSD__
|
|
17 #include <sys/cdrio.h>
|
|
18 #include "vcd_read_fbsd.h"
|
|
19 #elif defined(__NetBSD__)
|
|
20 #include "vcd_read_nbsd.h"
|
|
21 #else
|
|
22 #include "vcd_read.h"
|
|
23 #endif
|
|
24
|
|
25 static struct stream_priv_s {
|
|
26 int track;
|
|
27 char* device;
|
|
28 } stream_priv_dflts = {
|
|
29 1,
|
|
30 DEFAULT_CDROM_DEVICE
|
|
31 };
|
|
32
|
|
33 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
|
|
34 /// URL definition
|
|
35 static m_option_t stream_opts_fields[] = {
|
|
36 { "track", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL },
|
|
37 { "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL},
|
|
38 /// For url parsing
|
|
39 { "hostname", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL },
|
|
40 { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL},
|
|
41 { NULL, NULL, 0, 0, 0, 0, NULL }
|
|
42 };
|
|
43 static struct m_struct_st stream_opts = {
|
|
44 "vcd",
|
|
45 sizeof(struct stream_priv_s),
|
|
46 &stream_priv_dflts,
|
|
47 stream_opts_fields
|
|
48 };
|
|
49
|
|
50 static int fill_buffer(stream_t *s, char* buffer, int max_len){
|
|
51 return vcd_read(s->priv,buffer);
|
|
52 }
|
|
53
|
|
54 static int seek(stream_t *s,off_t newpos) {
|
|
55 s->pos = newpos;
|
|
56 vcd_set_msf(s->priv,s->pos/VCD_SECTOR_DATA);
|
|
57 return 1;
|
|
58 }
|
|
59
|
|
60 static void close_s(stream_t *stream) {
|
|
61 free(stream->priv);
|
|
62 }
|
|
63
|
|
64 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
|
|
65 struct stream_priv_s* p = (struct stream_priv_s*)opts;
|
|
66 int ret,ret2,f;
|
|
67 mp_vcd_priv_t* vcd;
|
|
68 #ifdef __FreeBSD__
|
|
69 int bsize = VCD_SECTOR_SIZE;
|
|
70 #endif
|
|
71
|
|
72 if(mode != STREAM_READ) {
|
|
73 m_struct_free(&stream_opts,opts);
|
|
74 return STREAM_UNSUPORTED;
|
|
75 }
|
|
76
|
|
77 f=open(p->device,O_RDONLY);
|
|
78 if(f<0){
|
|
79 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,p->device);
|
|
80 close(f);
|
|
81 m_struct_free(&stream_opts,opts);
|
|
82 return STREAM_ERROR;
|
|
83 }
|
|
84
|
|
85 vcd = vcd_read_toc(f);
|
|
86 if(!vcd) {
|
|
87 mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n");
|
|
88 close(f);
|
|
89 m_struct_free(&stream_opts,opts);
|
|
90 return STREAM_ERROR;
|
|
91 }
|
|
92 ret2=vcd_get_track_end(vcd,p->track);
|
|
93 if(ret2<0){
|
|
94 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n");
|
|
95 close(f);
|
|
96 free(vcd);
|
|
97 m_struct_free(&stream_opts,opts);
|
|
98 return STREAM_ERROR;
|
|
99 }
|
|
100 ret=vcd_seek_to_track(vcd,p->track);
|
|
101 if(ret<0){
|
|
102 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n");
|
|
103 close(f);
|
|
104 free(vcd);
|
|
105 m_struct_free(&stream_opts,opts);
|
|
106 return STREAM_ERROR;
|
|
107 }
|
|
108 mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2);
|
|
109
|
|
110 #ifdef __FreeBSD__
|
|
111 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
|
|
112 mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE");
|
|
113 }
|
|
114 #endif
|
|
115
|
|
116 stream->fd = f;
|
|
117 stream->type = STREAMTYPE_VCD;
|
|
118 stream->sector_size = VCD_SECTOR_DATA;
|
|
119 stream->start_pos=ret;
|
|
120 stream->end_pos=ret2;
|
|
121 stream->priv = vcd;
|
|
122
|
|
123 stream->fill_buffer = fill_buffer;
|
|
124 stream->seek = seek;
|
|
125 stream->close = close_s;
|
|
126
|
|
127 m_struct_free(&stream_opts,opts);
|
|
128 return STREAM_OK;
|
|
129 }
|
|
130
|
|
131 stream_info_t stream_info_vcd = {
|
|
132 "Video CD",
|
|
133 "vcd",
|
|
134 "Albeu",
|
|
135 "based on the code from ???",
|
|
136 open_s,
|
|
137 { "vcd", NULL },
|
|
138 &stream_opts,
|
|
139 1 // Urls are an option string
|
|
140 };
|
|
141
|
|
142 #endif
|