Disable libavcodec AAC encoder, there are too many systems where it doesn't compile.
[mplayer/glamo.git] / stream / vcd_read_fbsd.h
blob132b6b2994c6eb8b82306c2ca2d6ee362e78fde0
1 #ifndef MPLAYER_VCD_READ_FBSD_H
2 #define MPLAYER_VCD_READ_FBSD_H
4 #include <sys/types.h>
5 #include <inttypes.h>
6 #include "libavutil/intreadwrite.h"
7 #include <sys/cdio.h>
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
16 #include <sys/cdrio.h>
17 #define TOCADDR(te) ((te).entry.addr)
18 #define READ_TOC CDIOREADTOCENTRY
19 #endif
20 #include "mp_msg.h"
22 //=================== VideoCD ==========================
23 #define CDROM_LEADOUT 0xAA
25 typedef struct {
26 uint8_t sync [12];
27 uint8_t header [4];
28 uint8_t subheader [8];
29 uint8_t data [2324];
30 uint8_t spare [4];
31 } cdsector_t;
33 #ifdef VCD_NETBSD
34 typedef struct ioc_read_toc_entry vcd_tocentry;
35 #else
36 typedef struct ioc_read_toc_single_entry vcd_tocentry;
37 #endif
39 typedef struct mp_vcd_priv_st {
40 int fd;
41 vcd_tocentry entry;
42 #ifdef VCD_NETBSD
43 struct cd_toc_entry entry_data;
44 #else
45 cdsector_t buf;
46 #endif
47 struct ioc_toc_header tochdr;
48 } mp_vcd_priv_t;
50 static inline void
51 vcd_set_msf(mp_vcd_priv_t* vcd, unsigned int sect)
53 #ifdef VCD_NETBSD
54 vcd->entry.data = &vcd->entry_data;
55 #endif
56 sect += 150;
57 TOCADDR(vcd->entry).msf.frame = sect % 75;
58 sect = sect / 75;
59 TOCADDR(vcd->entry).msf.second = sect % 60;
60 sect = sect / 60;
61 TOCADDR(vcd->entry).msf.minute = sect;
64 static inline void
65 vcd_inc_msf(mp_vcd_priv_t* vcd)
67 #ifdef VCD_NETBSD
68 vcd->entry.data = &vcd->entry_data;
69 #endif
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++;
81 static inline unsigned int
82 vcd_get_msf(mp_vcd_priv_t* vcd)
84 #ifdef VCD_NETBSD
85 vcd->entry.data = &vcd->entry_data;
86 #endif
87 return TOCADDR(vcd->entry).msf.frame +
88 (TOCADDR(vcd->entry).msf.second +
89 TOCADDR(vcd->entry).msf.minute * 60) * 75 - 150;
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
99 static int
100 read_toc_entry(mp_vcd_priv_t *vcd, int nr)
102 vcd->entry.address_format = CD_MSF_FORMAT;
103 #ifdef VCD_NETBSD
104 vcd->entry.data_len = sizeof(struct cd_toc_entry);
105 vcd->entry.data = &vcd->entry_data;
106 vcd->entry.starting_track = nr;
107 #else
108 vcd->entry.track = nr;
109 #endif
110 if (ioctl(vcd->fd, READ_TOC, &vcd->entry) == -1) {
111 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno));
112 return 0;
114 return 1;
118 vcd_seek_to_track(mp_vcd_priv_t* vcd, int track)
120 if (!read_toc_entry(vcd, track))
121 return -1;
122 return VCD_SECTOR_DATA * vcd_get_msf(vcd);
126 vcd_get_track_end(mp_vcd_priv_t* vcd, int track)
128 if (!read_toc_entry(vcd,
129 track < vcd->tochdr.ending_track ? track + 1 : CDROM_LEADOUT))
130 return -1;
131 return VCD_SECTOR_DATA * vcd_get_msf(vcd);
134 mp_vcd_priv_t*
135 vcd_read_toc(int fd)
137 struct ioc_toc_header tochdr;
138 mp_vcd_priv_t* vcd;
139 int i, last_startsect;
140 if (ioctl(fd, CDIOREADTOCHEADER, &tochdr) == -1) {
141 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
142 return NULL;
144 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", tochdr.starting_track);
145 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", tochdr.ending_track);
146 vcd = malloc(sizeof(mp_vcd_priv_t));
147 vcd->fd = fd;
148 vcd->tochdr = tochdr;
149 for (i = tochdr.starting_track; i <= tochdr.ending_track + 1; i++) {
150 if (!read_toc_entry(vcd,
151 i <= tochdr.ending_track ? i : CDROM_LEADOUT)) {
152 free(vcd);
153 return NULL;
156 if (i <= tochdr.ending_track)
157 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n",
158 #ifdef VCD_NETBSD
159 (int)vcd->entry.starting_track,
160 (int)vcd->entry.data->addr_type,
161 (int)vcd->entry.data->control,
162 #else
163 (int)vcd->entry.track,
164 (int)vcd->entry.entry.addr_type,
165 (int)vcd->entry.entry.control,
166 #endif
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
173 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO))
175 int startsect = vcd_get_msf(vcd);
176 if (i > tochdr.starting_track)
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);
187 last_startsect = startsect;
190 return vcd;
193 static int
194 vcd_read(mp_vcd_priv_t* vcd, char *mem)
196 #ifdef VCD_NETBSD
197 struct scsireq sc;
198 int lba = vcd_get_msf(vcd);
199 int blocks;
200 int rc;
202 blocks = 1;
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;
213 sc.datalen = VCD_SECTOR_DATA;
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;
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;
227 #else
228 if (pread(vcd->fd,&vcd->buf,VCD_SECTOR_SIZE,vcd_get_msf(vcd)*VCD_SECTOR_SIZE)
229 != VCD_SECTOR_SIZE) return 0; // EOF?
231 memcpy(mem,vcd->buf.data,VCD_SECTOR_DATA);
232 #endif
233 vcd_inc_msf(vcd);
234 return VCD_SECTOR_DATA;
237 #endif /* MPLAYER_VCD_READ_FBSD_H */