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