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