aboutsummaryrefslogtreecommitdiff
path: root/audio/asunder/files/patch-src_main.c
blob: 30add76d880392ded645a59f6c579882871f8bf6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
--- src/main.c.orig	2007-08-27 04:00:08.000000000 +0200
+++ src/main.c	2007-10-08 13:17:38.000000000 +0200
@@ -22,7 +22,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include <linux/cdrom.h>
+#include <sys/cdio.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
@@ -177,6 +177,9 @@
     int fd;
     bool ret = false;
     int status;
+
+    struct ioc_read_subchannel cdsc;
+    struct cd_sub_channel_info data;
     
     // open the device
     fd = open(cdrom, O_RDONLY | O_NONBLOCK);
@@ -210,8 +213,13 @@
     static bool alreadyKnowGood = false; /* check when program just started */
     static bool alreadyCleared = true; /* no need to clear when program just started */
     
-    status = ioctl(fd, CDROM_DISC_STATUS, CDSL_CURRENT);
-    if (status == CDS_AUDIO || status == CDS_MIXED)
+    bzero(&cdsc,sizeof(cdsc));
+    cdsc.data = &data;
+    cdsc.data_len = sizeof(data);
+    cdsc.data_format = CD_CURRENT_POSITION;
+    cdsc.address_format = CD_MSF_FORMAT;
+    status = ioctl(fd, CDIOCREADSUBCHANNEL, (char *)&cdsc);
+    if (status >= 0)
     {
         if (!alreadyKnowGood)
         {
@@ -308,7 +316,8 @@
     //~ {
         //~ ioctl(fd, CDROMCLOSETRAY, CDSL_CURRENT);
     //~ } else {
-            ioctl(fd, CDROMEJECT, CDSL_CURRENT);
+            ioctl(fd, CDIOCALLOW);
+            ioctl(fd, CDIOCEJECT);
     //~ }
     
     close(fd);
@@ -367,13 +376,16 @@
 {
     int fd;
     int status;
-    struct cdrom_tochdr th;
-    struct cdrom_tocentry te;
+    struct ioc_toc_header th;
+    struct ioc_read_toc_single_entry te;
     int i;
     
     cddb_disc_t * disc = NULL;
     cddb_track_t * track = NULL;
 
+    struct ioc_read_subchannel cdsc;
+    struct cd_sub_channel_info data;
+
     char trackname[9];
 
     // open the device
@@ -385,15 +397,20 @@
     }
 
     // read disc status info
-    status = ioctl(fd, CDROM_DISC_STATUS, CDSL_CURRENT);
-    if ((status == CDS_AUDIO) || (status == CDS_MIXED))
+    bzero(&cdsc,sizeof(cdsc));
+    cdsc.data = &data;
+    cdsc.data_len = sizeof(data);
+    cdsc.data_format = CD_CURRENT_POSITION;
+    cdsc.address_format = CD_MSF_FORMAT;
+    status = ioctl(fd, CDIOCREADSUBCHANNEL, (char *)&cdsc);
+    if (status >= 0)
     {
         // see if we can read the disc's table of contents (TOC).
-        if (ioctl(fd, CDROMREADTOCHDR, &th) == 0)
+        if (ioctl(fd, CDIOREADTOCHEADER, &th) == 0)
         {
 #ifdef DEBUG
-            printf("starting track: %d\n", th.cdth_trk0);
-            printf("ending track: %d\n", th.cdth_trk1);
+            printf("starting track: %d\n", th.starting_track);
+            printf("ending track: %d\n", th.ending_track);
 #endif
             disc = cddb_disc_new();
             if (disc == NULL)
@@ -402,13 +419,13 @@
                 exit(-1);
             }
             
-            te.cdte_format = CDROM_LBA;
-            for (i=th.cdth_trk0; i<=th.cdth_trk1; i++)
+            te.address_format = CD_LBA_FORMAT;
+            for (i=th.starting_track; i<=th.ending_track; i++)
             {
-                te.cdte_track = i;
-                if (ioctl(fd, CDROMREADTOCENTRY, &te) == 0)
+                te.track = i;
+                if (ioctl(fd, CDIOREADTOCENTRY, &te) == 0)
                 {
-                    if (te.cdte_ctrl & CDROM_DATA_TRACK)
+                    if (te.entry.control & 0x04)
                     {
                         // track is a DATA track. make sure its "rip" box is not checked by default
                         track_format[i] = FALSE;
@@ -423,17 +440,17 @@
                         exit(-1);
                     }
                 
-                    cddb_track_set_frame_offset(track, te.cdte_addr.lba+SECONDS_TO_FRAMES(2));
+                    cddb_track_set_frame_offset(track, ntohl(te.entry.addr.lba)+SECONDS_TO_FRAMES(2));
                     snprintf(trackname, 9, "Track %d", i);
                     cddb_track_set_title(track, trackname);
                     cddb_track_set_artist(track, "Unknown Artist");
                     cddb_disc_add_track(disc, track);
                 }
             }
-            te.cdte_track = CDROM_LEADOUT;
-            if (ioctl(fd, CDROMREADTOCENTRY, &te) == 0)
+            te.track = 0xAA;
+            if (ioctl(fd, CDIOREADTOCENTRY, &te) == 0)
             {
-                cddb_disc_set_length(disc, (te.cdte_addr.lba+SECONDS_TO_FRAMES(2))/SECONDS_TO_FRAMES(1));
+                cddb_disc_set_length(disc, (ntohl(te.entry.addr.lba)+SECONDS_TO_FRAMES(2))/SECONDS_TO_FRAMES(1));
             }
         }
     }