]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/cdunix.cpp
92bf9fd72b314f5dca58a3c9e938eccafbbdae11
1 ////////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
7 // Copyright: (C) 1997, 1998, Guilhem Lavaux
9 // License: wxWindows license
10 ////////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "cdunix.h"
15 #include <sys/types.h>
16 #include <sys/ioctl.h>
22 #include <linux/cdrom.h>
29 #include "wx/wxprec.h"
36 wxCDAudioLinux::wxCDAudioLinux()
37 : wxCDAudio(), m_fd(-1)
39 OpenDevice("/dev/cdrom");
42 wxCDAudioLinux::wxCDAudioLinux(const char *dev_name
)
43 : wxCDAudio(), m_fd(-1)
48 wxCDAudioLinux::~wxCDAudioLinux()
57 void wxCDAudioLinux::OpenDevice(const char *dev_name
)
59 struct cdrom_tocentry entry
, old_entry
;
60 struct cdrom_tochdr diskinf
;
61 struct cdrom_msf0
*msf
= &entry
.cdte_addr
.msf
,
62 *old_msf
= &old_entry
.cdte_addr
.msf
;
66 int hour
, minute
, second
;
71 m_fd
= open(dev_name
, O_RDONLY
);
78 ioctl(m_fd
, CDROMREADTOCHDR
, &diskinf
);
80 nb_tracks
= diskinf
.cdth_trk1
-diskinf
.cdth_trk0
+1;
81 m_trksize
= new wxCDtime
[nb_tracks
+1];
82 m_trkpos
= new wxCDtime
[nb_tracks
+1];
86 for (i
=diskinf
.cdth_trk0
;i
<=diskinf
.cdth_trk1
;i
++) {
88 entry
.cdte_format
= CDROM_MSF
;
89 ioctl(m_fd
, CDROMREADTOCENTRY
, &entry
);
91 minute
= msf
->minute
- old_msf
->minute
;
92 second
= msf
->second
- old_msf
->second
;
101 the_track
= &m_trksize
[i
-diskinf
.cdth_trk0
];
102 the_track
->track
= i
-diskinf
.cdth_trk0
;
103 the_track
->hour
= hour
;
104 the_track
->min
= minute
;
105 the_track
->sec
= second
;
107 the_track
= &m_trkpos
[i
-diskinf
.cdth_trk0
];
108 the_track
->track
= i
-diskinf
.cdth_trk0
;
109 the_track
->hour
= old_msf
->minute
/ 60;
110 the_track
->min
= old_msf
->minute
% 60;
111 the_track
->sec
= old_msf
->second
;
115 entry
.cdte_track
= CDROM_LEADOUT
;
116 entry
.cdte_format
= CDROM_MSF
;
117 ioctl(m_fd
, CDROMREADTOCENTRY
, &entry
);
119 tot_tm
.track
= nb_tracks
;
120 tot_tm
.hour
= msf
->minute
/ 60;
121 tot_tm
.min
= msf
->minute
% 60;
122 tot_tm
.sec
= msf
->second
% 60;
124 m_trksize
[nb_tracks
].track
= nb_tracks
;
125 minute
= msf
->minute
- old_msf
->minute
;
126 second
= msf
->second
- old_msf
->second
;
134 m_trksize
[nb_tracks
].hour
= hour
;
135 m_trksize
[nb_tracks
].min
= minute
;
136 m_trksize
[nb_tracks
].sec
= second
;
137 m_trkpos
[nb_tracks
].track
= nb_tracks
;
138 m_trkpos
[nb_tracks
].hour
= old_msf
->minute
/ 60;
139 m_trkpos
[nb_tracks
].min
= old_msf
->minute
% 60;
140 m_trkpos
[nb_tracks
].sec
= old_msf
->second
;
142 m_toc
= new CDtoc(tot_tm
, m_trksize
, m_trkpos
);
145 bool wxCDAudioLinux::Play(const wxCDtime
& beg_time
, const wxCDtime
& end_time
)
147 struct cdrom_msf track_msf
;
149 track_msf
.cdmsf_min0
= beg_time
.hour
* 60 + beg_time
.min
;
150 track_msf
.cdmsf_sec0
= beg_time
.sec
;
151 track_msf
.cdmsf_frame0
= 0;
152 track_msf
.cdmsf_min1
= end_time
.hour
* 60 + end_time
.min
;
153 track_msf
.cdmsf_sec1
= end_time
.sec
;
154 track_msf
.cdmsf_frame1
= 0;
155 return (ioctl(m_fd
, CDROMPLAYMSF
, &track_msf
) != -1);
158 bool wxCDAudioLinux::Pause()
160 return (ioctl(m_fd
, CDROMPAUSE
, 0) != -1);
163 bool wxCDAudioLinux::Resume()
165 return (ioctl(m_fd
, CDROMRESUME
, 0) != -1);
168 wxCDAudio::CDstatus
wxCDAudioLinux::GetStatus()
170 struct cdrom_subchnl subchnl
;
171 ioctl(m_fd
, CDROMSUBCHNL
, &subchnl
);
172 switch (subchnl
.cdsc_audiostatus
) {
173 case CDROM_AUDIO_PLAY
: return PLAYING
;
174 case CDROM_AUDIO_PAUSED
: return PAUSED
;
175 case CDROM_AUDIO_COMPLETED
: return STOPPED
;
181 wxCDtime
wxCDAudioLinux::GetTime()
184 struct cdrom_subchnl subchnl
;
186 ioctl(m_fd
, CDROMSUBCHNL
, &subchnl
);
187 cdtime
.track
= subchnl
.cdsc_trk
;
188 cdtime
.min
= subchnl
.cdsc_reladdr
.msf
.minute
;
189 cdtime
.hour
= cdtime
.min
/ 60;
191 cdtime
.sec
= subchnl
.cdsc_reladdr
.msf
.second
;
196 wxCDAudio::CDtoc
& wxCDAudioLinux::GetToc()