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