Mercurial > mplayer.hg
annotate libmpdemux/stream_vcd.c @ 15745:3d712cf823c0
Sync with 1.1010
author | gpoirier |
---|---|
date | Fri, 17 Jun 2005 11:31:25 +0000 |
parents | 3758536dcef3 |
children | 25feca1387e7 |
rev | line source |
---|---|
9886 | 1 |
2 #include "config.h" | |
3 | |
4 #ifdef HAVE_VCD | |
5 #include "mp_msg.h" | |
6 #include "stream.h" | |
7 #include "help_mp.h" | |
8 #include "../m_option.h" | |
9 #include "../m_struct.h" | |
10 | |
10121
d42177a0da2a
Changed the STREAMING defines to MPLAYER_NETWORK to avoid name definition clash.
bertrand
parents:
9886
diff
changeset
|
11 #include <fcntl.h> |
9886 | 12 #include <stdlib.h> |
13 #include <unistd.h> | |
14 #include <sys/ioctl.h> | |
15 #include <errno.h> | |
16 | |
15566 | 17 #if defined(__FreeBSD__) || defined(__DragonFly__) |
9886 | 18 #include <sys/cdrio.h> |
19 #include "vcd_read_fbsd.h" | |
12797
b2419eef04da
OpenBSD portability patches from the OpenBSD ports tree
diego
parents:
10591
diff
changeset
|
20 #elif defined(__NetBSD__) || defined (__OpenBSD__) |
13678 | 21 #include "vcd_read_nbsd.h" |
13681
e52daf7f3bcc
enable vcd for all darwin based sys not only mac osx
nplourde
parents:
13678
diff
changeset
|
22 #elif defined(SYS_DARWIN) |
e52daf7f3bcc
enable vcd for all darwin based sys not only mac osx
nplourde
parents:
13678
diff
changeset
|
23 #include "vcd_read_darwin.h" |
9886 | 24 #else |
25 #include "vcd_read.h" | |
26 #endif | |
27 | |
10591 | 28 extern char *cdrom_device; |
29 | |
9886 | 30 static struct stream_priv_s { |
31 int track; | |
32 char* device; | |
33 } stream_priv_dflts = { | |
34 1, | |
10591 | 35 NULL |
9886 | 36 }; |
37 | |
38 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f) | |
39 /// URL definition | |
40 static m_option_t stream_opts_fields[] = { | |
41 { "track", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, | |
42 { "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
43 /// For url parsing | |
44 { "hostname", ST_OFF(track), CONF_TYPE_INT, M_OPT_MIN, 1, 0, NULL }, | |
45 { "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
46 { NULL, NULL, 0, 0, 0, 0, NULL } | |
47 }; | |
48 static struct m_struct_st stream_opts = { | |
49 "vcd", | |
50 sizeof(struct stream_priv_s), | |
51 &stream_priv_dflts, | |
52 stream_opts_fields | |
53 }; | |
54 | |
55 static int fill_buffer(stream_t *s, char* buffer, int max_len){ | |
56 return vcd_read(s->priv,buffer); | |
57 } | |
58 | |
59 static int seek(stream_t *s,off_t newpos) { | |
60 s->pos = newpos; | |
61 vcd_set_msf(s->priv,s->pos/VCD_SECTOR_DATA); | |
62 return 1; | |
63 } | |
64 | |
65 static void close_s(stream_t *stream) { | |
66 free(stream->priv); | |
67 } | |
68 | |
69 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { | |
70 struct stream_priv_s* p = (struct stream_priv_s*)opts; | |
71 int ret,ret2,f; | |
72 mp_vcd_priv_t* vcd; | |
73 #ifdef __FreeBSD__ | |
74 int bsize = VCD_SECTOR_SIZE; | |
75 #endif | |
76 | |
77 if(mode != STREAM_READ) { | |
78 m_struct_free(&stream_opts,opts); | |
79 return STREAM_UNSUPORTED; | |
80 } | |
81 | |
10591 | 82 if (!p->device) { |
83 if(cdrom_device) | |
84 p->device = strdup(cdrom_device); | |
85 else | |
86 p->device = strdup(DEFAULT_CDROM_DEVICE); | |
87 } | |
88 | |
9886 | 89 f=open(p->device,O_RDONLY); |
90 if(f<0){ | |
91 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_CdDevNotfound,p->device); | |
92 m_struct_free(&stream_opts,opts); | |
93 return STREAM_ERROR; | |
94 } | |
95 | |
96 vcd = vcd_read_toc(f); | |
97 if(!vcd) { | |
98 mp_msg(MSGT_OPEN,MSGL_ERR,"Failed to get cd toc\n"); | |
99 close(f); | |
100 m_struct_free(&stream_opts,opts); | |
101 return STREAM_ERROR; | |
102 } | |
103 ret2=vcd_get_track_end(vcd,p->track); | |
104 if(ret2<0){ | |
105 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (get)\n"); | |
106 close(f); | |
107 free(vcd); | |
108 m_struct_free(&stream_opts,opts); | |
109 return STREAM_ERROR; | |
110 } | |
111 ret=vcd_seek_to_track(vcd,p->track); | |
112 if(ret<0){ | |
113 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_ErrTrackSelect " (seek)\n"); | |
114 close(f); | |
115 free(vcd); | |
116 m_struct_free(&stream_opts,opts); | |
117 return STREAM_ERROR; | |
118 } | |
119 mp_msg(MSGT_OPEN,MSGL_V,"VCD start byte position: 0x%X end: 0x%X\n",ret,ret2); | |
120 | |
121 #ifdef __FreeBSD__ | |
122 if (ioctl (f, CDRIOCSETBLOCKSIZE, &bsize) == -1) { | |
123 mp_msg(MSGT_OPEN,MSGL_WARN,"Error in CDRIOCSETBLOCKSIZE"); | |
124 } | |
125 #endif | |
126 | |
127 stream->fd = f; | |
128 stream->type = STREAMTYPE_VCD; | |
129 stream->sector_size = VCD_SECTOR_DATA; | |
130 stream->start_pos=ret; | |
131 stream->end_pos=ret2; | |
132 stream->priv = vcd; | |
133 | |
134 stream->fill_buffer = fill_buffer; | |
135 stream->seek = seek; | |
136 stream->close = close_s; | |
137 | |
138 m_struct_free(&stream_opts,opts); | |
139 return STREAM_OK; | |
140 } | |
141 | |
142 stream_info_t stream_info_vcd = { | |
143 "Video CD", | |
144 "vcd", | |
145 "Albeu", | |
146 "based on the code from ???", | |
147 open_s, | |
148 { "vcd", NULL }, | |
149 &stream_opts, | |
150 1 // Urls are an option string | |
151 }; | |
152 | |
153 #endif |