2002-07-28 22:45:45 +00:00
|
|
|
/* gstcdplay
|
|
|
|
* Copyright (c) 2002 Charles Schmidt <cbschmid@uiuc.edu>
|
|
|
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2004-03-15 16:32:54 +00:00
|
|
|
#ifdef HAVE_CDROM_BSD_NETBSD /* net & open */
|
2004-02-27 23:36:43 +00:00
|
|
|
#ifndef CDIOREADTOCHDR
|
|
|
|
#define CDIOREADTOCHDR CDIOREADTOCHEADER
|
|
|
|
#endif
|
2004-03-15 16:32:54 +00:00
|
|
|
gboolean cd_init(struct cd *cd,const gchar *device)
|
2002-07-28 22:45:45 +00:00
|
|
|
{
|
2005-12-06 19:55:58 +00:00
|
|
|
struct ioc_toc_header toc_header;
|
|
|
|
struct ioc_read_toc_entry toc_entry;
|
|
|
|
struct cd_toc_entry toc_entry_data;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
cd->fd = open(device,O_RDONLY | O_NONBLOCK);
|
|
|
|
|
|
|
|
if (cd->fd == -1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the toc header information */
|
|
|
|
if (ioctl(cd->fd,CDIOREADTOCHDR,&toc_header) != 0) {
|
|
|
|
close(cd->fd);
|
|
|
|
cd->fd = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read each entry in the toc header */
|
|
|
|
for (i = 1; i <= toc_header.ending_track; i++) {
|
|
|
|
toc_entry.address_format = CD_MSF_FORMAT;
|
|
|
|
toc_entry.starting_track = i;
|
|
|
|
toc_entry.data = &toc_entry_data;
|
|
|
|
toc_entry.data_len = sizeof(toc_entry_data);
|
|
|
|
|
|
|
|
if (ioctl(cd->fd,CDIOREADTOCENTRYS,&toc_entry) != 0) {
|
|
|
|
close(cd->fd);
|
|
|
|
cd->fd = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cd->tracks[i].minute = toc_entry.data->addr.msf.minute;
|
|
|
|
cd->tracks[i].second = toc_entry.data->addr.msf.second;
|
|
|
|
cd->tracks[i].frame = toc_entry.data->addr.msf.frame;
|
|
|
|
cd->tracks[i].data_track = (toc_entry.data->control & 4) == 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the leadout */
|
|
|
|
toc_entry.address_format = CD_MSF_FORMAT;
|
|
|
|
toc_entry.starting_track = 0xAA; /* leadout */
|
|
|
|
toc_entry.data = &toc_entry_data;
|
|
|
|
toc_entry.data_len = sizeof(toc_entry_data);
|
|
|
|
|
|
|
|
if (ioctl(cd->fd,CDIOREADTOCENTRYS,&toc_entry) != 0) {
|
|
|
|
close(cd->fd);
|
|
|
|
cd->fd = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cd->tracks[LEADOUT].minute = toc_entry.data->addr.msf.minute;
|
|
|
|
cd->tracks[LEADOUT].second = toc_entry.data->addr.msf.second;
|
|
|
|
cd->tracks[LEADOUT].frame = toc_entry.data->addr.msf.frame;
|
|
|
|
|
|
|
|
cd->num_tracks = toc_header.ending_track;
|
|
|
|
|
|
|
|
return TRUE;
|
2002-07-28 22:45:45 +00:00
|
|
|
}
|
|
|
|
#elif defined HAVE_CDROM_BSD_DARWIN
|
2004-03-15 16:32:54 +00:00
|
|
|
gboolean cd_init(struct cd *cd,const gchar *device)
|
2002-07-28 22:45:45 +00:00
|
|
|
{
|
2005-12-06 19:55:58 +00:00
|
|
|
struct ioc_toc_header toc_header;
|
|
|
|
struct ioc_read_toc_entry toc_entry;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
cd->fd = open(device,O_RDONLY | O_NONBLOCK);
|
|
|
|
|
|
|
|
if (cd->fd == -1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the toc header information */
|
|
|
|
if (ioctl(cd->fd,CDIOREADTOCHDR,&toc_header) != 0) {
|
|
|
|
close(cd->fd);
|
|
|
|
cd->fd = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read each entry in the toc header */
|
|
|
|
for (i = 1; i <= toc_header.ending_track; i++) {
|
|
|
|
toc_entry.address_format = CD_MSF_FORMAT;
|
|
|
|
toc_entry.starting_track = i;
|
|
|
|
|
|
|
|
if (ioctl(cd->fd,CDIOREADTOCENTRYS,&toc_entry) != 0) {
|
|
|
|
close(cd->fd);
|
|
|
|
cd->fd = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cd->tracks[i].minute = toc_entry.data->addr[1];
|
|
|
|
cd->tracks[i].second = toc_entry.data->addr[2];
|
|
|
|
cd->tracks[i].frame = toc_entry.data->addr[3];
|
|
|
|
cd->tracks[i].data_track = (toc_entry.data->control & 4) == 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the leadout */
|
|
|
|
toc_entry.address_format = CD_MSF_FORMAT;
|
|
|
|
toc_entry.starting_track = 0xAA; /* leadout */
|
|
|
|
toc_entry.data = &toc_entry_data;
|
|
|
|
toc_entry.data_len = sizeof(toc_entry_data);
|
|
|
|
|
|
|
|
if (ioctl(cd->fd,CDIOREADTOCENTRYS,&toc_entry) != 0) {
|
|
|
|
close(cd->fd);
|
|
|
|
cd->fd = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cd->tracks[LEADOUT].minute = toc_entry.data->addr[1];
|
|
|
|
cd->tracks[LEADOUT].second = toc_entry.data->addr[2];
|
|
|
|
cd->tracks[LEADOUT].frame = toc_entry.data->addr[3];
|
|
|
|
|
|
|
|
cd->num_tracks = toc_header.ending_track;
|
|
|
|
|
|
|
|
return TRUE;
|
2002-07-28 22:45:45 +00:00
|
|
|
}
|
|
|
|
#else /* free */
|
2004-03-15 16:32:54 +00:00
|
|
|
gboolean cd_init(struct cd *cd,const gchar *device)
|
2002-07-28 22:45:45 +00:00
|
|
|
{
|
2005-12-06 19:55:58 +00:00
|
|
|
struct ioc_toc_header toc_header;
|
|
|
|
struct ioc_read_toc_entry toc_entry;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
cd->fd = open(device,O_RDONLY | O_NONBLOCK);
|
|
|
|
|
|
|
|
if (cd->fd == -1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the toc header information */
|
|
|
|
if (ioctl(cd->fd,CDIOREADTOCHDR,&toc_header) != 0) {
|
|
|
|
close(cd->fd);
|
|
|
|
cd->fd = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read each entry in the toc header */
|
|
|
|
for (i = 1; i <= toc_header.ending_track; i++) {
|
|
|
|
toc_entry.address_format = CD_MSF_FORMAT;
|
|
|
|
toc_entry.starting_track = i;
|
|
|
|
|
|
|
|
if (ioctl(cd->fd,CDIOREADTOCENTRYS,&toc_entry) != 0) {
|
|
|
|
close(cd->fd);
|
|
|
|
cd->fd = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cd->tracks[i].minute = toc_entry.entry.addr.msf.minute;
|
|
|
|
cd->tracks[i].second = toc_entry.entry.addr.msf.second;
|
|
|
|
cd->tracks[i].frame = toc_entry.entry.addr.msf.frame;
|
|
|
|
cd->tracks[i].data_track = (toc_entry.data->control & 4) == 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the leadout */
|
|
|
|
toc_entry.address_format = CD_MSF_FORMAT;
|
|
|
|
toc_entry.starting_track = 0xAA; /* leadout */
|
|
|
|
toc_entry.data = &toc_entry_data;
|
|
|
|
toc_entry.data_len = sizeof(toc_entry_data);
|
|
|
|
|
|
|
|
if (ioctl(cd->fd,CDIOREADTOCENTRYS,&toc_entry) != 0) {
|
|
|
|
close(cd->fd);
|
|
|
|
cd->fd = -1;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cd->tracks[LEADOUT].minute = toc_entry.entry.addr.msf.minute;
|
|
|
|
cd->tracks[LEADOUT].second = toc_entry.entry.addr.msf.second;
|
|
|
|
cd->tracks[LEADOUT].frame = toc_entry.entry.addr.msf.frame;
|
|
|
|
|
|
|
|
cd->num_tracks = toc_header.ending_track;
|
|
|
|
|
|
|
|
return TRUE;
|
2002-07-28 22:45:45 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-03-15 16:32:54 +00:00
|
|
|
gboolean cd_start(struct cd *cd,gint start_track,gint end_track)
|
2002-07-28 22:45:45 +00:00
|
|
|
{
|
2005-12-06 19:55:58 +00:00
|
|
|
struct ioc_play_msf msf;
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
if (cd->fd == -1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
cd_fix_track_range(cd,&start_track,&end_track);
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
msf.start_m = cd->tracks[start_track].minute;
|
|
|
|
msf.start_s = cd->tracks[start_track].second;
|
|
|
|
msf.start_f = cd->tracks[start_track].frame;
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
if (end_track == LEADOUT) {
|
|
|
|
msf.end_m = cd->tracks[end_track].minute;
|
|
|
|
msf.end_s = cd->tracks[end_track].second;
|
|
|
|
msf.end_f = cd->tracks[end_track].frame;
|
|
|
|
} else {
|
|
|
|
msf.end_m = cd->tracks[end_track+1].minute;
|
|
|
|
msf.end_s = cd->tracks[end_track+1].second;
|
|
|
|
msf.end_f = cd->tracks[end_track+1].frame;
|
|
|
|
}
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
if (ioctl(cd->fd,CDIOCPLAYMSF,&msf) != 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-28 22:45:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-03-15 16:32:54 +00:00
|
|
|
gboolean cd_pause(struct cd *cd)
|
2002-07-28 22:45:45 +00:00
|
|
|
{
|
2005-12-06 19:55:58 +00:00
|
|
|
if (cd->fd == -1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
if (ioctl(cd->fd,CDIOCPAUSE,NULL) != 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
return TRUE;
|
2002-07-28 22:45:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-15 16:32:54 +00:00
|
|
|
gboolean cd_resume(struct cd *cd)
|
2002-07-28 22:45:45 +00:00
|
|
|
{
|
2005-12-06 19:55:58 +00:00
|
|
|
if (cd->fd == -1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
if (ioctl(cd->fd,CDIOCRESUME,NULL) != 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
return TRUE;
|
2002-07-28 22:45:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-15 16:32:54 +00:00
|
|
|
gboolean cd_stop(struct cd *cd)
|
2002-07-28 22:45:45 +00:00
|
|
|
{
|
2005-12-06 19:55:58 +00:00
|
|
|
if (cd->fd == -1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
if (ioctl(cd->fd,CDIOCSTOP,NULL) != 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
return TRUE;
|
2002-07-28 22:45:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -1 for error, 0 for not playing, 1 for playing */
|
2004-03-15 16:32:54 +00:00
|
|
|
CDStatus cd_status(struct cd *cd)
|
2002-07-28 22:45:45 +00:00
|
|
|
{
|
2005-12-06 19:55:58 +00:00
|
|
|
struct ioc_read_subchannel sub_channel;
|
|
|
|
struct cd_sub_channel_info sub_channel_info;
|
|
|
|
|
|
|
|
if (cd->fd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub_channel.address_format = CD_MSF_FORMAT;
|
|
|
|
sub_channel.data_format = CD_CURRENT_POSITION;
|
|
|
|
sub_channel.track = 0;
|
|
|
|
sub_channel.data = &sub_channel_info;
|
|
|
|
sub_channel.data_len = sizeof(sub_channel_info);
|
|
|
|
|
|
|
|
if (ioctl(cd->fd,CDIOCREADSUBCHANNEL,&sub_channel) != 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (sub_channel.data->header.audio_status) {
|
|
|
|
case CD_AS_PLAY_IN_PROGRESS:
|
|
|
|
case CD_AS_PLAY_PAUSED:
|
|
|
|
return CD_PLAYING;
|
|
|
|
break;
|
|
|
|
case CD_AS_PLAY_COMPLETED:
|
|
|
|
return CD_COMPLETED;
|
|
|
|
break;
|
|
|
|
case CD_AS_AUDIO_INVALID:
|
|
|
|
case CD_AS_PLAY_ERROR:
|
|
|
|
default:
|
|
|
|
return CD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2002-07-28 22:45:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-15 16:32:54 +00:00
|
|
|
gint cd_current_track(struct cd *cd)
|
2002-07-28 22:45:45 +00:00
|
|
|
{
|
2005-12-06 19:55:58 +00:00
|
|
|
struct ioc_read_subchannel sub_channel;
|
|
|
|
struct cd_sub_channel_info sub_channel_info;
|
2004-03-15 16:32:54 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
if (cd->fd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2004-03-15 16:32:54 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
sub_channel.address_format = CD_MSF_FORMAT;
|
|
|
|
sub_channel.data_format = CD_TRACK_INFO;
|
|
|
|
sub_channel.track = 0;
|
|
|
|
sub_channel.data = &sub_channel_info;
|
|
|
|
sub_channel.data_len = sizeof(sub_channel_info);
|
2004-03-15 16:32:54 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
if (ioctl(cd->fd,CDIOCREADSUBCHANNEL,&sub_channel) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2004-03-15 16:32:54 +00:00
|
|
|
|
2004-02-27 23:36:43 +00:00
|
|
|
#ifdef __NetBSD__
|
2005-12-06 19:55:58 +00:00
|
|
|
return sub_channel.data->what.track_info.track_number;
|
2004-02-27 23:36:43 +00:00
|
|
|
#else
|
2005-12-06 19:55:58 +00:00
|
|
|
return sub_channel.data->track_number;
|
2004-02-27 23:36:43 +00:00
|
|
|
#endif
|
2002-07-28 22:45:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-15 16:32:54 +00:00
|
|
|
gboolean cd_close(struct cd *cd)
|
2002-07-28 22:45:45 +00:00
|
|
|
{
|
2005-12-06 19:55:58 +00:00
|
|
|
if (cd->fd == -1) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
if (close(cd->fd) != 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
cd->fd = -1;
|
2002-07-28 22:45:45 +00:00
|
|
|
|
2005-12-06 19:55:58 +00:00
|
|
|
return TRUE;
|
2002-07-28 22:45:45 +00:00
|
|
|
}
|
2004-03-15 16:32:54 +00:00
|
|
|
|