Mercurial > mplayer.hg
annotate stream/vcd_read_nbsd.h @ 23856:07d30c4c81b8
READ_TOC for making *BSD code more similar
author | reimar |
---|---|
date | Fri, 27 Jul 2007 17:18:03 +0000 |
parents | 3522fdbd3d2a |
children |
rev | line source |
---|---|
5872 | 1 |
2 #include <sys/types.h> | |
23854 | 3 #include <inttypes.h> |
23853 | 4 #include "libavutil/intreadwrite.h" |
5872 | 5 #include <sys/cdio.h> |
6 #include <sys/scsiio.h> | |
7 | |
8 #define CDROM_LEADOUT 0xAA | |
23847
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
9 #define TOCADDR(te) ((te).data->addr) |
23856 | 10 #define READ_TOC CDIOREADTOCENTRYS |
5872 | 11 |
9887 | 12 typedef struct mp_vcd_priv_st { |
13 int fd; | |
14 struct ioc_read_toc_entry entry; | |
15 struct cd_toc_entry entry_data; | |
16 } mp_vcd_priv_t; | |
5872 | 17 |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
18 static inline void |
9887 | 19 vcd_set_msf(mp_vcd_priv_t* vcd, unsigned int sect) |
5872 | 20 { |
23847
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
21 vcd->entry.data = &vcd->entry_data; |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
22 TOCADDR(vcd->entry).msf.frame = sect % 75; |
5872 | 23 sect = sect / 75; |
23847
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
24 TOCADDR(vcd->entry).msf.second = sect % 60; |
5872 | 25 sect = sect / 60; |
23847
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
26 TOCADDR(vcd->entry).msf.minute = sect; |
5872 | 27 } |
28 | |
8532
9688aa033083
fix VCD playback - this is a patch from the netbsd pkgsrc tree,
arpi
parents:
7406
diff
changeset
|
29 static inline void |
9887 | 30 vcd_inc_msf(mp_vcd_priv_t* vcd) |
8532
9688aa033083
fix VCD playback - this is a patch from the netbsd pkgsrc tree,
arpi
parents:
7406
diff
changeset
|
31 { |
23847
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
32 vcd->entry.data = &vcd->entry_data; |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
33 TOCADDR(vcd->entry).msf.frame++; |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
34 if (TOCADDR(vcd->entry).msf.frame==75){ |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
35 TOCADDR(vcd->entry).msf.frame=0; |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
36 TOCADDR(vcd->entry).msf.second++; |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
37 if (TOCADDR(vcd->entry).msf.second==60){ |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
38 TOCADDR(vcd->entry).msf.second=0; |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
39 TOCADDR(vcd->entry).msf.minute++; |
8532
9688aa033083
fix VCD playback - this is a patch from the netbsd pkgsrc tree,
arpi
parents:
7406
diff
changeset
|
40 } |
9688aa033083
fix VCD playback - this is a patch from the netbsd pkgsrc tree,
arpi
parents:
7406
diff
changeset
|
41 } |
9688aa033083
fix VCD playback - this is a patch from the netbsd pkgsrc tree,
arpi
parents:
7406
diff
changeset
|
42 } |
9688aa033083
fix VCD playback - this is a patch from the netbsd pkgsrc tree,
arpi
parents:
7406
diff
changeset
|
43 |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
44 static inline unsigned int |
9887 | 45 vcd_get_msf(mp_vcd_priv_t* vcd) |
5872 | 46 { |
23847
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
47 vcd->entry.data = &vcd->entry_data; |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
48 return TOCADDR(vcd->entry).msf.frame + |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
49 (TOCADDR(vcd->entry).msf.second + |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
50 TOCADDR(vcd->entry).msf.minute * 60) * 75; |
5872 | 51 } |
52 | |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
53 int |
9887 | 54 vcd_seek_to_track(mp_vcd_priv_t* vcd, int track) |
5872 | 55 { |
9887 | 56 vcd->entry.address_format = CD_MSF_FORMAT; |
57 vcd->entry.starting_track = track; | |
58 vcd->entry.data_len = sizeof(struct cd_toc_entry); | |
59 vcd->entry.data = &vcd->entry_data; | |
23856 | 60 if (ioctl(vcd->fd, READ_TOC, &vcd->entry)) { |
9887 | 61 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif1: %s\n",strerror(errno)); |
5872 | 62 return -1; |
63 } | |
9887 | 64 return VCD_SECTOR_DATA * vcd_get_msf(vcd); |
5872 | 65 } |
66 | |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
67 int |
9887 | 68 vcd_get_track_end(mp_vcd_priv_t* vcd, int track) |
5872 | 69 { |
70 struct ioc_toc_header tochdr; | |
9887 | 71 if (ioctl(vcd->fd, CDIOREADTOCHEADER, &tochdr) == -1) { |
72 mp_msg(MSGT_STREAM,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); | |
5872 | 73 return -1; |
74 } | |
9887 | 75 vcd->entry.address_format = CD_MSF_FORMAT; |
76 vcd->entry.starting_track = track < tochdr.ending_track ? (track + 1) : CDROM_LEADOUT; | |
77 vcd->entry.data_len = sizeof(struct cd_toc_entry); | |
78 vcd->entry.data = &vcd->entry_data; | |
23856 | 79 if (ioctl(vcd->fd, READ_TOC, &vcd->entry)) { |
9887 | 80 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno)); |
5872 | 81 return -1; |
82 } | |
9887 | 83 return VCD_SECTOR_DATA * vcd_get_msf(vcd); |
5872 | 84 } |
85 | |
9887 | 86 mp_vcd_priv_t* |
5872 | 87 vcd_read_toc(int fd) |
88 { | |
89 struct ioc_toc_header tochdr; | |
9887 | 90 mp_vcd_priv_t* vcd; |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
91 int i, min = 0, sec = 0, frame = 0; |
5872 | 92 if (ioctl(fd, CDIOREADTOCHEADER, &tochdr) == -1) { |
9887 | 93 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); |
23850 | 94 return NULL; |
5872 | 95 } |
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
|
96 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
|
97 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", tochdr.ending_track); |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
98 for (i = tochdr.starting_track; i <= tochdr.ending_track + 1; i++) { |
5872 | 99 struct ioc_read_toc_entry tocentry; |
100 struct cd_toc_entry tocentry_data; | |
101 | |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
102 tocentry.starting_track = i<=tochdr.ending_track ? i : CDROM_LEADOUT; |
5872 | 103 tocentry.address_format = CD_MSF_FORMAT; |
104 tocentry.data_len = sizeof(struct cd_toc_entry); | |
105 tocentry.data = &tocentry_data; | |
106 | |
23856 | 107 if (ioctl(fd, READ_TOC, &tocentry) == -1) { |
9887 | 108 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno)); |
109 return NULL; | |
5872 | 110 } |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
111 |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
112 if (i <= tochdr.ending_track) |
9887 | 113 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n", |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
114 (int)tocentry.starting_track, |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
115 (int)tocentry.data->addr_type, |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
116 (int)tocentry.data->control, |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
117 (int)tocentry.address_format, |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
118 (int)TOCADDR(tocentry).msf.minute, |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
119 (int)TOCADDR(tocentry).msf.second, |
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
120 (int)TOCADDR(tocentry).msf.frame |
5872 | 121 ); |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
122 |
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
|
123 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO)) |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
124 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
125 if (i > tochdr.starting_track) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
126 { |
23847
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
127 min = TOCADDR(tocentry).msf.minute - min; |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
128 sec = TOCADDR(tocentry).msf.second - sec; |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
129 frame = TOCADDR(tocentry).msf.frame - frame; |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
130 if ( frame < 0 ) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
131 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
132 frame += 75; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
133 sec --; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
134 } |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
135 if ( sec < 0 ) |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
136 { |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
137 sec += 60; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
138 min --; |
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
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_TRACK_%d_MSF=%02d:%02d:%02d\n", i - 1, min, sec, frame); |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
141 } |
23847
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
142 min = TOCADDR(tocentry).msf.minute; |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
143 sec = TOCADDR(tocentry).msf.second; |
773e6c50d1b8
TOCADDR macro as first step to common *BSD vcd reading code
reimar
parents:
19271
diff
changeset
|
144 frame = TOCADDR(tocentry).msf.frame; |
16547
aa15d627a00b
Prints the numbers of start and end tracks and MSF length for each
gpoirier
parents:
12797
diff
changeset
|
145 } |
5872 | 146 } |
9887 | 147 vcd = malloc(sizeof(mp_vcd_priv_t)); |
148 vcd->fd = fd; | |
149 return vcd; | |
5872 | 150 } |
151 | |
23849
2911a78219a8
Cosmetics to reduce diff between Free- and netBSD vcd stuff
reimar
parents:
23848
diff
changeset
|
152 static int |
9887 | 153 vcd_read(mp_vcd_priv_t* vcd, char *mem) |
5872 | 154 { |
155 struct scsireq sc; | |
9887 | 156 int lba = vcd_get_msf(vcd); |
5872 | 157 int blocks; |
158 int rc; | |
159 | |
160 blocks = 1; | |
161 | |
162 memset(&sc, 0, sizeof(sc)); | |
163 sc.cmd[0] = 0xBE; | |
23853 | 164 sc.cmd[1] = 5 << 2; // mode2/form2 |
165 AV_WB32(&sc.cmd[2], lba); | |
166 AV_WB24(&sc.cmd[6], blocks); | |
167 sc.cmd[9] = 1 << 4; // user data only | |
168 sc.cmd[10] = 0; // no subchannel | |
5872 | 169 sc.cmdlen = 12; |
170 sc.databuf = (caddr_t) mem; | |
171 sc.datalen = 2328; | |
172 sc.senselen = sizeof(sc.sense); | |
173 sc.flags = SCCMD_READ; | |
174 sc.timeout = 10000; | |
9887 | 175 rc = ioctl(vcd->fd, SCIOCCOMMAND, &sc); |
5872 | 176 if (rc == -1) { |
9887 | 177 mp_msg(MSGT_STREAM,MSGL_ERR,"SCIOCCOMMAND: %s\n",strerror(errno)); |
5872 | 178 return -1; |
179 } | |
180 if (sc.retsts || sc.error) { | |
9887 | 181 mp_msg(MSGT_STREAM,MSGL_ERR,"scsi command failed: status %d error %d\n", |
182 sc.retsts,sc.error); | |
5872 | 183 return -1; |
184 } | |
9887 | 185 vcd_inc_msf(vcd); |
5872 | 186 return VCD_SECTOR_DATA; |
187 } | |
188 |