comparison src/cdrom/osf/SDL_syscdrom.c @ 873:89666943c598

Date: Sun, 07 Mar 2004 22:54:11 +0900 From: Hayashi Naoyuki Subject: Tru64 cdrom and pthread option fix SDL-1.2.7/src/cdrom/osf/SDL_syscdrom.c Fixes Some CD-ROM drives(ex. TEAC CD-532E) cannot play first 150 frames(aka gap). CheckDrive() fix. The end of comment is "* /" in AddDrive(). SDL-1.2.7/configure.in Fixes Add *-*-osf pthread option and delete line SDL_LIBS="$SDL_LIBS -lrt".
author Sam Lantinga <slouken@libsdl.org>
date Sun, 07 Mar 2004 16:40:15 +0000
parents e92bcf2573cb
children 9719e7f51a3a
comparison
equal deleted inserted replaced
872:e7be95d758e8 873:89666943c598
57 static int SDL_SYS_CDResume(SDL_CD *cdrom); 57 static int SDL_SYS_CDResume(SDL_CD *cdrom);
58 static int SDL_SYS_CDStop(SDL_CD *cdrom); 58 static int SDL_SYS_CDStop(SDL_CD *cdrom);
59 static int SDL_SYS_CDEject(SDL_CD *cdrom); 59 static int SDL_SYS_CDEject(SDL_CD *cdrom);
60 static void SDL_SYS_CDClose(SDL_CD *cdrom); 60 static void SDL_SYS_CDClose(SDL_CD *cdrom);
61 61
62 /* Some ioctl() errno values which occur when the tray is empty */
63 #define ERRNO_TRAYEMPTY(errno) \
64 ((errno == EIO) || (errno == ENOENT) || (errno == EINVAL))
65
66 /* Check a drive to see if it is a CD-ROM */ 62 /* Check a drive to see if it is a CD-ROM */
67 /* Caution!! Not tested. */ 63 /* Caution!! Not tested. */
68 static int CheckDrive(char *drive, struct stat *stbuf) 64 static int CheckDrive(char *drive, struct stat *stbuf)
69 { 65 {
70 int is_cd, cdfd; 66 int cdfd, is_cd = 0;
71 struct cd_sub_channel info; 67 struct mode_sel_sns_params msp;
68 struct inquiry_info inq;
69
70 #ifdef DEBUG_CDROM
71 char *devtype[] = {"Disk", "Tape", "Printer", "Processor", "WORM",
72 "CD-ROM", "Scanner", "Optical", "Changer", "Comm", "Unknown"};
73 #endif
74
75 bzero(&msp, sizeof(msp));
76 bzero(&inq, sizeof(inq));
72 77
73 /* If it doesn't exist, return -1 */ 78 /* If it doesn't exist, return -1 */
74 if ( stat(drive, stbuf) < 0 ) { 79 if ( stat(drive, stbuf) < 0 ) {
75 return(-1); 80 return(-1);
76 } 81 }
77 82
78 /* If it does exist, verify that it's an available CD-ROM */ 83 if ( (cdfd = open(drive, (O_RDWR|O_NDELAY), 0)) >= 0 ) {
79 is_cd = 0; 84 msp.msp_addr = (caddr_t) &inq;
80 if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) { 85 msp.msp_pgcode = 0;
81 cdfd = open(drive, (O_RDWR|O_NDELAY), 0); 86 msp.msp_pgctrl = 0;
82 if ( cdfd >= 0 ) { 87 msp.msp_length = sizeof(inq);
83 info.sch_address_format = CDROM_MSF_FORMAT; 88 msp.msp_setps = 0;
84 info.sch_data_format = CDROM_CURRENT_POSITION; 89
85 info.sch_alloc_length = 0; 90 if ( ioctl(cdfd, SCSI_GET_INQUIRY_DATA, &msp) )
86 info.sch_track_number = 0; 91 return (0);
87 info.sch_buffer = NULL; 92
88 /* 93 #ifdef DEBUG_CDROM
89 * 94 fprintf(stderr, "Device Type: %s\n", devtype[inq.perfdt]);
90 * Under Linux, EIO occurs when a disk is not present. 95 fprintf(stderr, "Vendor: %.8s\n", inq.vndrid);
91 * This isn't 100% reliable, so we use the USE_MNTENT 96 fprintf(stderr, "Product: %.8s\n", inq.prodid);
92 * code above instead. 97 fprintf(stderr, "Revision: %.8s\n", inq.revlvl);
93 * 98 #endif
94 */ 99 if ( inq.perfdt == DTYPE_RODIRECT )
95 if ( (ioctl(cdfd, CDROM_READ_SUBCHANNEL, &info) == 0) || 100 is_cd = 1;
96 ERRNO_TRAYEMPTY(errno) ) {
97 is_cd = 1;
98 }
99
100 close(cdfd);
101 }
102 } 101 }
103 102
104 return(is_cd); 103 return(is_cd);
105 } 104 }
106 105
111 110
112 if ( SDL_numcds < MAX_DRIVES ) { 111 if ( SDL_numcds < MAX_DRIVES ) {
113 /* Check to make sure it's not already in our list. 112 /* Check to make sure it's not already in our list.
114 * This can happen when we see a drive via symbolic link. 113 * This can happen when we see a drive via symbolic link.
115 * 114 *
116 * / 115 */
117 for ( i=0; i<SDL_numcds; ++i ) { 116 for ( i=0; i<SDL_numcds; ++i ) {
118 if ( stbuf->st_rdev == SDL_cdmode[i] ) { 117 if ( stbuf->st_rdev == SDL_cdmode[i] ) {
119 #ifdef DEBUG_CDROM 118 #ifdef DEBUG_CDROM
120 fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]); 119 fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]);
121 #endif 120 #endif
140 } 139 }
141 } 140 }
142 141
143 int SDL_SYS_CDInit(void) 142 int SDL_SYS_CDInit(void)
144 { 143 {
145 /* checklist: /dev/cdrom,/dev/cd?c /dev/acd?c 144 /* checklist: /dev/rdisk/cdrom?c
146 * /dev/matcd?c /dev/mcd?c /dev/scd?c
147 * 145 *
148 */ 146 */
149 static char *checklist[] = { 147 static char *checklist[] = {
150 "?0 rdisk/cdrom?",NULL}; 148 "?0 rdisk/cdrom?",NULL};
151 char drive[32]; 149 char drive[32];
285 if (ioctl(cdrom->id, CDROM_TOC_ENTRYS, &toc)) { 283 if (ioctl(cdrom->id, CDROM_TOC_ENTRYS, &toc)) {
286 fprintf(stderr,"ioctl error CDROM_TOC_ENTRYS\n"); 284 fprintf(stderr,"ioctl error CDROM_TOC_ENTRYS\n");
287 return -1; 285 return -1;
288 } 286 }
289 287
290 (char *)cdte = toc.toc_buffer + sizeof(hdr); 288 cdte =(struct cd_toc_entry *) ((char *) toc.toc_buffer + sizeof(hdr));
291 for (i=0; i <= cdrom->numtracks; ++i) { 289 for (i=0; i <= cdrom->numtracks; ++i) {
292 if (i == cdrom->numtracks ) { 290 if (i == cdrom->numtracks ) {
293 cdrom->track[i].id = 0xAA;; 291 cdrom->track[i].id = 0xAA;;
294 } else { 292 } else {
295 cdrom->track[i].id = hdr.th_starting_track + i; 293 cdrom->track[i].id = hdr.th_starting_track + i;
296 } 294 }
297 295
298 cdrom->track[i].type = 296 cdrom->track[i].type =
299 cdte[i].te_control & CDROM_DATA_TRACK; 297 cdte[i].te_control & CDROM_DATA_TRACK;
300 cdrom->track[i].offset = 298 cdrom->track[i].offset =
301 cdte[i].te_absaddr.lba.addr3 << 24 | 299 cdte[i].te_absaddr.lba.addr3 << 24 |
302 cdte[i].te_absaddr.lba.addr2 << 16 | 300 cdte[i].te_absaddr.lba.addr2 << 16 |
303 cdte[i].te_absaddr.lba.addr1 << 8 | 301 cdte[i].te_absaddr.lba.addr1 << 8 |
304 cdte[i].te_absaddr.lba.addr0; 302 cdte[i].te_absaddr.lba.addr0;
305 cdrom->track[i].length = 0; 303 cdrom->track[i].length = 0;
306 if ( i > 0 ) { 304 if ( i > 0 ) {
307 cdrom->track[i - 1].length = 305 cdrom->track[i - 1].length =
308 cdrom->track[i].offset - 306 cdrom->track[i].offset -
309 cdrom->track[i - 1].offset; 307 cdrom->track[i - 1].offset;
310 } 308 }
311 } 309 }
312 #ifdef DEBUG_CDROM 310 #ifdef DEBUG_CDROM
313 for (i = 0; i <= cdrom->numtracks; i++) { 311 for (i = 0; i <= cdrom->numtracks; i++) {
314 fprintf(stderr,"toc_entry[%d].te_track_number = %d\n", 312 fprintf(stderr,"toc_entry[%d].te_track_number = %d\n",
315 i,cdte[i].te_track_number); 313 i,cdte[i].te_track_number);
316 fprintf(stderr,"cdrom->track[%d].id = %d\n", i,cdrom->track[i].id); 314 fprintf(stderr,"cdrom->track[%d].id = %d\n", i,cdrom->track[i].id);
386 } 384 }
387 385
388 /* Start play */ 386 /* Start play */
389 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) 387 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
390 { 388 {
391 /* Play MSF 389 /*
392 * 390 * Play MSF
393 */ 391 */
394 struct cd_play_audio_msf msf; 392 struct cd_play_audio_msf msf;
395 int end; 393 int end;
396 394
397 bzero(&msf, sizeof(msf)); 395 bzero(&msf, sizeof(msf));
396 start += 150; /* Some CD-ROM drives cannot play the first 150 frames. */
398 end = start +length; 397 end = start +length;
399 FRAMES_TO_MSF(start, 398 FRAMES_TO_MSF(start,
400 &msf.msf_starting_M_unit, 399 &msf.msf_starting_M_unit,
401 &msf.msf_starting_S_unit, 400 &msf.msf_starting_S_unit,
402 &msf.msf_starting_F_unit); 401 &msf.msf_starting_F_unit);
448 } 447 }
449 SDL_numcds = 0; 448 SDL_numcds = 0;
450 } 449 }
451 } 450 }
452 451
453