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