annotate libmpdemux/vcd_read_nbsd.h @ 12564:7905ed33cc12

translated
author alex
date Fri, 11 Jun 2004 10:33:20 +0000
parents d862231858d5
children b2419eef04da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
1
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
2 #include <sys/types.h>
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
3 #include <sys/inttypes.h>
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
4 #include <sys/cdio.h>
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
5 #include <sys/scsiio.h>
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
6
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
7 #define CDROM_LEADOUT 0xAA
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
8
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
9 typedef struct mp_vcd_priv_st {
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
10 int fd;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
11 struct ioc_read_toc_entry entry;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
12 struct cd_toc_entry entry_data;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
13 } mp_vcd_priv_t;
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
14
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
15 static inline void
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
16 vcd_set_msf(mp_vcd_priv_t* vcd, unsigned int sect)
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
17 {
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
18 vcd->entry_data.addr.msf.frame = sect % 75;
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
19 sect = sect / 75;
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
20 vcd->entry_data.addr.msf.second = sect % 60;
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
21 sect = sect / 60;
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
22 vcd->entry_data.addr.msf.minute = sect;
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
23 }
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
24
8532
9688aa033083 fix VCD playback - this is a patch from the netbsd pkgsrc tree,
arpi
parents: 7406
diff changeset
25 static inline void
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
26 vcd_inc_msf(mp_vcd_priv_t* vcd)
8532
9688aa033083 fix VCD playback - this is a patch from the netbsd pkgsrc tree,
arpi
parents: 7406
diff changeset
27 {
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
28 vcd->entry_data.addr.msf.frame++;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
29 if (vcd->entry_data.addr.msf.frame==75){
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
30 vcd->entry_data.addr.msf.frame=0;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
31 vcd->entry_data.addr.msf.second++;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
32 if (vcd->entry_data.addr.msf.second==60){
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
33 vcd->entry_data.addr.msf.second=0;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
34 vcd->entry_data.addr.msf.minute++;
8532
9688aa033083 fix VCD playback - this is a patch from the netbsd pkgsrc tree,
arpi
parents: 7406
diff changeset
35 }
9688aa033083 fix VCD playback - this is a patch from the netbsd pkgsrc tree,
arpi
parents: 7406
diff changeset
36 }
9688aa033083 fix VCD playback - this is a patch from the netbsd pkgsrc tree,
arpi
parents: 7406
diff changeset
37 }
9688aa033083 fix VCD playback - this is a patch from the netbsd pkgsrc tree,
arpi
parents: 7406
diff changeset
38
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
39 static inline unsigned int
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
40 vcd_get_msf(mp_vcd_priv_t* vcd)
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
41 {
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
42 return vcd->entry_data.addr.msf.frame +
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
43 (vcd->entry_data.addr.msf.second +
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
44 vcd->entry_data.addr.msf.minute * 60) * 75;
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
45 }
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
46
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
47 int
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
48 vcd_seek_to_track(mp_vcd_priv_t* vcd, int track)
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
49 {
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
50 vcd->entry.address_format = CD_MSF_FORMAT;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
51 vcd->entry.starting_track = track;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
52 vcd->entry.data_len = sizeof(struct cd_toc_entry);
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
53 vcd->entry.data = &vcd->entry_data;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
54 if (ioctl(vcd->fd, CDIOREADTOCENTRIES, &vcd->entry)) {
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
55 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif1: %s\n",strerror(errno));
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
56 return -1;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
57 }
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
58 return VCD_SECTOR_DATA * vcd_get_msf(vcd);
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
59 }
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
60
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
61 int
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
62 vcd_get_track_end(mp_vcd_priv_t* vcd, int track)
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
63 {
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
64 struct ioc_toc_header tochdr;
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
65 if (ioctl(vcd->fd, CDIOREADTOCHEADER, &tochdr) == -1) {
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
66 mp_msg(MSGT_STREAM,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
67 return -1;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
68 }
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
69 vcd->entry.address_format = CD_MSF_FORMAT;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
70 vcd->entry.starting_track = track < tochdr.ending_track ? (track + 1) : CDROM_LEADOUT;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
71 vcd->entry.data_len = sizeof(struct cd_toc_entry);
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
72 vcd->entry.data = &vcd->entry_data;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
73 if (ioctl(vcd->fd, CDIOREADTOCENTRYS, &vcd->entry)) {
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
74 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno));
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
75 return -1;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
76 }
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
77 return VCD_SECTOR_DATA * vcd_get_msf(vcd);
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
78 }
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
79
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
80 mp_vcd_priv_t*
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
81 vcd_read_toc(int fd)
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
82 {
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
83 struct ioc_toc_header tochdr;
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
84 mp_vcd_priv_t* vcd;
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
85 int i;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
86 if (ioctl(fd, CDIOREADTOCHEADER, &tochdr) == -1) {
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
87 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
88 return;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
89 }
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
90 for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) {
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
91 struct ioc_read_toc_entry tocentry;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
92 struct cd_toc_entry tocentry_data;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
93
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
94 tocentry.starting_track = i;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
95 tocentry.address_format = CD_MSF_FORMAT;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
96 tocentry.data_len = sizeof(struct cd_toc_entry);
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
97 tocentry.data = &tocentry_data;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
98
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
99 if (ioctl(fd, CDIOREADTOCENTRYS, &tocentry) == -1) {
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
100 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno));
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
101 return NULL;
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
102 }
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
103 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n",
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
104 (int) tocentry.starting_track,
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
105 (int) tocentry.data->addr_type,
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
106 (int) tocentry.data->control,
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
107 (int) tocentry.address_format,
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
108 (int) tocentry.data->addr.msf.minute,
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
109 (int) tocentry.data->addr.msf.second,
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
110 (int) tocentry.data->addr.msf.frame
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
111 );
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
112 }
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
113 vcd = malloc(sizeof(mp_vcd_priv_t));
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
114 vcd->fd = fd;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
115 return vcd;
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
116 }
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
117
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
118 static int
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
119 vcd_read(mp_vcd_priv_t* vcd, char *mem)
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
120 {
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
121 struct scsireq sc;
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
122 int lba = vcd_get_msf(vcd);
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
123 int blocks;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
124 int sector_type;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
125 int sync, header_code, user_data, edc_ecc, error_field;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
126 int sub_channel;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
127 int rc;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
128
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
129 blocks = 1;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
130 sector_type = 5; /* mode2/form2 */
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
131 sync = 0;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
132 header_code = 0;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
133 user_data = 1;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
134 edc_ecc = 0;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
135 error_field = 0;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
136 sub_channel = 0;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
137
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
138 memset(&sc, 0, sizeof(sc));
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
139 sc.cmd[0] = 0xBE;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
140 sc.cmd[1] = (sector_type) << 2;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
141 sc.cmd[2] = (lba >> 24) & 0xff;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
142 sc.cmd[3] = (lba >> 16) & 0xff;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
143 sc.cmd[4] = (lba >> 8) & 0xff;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
144 sc.cmd[5] = lba & 0xff;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
145 sc.cmd[6] = (blocks >> 16) & 0xff;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
146 sc.cmd[7] = (blocks >> 8) & 0xff;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
147 sc.cmd[8] = blocks & 0xff;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
148 sc.cmd[9] = (sync << 7) | (header_code << 5) | (user_data << 4) |
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
149 (edc_ecc << 3) | (error_field << 1);
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
150 sc.cmd[10] = sub_channel;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
151 sc.cmdlen = 12;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
152 sc.databuf = (caddr_t) mem;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
153 sc.datalen = 2328;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
154 sc.senselen = sizeof(sc.sense);
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
155 sc.flags = SCCMD_READ;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
156 sc.timeout = 10000;
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
157 rc = ioctl(vcd->fd, SCIOCCOMMAND, &sc);
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
158 if (rc == -1) {
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
159 mp_msg(MSGT_STREAM,MSGL_ERR,"SCIOCCOMMAND: %s\n",strerror(errno));
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
160 return -1;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
161 }
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
162 if (sc.retsts || sc.error) {
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
163 mp_msg(MSGT_STREAM,MSGL_ERR,"scsi command failed: status %d error %d\n",
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
164 sc.retsts,sc.error);
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
165 return -1;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
166 }
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 8532
diff changeset
167 vcd_inc_msf(vcd);
5872
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
168 return VCD_SECTOR_DATA;
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
169 }
02576893af2a OpenBSD, NetBSD portability patches by
arpi
parents:
diff changeset
170