Mercurial > mplayer.hg
annotate stream/stream_vcd.c @ 31230:0a182f029587
Reindent.
author | reimar |
---|---|
date | Mon, 31 May 2010 21:16:02 +0000 |
parents | 9bab99cfdff2 |
children | 045110c125c6 |
rev | line source |
---|---|
30426
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
1 /* |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
2 * This file is part of MPlayer. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
3 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
7 * (at your option) any later version. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
8 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
12 * GNU General Public License for more details. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
13 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
17 */ |
9886 | 18 |
19 #include "config.h" | |
20 | |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
25691
diff
changeset
|
21 #if defined(__MINGW32__) || defined(__CYGWIN__) |
22506 | 22 #include <windows.h> |
23 #endif | |
24 | |
30777 | 25 #include "osdep/osdep.h" |
26 | |
9886 | 27 #include "mp_msg.h" |
28 #include "stream.h" | |
29 #include "help_mp.h" | |
17012 | 30 #include "m_option.h" |
31 #include "m_struct.h" | |
9886 | 32 |
10121
d42177a0da2a
Changed the STREAMING defines to MPLAYER_NETWORK to avoid name definition clash.
bertrand
parents:
9886
diff
changeset
|
33 #include <fcntl.h> |
9886 | 34 #include <stdlib.h> |
35 #include <unistd.h> | |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
25691
diff
changeset
|
36 #if !defined(__MINGW32__) && !defined(__CYGWIN__) |
9886 | 37 #include <sys/ioctl.h> |
22506 | 38 #endif |
9886 | 39 #include <errno.h> |
40 | |
23857 | 41 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27727
diff
changeset
|
42 #include "vcd_read_fbsd.h" |
25342
23f02d6ac901
Replace SYS_DARWIN by __APPLE__ and __DARWIN__ where appropriate.
diego
parents:
25242
diff
changeset
|
43 #elif defined(__APPLE__) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27727
diff
changeset
|
44 #include "vcd_read_darwin.h" |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
25691
diff
changeset
|
45 #elif defined(__MINGW32__) || defined(__CYGWIN__) |
22506 | 46 #include "vcd_read_win32.h" |
30777 | 47 #elif defined(__OS2__) |
48 #include "vcd_read_os2.h" | |
9886 | 49 #else |
50 #include "vcd_read.h" | |
51 #endif | |
52 | |
21926
a8cd73869242
at open() assign *file_format=DEMUXER_TYPE_MPEG_PS to avoid useless demuxer probing
nicodvb
parents:
21848
diff
changeset
|
53 #include "libmpdemux/demuxer.h" |
a8cd73869242
at open() assign *file_format=DEMUXER_TYPE_MPEG_PS to avoid useless demuxer probing
nicodvb
parents:
21848
diff
changeset
|
54 |
10591 | 55 extern char *cdrom_device; |
56 | |
9886 | 57 static struct stream_priv_s { |
58 int track; | |
59 char* device; | |
60 } stream_priv_dflts = { | |
61 1, | |
10591 | 62 NULL |
9886 | 63 }; |
64 | |
65 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f) | |
66 /// URL definition | |
25242 | 67 static const m_option_t stream_opts_fields[] = { |
9886 | 68 { "track", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, |
69 { "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
70 /// For url parsing | |
71 { "hostname", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, | |
72 { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
73 { NULL, NULL, 0, 0, 0, 0, NULL } | |
74 }; | |
25691 | 75 static const struct m_struct_st stream_opts = { |
9886 | 76 "vcd", |
77 sizeof(struct stream_priv_s), | |
78 &stream_priv_dflts, | |
79 stream_opts_fields | |
80 }; | |
81 | |
82 static int fill_buffer(stream_t *s, char* buffer, int max_len){ | |
15912 | 83 if(s->pos > s->end_pos) /// don't past end of current track |
84 return 0; | |
9886 | 85 return vcd_read(s->priv,buffer); |
86 } | |
87 | |
88 static int seek(stream_t *s,off_t newpos) { | |
89 s->pos = newpos; | |
90 vcd_set_msf(s->priv,s->pos/VCD_SECTOR_DATA); | |
91 return 1; | |
92 } | |
93 | |
30977
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
94 static int control(stream_t *stream, int cmd, void *arg) { |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
95 struct stream_priv_s *p = stream->priv; |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
96 switch(cmd) { |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
97 case STREAM_CTRL_GET_NUM_CHAPTERS: |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
98 { |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
99 mp_vcd_priv_t *vcd = vcd_read_toc(stream->fd); |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
100 if (!vcd) |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
101 break; |
30981 | 102 *(unsigned int *)arg = vcd_end_track(vcd); |
30977
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
103 return STREAM_OK; |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
104 } |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
105 case STREAM_CTRL_SEEK_TO_CHAPTER: |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
106 { |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
107 int r; |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
108 unsigned int track = *(unsigned int *)arg + 1; |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
109 mp_vcd_priv_t *vcd = vcd_read_toc(stream->fd); |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
110 if (!vcd) |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
111 break; |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
112 r = vcd_seek_to_track(vcd, track); |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
113 if (r >= 0) { |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
114 p->track = track; |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
115 return STREAM_OK; |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
116 } |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
117 break; |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
118 } |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
119 case STREAM_CTRL_GET_CURRENT_CHAPTER: |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
120 { |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
121 *(unsigned int *)arg = p->track - 1; |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
122 return STREAM_OK; |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
123 } |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
124 } |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
125 return STREAM_UNSUPPORTED; |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
126 } |
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
127 |
9886 | 128 static void close_s(stream_t *stream) { |
129 free(stream->priv); | |
130 } | |
131 | |
132 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { | |
30752 | 133 struct stream_priv_s* p = opts; |
22775
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
134 int ret,ret2,f,sect,tmp; |
9886 | 135 mp_vcd_priv_t* vcd; |
21848 | 136 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
9886 | 137 int bsize = VCD_SECTOR_SIZE; |
138 #endif | |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
25691
diff
changeset
|
139 #if defined(__MINGW32__) || defined(__CYGWIN__) |
22506 | 140 HANDLE hd; |
141 char device[] = "\\\\.\\?:"; | |
142 #endif | |
30777 | 143 #if defined(__OS2__) |
144 char device[] = "X:"; | |
145 HFILE hcd; | |
146 ULONG ulAction; | |
147 ULONG rc; | |
148 #endif | |
9886 | 149 |
22506 | 150 if(mode != STREAM_READ |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
25691
diff
changeset
|
151 #if defined(__MINGW32__) || defined(__CYGWIN__) |
22506 | 152 || GetVersion() > 0x80000000 // Win9x |
153 #endif | |
154 ) { | |
9886 | 155 m_struct_free(&stream_opts,opts); |
24257 | 156 return STREAM_UNSUPPORTED; |
9886 | 157 } |
158 | |
10591 | 159 if (!p->device) { |
160 if(cdrom_device) | |
161 p->device = strdup(cdrom_device); | |
162 else | |
163 p->device = strdup(DEFAULT_CDROM_DEVICE); | |
164 } | |
165 | |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
25691
diff
changeset
|
166 #if defined(__MINGW32__) || defined(__CYGWIN__) |
22506 | 167 device[4] = p->device[0]; |
168 /* open() can't be used for devices so do it the complicated way */ | |
169 hd = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL, | |
170 OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); | |
171 f = _open_osfhandle((long)hd, _O_RDONLY); | |
30777 | 172 #elif defined(__OS2__) |
173 device[0] = p->device[0]; | |
174 rc = DosOpen(device, &hcd, &ulAction, 0, FILE_NORMAL, | |
175 OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW, | |
176 OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE | OPEN_FLAGS_DASD, | |
177 NULL); | |
178 f = rc ? -1 : hcd; | |
22506 | 179 #else |
9886 | 180 f=open(p->device,O_RDONLY); |
22506 | 181 #endif |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27727
diff
changeset
|
182 if(f<0){ |
9886 | 183 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,p->device); |
184 m_struct_free(&stream_opts,opts); | |
185 return STREAM_ERROR; | |
186 } | |
187 | |
188 vcd = vcd_read_toc(f); | |
189 if(!vcd) { | |
190 mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n"); | |
191 close(f); | |
192 m_struct_free(&stream_opts,opts); | |
193 return STREAM_ERROR; | |
194 } | |
195 ret2=vcd_get_track_end(vcd,p->track); | |
196 if(ret2<0){ | |
197 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n"); | |
198 close(f); | |
199 free(vcd); | |
200 m_struct_free(&stream_opts,opts); | |
201 return STREAM_ERROR; | |
202 } | |
203 ret=vcd_seek_to_track(vcd,p->track); | |
204 if(ret<0){ | |
205 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n"); | |
206 close(f); | |
207 free(vcd); | |
208 m_struct_free(&stream_opts,opts); | |
209 return STREAM_ERROR; | |
210 } | |
22775
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
211 /* search forward up to at most 3 seconds to skip leading margin */ |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
212 sect = ret / VCD_SECTOR_DATA; |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
213 for (tmp = sect; tmp < sect + 3 * 75; tmp++) { |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
214 char mem[VCD_SECTOR_DATA]; |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
215 //since MPEG packs are block-aligned we stop discarding sectors if they are non-null |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
216 if (vcd_read(vcd, mem) != VCD_SECTOR_DATA || mem[2] || mem[3]) |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
217 break; |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
218 } |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
219 mp_msg(MSGT_OPEN, MSGL_DBG2, "%d leading sectors skipped\n", tmp - sect); |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
220 vcd_set_msf(vcd, tmp); |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
221 ret = tmp * VCD_SECTOR_DATA; |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
222 |
9886 | 223 mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2); |
224 | |
21848 | 225 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
9886 | 226 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) { |
227 mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE"); | |
228 } | |
229 #endif | |
230 | |
231 stream->fd = f; | |
232 stream->type = STREAMTYPE_VCD; | |
233 stream->sector_size = VCD_SECTOR_DATA; | |
234 stream->start_pos=ret; | |
235 stream->end_pos=ret2; | |
236 stream->priv = vcd; | |
237 | |
238 stream->fill_buffer = fill_buffer; | |
239 stream->seek = seek; | |
30977
0b45d6af9ffe
Export VCD tracks as chapters, just like for cue:// URLs.
reimar
parents:
30777
diff
changeset
|
240 stream->control = control; |
9886 | 241 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
|
242 *file_format = DEMUXER_TYPE_MPEG_PS; |
9886 | 243 |
244 m_struct_free(&stream_opts,opts); | |
245 return STREAM_OK; | |
246 } | |
247 | |
25211 | 248 const stream_info_t stream_info_vcd = { |
9886 | 249 "Video CD", |
250 "vcd", | |
251 "Albeu", | |
252 "based on the code from ???", | |
253 open_s, | |
254 { "vcd", NULL }, | |
255 &stream_opts, | |
256 1 // Urls are an option string | |
257 }; |