diff --git a/lib/driver/MSWindows/win32.c b/lib/driver/MSWindows/win32.c index 846d558c..31c65de0 100644 --- a/lib/driver/MSWindows/win32.c +++ b/lib/driver/MSWindows/win32.c @@ -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 @@ -26,7 +26,7 @@ # include "config.h" #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 #include @@ -543,27 +543,22 @@ read_toc_win32 (void *p_user_data) } /*! - Eject media. Return 1 if successful, 0 otherwise. + Close media tray. */ -static int -eject_media_win32 (void *p_user_data) { +static driver_return_code_t +open_close_media_win32 (const char *psz_win32_drive, DWORD command_flags) +{ #ifdef _XBOX return DRIVER_OP_UNSUPPORTED; #else - _img_private_t *p_env = p_user_data; - - MCI_OPEN_PARMS op; MCI_STATUS_PARMS st; DWORD i_flags; - char psz_drive[4]; int ret; memset( &op, 0, sizeof(MCI_OPEN_PARMS) ); op.lpstrDeviceType = (LPCSTR)MCI_DEVTYPE_CD_AUDIO; - strcpy( psz_drive, "X:" ); - psz_drive[0] = p_env->gen.source_name[0]; - op.lpstrElementName = psz_drive; + op.lpstrElementName = psz_win32_drive; /* Set the flags for the device type */ 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 ) ) { st.dwItem = MCI_STATUS_READY; /* 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 */ _cdio_mciSendCommand( op.wDeviceID, MCI_CLOSE, MCI_WAIT, 0 ); } else - ret = 0; + ret = DRIVER_OP_ERROR; return ret; #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". */ @@ -801,8 +820,11 @@ cdio_is_device_win32(const char *source_name) } 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 if ( WIN_NT ) { return close_tray_win32ioctl (psz_win32_drive); @@ -813,13 +835,14 @@ close_tray_win32 ( const char *psz_win32_drive) return DRIVER_OP_UNSUPPORTED; #endif } +#endif /*! Initialization routine. This is the only thing that doesn't get called via a function pointer. In fact *we* are the ones to set that up. */ -CdIo * +CdIo_t * cdio_open_win32 (const char *psz_source_name) { #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 ones to set that up. */ -CdIo * +CdIo_t * cdio_open_am_win32 (const char *psz_orig_source, const char *psz_access_mode) { #ifdef HAVE_WIN32_CDROM - CdIo *ret; + CdIo_t *ret; _img_private_t *_data; char *psz_source; diff --git a/lib/driver/device.c b/lib/driver/device.c index 3c918b86..7fcd0d23 100644 --- a/lib/driver/device.c +++ b/lib/driver/device.c @@ -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 @@ -292,7 +292,7 @@ cdio_destroy (CdIo_t *p_cdio) CdIo_last_driver = CDIO_DRIVER_UNINIT; 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->env = NULL; free (p_cdio); diff --git a/src/cdda-player.c b/src/cdda-player.c index e12f4c11..1f444a19 100644 --- a/src/cdda-player.c +++ b/src/cdda-player.c @@ -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 @@ -284,7 +284,7 @@ oops(const char *txt, int rc) static void cd_stop(CdIo_t *p_cdio) { - if (b_cd) { + if (b_cd && p_cdio) { action("stop..."); if (DRIVER_OP_SUCCESS != cdio_audio_stop(p_cdio)) xperror("stop"); @@ -292,13 +292,16 @@ cd_stop(CdIo_t *p_cdio) } static void -cd_eject(CdIo_t *p_cdio) +cd_eject(void) { - cd_stop(p_cdio); - action("eject..."); - if (DRIVER_OP_SUCCESS != cdio_eject_media(&p_cdio)) - xperror("eject"); - b_cd = 0; + if (p_cdio) { + cd_stop(p_cdio); + action("eject..."); + if (DRIVER_OP_SUCCESS != cdio_eject_media(&p_cdio)) + xperror("eject"); + b_cd = 0; + p_cdio = NULL; + } } static void @@ -330,7 +333,7 @@ read_subchannel(CdIo_t *p_cdio) b_cd = 0; } if (auto_mode && sub.audio_status == CDIO_MMC_READ_SUB_ST_COMPLETED) - cd_eject(p_cdio); + cd_eject(); } static void @@ -1137,10 +1140,6 @@ main(int argc, char *argv[]) cdio_free_device_list(ppsz_cdda_drives); } - /* open device */ - if (b_verbose) - fprintf(stderr,"open %s... ", psz_device); - if (!interactive) { b_sig = true; 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); if (!p_cdio) { @@ -1170,49 +1173,52 @@ main(int argc, char *argv[]) if (!interactive) { b_sig = true; nostop=1; - read_toc(p_cdio); - if (!b_cd && todo != EJECT_CD) { - 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; - } + if (EJECT_CD == todo) { + cd_eject(); } 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 ) { - if (!b_cd) - read_toc(p_cdio); + if (!b_cd) read_toc(p_cdio); read_subchannel(p_cdio); display_status(); @@ -1232,7 +1238,7 @@ main(int argc, char *argv[]) break; case 'E': case 'e': - cd_eject(p_cdio); + cd_eject(); break; case 'S': case 's':