Mercurial > mplayer.hg
annotate stream/vcd_read_fbsd.h @ 27428:bea545589195
fixes spotted by diego
author | compn |
---|---|
date | Wed, 13 Aug 2008 18:22:10 +0000 |
parents | 7ee4ae1648e6 |
children | b4cbeff5153e |
rev | line source |
---|---|
26029 | 1 #ifndef MPLAYER_VCD_READ_FBSD_H |
2 #define MPLAYER_VCD_READ_FBSD_H | |
26012 | 3 |
23857 | 4 #include <sys/types.h> |
5 #include <inttypes.h> | |
6 #include "libavutil/intreadwrite.h" | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
958
diff
changeset
|
7 #include <sys/cdio.h> |
23857 | 8 #if defined(__NetBSD__) || defined(__OpenBSD__) |
9 #define VCD_NETBSD 1 | |
10 #endif | |
11 #ifdef VCD_NETBSD | |
12 #include <sys/scsiio.h> | |
13 #define TOCADDR(te) ((te).data->addr) | |
14 #define READ_TOC CDIOREADTOCENTRYS | |
15 #else | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
958
diff
changeset
|
16 #include <sys/cdrio.h> |
23857 | 17 #define TOCADDR(te) ((te).entry.addr) |
18 #define READ_TOC CDIOREADTOCENTRY | |
19 #endif | |
26184
7ee4ae1648e6
Add missing header #includes to fix 'make checkheaders'.
diego
parents:
26029
diff
changeset
|
20 #include "mp_msg.h" |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
958
diff
changeset
|
21 |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
22 //=================== VideoCD ========================== |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
23 #define CDROM_LEADOUT 0xAA |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
24 |
1177
f2516027a346
FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents:
1038
diff
changeset
|
25 typedef struct { |
f2516027a346
FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents:
1038
diff
changeset
|
26 uint8_t sync [12]; |
f2516027a346
FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents:
1038
diff
changeset
|
27 uint8_t header [4]; |
f2516027a346
FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents:
1038
diff
changeset
|
28 uint8_t subheader [8]; |
f2516027a346
FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents:
1038
diff
changeset
|
29 uint8_t data [2324]; |
f2516027a346
FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents:
1038
diff
changeset
|
30 uint8_t spare [4]; |
f2516027a346
FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents:
1038
diff
changeset
|
31 } cdsector_t; |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
32 |
23858 | 33 #ifdef VCD_NETBSD |
23859 | 34 typedef struct ioc_read_toc_entry vcd_tocentry; |
23858 | 35 #else |
23859 | 36 typedef struct ioc_read_toc_single_entry vcd_tocentry; |
23858 | 37 #endif |
38 | |
9887 | 39 typedef struct mp_vcd_priv_st { |
40 int fd; | |
23858 | 41 vcd_tocentry entry; |
23857 | 42 #ifdef VCD_NETBSD |
43 struct cd_toc_entry entry_data; | |
44 #else | |
9887 | 45 cdsector_t buf; |
23857 | 46 #endif |
25411
aef6ff061c9a
Caching toc header in vcd private structure for later use.
ulion
parents:
23862
diff
changeset
|
47 struct ioc_toc_header tochdr; |
9887 | 48 } mp_vcd_priv_t; |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
49 |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
50 static inline void |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
51 vcd_set_msf(mp_vcd_priv_t* vcd, unsigned int sect) |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
52 { |
23857 | 53 #ifdef VCD_NETBSD |
54 vcd->entry.data = &vcd->entry_data; | |
55 #endif | |
23862 | 56 sect += 150; |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
57 TOCADDR(vcd->entry).msf.frame = sect % 75; |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
58 sect = sect / 75; |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
59 TOCADDR(vcd->entry).msf.second = sect % 60; |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
60 sect = sect / 60; |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
61 TOCADDR(vcd->entry).msf.minute = sect; |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
62 } |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
63 |
23852 | 64 static inline void |
65 vcd_inc_msf(mp_vcd_priv_t* vcd) | |
66 { | |
23857 | 67 #ifdef VCD_NETBSD |
68 vcd->entry.data = &vcd->entry_data; | |
69 #endif | |
23852 | 70 TOCADDR(vcd->entry).msf.frame++; |
71 if (TOCADDR(vcd->entry).msf.frame==75){ | |
72 TOCADDR(vcd->entry).msf.frame=0; | |
73 TOCADDR(vcd->entry).msf.second++; | |
74 if (TOCADDR(vcd->entry).msf.second==60){ | |
75 TOCADDR(vcd->entry).msf.second=0; | |
76 TOCADDR(vcd->entry).msf.minute++; | |
77 } | |
78 } | |
79 } | |
80 | |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
81 static inline unsigned int |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
82 vcd_get_msf(mp_vcd_priv_t* vcd) |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
83 { |
23857 | 84 #ifdef VCD_NETBSD |
85 vcd->entry.data = &vcd->entry_data; | |
86 #endif | |
23847
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
87 return TOCADDR(vcd->entry).msf.frame + |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
88 (TOCADDR(vcd->entry).msf.second + |
23862 | 89 TOCADDR(vcd->entry).msf.minute * 60) * 75 - 150; |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
90 } |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
91 |
23858 | 92 /** |
93 * \brief read a TOC entry | |
94 * \param fd device to read from | |
95 * \param dst buffer to read data into | |
96 * \param nr track number to read info for | |
97 * \return 1 on success, 0 on failure | |
98 */ | |
99 static int | |
23860 | 100 read_toc_entry(mp_vcd_priv_t *vcd, int nr) |
23858 | 101 { |
23860 | 102 vcd->entry.address_format = CD_MSF_FORMAT; |
23858 | 103 #ifdef VCD_NETBSD |
23860 | 104 vcd->entry.data_len = sizeof(struct cd_toc_entry); |
105 vcd->entry.data = &vcd->entry_data; | |
106 vcd->entry.starting_track = nr; | |
23858 | 107 #else |
23860 | 108 vcd->entry.track = nr; |
23858 | 109 #endif |
23860 | 110 if (ioctl(vcd->fd, READ_TOC, &vcd->entry) == -1) { |
23858 | 111 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno)); |
112 return 0; | |
113 } | |
114 return 1; | |
115 } | |
116 | |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
117 int |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
118 vcd_seek_to_track(mp_vcd_priv_t* vcd, int track) |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
119 { |
23860 | 120 if (!read_toc_entry(vcd, track)) |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
121 return -1; |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
122 return VCD_SECTOR_DATA * vcd_get_msf(vcd); |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
123 } |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
124 |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
125 int |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
126 vcd_get_track_end(mp_vcd_priv_t* vcd, int track) |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
127 { |
23860 | 128 if (!read_toc_entry(vcd, |
25411
aef6ff061c9a
Caching toc header in vcd private structure for later use.
ulion
parents:
23862
diff
changeset
|
129 track < vcd->tochdr.ending_track ? track + 1 : CDROM_LEADOUT)) |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
130 return -1; |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
131 return VCD_SECTOR_DATA * vcd_get_msf(vcd); |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
132 } |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
133 |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
134 mp_vcd_priv_t* |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
135 vcd_read_toc(int fd) |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
136 { |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
137 struct ioc_toc_header tochdr; |
9887 | 138 mp_vcd_priv_t* vcd; |
23861 | 139 int i, last_startsect; |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
140 if (ioctl(fd, CDIOREADTOCHEADER, &tochdr) == -1) { |
9887 | 141 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); |
142 return NULL; | |
143 } | |
18237
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
16547
diff
changeset
|
144 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", tochdr.starting_track); |
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
16547
diff
changeset
|
145 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", tochdr.ending_track); |
23860 | 146 vcd = malloc(sizeof(mp_vcd_priv_t)); |
147 vcd->fd = fd; | |
25411
aef6ff061c9a
Caching toc header in vcd private structure for later use.
ulion
parents:
23862
diff
changeset
|
148 vcd->tochdr = tochdr; |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
149 for (i = tochdr.starting_track; i <= tochdr.ending_track + 1; i++) { |
23860 | 150 if (!read_toc_entry(vcd, |
151 i <= tochdr.ending_track ? i : CDROM_LEADOUT)) { | |
152 free(vcd); | |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
153 return NULL; |
23860 | 154 } |
23851 | 155 |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
156 if (i <= tochdr.ending_track) |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
157 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n", |
23857 | 158 #ifdef VCD_NETBSD |
23860 | 159 (int)vcd->entry.starting_track, |
160 (int)vcd->entry.data->addr_type, | |
161 (int)vcd->entry.data->control, | |
23857 | 162 #else |
23860 | 163 (int)vcd->entry.track, |
164 (int)vcd->entry.entry.addr_type, | |
165 (int)vcd->entry.entry.control, | |
23857 | 166 #endif |
23860 | 167 (int)vcd->entry.address_format, |
168 (int)TOCADDR(vcd->entry).msf.minute, | |
169 (int)TOCADDR(vcd->entry).msf.second, | |
170 (int)TOCADDR(vcd->entry).msf.frame | |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
171 ); |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
172 |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
173 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO)) |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
174 { |
23861 | 175 int startsect = vcd_get_msf(vcd); |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
176 if (i > tochdr.starting_track) |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
177 { |
23861 | 178 // convert duraion to MSF |
179 vcd_set_msf(vcd, startsect - last_startsect); | |
180 mp_msg(MSGT_IDENTIFY, MSGL_INFO, | |
181 "ID_VCD_TRACK_%d_MSF=%02d:%02d:%02d\n", | |
182 i - 1, | |
183 TOCADDR(vcd->entry).msf.minute, | |
184 TOCADDR(vcd->entry).msf.second, | |
185 TOCADDR(vcd->entry).msf.frame); | |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
9899
diff
changeset
|
186 } |
23861 | 187 last_startsect = startsect; |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
188 } |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
189 } |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
190 return vcd; |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
191 } |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
192 |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
193 static int |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
194 vcd_read(mp_vcd_priv_t* vcd, char *mem) |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23847
diff
changeset
|
195 { |
23857 | 196 #ifdef VCD_NETBSD |
197 struct scsireq sc; | |
198 int lba = vcd_get_msf(vcd); | |
199 int blocks; | |
200 int rc; | |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
201 |
23857 | 202 blocks = 1; |
203 | |
204 memset(&sc, 0, sizeof(sc)); | |
205 sc.cmd[0] = 0xBE; | |
206 sc.cmd[1] = 5 << 2; // mode2/form2 | |
207 AV_WB32(&sc.cmd[2], lba); | |
208 AV_WB24(&sc.cmd[6], blocks); | |
209 sc.cmd[9] = 1 << 4; // user data only | |
210 sc.cmd[10] = 0; // no subchannel | |
211 sc.cmdlen = 12; | |
212 sc.databuf = (caddr_t) mem; | |
25873 | 213 sc.datalen = VCD_SECTOR_DATA; |
23857 | 214 sc.senselen = sizeof(sc.sense); |
215 sc.flags = SCCMD_READ; | |
216 sc.timeout = 10000; | |
217 rc = ioctl(vcd->fd, SCIOCCOMMAND, &sc); | |
218 if (rc == -1) { | |
219 mp_msg(MSGT_STREAM,MSGL_ERR,"SCIOCCOMMAND: %s\n",strerror(errno)); | |
220 return -1; | |
221 } | |
222 if (sc.retsts || sc.error) { | |
223 mp_msg(MSGT_STREAM,MSGL_ERR,"scsi command failed: status %d error %d\n", | |
224 sc.retsts,sc.error); | |
225 return -1; | |
226 } | |
227 #else | |
23851 | 228 if (pread(vcd->fd,&vcd->buf,VCD_SECTOR_SIZE,vcd_get_msf(vcd)*VCD_SECTOR_SIZE) |
229 != VCD_SECTOR_SIZE) return 0; // EOF? | |
1177
f2516027a346
FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents:
1038
diff
changeset
|
230 |
23857 | 231 memcpy(mem,vcd->buf.data,VCD_SECTOR_DATA); |
232 #endif | |
23852 | 233 vcd_inc_msf(vcd); |
23851 | 234 return VCD_SECTOR_DATA; |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
235 } |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff
changeset
|
236 |
26029 | 237 #endif /* MPLAYER_VCD_READ_FBSD_H */ |