annotate stream/vcd_read_fbsd.h @ 23940:1b3e61a77754

Update copyright info and license
author ivo
date Tue, 31 Jul 2007 08:17:35 +0000
parents a20ea1dd0812
children aef6ff061c9a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23857
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
1 #include <sys/types.h>
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
2 #include <inttypes.h>
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
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
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
5 #if defined(__NetBSD__) || defined(__OpenBSD__)
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
6 #define VCD_NETBSD 1
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
7 #endif
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
8 #ifdef VCD_NETBSD
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
9 #include <sys/scsiio.h>
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
10 #define TOCADDR(te) ((te).data->addr)
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
11 #define READ_TOC CDIOREADTOCENTRYS
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
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
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
14 #define TOCADDR(te) ((te).entry.addr)
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
15 #define READ_TOC CDIOREADTOCENTRY
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
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
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
29 #ifdef VCD_NETBSD
23859
df48923d6325 Fix several 100l
reimar
parents: 23858
diff changeset
30 typedef struct ioc_read_toc_entry vcd_tocentry;
23858
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
31 #else
23859
df48923d6325 Fix several 100l
reimar
parents: 23858
diff changeset
32 typedef struct ioc_read_toc_single_entry vcd_tocentry;
23858
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
33 #endif
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
34
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
35 typedef struct mp_vcd_priv_st {
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
36 int fd;
23858
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
37 vcd_tocentry entry;
23857
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
38 #ifdef VCD_NETBSD
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
39 struct cd_toc_entry entry_data;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
40 #else
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
41 cdsector_t buf;
23857
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
42 #endif
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
43 } mp_vcd_priv_t;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
44
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
45 static inline void
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
46 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
47 {
23857
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
48 #ifdef VCD_NETBSD
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
49 vcd->entry.data = &vcd->entry_data;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
50 #endif
23862
a20ea1dd0812 Fix MSF -> sector conversion being 150 sectors of
reimar
parents: 23861
diff changeset
51 sect += 150;
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
52 TOCADDR(vcd->entry).msf.frame = sect % 75;
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
53 sect = sect / 75;
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
54 TOCADDR(vcd->entry).msf.second = sect % 60;
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
55 sect = sect / 60;
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
56 TOCADDR(vcd->entry).msf.minute = sect;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
57 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
58
23852
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
59 static inline void
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
60 vcd_inc_msf(mp_vcd_priv_t* vcd)
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
61 {
23857
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
62 #ifdef VCD_NETBSD
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
63 vcd->entry.data = &vcd->entry_data;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
64 #endif
23852
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
65 TOCADDR(vcd->entry).msf.frame++;
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
66 if (TOCADDR(vcd->entry).msf.frame==75){
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
67 TOCADDR(vcd->entry).msf.frame=0;
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
68 TOCADDR(vcd->entry).msf.second++;
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
69 if (TOCADDR(vcd->entry).msf.second==60){
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
70 TOCADDR(vcd->entry).msf.second=0;
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
71 TOCADDR(vcd->entry).msf.minute++;
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
72 }
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
73 }
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
74 }
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
75
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
76 static inline unsigned int
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
77 vcd_get_msf(mp_vcd_priv_t* vcd)
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
78 {
23857
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
79 #ifdef VCD_NETBSD
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
80 vcd->entry.data = &vcd->entry_data;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
81 #endif
23847
773e6c50d1b8 TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents: 19271
diff changeset
82 return TOCADDR(vcd->entry).msf.frame +
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
83 (TOCADDR(vcd->entry).msf.second +
23862
a20ea1dd0812 Fix MSF -> sector conversion being 150 sectors of
reimar
parents: 23861
diff changeset
84 TOCADDR(vcd->entry).msf.minute * 60) * 75 - 150;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
85 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
86
23858
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
87 /**
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
88 * \brief read a TOC entry
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
89 * \param fd device to read from
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
90 * \param dst buffer to read data into
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
91 * \param nr track number to read info for
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
92 * \return 1 on success, 0 on failure
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
93 */
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
94 static int
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
95 read_toc_entry(mp_vcd_priv_t *vcd, int nr)
23858
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
96 {
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
97 vcd->entry.address_format = CD_MSF_FORMAT;
23858
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
98 #ifdef VCD_NETBSD
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
99 vcd->entry.data_len = sizeof(struct cd_toc_entry);
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
100 vcd->entry.data = &vcd->entry_data;
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
101 vcd->entry.starting_track = nr;
23858
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
102 #else
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
103 vcd->entry.track = nr;
23858
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
104 #endif
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
105 if (ioctl(vcd->fd, READ_TOC, &vcd->entry) == -1) {
23858
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
106 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno));
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
107 return 0;
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
108 }
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
109 return 1;
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
110 }
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
111
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
112 int
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
113 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
114 {
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
115 if (!read_toc_entry(vcd, track))
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
116 return -1;
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
117 return VCD_SECTOR_DATA * vcd_get_msf(vcd);
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
118 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
119
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
120 int
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
121 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
122 {
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
123 struct ioc_toc_header tochdr;
23851
6dbeddab0b45 More VCD cosmetics
reimar
parents: 23849
diff changeset
124 if (ioctl(vcd->fd, CDIOREADTOCHEADER, &tochdr) == -1) {
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
125 mp_msg(MSGT_STREAM,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
126 return -1;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
127 }
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
128 if (!read_toc_entry(vcd,
23858
85cb783c723c Factor out some common code
reimar
parents: 23857
diff changeset
129 track < tochdr.ending_track ? track + 1 : CDROM_LEADOUT))
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
130 return -1;
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
131 return VCD_SECTOR_DATA * vcd_get_msf(vcd);
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
132 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
133
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
134 mp_vcd_priv_t*
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
135 vcd_read_toc(int fd)
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
136 {
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
137 struct ioc_toc_header tochdr;
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
138 mp_vcd_priv_t* vcd;
23861
5d8097aa11cc Simplify track length calculation
reimar
parents: 23860
diff changeset
139 int i, last_startsect;
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
140 if (ioctl(fd, CDIOREADTOCHEADER, &tochdr) == -1) {
9887
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
141 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
142 return NULL;
d862231858d5 Make the vcd API fully reentrant.
albeu
parents: 7406
diff changeset
143 }
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
144 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
145 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", tochdr.ending_track);
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
146 vcd = malloc(sizeof(mp_vcd_priv_t));
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
147 vcd->fd = fd;
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
148 for (i = tochdr.starting_track; i <= tochdr.ending_track + 1; i++) {
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
149 if (!read_toc_entry(vcd,
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
150 i <= tochdr.ending_track ? i : CDROM_LEADOUT)) {
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
151 free(vcd);
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
152 return NULL;
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
153 }
23851
6dbeddab0b45 More VCD cosmetics
reimar
parents: 23849
diff changeset
154
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
155 if (i <= tochdr.ending_track)
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
156 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n",
23857
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
157 #ifdef VCD_NETBSD
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
158 (int)vcd->entry.starting_track,
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
159 (int)vcd->entry.data->addr_type,
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
160 (int)vcd->entry.data->control,
23857
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
161 #else
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
162 (int)vcd->entry.track,
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
163 (int)vcd->entry.entry.addr_type,
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
164 (int)vcd->entry.entry.control,
23857
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
165 #endif
23860
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
166 (int)vcd->entry.address_format,
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
167 (int)TOCADDR(vcd->entry).msf.minute,
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
168 (int)TOCADDR(vcd->entry).msf.second,
866b72d264a8 Some more *BSD vcd_read simplification
reimar
parents: 23859
diff changeset
169 (int)TOCADDR(vcd->entry).msf.frame
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
170 );
16547
aa15d627a00b Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents: 9899
diff changeset
171
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
172 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO))
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
173 {
23861
5d8097aa11cc Simplify track length calculation
reimar
parents: 23860
diff changeset
174 int startsect = vcd_get_msf(vcd);
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
175 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
176 {
23861
5d8097aa11cc Simplify track length calculation
reimar
parents: 23860
diff changeset
177 // convert duraion to MSF
5d8097aa11cc Simplify track length calculation
reimar
parents: 23860
diff changeset
178 vcd_set_msf(vcd, startsect - last_startsect);
5d8097aa11cc Simplify track length calculation
reimar
parents: 23860
diff changeset
179 mp_msg(MSGT_IDENTIFY, MSGL_INFO,
5d8097aa11cc Simplify track length calculation
reimar
parents: 23860
diff changeset
180 "ID_VCD_TRACK_%d_MSF=%02d:%02d:%02d\n",
5d8097aa11cc Simplify track length calculation
reimar
parents: 23860
diff changeset
181 i - 1,
5d8097aa11cc Simplify track length calculation
reimar
parents: 23860
diff changeset
182 TOCADDR(vcd->entry).msf.minute,
5d8097aa11cc Simplify track length calculation
reimar
parents: 23860
diff changeset
183 TOCADDR(vcd->entry).msf.second,
5d8097aa11cc Simplify track length calculation
reimar
parents: 23860
diff changeset
184 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
185 }
23861
5d8097aa11cc Simplify track length calculation
reimar
parents: 23860
diff changeset
186 last_startsect = startsect;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
187 }
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
188 }
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
189 return vcd;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
190 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
191
23849
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
192 static int
2911a78219a8 Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents: 23847
diff changeset
193 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
194 {
23857
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
195 #ifdef VCD_NETBSD
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
196 struct scsireq sc;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
197 int lba = vcd_get_msf(vcd);
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
198 int blocks;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
199 int rc;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
200
23857
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
201 blocks = 1;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
202
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
203 memset(&sc, 0, sizeof(sc));
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
204 sc.cmd[0] = 0xBE;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
205 sc.cmd[1] = 5 << 2; // mode2/form2
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
206 AV_WB32(&sc.cmd[2], lba);
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
207 AV_WB24(&sc.cmd[6], blocks);
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
208 sc.cmd[9] = 1 << 4; // user data only
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
209 sc.cmd[10] = 0; // no subchannel
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
210 sc.cmdlen = 12;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
211 sc.databuf = (caddr_t) mem;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
212 sc.datalen = 2328;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
213 sc.senselen = sizeof(sc.sense);
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
214 sc.flags = SCCMD_READ;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
215 sc.timeout = 10000;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
216 rc = ioctl(vcd->fd, SCIOCCOMMAND, &sc);
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
217 if (rc == -1) {
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
218 mp_msg(MSGT_STREAM,MSGL_ERR,"SCIOCCOMMAND: %s\n",strerror(errno));
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
219 return -1;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
220 }
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
221 if (sc.retsts || sc.error) {
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
222 mp_msg(MSGT_STREAM,MSGL_ERR,"scsi command failed: status %d error %d\n",
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
223 sc.retsts,sc.error);
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
224 return -1;
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
225 }
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
226 #else
23851
6dbeddab0b45 More VCD cosmetics
reimar
parents: 23849
diff changeset
227 if (pread(vcd->fd,&vcd->buf,VCD_SECTOR_SIZE,vcd_get_msf(vcd)*VCD_SECTOR_SIZE)
6dbeddab0b45 More VCD cosmetics
reimar
parents: 23849
diff changeset
228 != VCD_SECTOR_SIZE) return 0; // EOF?
1177
f2516027a346 FreeBSD patch by Vladimir Kushnir <vkushnir@Alfacom.net>
arpi_esp
parents: 1038
diff changeset
229
23857
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
230 memcpy(mem,vcd->buf.data,VCD_SECTOR_DATA);
d5223bab4b92 Somewhat unified *BSD vcd reading
reimar
parents: 23856
diff changeset
231 #endif
23852
5982ecb1dcdf vcd_inc_msf function also for freebsd vcd_read
reimar
parents: 23851
diff changeset
232 vcd_inc_msf(vcd);
23851
6dbeddab0b45 More VCD cosmetics
reimar
parents: 23849
diff changeset
233 return VCD_SECTOR_DATA;
958
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
234 }
162a78d3cc08 FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
diff changeset
235