Mercurial > mplayer.hg
annotate stream/stream_vcd.c @ 22671:99db91e74443
Remove remnants of Linux 2.6 support, the mga_vid.c part was made to
disappear in Limbo with 'cvs admin -o' ages ago.
author | diego |
---|---|
date | Sat, 17 Mar 2007 13:53:15 +0000 |
parents | 72fbf66a9429 |
children | f6dc5fd2b347 |
rev | line source |
---|---|
9886 | 1 |
2 #include "config.h" | |
3 | |
22506 | 4 #ifdef WIN32 |
5 #include <windows.h> | |
6 #endif | |
7 | |
9886 | 8 #include "mp_msg.h" |
9 #include "stream.h" | |
10 #include "help_mp.h" | |
17012 | 11 #include "m_option.h" |
12 #include "m_struct.h" | |
9886 | 13 |
10121
d42177a0da2a
Changed the STREAMING defines to MPLAYER_NETWORK to avoid name definition clash.
bertrand
parents:
9886
diff
changeset
|
14 #include <fcntl.h> |
9886 | 15 #include <stdlib.h> |
16 #include <unistd.h> | |
22506 | 17 #ifndef WIN32 |
9886 | 18 #include <sys/ioctl.h> |
22506 | 19 #endif |
9886 | 20 #include <errno.h> |
21 | |
21848 | 22 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
9886 | 23 #include <sys/cdrio.h> |
24 #include "vcd_read_fbsd.h" | |
12797
b2419eef04da
OpenBSD portability patches from the OpenBSD ports tree
diego
parents:
10591
diff
changeset
|
25 #elif defined(__NetBSD__) || defined (__OpenBSD__) |
13678 | 26 #include "vcd_read_nbsd.h" |
13681
e52daf7f3bcc
enable vcd for all darwin based sys not only mac osx
nplourde
parents:
13678
diff
changeset
|
27 #elif defined(SYS_DARWIN) |
e52daf7f3bcc
enable vcd for all darwin based sys not only mac osx
nplourde
parents:
13678
diff
changeset
|
28 #include "vcd_read_darwin.h" |
22506 | 29 #elif defined(WIN32) |
30 #include "vcd_read_win32.h" | |
9886 | 31 #else |
32 #include "vcd_read.h" | |
33 #endif | |
34 | |
21926
a8cd73869242
at open() assign *file_format=DEMUXER_TYPE_MPEG_PS to avoid useless demuxer probing
nicodvb
parents:
21848
diff
changeset
|
35 #include "libmpdemux/demuxer.h" |
a8cd73869242
at open() assign *file_format=DEMUXER_TYPE_MPEG_PS to avoid useless demuxer probing
nicodvb
parents:
21848
diff
changeset
|
36 |
10591 | 37 extern char *cdrom_device; |
38 | |
9886 | 39 static struct stream_priv_s { |
40 int track; | |
41 char* device; | |
42 } stream_priv_dflts = { | |
43 1, | |
10591 | 44 NULL |
9886 | 45 }; |
46 | |
47 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f) | |
48 /// URL definition | |
49 static m_option_t stream_opts_fields[] = { | |
50 { "track", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, | |
51 { "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
52 /// For url parsing | |
53 { "hostname", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, | |
54 { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
55 { NULL, NULL, 0, 0, 0, 0, NULL } | |
56 }; | |
57 static struct m_struct_st stream_opts = { | |
58 "vcd", | |
59 sizeof(struct stream_priv_s), | |
60 &stream_priv_dflts, | |
61 stream_opts_fields | |
62 }; | |
63 | |
64 static int fill_buffer(stream_t *s, char* buffer, int max_len){ | |
15912 | 65 if(s->pos > s->end_pos) /// don't past end of current track |
66 return 0; | |
9886 | 67 return vcd_read(s->priv,buffer); |
68 } | |
69 | |
70 static int seek(stream_t *s,off_t newpos) { | |
71 s->pos = newpos; | |
72 vcd_set_msf(s->priv,s->pos/VCD_SECTOR_DATA); | |
73 return 1; | |
74 } | |
75 | |
76 static void close_s(stream_t *stream) { | |
77 free(stream->priv); | |
78 } | |
79 | |
80 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { | |
81 struct stream_priv_s* p = (struct stream_priv_s*)opts; | |
82 int ret,ret2,f; | |
83 mp_vcd_priv_t* vcd; | |
21848 | 84 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
9886 | 85 int bsize = VCD_SECTOR_SIZE; |
86 #endif | |
22506 | 87 #ifdef WIN32 |
88 HANDLE hd; | |
89 char device[] = "\\\\.\\?:"; | |
90 #endif | |
9886 | 91 |
22506 | 92 if(mode != STREAM_READ |
93 #ifdef WIN32 | |
94 || GetVersion() > 0x80000000 // Win9x | |
95 #endif | |
96 ) { | |
9886 | 97 m_struct_free(&stream_opts,opts); |
98 return STREAM_UNSUPORTED; | |
99 } | |
100 | |
10591 | 101 if (!p->device) { |
102 if(cdrom_device) | |
103 p->device = strdup(cdrom_device); | |
104 else | |
105 p->device = strdup(DEFAULT_CDROM_DEVICE); | |
106 } | |
107 | |
22506 | 108 #ifdef WIN32 |
109 device[4] = p->device[0]; | |
110 /* open() can't be used for devices so do it the complicated way */ | |
111 hd = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL, | |
112 OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); | |
113 f = _open_osfhandle((long)hd, _O_RDONLY); | |
114 #else | |
9886 | 115 f=open(p->device,O_RDONLY); |
22506 | 116 #endif |
9886 | 117 if(f<0){ |
118 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,p->device); | |
119 m_struct_free(&stream_opts,opts); | |
120 return STREAM_ERROR; | |
121 } | |
122 | |
123 vcd = vcd_read_toc(f); | |
124 if(!vcd) { | |
125 mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n"); | |
126 close(f); | |
127 m_struct_free(&stream_opts,opts); | |
128 return STREAM_ERROR; | |
129 } | |
130 ret2=vcd_get_track_end(vcd,p->track); | |
131 if(ret2<0){ | |
132 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n"); | |
133 close(f); | |
134 free(vcd); | |
135 m_struct_free(&stream_opts,opts); | |
136 return STREAM_ERROR; | |
137 } | |
138 ret=vcd_seek_to_track(vcd,p->track); | |
139 if(ret<0){ | |
140 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n"); | |
141 close(f); | |
142 free(vcd); | |
143 m_struct_free(&stream_opts,opts); | |
144 return STREAM_ERROR; | |
145 } | |
146 mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2); | |
147 | |
21848 | 148 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
9886 | 149 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) { |
150 mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE"); | |
151 } | |
152 #endif | |
153 | |
154 stream->fd = f; | |
155 stream->type = STREAMTYPE_VCD; | |
156 stream->sector_size = VCD_SECTOR_DATA; | |
157 stream->start_pos=ret; | |
158 stream->end_pos=ret2; | |
159 stream->priv = vcd; | |
160 | |
161 stream->fill_buffer = fill_buffer; | |
162 stream->seek = seek; | |
163 stream->close = close_s; | |
21926
a8cd73869242
at open() assign *file_format=DEMUXER_TYPE_MPEG_PS to avoid useless demuxer probing
nicodvb
parents:
21848
diff
changeset
|
164 *file_format = DEMUXER_TYPE_MPEG_PS; |
9886 | 165 |
166 m_struct_free(&stream_opts,opts); | |
167 return STREAM_OK; | |
168 } | |
169 | |
170 stream_info_t stream_info_vcd = { | |
171 "Video CD", | |
172 "vcd", | |
173 "Albeu", | |
174 "based on the code from ???", | |
175 open_s, | |
176 { "vcd", NULL }, | |
177 &stream_opts, | |
178 1 // Urls are an option string | |
179 }; |