win32.c: get eject working.

device.c: an additional test for a NULL pointer to be on the safe side.
cdda-player: better handling of eject.
This commit is contained in:
rocky
2005-03-09 02:19:54 +00:00
parent 683e3d8eaf
commit 76d8cbe880
3 changed files with 101 additions and 72 deletions

View File

@@ -1,5 +1,5 @@
/* /*
$Id: win32.c,v 1.27 2005/03/08 03:19:29 rocky Exp $ $Id: win32.c,v 1.28 2005/03/09 02:19:54 rocky Exp $
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com> Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -26,7 +26,7 @@
# include "config.h" # include "config.h"
#endif #endif
static const char _rcsid[] = "$Id: win32.c,v 1.27 2005/03/08 03:19:29 rocky Exp $"; static const char _rcsid[] = "$Id: win32.c,v 1.28 2005/03/09 02:19:54 rocky Exp $";
#include <cdio/cdio.h> #include <cdio/cdio.h>
#include <cdio/sector.h> #include <cdio/sector.h>
@@ -543,27 +543,22 @@ read_toc_win32 (void *p_user_data)
} }
/*! /*!
Eject media. Return 1 if successful, 0 otherwise. Close media tray.
*/ */
static int static driver_return_code_t
eject_media_win32 (void *p_user_data) { open_close_media_win32 (const char *psz_win32_drive, DWORD command_flags)
{
#ifdef _XBOX #ifdef _XBOX
return DRIVER_OP_UNSUPPORTED; return DRIVER_OP_UNSUPPORTED;
#else #else
_img_private_t *p_env = p_user_data;
MCI_OPEN_PARMS op; MCI_OPEN_PARMS op;
MCI_STATUS_PARMS st; MCI_STATUS_PARMS st;
DWORD i_flags; DWORD i_flags;
char psz_drive[4];
int ret; int ret;
memset( &op, 0, sizeof(MCI_OPEN_PARMS) ); memset( &op, 0, sizeof(MCI_OPEN_PARMS) );
op.lpstrDeviceType = (LPCSTR)MCI_DEVTYPE_CD_AUDIO; op.lpstrDeviceType = (LPCSTR)MCI_DEVTYPE_CD_AUDIO;
strcpy( psz_drive, "X:" ); op.lpstrElementName = psz_win32_drive;
psz_drive[0] = p_env->gen.source_name[0];
op.lpstrElementName = psz_drive;
/* Set the flags for the device type */ /* Set the flags for the device type */
i_flags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | i_flags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID |
@@ -572,16 +567,40 @@ eject_media_win32 (void *p_user_data) {
if( _cdio_mciSendCommand( 0, MCI_OPEN, i_flags, &op ) ) { if( _cdio_mciSendCommand( 0, MCI_OPEN, i_flags, &op ) ) {
st.dwItem = MCI_STATUS_READY; st.dwItem = MCI_STATUS_READY;
/* Eject disc */ /* Eject disc */
ret = _cdio_mciSendCommand( op.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0 ) != 0; ret = _cdio_mciSendCommand( op.wDeviceID, MCI_SET, command_flags, 0 ) == 0;
/* Release access to the device */ /* Release access to the device */
_cdio_mciSendCommand( op.wDeviceID, MCI_CLOSE, MCI_WAIT, 0 ); _cdio_mciSendCommand( op.wDeviceID, MCI_CLOSE, MCI_WAIT, 0 );
} else } else
ret = 0; ret = DRIVER_OP_ERROR;
return ret; return ret;
#endif #endif
} }
/*!
Eject media.
*/
static driver_return_code_t
eject_media_win32 (void *p_user_data)
{
const _img_private_t *p_env = p_user_data;
char psz_drive[4];
unsigned int i_device = strlen(p_env->gen.source_name);
strcpy( psz_drive, "X:" );
if (6 == i_device) {
psz_drive[0] = p_env->gen.source_name[4];
} else if (2 == i_device) {
psz_drive[0] = p_env->gen.source_name[0];
} else {
cdio_info ("Can't pick out drive letter from device %s",
p_env->gen.source_name);
return DRIVER_OP_ERROR;
}
return open_close_media_win32(psz_drive, MCI_SET_DOOR_OPEN);
}
/*! /*!
Return the value associated with the key "arg". Return the value associated with the key "arg".
*/ */
@@ -801,8 +820,11 @@ cdio_is_device_win32(const char *source_name)
} }
driver_return_code_t driver_return_code_t
close_tray_win32 ( const char *psz_win32_drive) close_tray_win32 (const char *psz_win32_drive)
{ {
#if 0
return open_close_media_win32(psz_win32_drive, MCI_SET_DOOR_CLOSED);
#else
#ifdef HAVE_WIN32_CDROM #ifdef HAVE_WIN32_CDROM
if ( WIN_NT ) { if ( WIN_NT ) {
return close_tray_win32ioctl (psz_win32_drive); return close_tray_win32ioctl (psz_win32_drive);
@@ -813,13 +835,14 @@ close_tray_win32 ( const char *psz_win32_drive)
return DRIVER_OP_UNSUPPORTED; return DRIVER_OP_UNSUPPORTED;
#endif #endif
} }
#endif
/*! /*!
Initialization routine. This is the only thing that doesn't Initialization routine. This is the only thing that doesn't
get called via a function pointer. In fact *we* are the get called via a function pointer. In fact *we* are the
ones to set that up. ones to set that up.
*/ */
CdIo * CdIo_t *
cdio_open_win32 (const char *psz_source_name) cdio_open_win32 (const char *psz_source_name)
{ {
#ifdef HAVE_WIN32_CDROM #ifdef HAVE_WIN32_CDROM
@@ -838,12 +861,12 @@ cdio_open_win32 (const char *psz_source_name)
get called via a function pointer. In fact *we* are the get called via a function pointer. In fact *we* are the
ones to set that up. ones to set that up.
*/ */
CdIo * CdIo_t *
cdio_open_am_win32 (const char *psz_orig_source, const char *psz_access_mode) cdio_open_am_win32 (const char *psz_orig_source, const char *psz_access_mode)
{ {
#ifdef HAVE_WIN32_CDROM #ifdef HAVE_WIN32_CDROM
CdIo *ret; CdIo_t *ret;
_img_private_t *_data; _img_private_t *_data;
char *psz_source; char *psz_source;

View File

@@ -1,5 +1,5 @@
/* /*
$Id: device.c,v 1.17 2005/03/08 04:10:36 rocky Exp $ $Id: device.c,v 1.18 2005/03/09 02:19:54 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com> Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -292,7 +292,7 @@ cdio_destroy (CdIo_t *p_cdio)
CdIo_last_driver = CDIO_DRIVER_UNINIT; CdIo_last_driver = CDIO_DRIVER_UNINIT;
if (p_cdio == NULL) return; if (p_cdio == NULL) return;
if (p_cdio->op.free != NULL) if (p_cdio->op.free != NULL && p_cdio->env)
p_cdio->op.free (p_cdio->env); p_cdio->op.free (p_cdio->env);
p_cdio->env = NULL; p_cdio->env = NULL;
free (p_cdio); free (p_cdio);

View File

@@ -1,5 +1,5 @@
/* /*
$Id: cdda-player.c,v 1.2 2005/03/08 03:11:19 rocky Exp $ $Id: cdda-player.c,v 1.3 2005/03/09 02:19:54 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com> Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -284,7 +284,7 @@ oops(const char *txt, int rc)
static void static void
cd_stop(CdIo_t *p_cdio) cd_stop(CdIo_t *p_cdio)
{ {
if (b_cd) { if (b_cd && p_cdio) {
action("stop..."); action("stop...");
if (DRIVER_OP_SUCCESS != cdio_audio_stop(p_cdio)) if (DRIVER_OP_SUCCESS != cdio_audio_stop(p_cdio))
xperror("stop"); xperror("stop");
@@ -292,13 +292,16 @@ cd_stop(CdIo_t *p_cdio)
} }
static void static void
cd_eject(CdIo_t *p_cdio) cd_eject(void)
{ {
cd_stop(p_cdio); if (p_cdio) {
action("eject..."); cd_stop(p_cdio);
if (DRIVER_OP_SUCCESS != cdio_eject_media(&p_cdio)) action("eject...");
xperror("eject"); if (DRIVER_OP_SUCCESS != cdio_eject_media(&p_cdio))
b_cd = 0; xperror("eject");
b_cd = 0;
p_cdio = NULL;
}
} }
static void static void
@@ -330,7 +333,7 @@ read_subchannel(CdIo_t *p_cdio)
b_cd = 0; b_cd = 0;
} }
if (auto_mode && sub.audio_status == CDIO_MMC_READ_SUB_ST_COMPLETED) if (auto_mode && sub.audio_status == CDIO_MMC_READ_SUB_ST_COMPLETED)
cd_eject(p_cdio); cd_eject();
} }
static void static void
@@ -1137,10 +1140,6 @@ main(int argc, char *argv[])
cdio_free_device_list(ppsz_cdda_drives); cdio_free_device_list(ppsz_cdda_drives);
} }
/* open device */
if (b_verbose)
fprintf(stderr,"open %s... ", psz_device);
if (!interactive) { if (!interactive) {
b_sig = true; b_sig = true;
nostop=1; nostop=1;
@@ -1149,6 +1148,10 @@ main(int argc, char *argv[])
} }
} }
/* open device */
if (b_verbose)
fprintf(stderr,"open %s... ", psz_device);
p_cdio = cdio_open (psz_device, driver_id); p_cdio = cdio_open (psz_device, driver_id);
if (!p_cdio) { if (!p_cdio) {
@@ -1170,49 +1173,52 @@ main(int argc, char *argv[])
if (!interactive) { if (!interactive) {
b_sig = true; b_sig = true;
nostop=1; nostop=1;
read_toc(p_cdio); if (EJECT_CD == todo) {
if (!b_cd && todo != EJECT_CD) { cd_eject();
cd_close(psz_device);
read_toc(p_cdio);
}
if (b_cd || todo == EJECT_CD) {
switch (todo) {
case STOP_PLAYING:
cd_stop(p_cdio);
break;
case EJECT_CD:
cd_stop(p_cdio);
cd_eject(p_cdio);
break;
case LIST_TRACKS:
tracklist();
break;
case PS_LIST_TRACKS:
ps_tracklist();
break;
case PLAY_TRACK:
/* play just this one track */
if (b_record) {
printf("%s / %s\n", artist, title);
if (one_track)
printf("%s\n", cd_info[start_track].title);
}
play_track(start_track, stop_track);
break;
case PLAY_CD:
if (b_record)
printf("%s / %s\n", artist, title);
play_track(1,CDIO_CDROM_LEADOUT_TRACK);
break;
}
} else { } else {
fprintf(stderr,"no CD in drive (%s)\n", psz_device); read_toc(p_cdio);
if (!b_cd) {
cd_close(psz_device);
read_toc(p_cdio);
}
if (b_cd)
switch (todo) {
case STOP_PLAYING:
cd_stop(p_cdio);
break;
case EJECT_CD:
/* Should have been handled above. */
cd_eject();
break;
case LIST_TRACKS:
tracklist();
break;
case PS_LIST_TRACKS:
ps_tracklist();
break;
case PLAY_TRACK:
/* play just this one track */
if (b_record) {
printf("%s / %s\n", artist, title);
if (one_track)
printf("%s\n", cd_info[start_track].title);
}
play_track(start_track, stop_track);
break;
case PLAY_CD:
if (b_record)
printf("%s / %s\n", artist, title);
play_track(1,CDIO_CDROM_LEADOUT_TRACK);
break;
}
else {
fprintf(stderr,"no CD in drive (%s)\n", psz_device);
}
} }
} }
while ( !b_sig ) { while ( !b_sig ) {
if (!b_cd) if (!b_cd) read_toc(p_cdio);
read_toc(p_cdio);
read_subchannel(p_cdio); read_subchannel(p_cdio);
display_status(); display_status();
@@ -1232,7 +1238,7 @@ main(int argc, char *argv[])
break; break;
case 'E': case 'E':
case 'e': case 'e':
cd_eject(p_cdio); cd_eject();
break; break;
case 'S': case 'S':
case 's': case 's':