vo_gl: reject MS Windows native OpenGL as software rasterizer
[mplayer.git] / stream / stream_vcd.c
blobe06e381f59bdb6e3eec8447eb78756c0abfd4285
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "config.h"
21 #if defined(__MINGW32__) || defined(__CYGWIN__)
22 #include <windows.h>
23 #endif
25 #include "mp_msg.h"
26 #include "stream.h"
27 #include "m_option.h"
28 #include "m_struct.h"
30 #include <fcntl.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33 #if !defined(__MINGW32__) && !defined(__CYGWIN__)
34 #include <sys/ioctl.h>
35 #endif
36 #include <errno.h>
38 #include "talloc.h"
40 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
41 #include "vcd_read_fbsd.h"
42 #elif defined(__APPLE__)
43 #include "vcd_read_darwin.h"
44 #elif defined(__MINGW32__) || defined(__CYGWIN__)
45 #include "vcd_read_win32.h"
46 #else
47 #include "vcd_read.h"
48 #endif
50 #include "libmpdemux/demuxer.h"
52 extern char *cdrom_device;
54 static struct stream_priv_s {
55 int track;
56 char* device;
57 } stream_priv_dflts = {
59 NULL
62 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
63 /// URL definition
64 static const m_option_t stream_opts_fields[] = {
65 { "track", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL },
66 { "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL},
67 /// For url parsing
68 { "hostname", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL },
69 { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL},
70 { NULL, NULL, 0, 0, 0, 0, NULL }
72 static const struct m_struct_st stream_opts = {
73 "vcd",
74 sizeof(struct stream_priv_s),
75 &stream_priv_dflts,
76 stream_opts_fields
79 static int fill_buffer(stream_t *s, char* buffer, int max_len){
80 if(s->pos > s->end_pos) /// don't past end of current track
81 return 0;
82 return vcd_read(s->priv,buffer);
85 static int seek(stream_t *s,off_t newpos) {
86 s->pos = newpos;
87 vcd_set_msf(s->priv,s->pos/VCD_SECTOR_DATA);
88 return 1;
91 static int control(stream_t *stream, int cmd, void *arg) {
92 struct stream_priv_s *p = stream->priv;
93 switch(cmd) {
94 case STREAM_CTRL_GET_NUM_CHAPTERS:
96 mp_vcd_priv_t *vcd = vcd_read_toc(stream->fd);
97 if (!vcd)
98 break;
99 *(unsigned int *)arg = vcd_end_track(vcd);
100 return STREAM_OK;
102 case STREAM_CTRL_SEEK_TO_CHAPTER:
104 int r;
105 unsigned int track = *(unsigned int *)arg + 1;
106 mp_vcd_priv_t *vcd = vcd_read_toc(stream->fd);
107 if (!vcd)
108 break;
109 r = vcd_seek_to_track(vcd, track);
110 if (r >= 0) {
111 p->track = track;
112 return STREAM_OK;
114 break;
116 case STREAM_CTRL_GET_CURRENT_CHAPTER:
118 *(unsigned int *)arg = p->track - 1;
119 return STREAM_OK;
122 return STREAM_UNSUPPORTED;
125 static void close_s(stream_t *stream) {
126 free(stream->priv);
129 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
130 struct stream_priv_s* p = opts;
131 int ret,ret2,f,sect,tmp;
132 mp_vcd_priv_t* vcd;
133 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
134 int bsize = VCD_SECTOR_SIZE;
135 #endif
136 #if defined(__MINGW32__) || defined(__CYGWIN__)
137 HANDLE hd;
138 char device[] = "\\\\.\\?:";
139 #endif
141 if(mode != STREAM_READ
142 #if defined(__MINGW32__) || defined(__CYGWIN__)
143 || GetVersion() > 0x80000000 // Win9x
144 #endif
146 m_struct_free(&stream_opts,opts);
147 return STREAM_UNSUPPORTED;
150 if (!p->device) {
151 if(cdrom_device)
152 p->device = talloc_strdup(NULL, cdrom_device);
153 else
154 p->device = talloc_strdup(NULL, DEFAULT_CDROM_DEVICE);
157 #if defined(__MINGW32__) || defined(__CYGWIN__)
158 device[4] = p->device[0];
159 /* open() can't be used for devices so do it the complicated way */
160 hd = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL,
161 OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
162 f = _open_osfhandle((long)hd, _O_RDONLY);
163 #else
164 f=open(p->device,O_RDONLY);
165 #endif
166 if(f<0){
167 mp_tmsg(MSGT_OPEN,MSGL_ERR,"CD-ROM Device '%s' not found.\n",p->device);
168 m_struct_free(&stream_opts,opts);
169 return STREAM_ERROR;
172 vcd = vcd_read_toc(f);
173 if(!vcd) {
174 mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n");
175 close(f);
176 m_struct_free(&stream_opts,opts);
177 return STREAM_ERROR;
179 ret2=vcd_get_track_end(vcd,p->track);
180 if(ret2<0){
181 mp_msg(MSGT_OPEN, MSGL_ERR, "%s (get)\n",
182 mp_gtext("Error selecting VCD track."));
183 close(f);
184 free(vcd);
185 m_struct_free(&stream_opts,opts);
186 return STREAM_ERROR;
188 ret=vcd_seek_to_track(vcd,p->track);
189 if(ret<0){
190 mp_msg(MSGT_OPEN, MSGL_ERR, "%s (seek)\n",
191 mp_gtext("Error selecting VCD track."));
192 close(f);
193 free(vcd);
194 m_struct_free(&stream_opts,opts);
195 return STREAM_ERROR;
197 /* search forward up to at most 3 seconds to skip leading margin */
198 sect = ret / VCD_SECTOR_DATA;
199 for (tmp = sect; tmp < sect + 3 * 75; tmp++) {
200 char mem[VCD_SECTOR_DATA];
201 //since MPEG packs are block-aligned we stop discarding sectors if they are non-null
202 if (vcd_read(vcd, mem) != VCD_SECTOR_DATA || mem[2] || mem[3])
203 break;
205 mp_msg(MSGT_OPEN, MSGL_DBG2, "%d leading sectors skipped\n", tmp - sect);
206 vcd_set_msf(vcd, tmp);
207 ret = tmp * VCD_SECTOR_DATA;
209 mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2);
211 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
212 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
213 mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE");
215 #endif
217 stream->fd = f;
218 stream->type = STREAMTYPE_VCD;
219 stream->sector_size = VCD_SECTOR_DATA;
220 stream->start_pos=ret;
221 stream->end_pos=ret2;
222 stream->priv = vcd;
224 stream->fill_buffer = fill_buffer;
225 stream->seek = seek;
226 stream->control = control;
227 stream->close = close_s;
228 *file_format = DEMUXER_TYPE_MPEG_PS;
230 m_struct_free(&stream_opts,opts);
231 return STREAM_OK;
234 const stream_info_t stream_info_vcd = {
235 "Video CD",
236 "vcd",
237 "Albeu",
238 "based on the code from ???",
239 open_s,
240 { "vcd", NULL },
241 &stream_opts,
242 1 // Urls are an option string