Mercurial > mplayer.hg
annotate stream/stream_vcd.c @ 30707:4d15378da04a
Mark vf_opts/vf_opts_fields structures as const.
author | diego |
---|---|
date | Fri, 26 Feb 2010 17:21:06 +0000 |
parents | ce0122361a39 |
children | abec4bb780e5 |
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 | |
9886 | 25 #include "mp_msg.h" |
26 #include "stream.h" | |
27 #include "help_mp.h" | |
17012 | 28 #include "m_option.h" |
29 #include "m_struct.h" | |
9886 | 30 |
10121
d42177a0da2a
Changed the STREAMING defines to MPLAYER_NETWORK to avoid name definition clash.
bertrand
parents:
9886
diff
changeset
|
31 #include <fcntl.h> |
9886 | 32 #include <stdlib.h> |
33 #include <unistd.h> | |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
25691
diff
changeset
|
34 #if !defined(__MINGW32__) && !defined(__CYGWIN__) |
9886 | 35 #include <sys/ioctl.h> |
22506 | 36 #endif |
9886 | 37 #include <errno.h> |
38 | |
23857 | 39 #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
|
40 #include "vcd_read_fbsd.h" |
25342
23f02d6ac901
Replace SYS_DARWIN by __APPLE__ and __DARWIN__ where appropriate.
diego
parents:
25242
diff
changeset
|
41 #elif defined(__APPLE__) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27727
diff
changeset
|
42 #include "vcd_read_darwin.h" |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
25691
diff
changeset
|
43 #elif defined(__MINGW32__) || defined(__CYGWIN__) |
22506 | 44 #include "vcd_read_win32.h" |
9886 | 45 #else |
46 #include "vcd_read.h" | |
47 #endif | |
48 | |
21926
a8cd73869242
at open() assign *file_format=DEMUXER_TYPE_MPEG_PS to avoid useless demuxer probing
nicodvb
parents:
21848
diff
changeset
|
49 #include "libmpdemux/demuxer.h" |
a8cd73869242
at open() assign *file_format=DEMUXER_TYPE_MPEG_PS to avoid useless demuxer probing
nicodvb
parents:
21848
diff
changeset
|
50 |
10591 | 51 extern char *cdrom_device; |
52 | |
9886 | 53 static struct stream_priv_s { |
54 int track; | |
55 char* device; | |
56 } stream_priv_dflts = { | |
57 1, | |
10591 | 58 NULL |
9886 | 59 }; |
60 | |
61 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f) | |
62 /// URL definition | |
25242 | 63 static const m_option_t stream_opts_fields[] = { |
9886 | 64 { "track", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, |
65 { "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
66 /// For url parsing | |
67 { "hostname", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, | |
68 { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
69 { NULL, NULL, 0, 0, 0, 0, NULL } | |
70 }; | |
25691 | 71 static const struct m_struct_st stream_opts = { |
9886 | 72 "vcd", |
73 sizeof(struct stream_priv_s), | |
74 &stream_priv_dflts, | |
75 stream_opts_fields | |
76 }; | |
77 | |
78 static int fill_buffer(stream_t *s, char* buffer, int max_len){ | |
15912 | 79 if(s->pos > s->end_pos) /// don't past end of current track |
80 return 0; | |
9886 | 81 return vcd_read(s->priv,buffer); |
82 } | |
83 | |
84 static int seek(stream_t *s,off_t newpos) { | |
85 s->pos = newpos; | |
86 vcd_set_msf(s->priv,s->pos/VCD_SECTOR_DATA); | |
87 return 1; | |
88 } | |
89 | |
90 static void close_s(stream_t *stream) { | |
91 free(stream->priv); | |
92 } | |
93 | |
94 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { | |
95 struct stream_priv_s* p = (struct stream_priv_s*)opts; | |
22775
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
96 int ret,ret2,f,sect,tmp; |
9886 | 97 mp_vcd_priv_t* vcd; |
21848 | 98 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
9886 | 99 int bsize = VCD_SECTOR_SIZE; |
100 #endif | |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
25691
diff
changeset
|
101 #if defined(__MINGW32__) || defined(__CYGWIN__) |
22506 | 102 HANDLE hd; |
103 char device[] = "\\\\.\\?:"; | |
104 #endif | |
9886 | 105 |
22506 | 106 if(mode != STREAM_READ |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
25691
diff
changeset
|
107 #if defined(__MINGW32__) || defined(__CYGWIN__) |
22506 | 108 || GetVersion() > 0x80000000 // Win9x |
109 #endif | |
110 ) { | |
9886 | 111 m_struct_free(&stream_opts,opts); |
24257 | 112 return STREAM_UNSUPPORTED; |
9886 | 113 } |
114 | |
10591 | 115 if (!p->device) { |
116 if(cdrom_device) | |
117 p->device = strdup(cdrom_device); | |
118 else | |
119 p->device = strdup(DEFAULT_CDROM_DEVICE); | |
120 } | |
121 | |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
25691
diff
changeset
|
122 #if defined(__MINGW32__) || defined(__CYGWIN__) |
22506 | 123 device[4] = p->device[0]; |
124 /* open() can't be used for devices so do it the complicated way */ | |
125 hd = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL, | |
126 OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); | |
127 f = _open_osfhandle((long)hd, _O_RDONLY); | |
128 #else | |
9886 | 129 f=open(p->device,O_RDONLY); |
22506 | 130 #endif |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27727
diff
changeset
|
131 if(f<0){ |
9886 | 132 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,p->device); |
133 m_struct_free(&stream_opts,opts); | |
134 return STREAM_ERROR; | |
135 } | |
136 | |
137 vcd = vcd_read_toc(f); | |
138 if(!vcd) { | |
139 mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n"); | |
140 close(f); | |
141 m_struct_free(&stream_opts,opts); | |
142 return STREAM_ERROR; | |
143 } | |
144 ret2=vcd_get_track_end(vcd,p->track); | |
145 if(ret2<0){ | |
146 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n"); | |
147 close(f); | |
148 free(vcd); | |
149 m_struct_free(&stream_opts,opts); | |
150 return STREAM_ERROR; | |
151 } | |
152 ret=vcd_seek_to_track(vcd,p->track); | |
153 if(ret<0){ | |
154 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n"); | |
155 close(f); | |
156 free(vcd); | |
157 m_struct_free(&stream_opts,opts); | |
158 return STREAM_ERROR; | |
159 } | |
22775
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
160 /* 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
|
161 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
|
162 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
|
163 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
|
164 //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
|
165 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
|
166 break; |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
167 } |
f6dc5fd2b347
at open() discard front margin/empty sectors (fixes demuxing by libavformat); patch by Zuxy meng
nicodvb
parents:
22506
diff
changeset
|
168 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
|
169 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
|
170 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
|
171 |
9886 | 172 mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2); |
173 | |
21848 | 174 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
9886 | 175 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) { |
176 mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE"); | |
177 } | |
178 #endif | |
179 | |
180 stream->fd = f; | |
181 stream->type = STREAMTYPE_VCD; | |
182 stream->sector_size = VCD_SECTOR_DATA; | |
183 stream->start_pos=ret; | |
184 stream->end_pos=ret2; | |
185 stream->priv = vcd; | |
186 | |
187 stream->fill_buffer = fill_buffer; | |
188 stream->seek = seek; | |
189 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
|
190 *file_format = DEMUXER_TYPE_MPEG_PS; |
9886 | 191 |
192 m_struct_free(&stream_opts,opts); | |
193 return STREAM_OK; | |
194 } | |
195 | |
25211 | 196 const stream_info_t stream_info_vcd = { |
9886 | 197 "Video CD", |
198 "vcd", | |
199 "Albeu", | |
200 "based on the code from ???", | |
201 open_s, | |
202 { "vcd", NULL }, | |
203 &stream_opts, | |
204 1 // Urls are an option string | |
205 }; |