comparison stream/vcd_read_fbsd.h @ 23858:85cb783c723c

Factor out some common code
author reimar
date Fri, 27 Jul 2007 18:04:52 +0000
parents d5223bab4b92
children df48923d6325
comparison
equal deleted inserted replaced
23857:d5223bab4b92 23858:85cb783c723c
24 uint8_t subheader [8]; 24 uint8_t subheader [8];
25 uint8_t data [2324]; 25 uint8_t data [2324];
26 uint8_t spare [4]; 26 uint8_t spare [4];
27 } cdsector_t; 27 } cdsector_t;
28 28
29 #ifdef VCD_NETBSD
30 typedef struct ioc_read_toc_entry vcd_tocentry
31 #else
32 typedef struct ioc_read_toc_single_entry vcd_tocentry
33 #endif
34
29 typedef struct mp_vcd_priv_st { 35 typedef struct mp_vcd_priv_st {
30 int fd; 36 int fd;
31 #ifdef VCD_NETBSD 37 vcd_tocentry entry;
32 struct ioc_read_toc_entry entry; 38 #ifdef VCD_NETBSD
33 struct cd_toc_entry entry_data; 39 struct cd_toc_entry entry_data;
34 #else 40 #else
35 struct ioc_read_toc_single_entry entry;
36 cdsector_t buf; 41 cdsector_t buf;
37 #endif 42 #endif
38 } mp_vcd_priv_t; 43 } mp_vcd_priv_t;
39 44
40 static inline void 45 static inline void
76 return TOCADDR(vcd->entry).msf.frame + 81 return TOCADDR(vcd->entry).msf.frame +
77 (TOCADDR(vcd->entry).msf.second + 82 (TOCADDR(vcd->entry).msf.second +
78 TOCADDR(vcd->entry).msf.minute * 60) * 75; 83 TOCADDR(vcd->entry).msf.minute * 60) * 75;
79 } 84 }
80 85
86 /**
87 * \brief read a TOC entry
88 * \param fd device to read from
89 * \param dst buffer to read data into
90 * \param nr track number to read info for
91 * \return 1 on success, 0 on failure
92 */
93 static int
94 read_toc_entry(int fd, vcd_tocentry *dst, int nr)
95 {
96 dst->address_format = CD_MSF_FORMAT;
97 #ifdef VCD_NETBSD
98 dst->starting_track = nr;
99 #else
100 dst->track = nr;
101 #endif
102 if (ioctl(fd, READ_TOC, dst) == -1) {
103 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno));
104 return 0;
105 }
106 return 1;
107 }
108
81 int 109 int
82 vcd_seek_to_track(mp_vcd_priv_t* vcd, int track) 110 vcd_seek_to_track(mp_vcd_priv_t* vcd, int track)
83 { 111 {
84 vcd->entry.address_format = CD_MSF_FORMAT; 112 #ifdef VCD_NETBSD
85 #ifdef VCD_NETBSD
86 vcd->entry.starting_track = track;
87 vcd->entry.data_len = sizeof(struct cd_toc_entry); 113 vcd->entry.data_len = sizeof(struct cd_toc_entry);
88 vcd->entry.data = &vcd->entry_data; 114 vcd->entry.data = &vcd->entry_data;
89 #else 115 #endif
90 vcd->entry.track = track; 116 if (!read_toc_entry(vcd->fd, &vcd->entry, track))
91 #endif 117 return -1;
92 if (ioctl(vcd->fd, READ_TOC, &vcd->entry)) {
93 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif1: %s\n",strerror(errno));
94 return -1;
95 }
96 return VCD_SECTOR_DATA * vcd_get_msf(vcd); 118 return VCD_SECTOR_DATA * vcd_get_msf(vcd);
97 } 119 }
98 120
99 int 121 int
100 vcd_get_track_end(mp_vcd_priv_t* vcd, int track) 122 vcd_get_track_end(mp_vcd_priv_t* vcd, int track)
102 struct ioc_toc_header tochdr; 124 struct ioc_toc_header tochdr;
103 if (ioctl(vcd->fd, CDIOREADTOCHEADER, &tochdr) == -1) { 125 if (ioctl(vcd->fd, CDIOREADTOCHEADER, &tochdr) == -1) {
104 mp_msg(MSGT_STREAM,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno)); 126 mp_msg(MSGT_STREAM,MSGL_ERR,"read CDROM toc header: %s\n",strerror(errno));
105 return -1; 127 return -1;
106 } 128 }
107 vcd->entry.address_format = CD_MSF_FORMAT; 129 #ifdef VCD_NETBSD
108 #ifdef VCD_NETBSD
109 vcd->entry.starting_track = track < tochdr.ending_track ? (track + 1) : CDROM_LEADOUT;
110 vcd->entry.data_len = sizeof(struct cd_toc_entry); 130 vcd->entry.data_len = sizeof(struct cd_toc_entry);
111 vcd->entry.data = &vcd->entry_data; 131 vcd->entry.data = &vcd->entry_data;
112 #else 132 #endif
113 vcd->entry.track = track<tochdr.ending_track?(track+1):CDROM_LEADOUT; 133 if (!read_toc_entry(vcd->fd, &vcd->entry,
114 #endif 134 track < tochdr.ending_track ? track + 1 : CDROM_LEADOUT))
115 if (ioctl(vcd->fd, READ_TOC, &vcd->entry)) { 135 return -1;
116 mp_msg(MSGT_STREAM,MSGL_ERR,"ioctl dif2: %s\n",strerror(errno));
117 return -1;
118 }
119 return VCD_SECTOR_DATA * vcd_get_msf(vcd); 136 return VCD_SECTOR_DATA * vcd_get_msf(vcd);
120 } 137 }
121 138
122 mp_vcd_priv_t* 139 mp_vcd_priv_t*
123 vcd_read_toc(int fd) 140 vcd_read_toc(int fd)
130 return NULL; 147 return NULL;
131 } 148 }
132 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", tochdr.starting_track); 149 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_START_TRACK=%d\n", tochdr.starting_track);
133 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", tochdr.ending_track); 150 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VCD_END_TRACK=%d\n", tochdr.ending_track);
134 for (i = tochdr.starting_track; i <= tochdr.ending_track + 1; i++) { 151 for (i = tochdr.starting_track; i <= tochdr.ending_track + 1; i++) {
135 #ifdef VCD_NETBSD 152 vcd_tocentry tocentry;
136 struct ioc_read_toc_entry tocentry; 153 #ifdef VCD_NETBSD
137 struct cd_toc_entry tocentry_data; 154 struct cd_toc_entry tocentry_data;
138
139 tocentry.starting_track = i<=tochdr.ending_track ? i : CDROM_LEADOUT;
140 tocentry.data_len = sizeof(struct cd_toc_entry); 155 tocentry.data_len = sizeof(struct cd_toc_entry);
141 tocentry.data = &tocentry_data; 156 tocentry.data = &tocentry_data;
142 #else 157 #endif
143 struct ioc_read_toc_single_entry tocentry; 158 if (!read_toc_entry(fd, &tocentry,
144 159 i <= tochdr.ending_track ? i : CDROM_LEADOUT));
145 tocentry.track = i<=tochdr.ending_track ? i : CDROM_LEADOUT;
146 #endif
147 tocentry.address_format = CD_MSF_FORMAT;
148
149 if (ioctl(fd, READ_TOC, &tocentry) == -1) {
150 mp_msg(MSGT_OPEN,MSGL_ERR,"read CDROM toc entry: %s\n",strerror(errno));
151 return NULL; 160 return NULL;
152 }
153 161
154 if (i <= tochdr.ending_track) 162 if (i <= tochdr.ending_track)
155 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n", 163 mp_msg(MSGT_OPEN,MSGL_INFO,"track %02d: adr=%d ctrl=%d format=%d %02d:%02d:%02d\n",
156 #ifdef VCD_NETBSD 164 #ifdef VCD_NETBSD
157 (int)tocentry.starting_track, 165 (int)tocentry.starting_track,