annotate stream/stream_vcd.c @ 22560:c06ec6fd3b29

Rename all target to libs.
author diego
date Wed, 14 Mar 2007 20:17:01 +0000
parents 72fbf66a9429
children f6dc5fd2b347
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
1
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
2 #include "config.h"
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
3
22506
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
4 #ifdef WIN32
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
5 #include <windows.h>
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
6 #endif
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
7
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
8 #include "mp_msg.h"
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
9 #include "stream.h"
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
10 #include "help_mp.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 15912
diff changeset
11 #include "m_option.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 15912
diff changeset
12 #include "m_struct.h"
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
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
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
15 #include <stdlib.h>
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
16 #include <unistd.h>
22506
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
17 #ifndef WIN32
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
18 #include <sys/ioctl.h>
22506
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
19 #endif
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
20 #include <errno.h>
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
21
21848
3ff1eade91f9 GNU/kFreeBSD support, closes Bugzilla #704.
diego
parents: 19271
diff changeset
22 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
23 #include <sys/cdrio.h>
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
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
dc1facd7c7b0 add vcd support to darwin for ppc
nplourde
parents: 12797
diff changeset
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
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
29 #elif defined(WIN32)
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
30 #include "vcd_read_win32.h"
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
31 #else
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
32 #include "vcd_read.h"
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
33 #endif
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
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
0d381b648b51 Fix -cdrom-device to work again with cdda and vcd.
albeu
parents: 10121
diff changeset
37 extern char *cdrom_device;
0d381b648b51 Fix -cdrom-device to work again with cdda and vcd.
albeu
parents: 10121
diff changeset
38
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
39 static struct stream_priv_s {
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
40 int track;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
41 char* device;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
42 } stream_priv_dflts = {
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
43 1,
10591
0d381b648b51 Fix -cdrom-device to work again with cdda and vcd.
albeu
parents: 10121
diff changeset
44 NULL
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
45 };
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
46
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
47 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
48 /// URL definition
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
49 static m_option_t stream_opts_fields[] = {
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
50 { "track", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL },
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
51 { "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL},
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
52 /// For url parsing
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
53 { "hostname", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL },
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
54 { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL},
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
55 { NULL, NULL, 0, 0, 0, 0, NULL }
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
56 };
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
57 static struct m_struct_st stream_opts = {
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
58 "vcd",
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
59 sizeof(struct stream_priv_s),
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
60 &stream_priv_dflts,
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
61 stream_opts_fields
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
62 };
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
63
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
64 static int fill_buffer(stream_t *s, char* buffer, int max_len){
15912
25feca1387e7 don't read past the end of the selected track
nicodvb
parents: 15566
diff changeset
65 if(s->pos > s->end_pos) /// don't past end of current track
25feca1387e7 don't read past the end of the selected track
nicodvb
parents: 15566
diff changeset
66 return 0;
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
67 return vcd_read(s->priv,buffer);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
68 }
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
69
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
70 static int seek(stream_t *s,off_t newpos) {
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
71 s->pos = newpos;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
72 vcd_set_msf(s->priv,s->pos/VCD_SECTOR_DATA);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
73 return 1;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
74 }
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
75
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
76 static void close_s(stream_t *stream) {
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
77 free(stream->priv);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
78 }
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
79
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
80 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
81 struct stream_priv_s* p = (struct stream_priv_s*)opts;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
82 int ret,ret2,f;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
83 mp_vcd_priv_t* vcd;
21848
3ff1eade91f9 GNU/kFreeBSD support, closes Bugzilla #704.
diego
parents: 19271
diff changeset
84 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
85 int bsize = VCD_SECTOR_SIZE;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
86 #endif
22506
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
87 #ifdef WIN32
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
88 HANDLE hd;
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
89 char device[] = "\\\\.\\?:";
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
90 #endif
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
91
22506
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
92 if(mode != STREAM_READ
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
93 #ifdef WIN32
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
94 || GetVersion() > 0x80000000 // Win9x
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
95 #endif
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
96 ) {
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
97 m_struct_free(&stream_opts,opts);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
98 return STREAM_UNSUPORTED;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
99 }
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
100
10591
0d381b648b51 Fix -cdrom-device to work again with cdda and vcd.
albeu
parents: 10121
diff changeset
101 if (!p->device) {
0d381b648b51 Fix -cdrom-device to work again with cdda and vcd.
albeu
parents: 10121
diff changeset
102 if(cdrom_device)
0d381b648b51 Fix -cdrom-device to work again with cdda and vcd.
albeu
parents: 10121
diff changeset
103 p->device = strdup(cdrom_device);
0d381b648b51 Fix -cdrom-device to work again with cdda and vcd.
albeu
parents: 10121
diff changeset
104 else
0d381b648b51 Fix -cdrom-device to work again with cdda and vcd.
albeu
parents: 10121
diff changeset
105 p->device = strdup(DEFAULT_CDROM_DEVICE);
0d381b648b51 Fix -cdrom-device to work again with cdda and vcd.
albeu
parents: 10121
diff changeset
106 }
0d381b648b51 Fix -cdrom-device to work again with cdda and vcd.
albeu
parents: 10121
diff changeset
107
22506
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
108 #ifdef WIN32
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
109 device[4] = p->device[0];
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
110 /* open() can't be used for devices so do it the complicated way */
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
111 hd = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL,
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
112 OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
113 f = _open_osfhandle((long)hd, _O_RDONLY);
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
114 #else
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
115 f=open(p->device,O_RDONLY);
22506
72fbf66a9429 add vcd:// for win32, patch by zuxy meng
compn
parents: 21926
diff changeset
116 #endif
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
117 if(f<0){
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
118 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,p->device);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
119 m_struct_free(&stream_opts,opts);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
120 return STREAM_ERROR;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
121 }
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
122
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
123 vcd = vcd_read_toc(f);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
124 if(!vcd) {
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
125 mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n");
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
126 close(f);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
127 m_struct_free(&stream_opts,opts);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
128 return STREAM_ERROR;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
129 }
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
130 ret2=vcd_get_track_end(vcd,p->track);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
131 if(ret2<0){
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
132 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n");
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
133 close(f);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
134 free(vcd);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
135 m_struct_free(&stream_opts,opts);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
136 return STREAM_ERROR;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
137 }
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
138 ret=vcd_seek_to_track(vcd,p->track);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
139 if(ret<0){
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
140 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n");
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
141 close(f);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
142 free(vcd);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
143 m_struct_free(&stream_opts,opts);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
144 return STREAM_ERROR;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
145 }
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
146 mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
147
21848
3ff1eade91f9 GNU/kFreeBSD support, closes Bugzilla #704.
diego
parents: 19271
diff changeset
148 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
9886
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
149 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) {
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
150 mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE");
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
151 }
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
152 #endif
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
153
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
154 stream->fd = f;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
155 stream->type = STREAMTYPE_VCD;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
156 stream->sector_size = VCD_SECTOR_DATA;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
157 stream->start_pos=ret;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
158 stream->end_pos=ret2;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
159 stream->priv = vcd;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
160
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
161 stream->fill_buffer = fill_buffer;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
162 stream->seek = seek;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
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
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
165
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
166 m_struct_free(&stream_opts,opts);
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
167 return STREAM_OK;
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
168 }
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
169
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
170 stream_info_t stream_info_vcd = {
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
171 "Video CD",
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
172 "vcd",
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
173 "Albeu",
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
174 "based on the code from ???",
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
175 open_s,
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
176 { "vcd", NULL },
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
177 &stream_opts,
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
178 1 // Urls are an option string
e578e4375434 Port vcd to the new API
albeu
parents:
diff changeset
179 };