comparison stream/vcd_read_fbsd.h @ 23860:866b72d264a8

Some more *BSD vcd_read simplification
author reimar
date Fri, 27 Jul 2007 18:34:09 +0000
parents df48923d6325
children 5d8097aa11cc
comparison
equal deleted inserted replaced
23859:df48923d6325 23860:866b72d264a8
89 * \param dst buffer to read data into 89 * \param dst buffer to read data into
90 * \param nr track number to read info for 90 * \param nr track number to read info for
91 * \return 1 on success, 0 on failure 91 * \return 1 on success, 0 on failure
92 */ 92 */
93 static int 93 static int
94 read_toc_entry(int fd, vcd_tocentry *dst, int nr) 94 read_toc_entry(mp_vcd_priv_t *vcd, int nr)
95 { 95 {
96 dst->address_format = CD_MSF_FORMAT; 96 vcd->entry.address_format = CD_MSF_FORMAT;
97 #ifdef VCD_NETBSD 97 #ifdef VCD_NETBSD
98 dst->starting_track = nr; 98 vcd->entry.data_len = sizeof(struct cd_toc_entry);
99 #else 99 vcd->entry.data = &vcd->entry_data;
100 dst->track = nr; 100 vcd->entry.starting_track = nr;
101 #endif 101 #else
102 if (ioctl(fd, READ_TOC, dst) == -1) { 102 vcd->entry.track = nr;
103 #endif
104 if (ioctl(vcd->fd, READ_TOC, &vcd->entry) == -1) {
103 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno)); 105 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno));
104 return 0; 106 return 0;
105 } 107 }
106 return 1; 108 return 1;
107 } 109 }
108 110
109 int 111 int
110 vcd_seek_to_track(mp_vcd_priv_t* vcd, int track) 112 vcd_seek_to_track(mp_vcd_priv_t* vcd, int track)
111 { 113 {
112 #ifdef VCD_NETBSD 114 if (!read_toc_entry(vcd, track))
113 vcd->entry.data_len = sizeof(struct cd_toc_entry);
114 vcd->entry.data = &vcd->entry_data;
115 #endif
116 if (!read_toc_entry(vcd->fd, &vcd->entry, track))
117 return -1; 115 return -1;
118 return VCD_SECTOR_DATA * vcd_get_msf(vcd); 116 return VCD_SECTOR_DATA * vcd_get_msf(vcd);
119 } 117 }
120 118
121 int 119 int
124 struct ioc_toc_header tochdr; 122 struct ioc_toc_header tochdr;
125 if (ioctl(vcd->fd, CDIOREADTOCHEADER, &tochdr) == -1) { 123 if (ioctl(vcd->fd, CDIOREADTOCHEADER, &tochdr) == -1) {
126 mp_msg(MSGT_STREAM,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); 124 mp_msg(MSGT_STREAM,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
127 return -1; 125 return -1;
128 } 126 }
129 #ifdef VCD_NETBSD 127 if (!read_toc_entry(vcd,
130 vcd->entry.data_len = sizeof(struct cd_toc_entry);
131 vcd->entry.data = &vcd->entry_data;
132 #endif
133 if (!read_toc_entry(vcd->fd, &vcd->entry,
134 track < tochdr.ending_track ? track + 1 : CDROM_LEADOUT)) 128 track < tochdr.ending_track ? track + 1 : CDROM_LEADOUT))
135 return -1; 129 return -1;
136 return VCD_SECTOR_DATA * vcd_get_msf(vcd); 130 return VCD_SECTOR_DATA * vcd_get_msf(vcd);
137 } 131 }
138 132
146 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); 140 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
147 return NULL; 141 return NULL;
148 } 142 }
149 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", tochdr.starting_track); 143 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", tochdr.starting_track);
150 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", tochdr.ending_track); 144 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", tochdr.ending_track);
145 vcd = malloc(sizeof(mp_vcd_priv_t));
146 vcd->fd = fd;
151 for (i = tochdr.starting_track; i <= tochdr.ending_track + 1; i++) { 147 for (i = tochdr.starting_track; i <= tochdr.ending_track + 1; i++) {
152 vcd_tocentry tocentry; 148 if (!read_toc_entry(vcd,
153 #ifdef VCD_NETBSD 149 i <= tochdr.ending_track ? i : CDROM_LEADOUT)) {
154 struct cd_toc_entry tocentry_data; 150 free(vcd);
155 tocentry.data_len = sizeof(struct cd_toc_entry);
156 tocentry.data = &tocentry_data;
157 #endif
158 if (!read_toc_entry(fd, &tocentry,
159 i <= tochdr.ending_track ? i : CDROM_LEADOUT))
160 return NULL; 151 return NULL;
152 }
161 153
162 if (i <= tochdr.ending_track) 154 if (i <= tochdr.ending_track)
163 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n", 155 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n",
164 #ifdef VCD_NETBSD 156 #ifdef VCD_NETBSD
165 (int)tocentry.starting_track, 157 (int)vcd->entry.starting_track,
166 (int)tocentry.data->addr_type, 158 (int)vcd->entry.data->addr_type,
167 (int)tocentry.data->control, 159 (int)vcd->entry.data->control,
168 #else 160 #else
169 (int)tocentry.track, 161 (int)vcd->entry.track,
170 (int)tocentry.entry.addr_type, 162 (int)vcd->entry.entry.addr_type,
171 (int)tocentry.entry.control, 163 (int)vcd->entry.entry.control,
172 #endif 164 #endif
173 (int)tocentry.address_format, 165 (int)vcd->entry.address_format,
174 (int)TOCADDR(tocentry).msf.minute, 166 (int)TOCADDR(vcd->entry).msf.minute,
175 (int)TOCADDR(tocentry).msf.second, 167 (int)TOCADDR(vcd->entry).msf.second,
176 (int)TOCADDR(tocentry).msf.frame 168 (int)TOCADDR(vcd->entry).msf.frame
177 ); 169 );
178 170
179 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO)) 171 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO))
180 { 172 {
181 if (i > tochdr.starting_track) 173 if (i > tochdr.starting_track)
182 { 174 {
183 min = TOCADDR(tocentry).msf.minute - min; 175 min = TOCADDR(vcd->entry).msf.minute - min;
184 sec = TOCADDR(tocentry).msf.second - sec; 176 sec = TOCADDR(vcd->entry).msf.second - sec;
185 frame = TOCADDR(tocentry).msf.frame - frame; 177 frame = TOCADDR(vcd->entry).msf.frame - frame;
186 if ( frame < 0 ) 178 if ( frame < 0 )
187 { 179 {
188 frame += 75; 180 frame += 75;
189 sec --; 181 sec --;
190 } 182 }
193 sec += 60; 185 sec += 60;
194 min --; 186 min --;
195 } 187 }
196 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_TRACK_%d_MSF=%02d:%02d:%02d\n", i - 1, min, sec, frame); 188 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_TRACK_%d_MSF=%02d:%02d:%02d\n", i - 1, min, sec, frame);
197 } 189 }
198 min = TOCADDR(tocentry).msf.minute; 190 min = TOCADDR(vcd->entry).msf.minute;
199 sec = TOCADDR(tocentry).msf.second; 191 sec = TOCADDR(vcd->entry).msf.second;
200 frame = TOCADDR(tocentry).msf.frame; 192 frame = TOCADDR(vcd->entry).msf.frame;
201 } 193 }
202 } 194 }
203 vcd = malloc(sizeof(mp_vcd_priv_t));
204 vcd->fd = fd;
205 return vcd; 195 return vcd;
206 } 196 }
207 197
208 static int 198 static int
209 vcd_read(mp_vcd_priv_t* vcd, char *mem) 199 vcd_read(mp_vcd_priv_t* vcd, char *mem)