]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/cdunix.cpp
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 IMPLEMENT_DYNAMIC_CLASS(wxCDAudioLinux
, wxCDAudio
)
38 wxCDAudioLinux::wxCDAudioLinux()
39 : wxCDAudio(), m_fd(-1)
41 OpenDevice("/dev/cdrom");
44 wxCDAudioLinux::wxCDAudioLinux(const char *dev_name
)
45 : wxCDAudio(), m_fd(-1)
50 wxCDAudioLinux::~wxCDAudioLinux()
59 void wxCDAudioLinux::OpenDevice(const char *dev_name
)
61 struct cdrom_tocentry entry
, old_entry
;
62 struct cdrom_tochdr diskinf
;
63 struct cdrom_msf0
*msf
= &entry
.cdte_addr
.msf
,
64 *old_msf
= &old_entry
.cdte_addr
.msf
;
68 int hour
, minute
, second
;
73 m_fd
= open(dev_name
, O_RDONLY
);
80 ioctl(m_fd
, CDROMREADTOCHDR
, &diskinf
);
82 nb_tracks
= diskinf
.cdth_trk1
-diskinf
.cdth_trk0
+1;
83 m_trksize
= new wxCDtime
[nb_tracks
+1];
84 m_trkpos
= new wxCDtime
[nb_tracks
+1];
88 for (i
=diskinf
.cdth_trk0
;i
<=diskinf
.cdth_trk1
;i
++) {
90 entry
.cdte_format
= CDROM_MSF
;
91 ioctl(m_fd
, CDROMREADTOCENTRY
, &entry
);
93 minute
= msf
->minute
- old_msf
->minute
;
94 second
= msf
->second
- old_msf
->second
;
103 the_track
= &m_trksize
[i
-diskinf
.cdth_trk0
];
104 the_track
->track
= i
-diskinf
.cdth_trk0
;
105 the_track
->hour
= hour
;
106 the_track
->min
= minute
;
107 the_track
->sec
= second
;
109 the_track
= &m_trkpos
[i
-diskinf
.cdth_trk0
];
110 the_track
->track
= i
-diskinf
.cdth_trk0
;
111 the_track
->hour
= old_msf
->minute
/ 60;
112 the_track
->min
= old_msf
->minute
% 60;
113 the_track
->sec
= old_msf
->second
;
117 entry
.cdte_track
= CDROM_LEADOUT
;
118 entry
.cdte_format
= CDROM_MSF
;
119 ioctl(m_fd
, CDROMREADTOCENTRY
, &entry
);
121 tot_tm
.track
= nb_tracks
;
122 tot_tm
.hour
= msf
->minute
/ 60;
123 tot_tm
.min
= msf
->minute
% 60;
124 tot_tm
.sec
= msf
->second
% 60;
126 m_trksize
[nb_tracks
].track
= nb_tracks
;
127 minute
= msf
->minute
- old_msf
->minute
;
128 second
= msf
->second
- old_msf
->second
;
136 m_trksize
[nb_tracks
].hour
= hour
;
137 m_trksize
[nb_tracks
].min
= minute
;
138 m_trksize
[nb_tracks
].sec
= second
;
139 m_trkpos
[nb_tracks
].track
= nb_tracks
;
140 m_trkpos
[nb_tracks
].hour
= old_msf
->minute
/ 60;
141 m_trkpos
[nb_tracks
].min
= old_msf
->minute
% 60;
142 m_trkpos
[nb_tracks
].sec
= old_msf
->second
;
144 m_toc
= new CDtoc(tot_tm
, m_trksize
, m_trkpos
);
147 bool wxCDAudioLinux::Play(const wxCDtime
& beg_time
, const wxCDtime
& end_time
)
149 struct cdrom_msf track_msf
;
151 track_msf
.cdmsf_min0
= beg_time
.hour
* 60 + beg_time
.min
;
152 track_msf
.cdmsf_sec0
= beg_time
.sec
;
153 track_msf
.cdmsf_frame0
= 0;
154 track_msf
.cdmsf_min1
= end_time
.hour
* 60 + end_time
.min
;
155 track_msf
.cdmsf_sec1
= end_time
.sec
;
156 track_msf
.cdmsf_frame1
= 0;
157 return (ioctl(m_fd
, CDROMPLAYMSF
, &track_msf
) != -1);
160 bool wxCDAudioLinux::Pause()
162 return (ioctl(m_fd
, CDROMPAUSE
, 0) != -1);
165 bool wxCDAudioLinux::Resume()
167 return (ioctl(m_fd
, CDROMRESUME
, 0) != -1);
170 wxCDAudio::CDstatus
wxCDAudioLinux::GetStatus()
172 struct cdrom_subchnl subchnl
;
173 ioctl(m_fd
, CDROMSUBCHNL
, &subchnl
);
174 switch (subchnl
.cdsc_audiostatus
) {
175 case CDROM_AUDIO_PLAY
: return PLAYING
;
176 case CDROM_AUDIO_PAUSED
: return PAUSED
;
177 case CDROM_AUDIO_COMPLETED
: return STOPPED
;
183 wxCDtime
wxCDAudioLinux::GetTime()
186 struct cdrom_subchnl subchnl
;
188 ioctl(m_fd
, CDROMSUBCHNL
, &subchnl
);
189 cdtime
.track
= subchnl
.cdsc_trk
;
190 cdtime
.min
= subchnl
.cdsc_reladdr
.msf
.minute
;
191 cdtime
.hour
= cdtime
.min
/ 60;
193 cdtime
.sec
= subchnl
.cdsc_reladdr
.msf
.second
;
198 wxCDAudio::CDtoc
& wxCDAudioLinux::GetToc()