CD-ROM support is so passé :)
authorSam Lantinga <slouken@libsdl.org>
Sat, 05 Sep 2009 09:11:03 +0000
changeset 32435db962a9a991
parent 3242 af4a5af3cd2b
child 3244 7c73d5b5a0d6
CD-ROM support is so passé :)
TODO
configure.in
include/SDL.h
include/SDL_cdrom.h
include/SDL_config.h.in
include/SDL_config_dreamcast.h
include/SDL_config_iphoneos.h
include/SDL_config_macosx.h
include/SDL_config_minimal.h
include/SDL_config_nintendods.h
include/SDL_config_os2.h
include/SDL_config_pandora.h
include/SDL_config_win32.h
src/SDL.c
src/cdrom/SDL_cdrom.c
src/cdrom/SDL_syscdrom.h
src/cdrom/aix/SDL_syscdrom.c
src/cdrom/beos/SDL_syscdrom.cc
src/cdrom/bsdi/SDL_syscdrom.c
src/cdrom/dc/SDL_syscdrom.c
src/cdrom/dummy/SDL_syscdrom.c
src/cdrom/freebsd/SDL_syscdrom.c
src/cdrom/linux/SDL_syscdrom.c
src/cdrom/macosx/AudioFilePlayer.c
src/cdrom/macosx/AudioFilePlayer.h
src/cdrom/macosx/AudioFileReaderThread.c
src/cdrom/macosx/CDPlayer.c
src/cdrom/macosx/CDPlayer.h
src/cdrom/macosx/SDLOSXCAGuard.c
src/cdrom/macosx/SDLOSXCAGuard.h
src/cdrom/macosx/SDL_syscdrom.c
src/cdrom/macosx/SDL_syscdrom_c.h
src/cdrom/mint/SDL_syscdrom.c
src/cdrom/openbsd/SDL_syscdrom.c
src/cdrom/os2/SDL_syscdrom.c
src/cdrom/osf/SDL_syscdrom.c
src/cdrom/qnx/SDL_syscdrom.c
src/cdrom/win32/SDL_syscdrom.c
test/Makefile.in
test/testcdrom.c
     1.1 --- a/TODO	Sat Sep 05 09:03:35 2009 +0000
     1.2 +++ b/TODO	Sat Sep 05 09:11:03 2009 +0000
     1.3 @@ -50,4 +50,4 @@
     1.4  compatibility in this way.
     1.5  
     1.6  Requests:
     1.7 - * PCM and CDROM volume control (deprecated, but possible)
     1.8 + * PCM volume control (deprecated, but possible)
     2.1 --- a/configure.in	Sat Sep 05 09:03:35 2009 +0000
     2.2 +++ b/configure.in	Sat Sep 05 09:11:03 2009 +0000
     2.3 @@ -206,7 +206,6 @@
     2.4  # Standard C sources
     2.5  SOURCES="$SOURCES $srcdir/src/*.c"
     2.6  SOURCES="$SOURCES $srcdir/src/audio/*.c"
     2.7 -SOURCES="$SOURCES $srcdir/src/cdrom/*.c"
     2.8  SOURCES="$SOURCES $srcdir/src/cpuinfo/*.c"
     2.9  SOURCES="$SOURCES $srcdir/src/events/*.c"
    2.10  SOURCES="$SOURCES $srcdir/src/file/*.c"
    2.11 @@ -265,12 +264,6 @@
    2.12  else
    2.13      SOURCES="$SOURCES $srcdir/src/power/*.c"
    2.14  fi
    2.15 -AC_ARG_ENABLE(cdrom,
    2.16 -AC_HELP_STRING([--enable-cdrom], [Enable the cdrom subsystem [[default=yes]]]),
    2.17 -              , enable_cdrom=yes)
    2.18 -if test x$enable_cdrom != xyes; then
    2.19 -    AC_DEFINE(SDL_CDROM_DISABLED)
    2.20 -fi
    2.21  AC_ARG_ENABLE(threads,
    2.22  AC_HELP_STRING([--enable-threads], [Enable the threading subsystem [[default=yes]]]),
    2.23                , enable_threads=yes)
    2.24 @@ -2481,41 +2474,6 @@
    2.25                 ;;
    2.26               esac
    2.27          fi
    2.28 -        # Set up files for the cdrom library
    2.29 -        if test x$enable_cdrom = xyes; then
    2.30 -          case $ARCH in
    2.31 -            linux|solaris)
    2.32 -                AC_DEFINE(SDL_CDROM_LINUX)
    2.33 -                SOURCES="$SOURCES $srcdir/src/cdrom/linux/*.c"
    2.34 -                have_cdrom=yes
    2.35 -            ;;
    2.36 -            *freebsd*)
    2.37 -                AC_DEFINE(SDL_CDROM_FREEBSD)
    2.38 -                SOURCES="$SOURCES $srcdir/src/cdrom/freebsd/*.c"
    2.39 -                have_cdrom=yes
    2.40 -            ;;
    2.41 -            *openbsd*|*netbsd*)
    2.42 -                AC_DEFINE(SDL_CDROM_OPENBSD)
    2.43 -                SOURCES="$SOURCES $srcdir/src/cdrom/openbsd/*.c"
    2.44 -                have_cdrom=yes
    2.45 -            ;;
    2.46 -            bsdi)
    2.47 -                AC_DEFINE(SDL_CDROM_BSDI)
    2.48 -                SOURCES="$SOURCES $srcdir/src/cdrom/bsdi/*.c"
    2.49 -                have_cdrom=yes
    2.50 -            ;;
    2.51 -            aix)
    2.52 -                AC_DEFINE(SDL_CDROM_AIX)
    2.53 -                SOURCES="$SOURCES $srcdir/src/cdrom/aix/*.c"
    2.54 -                have_cdrom=yes
    2.55 -            ;;
    2.56 -            osf)
    2.57 -                AC_DEFINE(SDL_CDROM_OSF)
    2.58 -                SOURCES="$SOURCES $srcdir/src/cdrom/osf/*.c"
    2.59 -                have_cdrom=yes
    2.60 -            ;;
    2.61 -          esac
    2.62 -        fi
    2.63          # Set up files for the thread library
    2.64          if test x$enable_threads = xyes -a x$use_pthreads != xyes -a x$use_pth != xyes -a x$ARCH = xirix; then
    2.65              AC_DEFINE(SDL_THREAD_SPROC)
    2.66 @@ -2560,12 +2518,6 @@
    2.67              EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lasound"
    2.68              have_audio=yes
    2.69          fi
    2.70 -        # Set up files for the cdrom library
    2.71 -        if test x$enable_cdrom = xyes; then
    2.72 -            AC_DEFINE(SDL_CDROM_QNX)
    2.73 -            SOURCES="$SOURCES $srcdir/src/cdrom/qnx/*.c"
    2.74 -            have_cdrom=yes
    2.75 -        fi
    2.76          # Set up files for the timer library
    2.77          if test x$enable_timers = xyes; then
    2.78              AC_DEFINE(SDL_TIMER_UNIX)
    2.79 @@ -2743,12 +2695,6 @@
    2.80              SOURCES="$SOURCES $srcdir/src/power/windows/SDL_syspower.c"
    2.81              have_power=yes
    2.82          fi
    2.83 -        # Set up files for the cdrom library
    2.84 -        if test x$enable_cdrom = xyes; then
    2.85 -            AC_DEFINE(SDL_CDROM_WIN32)
    2.86 -            SOURCES="$SOURCES $srcdir/src/cdrom/win32/*.c"
    2.87 -            have_cdrom=yes
    2.88 -        fi
    2.89          # Set up files for the thread library
    2.90          if test x$enable_threads = xyes; then
    2.91              AC_DEFINE(SDL_THREAD_WIN32)
    2.92 @@ -2801,12 +2747,6 @@
    2.93              SOURCES="$SOURCES $srcdir/src/joystick/beos/*.cc"
    2.94              have_joystick=yes
    2.95          fi
    2.96 -        # Set up files for the cdrom library
    2.97 -        if test x$enable_cdrom = xyes; then
    2.98 -            AC_DEFINE(SDL_CDROM_BEOS)
    2.99 -            SOURCES="$SOURCES $srcdir/src/cdrom/beos/*.cc"
   2.100 -            have_cdrom=yes
   2.101 -        fi
   2.102          # Set up files for the thread library
   2.103          if test x$enable_threads = xyes; then
   2.104              AC_DEFINE(SDL_THREAD_BEOS)
   2.105 @@ -2910,12 +2850,6 @@
   2.106              SOURCES="$SOURCES $srcdir/src/power/macosx/*.c"
   2.107              have_power=yes
   2.108          fi
   2.109 -        # Set up files for the cdrom library
   2.110 -        if test x$enable_cdrom = xyes; then
   2.111 -            AC_DEFINE(SDL_CDROM_MACOSX)
   2.112 -            SOURCES="$SOURCES $srcdir/src/cdrom/macosx/*.c"
   2.113 -            have_cdrom=yes
   2.114 -        fi
   2.115          # Set up files for the timer library
   2.116          if test x$enable_timers = xyes; then
   2.117              AC_DEFINE(SDL_TIMER_UNIX)
   2.118 @@ -2929,7 +2863,7 @@
   2.119          EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Carbon"
   2.120          EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,IOKit"
   2.121          # If either the audio or CD driver is used, add the AudioUnit framework
   2.122 -        if test x$enable_audio = xyes -o x$enable_cdrom = xyes; then
   2.123 +        if test x$enable_audio = xyes; then
   2.124              EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit"
   2.125          fi
   2.126          ;;
   2.127 @@ -2959,12 +2893,6 @@
   2.128              SOURCES="$SOURCES $srcdir/src/joystick/mint/*.c"
   2.129              have_joystick=yes
   2.130          fi
   2.131 -        # Set up files for the cdrom library
   2.132 -        if test x$enable_cdrom = xyes; then
   2.133 -            AC_DEFINE(SDL_CDROM_MINT)
   2.134 -            SOURCES="$SOURCES $srcdir/src/cdrom/mint/*.c"
   2.135 -            have_cdrom=yes
   2.136 -        fi
   2.137          # Set up files for the timer library
   2.138          if test x$enable_timers = xyes; then
   2.139              if test x$enable_threads = xyes -a x$enable_pth = xyes; then
   2.140 @@ -3025,12 +2953,6 @@
   2.141      fi
   2.142      SOURCES="$SOURCES $srcdir/src/haptic/dummy/*.c"
   2.143  fi
   2.144 -if test x$have_cdrom != xyes; then
   2.145 -    if test x$enable_cdrom = xyes; then
   2.146 -        AC_DEFINE(SDL_CDROM_DISABLED)
   2.147 -    fi
   2.148 -    SOURCES="$SOURCES $srcdir/src/cdrom/dummy/*.c"
   2.149 -fi
   2.150  if test x$have_threads != xyes; then
   2.151      if test x$enable_threads = xyes; then
   2.152          AC_DEFINE(SDL_THREADS_DISABLED)
     3.1 --- a/include/SDL.h	Sat Sep 05 09:03:35 2009 +0000
     3.2 +++ b/include/SDL.h	Sat Sep 05 09:11:03 2009 +0000
     3.3 @@ -78,7 +78,6 @@
     3.4  #include "SDL_stdinc.h"
     3.5  #include "SDL_atomic.h"
     3.6  #include "SDL_audio.h"
     3.7 -#include "SDL_cdrom.h"
     3.8  #include "SDL_cpuinfo.h"
     3.9  #include "SDL_endian.h"
    3.10  #include "SDL_error.h"
    3.11 @@ -109,7 +108,6 @@
    3.12  #define SDL_INIT_TIMER          0x00000001
    3.13  #define SDL_INIT_AUDIO          0x00000010
    3.14  #define SDL_INIT_VIDEO          0x00000020
    3.15 -#define SDL_INIT_CDROM          0x00000100
    3.16  #define SDL_INIT_JOYSTICK       0x00000200
    3.17  #define SDL_INIT_HAPTIC         0x00001000
    3.18  #define SDL_INIT_NOPARACHUTE    0x00100000      /* Don't catch fatal signals */
     4.1 --- a/include/SDL_cdrom.h	Sat Sep 05 09:03:35 2009 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,186 +0,0 @@
     4.4 -/*
     4.5 -    SDL - Simple DirectMedia Layer
     4.6 -    Copyright (C) 1997-2009 Sam Lantinga
     4.7 -
     4.8 -    This library is free software; you can redistribute it and/or
     4.9 -    modify it under the terms of the GNU Lesser General Public
    4.10 -    License as published by the Free Software Foundation; either
    4.11 -    version 2.1 of the License, or (at your option) any later version.
    4.12 -
    4.13 -    This library is distributed in the hope that it will be useful,
    4.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 -    Lesser General Public License for more details.
    4.17 -
    4.18 -    You should have received a copy of the GNU Lesser General Public
    4.19 -    License along with this library; if not, write to the Free Software
    4.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    4.21 -
    4.22 -    Sam Lantinga
    4.23 -    slouken@libsdl.org
    4.24 -*/
    4.25 -
    4.26 -/**
    4.27 - * \file SDL_cdrom.h
    4.28 - *
    4.29 - * This is the CD-audio control API for Simple DirectMedia Layer
    4.30 - */
    4.31 -
    4.32 -#ifndef _SDL_cdrom_h
    4.33 -#define _SDL_cdrom_h
    4.34 -
    4.35 -#include "SDL_stdinc.h"
    4.36 -#include "SDL_error.h"
    4.37 -
    4.38 -#include "begin_code.h"
    4.39 -/* Set up for C function definitions, even when using C++ */
    4.40 -#ifdef __cplusplus
    4.41 -/* *INDENT-OFF* */
    4.42 -extern "C" {
    4.43 -/* *INDENT-ON* */
    4.44 -#endif
    4.45 -
    4.46 -/* In order to use these functions, SDL_Init() must have been called
    4.47 -   with the SDL_INIT_CDROM flag.  This causes SDL to scan the system
    4.48 -   for CD-ROM drives, and load appropriate drivers.
    4.49 -*/
    4.50 -
    4.51 -/* The maximum number of CD-ROM tracks on a disk */
    4.52 -#define SDL_MAX_TRACKS	99
    4.53 -
    4.54 -/* The types of CD-ROM track possible */
    4.55 -#define SDL_AUDIO_TRACK	0x00
    4.56 -#define SDL_DATA_TRACK	0x04
    4.57 -
    4.58 -/* The possible states which a CD-ROM drive can be in. */
    4.59 -typedef enum
    4.60 -{
    4.61 -    CD_TRAYEMPTY,
    4.62 -    CD_STOPPED,
    4.63 -    CD_PLAYING,
    4.64 -    CD_PAUSED,
    4.65 -    CD_ERROR = -1
    4.66 -} CDstatus;
    4.67 -
    4.68 -/* Given a status, returns true if there's a disk in the drive */
    4.69 -#define CD_INDRIVE(status)	((int)(status) > 0)
    4.70 -
    4.71 -typedef struct SDL_CDtrack
    4.72 -{
    4.73 -    Uint8 id;                   /* Track number */
    4.74 -    Uint8 type;                 /* Data or audio track */
    4.75 -    Uint16 unused;
    4.76 -    Uint32 length;              /* Length, in frames, of this track */
    4.77 -    Uint32 offset;              /* Offset, in frames, from start of disk */
    4.78 -} SDL_CDtrack;
    4.79 -
    4.80 -/* This structure is only current as of the last call to SDL_CDStatus() */
    4.81 -typedef struct SDL_CD
    4.82 -{
    4.83 -    int id;                     /* Private drive identifier */
    4.84 -    CDstatus status;            /* Current drive status */
    4.85 -
    4.86 -    /* The rest of this structure is only valid if there's a CD in drive */
    4.87 -    int numtracks;              /* Number of tracks on disk */
    4.88 -    int cur_track;              /* Current track position */
    4.89 -    int cur_frame;              /* Current frame offset within current track */
    4.90 -    SDL_CDtrack track[SDL_MAX_TRACKS + 1];
    4.91 -} SDL_CD;
    4.92 -
    4.93 -/* Conversion functions from frames to Minute/Second/Frames and vice versa */
    4.94 -#define CD_FPS	75
    4.95 -#define FRAMES_TO_MSF(f, M,S,F)	{					\
    4.96 -	int value = f;							\
    4.97 -	*(F) = value%CD_FPS;						\
    4.98 -	value /= CD_FPS;						\
    4.99 -	*(S) = value%60;						\
   4.100 -	value /= 60;							\
   4.101 -	*(M) = value;							\
   4.102 -}
   4.103 -#define MSF_TO_FRAMES(M, S, F)	((M)*60*CD_FPS+(S)*CD_FPS+(F))
   4.104 -
   4.105 -/* CD-audio API functions: */
   4.106 -
   4.107 -/* Returns the number of CD-ROM drives on the system, or -1 if
   4.108 -   SDL_Init() has not been called with the SDL_INIT_CDROM flag.
   4.109 - */
   4.110 -extern DECLSPEC int SDLCALL SDL_CDNumDrives(void);
   4.111 -
   4.112 -/* Returns a human-readable, system-dependent identifier for the CD-ROM.
   4.113 -   Example:
   4.114 -	"/dev/cdrom"
   4.115 -	"E:"
   4.116 -	"/dev/disk/ide/1/master"
   4.117 -*/
   4.118 -extern DECLSPEC const char *SDLCALL SDL_CDName(int drive);
   4.119 -
   4.120 -/* Opens a CD-ROM drive for access.  It returns a drive handle on success,
   4.121 -   or NULL if the drive was invalid or busy.  This newly opened CD-ROM
   4.122 -   becomes the default CD used when other CD functions are passed a NULL
   4.123 -   CD-ROM handle.
   4.124 -   Drives are numbered starting with 0.  Drive 0 is the system default CD-ROM.
   4.125 -*/
   4.126 -extern DECLSPEC SDL_CD *SDLCALL SDL_CDOpen(int drive);
   4.127 -
   4.128 -/* This function returns the current status of the given drive.
   4.129 -   If the drive has a CD in it, the table of contents of the CD and current
   4.130 -   play position of the CD will be stored in the SDL_CD structure.
   4.131 -*/
   4.132 -extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD * cdrom);
   4.133 -
   4.134 -/* Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks'
   4.135 -   tracks and 'nframes' frames.  If both 'ntrack' and 'nframe' are 0, play 
   4.136 -   until the end of the CD.  This function will skip data tracks.
   4.137 -   This function should only be called after calling SDL_CDStatus() to 
   4.138 -   get track information about the CD.
   4.139 -   For example:
   4.140 -	// Play entire CD:
   4.141 -	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
   4.142 -		SDL_CDPlayTracks(cdrom, 0, 0, 0, 0);
   4.143 -	// Play last track:
   4.144 -	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
   4.145 -		SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0);
   4.146 -	}
   4.147 -	// Play first and second track and 10 seconds of third track:
   4.148 -	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
   4.149 -		SDL_CDPlayTracks(cdrom, 0, 0, 2, 10);
   4.150 -
   4.151 -   This function returns 0, or -1 if there was an error.
   4.152 -*/
   4.153 -extern DECLSPEC int SDLCALL SDL_CDPlayTracks(SDL_CD * cdrom,
   4.154 -                                             int start_track,
   4.155 -                                             int start_frame, int ntracks,
   4.156 -                                             int nframes);
   4.157 -
   4.158 -/* Play the given CD starting at 'start' frame for 'length' frames.
   4.159 -   It returns 0, or -1 if there was an error.
   4.160 -*/
   4.161 -extern DECLSPEC int SDLCALL SDL_CDPlay(SDL_CD * cdrom, int start, int length);
   4.162 -
   4.163 -/* Pause play -- returns 0, or -1 on error */
   4.164 -extern DECLSPEC int SDLCALL SDL_CDPause(SDL_CD * cdrom);
   4.165 -
   4.166 -/* Resume play -- returns 0, or -1 on error */
   4.167 -extern DECLSPEC int SDLCALL SDL_CDResume(SDL_CD * cdrom);
   4.168 -
   4.169 -/* Stop play -- returns 0, or -1 on error */
   4.170 -extern DECLSPEC int SDLCALL SDL_CDStop(SDL_CD * cdrom);
   4.171 -
   4.172 -/* Eject CD-ROM -- returns 0, or -1 on error */
   4.173 -extern DECLSPEC int SDLCALL SDL_CDEject(SDL_CD * cdrom);
   4.174 -
   4.175 -/* Closes the handle for the CD-ROM drive */
   4.176 -extern DECLSPEC void SDLCALL SDL_CDClose(SDL_CD * cdrom);
   4.177 -
   4.178 -
   4.179 -/* Ends C function definitions when using C++ */
   4.180 -#ifdef __cplusplus
   4.181 -/* *INDENT-OFF* */
   4.182 -}
   4.183 -/* *INDENT-ON* */
   4.184 -#endif
   4.185 -#include "close_code.h"
   4.186 -
   4.187 -#endif /* _SDL_video_h */
   4.188 -
   4.189 -/* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/include/SDL_config.h.in	Sat Sep 05 09:03:35 2009 +0000
     5.2 +++ b/include/SDL_config.h.in	Sat Sep 05 09:11:03 2009 +0000
     5.3 @@ -160,7 +160,6 @@
     5.4  
     5.5  /* Allow disabling of core subsystems */
     5.6  #undef SDL_AUDIO_DISABLED
     5.7 -#undef SDL_CDROM_DISABLED
     5.8  #undef SDL_CPUINFO_DISABLED
     5.9  #undef SDL_EVENTS_DISABLED
    5.10  #undef SDL_FILE_DISABLED
    5.11 @@ -204,22 +203,6 @@
    5.12  #undef SDL_AUDIO_DRIVER_FUSIONSOUND
    5.13  #undef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
    5.14  
    5.15 -/* Enable various cdrom drivers */
    5.16 -#undef SDL_CDROM_AIX
    5.17 -#undef SDL_CDROM_BEOS
    5.18 -#undef SDL_CDROM_BSDI
    5.19 -#undef SDL_CDROM_DC
    5.20 -#undef SDL_CDROM_DUMMY
    5.21 -#undef SDL_CDROM_FREEBSD
    5.22 -#undef SDL_CDROM_LINUX
    5.23 -#undef SDL_CDROM_MACOSX
    5.24 -#undef SDL_CDROM_MINT
    5.25 -#undef SDL_CDROM_OPENBSD
    5.26 -#undef SDL_CDROM_OS2
    5.27 -#undef SDL_CDROM_OSF
    5.28 -#undef SDL_CDROM_QNX
    5.29 -#undef SDL_CDROM_WIN32
    5.30 -
    5.31  /* Enable various input drivers */
    5.32  #undef SDL_INPUT_LINUXEV
    5.33  #undef SDL_INPUT_TSLIB
     6.1 --- a/include/SDL_config_dreamcast.h	Sat Sep 05 09:03:35 2009 +0000
     6.2 +++ b/include/SDL_config_dreamcast.h	Sat Sep 05 09:11:03 2009 +0000
     6.3 @@ -88,9 +88,6 @@
     6.4  #define SDL_AUDIO_DRIVER_DISK	1
     6.5  #define SDL_AUDIO_DRIVER_DUMMY	1
     6.6  
     6.7 -/* Enable various cdrom drivers */
     6.8 -#define SDL_CDROM_DC	1
     6.9 -
    6.10  /* Enable various input drivers */
    6.11  #define SDL_JOYSTICK_DC	1
    6.12  #define SDL_HAPTIC_DUMMY	1
     7.1 --- a/include/SDL_config_iphoneos.h	Sat Sep 05 09:03:35 2009 +0000
     7.2 +++ b/include/SDL_config_iphoneos.h	Sat Sep 05 09:11:03 2009 +0000
     7.3 @@ -106,9 +106,6 @@
     7.4  /* Enable the dummy audio driver (src/audio/dummy/\*.c) */
     7.5  #define SDL_AUDIO_DRIVER_DUMMY	1
     7.6  
     7.7 -/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */
     7.8 -#define SDL_CDROM_DISABLED	1
     7.9 -
    7.10  /* Enable the stub haptic driver (src/haptic/dummy/\*.c) */
    7.11  #define SDL_HAPTIC_DISABLED	1
    7.12  
     8.1 --- a/include/SDL_config_macosx.h	Sat Sep 05 09:03:35 2009 +0000
     8.2 +++ b/include/SDL_config_macosx.h	Sat Sep 05 09:11:03 2009 +0000
     8.3 @@ -106,9 +106,6 @@
     8.4  #define SDL_AUDIO_DRIVER_DISK	1
     8.5  #define SDL_AUDIO_DRIVER_DUMMY	1
     8.6  
     8.7 -/* Enable various cdrom drivers */
     8.8 -#define SDL_CDROM_MACOSX	1
     8.9 -
    8.10  /* Enable various input drivers */
    8.11  #define SDL_JOYSTICK_IOKIT	1
    8.12  #define SDL_HAPTIC_IOKIT	1
     9.1 --- a/include/SDL_config_minimal.h	Sat Sep 05 09:03:35 2009 +0000
     9.2 +++ b/include/SDL_config_minimal.h	Sat Sep 05 09:11:03 2009 +0000
     9.3 @@ -43,9 +43,6 @@
     9.4  /* Enable the dummy audio driver (src/audio/dummy/\*.c) */
     9.5  #define SDL_AUDIO_DRIVER_DUMMY	1
     9.6  
     9.7 -/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */
     9.8 -#define SDL_CDROM_DISABLED	1
     9.9 -
    9.10  /* Enable the stub joystick driver (src/joystick/dummy/\*.c) */
    9.11  #define SDL_JOYSTICK_DISABLED	1
    9.12  
    10.1 --- a/include/SDL_config_nintendods.h	Sat Sep 05 09:03:35 2009 +0000
    10.2 +++ b/include/SDL_config_nintendods.h	Sat Sep 05 09:11:03 2009 +0000
    10.3 @@ -96,9 +96,6 @@
    10.4  #define SDL_AUDIO_DRIVER_NDS	1
    10.5  /*#define SDL_AUDIO_DRIVER_DUMMY	1 TODO: uncomment this later*/
    10.6  
    10.7 -/* DS doesn't have optical media */
    10.8 -#define SDL_CDROM_DISABLED	1
    10.9 -
   10.10  /* Enable various input drivers */
   10.11  #define SDL_JOYSTICK_NDS	1
   10.12  /*#define SDL_JOYSTICK_DUMMY	1 TODO: uncomment this later*/
    11.1 --- a/include/SDL_config_os2.h	Sat Sep 05 09:03:35 2009 +0000
    11.2 +++ b/include/SDL_config_os2.h	Sat Sep 05 09:11:03 2009 +0000
    11.3 @@ -116,9 +116,6 @@
    11.4  #define SDL_AUDIO_DRIVER_DISK	1
    11.5  #define SDL_AUDIO_DRIVER_DUMMY	1
    11.6  
    11.7 -/* Enable various cdrom drivers */
    11.8 -#define SDL_CDROM_OS2	1
    11.9 -
   11.10  /* Enable various input drivers */
   11.11  #define SDL_JOYSTICK_OS2	1
   11.12  #define SDL_HAPTIC_DUMMY	1
    12.1 --- a/include/SDL_config_pandora.h	Sat Sep 05 09:03:35 2009 +0000
    12.2 +++ b/include/SDL_config_pandora.h	Sat Sep 05 09:11:03 2009 +0000
    12.3 @@ -95,7 +95,6 @@
    12.4  #define HAVE_SETJMP 1
    12.5  #define HAVE_NANOSLEEP 1
    12.6  
    12.7 -#define SDL_CDROM_DISABLED 1
    12.8  #define SDL_AUDIO_DRIVER_DUMMY 1
    12.9  #define SDL_AUDIO_DRIVER_OSS 1
   12.10  
    13.1 --- a/include/SDL_config_win32.h	Sat Sep 05 09:03:35 2009 +0000
    13.2 +++ b/include/SDL_config_win32.h	Sat Sep 05 09:11:03 2009 +0000
    13.3 @@ -150,13 +150,6 @@
    13.4  #define SDL_AUDIO_DRIVER_DISK	1
    13.5  #define SDL_AUDIO_DRIVER_DUMMY	1
    13.6  
    13.7 -/* Enable various cdrom drivers */
    13.8 -#ifdef _WIN32_WCE
    13.9 -#define SDL_CDROM_DISABLED	1
   13.10 -#else
   13.11 -#define SDL_CDROM_WIN32		1
   13.12 -#endif
   13.13 -
   13.14  /* Enable various input drivers */
   13.15  #ifdef _WIN32_WCE
   13.16  #define SDL_JOYSTICK_DISABLED	1
    14.1 --- a/src/SDL.c	Sat Sep 05 09:03:35 2009 +0000
    14.2 +++ b/src/SDL.c	Sat Sep 05 09:11:03 2009 +0000
    14.3 @@ -42,10 +42,6 @@
    14.4  extern int SDL_HapticInit(void);
    14.5  extern int SDL_HapticQuit(void);
    14.6  #endif
    14.7 -#if !SDL_CDROM_DISABLED
    14.8 -extern int SDL_CDROMInit(void);
    14.9 -extern void SDL_CDROMQuit(void);
   14.10 -#endif
   14.11  #if !SDL_TIMERS_DISABLED
   14.12  extern void SDL_StartTicks(void);
   14.13  extern int SDL_TimerInit(void);
   14.14 @@ -145,22 +141,6 @@
   14.15          return (-1);
   14.16      }
   14.17  #endif
   14.18 -
   14.19 -
   14.20 -#if !SDL_CDROM_DISABLED
   14.21 -    /* Initialize the CD-ROM subsystem */
   14.22 -    if ((flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM)) {
   14.23 -        if (SDL_CDROMInit() < 0) {
   14.24 -            return (-1);
   14.25 -        }
   14.26 -        SDL_initialized |= SDL_INIT_CDROM;
   14.27 -    }
   14.28 -#else
   14.29 -    if (flags & SDL_INIT_CDROM) {
   14.30 -        SDL_SetError("SDL not built with cdrom support");
   14.31 -        return (-1);
   14.32 -    }
   14.33 -#endif
   14.34      return (0);
   14.35  }
   14.36  
   14.37 @@ -198,12 +178,6 @@
   14.38  SDL_QuitSubSystem(Uint32 flags)
   14.39  {
   14.40      /* Shut down requested initialized subsystems */
   14.41 -#if !SDL_CDROM_DISABLED
   14.42 -    if ((flags & SDL_initialized & SDL_INIT_CDROM)) {
   14.43 -        SDL_CDROMQuit();
   14.44 -        SDL_initialized &= ~SDL_INIT_CDROM;
   14.45 -    }
   14.46 -#endif
   14.47  #if !SDL_JOYSTICK_DISABLED
   14.48      if ((flags & SDL_initialized & SDL_INIT_JOYSTICK)) {
   14.49          SDL_JoystickQuit();
    15.1 --- a/src/cdrom/SDL_cdrom.c	Sat Sep 05 09:03:35 2009 +0000
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,357 +0,0 @@
    15.4 -/*
    15.5 -    SDL - Simple DirectMedia Layer
    15.6 -    Copyright (C) 1997-2009 Sam Lantinga
    15.7 -
    15.8 -    This library is free software; you can redistribute it and/or
    15.9 -    modify it under the terms of the GNU Lesser General Public
   15.10 -    License as published by the Free Software Foundation; either
   15.11 -    version 2.1 of the License, or (at your option) any later version.
   15.12 -
   15.13 -    This library is distributed in the hope that it will be useful,
   15.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15.16 -    Lesser General Public License for more details.
   15.17 -
   15.18 -    You should have received a copy of the GNU Lesser General Public
   15.19 -    License along with this library; if not, write to the Free Software
   15.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   15.21 -
   15.22 -    Sam Lantinga
   15.23 -    slouken@libsdl.org
   15.24 -*/
   15.25 -#include "SDL_config.h"
   15.26 -
   15.27 -/* This is the CD-audio control API for Simple DirectMedia Layer */
   15.28 -
   15.29 -#include "SDL_cdrom.h"
   15.30 -#include "SDL_syscdrom.h"
   15.31 -
   15.32 -#define CLIP_FRAMES	10      /* Some CD-ROMs won't go all the way */
   15.33 -
   15.34 -static int SDL_cdinitted = 0;
   15.35 -static SDL_CD *default_cdrom;
   15.36 -
   15.37 -/* The system level CD-ROM control functions */
   15.38 -struct CDcaps SDL_CDcaps = {
   15.39 -    NULL,                       /* Name */
   15.40 -    NULL,                       /* Open */
   15.41 -    NULL,                       /* GetTOC */
   15.42 -    NULL,                       /* Status */
   15.43 -    NULL,                       /* Play */
   15.44 -    NULL,                       /* Pause */
   15.45 -    NULL,                       /* Resume */
   15.46 -    NULL,                       /* Stop */
   15.47 -    NULL,                       /* Eject */
   15.48 -    NULL,                       /* Close */
   15.49 -};
   15.50 -
   15.51 -int SDL_numcds;
   15.52 -
   15.53 -int
   15.54 -SDL_CDROMInit(void)
   15.55 -{
   15.56 -    int retval;
   15.57 -
   15.58 -    SDL_numcds = 0;
   15.59 -    retval = SDL_SYS_CDInit();
   15.60 -    if (retval == 0) {
   15.61 -        SDL_cdinitted = 1;
   15.62 -    }
   15.63 -    default_cdrom = NULL;
   15.64 -    return (retval);
   15.65 -}
   15.66 -
   15.67 -/* Check to see if the CD-ROM subsystem has been initialized */
   15.68 -static int
   15.69 -CheckInit(int check_cdrom, SDL_CD ** cdrom)
   15.70 -{
   15.71 -    int okay;
   15.72 -
   15.73 -    okay = SDL_cdinitted;
   15.74 -    if (check_cdrom && (*cdrom == NULL)) {
   15.75 -        *cdrom = default_cdrom;
   15.76 -        if (*cdrom == NULL) {
   15.77 -            SDL_SetError("CD-ROM not opened");
   15.78 -            okay = 0;
   15.79 -        }
   15.80 -    }
   15.81 -    if (!SDL_cdinitted) {
   15.82 -        SDL_SetError("CD-ROM subsystem not initialized");
   15.83 -    }
   15.84 -    return (okay);
   15.85 -}
   15.86 -
   15.87 -int
   15.88 -SDL_CDNumDrives(void)
   15.89 -{
   15.90 -    if (!CheckInit(0, NULL)) {
   15.91 -        return (-1);
   15.92 -    }
   15.93 -    return (SDL_numcds);
   15.94 -}
   15.95 -
   15.96 -const char *
   15.97 -SDL_CDName(int drive)
   15.98 -{
   15.99 -    if (!CheckInit(0, NULL)) {
  15.100 -        return (NULL);
  15.101 -    }
  15.102 -    if (drive >= SDL_numcds) {
  15.103 -        SDL_SetError("Invalid CD-ROM drive index");
  15.104 -        return (NULL);
  15.105 -    }
  15.106 -    if (SDL_CDcaps.Name) {
  15.107 -        return (SDL_CDcaps.Name(drive));
  15.108 -    } else {
  15.109 -        return ("");
  15.110 -    }
  15.111 -}
  15.112 -
  15.113 -SDL_CD *
  15.114 -SDL_CDOpen(int drive)
  15.115 -{
  15.116 -    struct SDL_CD *cdrom;
  15.117 -
  15.118 -    if (!CheckInit(0, NULL)) {
  15.119 -        return (NULL);
  15.120 -    }
  15.121 -    if (drive >= SDL_numcds) {
  15.122 -        SDL_SetError("Invalid CD-ROM drive index");
  15.123 -        return (NULL);
  15.124 -    }
  15.125 -    cdrom = (SDL_CD *) SDL_malloc(sizeof(*cdrom));
  15.126 -    if (cdrom == NULL) {
  15.127 -        SDL_OutOfMemory();
  15.128 -        return (NULL);
  15.129 -    }
  15.130 -    SDL_memset(cdrom, 0, sizeof(*cdrom));
  15.131 -    cdrom->id = SDL_CDcaps.Open(drive);
  15.132 -    if (cdrom->id < 0) {
  15.133 -        SDL_free(cdrom);
  15.134 -        return (NULL);
  15.135 -    }
  15.136 -    default_cdrom = cdrom;
  15.137 -    return (cdrom);
  15.138 -}
  15.139 -
  15.140 -CDstatus
  15.141 -SDL_CDStatus(SDL_CD * cdrom)
  15.142 -{
  15.143 -    CDstatus status;
  15.144 -    int i;
  15.145 -    Uint32 position;
  15.146 -
  15.147 -    /* Check if the CD-ROM subsystem has been initialized */
  15.148 -    if (!CheckInit(1, &cdrom)) {
  15.149 -        return (CD_ERROR);
  15.150 -    }
  15.151 -
  15.152 -    /* Get the current status of the drive */
  15.153 -    cdrom->numtracks = 0;
  15.154 -    cdrom->cur_track = 0;
  15.155 -    cdrom->cur_frame = 0;
  15.156 -    status = SDL_CDcaps.Status(cdrom, &i);
  15.157 -    position = (Uint32) i;
  15.158 -    cdrom->status = status;
  15.159 -
  15.160 -    /* Get the table of contents, if there's a CD available */
  15.161 -    if (CD_INDRIVE(status)) {
  15.162 -        if (SDL_CDcaps.GetTOC(cdrom) < 0) {
  15.163 -            status = CD_ERROR;
  15.164 -        }
  15.165 -        /* If the drive is playing, get current play position */
  15.166 -        if ((status == CD_PLAYING) || (status == CD_PAUSED)) {
  15.167 -            for (i = 1; cdrom->track[i].offset <= position; ++i) {
  15.168 -                /* Keep looking */ ;
  15.169 -            }
  15.170 -#ifdef DEBUG_CDROM
  15.171 -            fprintf(stderr,
  15.172 -                    "Current position: %d, track = %d (offset is %d)\n",
  15.173 -                    position, i - 1, cdrom->track[i - 1].offset);
  15.174 -#endif
  15.175 -            cdrom->cur_track = i - 1;
  15.176 -            position -= cdrom->track[cdrom->cur_track].offset;
  15.177 -            cdrom->cur_frame = position;
  15.178 -        }
  15.179 -    }
  15.180 -    return (status);
  15.181 -}
  15.182 -
  15.183 -int
  15.184 -SDL_CDPlayTracks(SDL_CD * cdrom,
  15.185 -                 int strack, int sframe, int ntracks, int nframes)
  15.186 -{
  15.187 -    int etrack, eframe;
  15.188 -    int start, length;
  15.189 -
  15.190 -    /* Check if the CD-ROM subsystem has been initialized */
  15.191 -    if (!CheckInit(1, &cdrom)) {
  15.192 -        return (CD_ERROR);
  15.193 -    }
  15.194 -
  15.195 -    /* Determine the starting and ending tracks */
  15.196 -    if ((strack < 0) || (strack >= cdrom->numtracks)) {
  15.197 -        SDL_SetError("Invalid starting track");
  15.198 -        return (CD_ERROR);
  15.199 -    }
  15.200 -    if (!ntracks && !nframes) {
  15.201 -        etrack = cdrom->numtracks;
  15.202 -        eframe = 0;
  15.203 -    } else {
  15.204 -        etrack = strack + ntracks;
  15.205 -        if (etrack == strack) {
  15.206 -            eframe = sframe + nframes;
  15.207 -        } else {
  15.208 -            eframe = nframes;
  15.209 -        }
  15.210 -    }
  15.211 -    if (etrack > cdrom->numtracks) {
  15.212 -        SDL_SetError("Invalid play length");
  15.213 -        return (CD_ERROR);
  15.214 -    }
  15.215 -
  15.216 -    /* Skip data tracks and verify frame offsets */
  15.217 -    while ((strack <= etrack) &&
  15.218 -           (cdrom->track[strack].type == SDL_DATA_TRACK)) {
  15.219 -        ++strack;
  15.220 -    }
  15.221 -    if (sframe >= (int) cdrom->track[strack].length) {
  15.222 -        SDL_SetError("Invalid starting frame for track %d", strack);
  15.223 -        return (CD_ERROR);
  15.224 -    }
  15.225 -    while ((etrack > strack) &&
  15.226 -           (cdrom->track[etrack - 1].type == SDL_DATA_TRACK)) {
  15.227 -        --etrack;
  15.228 -    }
  15.229 -    if (eframe > (int) cdrom->track[etrack].length) {
  15.230 -        SDL_SetError("Invalid ending frame for track %d", etrack);
  15.231 -        return (CD_ERROR);
  15.232 -    }
  15.233 -
  15.234 -    /* Determine start frame and play length */
  15.235 -    start = (cdrom->track[strack].offset + sframe);
  15.236 -    length = (cdrom->track[etrack].offset + eframe) - start;
  15.237 -#ifdef CLIP_FRAMES
  15.238 -    /* I've never seen this necessary, but xmcd does it.. */
  15.239 -    length -= CLIP_FRAMES;      /* CLIP_FRAMES == 10 */
  15.240 -#endif
  15.241 -    if (length < 0) {
  15.242 -        return (0);
  15.243 -    }
  15.244 -
  15.245 -    /* Play! */
  15.246 -#ifdef DEBUG_CDROM
  15.247 -    fprintf(stderr, "Playing %d frames at offset %d\n", length, start);
  15.248 -#endif
  15.249 -    return (SDL_CDcaps.Play(cdrom, start, length));
  15.250 -}
  15.251 -
  15.252 -int
  15.253 -SDL_CDPlay(SDL_CD * cdrom, int sframe, int length)
  15.254 -{
  15.255 -    /* Check if the CD-ROM subsystem has been initialized */
  15.256 -    if (!CheckInit(1, &cdrom)) {
  15.257 -        return (CD_ERROR);
  15.258 -    }
  15.259 -
  15.260 -    return (SDL_CDcaps.Play(cdrom, sframe, length));
  15.261 -}
  15.262 -
  15.263 -int
  15.264 -SDL_CDPause(SDL_CD * cdrom)
  15.265 -{
  15.266 -    CDstatus status;
  15.267 -    int retval;
  15.268 -
  15.269 -    /* Check if the CD-ROM subsystem has been initialized */
  15.270 -    if (!CheckInit(1, &cdrom)) {
  15.271 -        return (CD_ERROR);
  15.272 -    }
  15.273 -
  15.274 -    status = SDL_CDcaps.Status(cdrom, NULL);
  15.275 -    switch (status) {
  15.276 -    case CD_PLAYING:
  15.277 -        retval = SDL_CDcaps.Pause(cdrom);
  15.278 -        break;
  15.279 -    default:
  15.280 -        retval = 0;
  15.281 -        break;
  15.282 -    }
  15.283 -    return (retval);
  15.284 -}
  15.285 -
  15.286 -int
  15.287 -SDL_CDResume(SDL_CD * cdrom)
  15.288 -{
  15.289 -    CDstatus status;
  15.290 -    int retval;
  15.291 -
  15.292 -    /* Check if the CD-ROM subsystem has been initialized */
  15.293 -    if (!CheckInit(1, &cdrom)) {
  15.294 -        return (CD_ERROR);
  15.295 -    }
  15.296 -
  15.297 -    status = SDL_CDcaps.Status(cdrom, NULL);
  15.298 -    switch (status) {
  15.299 -    case CD_PAUSED:
  15.300 -        retval = SDL_CDcaps.Resume(cdrom);
  15.301 -    default:
  15.302 -        retval = 0;
  15.303 -        break;
  15.304 -    }
  15.305 -    return (retval);
  15.306 -}
  15.307 -
  15.308 -int
  15.309 -SDL_CDStop(SDL_CD * cdrom)
  15.310 -{
  15.311 -    CDstatus status;
  15.312 -    int retval;
  15.313 -
  15.314 -    /* Check if the CD-ROM subsystem has been initialized */
  15.315 -    if (!CheckInit(1, &cdrom)) {
  15.316 -        return (CD_ERROR);
  15.317 -    }
  15.318 -
  15.319 -    status = SDL_CDcaps.Status(cdrom, NULL);
  15.320 -    switch (status) {
  15.321 -    case CD_PLAYING:
  15.322 -    case CD_PAUSED:
  15.323 -        retval = SDL_CDcaps.Stop(cdrom);
  15.324 -    default:
  15.325 -        retval = 0;
  15.326 -        break;
  15.327 -    }
  15.328 -    return (retval);
  15.329 -}
  15.330 -
  15.331 -int
  15.332 -SDL_CDEject(SDL_CD * cdrom)
  15.333 -{
  15.334 -    /* Check if the CD-ROM subsystem has been initialized */
  15.335 -    if (!CheckInit(1, &cdrom)) {
  15.336 -        return (CD_ERROR);
  15.337 -    }
  15.338 -    return (SDL_CDcaps.Eject(cdrom));
  15.339 -}
  15.340 -
  15.341 -void
  15.342 -SDL_CDClose(SDL_CD * cdrom)
  15.343 -{
  15.344 -    /* Check if the CD-ROM subsystem has been initialized */
  15.345 -    if (!CheckInit(1, &cdrom)) {
  15.346 -        return;
  15.347 -    }
  15.348 -    SDL_CDcaps.Close(cdrom);
  15.349 -    SDL_free(cdrom);
  15.350 -    default_cdrom = NULL;
  15.351 -}
  15.352 -
  15.353 -void
  15.354 -SDL_CDROMQuit(void)
  15.355 -{
  15.356 -    SDL_SYS_CDQuit();
  15.357 -    SDL_cdinitted = 0;
  15.358 -}
  15.359 -
  15.360 -/* vi: set ts=4 sw=4 expandtab: */
    16.1 --- a/src/cdrom/SDL_syscdrom.h	Sat Sep 05 09:03:35 2009 +0000
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,78 +0,0 @@
    16.4 -/*
    16.5 -    SDL - Simple DirectMedia Layer
    16.6 -    Copyright (C) 1997-2009 Sam Lantinga
    16.7 -
    16.8 -    This library is SDL_free software; you can redistribute it and/or
    16.9 -    modify it under the terms of the GNU Lesser General Public
   16.10 -    License as published by the Free Software Foundation; either
   16.11 -    version 2.1 of the License, or (at your option) any later version.
   16.12 -
   16.13 -    This library is distributed in the hope that it will be useful,
   16.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   16.16 -    Lesser General Public License for more details.
   16.17 -
   16.18 -    You should have received a copy of the GNU Lesser General Public
   16.19 -    License along with this library; if not, write to the Free Software
   16.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   16.21 -
   16.22 -    Sam Lantinga
   16.23 -    slouken@libsdl.org
   16.24 -*/
   16.25 -#include "SDL_config.h"
   16.26 -
   16.27 -/* This is the system specific header for the SDL CD-ROM API */
   16.28 -
   16.29 -/* Structure of CD audio control functions */
   16.30 -extern struct CDcaps
   16.31 -{
   16.32 -    /* Get the name of the specified drive */
   16.33 -    const char *(*Name) (int drive);
   16.34 -
   16.35 -    /* Open the specified drive, returning a drive id, or -1 on error */
   16.36 -    int (*Open) (int drive);
   16.37 -
   16.38 -    /* Get table-of-contents (number of tracks + track info) for disk.
   16.39 -       The TOC information should be stored in the cdrom structure.
   16.40 -       This function should return 0 on success, or -1 on error.
   16.41 -     */
   16.42 -    int (*GetTOC) (SDL_CD * cdrom);
   16.43 -
   16.44 -    /* Return the current status and play position, in frames, of the
   16.45 -       drive.  'position' may be NULL, and if so, should be ignored.
   16.46 -     */
   16.47 -      CDstatus(*Status) (SDL_CD * cdrom, int *position);
   16.48 -
   16.49 -    /* Play from frame 'start' to 'start+len' */
   16.50 -    int (*Play) (SDL_CD * cdrom, int start, int len);
   16.51 -
   16.52 -    /* Pause play */
   16.53 -    int (*Pause) (SDL_CD * cdrom);
   16.54 -
   16.55 -    /* Resume play */
   16.56 -    int (*Resume) (SDL_CD * cdrom);
   16.57 -
   16.58 -    /* Stop play */
   16.59 -    int (*Stop) (SDL_CD * cdrom);
   16.60 -
   16.61 -    /* Eject the current disk */
   16.62 -    int (*Eject) (SDL_CD * cdrom);
   16.63 -
   16.64 -    /* Close the specified drive */
   16.65 -    void (*Close) (SDL_CD * cdrom);
   16.66 -} SDL_CDcaps;
   16.67 -
   16.68 -/* The number of available CD-ROM drives on the system */
   16.69 -extern int SDL_numcds;
   16.70 -
   16.71 -/* Function to scan the system for CD-ROM drives and fill SDL_CDcaps.
   16.72 - * This function should set SDL_numcds to the number of available CD
   16.73 - * drives.  Drive 0 should be the system default CD-ROM.
   16.74 - * It should return 0, or -1 on an unrecoverable fatal error.
   16.75 -*/
   16.76 -extern int SDL_SYS_CDInit(void);
   16.77 -
   16.78 -/* Function to perform any system-specific CD-ROM related cleanup */
   16.79 -extern void SDL_SYS_CDQuit(void);
   16.80 -
   16.81 -/* vi: set ts=4 sw=4 expandtab: */
    17.1 --- a/src/cdrom/aix/SDL_syscdrom.c	Sat Sep 05 09:03:35 2009 +0000
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,665 +0,0 @@
    17.4 -/*
    17.5 -    SDL - Simple DirectMedia Layer
    17.6 -    Copyright (C) 1997-2009 Sam Lantinga
    17.7 -
    17.8 -    This library is free software; you can redistribute it and/or
    17.9 -    modify it under the terms of the GNU Lesser General Public
   17.10 -    License as published by the Free Software Foundation; either
   17.11 -    version 2.1 of the License, or (at your option) any later version.
   17.12 -
   17.13 -    This library is distributed in the hope that it will be useful,
   17.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   17.16 -    Lesser General Public License for more details.
   17.17 -
   17.18 -    You should have received a copy of the GNU Lesser General Public
   17.19 -    License along with this library; if not, write to the Free Software
   17.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   17.21 -
   17.22 -    Carsten Griwodz
   17.23 -    griff@kom.tu-darmstadt.de
   17.24 -
   17.25 -    based on linux/SDL_syscdrom.c by Sam Lantinga
   17.26 -*/
   17.27 -#include "SDL_config.h"
   17.28 -
   17.29 -#ifdef SDL_CDROM_AIX
   17.30 -
   17.31 -/* Functions for system-level CD-ROM audio control */
   17.32 -
   17.33 -/*#define DEBUG_CDROM 1*/
   17.34 -
   17.35 -#include <sys/types.h>
   17.36 -#include <sys/stat.h>
   17.37 -#include <fcntl.h>
   17.38 -#include <errno.h>
   17.39 -#include <unistd.h>
   17.40 -
   17.41 -#include <sys/ioctl.h>
   17.42 -#include <sys/devinfo.h>
   17.43 -#include <sys/mntctl.h>
   17.44 -#include <sys/statfs.h>
   17.45 -#include <sys/vmount.h>
   17.46 -#include <fstab.h>
   17.47 -#include <sys/scdisk.h>
   17.48 -
   17.49 -#include "SDL_cdrom.h"
   17.50 -#include "../SDL_syscdrom.h"
   17.51 -
   17.52 -/* The maximum number of CD-ROM drives we'll detect */
   17.53 -#define MAX_DRIVES	16
   17.54 -
   17.55 -/* A list of available CD-ROM drives */
   17.56 -static char *SDL_cdlist[MAX_DRIVES];
   17.57 -static dev_t SDL_cdmode[MAX_DRIVES];
   17.58 -
   17.59 -/* The system-dependent CD control functions */
   17.60 -static const char *SDL_SYS_CDName(int drive);
   17.61 -static int SDL_SYS_CDOpen(int drive);
   17.62 -static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
   17.63 -static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
   17.64 -static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
   17.65 -static int SDL_SYS_CDPause(SDL_CD * cdrom);
   17.66 -static int SDL_SYS_CDResume(SDL_CD * cdrom);
   17.67 -static int SDL_SYS_CDStop(SDL_CD * cdrom);
   17.68 -static int SDL_SYS_CDEject(SDL_CD * cdrom);
   17.69 -static void SDL_SYS_CDClose(SDL_CD * cdrom);
   17.70 -static int SDL_SYS_CDioctl(int id, int command, void *arg);
   17.71 -
   17.72 -/* Check a drive to see if it is a CD-ROM */
   17.73 -static int
   17.74 -CheckDrive(char *drive, struct stat *stbuf)
   17.75 -{
   17.76 -    int is_cd;
   17.77 -    int cdfd;
   17.78 -    int ret;
   17.79 -    struct devinfo info;
   17.80 -
   17.81 -    /* If it doesn't exist, return -1 */
   17.82 -    if (stat(drive, stbuf) < 0) {
   17.83 -        return -1;
   17.84 -    }
   17.85 -
   17.86 -    /* If it does exist, verify that it's an available CD-ROM */
   17.87 -    is_cd = 0;
   17.88 -    if (S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode)) {
   17.89 -        cdfd = open(drive, (O_RDONLY | O_EXCL | O_NONBLOCK), 0);
   17.90 -        if (cdfd >= 0) {
   17.91 -            ret = SDL_SYS_CDioctl(cdfd, IOCINFO, &info);
   17.92 -            if (ret < 0) {
   17.93 -                /* Some kind of error */
   17.94 -                is_cd = 0;
   17.95 -            } else {
   17.96 -                if (info.devtype == DD_CDROM) {
   17.97 -                    is_cd = 1;
   17.98 -                } else {
   17.99 -                    is_cd = 0;
  17.100 -                }
  17.101 -            }
  17.102 -            close(cdfd);
  17.103 -        }
  17.104 -#ifdef DEBUG_CDROM
  17.105 -        else {
  17.106 -            fprintf(stderr, "Could not open drive %s (%s)\n", drive,
  17.107 -                    strerror(errno));
  17.108 -        }
  17.109 -#endif
  17.110 -    }
  17.111 -    return is_cd;
  17.112 -}
  17.113 -
  17.114 -/* Add a CD-ROM drive to our list of valid drives */
  17.115 -static void
  17.116 -AddDrive(char *drive, struct stat *stbuf)
  17.117 -{
  17.118 -    int i;
  17.119 -
  17.120 -    if (SDL_numcds < MAX_DRIVES) {
  17.121 -        /* Check to make sure it's not already in our list.
  17.122 -           This can happen when we see a drive via symbolic link.
  17.123 -         */
  17.124 -        for (i = 0; i < SDL_numcds; ++i) {
  17.125 -            if (stbuf->st_rdev == SDL_cdmode[i]) {
  17.126 -#ifdef DEBUG_CDROM
  17.127 -                fprintf(stderr, "Duplicate drive detected: %s == %s\n",
  17.128 -                        drive, SDL_cdlist[i]);
  17.129 -#endif
  17.130 -                return;
  17.131 -            }
  17.132 -        }
  17.133 -
  17.134 -        /* Add this drive to our list */
  17.135 -        i = SDL_numcds;
  17.136 -        SDL_cdlist[i] = SDL_strdup(drive);
  17.137 -        if (SDL_cdlist[i] == NULL) {
  17.138 -            SDL_OutOfMemory();
  17.139 -            return;
  17.140 -        }
  17.141 -        SDL_cdmode[i] = stbuf->st_rdev;
  17.142 -        ++SDL_numcds;
  17.143 -#ifdef DEBUG_CDROM
  17.144 -        fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
  17.145 -#endif
  17.146 -    }
  17.147 -}
  17.148 -
  17.149 -static void
  17.150 -CheckMounts()
  17.151 -{
  17.152 -    char *buffer;
  17.153 -    int bufsz;
  17.154 -    struct vmount *ptr;
  17.155 -    int ret;
  17.156 -
  17.157 -    buffer = (char *) SDL_malloc(10);
  17.158 -    bufsz = 10;
  17.159 -    if (buffer == NULL) {
  17.160 -        fprintf(stderr,
  17.161 -                "Could not allocate 10 bytes in aix/SDL_syscdrom.c:CheckMounts\n");
  17.162 -        exit(-10);
  17.163 -    }
  17.164 -
  17.165 -    do {
  17.166 -        /* mntctrl() returns an array of all mounted filesystems */
  17.167 -        ret = mntctl(MCTL_QUERY, bufsz, buffer);
  17.168 -        if (ret == 0) {
  17.169 -            /* Buffer was too small, realloc.    */
  17.170 -            bufsz = *(int *) buffer;    /* Required size is in first word.   */
  17.171 -            /* (whatever a word is in AIX 4.3.3) */
  17.172 -            /* int seems to be OK in 32bit mode. */
  17.173 -            SDL_free(buffer);
  17.174 -            buffer = (char *) SDL_malloc(bufsz);
  17.175 -            if (buffer == NULL) {
  17.176 -                fprintf(stderr,
  17.177 -                        "Could not allocate %d bytes in aix/SDL_syscdrom.c:CheckMounts\n",
  17.178 -                        bufsz);
  17.179 -                exit(-10);
  17.180 -            }
  17.181 -        } else if (ret < 0) {
  17.182 -#ifdef DEBUG_CDROM
  17.183 -            fprintf(stderr, "Error reading vmount structures\n");
  17.184 -#endif
  17.185 -            return;
  17.186 -        }
  17.187 -    } while (ret == 0);
  17.188 -
  17.189 -#ifdef DEBUG_CDROM
  17.190 -    fprintf(stderr, "Read %d vmount structures\n", ret);
  17.191 -#endif
  17.192 -    ptr = (struct vmount *) buffer;
  17.193 -    do {
  17.194 -        switch (ptr->vmt_gfstype) {
  17.195 -        case MNT_CDROM:
  17.196 -            {
  17.197 -                struct stat stbuf;
  17.198 -                char *text;
  17.199 -
  17.200 -                text = (char *) ptr + ptr->vmt_data[VMT_OBJECT].vmt_off;
  17.201 -#ifdef DEBUG_CDROM
  17.202 -                fprintf(stderr,
  17.203 -                        "Checking mount path: %s mounted on %s\n", text,
  17.204 -                        (char *) ptr + ptr->vmt_data[VMT_STUB].vmt_off);
  17.205 -#endif
  17.206 -                if (CheckDrive(text, &stbuf) > 0) {
  17.207 -                    AddDrive(text, &stbuf);
  17.208 -                }
  17.209 -            }
  17.210 -            break;
  17.211 -        default:
  17.212 -            break;
  17.213 -        }
  17.214 -        ptr = (struct vmount *) ((char *) ptr + ptr->vmt_length);
  17.215 -        ret--;
  17.216 -    } while (ret > 0);
  17.217 -
  17.218 -    free(buffer);
  17.219 -}
  17.220 -
  17.221 -static int
  17.222 -CheckNonmounts()
  17.223 -{
  17.224 -#ifdef _THREAD_SAFE
  17.225 -    AFILE_t fsFile = NULL;
  17.226 -    int passNo = 0;
  17.227 -    int ret;
  17.228 -    struct fstab entry;
  17.229 -    struct stat stbuf;
  17.230 -
  17.231 -    ret = setfsent_r(&fsFile, &passNo);
  17.232 -    if (ret != 0)
  17.233 -        return -1;
  17.234 -    do {
  17.235 -        ret = getfsent_r(&entry, &fsFile, &passNo);
  17.236 -        if (ret == 0) {
  17.237 -            char *l = SDL_strrchr(entry.fs_spec, '/');
  17.238 -            if (l != NULL) {
  17.239 -                if (!SDL_strncmp("cd", ++l, 2)) {
  17.240 -#ifdef DEBUG_CDROM
  17.241 -                    fprintf(stderr,
  17.242 -                            "Found unmounted CD ROM drive with device name %s\n",
  17.243 -                            entry.fs_spec);
  17.244 -#endif
  17.245 -                    if (CheckDrive(entry.fs_spec, &stbuf) > 0) {
  17.246 -                        AddDrive(entry.fs_spec, &stbuf);
  17.247 -                    }
  17.248 -                }
  17.249 -            }
  17.250 -        }
  17.251 -    } while (ret == 0);
  17.252 -    ret = endfsent_r(&fsFile);
  17.253 -    if (ret != 0)
  17.254 -        return -1;
  17.255 -    return 0;
  17.256 -#else
  17.257 -    struct fstab *entry;
  17.258 -    struct stat stbuf;
  17.259 -
  17.260 -    setfsent();
  17.261 -    do {
  17.262 -        entry = getfsent();
  17.263 -        if (entry != NULL) {
  17.264 -            char *l = SDL_strrchr(entry->fs_spec, '/');
  17.265 -            if (l != NULL) {
  17.266 -                if (!SDL_strncmp("cd", ++l, 2)) {
  17.267 -#ifdef DEBUG_CDROM
  17.268 -                    fprintf(stderr,
  17.269 -                            "Found unmounted CD ROM drive with device name %s",
  17.270 -                            entry->fs_spec);
  17.271 -#endif
  17.272 -                    if (CheckDrive(entry->fs_spec, &stbuf) > 0) {
  17.273 -                        AddDrive(entry->fs_spec, &stbuf);
  17.274 -                    }
  17.275 -                }
  17.276 -            }
  17.277 -        }
  17.278 -    } while (entry != NULL);
  17.279 -    endfsent();
  17.280 -#endif
  17.281 -}
  17.282 -
  17.283 -int
  17.284 -SDL_SYS_CDInit(void)
  17.285 -{
  17.286 -    char *SDLcdrom;
  17.287 -    struct stat stbuf;
  17.288 -
  17.289 -    /* Fill in our driver capabilities */
  17.290 -    SDL_CDcaps.Name = SDL_SYS_CDName;
  17.291 -    SDL_CDcaps.Open = SDL_SYS_CDOpen;
  17.292 -    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
  17.293 -    SDL_CDcaps.Status = SDL_SYS_CDStatus;
  17.294 -    SDL_CDcaps.Play = SDL_SYS_CDPlay;
  17.295 -    SDL_CDcaps.Pause = SDL_SYS_CDPause;
  17.296 -    SDL_CDcaps.Resume = SDL_SYS_CDResume;
  17.297 -    SDL_CDcaps.Stop = SDL_SYS_CDStop;
  17.298 -    SDL_CDcaps.Eject = SDL_SYS_CDEject;
  17.299 -    SDL_CDcaps.Close = SDL_SYS_CDClose;
  17.300 -
  17.301 -    /* Look in the environment for our CD-ROM drive list */
  17.302 -    SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
  17.303 -    if (SDLcdrom != NULL) {
  17.304 -        char *cdpath, *delim;
  17.305 -        size_t len = SDL_strlen(SDLcdrom) + 1;
  17.306 -        cdpath = SDL_stack_alloc(char, len);
  17.307 -        if (cdpath != NULL) {
  17.308 -            SDL_strlcpy(cdpath, SDLcdrom, len);
  17.309 -            SDLcdrom = cdpath;
  17.310 -            do {
  17.311 -                delim = SDL_strchr(SDLcdrom, ':');
  17.312 -                if (delim) {
  17.313 -                    *delim++ = '\0';
  17.314 -                }
  17.315 -#ifdef DEBUG_CDROM
  17.316 -                fprintf(stderr,
  17.317 -                        "Checking CD-ROM drive from SDL_CDROM: %s\n",
  17.318 -                        SDLcdrom);
  17.319 -#endif
  17.320 -                if (CheckDrive(SDLcdrom, &stbuf) > 0) {
  17.321 -                    AddDrive(SDLcdrom, &stbuf);
  17.322 -                }
  17.323 -                if (delim) {
  17.324 -                    SDLcdrom = delim;
  17.325 -                } else {
  17.326 -                    SDLcdrom = NULL;
  17.327 -                }
  17.328 -            } while (SDLcdrom);
  17.329 -            SDL_stack_free(cdpath);
  17.330 -        }
  17.331 -
  17.332 -        /* If we found our drives, there's nothing left to do */
  17.333 -        if (SDL_numcds > 0) {
  17.334 -            return (0);
  17.335 -        }
  17.336 -    }
  17.337 -
  17.338 -    CheckMounts();
  17.339 -    CheckNonmounts();
  17.340 -
  17.341 -    return 0;
  17.342 -}
  17.343 -
  17.344 -/* General ioctl() CD-ROM command function */
  17.345 -static int
  17.346 -SDL_SYS_CDioctl(int id, int command, void *arg)
  17.347 -{
  17.348 -    int retval;
  17.349 -
  17.350 -    retval = ioctl(id, command, arg);
  17.351 -    if (retval < 0) {
  17.352 -        SDL_SetError("ioctl() error: %s", strerror(errno));
  17.353 -    }
  17.354 -    return retval;
  17.355 -}
  17.356 -
  17.357 -static const char *
  17.358 -SDL_SYS_CDName(int drive)
  17.359 -{
  17.360 -    return (SDL_cdlist[drive]);
  17.361 -}
  17.362 -
  17.363 -static int
  17.364 -SDL_SYS_CDOpen(int drive)
  17.365 -{
  17.366 -    int fd;
  17.367 -    char *lastsl;
  17.368 -    char *cdromname;
  17.369 -    size_t len;
  17.370 -
  17.371 -    /*
  17.372 -     * We found /dev/cd? drives and that is in our list. But we can
  17.373 -     * open only the /dev/rcd? versions of those devices for Audio CD.
  17.374 -     */
  17.375 -    len = SDL_strlen(SDL_cdlist[drive]) + 2;
  17.376 -    cdromname = (char *) SDL_malloc(len);
  17.377 -    SDL_strlcpy(cdromname, SDL_cdlist[drive], len);
  17.378 -    lastsl = SDL_strrchr(cdromname, '/');
  17.379 -    if (lastsl) {
  17.380 -        *lastsl = 0;
  17.381 -        SDL_strlcat(cdromname, "/r", len);
  17.382 -        lastsl = SDL_strrchr(SDL_cdlist[drive], '/');
  17.383 -        if (lastsl) {
  17.384 -            lastsl++;
  17.385 -            SDL_strlcat(cdromname, lastsl, len);
  17.386 -        }
  17.387 -    }
  17.388 -#ifdef DEBUG_CDROM
  17.389 -    fprintf(stderr, "Should open drive %s, opening %s\n", SDL_cdlist[drive],
  17.390 -            cdromname);
  17.391 -#endif
  17.392 -
  17.393 -    /*
  17.394 -     * Use exclusive access. Don't use SC_DIAGNOSTICS as xmcd does because they
  17.395 -     * require root priviledges, and we don't want that. SC_SINGLE provides
  17.396 -     * exclusive access with less trouble.
  17.397 -     */
  17.398 -    fd = openx(cdromname, O_RDONLY, NULL, SC_SINGLE);
  17.399 -    if (fd < 0) {
  17.400 -#ifdef DEBUG_CDROM
  17.401 -        fprintf(stderr, "Could not open drive %s (%s)\n", cdromname,
  17.402 -                strerror(errno));
  17.403 -#endif
  17.404 -    } else {
  17.405 -        struct mode_form_op cdMode;
  17.406 -        int ret;
  17.407 -#ifdef DEBUG_CDROM
  17.408 -        cdMode.action = CD_GET_MODE;
  17.409 -        ret = SDL_SYS_CDioctl(fd, DK_CD_MODE, &cdMode);
  17.410 -        if (ret < 0) {
  17.411 -            fprintf(stderr,
  17.412 -                    "Could not get drive mode for %s (%s)\n",
  17.413 -                    cdromname, strerror(errno));
  17.414 -        } else {
  17.415 -            switch (cdMode.cd_mode_form) {
  17.416 -            case CD_MODE1:
  17.417 -                fprintf(stderr,
  17.418 -                        "Drive mode for %s is %s\n",
  17.419 -                        cdromname, "CD-ROM Data Mode 1");
  17.420 -                break;
  17.421 -            case CD_MODE2_FORM1:
  17.422 -                fprintf(stderr,
  17.423 -                        "Drive mode for %s is %s\n",
  17.424 -                        cdromname, "CD-ROM XA Data Mode 2 Form 1");
  17.425 -                break;
  17.426 -            case CD_MODE2_FORM2:
  17.427 -                fprintf(stderr,
  17.428 -                        "Drive mode for %s is %s\n",
  17.429 -                        cdromname, "CD-ROM XA Data Mode 2 Form 2");
  17.430 -                break;
  17.431 -            case CD_DA:
  17.432 -                fprintf(stderr,
  17.433 -                        "Drive mode for %s is %s\n", cdromname, "CD-DA");
  17.434 -                break;
  17.435 -            default:
  17.436 -                fprintf(stderr,
  17.437 -                        "Drive mode for %s is %s\n", cdromname, "unknown");
  17.438 -                break;
  17.439 -            }
  17.440 -        }
  17.441 -#endif
  17.442 -
  17.443 -        cdMode.action = CD_CHG_MODE;
  17.444 -        cdMode.cd_mode_form = CD_DA;
  17.445 -        ret = SDL_SYS_CDioctl(fd, DK_CD_MODE, &cdMode);
  17.446 -        if (ret < 0) {
  17.447 -#ifdef DEBUG_CDROM
  17.448 -            fprintf(stderr,
  17.449 -                    "Could not set drive mode for %s (%s)\n",
  17.450 -                    cdromname, strerror(errno));
  17.451 -#endif
  17.452 -            SDL_SetError
  17.453 -                ("ioctl() error: Could not set CD drive mode, %s",
  17.454 -                 strerror(errno));
  17.455 -        } else {
  17.456 -#ifdef DEBUG_CDROM
  17.457 -            fprintf(stderr, "Drive mode for %s set to CD_DA\n", cdromname);
  17.458 -#endif
  17.459 -        }
  17.460 -    }
  17.461 -    SDL_free(cdromname);
  17.462 -    return fd;
  17.463 -}
  17.464 -
  17.465 -static int
  17.466 -SDL_SYS_CDGetTOC(SDL_CD * cdrom)
  17.467 -{
  17.468 -    struct cd_audio_cmd cmd;
  17.469 -    struct cd_audio_cmd entry;
  17.470 -    int i;
  17.471 -    int okay;
  17.472 -
  17.473 -    cmd.audio_cmds = CD_TRK_INFO_AUDIO;
  17.474 -    cmd.msf_flag = FALSE;
  17.475 -    if (SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd) < 0) {
  17.476 -        return -1;
  17.477 -    }
  17.478 -
  17.479 -    okay = 0;
  17.480 -    cdrom->numtracks = cmd.indexing.track_index.last_track
  17.481 -        - cmd.indexing.track_index.first_track + 1;
  17.482 -    if (cdrom->numtracks > SDL_MAX_TRACKS) {
  17.483 -        cdrom->numtracks = SDL_MAX_TRACKS;
  17.484 -    }
  17.485 -
  17.486 -    /* Read all the track TOC entries */
  17.487 -    for (i = 0; i <= cdrom->numtracks; ++i) {
  17.488 -        if (i == cdrom->numtracks) {
  17.489 -            cdrom->track[i].id = 0xAA;;
  17.490 -        } else {
  17.491 -            cdrom->track[i].id = cmd.indexing.track_index.first_track + i;
  17.492 -        }
  17.493 -        entry.audio_cmds = CD_GET_TRK_MSF;
  17.494 -        entry.indexing.track_msf.track = cdrom->track[i].id;
  17.495 -        if (SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &entry) < 0) {
  17.496 -            break;
  17.497 -        } else {
  17.498 -            cdrom->track[i].type = 0;   /* don't know how to detect 0x04 data track */
  17.499 -            cdrom->track[i].offset =
  17.500 -                MSF_TO_FRAMES(entry.indexing.track_msf.mins,
  17.501 -                              entry.indexing.track_msf.secs,
  17.502 -                              entry.indexing.track_msf.frames);
  17.503 -            cdrom->track[i].length = 0;
  17.504 -            if (i > 0) {
  17.505 -                cdrom->track[i - 1].length = cdrom->track[i].offset
  17.506 -                    - cdrom->track[i - 1].offset;
  17.507 -            }
  17.508 -        }
  17.509 -    }
  17.510 -    if (i == (cdrom->numtracks + 1)) {
  17.511 -        okay = 1;
  17.512 -    }
  17.513 -    return (okay ? 0 : -1);
  17.514 -}
  17.515 -
  17.516 -/* Get CD-ROM status */
  17.517 -static CDstatus
  17.518 -SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
  17.519 -{
  17.520 -    CDstatus status;
  17.521 -    struct cd_audio_cmd cmd;
  17.522 -    cmd.audio_cmds = CD_INFO_AUDIO;
  17.523 -
  17.524 -    if (SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd) < 0) {
  17.525 -#ifdef DEBUG_CDROM
  17.526 -        fprintf(stderr, "ioctl failed in SDL_SYS_CDStatus (%s)\n",
  17.527 -                SDL_GetError());
  17.528 -#endif
  17.529 -        status = CD_ERROR;
  17.530 -    } else {
  17.531 -        switch (cmd.status) {
  17.532 -        case CD_NO_AUDIO:
  17.533 -        case CD_COMPLETED:
  17.534 -            status = CD_STOPPED;
  17.535 -            break;
  17.536 -        case CD_PLAY_AUDIO:
  17.537 -            status = CD_PLAYING;
  17.538 -            break;
  17.539 -        case CD_PAUSE_AUDIO:
  17.540 -            status = CD_PAUSED;
  17.541 -            break;
  17.542 -        case CD_NOT_VALID:
  17.543 -#ifdef DEBUG_CDROM
  17.544 -            fprintf(stderr, "cdStatus failed with CD_NOT_VALID\n");
  17.545 -#endif
  17.546 -            status = CD_ERROR;
  17.547 -            break;
  17.548 -        case CD_STATUS_ERROR:
  17.549 -#ifdef DEBUG_CDROM
  17.550 -            fprintf(stderr, "cdStatus failed with CD_STATUS_ERROR\n");
  17.551 -#endif
  17.552 -            status = CD_ERROR;
  17.553 -            break;
  17.554 -        default:
  17.555 -#ifdef DEBUG_CDROM
  17.556 -            fprintf(stderr, "cdStatus failed with unknown error\n");
  17.557 -#endif
  17.558 -            status = CD_ERROR;
  17.559 -            break;
  17.560 -        }
  17.561 -    }
  17.562 -    if (position) {
  17.563 -        if (status == CD_PLAYING || (status == CD_PAUSED)) {
  17.564 -            *position =
  17.565 -                MSF_TO_FRAMES(cmd.indexing.info_audio.current_mins,
  17.566 -                              cmd.indexing.info_audio.current_secs,
  17.567 -                              cmd.indexing.info_audio.current_frames);
  17.568 -        } else {
  17.569 -            *position = 0;
  17.570 -        }
  17.571 -    }
  17.572 -    return status;
  17.573 -}
  17.574 -
  17.575 -/* Start play */
  17.576 -static int
  17.577 -SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
  17.578 -{
  17.579 -    struct cd_audio_cmd cmd;
  17.580 -
  17.581 -    /*
  17.582 -     * My CD Rom is muted by default. I think I read that this is new with
  17.583 -     * AIX 4.3. SDL does not change the volume, so I need a kludge. Maybe
  17.584 -     * its better to do this elsewhere?
  17.585 -     */
  17.586 -    cmd.audio_cmds = CD_PLAY_AUDIO | CD_SET_VOLUME;
  17.587 -    cmd.msf_flag = TRUE;
  17.588 -    FRAMES_TO_MSF(start,
  17.589 -                  &cmd.indexing.msf.first_mins,
  17.590 -                  &cmd.indexing.msf.first_secs,
  17.591 -                  &cmd.indexing.msf.first_frames);
  17.592 -    FRAMES_TO_MSF(start + length,
  17.593 -                  &cmd.indexing.msf.last_mins,
  17.594 -                  &cmd.indexing.msf.last_secs, &cmd.indexing.msf.last_frames);
  17.595 -    cmd.volume_type = CD_VOLUME_ALL;
  17.596 -    cmd.all_channel_vol = 255;  /* This is a uchar. What is a good value? No docu! */
  17.597 -    cmd.out_port_0_sel = CD_AUDIO_CHNL_0;
  17.598 -    cmd.out_port_1_sel = CD_AUDIO_CHNL_1;
  17.599 -    cmd.out_port_2_sel = CD_AUDIO_CHNL_2;
  17.600 -    cmd.out_port_3_sel = CD_AUDIO_CHNL_3;
  17.601 -
  17.602 -#ifdef DEBUG_CDROM
  17.603 -    fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
  17.604 -            cmd.indexing.msf.first_mins,
  17.605 -            cmd.indexing.msf.first_secs,
  17.606 -            cmd.indexing.msf.first_frames,
  17.607 -            cmd.indexing.msf.last_mins,
  17.608 -            cmd.indexing.msf.last_secs, cmd.indexing.msf.last_frames);
  17.609 -#endif
  17.610 -    return (SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd));
  17.611 -}
  17.612 -
  17.613 -/* Pause play */
  17.614 -static int
  17.615 -SDL_SYS_CDPause(SDL_CD * cdrom)
  17.616 -{
  17.617 -    struct cd_audio_cmd cmd;
  17.618 -    cmd.audio_cmds = CD_PAUSE_AUDIO;
  17.619 -    return (SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd));
  17.620 -}
  17.621 -
  17.622 -/* Resume play */
  17.623 -static int
  17.624 -SDL_SYS_CDResume(SDL_CD * cdrom)
  17.625 -{
  17.626 -    struct cd_audio_cmd cmd;
  17.627 -    cmd.audio_cmds = CD_RESUME_AUDIO;
  17.628 -    return (SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd));
  17.629 -}
  17.630 -
  17.631 -/* Stop play */
  17.632 -static int
  17.633 -SDL_SYS_CDStop(SDL_CD * cdrom)
  17.634 -{
  17.635 -    struct cd_audio_cmd cmd;
  17.636 -    cmd.audio_cmds = CD_STOP_AUDIO;
  17.637 -    return (SDL_SYS_CDioctl(cdrom->id, DKAUDIO, &cmd));
  17.638 -}
  17.639 -
  17.640 -/* Eject the CD-ROM */
  17.641 -static int
  17.642 -SDL_SYS_CDEject(SDL_CD * cdrom)
  17.643 -{
  17.644 -    return (SDL_SYS_CDioctl(cdrom->id, DKEJECT, 0));
  17.645 -}
  17.646 -
  17.647 -/* Close the CD-ROM handle */
  17.648 -static void
  17.649 -SDL_SYS_CDClose(SDL_CD * cdrom)
  17.650 -{
  17.651 -    close(cdrom->id);
  17.652 -}
  17.653 -
  17.654 -void
  17.655 -SDL_SYS_CDQuit(void)
  17.656 -{
  17.657 -    int i;
  17.658 -
  17.659 -    if (SDL_numcds > 0) {
  17.660 -        for (i = 0; i < SDL_numcds; ++i) {
  17.661 -            SDL_free(SDL_cdlist[i]);
  17.662 -        }
  17.663 -        SDL_numcds = 0;
  17.664 -    }
  17.665 -}
  17.666 -
  17.667 -#endif /* SDL_CDROM_AIX */
  17.668 -/* vi: set ts=4 sw=4 expandtab: */
    18.1 --- a/src/cdrom/beos/SDL_syscdrom.cc	Sat Sep 05 09:03:35 2009 +0000
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,427 +0,0 @@
    18.4 -/*
    18.5 -    SDL - Simple DirectMedia Layer
    18.6 -    Copyright (C) 1997-2009 Sam Lantinga
    18.7 -
    18.8 -    This library is free software; you can redistribute it and/or
    18.9 -    modify it under the terms of the GNU Lesser General Public
   18.10 -    License as published by the Free Software Foundation; either
   18.11 -    version 2.1 of the License, or (at your option) any later version.
   18.12 -
   18.13 -    This library is distributed in the hope that it will be useful,
   18.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   18.16 -    Lesser General Public License for more details.
   18.17 -
   18.18 -    You should have received a copy of the GNU Lesser General Public
   18.19 -    License along with this library; if not, write to the Free Software
   18.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   18.21 -
   18.22 -    Sam Lantinga
   18.23 -    slouken@libsdl.org
   18.24 -*/
   18.25 -#include "SDL_config.h"
   18.26 -
   18.27 -#ifdef SDL_CDROM_BEOS
   18.28 -
   18.29 -/* Functions for system-level CD-ROM audio control on BeOS
   18.30 -   (not completely implemented yet)
   18.31 - */
   18.32 -
   18.33 -#include <sys/types.h>
   18.34 -#include <sys/stat.h>
   18.35 -#include <unistd.h>
   18.36 -
   18.37 -#include <scsi.h>
   18.38 -#include <Directory.h>
   18.39 -#include <Entry.h>
   18.40 -#include <Path.h>
   18.41 -
   18.42 -#include "SDL_cdrom.h"
   18.43 -extern "C"
   18.44 -{
   18.45 -#include "../SDL_syscdrom.h"
   18.46 -}
   18.47 -
   18.48 -/* Constants to help us get at the SCSI table-of-contents info */
   18.49 -#define CD_NUMTRACKS(toc)	toc.toc_data[3]
   18.50 -#define CD_TRACK(toc, track)	(&toc.toc_data[6+(track)*8])
   18.51 -#define CD_TRACK_N(toc, track)	CD_TRACK(toc, track)[0]
   18.52 -#define CD_TRACK_M(toc, track)	CD_TRACK(toc, track)[3]
   18.53 -#define CD_TRACK_S(toc, track)	CD_TRACK(toc, track)[4]
   18.54 -#define CD_TRACK_F(toc, track)	CD_TRACK(toc, track)[5]
   18.55 -
   18.56 -/* Constants to help us get at the SCSI position info */
   18.57 -#define POS_TRACK(pos)	pos.position[6]
   18.58 -#define POS_ABS_M(pos)	pos.position[9]
   18.59 -#define POS_ABS_S(pos)	pos.position[10]
   18.60 -#define POS_ABS_F(pos)	pos.position[11]
   18.61 -#define POS_REL_M(pos)	pos.position[13]
   18.62 -#define POS_REL_S(pos)	pos.position[14]
   18.63 -#define POS_REL_F(pos)	pos.position[15]
   18.64 -
   18.65 -/* The maximum number of CD-ROM drives we'll detect */
   18.66 -#define MAX_DRIVES	16
   18.67 -
   18.68 -/* A list of available CD-ROM drives */
   18.69 -static char *SDL_cdlist[MAX_DRIVES];
   18.70 -
   18.71 -/* The system-dependent CD control functions */
   18.72 -static const char *SDL_SYS_CDName(int drive);
   18.73 -static int SDL_SYS_CDOpen(int drive);
   18.74 -static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
   18.75 -static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
   18.76 -static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
   18.77 -static int SDL_SYS_CDPause(SDL_CD * cdrom);
   18.78 -static int SDL_SYS_CDResume(SDL_CD * cdrom);
   18.79 -static int SDL_SYS_CDStop(SDL_CD * cdrom);
   18.80 -static int SDL_SYS_CDEject(SDL_CD * cdrom);
   18.81 -static void SDL_SYS_CDClose(SDL_CD * cdrom);
   18.82 -int try_dir(const char *directory);
   18.83 -
   18.84 -
   18.85 -/* Check a drive to see if it is a CD-ROM */
   18.86 -static int
   18.87 -CheckDrive(char *drive)
   18.88 -{
   18.89 -    struct stat stbuf;
   18.90 -    int is_cd, cdfd;
   18.91 -    device_geometry info;
   18.92 -
   18.93 -    /* If it doesn't exist, return -1 */
   18.94 -    if (stat(drive, &stbuf) < 0) {
   18.95 -        return (-1);
   18.96 -    }
   18.97 -
   18.98 -    /* If it does exist, verify that it's an available CD-ROM */
   18.99 -    is_cd = 0;
  18.100 -    cdfd = open(drive, 0);
  18.101 -    if (cdfd >= 0) {
  18.102 -        if (ioctl(cdfd, B_GET_GEOMETRY, &info) == B_NO_ERROR) {
  18.103 -            if (info.device_type == B_CD) {
  18.104 -                is_cd = 1;
  18.105 -            }
  18.106 -        }
  18.107 -        close(cdfd);
  18.108 -    } else {
  18.109 -        /* This can happen when the drive is open .. (?) */ ;
  18.110 -        is_cd = 1;
  18.111 -    }
  18.112 -    return (is_cd);
  18.113 -}
  18.114 -
  18.115 -/* Add a CD-ROM drive to our list of valid drives */
  18.116 -static void
  18.117 -AddDrive(char *drive)
  18.118 -{
  18.119 -    int i;
  18.120 -    size_t len;
  18.121 -
  18.122 -    if (SDL_numcds < MAX_DRIVES) {
  18.123 -        /* Add this drive to our list */
  18.124 -        i = SDL_numcds;
  18.125 -        len = SDL_strlen(drive) + 1;
  18.126 -        SDL_cdlist[i] = (char *) SDL_malloc(len);
  18.127 -        if (SDL_cdlist[i] == NULL) {
  18.128 -            SDL_OutOfMemory();
  18.129 -            return;
  18.130 -        }
  18.131 -        SDL_strlcpy(SDL_cdlist[i], drive, len);
  18.132 -        ++SDL_numcds;
  18.133 -#ifdef CDROM_DEBUG
  18.134 -        fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
  18.135 -#endif
  18.136 -    }
  18.137 -}
  18.138 -
  18.139 -/* IDE bus scanning magic */
  18.140 -enum
  18.141 -{
  18.142 -    IDE_GET_DEVICES_INFO = B_DEVICE_OP_CODES_END + 50,
  18.143 -};
  18.144 -struct ide_ctrl_info
  18.145 -{
  18.146 -    bool ide_0_present;
  18.147 -    bool ide_0_master_present;
  18.148 -    bool ide_0_slave_present;
  18.149 -    int ide_0_master_type;
  18.150 -    int ide_0_slave_type;
  18.151 -    bool ide_1_present;
  18.152 -    bool ide_1_master_present;
  18.153 -    bool ide_1_slave_present;
  18.154 -    int ide_1_master_type;
  18.155 -    int ide_1_slave_type;
  18.156 -};
  18.157 -
  18.158 -int
  18.159 -SDL_SYS_CDInit(void)
  18.160 -{
  18.161 -    char *SDLcdrom;
  18.162 -    int raw_fd;
  18.163 -    struct ide_ctrl_info info;
  18.164 -
  18.165 -    /* Fill in our driver capabilities */
  18.166 -    SDL_CDcaps.Name = SDL_SYS_CDName;
  18.167 -    SDL_CDcaps.Open = SDL_SYS_CDOpen;
  18.168 -    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
  18.169 -    SDL_CDcaps.Status = SDL_SYS_CDStatus;
  18.170 -    SDL_CDcaps.Play = SDL_SYS_CDPlay;
  18.171 -    SDL_CDcaps.Pause = SDL_SYS_CDPause;
  18.172 -    SDL_CDcaps.Resume = SDL_SYS_CDResume;
  18.173 -    SDL_CDcaps.Stop = SDL_SYS_CDStop;
  18.174 -    SDL_CDcaps.Eject = SDL_SYS_CDEject;
  18.175 -    SDL_CDcaps.Close = SDL_SYS_CDClose;
  18.176 -
  18.177 -    /* Look in the environment for our CD-ROM drive list */
  18.178 -    SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
  18.179 -    if (SDLcdrom != NULL) {
  18.180 -        char *cdpath, *delim;
  18.181 -        size_t len = SDL_strlen(SDLcdrom) + 1;
  18.182 -        cdpath = SDL_stack_alloc(char, len);
  18.183 -        if (cdpath != NULL) {
  18.184 -            SDL_strlcpy(cdpath, SDLcdrom, len);
  18.185 -            SDLcdrom = cdpath;
  18.186 -            do {
  18.187 -                delim = SDL_strchr(SDLcdrom, ':');
  18.188 -                if (delim) {
  18.189 -                    *delim++ = '\0';
  18.190 -                }
  18.191 -                if (CheckDrive(SDLcdrom) > 0) {
  18.192 -                    AddDrive(SDLcdrom);
  18.193 -                }
  18.194 -                if (delim) {
  18.195 -                    SDLcdrom = delim;
  18.196 -                } else {
  18.197 -                    SDLcdrom = NULL;
  18.198 -                }
  18.199 -            } while (SDLcdrom);
  18.200 -            SDL_stack_free(cdpath);
  18.201 -        }
  18.202 -
  18.203 -        /* If we found our drives, there's nothing left to do */
  18.204 -        if (SDL_numcds > 0) {
  18.205 -            return (0);
  18.206 -        }
  18.207 -    }
  18.208 -
  18.209 -    /* Scan the system for CD-ROM drives */
  18.210 -    try_dir("/dev/disk");
  18.211 -    return 0;
  18.212 -}
  18.213 -
  18.214 -
  18.215 -int
  18.216 -try_dir(const char *directory)
  18.217 -{
  18.218 -    BDirectory dir;
  18.219 -    dir.SetTo(directory);
  18.220 -    if (dir.InitCheck() != B_NO_ERROR) {
  18.221 -        return false;
  18.222 -    }
  18.223 -    dir.Rewind();
  18.224 -    BEntry entry;
  18.225 -    while (dir.GetNextEntry(&entry) >= 0) {
  18.226 -        BPath path;
  18.227 -        const char *name;
  18.228 -        entry_ref e;
  18.229 -
  18.230 -        if (entry.GetPath(&path) != B_NO_ERROR)
  18.231 -            continue;
  18.232 -        name = path.Path();
  18.233 -
  18.234 -        if (entry.GetRef(&e) != B_NO_ERROR)
  18.235 -            continue;
  18.236 -
  18.237 -        if (entry.IsDirectory()) {
  18.238 -            if (SDL_strcmp(e.name, "floppy") == 0)
  18.239 -                continue;       /* ignore floppy (it is not silent)  */
  18.240 -            int devfd = try_dir(name);
  18.241 -            if (devfd >= 0)
  18.242 -                return devfd;
  18.243 -        } else {
  18.244 -            int devfd;
  18.245 -            device_geometry g;
  18.246 -
  18.247 -            if (SDL_strcmp(e.name, "raw") != 0)
  18.248 -                continue;       /* ignore partitions */
  18.249 -
  18.250 -            devfd = open(name, O_RDONLY);
  18.251 -            if (devfd < 0)
  18.252 -                continue;
  18.253 -
  18.254 -            if (ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) {
  18.255 -                if (g.device_type == B_CD) {
  18.256 -                    AddDrive(strdup(name));
  18.257 -                }
  18.258 -            }
  18.259 -            close(devfd);
  18.260 -        }
  18.261 -    }
  18.262 -    return B_ERROR;
  18.263 -}
  18.264 -
  18.265 -
  18.266 -/* General ioctl() CD-ROM command function */
  18.267 -static int
  18.268 -SDL_SYS_CDioctl(int index, int command, void *arg)
  18.269 -{
  18.270 -    int okay;
  18.271 -    int fd;
  18.272 -
  18.273 -    okay = 0;
  18.274 -    fd = open(SDL_cdlist[index], 0);
  18.275 -    if (fd >= 0) {
  18.276 -        if (ioctl(fd, command, arg) == B_NO_ERROR) {
  18.277 -            okay = 1;
  18.278 -        }
  18.279 -        close(fd);
  18.280 -    }
  18.281 -    return (okay ? 0 : -1);
  18.282 -}
  18.283 -
  18.284 -static const char *
  18.285 -SDL_SYS_CDName(int drive)
  18.286 -{
  18.287 -    return (SDL_cdlist[drive]);
  18.288 -}
  18.289 -
  18.290 -static int
  18.291 -SDL_SYS_CDOpen(int drive)
  18.292 -{
  18.293 -    return (drive);
  18.294 -}
  18.295 -
  18.296 -static int
  18.297 -SDL_SYS_CDGetTOC(SDL_CD * cdrom)
  18.298 -{
  18.299 -    int i;
  18.300 -    scsi_toc toc;
  18.301 -
  18.302 -    if (SDL_SYS_CDioctl(cdrom->id, B_SCSI_GET_TOC, &toc) == 0) {
  18.303 -        cdrom->numtracks = CD_NUMTRACKS(toc);
  18.304 -        if (cdrom->numtracks > SDL_MAX_TRACKS) {
  18.305 -            cdrom->numtracks = SDL_MAX_TRACKS;
  18.306 -        }
  18.307 -        for (i = 0; i <= cdrom->numtracks; ++i) {
  18.308 -            cdrom->track[i].id = CD_TRACK_N(toc, i);
  18.309 -            /* FIXME:  How do we tell on BeOS? */
  18.310 -            cdrom->track[i].type = SDL_AUDIO_TRACK;
  18.311 -            cdrom->track[i].offset = MSF_TO_FRAMES(CD_TRACK_M(toc, i),
  18.312 -                                                   CD_TRACK_S(toc, i),
  18.313 -                                                   CD_TRACK_F(toc, i));
  18.314 -            cdrom->track[i].length = 0;
  18.315 -            if (i > 0) {
  18.316 -                cdrom->track[i - 1].length =
  18.317 -                    cdrom->track[i].offset - cdrom->track[i - 1].offset;
  18.318 -            }
  18.319 -        }
  18.320 -        return (0);
  18.321 -    } else {
  18.322 -        return (-1);
  18.323 -    }
  18.324 -}
  18.325 -
  18.326 -/* Get CD-ROM status */
  18.327 -static CDstatus
  18.328 -SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
  18.329 -{
  18.330 -    CDstatus status;
  18.331 -    int fd;
  18.332 -    int cur_frame;
  18.333 -    scsi_position pos;
  18.334 -
  18.335 -    fd = open(SDL_cdlist[cdrom->id], 0);
  18.336 -    cur_frame = 0;
  18.337 -    if (fd >= 0) {
  18.338 -        if (ioctl(fd, B_SCSI_GET_POSITION, &pos) == B_NO_ERROR) {
  18.339 -            cur_frame =
  18.340 -                MSF_TO_FRAMES(POS_ABS_M(pos), POS_ABS_S(pos), POS_ABS_F(pos));
  18.341 -        }
  18.342 -        if (!pos.position[1] || (pos.position[1] >= 0x13) ||
  18.343 -            ((pos.position[1] == 0x12) && (!pos.position[6]))) {
  18.344 -            status = CD_STOPPED;
  18.345 -        } else if (pos.position[1] == 0x11) {
  18.346 -            status = CD_PLAYING;
  18.347 -        } else {
  18.348 -            status = CD_PAUSED;
  18.349 -        }
  18.350 -        close(fd);
  18.351 -    } else {
  18.352 -        status = CD_TRAYEMPTY;
  18.353 -    }
  18.354 -    if (position) {
  18.355 -        *position = cur_frame;
  18.356 -    }
  18.357 -    return (status);
  18.358 -}
  18.359 -
  18.360 -/* Start play */
  18.361 -static int
  18.362 -SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
  18.363 -{
  18.364 -    int okay;
  18.365 -    int fd;
  18.366 -    scsi_play_position pos;
  18.367 -
  18.368 -    okay = 0;
  18.369 -    fd = open(SDL_cdlist[cdrom->id], 0);
  18.370 -    if (fd >= 0) {
  18.371 -        FRAMES_TO_MSF(start, &pos.start_m, &pos.start_s, &pos.start_f);
  18.372 -        FRAMES_TO_MSF(start + length, &pos.end_m, &pos.end_s, &pos.end_f);
  18.373 -        if (ioctl(fd, B_SCSI_PLAY_POSITION, &pos) == B_NO_ERROR) {
  18.374 -            okay = 1;
  18.375 -        }
  18.376 -        close(fd);
  18.377 -    }
  18.378 -    return (okay ? 0 : -1);
  18.379 -}
  18.380 -
  18.381 -/* Pause play */
  18.382 -static int
  18.383 -SDL_SYS_CDPause(SDL_CD * cdrom)
  18.384 -{
  18.385 -    return (SDL_SYS_CDioctl(cdrom->id, B_SCSI_PAUSE_AUDIO, 0));
  18.386 -}
  18.387 -
  18.388 -/* Resume play */
  18.389 -static int
  18.390 -SDL_SYS_CDResume(SDL_CD * cdrom)
  18.391 -{
  18.392 -    return (SDL_SYS_CDioctl(cdrom->id, B_SCSI_RESUME_AUDIO, 0));
  18.393 -}
  18.394 -
  18.395 -/* Stop play */
  18.396 -static int
  18.397 -SDL_SYS_CDStop(SDL_CD * cdrom)
  18.398 -{
  18.399 -    return (SDL_SYS_CDioctl(cdrom->id, B_SCSI_STOP_AUDIO, 0));
  18.400 -}
  18.401 -
  18.402 -/* Eject the CD-ROM */
  18.403 -static int
  18.404 -SDL_SYS_CDEject(SDL_CD * cdrom)
  18.405 -{
  18.406 -    return (SDL_SYS_CDioctl(cdrom->id, B_SCSI_EJECT, 0));
  18.407 -}
  18.408 -
  18.409 -/* Close the CD-ROM handle */
  18.410 -static void
  18.411 -SDL_SYS_CDClose(SDL_CD * cdrom)
  18.412 -{
  18.413 -    close(cdrom->id);
  18.414 -}
  18.415 -
  18.416 -void
  18.417 -SDL_SYS_CDQuit(void)
  18.418 -{
  18.419 -    int i;
  18.420 -
  18.421 -    if (SDL_numcds > 0) {
  18.422 -        for (i = 0; i < SDL_numcds; ++i) {
  18.423 -            SDL_free(SDL_cdlist[i]);
  18.424 -        }
  18.425 -        SDL_numcds = 0;
  18.426 -    }
  18.427 -}
  18.428 -
  18.429 -#endif /* SDL_CDROM_BEOS */
  18.430 -/* vi: set ts=4 sw=4 expandtab: */
    19.1 --- a/src/cdrom/bsdi/SDL_syscdrom.c	Sat Sep 05 09:03:35 2009 +0000
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,550 +0,0 @@
    19.4 -/*
    19.5 -    SDL - Simple DirectMedia Layer
    19.6 -    Copyright (C) 1997-2009 Sam Lantinga
    19.7 -
    19.8 -    This library is free software; you can redistribute it and/or
    19.9 -    modify it under the terms of the GNU Lesser General Public
   19.10 -    License as published by the Free Software Foundation; either
   19.11 -    version 2.1 of the License, or (at your option) any later version.
   19.12 -
   19.13 -    This library is distributed in the hope that it will be useful,
   19.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   19.16 -    Lesser General Public License for more details.
   19.17 -
   19.18 -    You should have received a copy of the GNU Lesser General Public
   19.19 -    License along with this library; if not, write to the Free Software
   19.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   19.21 -
   19.22 -    Sam Lantinga
   19.23 -    slouken@libsdl.org
   19.24 -*/
   19.25 -#include "SDL_config.h"
   19.26 -
   19.27 -#ifdef SDL_CDROM_BSDI
   19.28 -
   19.29 -/*
   19.30 - * Functions for system-level CD-ROM audio control for BSD/OS 4.x
   19.31 - * This started life out as a copy of the freebsd/SDL_cdrom.c file but was
   19.32 - * heavily modified.   Works for standard (MMC) SCSI and ATAPI CDrom drives.
   19.33 - *
   19.34 - * Steven Schultz - sms@to.gd-es.com
   19.35 -*/
   19.36 -
   19.37 -#include <sys/types.h>
   19.38 -#include <sys/stat.h>
   19.39 -#include <fcntl.h>
   19.40 -#include <err.h>
   19.41 -#include <unistd.h>
   19.42 -#include <sys/ioctl.h>
   19.43 -#include </sys/dev/scsi/scsi.h>
   19.44 -#include </sys/dev/scsi/scsi_ioctl.h>
   19.45 -
   19.46 -#include "SDL_cdrom.h"
   19.47 -#include "../SDL_syscdrom.h"
   19.48 -
   19.49 -/*
   19.50 - * The msf_to_frame and frame_to_msf were yanked from libcdrom and inlined
   19.51 - * here so that -lcdrom doesn't have to be dragged in for something so simple.
   19.52 -*/
   19.53 -
   19.54 -#define	FRAMES_PER_SECOND	75
   19.55 -#define	FRAMES_PER_MINUTE	(FRAMES_PER_SECOND * 60)
   19.56 -
   19.57 -int
   19.58 -msf_to_frame(int minute, int second, int frame)
   19.59 -{
   19.60 -    return (minute * FRAMES_PER_MINUTE + second * FRAMES_PER_SECOND + frame);
   19.61 -}
   19.62 -
   19.63 -void
   19.64 -frame_to_msf(int frame, int *minp, int *secp, int *framep)
   19.65 -{
   19.66 -    *minp = frame / FRAMES_PER_MINUTE;
   19.67 -    *secp = (frame % FRAMES_PER_MINUTE) / FRAMES_PER_SECOND;
   19.68 -    *framep = frame % FRAMES_PER_SECOND;
   19.69 -}
   19.70 -
   19.71 -/* The maximum number of CD-ROM drives we'll detect */
   19.72 -#define MAX_DRIVES	16
   19.73 -
   19.74 -/* A list of available CD-ROM drives */
   19.75 -static char *SDL_cdlist[MAX_DRIVES];
   19.76 -static dev_t SDL_cdmode[MAX_DRIVES];
   19.77 -
   19.78 -/* The system-dependent CD control functions */
   19.79 -static const char *SDL_SYS_CDName(int drive);
   19.80 -static int SDL_SYS_CDOpen(int drive);
   19.81 -static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
   19.82 -static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
   19.83 -static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
   19.84 -static int SDL_SYS_CDPause(SDL_CD * cdrom);
   19.85 -static int SDL_SYS_CDResume(SDL_CD * cdrom);
   19.86 -static int SDL_SYS_CDStop(SDL_CD * cdrom);
   19.87 -static int SDL_SYS_CDEject(SDL_CD * cdrom);
   19.88 -static void SDL_SYS_CDClose(SDL_CD * cdrom);
   19.89 -
   19.90 -typedef struct scsi_cdb cdb_t;
   19.91 -
   19.92 -static int
   19.93 -scsi_cmd(int fd,
   19.94 -         struct scsi_cdb *cdb,
   19.95 -         int cdblen,
   19.96 -         int rw, caddr_t data, int datalen, struct scsi_user_cdb *sus)
   19.97 -{
   19.98 -    int scsistatus;
   19.99 -    unsigned char *cp;
  19.100 -    struct scsi_user_cdb suc;
  19.101 -
  19.102 -    /* safety checks */
  19.103 -    if (!cdb)
  19.104 -        return (-1);
  19.105 -    if (rw != SUC_READ && rw != SUC_WRITE)
  19.106 -        return (-1);
  19.107 -
  19.108 -    suc.suc_flags = rw;
  19.109 -    suc.suc_cdblen = cdblen;
  19.110 -    bcopy(cdb, suc.suc_cdb, cdblen);
  19.111 -    suc.suc_datalen = datalen;
  19.112 -    suc.suc_data = data;
  19.113 -    suc.suc_timeout = 10;       /* 10 secs max for TUR or SENSE */
  19.114 -    if (ioctl(fd, SCSIRAWCDB, &suc) == -1)
  19.115 -        return (-11);
  19.116 -    scsistatus = suc.suc_sus.sus_status;
  19.117 -    cp = suc.suc_sus.sus_sense;
  19.118 -
  19.119 -/*
  19.120 - * If a place to copy the sense data back to has been provided then the
  19.121 - * caller is responsible for checking the errors and printing any information
  19.122 - * out if the status was not successful.
  19.123 -*/
  19.124 -    if (scsistatus != 0 && !sus) {
  19.125 -        fprintf(stderr, "scsistatus = %x cmd = %x\n", scsistatus, cdb[0]);
  19.126 -        fprintf(stderr,
  19.127 -                "sense %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n",
  19.128 -                cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7],
  19.129 -                cp[8], cp[9], cp[10], cp[11], cp[12], cp[13], cp[14], cp[15]);
  19.130 -        return (1);
  19.131 -    }
  19.132 -    if (sus)
  19.133 -        bcopy(&suc, sus, sizeof(struct scsi_user_cdb));
  19.134 -    if (scsistatus)
  19.135 -        return (1);             /* Return non-zero for unsuccessful status */
  19.136 -    return (0);
  19.137 -}
  19.138 -
  19.139 -/* request vendor brand and model */
  19.140 -unsigned char *
  19.141 -Inquiry(int fd)
  19.142 -{
  19.143 -    static struct scsi_cdb6 cdb = {
  19.144 -        0x12,
  19.145 -        0, 0, 0,
  19.146 -        56,
  19.147 -        0
  19.148 -    };
  19.149 -    static unsigned char Inqbuffer[56];
  19.150 -
  19.151 -    if (scsi_cmd(fd, (cdb_t *) & cdb, 6, SUC_READ, Inqbuffer,
  19.152 -                 sizeof(Inqbuffer), 0))
  19.153 -        return ("\377");
  19.154 -    return (Inqbuffer);
  19.155 -}
  19.156 -
  19.157 -#define ADD_SENSECODE 12
  19.158 -#define ADD_SC_QUALIFIER 13
  19.159 -
  19.160 -int
  19.161 -TestForMedium(int fd)
  19.162 -{
  19.163 -    int sts, asc, ascq;
  19.164 -    struct scsi_user_cdb sus;
  19.165 -    static struct scsi_cdb6 cdb = {
  19.166 -        CMD_TEST_UNIT_READY,    /* command */
  19.167 -        0,                      /* reserved */
  19.168 -        0,                      /* reserved */
  19.169 -        0,                      /* reserved */
  19.170 -        0,                      /* reserved */
  19.171 -        0                       /* reserved */
  19.172 -    };
  19.173 -
  19.174 -  again:sts = scsi_cmd(fd, (cdb_t *) & cdb, 6, SUC_READ, 0, 0, &sus);
  19.175 -    asc = sus.suc_sus.sus_sense[ADD_SENSECODE];
  19.176 -    ascq = sus.suc_sus.sus_sense[ADD_SC_QUALIFIER];
  19.177 -    if (asc == 0x3a && ascq == 0x0)     /* no medium */
  19.178 -        return (0);
  19.179 -    if (asc == 0x28 && ascq == 0x0)     /* medium changed */
  19.180 -        goto again;
  19.181 -    if (asc == 0x4 && ascq == 0x1) {    /* coming ready */
  19.182 -        sleep(2);
  19.183 -        goto again;
  19.184 -    }
  19.185 -    return (1);
  19.186 -}
  19.187 -
  19.188 -/* Check a drive to see if it is a CD-ROM */
  19.189 -static int
  19.190 -CheckDrive(char *drive, struct stat *stbuf)
  19.191 -{
  19.192 -    int is_cd = 0, cdfd;
  19.193 -    char *p;
  19.194 -
  19.195 -    /* If it doesn't exist, return -1 */
  19.196 -    if (stat(drive, stbuf) < 0) {
  19.197 -        return (-1);
  19.198 -    }
  19.199 -
  19.200 -    /* If it does exist, verify that it's an available CD-ROM */
  19.201 -    cdfd = open(drive, (O_RDONLY | O_EXCL | O_NONBLOCK), 0);
  19.202 -    if (cdfd >= 0) {
  19.203 -        p = Inquiry(cdfd);
  19.204 -        if (*p == TYPE_ROM)
  19.205 -            is_cd = 1;
  19.206 -        close(cdfd);
  19.207 -    }
  19.208 -    return (is_cd);
  19.209 -}
  19.210 -
  19.211 -/* Add a CD-ROM drive to our list of valid drives */
  19.212 -static void
  19.213 -AddDrive(char *drive, struct stat *stbuf)
  19.214 -{
  19.215 -    int i;
  19.216 -
  19.217 -    if (SDL_numcds < MAX_DRIVES) {
  19.218 -        /* Check to make sure it's not already in our list.
  19.219 -           This can happen when we see a drive via symbolic link.
  19.220 -         */
  19.221 -        for (i = 0; i < SDL_numcds; ++i) {
  19.222 -            if (stbuf->st_rdev == SDL_cdmode[i]) {
  19.223 -#ifdef DEBUG_CDROM
  19.224 -                fprintf(stderr, "Duplicate drive detected: %s == %s\n",
  19.225 -                        drive, SDL_cdlist[i]);
  19.226 -#endif
  19.227 -                return;
  19.228 -            }
  19.229 -        }
  19.230 -
  19.231 -        /* Add this drive to our list */
  19.232 -        i = SDL_numcds;
  19.233 -        SDL_cdlist[i] = SDL_strdup(drive);
  19.234 -        if (SDL_cdlist[i] == NULL) {
  19.235 -            SDL_OutOfMemory();
  19.236 -            return;
  19.237 -        }
  19.238 -        SDL_cdmode[i] = stbuf->st_rdev;
  19.239 -        ++SDL_numcds;
  19.240 -#ifdef DEBUG_CDROM
  19.241 -        fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
  19.242 -#endif
  19.243 -    }
  19.244 -}
  19.245 -
  19.246 -int
  19.247 -SDL_SYS_CDInit(void)
  19.248 -{
  19.249 -    /* checklist: /dev/rsr?c */
  19.250 -    static char *checklist[] = {
  19.251 -        "?0 rsr?", NULL
  19.252 -    };
  19.253 -    char *SDLcdrom;
  19.254 -    int i, j, exists;
  19.255 -    char drive[32];
  19.256 -    struct stat stbuf;
  19.257 -
  19.258 -    /* Fill in our driver capabilities */
  19.259 -    SDL_CDcaps.Name = SDL_SYS_CDName;
  19.260 -    SDL_CDcaps.Open = SDL_SYS_CDOpen;
  19.261 -    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
  19.262 -    SDL_CDcaps.Status = SDL_SYS_CDStatus;
  19.263 -    SDL_CDcaps.Play = SDL_SYS_CDPlay;
  19.264 -    SDL_CDcaps.Pause = SDL_SYS_CDPause;
  19.265 -    SDL_CDcaps.Resume = SDL_SYS_CDResume;
  19.266 -    SDL_CDcaps.Stop = SDL_SYS_CDStop;
  19.267 -    SDL_CDcaps.Eject = SDL_SYS_CDEject;
  19.268 -    SDL_CDcaps.Close = SDL_SYS_CDClose;
  19.269 -
  19.270 -    /* Look in the environment for our CD-ROM drive list */
  19.271 -    SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
  19.272 -    if (SDLcdrom != NULL) {
  19.273 -        char *cdpath, *delim;
  19.274 -        size_t len = SDL_strlen(SDLcdrom) + 1;
  19.275 -        cdpath = SDL_stack_alloc(char, len);
  19.276 -        if (cdpath != NULL) {
  19.277 -            SDL_strlcpy(cdpath, SDLcdrom, len);
  19.278 -            SDLcdrom = cdpath;
  19.279 -            do {
  19.280 -                delim = SDL_strchr(SDLcdrom, ':');
  19.281 -                if (delim) {
  19.282 -                    *delim++ = '\0';
  19.283 -                }
  19.284 -                if (CheckDrive(SDLcdrom, &stbuf) > 0) {
  19.285 -                    AddDrive(SDLcdrom, &stbuf);
  19.286 -                }
  19.287 -                if (delim) {
  19.288 -                    SDLcdrom = delim;
  19.289 -                } else {
  19.290 -                    SDLcdrom = NULL;
  19.291 -                }
  19.292 -            } while (SDLcdrom);
  19.293 -            SDL_stack_free(cdpath);
  19.294 -        }
  19.295 -
  19.296 -        /* If we found our drives, there's nothing left to do */
  19.297 -        if (SDL_numcds > 0) {
  19.298 -            return (0);
  19.299 -        }
  19.300 -    }
  19.301 -
  19.302 -    /* Scan the system for CD-ROM drives */
  19.303 -    for (i = 0; checklist[i]; ++i) {
  19.304 -        if (checklist[i][0] == '?') {
  19.305 -            char *insert;
  19.306 -            exists = 1;
  19.307 -            for (j = checklist[i][1]; exists; ++j) {
  19.308 -                SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%sc",
  19.309 -                             &checklist[i][3]);
  19.310 -                insert = SDL_strchr(drive, '?');
  19.311 -                if (insert != NULL) {
  19.312 -                    *insert = j;
  19.313 -                }
  19.314 -                switch (CheckDrive(drive, &stbuf)) {
  19.315 -                    /* Drive exists and is a CD-ROM */
  19.316 -                case 1:
  19.317 -                    AddDrive(drive, &stbuf);
  19.318 -                    break;
  19.319 -                    /* Drive exists, but isn't a CD-ROM */
  19.320 -                case 0:
  19.321 -                    break;
  19.322 -                    /* Drive doesn't exist */
  19.323 -                case -1:
  19.324 -                    exists = 0;
  19.325 -                    break;
  19.326 -                }
  19.327 -            }
  19.328 -        } else {
  19.329 -            SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
  19.330 -                         checklist[i]);
  19.331 -            if (CheckDrive(drive, &stbuf) > 0) {
  19.332 -                AddDrive(drive, &stbuf);
  19.333 -            }
  19.334 -        }
  19.335 -    }
  19.336 -    return (0);
  19.337 -}
  19.338 -
  19.339 -static const char *
  19.340 -SDL_SYS_CDName(int drive)
  19.341 -{
  19.342 -    return (SDL_cdlist[drive]);
  19.343 -}
  19.344 -
  19.345 -static int
  19.346 -SDL_SYS_CDOpen(int drive)
  19.347 -{
  19.348 -    return (open(SDL_cdlist[drive], O_RDONLY | O_NONBLOCK | O_EXCL, 0));
  19.349 -}
  19.350 -
  19.351 -static int
  19.352 -SDL_SYS_CDGetTOC(SDL_CD * cdrom)
  19.353 -{
  19.354 -    u_char cdb[10], buf[4], *p, *toc;
  19.355 -    struct scsi_user_cdb sus;
  19.356 -    int i, sts, first_track, last_track, ntracks, toc_size;
  19.357 -
  19.358 -    bzero(cdb, sizeof(cdb));
  19.359 -    cdb[0] = 0x43;              /* Read TOC */
  19.360 -    cdb[1] = 0x2;               /* MSF */
  19.361 -    cdb[8] = 4;                 /* size TOC header */
  19.362 -    sts = scsi_cmd(cdrom->id, (cdb_t *) cdb, 10, SUC_READ, buf, 4, &sus);
  19.363 -    if (sts < 0)
  19.364 -        return (-1);
  19.365 -    first_track = buf[2];
  19.366 -    last_track = buf[3];
  19.367 -    ntracks = last_track - first_track + 1;
  19.368 -    cdrom->numtracks = ntracks;
  19.369 -    toc_size = 4 + (ntracks + 1) * 8;
  19.370 -    toc = (u_char *) SDL_malloc(toc_size);
  19.371 -    if (toc == NULL)
  19.372 -        return (-1);
  19.373 -    bzero(cdb, sizeof(cdb));
  19.374 -    cdb[0] = 0x43;
  19.375 -    cdb[1] = 0x2;
  19.376 -    cdb[6] = first_track;
  19.377 -    cdb[7] = toc_size >> 8;
  19.378 -    cdb[8] = toc_size & 0xff;
  19.379 -    sts = scsi_cmd(cdrom->id, (cdb_t *) cdb, 10, SUC_READ, toc, toc_size,
  19.380 -                   &sus);
  19.381 -    if (sts < 0) {
  19.382 -        SDL_free(toc);
  19.383 -        return (-1);
  19.384 -    }
  19.385 -
  19.386 -    for (i = 0, p = toc + 4; i <= ntracks; i++, p += 8) {
  19.387 -        if (i == ntracks)
  19.388 -            cdrom->track[i].id = 0xAA;  /* Leadout */
  19.389 -        else
  19.390 -            cdrom->track[i].id = first_track + i;
  19.391 -        if (p[1] & 0x20)
  19.392 -            cdrom->track[i].type = SDL_DATA_TRACK;
  19.393 -        else
  19.394 -            cdrom->track[i].type = SDL_AUDIO_TRACK;
  19.395 -        cdrom->track[i].offset = msf_to_frame(p[5], p[6], p[7]);
  19.396 -        cdrom->track[i].length = 0;
  19.397 -        if (i > 0)
  19.398 -            cdrom->track[i - 1].length = cdrom->track[i].offset -
  19.399 -                cdrom->track[i - 1].offset;
  19.400 -    }
  19.401 -    SDL_free(toc);
  19.402 -    return (0);
  19.403 -}
  19.404 -
  19.405 -/* Get CD-ROM status */
  19.406 -static CDstatus
  19.407 -SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
  19.408 -{
  19.409 -    CDstatus status;
  19.410 -    u_char cdb[10], buf[16];
  19.411 -    int sts;
  19.412 -    struct scsi_user_cdb sus;
  19.413 -
  19.414 -    bzero(cdb, sizeof(cdb));
  19.415 -    cdb[0] = 0x42;              /* read subq */
  19.416 -    cdb[1] = 0x2;               /* MSF */
  19.417 -    cdb[2] = 0x40;              /* q channel */
  19.418 -    cdb[3] = 1;                 /* current pos */
  19.419 -    cdb[7] = sizeof(buf) >> 8;
  19.420 -    cdb[8] = sizeof(buf) & 0xff;
  19.421 -    sts = scsi_cmd(cdrom->id, (cdb_t *) cdb, 10, SUC_READ, buf, sizeof(buf),
  19.422 -                   &sus);
  19.423 -    if (sts < 0)
  19.424 -        return (-1);
  19.425 -    if (sts) {
  19.426 -        if (TestForMedium(cdrom->id) == 0)
  19.427 -            status = CD_TRAYEMPTY;
  19.428 -        else
  19.429 -            status = CD_ERROR;
  19.430 -    } else {
  19.431 -        switch (buf[1]) {
  19.432 -        case 0x11:
  19.433 -            status = CD_PLAYING;
  19.434 -            break;
  19.435 -        case 0x12:
  19.436 -            status = CD_PAUSED;
  19.437 -            break;
  19.438 -        case 0x13:
  19.439 -        case 0x14:
  19.440 -        case 0x15:
  19.441 -            status = CD_STOPPED;
  19.442 -            break;
  19.443 -        default:
  19.444 -            status = CD_ERROR;
  19.445 -            break;
  19.446 -        }
  19.447 -    }
  19.448 -    if (position) {
  19.449 -        if (status == CD_PLAYING || (status == CD_PAUSED))
  19.450 -            *position = msf_to_frame(buf[9], buf[10], buf[11]);
  19.451 -        else
  19.452 -            *position = 0;
  19.453 -    }
  19.454 -    return (status);
  19.455 -}
  19.456 -
  19.457 -/* Start play */
  19.458 -static int
  19.459 -SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
  19.460 -{
  19.461 -    u_char cdb[10];
  19.462 -    int sts, minute, second, frame, eminute, esecond, eframe;
  19.463 -    struct scsi_user_cdb sus;
  19.464 -
  19.465 -    bzero(cdb, sizeof(cdb));
  19.466 -    cdb[0] = 0x47;              /* Play */
  19.467 -    frame_to_msf(start, &minute, &second, &frame);
  19.468 -    frame_to_msf(start + length, &eminute, &esecond, &eframe);
  19.469 -    cdb[3] = minute;
  19.470 -    cdb[4] = second;
  19.471 -    cdb[5] = frame;
  19.472 -    cdb[6] = eminute;
  19.473 -    cdb[7] = esecond;
  19.474 -    cdb[8] = eframe;
  19.475 -    sts = scsi_cmd(cdrom->id, (cdb_t *) cdb, 10, SUC_READ, 0, 0, &sus);
  19.476 -    return (sts);
  19.477 -}
  19.478 -
  19.479 -static int
  19.480 -pauseresume(SDL_CD * cdrom, int flag)
  19.481 -{
  19.482 -    u_char cdb[10];
  19.483 -    struct scsi_user_cdb sus;
  19.484 -
  19.485 -    bzero(cdb, sizeof(cdb));
  19.486 -    cdb[0] = 0x4b;
  19.487 -    cdb[8] = flag & 0x1;
  19.488 -    return (scsi_cmd(cdrom->id, (cdb_t *) cdb, 10, SUC_READ, 0, 0, &sus));
  19.489 -}
  19.490 -
  19.491 -/* Pause play */
  19.492 -static int
  19.493 -SDL_SYS_CDPause(SDL_CD * cdrom)
  19.494 -{
  19.495 -    return (pauseresume(cdrom, 0));
  19.496 -}
  19.497 -
  19.498 -/* Resume play */
  19.499 -static int
  19.500 -SDL_SYS_CDResume(SDL_CD * cdrom)
  19.501 -{
  19.502 -    return (pauseresume(cdrom, 1));
  19.503 -}
  19.504 -
  19.505 -/* Stop play */
  19.506 -static int
  19.507 -SDL_SYS_CDStop(SDL_CD * cdrom)
  19.508 -{
  19.509 -    u_char cdb[6];
  19.510 -    struct scsi_user_cdb sus;
  19.511 -
  19.512 -    bzero(cdb, sizeof(cdb));
  19.513 -    cdb[0] = 0x1b;              /* stop */
  19.514 -    cdb[1] = 1;                 /* immediate */
  19.515 -    return (scsi_cmd(cdrom->id, (cdb_t *) cdb, 6, SUC_READ, 0, 0, &sus));
  19.516 -}
  19.517 -
  19.518 -/* Eject the CD-ROM */
  19.519 -static int
  19.520 -SDL_SYS_CDEject(SDL_CD * cdrom)
  19.521 -{
  19.522 -    u_char cdb[6];
  19.523 -    struct scsi_user_cdb sus;
  19.524 -
  19.525 -    bzero(cdb, sizeof(cdb));
  19.526 -    cdb[0] = 0x1b;              /* stop */
  19.527 -    cdb[1] = 1;                 /* immediate */
  19.528 -    cdb[4] = 2;                 /* eject */
  19.529 -    return (scsi_cmd(cdrom->id, (cdb_t *) cdb, 6, SUC_READ, 0, 0, &sus));
  19.530 -}
  19.531 -
  19.532 -/* Close the CD-ROM handle */
  19.533 -static void
  19.534 -SDL_SYS_CDClose(SDL_CD * cdrom)
  19.535 -{
  19.536 -    close(cdrom->id);
  19.537 -}
  19.538 -
  19.539 -void
  19.540 -SDL_SYS_CDQuit(void)
  19.541 -{
  19.542 -    int i;
  19.543 -
  19.544 -    if (SDL_numcds > 0) {
  19.545 -        for (i = 0; i < SDL_numcds; ++i) {
  19.546 -            SDL_free(SDL_cdlist[i]);
  19.547 -        }
  19.548 -    }
  19.549 -    SDL_numcds = 0;
  19.550 -}
  19.551 -
  19.552 -#endif /* SDL_CDROM_BSDI */
  19.553 -/* vi: set ts=4 sw=4 expandtab: */
    20.1 --- a/src/cdrom/dc/SDL_syscdrom.c	Sat Sep 05 09:03:35 2009 +0000
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,187 +0,0 @@
    20.4 -/*
    20.5 -    SDL - Simple DirectMedia Layer
    20.6 -    Copyright (C) 1997-2009 Sam Lantinga
    20.7 -
    20.8 -    This library is free software; you can redistribute it and/or
    20.9 -    modify it under the terms of the GNU Lesser General Public
   20.10 -    License as published by the Free Software Foundation; either
   20.11 -    version 2.1 of the License, or (at your option) any later version.
   20.12 -
   20.13 -    This library is distributed in the hope that it will be useful,
   20.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   20.16 -    Lesser General Public License for more details.
   20.17 -
   20.18 -    You should have received a copy of the GNU Lesser General Public
   20.19 -    License along with this library; if not, write to the Free Software
   20.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   20.21 -
   20.22 -    Sam Lantinga
   20.23 -    slouken@libsdl.org
   20.24 -*/
   20.25 -#include "SDL_config.h"
   20.26 -
   20.27 -#ifdef SDL_CDROM_DC
   20.28 -
   20.29 -/* Functions for system-level CD-ROM audio control */
   20.30 -
   20.31 -#include <dc/cdrom.h>
   20.32 -#include <dc/spu.h>
   20.33 -
   20.34 -#include "SDL_cdrom.h"
   20.35 -#include "../SDL_syscdrom.h"
   20.36 -
   20.37 -/* The system-dependent CD control functions */
   20.38 -static const char *SDL_SYS_CDName(int drive);
   20.39 -static int SDL_SYS_CDOpen(int drive);
   20.40 -static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
   20.41 -static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
   20.42 -static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
   20.43 -static int SDL_SYS_CDPause(SDL_CD * cdrom);
   20.44 -static int SDL_SYS_CDResume(SDL_CD * cdrom);
   20.45 -static int SDL_SYS_CDStop(SDL_CD * cdrom);
   20.46 -static int SDL_SYS_CDEject(SDL_CD * cdrom);
   20.47 -static void SDL_SYS_CDClose(SDL_CD * cdrom);
   20.48 -
   20.49 -
   20.50 -int
   20.51 -SDL_SYS_CDInit(void)
   20.52 -{
   20.53 -    /* Fill in our driver capabilities */
   20.54 -    SDL_CDcaps.Name = SDL_SYS_CDName;
   20.55 -    SDL_CDcaps.Open = SDL_SYS_CDOpen;
   20.56 -    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
   20.57 -    SDL_CDcaps.Status = SDL_SYS_CDStatus;
   20.58 -    SDL_CDcaps.Play = SDL_SYS_CDPlay;
   20.59 -    SDL_CDcaps.Pause = SDL_SYS_CDPause;
   20.60 -    SDL_CDcaps.Resume = SDL_SYS_CDResume;
   20.61 -    SDL_CDcaps.Stop = SDL_SYS_CDStop;
   20.62 -    SDL_CDcaps.Eject = SDL_SYS_CDEject;
   20.63 -    SDL_CDcaps.Close = SDL_SYS_CDClose;
   20.64 -
   20.65 -    return (0);
   20.66 -}
   20.67 -
   20.68 -static const char *
   20.69 -SDL_SYS_CDName(int drive)
   20.70 -{
   20.71 -    return "/cd";
   20.72 -}
   20.73 -
   20.74 -static int
   20.75 -SDL_SYS_CDOpen(int drive)
   20.76 -{
   20.77 -    return (drive);
   20.78 -}
   20.79 -
   20.80 -#define	TRACK_CDDA	0
   20.81 -static int
   20.82 -SDL_SYS_CDGetTOC(SDL_CD * cdrom)
   20.83 -{
   20.84 -    CDROM_TOC toc;
   20.85 -    int ret, i;
   20.86 -
   20.87 -    ret = cdrom_read_toc(&toc, 0);
   20.88 -    if (ret != ERR_OK) {
   20.89 -        return -1;
   20.90 -    }
   20.91 -
   20.92 -    cdrom->numtracks = TOC_TRACK(toc.last) - TOC_TRACK(toc.first) + 1;
   20.93 -    for (i = 0; i < cdrom->numtracks; i++) {
   20.94 -        unsigned long entry = toc.entry[i];
   20.95 -        cdrom->track[i].id = i + 1;
   20.96 -        cdrom->track[i].type =
   20.97 -            (TOC_CTRL(toc.entry[i]) ==
   20.98 -             TRACK_CDDA) ? SDL_AUDIO_TRACK : SDL_DATA_TRACK;
   20.99 -        cdrom->track[i].offset = TOC_LBA(entry) - 150;
  20.100 -        cdrom->track[i].length =
  20.101 -            TOC_LBA((i + 1 <
  20.102 -                     toc.last) ? toc.entry[i + 1] : toc.leadout_sector) -
  20.103 -            TOC_LBA(entry);
  20.104 -    }
  20.105 -
  20.106 -    return 0;
  20.107 -}
  20.108 -
  20.109 -/* Get CD-ROM status */
  20.110 -static CDstatus
  20.111 -SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
  20.112 -{
  20.113 -    int ret, dc_status, disc_type;
  20.114 -
  20.115 -    ret = cdrom_get_status(&dc_status, &disc_type);
  20.116 -    if (ret != ERR_OK)
  20.117 -        return CD_ERROR;
  20.118 -
  20.119 -    switch (dc_status) {
  20.120 -//      case CD_STATUS_BUSY:
  20.121 -    case CD_STATUS_PAUSED:
  20.122 -        return CD_PAUSED;
  20.123 -    case CD_STATUS_STANDBY:
  20.124 -        return CD_STOPPED;
  20.125 -    case CD_STATUS_PLAYING:
  20.126 -        return CD_PLAYING;
  20.127 -//      case CD_STATUS_SEEKING:
  20.128 -//      case CD_STATUS_SCANING:
  20.129 -    case CD_STATUS_OPEN:
  20.130 -    case CD_STATUS_NO_DISC:
  20.131 -        return CD_TRAYEMPTY;
  20.132 -    default:
  20.133 -        return CD_ERROR;
  20.134 -    }
  20.135 -}
  20.136 -
  20.137 -/* Start play */
  20.138 -static int
  20.139 -SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
  20.140 -{
  20.141 -    int ret =
  20.142 -        cdrom_cdda_play(start - 150, start - 150 + length, 1, CDDA_SECTORS);
  20.143 -    return ret == ERR_OK ? 0 : -1;
  20.144 -}
  20.145 -
  20.146 -/* Pause play */
  20.147 -static int
  20.148 -SDL_SYS_CDPause(SDL_CD * cdrom)
  20.149 -{
  20.150 -    int ret = cdrom_cdda_pause();
  20.151 -    return ret == ERR_OK ? 0 : -1;
  20.152 -}
  20.153 -
  20.154 -/* Resume play */
  20.155 -static int
  20.156 -SDL_SYS_CDResume(SDL_CD * cdrom)
  20.157 -{
  20.158 -    int ret = cdrom_cdda_resume();
  20.159 -    return ret == ERR_OK ? 0 : -1;
  20.160 -}
  20.161 -
  20.162 -/* Stop play */
  20.163 -static int
  20.164 -SDL_SYS_CDStop(SDL_CD * cdrom)
  20.165 -{
  20.166 -    int ret = cdrom_spin_down();
  20.167 -    return ret == ERR_OK ? 0 : -1;
  20.168 -}
  20.169 -
  20.170 -/* Eject the CD-ROM */
  20.171 -static int
  20.172 -SDL_SYS_CDEject(SDL_CD * cdrom)
  20.173 -{
  20.174 -    return -1;
  20.175 -}
  20.176 -
  20.177 -/* Close the CD-ROM handle */
  20.178 -static void
  20.179 -SDL_SYS_CDClose(SDL_CD * cdrom)
  20.180 -{
  20.181 -}
  20.182 -
  20.183 -void
  20.184 -SDL_SYS_CDQuit(void)
  20.185 -{
  20.186 -
  20.187 -}
  20.188 -
  20.189 -#endif /* SDL_CDROM_DC */
  20.190 -/* vi: set ts=4 sw=4 expandtab: */
    21.1 --- a/src/cdrom/dummy/SDL_syscdrom.c	Sat Sep 05 09:03:35 2009 +0000
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,44 +0,0 @@
    21.4 -/*
    21.5 -    SDL - Simple DirectMedia Layer
    21.6 -    Copyright (C) 1997-2009 Sam Lantinga
    21.7 -
    21.8 -    This library is free software; you can redistribute it and/or
    21.9 -    modify it under the terms of the GNU Lesser General Public
   21.10 -    License as published by the Free Software Foundation; either
   21.11 -    version 2.1 of the License, or (at your option) any later version.
   21.12 -
   21.13 -    This library is distributed in the hope that it will be useful,
   21.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   21.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   21.16 -    Lesser General Public License for more details.
   21.17 -
   21.18 -    You should have received a copy of the GNU Lesser General Public
   21.19 -    License along with this library; if not, write to the Free Software
   21.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   21.21 -
   21.22 -    Sam Lantinga
   21.23 -    slouken@libsdl.org
   21.24 -*/
   21.25 -#include "SDL_config.h"
   21.26 -
   21.27 -#if defined(SDL_CDROM_DUMMY) || defined(SDL_CDROM_DISABLED)
   21.28 -
   21.29 -/* Stub functions for system-level CD-ROM audio control */
   21.30 -
   21.31 -#include "SDL_cdrom.h"
   21.32 -#include "../SDL_syscdrom.h"
   21.33 -
   21.34 -int
   21.35 -SDL_SYS_CDInit(void)
   21.36 -{
   21.37 -    return (0);
   21.38 -}
   21.39 -
   21.40 -void
   21.41 -SDL_SYS_CDQuit(void)
   21.42 -{
   21.43 -    return;
   21.44 -}
   21.45 -
   21.46 -#endif /* SDL_CDROM_DUMMY || SDL_CDROM_DISABLED */
   21.47 -/* vi: set ts=4 sw=4 expandtab: */
    22.1 --- a/src/cdrom/freebsd/SDL_syscdrom.c	Sat Sep 05 09:03:35 2009 +0000
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,422 +0,0 @@
    22.4 -/*
    22.5 -    SDL - Simple DirectMedia Layer
    22.6 -    Copyright (C) 1997-2009 Sam Lantinga
    22.7 -
    22.8 -    This library is free software; you can redistribute it and/or
    22.9 -    modify it under the terms of the GNU Lesser General Public
   22.10 -    License as published by the Free Software Foundation; either
   22.11 -    version 2.1 of the License, or (at your option) any later version.
   22.12 -
   22.13 -    This library is distributed in the hope that it will be useful,
   22.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   22.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   22.16 -    Lesser General Public License for more details.
   22.17 -
   22.18 -    You should have received a copy of the GNU Lesser General Public
   22.19 -    License along with this library; if not, write to the Free Software
   22.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   22.21 -
   22.22 -    Sam Lantinga
   22.23 -    slouken@libsdl.org
   22.24 -*/
   22.25 -#include "SDL_config.h"
   22.26 -
   22.27 -#ifdef SDL_CDROM_FREEBSD
   22.28 -
   22.29 -/* Functions for system-level CD-ROM audio control */
   22.30 -
   22.31 -#include <sys/types.h>
   22.32 -#include <sys/stat.h>
   22.33 -#include <fcntl.h>
   22.34 -#include <errno.h>
   22.35 -#include <unistd.h>
   22.36 -#include <sys/cdio.h>
   22.37 -
   22.38 -#include "SDL_cdrom.h"
   22.39 -#include "../SDL_syscdrom.h"
   22.40 -
   22.41 -
   22.42 -/* The maximum number of CD-ROM drives we'll detect */
   22.43 -#define MAX_DRIVES	16
   22.44 -
   22.45 -/* A list of available CD-ROM drives */
   22.46 -static char *SDL_cdlist[MAX_DRIVES];
   22.47 -static dev_t SDL_cdmode[MAX_DRIVES];
   22.48 -
   22.49 -/* The system-dependent CD control functions */
   22.50 -static const char *SDL_SYS_CDName(int drive);
   22.51 -static int SDL_SYS_CDOpen(int drive);
   22.52 -static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
   22.53 -static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
   22.54 -static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
   22.55 -static int SDL_SYS_CDPause(SDL_CD * cdrom);
   22.56 -static int SDL_SYS_CDResume(SDL_CD * cdrom);
   22.57 -static int SDL_SYS_CDStop(SDL_CD * cdrom);
   22.58 -static int SDL_SYS_CDEject(SDL_CD * cdrom);
   22.59 -static void SDL_SYS_CDClose(SDL_CD * cdrom);
   22.60 -
   22.61 -/* Some ioctl() errno values which occur when the tray is empty */
   22.62 -#define ERRNO_TRAYEMPTY(errno)	\
   22.63 -	((errno == EIO) || (errno == ENOENT) || (errno == EINVAL))
   22.64 -
   22.65 -/* Check a drive to see if it is a CD-ROM */
   22.66 -static int
   22.67 -CheckDrive(char *drive, struct stat *stbuf)
   22.68 -{
   22.69 -    int is_cd, cdfd;
   22.70 -    struct ioc_read_subchannel info;
   22.71 -
   22.72 -    /* If it doesn't exist, return -1 */
   22.73 -    if (stat(drive, stbuf) < 0) {
   22.74 -        return (-1);
   22.75 -    }
   22.76 -
   22.77 -    /* If it does exist, verify that it's an available CD-ROM */
   22.78 -    is_cd = 0;
   22.79 -    if (S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode)) {
   22.80 -        cdfd = open(drive, (O_RDONLY | O_EXCL | O_NONBLOCK), 0);
   22.81 -        if (cdfd >= 0) {
   22.82 -            info.address_format = CD_MSF_FORMAT;
   22.83 -            info.data_format = CD_CURRENT_POSITION;
   22.84 -            info.data_len = 0;
   22.85 -            info.data = NULL;
   22.86 -            /* Under Linux, EIO occurs when a disk is not present.
   22.87 -               This isn't 100% reliable, so we use the USE_MNTENT
   22.88 -               code above instead.
   22.89 -             */
   22.90 -            if ((ioctl(cdfd, CDIOCREADSUBCHANNEL, &info) == 0) ||
   22.91 -                ERRNO_TRAYEMPTY(errno)) {
   22.92 -                is_cd = 1;
   22.93 -            }
   22.94 -            close(cdfd);
   22.95 -        }
   22.96 -    }
   22.97 -    return (is_cd);
   22.98 -}
   22.99 -
  22.100 -/* Add a CD-ROM drive to our list of valid drives */
  22.101 -static void
  22.102 -AddDrive(char *drive, struct stat *stbuf)
  22.103 -{
  22.104 -    int i;
  22.105 -
  22.106 -    if (SDL_numcds < MAX_DRIVES) {
  22.107 -        /* Check to make sure it's not already in our list.
  22.108 -           This can happen when we see a drive via symbolic link.
  22.109 -         */
  22.110 -        for (i = 0; i < SDL_numcds; ++i) {
  22.111 -            if (stbuf->st_rdev == SDL_cdmode[i]) {
  22.112 -#ifdef DEBUG_CDROM
  22.113 -                fprintf(stderr, "Duplicate drive detected: %s == %s\n",
  22.114 -                        drive, SDL_cdlist[i]);
  22.115 -#endif
  22.116 -                return;
  22.117 -            }
  22.118 -        }
  22.119 -
  22.120 -        /* Add this drive to our list */
  22.121 -        i = SDL_numcds;
  22.122 -        SDL_cdlist[i] = SDL_strdup(drive);
  22.123 -        if (SDL_cdlist[i] == NULL) {
  22.124 -            SDL_OutOfMemory();
  22.125 -            return;
  22.126 -        }
  22.127 -        SDL_cdmode[i] = stbuf->st_rdev;
  22.128 -        ++SDL_numcds;
  22.129 -#ifdef DEBUG_CDROM
  22.130 -        fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
  22.131 -#endif
  22.132 -    }
  22.133 -}
  22.134 -
  22.135 -int
  22.136 -SDL_SYS_CDInit(void)
  22.137 -{
  22.138 -    /* checklist: /dev/cdrom,/dev/cd?c /dev/acd?c
  22.139 -       /dev/matcd?c /dev/mcd?c /dev/scd?c */
  22.140 -    static char *checklist[] = {
  22.141 -        "cdrom", "?0 cd?", "?0 acd?", "?0 matcd?", "?0 mcd?", "?0 scd?", NULL
  22.142 -    };
  22.143 -    char *SDLcdrom;
  22.144 -    int i, j, exists;
  22.145 -    char drive[32];
  22.146 -    struct stat stbuf;
  22.147 -
  22.148 -    /* Fill in our driver capabilities */
  22.149 -    SDL_CDcaps.Name = SDL_SYS_CDName;
  22.150 -    SDL_CDcaps.Open = SDL_SYS_CDOpen;
  22.151 -    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
  22.152 -    SDL_CDcaps.Status = SDL_SYS_CDStatus;
  22.153 -    SDL_CDcaps.Play = SDL_SYS_CDPlay;
  22.154 -    SDL_CDcaps.Pause = SDL_SYS_CDPause;
  22.155 -    SDL_CDcaps.Resume = SDL_SYS_CDResume;
  22.156 -    SDL_CDcaps.Stop = SDL_SYS_CDStop;
  22.157 -    SDL_CDcaps.Eject = SDL_SYS_CDEject;
  22.158 -    SDL_CDcaps.Close = SDL_SYS_CDClose;
  22.159 -
  22.160 -    /* Look in the environment for our CD-ROM drive list */
  22.161 -    SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
  22.162 -    if (SDLcdrom != NULL) {
  22.163 -        char *cdpath, *delim;
  22.164 -        size_t len = SDL_strlen(SDLcdrom) + 1;
  22.165 -        cdpath = SDL_stack_alloc(char, len);
  22.166 -        if (cdpath != NULL) {
  22.167 -            SDL_strlcpy(cdpath, SDLcdrom, len);
  22.168 -            SDLcdrom = cdpath;
  22.169 -            do {
  22.170 -                delim = SDL_strchr(SDLcdrom, ':');
  22.171 -                if (delim) {
  22.172 -                    *delim++ = '\0';
  22.173 -                }
  22.174 -                if (CheckDrive(SDLcdrom, &stbuf) > 0) {
  22.175 -                    AddDrive(SDLcdrom, &stbuf);
  22.176 -                }
  22.177 -                if (delim) {
  22.178 -                    SDLcdrom = delim;
  22.179 -                } else {
  22.180 -                    SDLcdrom = NULL;
  22.181 -                }
  22.182 -            } while (SDLcdrom);
  22.183 -            SDL_stack_free(cdpath);
  22.184 -        }
  22.185 -
  22.186 -        /* If we found our drives, there's nothing left to do */
  22.187 -        if (SDL_numcds > 0) {
  22.188 -            return (0);
  22.189 -        }
  22.190 -    }
  22.191 -
  22.192 -    /* Scan the system for CD-ROM drives */
  22.193 -    for (i = 0; checklist[i]; ++i) {
  22.194 -        if (checklist[i][0] == '?') {
  22.195 -            char *insert;
  22.196 -            exists = 1;
  22.197 -            for (j = checklist[i][1]; exists; ++j) {
  22.198 -                SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%sc",
  22.199 -                             &checklist[i][3]);
  22.200 -                insert = SDL_strchr(drive, '?');
  22.201 -                if (insert != NULL) {
  22.202 -                    *insert = j;
  22.203 -                }
  22.204 -                switch (CheckDrive(drive, &stbuf)) {
  22.205 -                    /* Drive exists and is a CD-ROM */
  22.206 -                case 1:
  22.207 -                    AddDrive(drive, &stbuf);
  22.208 -                    break;
  22.209 -                    /* Drive exists, but isn't a CD-ROM */
  22.210 -                case 0:
  22.211 -                    break;
  22.212 -                    /* Drive doesn't exist */
  22.213 -                case -1:
  22.214 -                    exists = 0;
  22.215 -                    break;
  22.216 -                }
  22.217 -            }
  22.218 -        } else {
  22.219 -            SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
  22.220 -                         checklist[i]);
  22.221 -            if (CheckDrive(drive, &stbuf) > 0) {
  22.222 -                AddDrive(drive, &stbuf);
  22.223 -            }
  22.224 -        }
  22.225 -    }
  22.226 -    return (0);
  22.227 -}
  22.228 -
  22.229 -/* General ioctl() CD-ROM command function */
  22.230 -static int
  22.231 -SDL_SYS_CDioctl(int id, int command, void *arg)
  22.232 -{
  22.233 -    int retval;
  22.234 -
  22.235 -    retval = ioctl(id, command, arg);
  22.236 -    if (retval < 0) {
  22.237 -        SDL_SetError("ioctl() error: %s", strerror(errno));
  22.238 -    }
  22.239 -    return (retval);
  22.240 -}
  22.241 -
  22.242 -static const char *
  22.243 -SDL_SYS_CDName(int drive)
  22.244 -{
  22.245 -    return (SDL_cdlist[drive]);
  22.246 -}
  22.247 -
  22.248 -static int
  22.249 -SDL_SYS_CDOpen(int drive)
  22.250 -{
  22.251 -    return (open(SDL_cdlist[drive], (O_RDONLY | O_EXCL | O_NONBLOCK), 0));
  22.252 -}
  22.253 -
  22.254 -static int
  22.255 -SDL_SYS_CDGetTOC(SDL_CD * cdrom)
  22.256 -{
  22.257 -    struct ioc_toc_header toc;
  22.258 -    int i, okay;
  22.259 -    struct ioc_read_toc_entry entry;
  22.260 -    struct cd_toc_entry data;
  22.261 -
  22.262 -    okay = 0;
  22.263 -    if (SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0) {
  22.264 -        cdrom->numtracks = toc.ending_track - toc.starting_track + 1;
  22.265 -        if (cdrom->numtracks > SDL_MAX_TRACKS) {
  22.266 -            cdrom->numtracks = SDL_MAX_TRACKS;
  22.267 -        }
  22.268 -        /* Read all the track TOC entries */
  22.269 -        for (i = 0; i <= cdrom->numtracks; ++i) {
  22.270 -            if (i == cdrom->numtracks) {
  22.271 -                cdrom->track[i].id = 0xAA;      /* CDROM_LEADOUT */
  22.272 -            } else {
  22.273 -                cdrom->track[i].id = toc.starting_track + i;
  22.274 -            }
  22.275 -            entry.starting_track = cdrom->track[i].id;
  22.276 -            entry.address_format = CD_MSF_FORMAT;
  22.277 -            entry.data_len = sizeof(data);
  22.278 -            entry.data = &data;
  22.279 -            if (SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCENTRYS, &entry) < 0) {
  22.280 -                break;
  22.281 -            } else {
  22.282 -                cdrom->track[i].type = data.control;
  22.283 -                cdrom->track[i].offset =
  22.284 -                    MSF_TO_FRAMES(data.addr.msf.minute,
  22.285 -                                  data.addr.msf.second, data.addr.msf.frame);
  22.286 -                cdrom->track[i].length = 0;
  22.287 -                if (i > 0) {
  22.288 -                    cdrom->track[i - 1].length =
  22.289 -                        cdrom->track[i].offset - cdrom->track[i - 1].offset;
  22.290 -                }
  22.291 -            }
  22.292 -        }
  22.293 -        if (i == (cdrom->numtracks + 1)) {
  22.294 -            okay = 1;
  22.295 -        }
  22.296 -    }
  22.297 -    return (okay ? 0 : -1);
  22.298 -}
  22.299 -
  22.300 -/* Get CD-ROM status */
  22.301 -static CDstatus
  22.302 -SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
  22.303 -{
  22.304 -    CDstatus status;
  22.305 -    struct ioc_toc_header toc;
  22.306 -    struct ioc_read_subchannel info;
  22.307 -    struct cd_sub_channel_info data;
  22.308 -
  22.309 -    info.address_format = CD_MSF_FORMAT;
  22.310 -    info.data_format = CD_CURRENT_POSITION;
  22.311 -    info.track = 0;
  22.312 -    info.data_len = sizeof(data);
  22.313 -    info.data = &data;
  22.314 -    if (ioctl(cdrom->id, CDIOCREADSUBCHANNEL, &info) < 0) {
  22.315 -        if (ERRNO_TRAYEMPTY(errno)) {
  22.316 -            status = CD_TRAYEMPTY;
  22.317 -        } else {
  22.318 -            status = CD_ERROR;
  22.319 -        }
  22.320 -    } else {
  22.321 -        switch (data.header.audio_status) {
  22.322 -        case CD_AS_AUDIO_INVALID:
  22.323 -        case CD_AS_NO_STATUS:
  22.324 -            /* Try to determine if there's a CD available */
  22.325 -            if (ioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0)
  22.326 -                status = CD_STOPPED;
  22.327 -            else
  22.328 -                status = CD_TRAYEMPTY;
  22.329 -            break;
  22.330 -        case CD_AS_PLAY_COMPLETED:
  22.331 -            status = CD_STOPPED;
  22.332 -            break;
  22.333 -        case CD_AS_PLAY_IN_PROGRESS:
  22.334 -            status = CD_PLAYING;
  22.335 -            break;
  22.336 -        case CD_AS_PLAY_PAUSED:
  22.337 -            status = CD_PAUSED;
  22.338 -            break;
  22.339 -        default:
  22.340 -            status = CD_ERROR;
  22.341 -            break;
  22.342 -        }
  22.343 -    }
  22.344 -    if (position) {
  22.345 -        if (status == CD_PLAYING || (status == CD_PAUSED)) {
  22.346 -            *position =
  22.347 -                MSF_TO_FRAMES(data.what.position.absaddr.msf.minute,
  22.348 -                              data.what.position.absaddr.msf.second,
  22.349 -                              data.what.position.absaddr.msf.frame);
  22.350 -        } else {
  22.351 -            *position = 0;
  22.352 -        }
  22.353 -    }
  22.354 -    return (status);
  22.355 -}
  22.356 -
  22.357 -/* Start play */
  22.358 -static int
  22.359 -SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
  22.360 -{
  22.361 -    struct ioc_play_msf playtime;
  22.362 -
  22.363 -    FRAMES_TO_MSF(start,
  22.364 -                  &playtime.start_m, &playtime.start_s, &playtime.start_f);
  22.365 -    FRAMES_TO_MSF(start + length,
  22.366 -                  &playtime.end_m, &playtime.end_s, &playtime.end_f);
  22.367 -#ifdef DEBUG_CDROM
  22.368 -    fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
  22.369 -            playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0,
  22.370 -            playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1);
  22.371 -#endif
  22.372 -    ioctl(cdrom->id, CDIOCSTART, 0);
  22.373 -    return (SDL_SYS_CDioctl(cdrom->id, CDIOCPLAYMSF, &playtime));
  22.374 -}
  22.375 -
  22.376 -/* Pause play */
  22.377 -static int
  22.378 -SDL_SYS_CDPause(SDL_CD * cdrom)
  22.379 -{
  22.380 -    return (SDL_SYS_CDioctl(cdrom->id, CDIOCPAUSE, 0));
  22.381 -}
  22.382 -
  22.383 -/* Resume play */
  22.384 -static int
  22.385 -SDL_SYS_CDResume(SDL_CD * cdrom)
  22.386 -{
  22.387 -    return (SDL_SYS_CDioctl(cdrom->id, CDIOCRESUME, 0));
  22.388 -}
  22.389 -
  22.390 -/* Stop play */
  22.391 -static int
  22.392 -SDL_SYS_CDStop(SDL_CD * cdrom)
  22.393 -{
  22.394 -    return (SDL_SYS_CDioctl(cdrom->id, CDIOCSTOP, 0));
  22.395 -}
  22.396 -
  22.397 -/* Eject the CD-ROM */
  22.398 -static int
  22.399 -SDL_SYS_CDEject(SDL_CD * cdrom)
  22.400 -{
  22.401 -    return (SDL_SYS_CDioctl(cdrom->id, CDIOCEJECT, 0));
  22.402 -}
  22.403 -
  22.404 -/* Close the CD-ROM handle */
  22.405 -static void
  22.406 -SDL_SYS_CDClose(SDL_CD * cdrom)
  22.407 -{
  22.408 -    close(cdrom->id);
  22.409 -}
  22.410 -
  22.411 -void
  22.412 -SDL_SYS_CDQuit(void)
  22.413 -{
  22.414 -    int i;
  22.415 -
  22.416 -    if (SDL_numcds > 0) {
  22.417 -        for (i = 0; i < SDL_numcds; ++i) {
  22.418 -            SDL_free(SDL_cdlist[i]);
  22.419 -        }
  22.420 -        SDL_numcds = 0;
  22.421 -    }
  22.422 -}
  22.423 -
  22.424 -#endif /* SDL_CDROM_FREEBSD */
  22.425 -/* vi: set ts=4 sw=4 expandtab: */
    23.1 --- a/src/cdrom/linux/SDL_syscdrom.c	Sat Sep 05 09:03:35 2009 +0000
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,585 +0,0 @@
    23.4 -/*
    23.5 -    SDL - Simple DirectMedia Layer
    23.6 -    Copyright (C) 1997-2009 Sam Lantinga
    23.7 -
    23.8 -    This library is free software; you can redistribute it and/or
    23.9 -    modify it under the terms of the GNU Lesser General Public
   23.10 -    License as published by the Free Software Foundation; either
   23.11 -    version 2.1 of the License, or (at your option) any later version.
   23.12 -
   23.13 -    This library is distributed in the hope that it will be useful,
   23.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   23.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   23.16 -    Lesser General Public License for more details.
   23.17 -
   23.18 -    You should have received a copy of the GNU Lesser General Public
   23.19 -    License along with this library; if not, write to the Free Software
   23.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   23.21 -
   23.22 -    Sam Lantinga
   23.23 -    slouken@libsdl.org
   23.24 -*/
   23.25 -#include "SDL_config.h"
   23.26 -
   23.27 -#ifdef SDL_CDROM_LINUX
   23.28 -
   23.29 -/* Functions for system-level CD-ROM audio control */
   23.30 -
   23.31 -#include <string.h>             /* For strerror() */
   23.32 -#include <sys/types.h>
   23.33 -#include <sys/stat.h>
   23.34 -#include <sys/ioctl.h>
   23.35 -#include <fcntl.h>
   23.36 -#include <errno.h>
   23.37 -#include <unistd.h>
   23.38 -#ifdef __LINUX__
   23.39 -#ifdef HAVE_LINUX_VERSION_H
   23.40 -/* linux 2.6.9 workaround */
   23.41 -#include <linux/version.h>
   23.42 -#if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,9)
   23.43 -#include <asm/types.h>
   23.44 -#define __le64 __u64
   23.45 -#define __le32 __u32
   23.46 -#define __le16 __u16
   23.47 -#define __be64 __u64
   23.48 -#define __be32 __u32
   23.49 -#define __be16 __u16
   23.50 -#endif /* linux 2.6.9 workaround */
   23.51 -#endif /* HAVE_LINUX_VERSION_H */
   23.52 -#include <linux/cdrom.h>
   23.53 -#endif
   23.54 -#ifdef __SVR4
   23.55 -#include <sys/cdio.h>
   23.56 -#endif
   23.57 -
   23.58 -/* Define this to use the alternative getmntent() code */
   23.59 -#ifndef __SVR4
   23.60 -#define USE_MNTENT
   23.61 -#endif
   23.62 -
   23.63 -#ifdef USE_MNTENT
   23.64 -#if defined(__USLC__)
   23.65 -#include <sys/mntent.h>
   23.66 -#else
   23.67 -#include <mntent.h>
   23.68 -#endif
   23.69 -
   23.70 -#ifndef _PATH_MNTTAB
   23.71 -#ifdef MNTTAB
   23.72 -#define _PATH_MNTTAB	MNTTAB
   23.73 -#else
   23.74 -#define _PATH_MNTTAB	"/etc/fstab"
   23.75 -#endif
   23.76 -#endif /* !_PATH_MNTTAB */
   23.77 -
   23.78 -#ifndef _PATH_MOUNTED
   23.79 -#define _PATH_MOUNTED	"/etc/mtab"
   23.80 -#endif /* !_PATH_MOUNTED */
   23.81 -
   23.82 -#ifndef MNTTYPE_CDROM
   23.83 -#define MNTTYPE_CDROM	"iso9660"
   23.84 -#endif
   23.85 -#ifndef MNTTYPE_SUPER
   23.86 -#define MNTTYPE_SUPER	"supermount"
   23.87 -#endif
   23.88 -#endif /* USE_MNTENT */
   23.89 -
   23.90 -#include "SDL_cdrom.h"
   23.91 -#include "../SDL_syscdrom.h"
   23.92 -
   23.93 -
   23.94 -/* The maximum number of CD-ROM drives we'll detect */
   23.95 -#define MAX_DRIVES	16
   23.96 -
   23.97 -/* A list of available CD-ROM drives */
   23.98 -static char *SDL_cdlist[MAX_DRIVES];
   23.99 -static dev_t SDL_cdmode[MAX_DRIVES];
  23.100 -
  23.101 -/* The system-dependent CD control functions */
  23.102 -static const char *SDL_SYS_CDName(int drive);
  23.103 -static int SDL_SYS_CDOpen(int drive);
  23.104 -static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
  23.105 -static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
  23.106 -static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
  23.107 -static int SDL_SYS_CDPause(SDL_CD * cdrom);
  23.108 -static int SDL_SYS_CDResume(SDL_CD * cdrom);
  23.109 -static int SDL_SYS_CDStop(SDL_CD * cdrom);
  23.110 -static int SDL_SYS_CDEject(SDL_CD * cdrom);
  23.111 -static void SDL_SYS_CDClose(SDL_CD * cdrom);
  23.112 -
  23.113 -/* Some ioctl() errno values which occur when the tray is empty */
  23.114 -#ifndef ENOMEDIUM
  23.115 -#define ENOMEDIUM ENOENT
  23.116 -#endif
  23.117 -#define ERRNO_TRAYEMPTY(errno)	\
  23.118 -	((errno == EIO)    || (errno == ENOENT) || \
  23.119 -	 (errno == EINVAL) || (errno == ENOMEDIUM))
  23.120 -
  23.121 -/* Check a drive to see if it is a CD-ROM */
  23.122 -static int
  23.123 -CheckDrive(char *drive, char *mnttype, struct stat *stbuf)
  23.124 -{
  23.125 -    int is_cd, cdfd;
  23.126 -    struct cdrom_subchnl info;
  23.127 -
  23.128 -    /* If it doesn't exist, return -1 */
  23.129 -    if (stat(drive, stbuf) < 0) {
  23.130 -        return (-1);
  23.131 -    }
  23.132 -
  23.133 -    /* If it does exist, verify that it's an available CD-ROM */
  23.134 -    is_cd = 0;
  23.135 -    if (S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode)) {
  23.136 -        cdfd = open(drive, (O_RDONLY | O_NONBLOCK), 0);
  23.137 -        if (cdfd >= 0) {
  23.138 -            info.cdsc_format = CDROM_MSF;
  23.139 -            /* Under Linux, EIO occurs when a disk is not present.
  23.140 -             */
  23.141 -            if ((ioctl(cdfd, CDROMSUBCHNL, &info) == 0) ||
  23.142 -                ERRNO_TRAYEMPTY(errno)) {
  23.143 -                is_cd = 1;
  23.144 -            }
  23.145 -            close(cdfd);
  23.146 -        }
  23.147 -#ifdef USE_MNTENT
  23.148 -        /* Even if we can't read it, it might be mounted */
  23.149 -        else if (mnttype && (SDL_strcmp(mnttype, MNTTYPE_CDROM) == 0)) {
  23.150 -            is_cd = 1;
  23.151 -        }
  23.152 -#endif
  23.153 -    }
  23.154 -    return (is_cd);
  23.155 -}
  23.156 -
  23.157 -/* Add a CD-ROM drive to our list of valid drives */
  23.158 -static void
  23.159 -AddDrive(char *drive, struct stat *stbuf)
  23.160 -{
  23.161 -    int i;
  23.162 -
  23.163 -    if (SDL_numcds < MAX_DRIVES) {
  23.164 -        /* Check to make sure it's not already in our list.
  23.165 -           This can happen when we see a drive via symbolic link.
  23.166 -         */
  23.167 -        for (i = 0; i < SDL_numcds; ++i) {
  23.168 -            if (stbuf->st_rdev == SDL_cdmode[i]) {
  23.169 -#ifdef DEBUG_CDROM
  23.170 -                fprintf(stderr, "Duplicate drive detected: %s == %s\n",
  23.171 -                        drive, SDL_cdlist[i]);
  23.172 -#endif
  23.173 -                return;
  23.174 -            }
  23.175 -        }
  23.176 -
  23.177 -        /* Add this drive to our list */
  23.178 -        i = SDL_numcds;
  23.179 -        SDL_cdlist[i] = SDL_strdup(drive);
  23.180 -        if (SDL_cdlist[i] == NULL) {
  23.181 -            SDL_OutOfMemory();
  23.182 -            return;
  23.183 -        }
  23.184 -        SDL_cdmode[i] = stbuf->st_rdev;
  23.185 -        ++SDL_numcds;
  23.186 -#ifdef DEBUG_CDROM
  23.187 -        fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
  23.188 -#endif
  23.189 -    }
  23.190 -}
  23.191 -
  23.192 -#ifdef USE_MNTENT
  23.193 -static void
  23.194 -CheckMounts(const char *mtab)
  23.195 -{
  23.196 -    FILE *mntfp;
  23.197 -    struct mntent *mntent;
  23.198 -    struct stat stbuf;
  23.199 -
  23.200 -    mntfp = setmntent(mtab, "r");
  23.201 -    if (mntfp != NULL) {
  23.202 -        char *tmp;
  23.203 -        char *mnt_type;
  23.204 -        size_t mnt_type_len;
  23.205 -        char *mnt_dev;
  23.206 -        size_t mnt_dev_len;
  23.207 -
  23.208 -        while ((mntent = getmntent(mntfp)) != NULL) {
  23.209 -            mnt_type_len = SDL_strlen(mntent->mnt_type) + 1;
  23.210 -            mnt_type = SDL_stack_alloc(char, mnt_type_len);
  23.211 -            if (mnt_type == NULL)
  23.212 -                continue;       /* maybe you'll get lucky next time. */
  23.213 -
  23.214 -            mnt_dev_len = SDL_strlen(mntent->mnt_fsname) + 1;
  23.215 -            mnt_dev = SDL_stack_alloc(char, mnt_dev_len);
  23.216 -            if (mnt_dev == NULL) {
  23.217 -                SDL_stack_free(mnt_type);
  23.218 -                continue;
  23.219 -            }
  23.220 -
  23.221 -            SDL_strlcpy(mnt_type, mntent->mnt_type, mnt_type_len);
  23.222 -            SDL_strlcpy(mnt_dev, mntent->mnt_fsname, mnt_dev_len);
  23.223 -
  23.224 -            /* Handle "supermount" filesystem mounts */
  23.225 -            if (SDL_strcmp(mnt_type, MNTTYPE_SUPER) == 0) {
  23.226 -                tmp = SDL_strstr(mntent->mnt_opts, "fs=");
  23.227 -                if (tmp) {
  23.228 -                    SDL_stack_free(mnt_type);
  23.229 -                    mnt_type = SDL_strdup(tmp + SDL_strlen("fs="));
  23.230 -                    if (mnt_type) {
  23.231 -                        tmp = SDL_strchr(mnt_type, ',');
  23.232 -                        if (tmp) {
  23.233 -                            *tmp = '\0';
  23.234 -                        }
  23.235 -                    }
  23.236 -                }
  23.237 -                tmp = SDL_strstr(mntent->mnt_opts, "dev=");
  23.238 -                if (tmp) {
  23.239 -                    SDL_stack_free(mnt_dev);
  23.240 -                    mnt_dev = SDL_strdup(tmp + SDL_strlen("dev="));
  23.241 -                    if (mnt_dev) {
  23.242 -                        tmp = SDL_strchr(mnt_dev, ',');
  23.243 -                        if (tmp) {
  23.244 -                            *tmp = '\0';
  23.245 -                        }
  23.246 -                    }
  23.247 -                }
  23.248 -            }
  23.249 -            if (SDL_strcmp(mnt_type, MNTTYPE_CDROM) == 0) {
  23.250 -#ifdef DEBUG_CDROM
  23.251 -                fprintf(stderr,
  23.252 -                        "Checking mount path from %s: %s mounted on %s of %s\n",
  23.253 -                        mtab, mnt_dev, mntent->mnt_dir, mnt_type);
  23.254 -#endif
  23.255 -                if (CheckDrive(mnt_dev, mnt_type, &stbuf) > 0) {
  23.256 -                    AddDrive(mnt_dev, &stbuf);
  23.257 -                }
  23.258 -            }
  23.259 -            SDL_stack_free(mnt_dev);
  23.260 -            SDL_stack_free(mnt_type);
  23.261 -        }
  23.262 -        endmntent(mntfp);
  23.263 -    }
  23.264 -}
  23.265 -#endif /* USE_MNTENT */
  23.266 -
  23.267 -int
  23.268 -SDL_SYS_CDInit(void)
  23.269 -{
  23.270 -    /* checklist: /dev/cdrom, /dev/hd?, /dev/scd? /dev/sr? */
  23.271 -    static char *checklist[] = {
  23.272 -        "cdrom", "?a hd?", "?0 scd?", "?0 sr?", NULL
  23.273 -    };
  23.274 -    char *SDLcdrom;
  23.275 -    int i, j, exists;
  23.276 -    char drive[32];
  23.277 -    struct stat stbuf;
  23.278 -
  23.279 -    /* Fill in our driver capabilities */
  23.280 -    SDL_CDcaps.Name = SDL_SYS_CDName;
  23.281 -    SDL_CDcaps.Open = SDL_SYS_CDOpen;
  23.282 -    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
  23.283 -    SDL_CDcaps.Status = SDL_SYS_CDStatus;
  23.284 -    SDL_CDcaps.Play = SDL_SYS_CDPlay;
  23.285 -    SDL_CDcaps.Pause = SDL_SYS_CDPause;
  23.286 -    SDL_CDcaps.Resume = SDL_SYS_CDResume;
  23.287 -    SDL_CDcaps.Stop = SDL_SYS_CDStop;
  23.288 -    SDL_CDcaps.Eject = SDL_SYS_CDEject;
  23.289 -    SDL_CDcaps.Close = SDL_SYS_CDClose;
  23.290 -
  23.291 -    /* Look in the environment for our CD-ROM drive list */
  23.292 -    SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
  23.293 -    if (SDLcdrom != NULL) {
  23.294 -        char *cdpath, *delim;
  23.295 -        size_t len = SDL_strlen(SDLcdrom) + 1;
  23.296 -        cdpath = SDL_stack_alloc(char, len);
  23.297 -        if (cdpath != NULL) {
  23.298 -            SDL_strlcpy(cdpath, SDLcdrom, len);
  23.299 -            SDLcdrom = cdpath;
  23.300 -            do {
  23.301 -                delim = SDL_strchr(SDLcdrom, ':');
  23.302 -                if (delim) {
  23.303 -                    *delim++ = '\0';
  23.304 -                }
  23.305 -#ifdef DEBUG_CDROM
  23.306 -                fprintf(stderr,
  23.307 -                        "Checking CD-ROM drive from SDL_CDROM: %s\n",
  23.308 -                        SDLcdrom);
  23.309 -#endif
  23.310 -                if (CheckDrive(SDLcdrom, NULL, &stbuf) > 0) {
  23.311 -                    AddDrive(SDLcdrom, &stbuf);
  23.312 -                }
  23.313 -                if (delim) {
  23.314 -                    SDLcdrom = delim;
  23.315 -                } else {
  23.316 -                    SDLcdrom = NULL;
  23.317 -                }
  23.318 -            } while (SDLcdrom);
  23.319 -            SDL_stack_free(cdpath);
  23.320 -        }
  23.321 -
  23.322 -        /* If we found our drives, there's nothing left to do */
  23.323 -        if (SDL_numcds > 0) {
  23.324 -            return (0);
  23.325 -        }
  23.326 -    }
  23.327 -#ifdef USE_MNTENT
  23.328 -    /* Check /dev/cdrom first :-) */
  23.329 -    if (CheckDrive("/dev/cdrom", NULL, &stbuf) > 0) {
  23.330 -        AddDrive("/dev/cdrom", &stbuf);
  23.331 -    }
  23.332 -
  23.333 -    /* Now check the currently mounted CD drives */
  23.334 -    CheckMounts(_PATH_MOUNTED);
  23.335 -
  23.336 -    /* Finally check possible mountable drives in /etc/fstab */
  23.337 -    CheckMounts(_PATH_MNTTAB);
  23.338 -
  23.339 -    /* If we found our drives, there's nothing left to do */
  23.340 -    if (SDL_numcds > 0) {
  23.341 -        return (0);
  23.342 -    }
  23.343 -#endif /* USE_MNTENT */
  23.344 -
  23.345 -    /* Scan the system for CD-ROM drives.
  23.346 -       Not always 100% reliable, so use the USE_MNTENT code above first.
  23.347 -     */
  23.348 -    for (i = 0; checklist[i]; ++i) {
  23.349 -        if (checklist[i][0] == '?') {
  23.350 -            char *insert;
  23.351 -            exists = 1;
  23.352 -            for (j = checklist[i][1]; exists; ++j) {
  23.353 -                SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
  23.354 -                             &checklist[i][3]);
  23.355 -                insert = SDL_strchr(drive, '?');
  23.356 -                if (insert != NULL) {
  23.357 -                    *insert = j;
  23.358 -                }
  23.359 -#ifdef DEBUG_CDROM
  23.360 -                fprintf(stderr, "Checking possible CD-ROM drive: %s\n",
  23.361 -                        drive);
  23.362 -#endif
  23.363 -                switch (CheckDrive(drive, NULL, &stbuf)) {
  23.364 -                    /* Drive exists and is a CD-ROM */
  23.365 -                case 1:
  23.366 -                    AddDrive(drive, &stbuf);
  23.367 -                    break;
  23.368 -                    /* Drive exists, but isn't a CD-ROM */
  23.369 -                case 0:
  23.370 -                    break;
  23.371 -                    /* Drive doesn't exist */
  23.372 -                case -1:
  23.373 -                    exists = 0;
  23.374 -                    break;
  23.375 -                }
  23.376 -            }
  23.377 -        } else {
  23.378 -            SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
  23.379 -                         checklist[i]);
  23.380 -#ifdef DEBUG_CDROM
  23.381 -            fprintf(stderr, "Checking possible CD-ROM drive: %s\n", drive);
  23.382 -#endif
  23.383 -            if (CheckDrive(drive, NULL, &stbuf) > 0) {
  23.384 -                AddDrive(drive, &stbuf);
  23.385 -            }
  23.386 -        }
  23.387 -    }
  23.388 -    return (0);
  23.389 -}
  23.390 -
  23.391 -/* General ioctl() CD-ROM command function */
  23.392 -static int
  23.393 -SDL_SYS_CDioctl(int id, int command, void *arg)
  23.394 -{
  23.395 -    int retval;
  23.396 -
  23.397 -    retval = ioctl(id, command, arg);
  23.398 -    if (retval < 0) {
  23.399 -        SDL_SetError("ioctl() error: %s", strerror(errno));
  23.400 -    }
  23.401 -    return (retval);
  23.402 -}
  23.403 -
  23.404 -static const char *
  23.405 -SDL_SYS_CDName(int drive)
  23.406 -{
  23.407 -    return (SDL_cdlist[drive]);
  23.408 -}
  23.409 -
  23.410 -static int
  23.411 -SDL_SYS_CDOpen(int drive)
  23.412 -{
  23.413 -    return (open(SDL_cdlist[drive], (O_RDONLY | O_NONBLOCK), 0));
  23.414 -}
  23.415 -
  23.416 -static int
  23.417 -SDL_SYS_CDGetTOC(SDL_CD * cdrom)
  23.418 -{
  23.419 -    struct cdrom_tochdr toc;
  23.420 -    int i, okay;
  23.421 -    struct cdrom_tocentry entry;
  23.422 -
  23.423 -    okay = 0;
  23.424 -    if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc) == 0) {
  23.425 -        cdrom->numtracks = toc.cdth_trk1 - toc.cdth_trk0 + 1;
  23.426 -        if (cdrom->numtracks > SDL_MAX_TRACKS) {
  23.427 -            cdrom->numtracks = SDL_MAX_TRACKS;
  23.428 -        }
  23.429 -        /* Read all the track TOC entries */
  23.430 -        for (i = 0; i <= cdrom->numtracks; ++i) {
  23.431 -            if (i == cdrom->numtracks) {
  23.432 -                cdrom->track[i].id = CDROM_LEADOUT;
  23.433 -            } else {
  23.434 -                cdrom->track[i].id = toc.cdth_trk0 + i;
  23.435 -            }
  23.436 -            entry.cdte_track = cdrom->track[i].id;
  23.437 -            entry.cdte_format = CDROM_MSF;
  23.438 -            if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCENTRY, &entry) < 0) {
  23.439 -                break;
  23.440 -            } else {
  23.441 -                if (entry.cdte_ctrl & CDROM_DATA_TRACK) {
  23.442 -                    cdrom->track[i].type = SDL_DATA_TRACK;
  23.443 -                } else {
  23.444 -                    cdrom->track[i].type = SDL_AUDIO_TRACK;
  23.445 -                }
  23.446 -                cdrom->track[i].offset =
  23.447 -                    MSF_TO_FRAMES(entry.cdte_addr.msf.minute,
  23.448 -                                  entry.cdte_addr.msf.second,
  23.449 -                                  entry.cdte_addr.msf.frame);
  23.450 -                cdrom->track[i].length = 0;
  23.451 -                if (i > 0) {
  23.452 -                    cdrom->track[i - 1].length =
  23.453 -                        cdrom->track[i].offset - cdrom->track[i - 1].offset;
  23.454 -                }
  23.455 -            }
  23.456 -        }
  23.457 -        if (i == (cdrom->numtracks + 1)) {
  23.458 -            okay = 1;
  23.459 -        }
  23.460 -    }
  23.461 -    return (okay ? 0 : -1);
  23.462 -}
  23.463 -
  23.464 -/* Get CD-ROM status */
  23.465 -static CDstatus
  23.466 -SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
  23.467 -{
  23.468 -    CDstatus status;
  23.469 -    struct cdrom_tochdr toc;
  23.470 -    struct cdrom_subchnl info;
  23.471 -
  23.472 -    info.cdsc_format = CDROM_MSF;
  23.473 -    if (ioctl(cdrom->id, CDROMSUBCHNL, &info) < 0) {
  23.474 -        if (ERRNO_TRAYEMPTY(errno)) {
  23.475 -            status = CD_TRAYEMPTY;
  23.476 -        } else {
  23.477 -            status = CD_ERROR;
  23.478 -        }
  23.479 -    } else {
  23.480 -        switch (info.cdsc_audiostatus) {
  23.481 -        case CDROM_AUDIO_INVALID:
  23.482 -        case CDROM_AUDIO_NO_STATUS:
  23.483 -            /* Try to determine if there's a CD available */
  23.484 -            if (ioctl(cdrom->id, CDROMREADTOCHDR, &toc) == 0)
  23.485 -                status = CD_STOPPED;
  23.486 -            else
  23.487 -                status = CD_TRAYEMPTY;
  23.488 -            break;
  23.489 -        case CDROM_AUDIO_COMPLETED:
  23.490 -            status = CD_STOPPED;
  23.491 -            break;
  23.492 -        case CDROM_AUDIO_PLAY:
  23.493 -            status = CD_PLAYING;
  23.494 -            break;
  23.495 -        case CDROM_AUDIO_PAUSED:
  23.496 -            /* Workaround buggy CD-ROM drive */
  23.497 -            if (info.cdsc_trk == CDROM_LEADOUT) {
  23.498 -                status = CD_STOPPED;
  23.499 -            } else {
  23.500 -                status = CD_PAUSED;
  23.501 -            }
  23.502 -            break;
  23.503 -        default:
  23.504 -            status = CD_ERROR;
  23.505 -            break;
  23.506 -        }
  23.507 -    }
  23.508 -    if (position) {
  23.509 -        if (status == CD_PLAYING || (status == CD_PAUSED)) {
  23.510 -            *position = MSF_TO_FRAMES(info.cdsc_absaddr.msf.minute,
  23.511 -                                      info.cdsc_absaddr.msf.second,
  23.512 -                                      info.cdsc_absaddr.msf.frame);
  23.513 -        } else {
  23.514 -            *position = 0;
  23.515 -        }
  23.516 -    }
  23.517 -    return (status);
  23.518 -}
  23.519 -
  23.520 -/* Start play */
  23.521 -static int
  23.522 -SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
  23.523 -{
  23.524 -    struct cdrom_msf playtime;
  23.525 -
  23.526 -    FRAMES_TO_MSF(start,
  23.527 -                  &playtime.cdmsf_min0, &playtime.cdmsf_sec0,
  23.528 -                  &playtime.cdmsf_frame0);
  23.529 -    FRAMES_TO_MSF(start + length, &playtime.cdmsf_min1, &playtime.cdmsf_sec1,
  23.530 -                  &playtime.cdmsf_frame1);
  23.531 -#ifdef DEBUG_CDROM
  23.532 -    fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
  23.533 -            playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0,
  23.534 -            playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1);
  23.535 -#endif
  23.536 -    return (SDL_SYS_CDioctl(cdrom->id, CDROMPLAYMSF, &playtime));
  23.537 -}
  23.538 -
  23.539 -/* Pause play */
  23.540 -static int
  23.541 -SDL_SYS_CDPause(SDL_CD * cdrom)
  23.542 -{
  23.543 -    return (SDL_SYS_CDioctl(cdrom->id, CDROMPAUSE, 0));
  23.544 -}
  23.545 -
  23.546 -/* Resume play */
  23.547 -static int
  23.548 -SDL_SYS_CDResume(SDL_CD * cdrom)
  23.549 -{
  23.550 -    return (SDL_SYS_CDioctl(cdrom->id, CDROMRESUME, 0));
  23.551 -}
  23.552 -
  23.553 -/* Stop play */
  23.554 -static int
  23.555 -SDL_SYS_CDStop(SDL_CD * cdrom)
  23.556 -{
  23.557 -    return (SDL_SYS_CDioctl(cdrom->id, CDROMSTOP, 0));
  23.558 -}
  23.559 -
  23.560 -/* Eject the CD-ROM */
  23.561 -static int
  23.562 -SDL_SYS_CDEject(SDL_CD * cdrom)
  23.563 -{
  23.564 -    return (SDL_SYS_CDioctl(cdrom->id, CDROMEJECT, 0));
  23.565 -}
  23.566 -
  23.567 -/* Close the CD-ROM handle */
  23.568 -static void
  23.569 -SDL_SYS_CDClose(SDL_CD * cdrom)
  23.570 -{
  23.571 -    close(cdrom->id);
  23.572 -}
  23.573 -
  23.574 -void
  23.575 -SDL_SYS_CDQuit(void)
  23.576 -{
  23.577 -    int i;
  23.578 -
  23.579 -    if (SDL_numcds > 0) {
  23.580 -        for (i = 0; i < SDL_numcds; ++i) {
  23.581 -            SDL_free(SDL_cdlist[i]);
  23.582 -        }
  23.583 -        SDL_numcds = 0;
  23.584 -    }
  23.585 -}
  23.586 -
  23.587 -#endif /* SDL_CDROM_LINUX */
  23.588 -/* vi: set ts=4 sw=4 expandtab: */
    24.1 --- a/src/cdrom/macosx/AudioFilePlayer.c	Sat Sep 05 09:03:35 2009 +0000
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,397 +0,0 @@
    24.4 -/*
    24.5 -    SDL - Simple DirectMedia Layer
    24.6 -    Copyright (C) 1997-2009 Sam Lantinga
    24.7 -
    24.8 -    This library is free software; you can redistribute it and/or
    24.9 -    modify it under the terms of the GNU Library General Public
   24.10 -    License as published by the Free Software Foundation; either
   24.11 -    version 2 of the License, or (at your option) any later version.
   24.12 -
   24.13 -    This library is distributed in the hope that it will be useful,
   24.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   24.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   24.16 -    Library General Public License for more details.
   24.17 -
   24.18 -    You should have received a copy of the GNU Library General Public
   24.19 -    License along with this library; if not, write to the Free
   24.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24.21 -
   24.22 -    Sam Lantinga
   24.23 -    slouken@libsdl.org
   24.24 -
   24.25 -    This file based on Apple sample code. We haven't changed the file name, 
   24.26 -    so if you want to see the original search for it on apple.com/developer
   24.27 -*/
   24.28 -#include "SDL_config.h"
   24.29 -
   24.30 -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   24.31 -    AudioFilePlayer.cpp
   24.32 -*/
   24.33 -#include "AudioFilePlayer.h"
   24.34 -
   24.35 -/*
   24.36 -void ThrowResult (OSStatus result, const char* str)
   24.37 -{
   24.38 -    SDL_SetError ("Error: %s %d", str, result);
   24.39 -    throw result;
   24.40 -}
   24.41 -*/
   24.42 -
   24.43 -#if DEBUG
   24.44 -static void
   24.45 -PrintStreamDesc(AudioStreamBasicDescription * inDesc)
   24.46 -{
   24.47 -    if (!inDesc) {
   24.48 -        printf("Can't print a NULL desc!\n");
   24.49 -        return;
   24.50 -    }
   24.51 -
   24.52 -    printf("- - - - - - - - - - - - - - - - - - - -\n");
   24.53 -    printf("  Sample Rate:%f\n", inDesc->mSampleRate);
   24.54 -    printf("  Format ID:%s\n", (char *) &inDesc->mFormatID);
   24.55 -    printf("  Format Flags:%lX\n", inDesc->mFormatFlags);
   24.56 -    printf("  Bytes per Packet:%ld\n", inDesc->mBytesPerPacket);
   24.57 -    printf("  Frames per Packet:%ld\n", inDesc->mFramesPerPacket);
   24.58 -    printf("  Bytes per Frame:%ld\n", inDesc->mBytesPerFrame);
   24.59 -    printf("  Channels per Frame:%ld\n", inDesc->mChannelsPerFrame);
   24.60 -    printf("  Bits per Channel:%ld\n", inDesc->mBitsPerChannel);
   24.61 -    printf("- - - - - - - - - - - - - - - - - - - -\n");
   24.62 -}
   24.63 -#endif
   24.64 -
   24.65 -
   24.66 -static int
   24.67 -AudioFilePlayer_SetDestination(AudioFilePlayer * afp, AudioUnit * inDestUnit)
   24.68 -{
   24.69 -    /*if (afp->mConnected) throw static_cast<OSStatus>(-1); *//* can't set dest if already engaged */
   24.70 -    if (afp->mConnected)
   24.71 -        return 0;
   24.72 -
   24.73 -    SDL_memcpy(&afp->mPlayUnit, inDestUnit, sizeof(afp->mPlayUnit));
   24.74 -
   24.75 -    OSStatus result = noErr;
   24.76 -
   24.77 -
   24.78 -    /* we can "down" cast a component instance to a component */
   24.79 -    ComponentDescription desc;
   24.80 -    result = GetComponentInfo((Component) * inDestUnit, &desc, 0, 0, 0);
   24.81 -    if (result)
   24.82 -        return 0;               /*THROW_RESULT("GetComponentInfo") */
   24.83 -
   24.84 -    /* we're going to use this to know which convert routine to call
   24.85 -       a v1 audio unit will have a type of 'aunt'
   24.86 -       a v2 audio unit will have one of several different types. */
   24.87 -    if (desc.componentType != kAudioUnitComponentType) {
   24.88 -        result = badComponentInstance;
   24.89 -        /*THROW_RESULT("BAD COMPONENT") */
   24.90 -        if (result)
   24.91 -            return 0;
   24.92 -    }
   24.93 -
   24.94 -    /* Set the input format of the audio unit. */
   24.95 -    result = AudioUnitSetProperty(*inDestUnit,
   24.96 -                                  kAudioUnitProperty_StreamFormat,
   24.97 -                                  kAudioUnitScope_Input,
   24.98 -                                  0,
   24.99 -                                  &afp->mFileDescription,
  24.100 -                                  sizeof(afp->mFileDescription));
  24.101 -    /*THROW_RESULT("AudioUnitSetProperty") */
  24.102 -    if (result)
  24.103 -        return 0;
  24.104 -    return 1;
  24.105 -}
  24.106 -
  24.107 -static void
  24.108 -AudioFilePlayer_SetNotifier(AudioFilePlayer * afp,
  24.109 -                            AudioFilePlayNotifier inNotifier, void *inRefCon)
  24.110 -{
  24.111 -    afp->mNotifier = inNotifier;
  24.112 -    afp->mRefCon = inRefCon;
  24.113 -}
  24.114 -
  24.115 -static int
  24.116 -AudioFilePlayer_IsConnected(AudioFilePlayer * afp)
  24.117 -{
  24.118 -    return afp->mConnected;
  24.119 -}
  24.120 -
  24.121 -static AudioUnit
  24.122 -AudioFilePlayer_GetDestUnit(AudioFilePlayer * afp)
  24.123 -{
  24.124 -    return afp->mPlayUnit;
  24.125 -}
  24.126 -
  24.127 -static void
  24.128 -AudioFilePlayer_Print(AudioFilePlayer * afp)
  24.129 -{
  24.130 -#if DEBUG
  24.131 -    printf("Is Connected:%s\n", (IsConnected()? "true" : "false"));
  24.132 -    printf("- - - - - - - - - - - - - - \n");
  24.133 -#endif
  24.134 -}
  24.135 -
  24.136 -static void
  24.137 -AudioFilePlayer_SetStartFrame(AudioFilePlayer * afp, int frame)
  24.138 -{
  24.139 -    SInt64 position = frame * 2352;
  24.140 -
  24.141 -    afp->mStartFrame = frame;
  24.142 -    afp->mAudioFileManager->SetPosition(afp->mAudioFileManager, position);
  24.143 -}
  24.144 -
  24.145 -
  24.146 -static int
  24.147 -AudioFilePlayer_GetCurrentFrame(AudioFilePlayer * afp)
  24.148 -{
  24.149 -    return afp->mStartFrame +
  24.150 -        (afp->mAudioFileManager->GetByteCounter(afp->mAudioFileManager) /
  24.151 -         2352);
  24.152 -}
  24.153 -
  24.154 -static void
  24.155 -AudioFilePlayer_SetStopFrame(AudioFilePlayer * afp, int frame)
  24.156 -{
  24.157 -    SInt64 position = frame * 2352;
  24.158 -
  24.159 -    afp->mAudioFileManager->SetEndOfFile(afp->mAudioFileManager, position);
  24.160 -}
  24.161 -
  24.162 -void
  24.163 -delete_AudioFilePlayer(AudioFilePlayer * afp)
  24.164 -{
  24.165 -    if (afp != NULL) {
  24.166 -        afp->Disconnect(afp);
  24.167 -
  24.168 -        if (afp->mAudioFileManager) {
  24.169 -            delete_AudioFileManager(afp->mAudioFileManager);
  24.170 -            afp->mAudioFileManager = 0;
  24.171 -        }
  24.172 -
  24.173 -        if (afp->mForkRefNum) {
  24.174 -            FSCloseFork(afp->mForkRefNum);
  24.175 -            afp->mForkRefNum = 0;
  24.176 -        }
  24.177 -        SDL_free(afp);
  24.178 -    }
  24.179 -}
  24.180 -
  24.181 -static int
  24.182 -AudioFilePlayer_Connect(AudioFilePlayer * afp)
  24.183 -{
  24.184 -#if DEBUG
  24.185 -    printf("Connect:%x, engaged=%d\n", (int) afp->mPlayUnit,
  24.186 -           (afp->mConnected ? 1 : 0));
  24.187 -#endif
  24.188 -    if (!afp->mConnected) {
  24.189 -        if (!afp->mAudioFileManager->DoConnect(afp->mAudioFileManager))
  24.190 -            return 0;
  24.191 -
  24.192 -        /* set the render callback for the file data to be supplied to the sound converter AU */
  24.193 -        afp->mInputCallback.inputProc = afp->mAudioFileManager->FileInputProc;
  24.194 -        afp->mInputCallback.inputProcRefCon = afp->mAudioFileManager;
  24.195 -
  24.196 -        OSStatus result = AudioUnitSetProperty(afp->mPlayUnit,
  24.197 -                                               kAudioUnitProperty_SetInputCallback,
  24.198 -                                               kAudioUnitScope_Input,
  24.199 -                                               0,
  24.200 -                                               &afp->mInputCallback,
  24.201 -                                               sizeof(afp->mInputCallback));
  24.202 -        if (result)
  24.203 -            return 0;           /*THROW_RESULT("AudioUnitSetProperty") */
  24.204 -        afp->mConnected = 1;
  24.205 -    }
  24.206 -
  24.207 -    return 1;
  24.208 -}
  24.209 -
  24.210 -/* warning noted, now please go away ;-) */
  24.211 -/* #warning This should redirect the calling of notification code to some other thread */
  24.212 -static void
  24.213 -AudioFilePlayer_DoNotification(AudioFilePlayer * afp, OSStatus inStatus)
  24.214 -{
  24.215 -    if (afp->mNotifier) {
  24.216 -        (*afp->mNotifier) (afp->mRefCon, inStatus);
  24.217 -    } else {
  24.218 -        SDL_SetError("Notification posted with no notifier in place");
  24.219 -
  24.220 -        if (inStatus == kAudioFilePlay_FileIsFinished)
  24.221 -            afp->Disconnect(afp);
  24.222 -        else if (inStatus != kAudioFilePlayErr_FilePlayUnderrun)
  24.223 -            afp->Disconnect(afp);
  24.224 -    }
  24.225 -}
  24.226 -
  24.227 -static void
  24.228 -AudioFilePlayer_Disconnect(AudioFilePlayer * afp)
  24.229 -{
  24.230 -#if DEBUG
  24.231 -    printf("Disconnect:%x,%ld, engaged=%d\n", (int) afp->mPlayUnit, 0,
  24.232 -           (afp->mConnected ? 1 : 0));
  24.233 -#endif
  24.234 -    if (afp->mConnected) {
  24.235 -        afp->mConnected = 0;
  24.236 -
  24.237 -        afp->mInputCallback.inputProc = 0;
  24.238 -        afp->mInputCallback.inputProcRefCon = 0;
  24.239 -        OSStatus result = AudioUnitSetProperty(afp->mPlayUnit,
  24.240 -                                               kAudioUnitProperty_SetInputCallback,
  24.241 -                                               kAudioUnitScope_Input,
  24.242 -                                               0,
  24.243 -                                               &afp->mInputCallback,
  24.244 -                                               sizeof(afp->mInputCallback));
  24.245 -        if (result)
  24.246 -            SDL_SetError("AudioUnitSetProperty:RemoveInputCallback:%ld",
  24.247 -                         result);
  24.248 -
  24.249 -        afp->mAudioFileManager->Disconnect(afp->mAudioFileManager);
  24.250 -    }
  24.251 -}
  24.252 -
  24.253 -typedef struct
  24.254 -{
  24.255 -    UInt32 offset;
  24.256 -    UInt32 blockSize;
  24.257 -} SSNDData;
  24.258 -
  24.259 -static int
  24.260 -AudioFilePlayer_OpenFile(AudioFilePlayer * afp, const FSRef * inRef,
  24.261 -                         SInt64 * outFileDataSize)
  24.262 -{
  24.263 -    ContainerChunk chunkHeader;
  24.264 -    ChunkHeader chunk;
  24.265 -    SSNDData ssndData;
  24.266 -
  24.267 -    OSErr result;
  24.268 -    HFSUniStr255 dfName;
  24.269 -    ByteCount actual;
  24.270 -    SInt64 offset;
  24.271 -
  24.272 -    /* Open the data fork of the input file */
  24.273 -    result = FSGetDataForkName(&dfName);
  24.274 -    if (result)
  24.275 -        return 0;               /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSGetDataForkName") */
  24.276 -
  24.277 -    result =
  24.278 -        FSOpenFork(inRef, dfName.length, dfName.unicode, fsRdPerm,
  24.279 -                   &afp->mForkRefNum);
  24.280 -    if (result)
  24.281 -        return 0;               /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSOpenFork") */
  24.282 -
  24.283 -    /* Read the file header, and check if it's indeed an AIFC file */
  24.284 -    result =
  24.285 -        FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(chunkHeader),
  24.286 -                   &chunkHeader, &actual);
  24.287 -    if (result)
  24.288 -        return 0;               /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */
  24.289 -
  24.290 -    if (chunkHeader.ckID != 'FORM') {
  24.291 -        result = -1;
  24.292 -        if (result)
  24.293 -            return 0;           /*THROW_RESULT("AudioFilePlayer::OpenFile(): chunk id is not 'FORM'"); */
  24.294 -    }
  24.295 -
  24.296 -    if (chunkHeader.formType != 'AIFC') {
  24.297 -        result = -1;
  24.298 -        if (result)
  24.299 -            return 0;           /*THROW_RESULT("AudioFilePlayer::OpenFile(): file format is not 'AIFC'"); */
  24.300 -    }
  24.301 -
  24.302 -    /* Search for the SSND chunk. We ignore all compression etc. information
  24.303 -       in other chunks. Of course that is kind of evil, but for now we are lazy
  24.304 -       and rely on the cdfs to always give us the same fixed format.
  24.305 -       TODO: Parse the COMM chunk we currently skip to fill in mFileDescription.
  24.306 -     */
  24.307 -    offset = 0;
  24.308 -    do {
  24.309 -        result =
  24.310 -            FSReadFork(afp->mForkRefNum, fsFromMark, offset,
  24.311 -                       sizeof(chunk), &chunk, &actual);
  24.312 -        if (result)
  24.313 -            return 0;           /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */
  24.314 -
  24.315 -        /* Skip the chunk data */
  24.316 -        offset = chunk.ckSize;
  24.317 -    } while (chunk.ckID != 'SSND');
  24.318 -
  24.319 -    /* Read the header of the SSND chunk. After this, we are positioned right
  24.320 -       at the start of the audio data. */
  24.321 -    result =
  24.322 -        FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(ssndData),
  24.323 -                   &ssndData, &actual);
  24.324 -    if (result)
  24.325 -        return 0;               /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork") */
  24.326 -
  24.327 -    result = FSSetForkPosition(afp->mForkRefNum, fsFromMark, ssndData.offset);
  24.328 -    if (result)
  24.329 -        return 0;               /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition") */
  24.330 -
  24.331 -    /* Data size */
  24.332 -    *outFileDataSize = chunk.ckSize - ssndData.offset - 8;
  24.333 -
  24.334 -    /* File format */
  24.335 -    afp->mFileDescription.mSampleRate = 44100;
  24.336 -    afp->mFileDescription.mFormatID = kAudioFormatLinearPCM;
  24.337 -    afp->mFileDescription.mFormatFlags =
  24.338 -        kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger;
  24.339 -    afp->mFileDescription.mBytesPerPacket = 4;
  24.340 -    afp->mFileDescription.mFramesPerPacket = 1;
  24.341 -    afp->mFileDescription.mBytesPerFrame = 4;
  24.342 -    afp->mFileDescription.mChannelsPerFrame = 2;
  24.343 -    afp->mFileDescription.mBitsPerChannel = 16;
  24.344 -
  24.345 -    return 1;
  24.346 -}
  24.347 -
  24.348 -AudioFilePlayer *
  24.349 -new_AudioFilePlayer(const FSRef * inFileRef)
  24.350 -{
  24.351 -    SInt64 fileDataSize = 0;
  24.352 -
  24.353 -    AudioFilePlayer *afp =
  24.354 -        (AudioFilePlayer *) SDL_malloc(sizeof(AudioFilePlayer));
  24.355 -    if (afp == NULL)
  24.356 -        return NULL;
  24.357 -    SDL_memset(afp, '\0', sizeof(*afp));
  24.358 -
  24.359 -#define SET_AUDIOFILEPLAYER_METHOD(m) afp->m = AudioFilePlayer_##m
  24.360 -    SET_AUDIOFILEPLAYER_METHOD(SetDestination);
  24.361 -    SET_AUDIOFILEPLAYER_METHOD(SetNotifier);
  24.362 -    SET_AUDIOFILEPLAYER_METHOD(SetStartFrame);
  24.363 -    SET_AUDIOFILEPLAYER_METHOD(GetCurrentFrame);
  24.364 -    SET_AUDIOFILEPLAYER_METHOD(SetStopFrame);
  24.365 -    SET_AUDIOFILEPLAYER_METHOD(Connect);
  24.366 -    SET_AUDIOFILEPLAYER_METHOD(Disconnect);
  24.367 -    SET_AUDIOFILEPLAYER_METHOD(DoNotification);
  24.368 -    SET_AUDIOFILEPLAYER_METHOD(IsConnected);
  24.369 -    SET_AUDIOFILEPLAYER_METHOD(GetDestUnit);
  24.370 -    SET_AUDIOFILEPLAYER_METHOD(Print);
  24.371 -    SET_AUDIOFILEPLAYER_METHOD(OpenFile);
  24.372 -#undef SET_AUDIOFILEPLAYER_METHOD
  24.373 -
  24.374 -    if (!afp->OpenFile(afp, inFileRef, &fileDataSize)) {
  24.375 -        SDL_free(afp);
  24.376 -        return NULL;
  24.377 -    }
  24.378 -
  24.379 -    /* we want about 4 seconds worth of data for the buffer */
  24.380 -    int bytesPerSecond =
  24.381 -        (UInt32) (4 * afp->mFileDescription.mSampleRate *
  24.382 -                  afp->mFileDescription.mBytesPerFrame);
  24.383 -
  24.384 -#if DEBUG
  24.385 -    printf("File format:\n");
  24.386 -    PrintStreamDesc(&afp->mFileDescription);
  24.387 -#endif
  24.388 -
  24.389 -    afp->mAudioFileManager = new_AudioFileManager(afp, afp->mForkRefNum,
  24.390 -                                                  fileDataSize,
  24.391 -                                                  bytesPerSecond);
  24.392 -    if (afp->mAudioFileManager == NULL) {
  24.393 -        delete_AudioFilePlayer(afp);
  24.394 -        return NULL;
  24.395 -    }
  24.396 -
  24.397 -    return afp;
  24.398 -}
  24.399 -
  24.400 -/* vi: set ts=4 sw=4 expandtab: */
    25.1 --- a/src/cdrom/macosx/AudioFilePlayer.h	Sat Sep 05 09:03:35 2009 +0000
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,178 +0,0 @@
    25.4 -/*
    25.5 -    SDL - Simple DirectMedia Layer
    25.6 -    Copyright (C) 1997-2009 Sam Lantinga
    25.7 -
    25.8 -    This library is free software; you can redistribute it and/or
    25.9 -    modify it under the terms of the GNU Library General Public
   25.10 -    License as published by the Free Software Foundation; either
   25.11 -    version 2 of the License, or (at your option) any later version.
   25.12 -
   25.13 -    This library is distributed in the hope that it will be useful,
   25.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   25.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   25.16 -    Library General Public License for more details.
   25.17 -
   25.18 -    You should have received a copy of the GNU Library General Public
   25.19 -    License along with this library; if not, write to the Free
   25.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   25.21 -
   25.22 -    Sam Lantinga
   25.23 -    slouken@libsdl.org
   25.24 -
   25.25 -    This file based on Apple sample code. We haven't changed the file name, 
   25.26 -    so if you want to see the original search for it on apple.com/developer
   25.27 -*/
   25.28 -#include "SDL_config.h"
   25.29 -
   25.30 -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   25.31 -    AudioFilePlayer.h
   25.32 -*/
   25.33 -#ifndef __AudioFilePlayer_H__
   25.34 -#define __AudioFilePlayer_H__
   25.35 -
   25.36 -#include <CoreServices/CoreServices.h>
   25.37 -
   25.38 -#include <AudioUnit/AudioUnit.h>
   25.39 -#ifdef AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
   25.40 -#include <AudioUnit/AUNTComponent.h>
   25.41 -#endif
   25.42 -
   25.43 -#include "SDL_error.h"
   25.44 -
   25.45 -const char *AudioFilePlayerErrorStr(OSStatus error);
   25.46 -
   25.47 -/*
   25.48 -void ThrowResult (OSStatus result, const char *str);
   25.49 -
   25.50 -#define THROW_RESULT(str)                                       \
   25.51 -    if (result) {                                               \
   25.52 -        ThrowResult (result, str);                              \
   25.53 -    }
   25.54 -*/
   25.55 -
   25.56 -typedef void (*AudioFilePlayNotifier) (void *inRefCon, OSStatus inStatus);
   25.57 -
   25.58 -enum
   25.59 -{
   25.60 -    kAudioFilePlayErr_FilePlayUnderrun = -10000,
   25.61 -    kAudioFilePlay_FileIsFinished = -10001,
   25.62 -    kAudioFilePlay_PlayerIsUninitialized = -10002
   25.63 -};
   25.64 -
   25.65 -
   25.66 -struct S_AudioFileManager;
   25.67 -
   25.68 -#pragma mark __________ AudioFilePlayer
   25.69 -typedef struct S_AudioFilePlayer
   25.70 -{
   25.71 -/*public:*/
   25.72 -    int (*SetDestination) (struct S_AudioFilePlayer * afp,
   25.73 -                           AudioUnit * inDestUnit);
   25.74 -    void (*SetNotifier) (struct S_AudioFilePlayer * afp,
   25.75 -                         AudioFilePlayNotifier inNotifier, void *inRefCon);
   25.76 -    void (*SetStartFrame) (struct S_AudioFilePlayer * afp, int frame);  /* seek in the file */
   25.77 -    int (*GetCurrentFrame) (struct S_AudioFilePlayer * afp);    /* get the current frame position */
   25.78 -    void (*SetStopFrame) (struct S_AudioFilePlayer * afp, int frame);   /* set limit in the file */
   25.79 -    int (*Connect) (struct S_AudioFilePlayer * afp);
   25.80 -    void (*Disconnect) (struct S_AudioFilePlayer * afp);
   25.81 -    void (*DoNotification) (struct S_AudioFilePlayer * afp, OSStatus inError);
   25.82 -    int (*IsConnected) (struct S_AudioFilePlayer * afp);
   25.83 -      AudioUnit(*GetDestUnit) (struct S_AudioFilePlayer * afp);
   25.84 -    void (*Print) (struct S_AudioFilePlayer * afp);
   25.85 -
   25.86 -/*private:*/
   25.87 -    AudioUnit mPlayUnit;
   25.88 -    SInt16 mForkRefNum;
   25.89 -
   25.90 -    AudioUnitInputCallback mInputCallback;
   25.91 -
   25.92 -    AudioStreamBasicDescription mFileDescription;
   25.93 -
   25.94 -    int mConnected;
   25.95 -
   25.96 -    struct S_AudioFileManager *mAudioFileManager;
   25.97 -
   25.98 -    AudioFilePlayNotifier mNotifier;
   25.99 -    void *mRefCon;
  25.100 -
  25.101 -    int mStartFrame;
  25.102 -
  25.103 -#pragma mark __________ Private_Methods
  25.104 -
  25.105 -    int (*OpenFile) (struct S_AudioFilePlayer * afp, const FSRef * inRef,
  25.106 -                     SInt64 * outFileSize);
  25.107 -} AudioFilePlayer;
  25.108 -
  25.109 -
  25.110 -AudioFilePlayer *new_AudioFilePlayer(const FSRef * inFileRef);
  25.111 -void delete_AudioFilePlayer(AudioFilePlayer * afp);
  25.112 -
  25.113 -
  25.114 -
  25.115 -#pragma mark __________ AudioFileManager
  25.116 -typedef struct S_AudioFileManager
  25.117 -{
  25.118 -/*public:*/
  25.119 -    /* this method should NOT be called by an object of this class
  25.120 -       as it is called by the parent's Disconnect() method */
  25.121 -    void (*Disconnect) (struct S_AudioFileManager * afm);
  25.122 -    int (*DoConnect) (struct S_AudioFileManager * afm);
  25.123 -      OSStatus(*Read) (struct S_AudioFileManager * afm, char *buffer,
  25.124 -                       UInt32 * len);
  25.125 -    const char *(*GetFileBuffer) (struct S_AudioFileManager * afm);
  25.126 -    const AudioFilePlayer *(*GetParent) (struct S_AudioFileManager * afm);
  25.127 -    void (*SetPosition) (struct S_AudioFileManager * afm, SInt64 pos);  /* seek/rewind in the file */
  25.128 -    int (*GetByteCounter) (struct S_AudioFileManager * afm);    /* return actual bytes streamed to audio hardware */
  25.129 -    void (*SetEndOfFile) (struct S_AudioFileManager * afm, SInt64 pos); /* set the "EOF" (will behave just like it reached eof) */
  25.130 -
  25.131 -/*protected:*/
  25.132 -    AudioFilePlayer *mParent;
  25.133 -    SInt16 mForkRefNum;
  25.134 -    SInt64 mAudioDataOffset;
  25.135 -
  25.136 -    char *mFileBuffer;
  25.137 -
  25.138 -    int mByteCounter;
  25.139 -
  25.140 -    int mReadFromFirstBuffer;
  25.141 -    int mLockUnsuccessful;
  25.142 -    int mIsEngaged;
  25.143 -
  25.144 -    int mNumTimesAskedSinceFinished;
  25.145 -
  25.146 -
  25.147 -    void *mTmpBuffer;
  25.148 -    UInt32 mBufferSize;
  25.149 -    UInt32 mBufferOffset;
  25.150 -/*public:*/
  25.151 -    UInt32 mChunkSize;
  25.152 -    SInt64 mFileLength;
  25.153 -    SInt64 mReadFilePosition;
  25.154 -    int mWriteToFirstBuffer;
  25.155 -    int mFinishedReadingData;
  25.156 -
  25.157 -/*protected:*/
  25.158 -      OSStatus(*Render) (struct S_AudioFileManager * afm,
  25.159 -                         AudioBuffer * ioData);
  25.160 -      OSStatus(*GetFileData) (struct S_AudioFileManager * afm,
  25.161 -                              void **inOutData, UInt32 * inOutDataSize);
  25.162 -    void (*AfterRender) (struct S_AudioFileManager * afm);
  25.163 -
  25.164 -/*public:*/
  25.165 -    /*static */
  25.166 -      OSStatus(*FileInputProc) (void *inRefCon,
  25.167 -                                AudioUnitRenderActionFlags inActionFlags,
  25.168 -                                const AudioTimeStamp * inTimeStamp,
  25.169 -                                UInt32 inBusNumber, AudioBuffer * ioData);
  25.170 -} AudioFileManager;
  25.171 -
  25.172 -
  25.173 -AudioFileManager *new_AudioFileManager(AudioFilePlayer * inParent,
  25.174 -                                       SInt16 inForkRefNum,
  25.175 -                                       SInt64 inFileLength,
  25.176 -                                       UInt32 inChunkSize);
  25.177 -
  25.178 -void delete_AudioFileManager(AudioFileManager * afm);
  25.179 -
  25.180 -#endif
  25.181 -/* vi: set ts=4 sw=4 expandtab: */
    26.1 --- a/src/cdrom/macosx/AudioFileReaderThread.c	Sat Sep 05 09:03:35 2009 +0000
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,657 +0,0 @@
    26.4 -/*
    26.5 -    SDL - Simple DirectMedia Layer
    26.6 -    Copyright (C) 1997-2009 Sam Lantinga
    26.7 -
    26.8 -    This library is free software; you can redistribute it and/or
    26.9 -    modify it under the terms of the GNU Library General Public
   26.10 -    License as published by the Free Software Foundation; either
   26.11 -    version 2 of the License, or (at your option) any later version.
   26.12 -
   26.13 -    This library is distributed in the hope that it will be useful,
   26.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   26.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   26.16 -    Library General Public License for more details.
   26.17 -
   26.18 -    You should have received a copy of the GNU Library General Public
   26.19 -    License along with this library; if not, write to the Free
   26.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   26.21 -
   26.22 -    Sam Lantinga
   26.23 -    slouken@libsdl.org
   26.24 -
   26.25 -    This file based on Apple sample code. We haven't changed the file name, 
   26.26 -    so if you want to see the original search for it on apple.com/developer
   26.27 -*/
   26.28 -#include "SDL_config.h"
   26.29 -
   26.30 -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   26.31 -   AudioFileManager.cpp
   26.32 -*/
   26.33 -#include "AudioFilePlayer.h"
   26.34 -#include <mach/mach.h>          /* used for setting policy of thread */
   26.35 -#include "SDLOSXCAGuard.h"
   26.36 -#include <pthread.h>
   26.37 -
   26.38 -/*#include <list>*/
   26.39 -
   26.40 -/*typedef void *FileData;*/
   26.41 -typedef struct S_FileData
   26.42 -{
   26.43 -    AudioFileManager *obj;
   26.44 -    struct S_FileData *next;
   26.45 -} FileData;
   26.46 -
   26.47 -
   26.48 -typedef struct S_FileReaderThread
   26.49 -{
   26.50 -/*public:*/
   26.51 -    SDLOSXCAGuard *(*GetGuard) (struct S_FileReaderThread * frt);
   26.52 -    void (*AddReader) (struct S_FileReaderThread * frt);
   26.53 -    void (*RemoveReader) (struct S_FileReaderThread * frt,
   26.54 -                          AudioFileManager * inItem);
   26.55 -    int (*TryNextRead) (struct S_FileReaderThread * frt,
   26.56 -                        AudioFileManager * inItem);
   26.57 -
   26.58 -    int mThreadShouldDie;
   26.59 -
   26.60 -/*private:*/
   26.61 -    /*typedef std::list<AudioFileManager*> FileData; */
   26.62 -
   26.63 -    SDLOSXCAGuard *mGuard;
   26.64 -    UInt32 mThreadPriority;
   26.65 -
   26.66 -    int mNumReaders;
   26.67 -    FileData *mFileData;
   26.68 -
   26.69 -
   26.70 -    void (*ReadNextChunk) (struct S_FileReaderThread * frt);
   26.71 -    int (*StartFixedPriorityThread) (struct S_FileReaderThread * frt);
   26.72 -    /*static */
   26.73 -      UInt32(*GetThreadBasePriority) (pthread_t inThread);
   26.74 -    /*static */
   26.75 -    void *(*DiskReaderEntry) (void *inRefCon);
   26.76 -} FileReaderThread;
   26.77 -
   26.78 -
   26.79 -static SDLOSXCAGuard *
   26.80 -FileReaderThread_GetGuard(FileReaderThread * frt)
   26.81 -{
   26.82 -    return frt->mGuard;
   26.83 -}
   26.84 -
   26.85 -/* returns 1 if succeeded */
   26.86 -static int
   26.87 -FileReaderThread_TryNextRead(FileReaderThread * frt,
   26.88 -                             AudioFileManager * inItem)
   26.89 -{
   26.90 -    int didLock = 0;
   26.91 -    int succeeded = 0;
   26.92 -    if (frt->mGuard->Try(frt->mGuard, &didLock)) {
   26.93 -        /*frt->mFileData.push_back (inItem); */
   26.94 -        /* !!! FIXME: this could be faster with a "tail" member. --ryan. */
   26.95 -        FileData *i = frt->mFileData;
   26.96 -        FileData *prev = NULL;
   26.97 -
   26.98 -        FileData *newfd = (FileData *) SDL_malloc(sizeof(FileData));
   26.99 -        newfd->obj = inItem;
  26.100 -        newfd->next = NULL;
  26.101 -
  26.102 -        while (i != NULL) {
  26.103 -            prev = i;
  26.104 -            i = i->next;
  26.105 -        }
  26.106 -        if (prev == NULL)
  26.107 -            frt->mFileData = newfd;
  26.108 -        else
  26.109 -            prev->next = newfd;
  26.110 -
  26.111 -        frt->mGuard->Notify(frt->mGuard);
  26.112 -        succeeded = 1;
  26.113 -
  26.114 -        if (didLock)
  26.115 -            frt->mGuard->Unlock(frt->mGuard);
  26.116 -    }
  26.117 -
  26.118 -    return succeeded;
  26.119 -}
  26.120 -
  26.121 -static void
  26.122 -FileReaderThread_AddReader(FileReaderThread * frt)
  26.123 -{
  26.124 -    if (frt->mNumReaders == 0) {
  26.125 -        frt->mThreadShouldDie = 0;
  26.126 -        frt->StartFixedPriorityThread(frt);
  26.127 -    }
  26.128 -    frt->mNumReaders++;
  26.129 -}
  26.130 -
  26.131 -static void
  26.132 -FileReaderThread_RemoveReader(FileReaderThread * frt,
  26.133 -                              AudioFileManager * inItem)
  26.134 -{
  26.135 -    if (frt->mNumReaders > 0) {
  26.136 -        int bNeedsRelease = frt->mGuard->Lock(frt->mGuard);
  26.137 -
  26.138 -        /*frt->mFileData.remove (inItem); */
  26.139 -        FileData *i = frt->mFileData;
  26.140 -        FileData *prev = NULL;
  26.141 -        while (i != NULL) {
  26.142 -            FileData *next = i->next;
  26.143 -            if (i->obj != inItem)
  26.144 -                prev = i;
  26.145 -            else {
  26.146 -                if (prev == NULL)
  26.147 -                    frt->mFileData = next;
  26.148 -                else
  26.149 -                    prev->next = next;
  26.150 -                SDL_free(i);
  26.151 -            }
  26.152 -            i = next;
  26.153 -        }
  26.154 -
  26.155 -        if (--frt->mNumReaders == 0) {
  26.156 -            frt->mThreadShouldDie = 1;
  26.157 -            frt->mGuard->Notify(frt->mGuard);   /* wake up thread so it will quit */
  26.158 -            frt->mGuard->Wait(frt->mGuard);     /* wait for thread to die */
  26.159 -        }
  26.160 -
  26.161 -        if (bNeedsRelease)
  26.162 -            frt->mGuard->Unlock(frt->mGuard);
  26.163 -    }
  26.164 -}
  26.165 -
  26.166 -static int
  26.167 -FileReaderThread_StartFixedPriorityThread(FileReaderThread * frt)
  26.168 -{
  26.169 -    pthread_attr_t theThreadAttrs;
  26.170 -    pthread_t pThread;
  26.171 -
  26.172 -    OSStatus result = pthread_attr_init(&theThreadAttrs);
  26.173 -    if (result)
  26.174 -        return 0;               /*THROW_RESULT("pthread_attr_init - Thread attributes could not be created.") */
  26.175 -
  26.176 -    result =
  26.177 -        pthread_attr_setdetachstate(&theThreadAttrs, PTHREAD_CREATE_DETACHED);
  26.178 -    if (result)
  26.179 -        return 0;               /*THROW_RESULT("pthread_attr_setdetachstate - Thread attributes could not be detached.") */
  26.180 -
  26.181 -    result =
  26.182 -        pthread_create(&pThread, &theThreadAttrs, frt->DiskReaderEntry, frt);
  26.183 -    if (result)
  26.184 -        return 0;               /*THROW_RESULT("pthread_create - Create and start the thread.") */
  26.185 -
  26.186 -    pthread_attr_destroy(&theThreadAttrs);
  26.187 -
  26.188 -    /* we've now created the thread and started it
  26.189 -       we'll now set the priority of the thread to the nominated priority
  26.190 -       and we'll also make the thread fixed */
  26.191 -    thread_extended_policy_data_t theFixedPolicy;
  26.192 -    thread_precedence_policy_data_t thePrecedencePolicy;
  26.193 -    SInt32 relativePriority;
  26.194 -
  26.195 -    /* make thread fixed */
  26.196 -    theFixedPolicy.timeshare = 0;       /* set to 1 for a non-fixed thread */
  26.197 -    result =
  26.198 -        thread_policy_set(pthread_mach_thread_np(pThread),
  26.199 -                          THREAD_EXTENDED_POLICY,
  26.200 -                          (thread_policy_t) & theFixedPolicy,
  26.201 -                          THREAD_EXTENDED_POLICY_COUNT);
  26.202 -    if (result)
  26.203 -        return 0;               /*THROW_RESULT("thread_policy - Couldn't set thread as fixed priority.") */
  26.204 -    /* set priority */
  26.205 -    /* precedency policy's "importance" value is relative to spawning thread's priority */
  26.206 -    relativePriority =
  26.207 -        frt->mThreadPriority - frt->GetThreadBasePriority(pthread_self());
  26.208 -
  26.209 -    thePrecedencePolicy.importance = relativePriority;
  26.210 -    result =
  26.211 -        thread_policy_set(pthread_mach_thread_np(pThread),
  26.212 -                          THREAD_PRECEDENCE_POLICY,
  26.213 -                          (thread_policy_t) & thePrecedencePolicy,
  26.214 -                          THREAD_PRECEDENCE_POLICY_COUNT);
  26.215 -    if (result)
  26.216 -        return 0;               /*THROW_RESULT("thread_policy - Couldn't set thread priority.") */
  26.217 -
  26.218 -    return 1;
  26.219 -}
  26.220 -
  26.221 -static UInt32
  26.222 -FileReaderThread_GetThreadBasePriority(pthread_t inThread)
  26.223 -{
  26.224 -    thread_basic_info_data_t threadInfo;
  26.225 -    policy_info_data_t thePolicyInfo;
  26.226 -    unsigned int count;
  26.227 -
  26.228 -    /* get basic info */
  26.229 -    count = THREAD_BASIC_INFO_COUNT;
  26.230 -    thread_info(pthread_mach_thread_np(inThread), THREAD_BASIC_INFO,
  26.231 -                (integer_t *) & threadInfo, &count);
  26.232 -
  26.233 -    switch (threadInfo.policy) {
  26.234 -    case POLICY_TIMESHARE:
  26.235 -        count = POLICY_TIMESHARE_INFO_COUNT;
  26.236 -        thread_info(pthread_mach_thread_np(inThread),
  26.237 -                    THREAD_SCHED_TIMESHARE_INFO,
  26.238 -                    (integer_t *) & (thePolicyInfo.ts), &count);
  26.239 -        return thePolicyInfo.ts.base_priority;
  26.240 -        break;
  26.241 -
  26.242 -    case POLICY_FIFO:
  26.243 -        count = POLICY_FIFO_INFO_COUNT;
  26.244 -        thread_info(pthread_mach_thread_np(inThread),
  26.245 -                    THREAD_SCHED_FIFO_INFO,
  26.246 -                    (integer_t *) & (thePolicyInfo.fifo), &count);
  26.247 -        if (thePolicyInfo.fifo.depressed) {
  26.248 -            return thePolicyInfo.fifo.depress_priority;
  26.249 -        } else {
  26.250 -            return thePolicyInfo.fifo.base_priority;
  26.251 -        }
  26.252 -        break;
  26.253 -
  26.254 -    case POLICY_RR:
  26.255 -        count = POLICY_RR_INFO_COUNT;
  26.256 -        thread_info(pthread_mach_thread_np(inThread),
  26.257 -                    THREAD_SCHED_RR_INFO,
  26.258 -                    (integer_t *) & (thePolicyInfo.rr), &count);
  26.259 -        if (thePolicyInfo.rr.depressed) {
  26.260 -            return thePolicyInfo.rr.depress_priority;
  26.261 -        } else {
  26.262 -            return thePolicyInfo.rr.base_priority;
  26.263 -        }
  26.264 -        break;
  26.265 -    }
  26.266 -
  26.267 -    return 0;
  26.268 -}
  26.269 -
  26.270 -static void *
  26.271 -FileReaderThread_DiskReaderEntry(void *inRefCon)
  26.272 -{
  26.273 -    FileReaderThread *frt = (FileReaderThread *) inRefCon;
  26.274 -    frt->ReadNextChunk(frt);
  26.275 -#if DEBUG
  26.276 -    printf("finished with reading file\n");
  26.277 -#endif
  26.278 -
  26.279 -    return 0;
  26.280 -}
  26.281 -
  26.282 -static void
  26.283 -FileReaderThread_ReadNextChunk(FileReaderThread * frt)
  26.284 -{
  26.285 -    OSStatus result;
  26.286 -    UInt32 dataChunkSize;
  26.287 -    AudioFileManager *theItem = 0;
  26.288 -
  26.289 -    for (;;) {
  26.290 -        {                       /* this is a scoped based lock */
  26.291 -            int bNeedsRelease = frt->mGuard->Lock(frt->mGuard);
  26.292 -
  26.293 -            if (frt->mThreadShouldDie) {
  26.294 -                frt->mGuard->Notify(frt->mGuard);
  26.295 -                if (bNeedsRelease)
  26.296 -                    frt->mGuard->Unlock(frt->mGuard);
  26.297 -                return;
  26.298 -            }
  26.299 -
  26.300 -            /*if (frt->mFileData.empty()) */
  26.301 -            if (frt->mFileData == NULL) {
  26.302 -                frt->mGuard->Wait(frt->mGuard);
  26.303 -            }
  26.304 -
  26.305 -            /* kill thread */
  26.306 -            if (frt->mThreadShouldDie) {
  26.307 -
  26.308 -                frt->mGuard->Notify(frt->mGuard);
  26.309 -                if (bNeedsRelease)
  26.310 -                    frt->mGuard->Unlock(frt->mGuard);
  26.311 -                return;
  26.312 -            }
  26.313 -
  26.314 -            /*theItem = frt->mFileData.front(); */
  26.315 -            /*frt->mFileData.pop_front(); */
  26.316 -            theItem = NULL;
  26.317 -            if (frt->mFileData != NULL) {
  26.318 -                FileData *next = frt->mFileData->next;
  26.319 -                theItem = frt->mFileData->obj;
  26.320 -                SDL_free(frt->mFileData);
  26.321 -                frt->mFileData = next;
  26.322 -            }
  26.323 -
  26.324 -            if (bNeedsRelease)
  26.325 -                frt->mGuard->Unlock(frt->mGuard);
  26.326 -        }
  26.327 -
  26.328 -        if ((theItem->mFileLength - theItem->mReadFilePosition) <
  26.329 -            theItem->mChunkSize)
  26.330 -            dataChunkSize = theItem->mFileLength - theItem->mReadFilePosition;
  26.331 -        else
  26.332 -            dataChunkSize = theItem->mChunkSize;
  26.333 -
  26.334 -        /* this is the exit condition for the thread */
  26.335 -        if (dataChunkSize <= 0) {
  26.336 -            theItem->mFinishedReadingData = 1;
  26.337 -            continue;
  26.338 -        }
  26.339 -        /* construct pointer */
  26.340 -        char *writePtr = (char *) (theItem->GetFileBuffer(theItem) +
  26.341 -                                   (theItem->mWriteToFirstBuffer ? 0 :
  26.342 -                                    theItem->mChunkSize));
  26.343 -
  26.344 -        /* read data */
  26.345 -        result = theItem->Read(theItem, writePtr, &dataChunkSize);
  26.346 -        if (result != noErr && result != eofErr) {
  26.347 -            AudioFilePlayer *afp =
  26.348 -                (AudioFilePlayer *) theItem->GetParent(theItem);
  26.349 -            afp->DoNotification(afp, result);
  26.350 -            continue;
  26.351 -        }
  26.352 -
  26.353 -        if (dataChunkSize != theItem->mChunkSize) {
  26.354 -            writePtr += dataChunkSize;
  26.355 -
  26.356 -            /* can't exit yet.. we still have to pass the partial buffer back */
  26.357 -            SDL_memset(writePtr, 0, (theItem->mChunkSize - dataChunkSize));
  26.358 -        }
  26.359 -
  26.360 -        theItem->mWriteToFirstBuffer = !theItem->mWriteToFirstBuffer;   /* switch buffers */
  26.361 -
  26.362 -        if (result == eofErr)
  26.363 -            theItem->mReadFilePosition = theItem->mFileLength;
  26.364 -        else
  26.365 -            theItem->mReadFilePosition += dataChunkSize;        /* increment count */
  26.366 -    }
  26.367 -}
  26.368 -
  26.369 -void
  26.370 -delete_FileReaderThread(FileReaderThread * frt)
  26.371 -{
  26.372 -    if (frt != NULL) {
  26.373 -        delete_SDLOSXCAGuard(frt->mGuard);
  26.374 -        SDL_free(frt);
  26.375 -    }
  26.376 -}
  26.377 -
  26.378 -FileReaderThread *
  26.379 -new_FileReaderThread()
  26.380 -{
  26.381 -    FileReaderThread *frt =
  26.382 -        (FileReaderThread *) SDL_malloc(sizeof(FileReaderThread));
  26.383 -    if (frt == NULL)
  26.384 -        return NULL;
  26.385 -    SDL_memset(frt, '\0', sizeof(*frt));
  26.386 -
  26.387 -    frt->mGuard = new_SDLOSXCAGuard();
  26.388 -    if (frt->mGuard == NULL) {
  26.389 -        SDL_free(frt);
  26.390 -        return NULL;
  26.391 -    }
  26.392 -#define SET_FILEREADERTHREAD_METHOD(m) frt->m = FileReaderThread_##m
  26.393 -    SET_FILEREADERTHREAD_METHOD(GetGuard);
  26.394 -    SET_FILEREADERTHREAD_METHOD(AddReader);
  26.395 -    SET_FILEREADERTHREAD_METHOD(RemoveReader);
  26.396 -    SET_FILEREADERTHREAD_METHOD(TryNextRead);
  26.397 -    SET_FILEREADERTHREAD_METHOD(ReadNextChunk);
  26.398 -    SET_FILEREADERTHREAD_METHOD(StartFixedPriorityThread);
  26.399 -    SET_FILEREADERTHREAD_METHOD(GetThreadBasePriority);
  26.400 -    SET_FILEREADERTHREAD_METHOD(DiskReaderEntry);
  26.401 -#undef SET_FILEREADERTHREAD_METHOD
  26.402 -
  26.403 -    frt->mThreadPriority = 62;
  26.404 -    return frt;
  26.405 -}
  26.406 -
  26.407 -
  26.408 -static FileReaderThread *sReaderThread;
  26.409 -
  26.410 -
  26.411 -static int
  26.412 -AudioFileManager_DoConnect(AudioFileManager * afm)
  26.413 -{
  26.414 -    if (!afm->mIsEngaged) {
  26.415 -        OSStatus result;
  26.416 -
  26.417 -        /*afm->mReadFilePosition = 0; */
  26.418 -        afm->mFinishedReadingData = 0;
  26.419 -
  26.420 -        afm->mNumTimesAskedSinceFinished = 0;
  26.421 -        afm->mLockUnsuccessful = 0;
  26.422 -
  26.423 -        UInt32 dataChunkSize;
  26.424 -
  26.425 -        if ((afm->mFileLength - afm->mReadFilePosition) < afm->mChunkSize)
  26.426 -            dataChunkSize = afm->mFileLength - afm->mReadFilePosition;
  26.427 -        else
  26.428 -            dataChunkSize = afm->mChunkSize;
  26.429 -
  26.430 -        result = afm->Read(afm, afm->mFileBuffer, &dataChunkSize);
  26.431 -        if (result)
  26.432 -            return 0;           /*THROW_RESULT("AudioFileManager::DoConnect(): Read") */
  26.433 -
  26.434 -        afm->mReadFilePosition += dataChunkSize;
  26.435 -
  26.436 -        afm->mWriteToFirstBuffer = 0;
  26.437 -        afm->mReadFromFirstBuffer = 1;
  26.438 -
  26.439 -        sReaderThread->AddReader(sReaderThread);
  26.440 -
  26.441 -        afm->mIsEngaged = 1;
  26.442 -    }
  26.443 -    /*
  26.444 -       else
  26.445 -       throw static_cast<OSStatus>(-1); *//* thread has already been started */
  26.446 -
  26.447 -    return 1;
  26.448 -}
  26.449 -
  26.450 -static void
  26.451 -AudioFileManager_Disconnect(AudioFileManager * afm)
  26.452 -{
  26.453 -    if (afm->mIsEngaged) {
  26.454 -        sReaderThread->RemoveReader(sReaderThread, afm);
  26.455 -        afm->mIsEngaged = 0;
  26.456 -    }
  26.457 -}
  26.458 -
  26.459 -static OSStatus
  26.460 -AudioFileManager_Read(AudioFileManager * afm, char *buffer, UInt32 * len)
  26.461 -{
  26.462 -    return FSReadFork(afm->mForkRefNum,
  26.463 -                      fsFromStart,
  26.464 -                      afm->mReadFilePosition + afm->mAudioDataOffset,
  26.465 -                      *len, buffer, len);
  26.466 -}
  26.467 -
  26.468 -static OSStatus
  26.469 -AudioFileManager_GetFileData(AudioFileManager * afm, void **inOutData,
  26.470 -                             UInt32 * inOutDataSize)
  26.471 -{
  26.472 -    if (afm->mFinishedReadingData) {
  26.473 -        ++afm->mNumTimesAskedSinceFinished;
  26.474 -        *inOutDataSize = 0;
  26.475 -        *inOutData = 0;
  26.476 -        return noErr;
  26.477 -    }
  26.478 -
  26.479 -    if (afm->mReadFromFirstBuffer == afm->mWriteToFirstBuffer) {
  26.480 -#if DEBUG
  26.481 -        printf("* * * * * * * Can't keep up with reading file\n");
  26.482 -#endif
  26.483 -
  26.484 -        afm->mParent->DoNotification(afm->mParent,
  26.485 -                                     kAudioFilePlayErr_FilePlayUnderrun);
  26.486 -        *inOutDataSize = 0;
  26.487 -        *inOutData = 0;
  26.488 -    } else {
  26.489 -        *inOutDataSize = afm->mChunkSize;
  26.490 -        *inOutData =
  26.491 -            afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm->mFileBuffer +
  26.492 -                                                            afm->mChunkSize);
  26.493 -    }
  26.494 -
  26.495 -    afm->mLockUnsuccessful = !sReaderThread->TryNextRead(sReaderThread, afm);
  26.496 -
  26.497 -    afm->mReadFromFirstBuffer = !afm->mReadFromFirstBuffer;
  26.498 -
  26.499 -    return noErr;
  26.500 -}
  26.501 -
  26.502 -static void
  26.503 -AudioFileManager_AfterRender(AudioFileManager * afm)
  26.504 -{
  26.505 -    if (afm->mNumTimesAskedSinceFinished > 0) {
  26.506 -        int didLock = 0;
  26.507 -        SDLOSXCAGuard *guard = sReaderThread->GetGuard(sReaderThread);
  26.508 -        if (guard->Try(guard, &didLock)) {
  26.509 -            afm->mParent->DoNotification(afm->mParent,
  26.510 -                                         kAudioFilePlay_FileIsFinished);
  26.511 -            if (didLock)
  26.512 -                guard->Unlock(guard);
  26.513 -        }
  26.514 -    }
  26.515 -
  26.516 -    if (afm->mLockUnsuccessful)
  26.517 -        afm->mLockUnsuccessful =
  26.518 -            !sReaderThread->TryNextRead(sReaderThread, afm);
  26.519 -}
  26.520 -
  26.521 -static void
  26.522 -AudioFileManager_SetPosition(AudioFileManager * afm, SInt64 pos)
  26.523 -{
  26.524 -    if (pos < 0 || pos >= afm->mFileLength) {
  26.525 -        SDL_SetError
  26.526 -            ("AudioFileManager::SetPosition - position invalid: %d filelen=%d\n",
  26.527 -             (unsigned int) pos, (unsigned int) afm->mFileLength);
  26.528 -        pos = 0;
  26.529 -    }
  26.530 -
  26.531 -    afm->mReadFilePosition = pos;
  26.532 -}
  26.533 -
  26.534 -static void
  26.535 -AudioFileManager_SetEndOfFile(AudioFileManager * afm, SInt64 pos)
  26.536 -{
  26.537 -    if (pos <= 0 || pos > afm->mFileLength) {
  26.538 -        SDL_SetError
  26.539 -            ("AudioFileManager::SetEndOfFile - position beyond actual eof\n");
  26.540 -        pos = afm->mFileLength;
  26.541 -    }
  26.542 -
  26.543 -    afm->mFileLength = pos;
  26.544 -}
  26.545 -
  26.546 -static const char *
  26.547 -AudioFileManager_GetFileBuffer(AudioFileManager * afm)
  26.548 -{
  26.549 -    return afm->mFileBuffer;
  26.550 -}
  26.551 -
  26.552 -const AudioFilePlayer *
  26.553 -AudioFileManager_GetParent(AudioFileManager * afm)
  26.554 -{
  26.555 -    return afm->mParent;
  26.556 -}
  26.557 -
  26.558 -static int
  26.559 -AudioFileManager_GetByteCounter(AudioFileManager * afm)
  26.560 -{
  26.561 -    return afm->mByteCounter;
  26.562 -}
  26.563 -
  26.564 -
  26.565 -static OSStatus
  26.566 -AudioFileManager_FileInputProc(void *inRefCon,
  26.567 -                               AudioUnitRenderActionFlags inActionFlags,
  26.568 -                               const AudioTimeStamp * inTimeStamp,
  26.569 -                               UInt32 inBusNumber, AudioBuffer * ioData)
  26.570 -{
  26.571 -    AudioFileManager *afm = (AudioFileManager *) inRefCon;
  26.572 -    return afm->Render(afm, ioData);
  26.573 -}
  26.574 -
  26.575 -static OSStatus
  26.576 -AudioFileManager_Render(AudioFileManager * afm, AudioBuffer * ioData)
  26.577 -{
  26.578 -    OSStatus result = noErr;
  26.579 -
  26.580 -    if (afm->mBufferOffset >= afm->mBufferSize) {
  26.581 -        result = afm->GetFileData(afm, &afm->mTmpBuffer, &afm->mBufferSize);
  26.582 -        if (result) {
  26.583 -            SDL_SetError("AudioConverterFillBuffer:%ld\n", result);
  26.584 -            afm->mParent->DoNotification(afm->mParent, result);
  26.585 -            return result;
  26.586 -        }
  26.587 -
  26.588 -        afm->mBufferOffset = 0;
  26.589 -    }
  26.590 -
  26.591 -    if (ioData->mDataByteSize > afm->mBufferSize - afm->mBufferOffset)
  26.592 -        ioData->mDataByteSize = afm->mBufferSize - afm->mBufferOffset;
  26.593 -    ioData->mData = (char *) afm->mTmpBuffer + afm->mBufferOffset;
  26.594 -    afm->mBufferOffset += ioData->mDataByteSize;
  26.595 -
  26.596 -    afm->mByteCounter += ioData->mDataByteSize;
  26.597 -    afm->AfterRender(afm);
  26.598 -    return result;
  26.599 -}
  26.600 -
  26.601 -
  26.602 -void
  26.603 -delete_AudioFileManager(AudioFileManager * afm)
  26.604 -{
  26.605 -    if (afm != NULL) {
  26.606 -        if (afm->mFileBuffer) {
  26.607 -            free(afm->mFileBuffer);
  26.608 -        }
  26.609 -
  26.610 -        SDL_free(afm);
  26.611 -    }
  26.612 -}
  26.613 -
  26.614 -
  26.615 -AudioFileManager *
  26.616 -new_AudioFileManager(AudioFilePlayer * inParent,
  26.617 -                     SInt16 inForkRefNum,
  26.618 -                     SInt64 inFileLength, UInt32 inChunkSize)
  26.619 -{
  26.620 -    AudioFileManager *afm;
  26.621 -
  26.622 -    if (sReaderThread == NULL) {
  26.623 -        sReaderThread = new_FileReaderThread();
  26.624 -        if (sReaderThread == NULL)
  26.625 -            return NULL;
  26.626 -    }
  26.627 -
  26.628 -    afm = (AudioFileManager *) SDL_malloc(sizeof(AudioFileManager));
  26.629 -    if (afm == NULL)
  26.630 -        return NULL;
  26.631 -    SDL_memset(afm, '\0', sizeof(*afm));
  26.632 -
  26.633 -#define SET_AUDIOFILEMANAGER_METHOD(m) afm->m = AudioFileManager_##m
  26.634 -    SET_AUDIOFILEMANAGER_METHOD(Disconnect);
  26.635 -    SET_AUDIOFILEMANAGER_METHOD(DoConnect);
  26.636 -    SET_AUDIOFILEMANAGER_METHOD(Read);
  26.637 -    SET_AUDIOFILEMANAGER_METHOD(GetFileBuffer);
  26.638 -    SET_AUDIOFILEMANAGER_METHOD(GetParent);
  26.639 -    SET_AUDIOFILEMANAGER_METHOD(SetPosition);
  26.640 -    SET_AUDIOFILEMANAGER_METHOD(GetByteCounter);
  26.641 -    SET_AUDIOFILEMANAGER_METHOD(SetEndOfFile);
  26.642 -    SET_AUDIOFILEMANAGER_METHOD(Render);
  26.643 -    SET_AUDIOFILEMANAGER_METHOD(GetFileData);
  26.644 -    SET_AUDIOFILEMANAGER_METHOD(AfterRender);
  26.645 -    SET_AUDIOFILEMANAGER_METHOD(FileInputProc);
  26.646 -#undef SET_AUDIOFILEMANAGER_METHOD
  26.647 -
  26.648 -    afm->mParent = inParent;
  26.649 -    afm->mForkRefNum = inForkRefNum;
  26.650 -    afm->mBufferSize = inChunkSize;
  26.651 -    afm->mBufferOffset = inChunkSize;
  26.652 -    afm->mChunkSize = inChunkSize;
  26.653 -    afm->mFileLength = inFileLength;
  26.654 -    afm->mFileBuffer = (char *) SDL_malloc(afm->mChunkSize * 2);
  26.655 -    FSGetForkPosition(afm->mForkRefNum, &afm->mAudioDataOffset);
  26.656 -    assert(afm->mFileBuffer != NULL);
  26.657 -    return afm;
  26.658 -}
  26.659 -
  26.660 -/* vi: set ts=4 sw=4 expandtab: */
    27.1 --- a/src/cdrom/macosx/CDPlayer.c	Sat Sep 05 09:03:35 2009 +0000
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,669 +0,0 @@
    27.4 -/*
    27.5 -    SDL - Simple DirectMedia Layer
    27.6 -    Copyright (C) 1997-2009 Sam Lantinga
    27.7 -
    27.8 -    This library is free software; you can redistribute it and/or
    27.9 -    modify it under the terms of the GNU Library General Public
   27.10 -    License as published by the Free Software Foundation; either
   27.11 -    version 2 of the License, or (at your option) any later version.
   27.12 -
   27.13 -    This library is distributed in the hope that it will be useful,
   27.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   27.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   27.16 -    Library General Public License for more details.
   27.17 -
   27.18 -    You should have received a copy of the GNU Library General Public
   27.19 -    License along with this library; if not, write to the Free
   27.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   27.21 -
   27.22 -    Sam Lantinga
   27.23 -    slouken@libsdl.org
   27.24 -*/
   27.25 -#include "SDL_config.h"
   27.26 -
   27.27 -#include "CDPlayer.h"
   27.28 -#include "AudioFilePlayer.h"
   27.29 -#include "SDLOSXCAGuard.h"
   27.30 -
   27.31 -/* we're exporting these functions into C land for SDL_syscdrom.c */
   27.32 -/*extern "C" {*/
   27.33 -
   27.34 -/*///////////////////////////////////////////////////////////////////////////
   27.35 -    Constants
   27.36 -  //////////////////////////////////////////////////////////////////////////*/
   27.37 -
   27.38 -#define kAudioCDFilesystemID   (UInt16)(('J' << 8) | 'H')       /* 'JH'; this avoids compiler warning */
   27.39 -
   27.40 -/* XML PList keys */
   27.41 -#define kRawTOCDataString           "Format 0x02 TOC Data"
   27.42 -#define kSessionsString             "Sessions"
   27.43 -#define kSessionTypeString          "Session Type"
   27.44 -#define kTrackArrayString           "Track Array"
   27.45 -#define kFirstTrackInSessionString      "First Track"
   27.46 -#define kLastTrackInSessionString       "Last Track"
   27.47 -#define kLeadoutBlockString         "Leadout Block"
   27.48 -#define kDataKeyString              "Data"
   27.49 -#define kPointKeyString             "Point"
   27.50 -#define kSessionNumberKeyString         "Session Number"
   27.51 -#define kStartBlockKeyString            "Start Block"
   27.52 -
   27.53 -/*///////////////////////////////////////////////////////////////////////////
   27.54 -    Globals
   27.55 -  //////////////////////////////////////////////////////////////////////////*/
   27.56 -
   27.57 -#pragma mark -- Globals --
   27.58 -
   27.59 -static int playBackWasInit = 0;
   27.60 -static AudioUnit theUnit;
   27.61 -static AudioFilePlayer *thePlayer = NULL;
   27.62 -static CDPlayerCompletionProc completionProc = NULL;
   27.63 -static SDL_mutex *apiMutex = NULL;
   27.64 -static SDL_sem *callbackSem;
   27.65 -static SDL_CD *theCDROM;
   27.66 -
   27.67 -/*///////////////////////////////////////////////////////////////////////////
   27.68 -    Prototypes
   27.69 -  //////////////////////////////////////////////////////////////////////////*/
   27.70 -
   27.71 -#pragma mark -- Prototypes --
   27.72 -
   27.73 -static OSStatus CheckInit();
   27.74 -
   27.75 -static void FilePlayNotificationHandler(void *inRefCon, OSStatus inStatus);
   27.76 -
   27.77 -static int RunCallBackThread(void *inRefCon);
   27.78 -
   27.79 -
   27.80 -#pragma mark -- Public Functions --
   27.81 -
   27.82 -void
   27.83 -Lock()
   27.84 -{
   27.85 -    if (!apiMutex) {
   27.86 -        apiMutex = SDL_CreateMutex();
   27.87 -    }
   27.88 -    SDL_mutexP(apiMutex);
   27.89 -}
   27.90 -
   27.91 -void
   27.92 -Unlock()
   27.93 -{
   27.94 -    SDL_mutexV(apiMutex);
   27.95 -}
   27.96 -
   27.97 -int
   27.98 -DetectAudioCDVolumes(FSVolumeRefNum * volumes, int numVolumes)
   27.99 -{
  27.100 -    int volumeIndex;
  27.101 -    int cdVolumeCount = 0;
  27.102 -    OSStatus result = noErr;
  27.103 -
  27.104 -    for (volumeIndex = 1; result == noErr || result != nsvErr; volumeIndex++) {
  27.105 -        FSVolumeRefNum actualVolume;
  27.106 -        FSVolumeInfo volumeInfo;
  27.107 -
  27.108 -        memset(&volumeInfo, 0, sizeof(volumeInfo));
  27.109 -
  27.110 -        result = FSGetVolumeInfo(kFSInvalidVolumeRefNum,
  27.111 -                                 volumeIndex,
  27.112 -                                 &actualVolume,
  27.113 -                                 kFSVolInfoFSInfo, &volumeInfo, NULL, NULL);
  27.114 -
  27.115 -        if (result == noErr) {
  27.116 -            if (volumeInfo.filesystemID == kAudioCDFilesystemID) {      /* It's an audio CD */
  27.117 -                if (volumes != NULL && cdVolumeCount < numVolumes)
  27.118 -                    volumes[cdVolumeCount] = actualVolume;
  27.119 -
  27.120 -                cdVolumeCount++;
  27.121 -            }
  27.122 -        } else {
  27.123 -            /* I'm commenting this out because it seems to be harmless */
  27.124 -            /*SDL_SetError ("DetectAudioCDVolumes: FSGetVolumeInfo returned %d", result); */
  27.125 -        }
  27.126 -    }
  27.127 -
  27.128 -    return cdVolumeCount;
  27.129 -}
  27.130 -
  27.131 -int
  27.132 -ReadTOCData(FSVolumeRefNum theVolume, SDL_CD * theCD)
  27.133 -{
  27.134 -    HFSUniStr255 dataForkName;
  27.135 -    OSStatus theErr;
  27.136 -    SInt16 forkRefNum;
  27.137 -    SInt64 forkSize;
  27.138 -    Ptr forkData = 0;
  27.139 -    ByteCount actualRead;
  27.140 -    CFDataRef dataRef = 0;
  27.141 -    CFPropertyListRef propertyListRef = 0;
  27.142 -
  27.143 -    FSRefParam fsRefPB;
  27.144 -    FSRef tocPlistFSRef;
  27.145 -
  27.146 -    const char *error = "Unspecified Error";
  27.147 -
  27.148 -    /* get stuff from .TOC.plist */
  27.149 -    fsRefPB.ioCompletion = NULL;
  27.150 -    fsRefPB.ioNamePtr = "\p.TOC.plist";
  27.151 -    fsRefPB.ioVRefNum = theVolume;
  27.152 -    fsRefPB.ioDirID = 0;
  27.153 -    fsRefPB.newRef = &tocPlistFSRef;
  27.154 -
  27.155 -    theErr = PBMakeFSRefSync(&fsRefPB);
  27.156 -    if (theErr != noErr) {
  27.157 -        error = "PBMakeFSRefSync";
  27.158 -        goto bail;
  27.159 -    }
  27.160 -
  27.161 -    /* Load and parse the TOC XML data */
  27.162 -
  27.163 -    theErr = FSGetDataForkName(&dataForkName);
  27.164 -    if (theErr != noErr) {
  27.165 -        error = "FSGetDataForkName";
  27.166 -        goto bail;
  27.167 -    }
  27.168 -
  27.169 -    theErr =
  27.170 -        FSOpenFork(&tocPlistFSRef, dataForkName.length, dataForkName.unicode,
  27.171 -                   fsRdPerm, &forkRefNum);
  27.172 -    if (theErr != noErr) {
  27.173 -        error = "FSOpenFork";
  27.174 -        goto bail;
  27.175 -    }
  27.176 -
  27.177 -    theErr = FSGetForkSize(forkRefNum, &forkSize);
  27.178 -    if (theErr != noErr) {
  27.179 -        error = "FSGetForkSize";
  27.180 -        goto bail;
  27.181 -    }
  27.182 -
  27.183 -    /* Allocate some memory for the XML data */
  27.184 -    forkData = NewPtr(forkSize);
  27.185 -    if (forkData == NULL) {
  27.186 -        error = "NewPtr";
  27.187 -        goto bail;
  27.188 -    }
  27.189 -
  27.190 -    theErr = FSReadFork(forkRefNum, fsFromStart, 0 /* offset location */ ,
  27.191 -                        forkSize, forkData, &actualRead);
  27.192 -    if (theErr != noErr) {
  27.193 -        error = "FSReadFork";
  27.194 -        goto bail;
  27.195 -    }
  27.196 -
  27.197 -    dataRef = CFDataCreate(kCFAllocatorDefault, (UInt8 *) forkData, forkSize);
  27.198 -    if (dataRef == 0) {
  27.199 -        error = "CFDataCreate";
  27.200 -        goto bail;
  27.201 -    }
  27.202 -
  27.203 -    propertyListRef = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
  27.204 -                                                      dataRef,
  27.205 -                                                      kCFPropertyListImmutable,
  27.206 -                                                      NULL);
  27.207 -    if (propertyListRef == NULL) {
  27.208 -        error = "CFPropertyListCreateFromXMLData";
  27.209 -        goto bail;
  27.210 -    }
  27.211 -
  27.212 -    /* Now we got the Property List in memory. Parse it. */
  27.213 -
  27.214 -    /* First, make sure the root item is a CFDictionary. If not, release and bail. */
  27.215 -    if (CFGetTypeID(propertyListRef) == CFDictionaryGetTypeID()) {
  27.216 -        CFDictionaryRef dictRef = (CFDictionaryRef) propertyListRef;
  27.217 -
  27.218 -        CFDataRef theRawTOCDataRef;
  27.219 -        CFArrayRef theSessionArrayRef;
  27.220 -        CFIndex numSessions;
  27.221 -        CFIndex index;
  27.222 -
  27.223 -        /* This is how we get the Raw TOC Data */
  27.224 -        theRawTOCDataRef =
  27.225 -            (CFDataRef) CFDictionaryGetValue(dictRef,
  27.226 -                                             CFSTR(kRawTOCDataString));
  27.227 -
  27.228 -        /* Get the session array info. */
  27.229 -        theSessionArrayRef =
  27.230 -            (CFArrayRef) CFDictionaryGetValue(dictRef,
  27.231 -                                              CFSTR(kSessionsString));
  27.232 -
  27.233 -        /* Find out how many sessions there are. */
  27.234 -        numSessions = CFArrayGetCount(theSessionArrayRef);
  27.235 -
  27.236 -        /* Initialize the total number of tracks to 0 */
  27.237 -        theCD->numtracks = 0;
  27.238 -
  27.239 -        /* Iterate over all sessions, collecting the track data */
  27.240 -        for (index = 0; index < numSessions; index++) {
  27.241 -            CFDictionaryRef theSessionDict;
  27.242 -            CFNumberRef leadoutBlock;
  27.243 -            CFArrayRef trackArray;
  27.244 -            CFIndex numTracks;
  27.245 -            CFIndex trackIndex;
  27.246 -            UInt32 value = 0;
  27.247 -
  27.248 -            theSessionDict = (CFDictionaryRef)
  27.249 -                CFArrayGetValueAtIndex(theSessionArrayRef, index);
  27.250 -            leadoutBlock =
  27.251 -                (CFNumberRef) CFDictionaryGetValue(theSessionDict,
  27.252 -                                                   CFSTR
  27.253 -                                                   (kLeadoutBlockString));
  27.254 -
  27.255 -            trackArray =
  27.256 -                (CFArrayRef) CFDictionaryGetValue(theSessionDict,
  27.257 -                                                  CFSTR(kTrackArrayString));
  27.258 -
  27.259 -            numTracks = CFArrayGetCount(trackArray);
  27.260 -
  27.261 -            for (trackIndex = 0; trackIndex < numTracks; trackIndex++) {
  27.262 -
  27.263 -                CFDictionaryRef theTrackDict;
  27.264 -                CFNumberRef trackNumber;
  27.265 -                CFNumberRef sessionNumber;
  27.266 -                CFNumberRef startBlock;
  27.267 -                CFBooleanRef isDataTrack;
  27.268 -                UInt32 value;
  27.269 -
  27.270 -                theTrackDict = (CFDictionaryRef)
  27.271 -                    CFArrayGetValueAtIndex(trackArray, trackIndex);
  27.272 -
  27.273 -                trackNumber =
  27.274 -                    (CFNumberRef) CFDictionaryGetValue(theTrackDict,
  27.275 -                                                       CFSTR
  27.276 -                                                       (kPointKeyString));
  27.277 -                sessionNumber =
  27.278 -                    (CFNumberRef) CFDictionaryGetValue(theTrackDict,
  27.279 -                                                       CFSTR
  27.280 -                                                       (kSessionNumberKeyString));
  27.281 -                startBlock =
  27.282 -                    (CFNumberRef) CFDictionaryGetValue(theTrackDict,
  27.283 -                                                       CFSTR
  27.284 -                                                       (kStartBlockKeyString));
  27.285 -                isDataTrack =
  27.286 -                    (CFBooleanRef) CFDictionaryGetValue(theTrackDict,
  27.287 -                                                        CFSTR
  27.288 -                                                        (kDataKeyString));
  27.289 -
  27.290 -                /* Fill in the SDL_CD struct */
  27.291 -                int idx = theCD->numtracks++;
  27.292 -
  27.293 -                CFNumberGetValue(trackNumber, kCFNumberSInt32Type, &value);
  27.294 -                theCD->track[idx].id = value;
  27.295 -
  27.296 -                CFNumberGetValue(startBlock, kCFNumberSInt32Type, &value);
  27.297 -                theCD->track[idx].offset = value;
  27.298 -
  27.299 -                theCD->track[idx].type =
  27.300 -                    (isDataTrack ==
  27.301 -                     kCFBooleanTrue) ? SDL_DATA_TRACK : SDL_AUDIO_TRACK;
  27.302 -
  27.303 -                /* Since the track lengths are not stored in .TOC.plist we compute them. */
  27.304 -                if (trackIndex > 0) {
  27.305 -                    theCD->track[idx - 1].length =
  27.306 -                        theCD->track[idx].offset - theCD->track[idx -
  27.307 -                                                                1].offset;
  27.308 -                }
  27.309 -            }
  27.310 -
  27.311 -            /* Compute the length of the last track */
  27.312 -            CFNumberGetValue(leadoutBlock, kCFNumberSInt32Type, &value);
  27.313 -
  27.314 -            theCD->track[theCD->numtracks - 1].length =
  27.315 -                value - theCD->track[theCD->numtracks - 1].offset;
  27.316 -
  27.317 -            /* Set offset to leadout track */
  27.318 -            theCD->track[theCD->numtracks].offset = value;
  27.319 -        }
  27.320 -
  27.321 -    }
  27.322 -
  27.323 -    theErr = 0;
  27.324 -    goto cleanup;
  27.325 -  bail:
  27.326 -    SDL_SetError("ReadTOCData: %s returned %d", error, theErr);
  27.327 -    theErr = -1;
  27.328 -  cleanup:
  27.329 -
  27.330 -    if (propertyListRef != NULL)
  27.331 -        CFRelease(propertyListRef);
  27.332 -    if (dataRef != NULL)
  27.333 -        CFRelease(dataRef);
  27.334 -    if (forkData != NULL)
  27.335 -        DisposePtr(forkData);
  27.336 -
  27.337 -    FSCloseFork(forkRefNum);
  27.338 -
  27.339 -    return theErr;
  27.340 -}
  27.341 -
  27.342 -int
  27.343 -ListTrackFiles(FSVolumeRefNum theVolume, FSRef * trackFiles, int numTracks)
  27.344 -{
  27.345 -    OSStatus result = -1;
  27.346 -    FSIterator iterator;
  27.347 -    ItemCount actualObjects;
  27.348 -    FSRef rootDirectory;
  27.349 -    FSRef ref;
  27.350 -    HFSUniStr255 nameStr;
  27.351 -
  27.352 -    result = FSGetVolumeInfo(theVolume,
  27.353 -                             0,
  27.354 -                             NULL,
  27.355 -                             kFSVolInfoFSInfo, NULL, NULL, &rootDirectory);
  27.356 -
  27.357 -    if (result != noErr) {
  27.358 -        SDL_SetError("ListTrackFiles: FSGetVolumeInfo returned %d", result);
  27.359 -        return result;
  27.360 -    }
  27.361 -
  27.362 -    result = FSOpenIterator(&rootDirectory, kFSIterateFlat, &iterator);
  27.363 -    if (result == noErr) {
  27.364 -        do {
  27.365 -            result = FSGetCatalogInfoBulk(iterator, 1, &actualObjects,
  27.366 -                                          NULL, kFSCatInfoNone, NULL,
  27.367 -                                          &ref, NULL, &nameStr);
  27.368 -            if (result == noErr) {
  27.369 -
  27.370 -                CFStringRef name;
  27.371 -                name =
  27.372 -                    CFStringCreateWithCharacters(NULL, nameStr.unicode,
  27.373 -                                                 nameStr.length);
  27.374 -
  27.375 -                /* Look for .aiff extension */
  27.376 -                if (CFStringHasSuffix(name, CFSTR(".aiff")) ||
  27.377 -                    CFStringHasSuffix(name, CFSTR(".cdda"))) {
  27.378 -
  27.379 -                    /* Extract the track id from the filename */
  27.380 -                    int trackID = 0, i = 0;
  27.381 -                    while (i < nameStr.length && !isdigit(nameStr.unicode[i])) {
  27.382 -                        ++i;
  27.383 -                    }
  27.384 -                    while (i < nameStr.length && isdigit(nameStr.unicode[i])) {
  27.385 -                        trackID = 10 * trackID + (nameStr.unicode[i] - '0');
  27.386 -                        ++i;
  27.387 -                    }
  27.388 -
  27.389 -#if DEBUG_CDROM
  27.390 -                    printf("Found AIFF for track %d: '%s'\n",
  27.391 -                           trackID, CFStringGetCStringPtr(name,
  27.392 -                                                          CFStringGetSystemEncoding
  27.393 -                                                          ()));
  27.394 -#endif
  27.395 -
  27.396 -                    /* Track ID's start at 1, but we want to start at 0 */
  27.397 -                    trackID--;
  27.398 -
  27.399 -                    assert(0 <= trackID && trackID <= SDL_MAX_TRACKS);
  27.400 -
  27.401 -                    if (trackID < numTracks)
  27.402 -                        memcpy(&trackFiles[trackID], &ref, sizeof(FSRef));
  27.403 -                }
  27.404 -                CFRelease(name);
  27.405 -            }
  27.406 -        } while (noErr == result);
  27.407 -        FSCloseIterator(iterator);
  27.408 -    }
  27.409 -
  27.410 -    return 0;
  27.411 -}
  27.412 -
  27.413 -int
  27.414 -LoadFile(const FSRef * ref, int startFrame, int stopFrame)
  27.415 -{
  27.416 -    int error = -1;
  27.417 -
  27.418 -    if (CheckInit() < 0)
  27.419 -        goto bail;
  27.420 -
  27.421 -    /* release any currently playing file */
  27.422 -    if (ReleaseFile() < 0)
  27.423 -        goto bail;
  27.424 -
  27.425 -#if DEBUG_CDROM
  27.426 -    printf("LoadFile: %d %d\n", startFrame, stopFrame);
  27.427 -#endif
  27.428 -
  27.429 -    /*try { */
  27.430 -
  27.431 -    /* create a new player, and attach to the audio unit */
  27.432 -
  27.433 -    thePlayer = new_AudioFilePlayer(ref);
  27.434 -    if (thePlayer == NULL) {
  27.435 -        SDL_SetError("LoadFile: Could not create player");
  27.436 -        return -3;              /*throw (-3); */
  27.437 -    }
  27.438 -
  27.439 -    if (!thePlayer->SetDestination(thePlayer, &theUnit))
  27.440 -        goto bail;
  27.441 -
  27.442 -    if (startFrame >= 0)
  27.443 -        thePlayer->SetStartFrame(thePlayer, startFrame);
  27.444 -
  27.445 -    if (stopFrame >= 0 && stopFrame > startFrame)
  27.446 -        thePlayer->SetStopFrame(thePlayer, stopFrame);
  27.447 -
  27.448 -    /* we set the notifier later */
  27.449 -    /*thePlayer->SetNotifier(thePlayer, FilePlayNotificationHandler, NULL); */
  27.450 -
  27.451 -    if (!thePlayer->Connect(thePlayer))
  27.452 -        goto bail;
  27.453 -
  27.454 -#if DEBUG_CDROM
  27.455 -    thePlayer->Print(thePlayer);
  27.456 -    fflush(stdout);
  27.457 -#endif
  27.458 -    /*}
  27.459 -       catch (...)
  27.460 -       {
  27.461 -       goto bail;
  27.462 -       } */
  27.463 -
  27.464 -    error = 0;
  27.465 -
  27.466 -  bail:
  27.467 -    return error;
  27.468 -}
  27.469 -
  27.470 -int
  27.471 -ReleaseFile()
  27.472 -{
  27.473 -    int error = -1;
  27.474 -
  27.475 -    /* (Don't see any way that the original C++ code could throw here.) --ryan. */
  27.476 -    /*try { */
  27.477 -    if (thePlayer != NULL) {
  27.478 -
  27.479 -        thePlayer->Disconnect(thePlayer);
  27.480 -
  27.481 -        delete_AudioFilePlayer(thePlayer);
  27.482 -
  27.483 -        thePlayer = NULL;
  27.484 -    }
  27.485 -    /*}
  27.486 -       catch (...)
  27.487 -       {
  27.488 -       goto bail;
  27.489 -       } */
  27.490 -
  27.491 -    error = 0;
  27.492 -
  27.493 -/*  bail: */
  27.494 -    return error;
  27.495 -}
  27.496 -
  27.497 -int
  27.498 -PlayFile()
  27.499 -{
  27.500 -    OSStatus result = -1;
  27.501 -
  27.502 -    if (CheckInit() < 0)
  27.503 -        goto bail;
  27.504 -
  27.505 -    /*try { */
  27.506 -
  27.507 -    // start processing of the audio unit
  27.508 -    result = AudioOutputUnitStart(theUnit);
  27.509 -    if (result)
  27.510 -        goto bail;              //THROW_RESULT("PlayFile: AudioOutputUnitStart")
  27.511 -
  27.512 -    /*}
  27.513 -       catch (...)
  27.514 -       {
  27.515 -       goto bail;
  27.516 -       } */
  27.517 -
  27.518 -    result = 0;
  27.519 -
  27.520 -  bail:
  27.521 -    return result;
  27.522 -}
  27.523 -
  27.524 -int
  27.525 -PauseFile()
  27.526 -{
  27.527 -    OSStatus result = -1;
  27.528 -
  27.529 -    if (CheckInit() < 0)
  27.530 -        goto bail;
  27.531 -
  27.532 -    /*try { */
  27.533 -
  27.534 -    /* stop processing the audio unit */
  27.535 -    result = AudioOutputUnitStop(theUnit);
  27.536 -    if (result)
  27.537 -        goto bail;              /*THROW_RESULT("PauseFile: AudioOutputUnitStop") */
  27.538 -    /*}
  27.539 -       catch (...)
  27.540 -       {
  27.541 -       goto bail;
  27.542 -       } */
  27.543 -
  27.544 -    result = 0;
  27.545 -  bail:
  27.546 -    return result;
  27.547 -}
  27.548 -
  27.549 -void
  27.550 -SetCompletionProc(CDPlayerCompletionProc proc, SDL_CD * cdrom)
  27.551 -{
  27.552 -    assert(thePlayer != NULL);
  27.553 -
  27.554 -    theCDROM = cdrom;
  27.555 -    completionProc = proc;
  27.556 -    thePlayer->SetNotifier(thePlayer, FilePlayNotificationHandler, cdrom);
  27.557 -}
  27.558 -
  27.559 -int
  27.560 -GetCurrentFrame()
  27.561 -{
  27.562 -    int frame;
  27.563 -
  27.564 -    if (thePlayer == NULL)
  27.565 -        frame = 0;
  27.566 -    else
  27.567 -        frame = thePlayer->GetCurrentFrame(thePlayer);
  27.568 -
  27.569 -    return frame;
  27.570 -}
  27.571 -
  27.572 -
  27.573 -#pragma mark -- Private Functions --
  27.574 -
  27.575 -static OSStatus
  27.576 -CheckInit()
  27.577 -{
  27.578 -    if (playBackWasInit)
  27.579 -        return 0;
  27.580 -
  27.581 -    OSStatus result = noErr;
  27.582 -
  27.583 -    /* Create the callback semaphore */
  27.584 -    callbackSem = SDL_CreateSemaphore(0);
  27.585 -
  27.586 -    /* Start callback thread */
  27.587 -    SDL_CreateThread(RunCallBackThread, NULL);
  27.588 -
  27.589 -    {                           /*try { */
  27.590 -        ComponentDescription desc;
  27.591 -
  27.592 -        desc.componentType = kAudioUnitComponentType;
  27.593 -        desc.componentSubType = kAudioUnitSubType_Output;
  27.594 -        desc.componentManufacturer = kAudioUnitID_DefaultOutput;
  27.595 -        desc.componentFlags = 0;
  27.596 -        desc.componentFlagsMask = 0;
  27.597 -
  27.598 -        Component comp = FindNextComponent(NULL, &desc);
  27.599 -        if (comp == NULL) {
  27.600 -            SDL_SetError("CheckInit: FindNextComponent returned NULL");
  27.601 -            if (result)
  27.602 -                return -1;      //throw(internalComponentErr);
  27.603 -        }
  27.604 -
  27.605 -        result = OpenAComponent(comp, &theUnit);
  27.606 -        if (result)
  27.607 -            return -1;          //THROW_RESULT("CheckInit: OpenAComponent")
  27.608 -
  27.609 -        // you need to initialize the output unit before you set it as a destination
  27.610 -        result = AudioUnitInitialize(theUnit);
  27.611 -        if (result)
  27.612 -            return -1;          //THROW_RESULT("CheckInit: AudioUnitInitialize")
  27.613 -
  27.614 -
  27.615 -        playBackWasInit = true;
  27.616 -    }
  27.617 -    /*catch (...)
  27.618 -       {
  27.619 -       return -1;
  27.620 -       } */
  27.621 -
  27.622 -    return 0;
  27.623 -}
  27.624 -
  27.625 -static void
  27.626 -FilePlayNotificationHandler(void *inRefCon, OSStatus inStatus)
  27.627 -{
  27.628 -    if (inStatus == kAudioFilePlay_FileIsFinished) {
  27.629 -
  27.630 -        /* notify non-CA thread to perform the callback */
  27.631 -        SDL_SemPost(callbackSem);
  27.632 -
  27.633 -    } else if (inStatus == kAudioFilePlayErr_FilePlayUnderrun) {
  27.634 -
  27.635 -        SDL_SetError("CDPlayer Notification: buffer underrun");
  27.636 -    } else if (inStatus == kAudioFilePlay_PlayerIsUninitialized) {
  27.637 -
  27.638 -        SDL_SetError("CDPlayer Notification: player is uninitialized");
  27.639 -    } else {
  27.640 -
  27.641 -        SDL_SetError("CDPlayer Notification: unknown error %ld", inStatus);
  27.642 -    }
  27.643 -}
  27.644 -
  27.645 -static int
  27.646 -RunCallBackThread(void *param)
  27.647 -{
  27.648 -    for (;;) {
  27.649 -
  27.650 -        SDL_SemWait(callbackSem);
  27.651 -
  27.652 -        if (completionProc && theCDROM) {
  27.653 -#if DEBUG_CDROM
  27.654 -            printf("callback!\n");
  27.655 -#endif
  27.656 -            (*completionProc) (theCDROM);
  27.657 -        } else {
  27.658 -#if DEBUG_CDROM
  27.659 -            printf("callback?\n");
  27.660 -#endif
  27.661 -        }
  27.662 -    }
  27.663 -
  27.664 -#if DEBUG_CDROM
  27.665 -    printf("thread dying now...\n");
  27.666 -#endif
  27.667 -
  27.668 -    return 0;
  27.669 -}
  27.670 -
  27.671 -/*}; // extern "C" */
  27.672 -/* vi: set ts=4 sw=4 expandtab: */
    28.1 --- a/src/cdrom/macosx/CDPlayer.h	Sat Sep 05 09:03:35 2009 +0000
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,72 +0,0 @@
    28.4 -/*
    28.5 -    SDL - Simple DirectMedia Layer
    28.6 -    Copyright (C) 1997-2009 Sam Lantinga
    28.7 -
    28.8 -    This library is free software; you can redistribute it and/or
    28.9 -    modify it under the terms of the GNU Library General Public
   28.10 -    License as published by the Free Software Foundation; either
   28.11 -    version 2 of the License, or (at your option) any later version.
   28.12 -
   28.13 -    This library is distributed in the hope that it will be useful,
   28.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   28.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   28.16 -    Library General Public License for more details.
   28.17 -
   28.18 -    You should have received a copy of the GNU Library General Public
   28.19 -    License along with this library; if not, write to the Free
   28.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   28.21 -
   28.22 -    Sam Lantinga
   28.23 -    slouken@libsdl.org
   28.24 -*/
   28.25 -#include "SDL_config.h"
   28.26 -
   28.27 -#ifndef __CDPlayer__H__
   28.28 -#define __CDPlayer__H__ 1
   28.29 -
   28.30 -#include <string.h>
   28.31 -
   28.32 -#include <Carbon/Carbon.h>
   28.33 -#include <CoreFoundation/CoreFoundation.h>
   28.34 -#include <AudioUnit/AudioUnit.h>
   28.35 -
   28.36 -#include "SDL_cdrom.h"
   28.37 -#include "SDL_thread.h"
   28.38 -#include "SDL_mutex.h"
   28.39 -
   28.40 -#ifdef __cplusplus
   28.41 -extern "C"
   28.42 -{
   28.43 -#endif
   28.44 -
   28.45 -    typedef void (*CDPlayerCompletionProc) (SDL_CD * cdrom);
   28.46 -
   28.47 -    void Lock();
   28.48 -
   28.49 -    void Unlock();
   28.50 -
   28.51 -    int LoadFile(const FSRef * ref, int startFrame, int endFrame);      /* pass -1 to do nothing */
   28.52 -
   28.53 -    int ReleaseFile();
   28.54 -
   28.55 -    int PlayFile();
   28.56 -
   28.57 -    int PauseFile();
   28.58 -
   28.59 -    void SetCompletionProc(CDPlayerCompletionProc proc, SDL_CD * cdrom);
   28.60 -
   28.61 -    int ReadTOCData(FSVolumeRefNum theVolume, SDL_CD * theCD);
   28.62 -
   28.63 -    int ListTrackFiles(FSVolumeRefNum theVolume, FSRef * trackFiles,
   28.64 -                       int numTracks);
   28.65 -
   28.66 -    int DetectAudioCDVolumes(FSVolumeRefNum * volumes, int numVolumes);
   28.67 -
   28.68 -    int GetCurrentFrame();
   28.69 -
   28.70 -#ifdef __cplusplus
   28.71 -};
   28.72 -#endif
   28.73 -
   28.74 -#endif /* __CD_Player__H__ */
   28.75 -/* vi: set ts=4 sw=4 expandtab: */
    29.1 --- a/src/cdrom/macosx/SDLOSXCAGuard.c	Sat Sep 05 09:03:35 2009 +0000
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,205 +0,0 @@
    29.4 -/*
    29.5 -    SDL - Simple DirectMedia Layer
    29.6 -    Copyright (C) 1997-2009 Sam Lantinga
    29.7 -
    29.8 -    This library is free software; you can redistribute it and/or
    29.9 -    modify it under the terms of the GNU Library General Public
   29.10 -    License as published by the Free Software Foundation; either
   29.11 -    version 2 of the License, or (at your option) any later version.
   29.12 -
   29.13 -    This library is distributed in the hope that it will be useful,
   29.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   29.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   29.16 -    Library General Public License for more details.
   29.17 -
   29.18 -    You should have received a copy of the GNU Library General Public
   29.19 -    License along with this library; if not, write to the Free
   29.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   29.21 -
   29.22 -    Sam Lantinga
   29.23 -    slouken@libsdl.org
   29.24 -*/
   29.25 -#include "SDL_config.h"
   29.26 -
   29.27 -/*  
   29.28 -    Note: This file hasn't been modified so technically we have to keep the disclaimer :-(
   29.29 -    
   29.30 -    Copyright:   Copyright 2002 Apple Computer, Inc. All rights reserved.
   29.31 -
   29.32 -    Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
   29.33 -            ("Apple") in consideration of your agreement to the following terms, and your
   29.34 -            use, installation, modification or redistribution of this Apple software
   29.35 -            constitutes acceptance of these terms.  If you do not agree with these terms,
   29.36 -            please do not use, install, modify or redistribute this Apple software.
   29.37 -
   29.38 -            In consideration of your agreement to abide by the following terms, and subject
   29.39 -            to these terms, Apple grants you a personal, non-exclusive license, under Apples
   29.40 -            copyrights in this original Apple software (the "Apple Software"), to use,
   29.41 -            reproduce, modify and redistribute the Apple Software, with or without
   29.42 -            modifications, in source and/or binary forms; provided that if you redistribute
   29.43 -            the Apple Software in its entirety and without modifications, you must retain
   29.44 -            this notice and the following text and disclaimers in all such redistributions of
   29.45 -            the Apple Software.  Neither the name, trademarks, service marks or logos of
   29.46 -            Apple Computer, Inc. may be used to endorse or promote products derived from the
   29.47 -            Apple Software without specific prior written permission from Apple.  Except as
   29.48 -            expressly stated in this notice, no other rights or licenses, express or implied,
   29.49 -            are granted by Apple herein, including but not limited to any patent rights that
   29.50 -            may be infringed by your derivative works or by other works in which the Apple
   29.51 -            Software may be incorporated.
   29.52 -
   29.53 -            The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
   29.54 -            WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
   29.55 -            WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29.56 -            PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
   29.57 -            COMBINATION WITH YOUR PRODUCTS.
   29.58 -
   29.59 -            IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
   29.60 -            CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
   29.61 -            GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   29.62 -            ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
   29.63 -            OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
   29.64 -            (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
   29.65 -            ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   29.66 -*/
   29.67 -/*=============================================================================
   29.68 -    CAGuard.cp
   29.69 -
   29.70 -=============================================================================*/
   29.71 -
   29.72 -/*=============================================================================
   29.73 -    Includes
   29.74 -  =============================================================================*/
   29.75 -
   29.76 -/*
   29.77 -#include <stdio.h>
   29.78 -#include <stdlib.h>
   29.79 -#include <string.h>
   29.80 -*/
   29.81 -#include "SDL_stdinc.h"
   29.82 -
   29.83 -/*#define NDEBUG 1*/
   29.84 -/*
   29.85 -#include <assert.h>
   29.86 -*/
   29.87 -#define assert(X)
   29.88 -
   29.89 -
   29.90 -#include "SDLOSXCAGuard.h"
   29.91 -
   29.92 -/*#warning      Need a try-based Locker too*/
   29.93 -/*=============================================================================
   29.94 -    SDLOSXCAGuard
   29.95 -  =============================================================================*/
   29.96 -
   29.97 -static int
   29.98 -SDLOSXCAGuard_Lock(SDLOSXCAGuard * cag)
   29.99 -{
  29.100 -    int theAnswer = 0;
  29.101 -
  29.102 -    if (pthread_self() != cag->mOwner) {
  29.103 -        OSStatus theError = pthread_mutex_lock(&cag->mMutex);
  29.104 -        (void) theError;
  29.105 -        assert(theError == 0);
  29.106 -        cag->mOwner = pthread_self();
  29.107 -        theAnswer = 1;
  29.108 -    }
  29.109 -
  29.110 -    return theAnswer;
  29.111 -}
  29.112 -
  29.113 -static void
  29.114 -SDLOSXCAGuard_Unlock(SDLOSXCAGuard * cag)
  29.115 -{
  29.116 -    OSStatus theError;
  29.117 -    assert(pthread_self() == cag->mOwner);
  29.118 -
  29.119 -    cag->mOwner = 0;
  29.120 -    theError = pthread_mutex_unlock(&cag->mMutex);
  29.121 -    (void) theError;
  29.122 -    assert(theError == 0);
  29.123 -}
  29.124 -
  29.125 -static int
  29.126 -SDLOSXCAGuard_Try(SDLOSXCAGuard * cag, int *outWasLocked)
  29.127 -{
  29.128 -    int theAnswer = 0;
  29.129 -    *outWasLocked = 0;
  29.130 -
  29.131 -    if (pthread_self() == cag->mOwner) {
  29.132 -        theAnswer = 1;
  29.133 -        *outWasLocked = 0;
  29.134 -    } else {
  29.135 -        OSStatus theError = pthread_mutex_trylock(&cag->mMutex);
  29.136 -        if (theError == 0) {
  29.137 -            cag->mOwner = pthread_self();
  29.138 -            theAnswer = 1;
  29.139 -            *outWasLocked = 1;
  29.140 -        }
  29.141 -    }
  29.142 -
  29.143 -    return theAnswer;
  29.144 -}
  29.145 -
  29.146 -static void
  29.147 -SDLOSXCAGuard_Wait(SDLOSXCAGuard * cag)
  29.148 -{
  29.149 -    OSStatus theError;
  29.150 -    assert(pthread_self() == cag->mOwner);
  29.151 -
  29.152 -    cag->mOwner = 0;
  29.153 -
  29.154 -    theError = pthread_cond_wait(&cag->mCondVar, &cag->mMutex);
  29.155 -    (void) theError;
  29.156 -    assert(theError == 0);
  29.157 -    cag->mOwner = pthread_self();
  29.158 -}
  29.159 -
  29.160 -static void
  29.161 -SDLOSXCAGuard_Notify(SDLOSXCAGuard * cag)
  29.162 -{
  29.163 -    OSStatus theError = pthread_cond_signal(&cag->mCondVar);
  29.164 -    (void) theError;
  29.165 -    assert(theError == 0);
  29.166 -}
  29.167 -
  29.168 -
  29.169 -SDLOSXCAGuard *
  29.170 -new_SDLOSXCAGuard(void)
  29.171 -{
  29.172 -    OSStatus theError;
  29.173 -    SDLOSXCAGuard *cag = (SDLOSXCAGuard *) SDL_malloc(sizeof(SDLOSXCAGuard));
  29.174 -    if (cag == NULL)
  29.175 -        return NULL;
  29.176 -    SDL_memset(cag, '\0', sizeof(*cag));
  29.177 -
  29.178 -#define SET_SDLOSXCAGUARD_METHOD(m) cag->m = SDLOSXCAGuard_##m
  29.179 -    SET_SDLOSXCAGUARD_METHOD(Lock);
  29.180 -    SET_SDLOSXCAGUARD_METHOD(Unlock);
  29.181 -    SET_SDLOSXCAGUARD_METHOD(Try);
  29.182 -    SET_SDLOSXCAGUARD_METHOD(Wait);
  29.183 -    SET_SDLOSXCAGUARD_METHOD(Notify);
  29.184 -#undef SET_SDLOSXCAGUARD_METHOD
  29.185 -
  29.186 -    theError = pthread_mutex_init(&cag->mMutex, NULL);
  29.187 -    (void) theError;
  29.188 -    assert(theError == 0);
  29.189 -
  29.190 -    theError = pthread_cond_init(&cag->mCondVar, NULL);
  29.191 -    (void) theError;
  29.192 -    assert(theError == 0);
  29.193 -
  29.194 -    cag->mOwner = 0;
  29.195 -    return cag;
  29.196 -}
  29.197 -
  29.198 -void
  29.199 -delete_SDLOSXCAGuard(SDLOSXCAGuard * cag)
  29.200 -{
  29.201 -    if (cag != NULL) {
  29.202 -        pthread_mutex_destroy(&cag->mMutex);
  29.203 -        pthread_cond_destroy(&cag->mCondVar);
  29.204 -        SDL_free(cag);
  29.205 -    }
  29.206 -}
  29.207 -
  29.208 -/* vi: set ts=4 sw=4 expandtab: */
    30.1 --- a/src/cdrom/macosx/SDLOSXCAGuard.h	Sat Sep 05 09:03:35 2009 +0000
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,116 +0,0 @@
    30.4 -/*
    30.5 -    SDL - Simple DirectMedia Layer
    30.6 -    Copyright (C) 1997-2009 Sam Lantinga
    30.7 -
    30.8 -    This library is free software; you can redistribute it and/or
    30.9 -    modify it under the terms of the GNU Library General Public
   30.10 -    License as published by the Free Software Foundation; either
   30.11 -    version 2 of the License, or (at your option) any later version.
   30.12 -
   30.13 -    This library is distributed in the hope that it will be useful,
   30.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   30.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   30.16 -    Library General Public License for more details.
   30.17 -
   30.18 -    You should have received a copy of the GNU Library General Public
   30.19 -    License along with this library; if not, write to the Free
   30.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   30.21 -
   30.22 -    Sam Lantinga
   30.23 -    slouken@libsdl.org
   30.24 -*/
   30.25 -#include "SDL_config.h"
   30.26 -
   30.27 -/*  
   30.28 -    Note: This file hasn't been modified so technically we have to keep the disclaimer :-(
   30.29 -
   30.30 -
   30.31 -    Copyright:   Copyright 2002 Apple Computer, Inc. All rights reserved.
   30.32 -
   30.33 -    Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
   30.34 -            ("Apple") in consideration of your agreement to the following terms, and your
   30.35 -            use, installation, modification or redistribution of this Apple software
   30.36 -            constitutes acceptance of these terms.  If you do not agree with these terms,
   30.37 -            please do not use, install, modify or redistribute this Apple software.
   30.38 -
   30.39 -            In consideration of your agreement to abide by the following terms, and subject
   30.40 -            to these terms, Apple grants you a personal, non-exclusive license, under Apples
   30.41 -            copyrights in this original Apple software (the "Apple Software"), to use,
   30.42 -            reproduce, modify and redistribute the Apple Software, with or without
   30.43 -            modifications, in source and/or binary forms; provided that if you redistribute
   30.44 -            the Apple Software in its entirety and without modifications, you must retain
   30.45 -            this notice and the following text and disclaimers in all such redistributions of
   30.46 -            the Apple Software.  Neither the name, trademarks, service marks or logos of
   30.47 -            Apple Computer, Inc. may be used to endorse or promote products derived from the
   30.48 -            Apple Software without specific prior written permission from Apple.  Except as
   30.49 -            expressly stated in this notice, no other rights or licenses, express or implied,
   30.50 -            are granted by Apple herein, including but not limited to any patent rights that
   30.51 -            may be infringed by your derivative works or by other works in which the Apple
   30.52 -            Software may be incorporated.
   30.53 -
   30.54 -            The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
   30.55 -            WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
   30.56 -            WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   30.57 -            PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
   30.58 -            COMBINATION WITH YOUR PRODUCTS.
   30.59 -
   30.60 -            IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
   30.61 -            CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
   30.62 -            GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   30.63 -            ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
   30.64 -            OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
   30.65 -            (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
   30.66 -            ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   30.67 -*/
   30.68 -/*=============================================================================
   30.69 -    CAGuard.h
   30.70 -
   30.71 -=============================================================================*/
   30.72 -#if !defined(__CAGuard_h__)
   30.73 -#define __CAGuard_h__
   30.74 -
   30.75 -/*=============================================================================
   30.76 -    Includes
   30.77 -  =============================================================================*/
   30.78 -
   30.79 -#include <CoreAudio/CoreAudioTypes.h>
   30.80 -#include <pthread.h>
   30.81 -
   30.82 -
   30.83 -/*=============================================================================
   30.84 -    CAGuard
   30.85 -  
   30.86 -    This is your typical mutex with signalling implemented via pthreads.
   30.87 -    Lock() will return true if and only if the guard is locked on that call.
   30.88 -    A thread that already has the guard will receive 'false' if it locks it
   30.89 -    again. Use of the stack-based CAGuard::Locker class is highly recommended
   30.90 -    to properly manage the recursive nesting. The Wait calls with timeouts
   30.91 -    will return true if and only if the timeout period expired. They will
   30.92 -    return false if they receive notification any other way.
   30.93 -  =============================================================================*/
   30.94 -
   30.95 -typedef struct S_SDLOSXCAGuard
   30.96 -{
   30.97 -
   30.98 -/*  Construction/Destruction */
   30.99 -/*public:*/
  30.100 -/*  Actions */
  30.101 -/*public:*/
  30.102 -    int (*Lock) (struct S_SDLOSXCAGuard * cag);
  30.103 -    void (*Unlock) (struct S_SDLOSXCAGuard * cag);
  30.104 -    int (*Try) (struct S_SDLOSXCAGuard * cag, int *outWasLocked);       /* returns true if lock is free, false if not */
  30.105 -    void (*Wait) (struct S_SDLOSXCAGuard * cag);
  30.106 -    void (*Notify) (struct S_SDLOSXCAGuard * cag);
  30.107 -
  30.108 -/*  Implementation */
  30.109 -/*protected:*/
  30.110 -    pthread_mutex_t mMutex;
  30.111 -    pthread_cond_t mCondVar;
  30.112 -    pthread_t mOwner;
  30.113 -} SDLOSXCAGuard;
  30.114 -
  30.115 -SDLOSXCAGuard *new_SDLOSXCAGuard(void);
  30.116 -void delete_SDLOSXCAGuard(SDLOSXCAGuard * cag);
  30.117 -
  30.118 -#endif
  30.119 -/* vi: set ts=4 sw=4 expandtab: */
    31.1 --- a/src/cdrom/macosx/SDL_syscdrom.c	Sat Sep 05 09:03:35 2009 +0000
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,523 +0,0 @@
    31.4 -/*
    31.5 -    SDL - Simple DirectMedia Layer
    31.6 -    Copyright (C) 1997-2009 Sam Lantinga
    31.7 -
    31.8 -    This library is free software; you can redistribute it and/or
    31.9 -    modify it under the terms of the GNU Lesser General Public
   31.10 -    License as published by the Free Software Foundation; either
   31.11 -    version 2.1 of the License, or (at your option) any later version.
   31.12 -
   31.13 -    This library is distributed in the hope that it will be useful,
   31.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   31.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   31.16 -    Lesser General Public License for more details.
   31.17 -
   31.18 -    You should have received a copy of the GNU Lesser General Public
   31.19 -    License along with this library; if not, write to the Free Software
   31.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   31.21 -
   31.22 -    Sam Lantinga
   31.23 -    slouken@libsdl.org
   31.24 -*/
   31.25 -#include "SDL_config.h"
   31.26 -
   31.27 -#ifdef SDL_CDROM_MACOSX
   31.28 -
   31.29 -#include "SDL_syscdrom_c.h"
   31.30 -
   31.31 -#pragma mark -- Globals --
   31.32 -
   31.33 -static FSRef **tracks;
   31.34 -static FSVolumeRefNum *volumes;
   31.35 -static CDstatus status;
   31.36 -static int nextTrackFrame;
   31.37 -static int nextTrackFramesRemaining;
   31.38 -static int fakeCD;
   31.39 -static int currentTrack;
   31.40 -static int didReadTOC;
   31.41 -static int cacheTOCNumTracks;
   31.42 -static int currentDrive;        /* Only allow 1 drive in use at a time */
   31.43 -
   31.44 -#pragma mark -- Prototypes --
   31.45 -
   31.46 -static const char *SDL_SYS_CDName(int drive);
   31.47 -static int SDL_SYS_CDOpen(int drive);
   31.48 -static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
   31.49 -static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
   31.50 -static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
   31.51 -static int SDL_SYS_CDPause(SDL_CD * cdrom);
   31.52 -static int SDL_SYS_CDResume(SDL_CD * cdrom);
   31.53 -static int SDL_SYS_CDStop(SDL_CD * cdrom);
   31.54 -static int SDL_SYS_CDEject(SDL_CD * cdrom);
   31.55 -static void SDL_SYS_CDClose(SDL_CD * cdrom);
   31.56 -
   31.57 -#pragma mark -- Helper Functions --
   31.58 -
   31.59 -/* Read a list of tracks from the volume */
   31.60 -static int
   31.61 -LoadTracks(SDL_CD * cdrom)
   31.62 -{
   31.63 -    /* Check if tracks are already loaded */
   31.64 -    if (tracks[cdrom->id] != NULL)
   31.65 -        return 0;
   31.66 -
   31.67 -    /* Allocate memory for tracks */
   31.68 -    tracks[cdrom->id] =
   31.69 -        (FSRef *) SDL_calloc(1, sizeof(**tracks) * cdrom->numtracks);
   31.70 -    if (tracks[cdrom->id] == NULL) {
   31.71 -        SDL_OutOfMemory();
   31.72 -        return -1;
   31.73 -    }
   31.74 -
   31.75 -    /* Load tracks */
   31.76 -    if (ListTrackFiles
   31.77 -        (volumes[cdrom->id], tracks[cdrom->id], cdrom->numtracks) < 0)
   31.78 -        return -1;
   31.79 -
   31.80 -    return 0;
   31.81 -}
   31.82 -
   31.83 -/* Find a file for a given start frame and length */
   31.84 -static FSRef *
   31.85 -GetFileForOffset(SDL_CD * cdrom, int start, int length, int *outStartFrame,
   31.86 -                 int *outStopFrame)
   31.87 -{
   31.88 -    int i;
   31.89 -
   31.90 -    for (i = 0; i < cdrom->numtracks; i++) {
   31.91 -
   31.92 -        if (cdrom->track[i].offset <= start &&
   31.93 -            start < (cdrom->track[i].offset + cdrom->track[i].length))
   31.94 -            break;
   31.95 -    }
   31.96 -
   31.97 -    if (i == cdrom->numtracks)
   31.98 -        return NULL;
   31.99 -
  31.100 -    currentTrack = i;
  31.101 -
  31.102 -    *outStartFrame = start - cdrom->track[i].offset;
  31.103 -
  31.104 -    if ((*outStartFrame + length) < cdrom->track[i].length) {
  31.105 -        *outStopFrame = *outStartFrame + length;
  31.106 -        length = 0;
  31.107 -        nextTrackFrame = -1;
  31.108 -        nextTrackFramesRemaining = -1;
  31.109 -    } else {
  31.110 -        *outStopFrame = -1;
  31.111 -        length -= cdrom->track[i].length - *outStartFrame;
  31.112 -        nextTrackFrame = cdrom->track[i + 1].offset;
  31.113 -        nextTrackFramesRemaining = length;
  31.114 -    }
  31.115 -
  31.116 -    return &tracks[cdrom->id][i];
  31.117 -}
  31.118 -
  31.119 -/* Setup another file for playback, or stop playback (called from another thread) */
  31.120 -static void
  31.121 -CompletionProc(SDL_CD * cdrom)
  31.122 -{
  31.123 -
  31.124 -    Lock();
  31.125 -
  31.126 -    if (nextTrackFrame > 0 && nextTrackFramesRemaining > 0) {
  31.127 -
  31.128 -        /* Load the next file to play */
  31.129 -        int startFrame, stopFrame;
  31.130 -        FSRef *file;
  31.131 -
  31.132 -        PauseFile();
  31.133 -        ReleaseFile();
  31.134 -
  31.135 -        file = GetFileForOffset(cdrom, nextTrackFrame,
  31.136 -                                nextTrackFramesRemaining, &startFrame,
  31.137 -                                &stopFrame);
  31.138 -
  31.139 -        if (file == NULL) {
  31.140 -            status = CD_STOPPED;
  31.141 -            Unlock();
  31.142 -            return;
  31.143 -        }
  31.144 -
  31.145 -        LoadFile(file, startFrame, stopFrame);
  31.146 -
  31.147 -        SetCompletionProc(CompletionProc, cdrom);
  31.148 -
  31.149 -        PlayFile();
  31.150 -    } else {
  31.151 -
  31.152 -        /* Release the current file */
  31.153 -        PauseFile();
  31.154 -        ReleaseFile();
  31.155 -        status = CD_STOPPED;
  31.156 -    }
  31.157 -
  31.158 -    Unlock();
  31.159 -}
  31.160 -
  31.161 -
  31.162 -#pragma mark -- Driver Functions --
  31.163 -
  31.164 -/* Initialize */
  31.165 -int
  31.166 -SDL_SYS_CDInit(void)
  31.167 -{
  31.168 -    /* Initialize globals */
  31.169 -    volumes = NULL;
  31.170 -    tracks = NULL;
  31.171 -    status = CD_STOPPED;
  31.172 -    nextTrackFrame = -1;
  31.173 -    nextTrackFramesRemaining = -1;
  31.174 -    fakeCD = SDL_FALSE;
  31.175 -    currentTrack = -1;
  31.176 -    didReadTOC = SDL_FALSE;
  31.177 -    cacheTOCNumTracks = -1;
  31.178 -    currentDrive = -1;
  31.179 -
  31.180 -    /* Fill in function pointers */
  31.181 -    SDL_CDcaps.Name = SDL_SYS_CDName;
  31.182 -    SDL_CDcaps.Open = SDL_SYS_CDOpen;
  31.183 -    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
  31.184 -    SDL_CDcaps.Status = SDL_SYS_CDStatus;
  31.185 -    SDL_CDcaps.Play = SDL_SYS_CDPlay;
  31.186 -    SDL_CDcaps.Pause = SDL_SYS_CDPause;
  31.187 -    SDL_CDcaps.Resume = SDL_SYS_CDResume;
  31.188 -    SDL_CDcaps.Stop = SDL_SYS_CDStop;
  31.189 -    SDL_CDcaps.Eject = SDL_SYS_CDEject;
  31.190 -    SDL_CDcaps.Close = SDL_SYS_CDClose;
  31.191 -
  31.192 -    /* 
  31.193 -       Read the list of "drives"
  31.194 -
  31.195 -       This is currently a hack that infers drives from
  31.196 -       mounted audio CD volumes, rather than
  31.197 -       actual CD-ROM devices - which means it may not
  31.198 -       act as expected sometimes.
  31.199 -     */
  31.200 -
  31.201 -    /* Find out how many cd volumes are mounted */
  31.202 -    SDL_numcds = DetectAudioCDVolumes(NULL, 0);
  31.203 -
  31.204 -    /*
  31.205 -       If there are no volumes, fake a cd device
  31.206 -       so tray empty can be reported.
  31.207 -     */
  31.208 -    if (SDL_numcds == 0) {
  31.209 -
  31.210 -        fakeCD = SDL_TRUE;
  31.211 -        SDL_numcds = 1;
  31.212 -        status = CD_TRAYEMPTY;
  31.213 -
  31.214 -        return 0;
  31.215 -    }
  31.216 -
  31.217 -    /* Allocate space for volumes */
  31.218 -    volumes = (FSVolumeRefNum *) SDL_calloc(1, sizeof(*volumes) * SDL_numcds);
  31.219 -    if (volumes == NULL) {
  31.220 -        SDL_OutOfMemory();
  31.221 -        return -1;
  31.222 -    }
  31.223 -
  31.224 -    /* Allocate space for tracks */
  31.225 -    tracks = (FSRef **) SDL_calloc(1, sizeof(*tracks) * (SDL_numcds + 1));
  31.226 -    if (tracks == NULL) {
  31.227 -        SDL_OutOfMemory();
  31.228 -        return -1;
  31.229 -    }
  31.230 -
  31.231 -    /* Mark the end of the tracks array */
  31.232 -    tracks[SDL_numcds] = (FSRef *) - 1;
  31.233 -
  31.234 -    /* 
  31.235 -       Redetect, now save all volumes for later
  31.236 -       Update SDL_numcds just in case it changed
  31.237 -     */
  31.238 -    {
  31.239 -        int numVolumes = SDL_numcds;
  31.240 -
  31.241 -        SDL_numcds = DetectAudioCDVolumes(volumes, numVolumes);
  31.242 -
  31.243 -        /* If more cds suddenly show up, ignore them */
  31.244 -        if (SDL_numcds > numVolumes) {
  31.245 -            SDL_SetError("Some CD's were added but they will be ignored");
  31.246 -            SDL_numcds = numVolumes;
  31.247 -        }
  31.248 -    }
  31.249 -
  31.250 -    return 0;
  31.251 -}
  31.252 -
  31.253 -/* Shutdown and cleanup */
  31.254 -void
  31.255 -SDL_SYS_CDQuit(void)
  31.256 -{
  31.257 -    ReleaseFile();
  31.258 -
  31.259 -    if (volumes != NULL)
  31.260 -        free(volumes);
  31.261 -
  31.262 -    if (tracks != NULL) {
  31.263 -
  31.264 -        FSRef **ptr;
  31.265 -        for (ptr = tracks; *ptr != (FSRef *) - 1; ptr++)
  31.266 -            if (*ptr != NULL)
  31.267 -                free(*ptr);
  31.268 -
  31.269 -        free(tracks);
  31.270 -    }
  31.271 -}
  31.272 -
  31.273 -/* Get the Unix disk name of the volume */
  31.274 -static const char *
  31.275 -SDL_SYS_CDName(int drive)
  31.276 -{
  31.277 -    OSStatus err = noErr;
  31.278 -    HParamBlockRec pb;
  31.279 -    GetVolParmsInfoBuffer volParmsInfo;
  31.280 -
  31.281 -    if (fakeCD)
  31.282 -        return "Fake CD-ROM Device";
  31.283 -
  31.284 -    pb.ioParam.ioNamePtr = NULL;
  31.285 -    pb.ioParam.ioVRefNum = volumes[drive];
  31.286 -    pb.ioParam.ioBuffer = (Ptr) & volParmsInfo;
  31.287 -    pb.ioParam.ioReqCount = (SInt32) sizeof(volParmsInfo);
  31.288 -    err = PBHGetVolParmsSync(&pb);
  31.289 -
  31.290 -    if (err != noErr) {
  31.291 -        SDL_SetError("PBHGetVolParmsSync returned %d", err);
  31.292 -        return NULL;
  31.293 -    }
  31.294 -
  31.295 -    return volParmsInfo.vMDeviceID;
  31.296 -}
  31.297 -
  31.298 -/* Open the "device" */
  31.299 -static int
  31.300 -SDL_SYS_CDOpen(int drive)
  31.301 -{
  31.302 -    /* Only allow 1 device to be open */
  31.303 -    if (currentDrive >= 0) {
  31.304 -        SDL_SetError("Only one cdrom is supported");
  31.305 -        return -1;
  31.306 -    } else
  31.307 -        currentDrive = drive;
  31.308 -
  31.309 -    return drive;
  31.310 -}
  31.311 -
  31.312 -/* Get the table of contents */
  31.313 -static int
  31.314 -SDL_SYS_CDGetTOC(SDL_CD * cdrom)
  31.315 -{
  31.316 -    if (fakeCD) {
  31.317 -        SDL_SetError(kErrorFakeDevice);
  31.318 -        return -1;
  31.319 -    }
  31.320 -
  31.321 -    if (didReadTOC) {
  31.322 -        cdrom->numtracks = cacheTOCNumTracks;
  31.323 -        return 0;
  31.324 -    }
  31.325 -
  31.326 -
  31.327 -    ReadTOCData(volumes[cdrom->id], cdrom);
  31.328 -    didReadTOC = SDL_TRUE;
  31.329 -    cacheTOCNumTracks = cdrom->numtracks;
  31.330 -
  31.331 -    return 0;
  31.332 -}
  31.333 -
  31.334 -/* Get CD-ROM status */
  31.335 -static CDstatus
  31.336 -SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
  31.337 -{
  31.338 -    if (position) {
  31.339 -        int trackFrame;
  31.340 -
  31.341 -        Lock();
  31.342 -        trackFrame = GetCurrentFrame();
  31.343 -        Unlock();
  31.344 -
  31.345 -        *position = cdrom->track[currentTrack].offset + trackFrame;
  31.346 -    }
  31.347 -
  31.348 -    return status;
  31.349 -}
  31.350 -
  31.351 -/* Start playback */
  31.352 -static int
  31.353 -SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
  31.354 -{
  31.355 -    int startFrame, stopFrame;
  31.356 -    FSRef *ref;
  31.357 -
  31.358 -    if (fakeCD) {
  31.359 -        SDL_SetError(kErrorFakeDevice);
  31.360 -        return -1;
  31.361 -    }
  31.362 -
  31.363 -    Lock();
  31.364 -
  31.365 -    if (LoadTracks(cdrom) < 0)
  31.366 -        return -2;
  31.367 -
  31.368 -    if (PauseFile() < 0)
  31.369 -        return -3;
  31.370 -
  31.371 -    if (ReleaseFile() < 0)
  31.372 -        return -4;
  31.373 -
  31.374 -    ref = GetFileForOffset(cdrom, start, length, &startFrame, &stopFrame);
  31.375 -    if (ref == NULL) {
  31.376 -        SDL_SetError("SDL_SYS_CDPlay: No file for start=%d, length=%d",
  31.377 -                     start, length);
  31.378 -        return -5;
  31.379 -    }
  31.380 -
  31.381 -    if (LoadFile(ref, startFrame, stopFrame) < 0)
  31.382 -        return -6;
  31.383 -
  31.384 -    SetCompletionProc(CompletionProc, cdrom);
  31.385 -
  31.386 -    if (PlayFile() < 0)
  31.387 -        return -7;
  31.388 -
  31.389 -    status = CD_PLAYING;
  31.390 -
  31.391 -    Unlock();
  31.392 -
  31.393 -    return 0;
  31.394 -}
  31.395 -
  31.396 -/* Pause playback */
  31.397 -static int
  31.398 -SDL_SYS_CDPause(SDL_CD * cdrom)
  31.399 -{
  31.400 -    if (fakeCD) {
  31.401 -        SDL_SetError(kErrorFakeDevice);
  31.402 -        return -1;
  31.403 -    }
  31.404 -
  31.405 -    Lock();
  31.406 -
  31.407 -    if (PauseFile() < 0) {
  31.408 -        Unlock();
  31.409 -        return -2;
  31.410 -    }
  31.411 -
  31.412 -    status = CD_PAUSED;
  31.413 -
  31.414 -    Unlock();
  31.415 -
  31.416 -    return 0;
  31.417 -}
  31.418 -
  31.419 -/* Resume playback */
  31.420 -static int
  31.421 -SDL_SYS_CDResume(SDL_CD * cdrom)
  31.422 -{
  31.423 -    if (fakeCD) {
  31.424 -        SDL_SetError(kErrorFakeDevice);
  31.425 -        return -1;
  31.426 -    }
  31.427 -
  31.428 -    Lock();
  31.429 -
  31.430 -    if (PlayFile() < 0) {
  31.431 -        Unlock();
  31.432 -        return -2;
  31.433 -    }
  31.434 -
  31.435 -    status = CD_PLAYING;
  31.436 -
  31.437 -    Unlock();
  31.438 -
  31.439 -    return 0;
  31.440 -}
  31.441 -
  31.442 -/* Stop playback */
  31.443 -static int
  31.444 -SDL_SYS_CDStop(SDL_CD * cdrom)
  31.445 -{
  31.446 -    if (fakeCD) {
  31.447 -        SDL_SetError(kErrorFakeDevice);
  31.448 -        return -1;
  31.449 -    }
  31.450 -
  31.451 -    Lock();
  31.452 -
  31.453 -    if (PauseFile() < 0) {
  31.454 -        Unlock();
  31.455 -        return -2;
  31.456 -    }
  31.457 -
  31.458 -    if (ReleaseFile() < 0) {
  31.459 -        Unlock();
  31.460 -        return -3;
  31.461 -    }
  31.462 -
  31.463 -    status = CD_STOPPED;
  31.464 -
  31.465 -    Unlock();
  31.466 -
  31.467 -    return 0;
  31.468 -}
  31.469 -
  31.470 -/* Eject the CD-ROM (Unmount the volume) */
  31.471 -static int
  31.472 -SDL_SYS_CDEject(SDL_CD * cdrom)
  31.473 -{
  31.474 -    OSStatus err;
  31.475 -    pid_t dissenter;
  31.476 -
  31.477 -    if (fakeCD) {
  31.478 -        SDL_SetError(kErrorFakeDevice);
  31.479 -        return -1;
  31.480 -    }
  31.481 -
  31.482 -    Lock();
  31.483 -
  31.484 -    if (PauseFile() < 0) {
  31.485 -        Unlock();
  31.486 -        return -2;
  31.487 -    }
  31.488 -
  31.489 -    if (ReleaseFile() < 0) {
  31.490 -        Unlock();
  31.491 -        return -3;
  31.492 -    }
  31.493 -
  31.494 -    status = CD_STOPPED;
  31.495 -
  31.496 -    /* Eject the volume */
  31.497 -    err = FSEjectVolumeSync(volumes[cdrom->id], kNilOptions, &dissenter);
  31.498 -
  31.499 -    if (err != noErr) {
  31.500 -        Unlock();
  31.501 -        SDL_SetError("PBUnmountVol returned %d", err);
  31.502 -        return -4;
  31.503 -    }
  31.504 -
  31.505 -    status = CD_TRAYEMPTY;
  31.506 -
  31.507 -    /* Invalidate volume and track info */
  31.508 -    volumes[cdrom->id] = 0;
  31.509 -    free(tracks[cdrom->id]);
  31.510 -    tracks[cdrom->id] = NULL;
  31.511 -
  31.512 -    Unlock();
  31.513 -
  31.514 -    return 0;
  31.515 -}
  31.516 -
  31.517 -/* Close the CD-ROM */
  31.518 -static void
  31.519 -SDL_SYS_CDClose(SDL_CD * cdrom)
  31.520 -{
  31.521 -    currentDrive = -1;
  31.522 -    return;
  31.523 -}
  31.524 -
  31.525 -#endif /* SDL_CDROM_MACOSX */
  31.526 -/* vi: set ts=4 sw=4 expandtab: */
    32.1 --- a/src/cdrom/macosx/SDL_syscdrom_c.h	Sat Sep 05 09:03:35 2009 +0000
    32.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.3 @@ -1,136 +0,0 @@
    32.4 -/*
    32.5 -    SDL - Simple DirectMedia Layer
    32.6 -    Copyright (C) 1997-2009 Sam Lantinga
    32.7 -
    32.8 -    This library is free software; you can redistribute it and/or
    32.9 -    modify it under the terms of the GNU Library General Public
   32.10 -    License as published by the Free Software Foundation; either
   32.11 -    version 2 of the License, or (at your option) any later version.
   32.12 -
   32.13 -    This library is distributed in the hope that it will be useful,
   32.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   32.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   32.16 -    Library General Public License for more details.
   32.17 -
   32.18 -    You should have received a copy of the GNU Library General Public
   32.19 -    License along with this library; if not, write to the Free
   32.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   32.21 -
   32.22 -    Sam Lantinga
   32.23 -    slouken@libsdl.org
   32.24 -*/
   32.25 -#include "SDL_config.h"
   32.26 -
   32.27 -/* This is the Mac OS X / CoreAudio specific header for the SDL CD-ROM API
   32.28 -   Contributed by Darrell Walisser and Max Horn
   32.29 - */
   32.30 -
   32.31 -/***********************************************************************************
   32.32 - Implementation Notes
   32.33 - *********************
   32.34 -
   32.35 -    This code has several limitations currently (all of which are proabaly fixable):
   32.36 -    
   32.37 -    1. A CD-ROM device is inferred from a mounted cdfs volume, so device 0 is
   32.38 -       not necessarily the first CD-ROM device on the system. (Somewhat easy to fix
   32.39 -       by useing the device name from the volume id's to reorder the volumes)
   32.40 -       
   32.41 -    2. You can only open and control 1 CD-ROM device at a time. (Challenging to fix,
   32.42 -       due to extensive code restructuring)
   32.43 -    
   32.44 -    3. The status reported by SDL_CDStatus only changes to from CD_PLAYING to CD_STOPPED in
   32.45 -       1-second intervals (because the audio is buffered in 1-second chunks) If
   32.46 -       the audio data is less than 1 second, the remainder is filled with silence.
   32.47 -       
   32.48 -       If you need to play sequences back-to-back that are less that 1 second long,
   32.49 -       use the frame position to determine when to play the next sequence, instead
   32.50 -       of SDL_CDStatus.
   32.51 -       
   32.52 -       This may be possible to fix with a clever usage of the AudioUnit API.
   32.53 -       
   32.54 -    4. When new volumes are inserted, our volume information is not updated. The only way
   32.55 -       to refresh this information is to reinit the CD-ROM subsystem of SDL. To fix this,
   32.56 -       one would probably have to fix point 1 above first, then figure out how to register
   32.57 -       for a notification when new media is mounted in order to perform an automatic
   32.58 -       rescan for cdfs volumes.
   32.59 -    
   32.60 -    
   32.61 -    
   32.62 -    So, here comes a description of how this all works.
   32.63 -    
   32.64 -        < Initializing >
   32.65 -        
   32.66 -        To get things rolling, we have to locate mounted volumes that contain
   32.67 -        audio (since nearly all Macs don't have analog audio-in on the sound card).
   32.68 -        That's easy, since these volumes have a flag that indicates this special
   32.69 -        filesystem. See DetectAudioCDVolumes() in CDPlayer.cpp for this code.
   32.70 -        
   32.71 -        Next, we parse the invisible .TOC.plist in the root of the volume, which gets us
   32.72 -        the track information (number, offset, length, leadout, etc). See ReadTOCData() in
   32.73 -        CDPlayer.cpp for the skinny on this.
   32.74 -        
   32.75 -        
   32.76 -        < The Playback Loop >
   32.77 -        
   32.78 -        Now come the tricky parts. Let's start with basic audio playback. When a frame
   32.79 -        range to play is requested, we must first find the .aiff files on the volume, 
   32.80 -        hopefully in the right order. Since these files all begin with a number "1 Audio Track", 
   32.81 -        etc, this is used to determine the correct track order.
   32.82 -        
   32.83 -        Once all files are determined, we have to find what file corresponds to the start
   32.84 -        and length parameter to SDL_SYS_CDPlay(). Again, this is quite simple by walking the
   32.85 -        cdrom's track list. At this point, we also save the offset to the next track and frames
   32.86 -        remaining, if we're going to have to play another file after the first one. See
   32.87 -        GetFileForOffset() for this code.
   32.88 -        
   32.89 -        At this point we have all info needed to start playback, so we hand off to the LoadFile()
   32.90 -        function, which proceeds to do its magic and plays back the file.
   32.91 -        
   32.92 -        When the file is finished playing, CompletionProc() is invoked, at which time we can
   32.93 -        play the next file if the previously saved next track and frames remaining
   32.94 -        indicates that we should. 
   32.95 -        
   32.96 -        
   32.97 -        < Magic >
   32.98 -        
   32.99 -        OK, so it's not really magic, but since I don't fully understand all the hidden details it
  32.100 -        seems like it to me ;-) The API's involved are the AudioUnit and AudioFile API's. These
  32.101 -        appear to be an extension of CoreAudio for creating modular playback and f/x entities.
  32.102 -        The important thing is that CPU usage is very low and reliability is very high. You'd
  32.103 -        be hard-pressed to find a way to stutter the playback with other CPU-intensive tasks.
  32.104 -    
  32.105 -        One part of this magic is that it uses multiple threads, which carries the usual potential
  32.106 -        for disaster if not handled carefully. Playback currently requires 4 additional threads:
  32.107 -            1. The coreaudio runloop thread
  32.108 -            2. The coreaudio device i/o thread
  32.109 -            3. The file streaming thread
  32.110 -            4. The notification/callback thread
  32.111 -        
  32.112 -        The first 2 threads are necessary evil - CoreAudio creates this no matter what the situation
  32.113 -        is (even the SDL sound implementation creates theses suckers). The last two are are created
  32.114 -        by us.
  32.115 -        
  32.116 -        The file is streamed from disk using a threaded double-buffer approach. 
  32.117 -        This way, the high latency operation of reading from disk can be performed without interrupting
  32.118 -        the real-time device thread (which amounts to avoiding dropouts). The device thread grabs the
  32.119 -        buffer that isn't being read and sends it to the CoreAudio mixer where it eventually gets 
  32.120 -        to the sound card.
  32.121 -        
  32.122 -        The device thread posts a notification when the file streaming thread is out of data. This
  32.123 -        notification must be handled in a separate thread to avoid potential deadlock in the
  32.124 -        device thread. That's where the notification thread comes in. This thread is signaled
  32.125 -        whenever a notification needs to be processed, so another file can be played back if need be.
  32.126 -        
  32.127 -        The API in CDPlayer.cpp contains synchronization because otherwise both the notification thread
  32.128 -        and main thread (or another other thread using the SDL CD api) can potentially call it at the same time.
  32.129 -    
  32.130 -************************************************************************************/
  32.131 -
  32.132 -
  32.133 -#include "SDL_cdrom.h"
  32.134 -#include "../SDL_syscdrom.h"
  32.135 -
  32.136 -#include "CDPlayer.h"
  32.137 -
  32.138 -#define kErrorFakeDevice "Error: Cannot proceed since we're faking a CD-ROM device. Reinit the CD-ROM subsystem to scan for new volumes."
  32.139 -/* vi: set ts=4 sw=4 expandtab: */
    33.1 --- a/src/cdrom/mint/SDL_syscdrom.c	Sat Sep 05 09:03:35 2009 +0000
    33.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.3 @@ -1,339 +0,0 @@
    33.4 -/*
    33.5 -    SDL - Simple DirectMedia Layer
    33.6 -    Copyright (C) 1997-2009 Sam Lantinga
    33.7 -
    33.8 -    This library is free software; you can redistribute it and/or
    33.9 -    modify it under the terms of the GNU Library General Public
   33.10 -    License as published by the Free Software Foundation; either
   33.11 -    version 2 of the License, or (at your option) any later version.
   33.12 -
   33.13 -    This library is distributed in the hope that it will be useful,
   33.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   33.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   33.16 -    Library General Public License for more details.
   33.17 -
   33.18 -    You should have received a copy of the GNU Library General Public
   33.19 -    License along with this library; if not, write to the Free
   33.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   33.21 -
   33.22 -    Sam Lantinga
   33.23 -    slouken@libsdl.org
   33.24 -*/
   33.25 -#include "SDL_config.h"
   33.26 -
   33.27 -#ifdef SDL_CDROM_MINT
   33.28 -
   33.29 -/*
   33.30 -	Atari MetaDOS CD-ROM functions
   33.31 -
   33.32 -	Patrice Mandin
   33.33 -*/
   33.34 -
   33.35 -#include <errno.h>
   33.36 -
   33.37 -#include <cdromio.h>
   33.38 -#include <metados.h>
   33.39 -
   33.40 -#include "SDL_cdrom.h"
   33.41 -#include "../SDL_syscdrom.h"
   33.42 -
   33.43 -/* Some ioctl() errno values which occur when the tray is empty */
   33.44 -#ifndef ENOMEDIUM
   33.45 -#define ENOMEDIUM ENOENT
   33.46 -#endif
   33.47 -#define ERRNO_TRAYEMPTY(errno)	\
   33.48 -	((errno == EIO)    || (errno == ENOENT) || \
   33.49 -	 (errno == EINVAL) || (errno == ENOMEDIUM))
   33.50 -
   33.51 -/* The maximum number of CD-ROM drives we'll detect */
   33.52 -#define MAX_DRIVES	32
   33.53 -
   33.54 -typedef struct
   33.55 -{
   33.56 -    unsigned char device[3];    /* Physical device letter + ':' + '\0' */
   33.57 -    metaopen_t metaopen;        /* Infos on opened drive */
   33.58 -} metados_drive_t;
   33.59 -
   33.60 -static metados_drive_t metados_drives[MAX_DRIVES];
   33.61 -
   33.62 -/* The system-dependent CD control functions */
   33.63 -static const char *SDL_SYS_CDName(int drive);
   33.64 -static int SDL_SYS_CDOpen(int drive);
   33.65 -static void SDL_SYS_CDClose(SDL_CD * cdrom);
   33.66 -static int SDL_SYS_CDioctl(int id, int command, void *arg);
   33.67 -static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
   33.68 -static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
   33.69 -static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
   33.70 -static int SDL_SYS_CDPause(SDL_CD * cdrom);
   33.71 -static int SDL_SYS_CDResume(SDL_CD * cdrom);
   33.72 -static int SDL_SYS_CDStop(SDL_CD * cdrom);
   33.73 -static int SDL_SYS_CDEject(SDL_CD * cdrom);
   33.74 -
   33.75 -int
   33.76 -SDL_SYS_CDInit(void)
   33.77 -{
   33.78 -    metainit_t metainit = { 0, 0, 0, 0 };
   33.79 -    metaopen_t metaopen;
   33.80 -    int i, handle;
   33.81 -    struct cdrom_subchnl info;
   33.82 -
   33.83 -    Metainit(&metainit);
   33.84 -    if (metainit.version == NULL) {
   33.85 -#ifdef DEBUG_CDROM
   33.86 -        fprintf(stderr, "MetaDOS not installed\n");
   33.87 -#endif
   33.88 -        return -1;
   33.89 -    }
   33.90 -
   33.91 -    if (metainit.drives_map == 0) {
   33.92 -#ifdef DEBUG_CDROM
   33.93 -        fprintf(stderr, "No MetaDOS devices present\n");
   33.94 -#endif
   33.95 -        return -1;
   33.96 -    }
   33.97 -
   33.98 -    SDL_numcds = 0;
   33.99 -
  33.100 -    for (i = 'A'; i <= 'Z'; i++) {
  33.101 -        metados_drives[SDL_numcds].device[0] = 0;
  33.102 -        metados_drives[SDL_numcds].device[1] = ':';
  33.103 -        metados_drives[SDL_numcds].device[2] = 0;
  33.104 -
  33.105 -        if (metainit.drives_map & (1 << (i - 'A'))) {
  33.106 -            handle = Metaopen(i, &metaopen);
  33.107 -            if (handle == 0) {
  33.108 -
  33.109 -                info.cdsc_format = CDROM_MSF;
  33.110 -                if ((Metaioctl
  33.111 -                     (i, METADOS_IOCTL_MAGIC, CDROMSUBCHNL, &info) == 0)
  33.112 -                    || ERRNO_TRAYEMPTY(errno)) {
  33.113 -                    metados_drives[SDL_numcds].device[0] = i;
  33.114 -                    ++SDL_numcds;
  33.115 -                }
  33.116 -
  33.117 -                Metaclose(i);
  33.118 -            }
  33.119 -        }
  33.120 -    }
  33.121 -
  33.122 -    /* Fill in our driver capabilities */
  33.123 -    SDL_CDcaps.Name = SDL_SYS_CDName;
  33.124 -    SDL_CDcaps.Open = SDL_SYS_CDOpen;
  33.125 -    SDL_CDcaps.Close = SDL_SYS_CDClose;
  33.126 -
  33.127 -    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
  33.128 -    SDL_CDcaps.Status = SDL_SYS_CDStatus;
  33.129 -    SDL_CDcaps.Play = SDL_SYS_CDPlay;
  33.130 -    SDL_CDcaps.Pause = SDL_SYS_CDPause;
  33.131 -    SDL_CDcaps.Resume = SDL_SYS_CDResume;
  33.132 -    SDL_CDcaps.Stop = SDL_SYS_CDStop;
  33.133 -    SDL_CDcaps.Eject = SDL_SYS_CDEject;
  33.134 -
  33.135 -    return 0;
  33.136 -}
  33.137 -
  33.138 -void
  33.139 -SDL_SYS_CDQuit(void)
  33.140 -{
  33.141 -    SDL_numcds = 0;
  33.142 -}
  33.143 -
  33.144 -static const char *
  33.145 -SDL_SYS_CDName(int drive)
  33.146 -{
  33.147 -    return (metados_drives[drive].device);
  33.148 -}
  33.149 -
  33.150 -static int
  33.151 -SDL_SYS_CDOpen(int drive)
  33.152 -{
  33.153 -    int handle;
  33.154 -
  33.155 -    handle =
  33.156 -        Metaopen(metados_drives[drive].device[0],
  33.157 -                 &(metados_drives[drive].metaopen));
  33.158 -    if (handle == 0) {
  33.159 -        return drive;
  33.160 -    }
  33.161 -
  33.162 -    return -1;
  33.163 -}
  33.164 -
  33.165 -static void
  33.166 -SDL_SYS_CDClose(SDL_CD * cdrom)
  33.167 -{
  33.168 -    Metaclose(metados_drives[cdrom->id].device[0]);
  33.169 -}
  33.170 -
  33.171 -static int
  33.172 -SDL_SYS_CDioctl(int id, int command, void *arg)
  33.173 -{
  33.174 -    int retval;
  33.175 -
  33.176 -    retval =
  33.177 -        Metaioctl(metados_drives[id].device[0], METADOS_IOCTL_MAGIC, command,
  33.178 -                  arg);
  33.179 -    if (retval < 0) {
  33.180 -        SDL_SetError("ioctl() error: %s", strerror(errno));
  33.181 -    }
  33.182 -    return (retval);
  33.183 -}
  33.184 -
  33.185 -static int
  33.186 -SDL_SYS_CDGetTOC(SDL_CD * cdrom)
  33.187 -{
  33.188 -    int i, okay;
  33.189 -    struct cdrom_tochdr toc;
  33.190 -    struct cdrom_tocentry entry;
  33.191 -
  33.192 -    /* Use standard ioctl() */
  33.193 -    if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc) < 0) {
  33.194 -        return -1;
  33.195 -    }
  33.196 -
  33.197 -    cdrom->numtracks = toc.cdth_trk1 - toc.cdth_trk0 + 1;
  33.198 -    if (cdrom->numtracks > SDL_MAX_TRACKS) {
  33.199 -        cdrom->numtracks = SDL_MAX_TRACKS;
  33.200 -    }
  33.201 -
  33.202 -    /* Read all the track TOC entries */
  33.203 -    okay = 1;
  33.204 -    for (i = 0; i <= cdrom->numtracks; ++i) {
  33.205 -        if (i == cdrom->numtracks) {
  33.206 -            cdrom->track[i].id = CDROM_LEADOUT;
  33.207 -        } else {
  33.208 -            cdrom->track[i].id = toc.cdth_trk0 + i;
  33.209 -        }
  33.210 -        entry.cdte_track = cdrom->track[i].id;
  33.211 -        entry.cdte_format = CDROM_MSF;
  33.212 -        if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCENTRY, &entry) < 0) {
  33.213 -            okay = 0;
  33.214 -            break;
  33.215 -        } else {
  33.216 -            if (entry.cdte_ctrl & CDROM_DATA_TRACK) {
  33.217 -                cdrom->track[i].type = SDL_DATA_TRACK;
  33.218 -            } else {
  33.219 -                cdrom->track[i].type = SDL_AUDIO_TRACK;
  33.220 -            }
  33.221 -            cdrom->track[i].offset =
  33.222 -                MSF_TO_FRAMES(entry.cdte_addr.msf.minute,
  33.223 -                              entry.cdte_addr.msf.second,
  33.224 -                              entry.cdte_addr.msf.frame);
  33.225 -            cdrom->track[i].length = 0;
  33.226 -            if (i > 0) {
  33.227 -                cdrom->track[i - 1].length =
  33.228 -                    cdrom->track[i].offset - cdrom->track[i - 1].offset;
  33.229 -            }
  33.230 -        }
  33.231 -    }
  33.232 -
  33.233 -    return (okay ? 0 : -1);
  33.234 -}
  33.235 -
  33.236 -/* Get CD-ROM status */
  33.237 -static CDstatus
  33.238 -SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
  33.239 -{
  33.240 -    CDstatus status;
  33.241 -    struct cdrom_tochdr toc;
  33.242 -    struct cdrom_subchnl info;
  33.243 -
  33.244 -    info.cdsc_format = CDROM_MSF;
  33.245 -    if (SDL_SYS_CDioctl(cdrom->id, CDROMSUBCHNL, &info) < 0) {
  33.246 -        if (ERRNO_TRAYEMPTY(errno)) {
  33.247 -            status = CD_TRAYEMPTY;
  33.248 -        } else {
  33.249 -            status = CD_ERROR;
  33.250 -        }
  33.251 -    } else {
  33.252 -        switch (info.cdsc_audiostatus) {
  33.253 -        case CDROM_AUDIO_INVALID:
  33.254 -        case CDROM_AUDIO_NO_STATUS:
  33.255 -            /* Try to determine if there's a CD available */
  33.256 -            if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc) == 0) {
  33.257 -                status = CD_STOPPED;
  33.258 -            } else {
  33.259 -                status = CD_TRAYEMPTY;
  33.260 -            }
  33.261 -            break;
  33.262 -        case CDROM_AUDIO_COMPLETED:
  33.263 -            status = CD_STOPPED;
  33.264 -            break;
  33.265 -        case CDROM_AUDIO_PLAY:
  33.266 -            status = CD_PLAYING;
  33.267 -            break;
  33.268 -        case CDROM_AUDIO_PAUSED:
  33.269 -            /* Workaround buggy CD-ROM drive */
  33.270 -            if (info.cdsc_trk == CDROM_LEADOUT) {
  33.271 -                status = CD_STOPPED;
  33.272 -            } else {
  33.273 -                status = CD_PAUSED;
  33.274 -            }
  33.275 -            break;
  33.276 -        default:
  33.277 -            status = CD_ERROR;
  33.278 -            break;
  33.279 -        }
  33.280 -    }
  33.281 -    if (position) {
  33.282 -        if (status == CD_PLAYING || (status == CD_PAUSED)) {
  33.283 -            *position = MSF_TO_FRAMES(info.cdsc_absaddr.msf.minute,
  33.284 -                                      info.cdsc_absaddr.msf.second,
  33.285 -                                      info.cdsc_absaddr.msf.frame);
  33.286 -        } else {
  33.287 -            *position = 0;
  33.288 -        }
  33.289 -    }
  33.290 -    return (status);
  33.291 -}
  33.292 -
  33.293 -/* Start play */
  33.294 -static int
  33.295 -SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
  33.296 -{
  33.297 -    struct cdrom_msf playtime;
  33.298 -
  33.299 -    FRAMES_TO_MSF(start,
  33.300 -                  &playtime.cdmsf_min0, &playtime.cdmsf_sec0,
  33.301 -                  &playtime.cdmsf_frame0);
  33.302 -    FRAMES_TO_MSF(start + length, &playtime.cdmsf_min1, &playtime.cdmsf_sec1,
  33.303 -                  &playtime.cdmsf_frame1);
  33.304 -#ifdef DEBUG_CDROM
  33.305 -    fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
  33.306 -            playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0,
  33.307 -            playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1);
  33.308 -#endif
  33.309 -
  33.310 -    return SDL_SYS_CDioctl(cdrom->id, CDROMPLAYMSF, &playtime);
  33.311 -}
  33.312 -
  33.313 -/* Pause play */
  33.314 -static int
  33.315 -SDL_SYS_CDPause(SDL_CD * cdrom)
  33.316 -{
  33.317 -    return SDL_SYS_CDioctl(cdrom->id, CDROMPAUSE, 0);
  33.318 -}
  33.319 -
  33.320 -/* Resume play */
  33.321 -static int
  33.322 -SDL_SYS_CDResume(SDL_CD * cdrom)
  33.323 -{
  33.324 -    return SDL_SYS_CDioctl(cdrom->id, CDROMRESUME, 0);
  33.325 -}
  33.326 -
  33.327 -/* Stop play */
  33.328 -static int
  33.329 -SDL_SYS_CDStop(SDL_CD * cdrom)
  33.330 -{
  33.331 -    return SDL_SYS_CDioctl(cdrom->id, CDROMSTOP, 0);
  33.332 -}
  33.333 -
  33.334 -/* Eject the CD-ROM */
  33.335 -static int
  33.336 -SDL_SYS_CDEject(SDL_CD * cdrom)
  33.337 -{
  33.338 -    return SDL_SYS_CDioctl(cdrom->id, CDROMEJECT, 0);
  33.339 -}
  33.340 -
  33.341 -#endif /* SDL_CDROM_MINT */
  33.342 -/* vi: set ts=4 sw=4 expandtab: */
    34.1 --- a/src/cdrom/openbsd/SDL_syscdrom.c	Sat Sep 05 09:03:35 2009 +0000
    34.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.3 @@ -1,430 +0,0 @@
    34.4 -/*
    34.5 -    SDL - Simple DirectMedia Layer
    34.6 -    Copyright (C) 1997-2009 Sam Lantinga
    34.7 -
    34.8 -    This library is free software; you can redistribute it and/or
    34.9 -    modify it under the terms of the GNU Lesser General Public
   34.10 -    License as published by the Free Software Foundation; either
   34.11 -    version 2.1 of the License, or (at your option) any later version.
   34.12 -
   34.13 -    This library is distributed in the hope that it will be useful,
   34.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   34.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   34.16 -    Lesser General Public License for more details.
   34.17 -
   34.18 -    You should have received a copy of the GNU Lesser General Public
   34.19 -    License along with this library; if not, write to the Free Software
   34.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   34.21 -
   34.22 -    Sam Lantinga
   34.23 -    slouken@libsdl.org
   34.24 -*/
   34.25 -#include "SDL_config.h"
   34.26 -
   34.27 -#ifdef SDL_CDROM_OPENBSD
   34.28 -
   34.29 -/* Functions for system-level CD-ROM audio control */
   34.30 -
   34.31 -#include <sys/types.h>
   34.32 -#include <sys/ioctl.h>
   34.33 -#include <sys/stat.h>
   34.34 -#include <fcntl.h>
   34.35 -#include <errno.h>
   34.36 -#include <unistd.h>
   34.37 -#include <sys/ioctl.h>
   34.38 -#include <sys/cdio.h>
   34.39 -
   34.40 -#include "SDL_cdrom.h"
   34.41 -#include "../SDL_syscdrom.h"
   34.42 -
   34.43 -
   34.44 -/* The maximum number of CD-ROM drives we'll detect */
   34.45 -#define MAX_DRIVES	16
   34.46 -
   34.47 -/* A list of available CD-ROM drives */
   34.48 -static char *SDL_cdlist[MAX_DRIVES];
   34.49 -static dev_t SDL_cdmode[MAX_DRIVES];
   34.50 -
   34.51 -/* The system-dependent CD control functions */
   34.52 -static const char *SDL_SYS_CDName(int drive);
   34.53 -static int SDL_SYS_CDOpen(int drive);
   34.54 -static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
   34.55 -static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
   34.56 -static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
   34.57 -static int SDL_SYS_CDPause(SDL_CD * cdrom);
   34.58 -static int SDL_SYS_CDResume(SDL_CD * cdrom);
   34.59 -static int SDL_SYS_CDStop(SDL_CD * cdrom);
   34.60 -static int SDL_SYS_CDEject(SDL_CD * cdrom);
   34.61 -static void SDL_SYS_CDClose(SDL_CD * cdrom);
   34.62 -
   34.63 -/* Some ioctl() errno values which occur when the tray is empty */
   34.64 -#define ERRNO_TRAYEMPTY(errno)	\
   34.65 -	((errno == EIO) || (errno == ENOENT) || (errno == EINVAL) || \
   34.66 -	 (errno == ENODEV))
   34.67 -
   34.68 -/* Check a drive to see if it is a CD-ROM */
   34.69 -static int
   34.70 -CheckDrive(char *drive, struct stat *stbuf)
   34.71 -{
   34.72 -    int is_cd, cdfd;
   34.73 -    struct ioc_read_subchannel info;
   34.74 -
   34.75 -    /* If it doesn't exist, return -1 */
   34.76 -    if (stat(drive, stbuf) < 0) {
   34.77 -        return (-1);
   34.78 -    }
   34.79 -
   34.80 -    /* If it does exist, verify that it's an available CD-ROM */
   34.81 -    is_cd = 0;
   34.82 -    if (S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode)) {
   34.83 -        cdfd = open(drive, (O_RDONLY | O_EXCL | O_NONBLOCK), 0);
   34.84 -        if (cdfd >= 0) {
   34.85 -            info.address_format = CD_MSF_FORMAT;
   34.86 -            info.data_format = CD_CURRENT_POSITION;
   34.87 -            info.data_len = 0;
   34.88 -            info.data = NULL;
   34.89 -            /* Under Linux, EIO occurs when a disk is not present.
   34.90 -               This isn't 100% reliable, so we use the USE_MNTENT
   34.91 -               code above instead.
   34.92 -             */
   34.93 -            if ((ioctl(cdfd, CDIOCREADSUBCHANNEL, &info) == 0) ||
   34.94 -                ERRNO_TRAYEMPTY(errno)) {
   34.95 -                is_cd = 1;
   34.96 -            }
   34.97 -            close(cdfd);
   34.98 -        } else if (ERRNO_TRAYEMPTY(errno))
   34.99 -            is_cd = 1;
  34.100 -    }
  34.101 -    return (is_cd);
  34.102 -}
  34.103 -
  34.104 -/* Add a CD-ROM drive to our list of valid drives */
  34.105 -static void
  34.106 -AddDrive(char *drive, struct stat *stbuf)
  34.107 -{
  34.108 -    int i;
  34.109 -
  34.110 -    if (SDL_numcds < MAX_DRIVES) {
  34.111 -        /* Check to make sure it's not already in our list.
  34.112 -           This can happen when we see a drive via symbolic link.
  34.113 -         */
  34.114 -        for (i = 0; i < SDL_numcds; ++i) {
  34.115 -            if (stbuf->st_rdev == SDL_cdmode[i]) {
  34.116 -#ifdef DEBUG_CDROM
  34.117 -                fprintf(stderr, "Duplicate drive detected: %s == %s\n",
  34.118 -                        drive, SDL_cdlist[i]);
  34.119 -#endif
  34.120 -                return;
  34.121 -            }
  34.122 -        }
  34.123 -
  34.124 -        /* Add this drive to our list */
  34.125 -        i = SDL_numcds;
  34.126 -        SDL_cdlist[i] = SDL_strdup(drive);
  34.127 -        if (SDL_cdlist[i] == NULL) {
  34.128 -            SDL_OutOfMemory();
  34.129 -            return;
  34.130 -        }
  34.131 -        SDL_cdmode[i] = stbuf->st_rdev;
  34.132 -        ++SDL_numcds;
  34.133 -#ifdef DEBUG_CDROM
  34.134 -        fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
  34.135 -#endif
  34.136 -    }
  34.137 -}
  34.138 -
  34.139 -int
  34.140 -SDL_SYS_CDInit(void)
  34.141 -{
  34.142 -    static char *checklist[] = {
  34.143 -#if defined(__OPENBSD__)
  34.144 -        "?0 cd?c", "cdrom", NULL
  34.145 -#elif defined(__NETBSD__)
  34.146 -        "?0 cd?d", "?0 cd?c", "cdrom", NULL
  34.147 -#else
  34.148 -        "?0 cd?c", "?0 acd?c", "cdrom", NULL
  34.149 -#endif
  34.150 -    };
  34.151 -    char *SDLcdrom;
  34.152 -    int i, j, exists;
  34.153 -    char drive[32];
  34.154 -    struct stat stbuf;
  34.155 -
  34.156 -    /* Fill in our driver capabilities */
  34.157 -    SDL_CDcaps.Name = SDL_SYS_CDName;
  34.158 -    SDL_CDcaps.Open = SDL_SYS_CDOpen;
  34.159 -    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
  34.160 -    SDL_CDcaps.Status = SDL_SYS_CDStatus;
  34.161 -    SDL_CDcaps.Play = SDL_SYS_CDPlay;
  34.162 -    SDL_CDcaps.Pause = SDL_SYS_CDPause;
  34.163 -    SDL_CDcaps.Resume = SDL_SYS_CDResume;
  34.164 -    SDL_CDcaps.Stop = SDL_SYS_CDStop;
  34.165 -    SDL_CDcaps.Eject = SDL_SYS_CDEject;
  34.166 -    SDL_CDcaps.Close = SDL_SYS_CDClose;
  34.167 -
  34.168 -    /* Look in the environment for our CD-ROM drive list */
  34.169 -    SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
  34.170 -    if (SDLcdrom != NULL) {
  34.171 -        char *cdpath, *delim;
  34.172 -        size_t len = SDL_strlen(SDLcdrom) + 1;
  34.173 -        cdpath = SDL_stack_alloc(char, len);
  34.174 -        if (cdpath != NULL) {
  34.175 -            SDL_strlcpy(cdpath, SDLcdrom, len);
  34.176 -            SDLcdrom = cdpath;
  34.177 -            do {
  34.178 -                delim = SDL_strchr(SDLcdrom, ':');
  34.179 -                if (delim) {
  34.180 -                    *delim++ = '\0';
  34.181 -                }
  34.182 -                if (CheckDrive(SDLcdrom, &stbuf) > 0) {
  34.183 -                    AddDrive(SDLcdrom, &stbuf);
  34.184 -                }
  34.185 -                if (delim) {
  34.186 -                    SDLcdrom = delim;
  34.187 -                } else {
  34.188 -                    SDLcdrom = NULL;
  34.189 -                }
  34.190 -            } while (SDLcdrom);
  34.191 -            SDL_stack_free(cdpath);
  34.192 -        }
  34.193 -
  34.194 -        /* If we found our drives, there's nothing left to do */
  34.195 -        if (SDL_numcds > 0) {
  34.196 -            return (0);
  34.197 -        }
  34.198 -    }
  34.199 -
  34.200 -    /* Scan the system for CD-ROM drives */
  34.201 -    for (i = 0; checklist[i]; ++i) {
  34.202 -        if (checklist[i][0] == '?') {
  34.203 -            char *insert;
  34.204 -            exists = 1;
  34.205 -            for (j = checklist[i][1]; exists; ++j) {
  34.206 -                SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
  34.207 -                             &checklist[i][3]);
  34.208 -                insert = SDL_strchr(drive, '?');
  34.209 -                if (insert != NULL) {
  34.210 -                    *insert = j;
  34.211 -                }
  34.212 -                switch (CheckDrive(drive, &stbuf)) {
  34.213 -                    /* Drive exists and is a CD-ROM */
  34.214 -                case 1:
  34.215 -                    AddDrive(drive, &stbuf);
  34.216 -                    break;
  34.217 -                    /* Drive exists, but isn't a CD-ROM */
  34.218 -                case 0:
  34.219 -                    break;
  34.220 -                    /* Drive doesn't exist */
  34.221 -                case -1:
  34.222 -                    exists = 0;
  34.223 -                    break;
  34.224 -                }
  34.225 -            }
  34.226 -        } else {
  34.227 -            SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s",
  34.228 -                         checklist[i]);
  34.229 -            if (CheckDrive(drive, &stbuf) > 0) {
  34.230 -                AddDrive(drive, &stbuf);
  34.231 -            }
  34.232 -        }
  34.233 -    }
  34.234 -    return (0);
  34.235 -}
  34.236 -
  34.237 -/* General ioctl() CD-ROM command function */
  34.238 -static int
  34.239 -SDL_SYS_CDioctl(int id, int command, void *arg)
  34.240 -{
  34.241 -    int retval;
  34.242 -
  34.243 -    retval = ioctl(id, command, arg);
  34.244 -    if (retval < 0) {
  34.245 -        SDL_SetError("ioctl() error: %s", strerror(errno));
  34.246 -    }
  34.247 -    return (retval);
  34.248 -}
  34.249 -
  34.250 -static const char *
  34.251 -SDL_SYS_CDName(int drive)
  34.252 -{
  34.253 -    return (SDL_cdlist[drive]);
  34.254 -}
  34.255 -
  34.256 -static int
  34.257 -SDL_SYS_CDOpen(int drive)
  34.258 -{
  34.259 -    return (open(SDL_cdlist[drive], (O_RDONLY | O_EXCL | O_NONBLOCK), 0));
  34.260 -}
  34.261 -
  34.262 -static int
  34.263 -SDL_SYS_CDGetTOC(SDL_CD * cdrom)
  34.264 -{
  34.265 -    struct ioc_toc_header toc;
  34.266 -    int i, okay;
  34.267 -    struct ioc_read_toc_entry entry;
  34.268 -    struct cd_toc_entry data;
  34.269 -
  34.270 -    okay = 0;
  34.271 -    if (SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0) {
  34.272 -        cdrom->numtracks = toc.ending_track - toc.starting_track + 1;
  34.273 -        if (cdrom->numtracks > SDL_MAX_TRACKS) {
  34.274 -            cdrom->numtracks = SDL_MAX_TRACKS;
  34.275 -        }
  34.276 -        /* Read all the track TOC entries */
  34.277 -        for (i = 0; i <= cdrom->numtracks; ++i) {
  34.278 -            if (i == cdrom->numtracks) {
  34.279 -                cdrom->track[i].id = 0xAA;      /* CDROM_LEADOUT */
  34.280 -            } else {
  34.281 -                cdrom->track[i].id = toc.starting_track + i;
  34.282 -            }
  34.283 -            entry.starting_track = cdrom->track[i].id;
  34.284 -            entry.address_format = CD_MSF_FORMAT;
  34.285 -            entry.data_len = sizeof(data);
  34.286 -            entry.data = &data;
  34.287 -            if (SDL_SYS_CDioctl(cdrom->id, CDIOREADTOCENTRYS, &entry) < 0) {
  34.288 -                break;
  34.289 -            } else {
  34.290 -                cdrom->track[i].type = data.control;
  34.291 -                cdrom->track[i].offset =
  34.292 -                    MSF_TO_FRAMES(data.addr.msf.minute,
  34.293 -                                  data.addr.msf.second, data.addr.msf.frame);
  34.294 -                cdrom->track[i].length = 0;
  34.295 -                if (i > 0) {
  34.296 -                    cdrom->track[i - 1].length =
  34.297 -                        cdrom->track[i].offset - cdrom->track[i - 1].offset;
  34.298 -                }
  34.299 -            }
  34.300 -        }
  34.301 -        if (i == (cdrom->numtracks + 1)) {
  34.302 -            okay = 1;
  34.303 -        }
  34.304 -    }
  34.305 -    return (okay ? 0 : -1);
  34.306 -}
  34.307 -
  34.308 -/* Get CD-ROM status */
  34.309 -static CDstatus
  34.310 -SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
  34.311 -{
  34.312 -    CDstatus status;
  34.313 -    struct ioc_toc_header toc;
  34.314 -    struct ioc_read_subchannel info;
  34.315 -    struct cd_sub_channel_info data;
  34.316 -
  34.317 -    info.address_format = CD_MSF_FORMAT;
  34.318 -    info.data_format = CD_CURRENT_POSITION;
  34.319 -    info.track = 0;
  34.320 -    info.data_len = sizeof(data);
  34.321 -    info.data = &data;
  34.322 -    if (ioctl(cdrom->id, CDIOCREADSUBCHANNEL, &info) < 0) {
  34.323 -        if (ERRNO_TRAYEMPTY(errno)) {
  34.324 -            status = CD_TRAYEMPTY;
  34.325 -        } else {
  34.326 -            status = CD_ERROR;
  34.327 -        }
  34.328 -    } else {
  34.329 -        switch (data.header.audio_status) {
  34.330 -        case CD_AS_AUDIO_INVALID:
  34.331 -        case CD_AS_NO_STATUS:
  34.332 -            /* Try to determine if there's a CD available */
  34.333 -            if (ioctl(cdrom->id, CDIOREADTOCHEADER, &toc) == 0)
  34.334 -                status = CD_STOPPED;
  34.335 -            else
  34.336 -                status = CD_TRAYEMPTY;
  34.337 -            break;
  34.338 -        case CD_AS_PLAY_COMPLETED:
  34.339 -            status = CD_STOPPED;
  34.340 -            break;
  34.341 -        case CD_AS_PLAY_IN_PROGRESS:
  34.342 -            status = CD_PLAYING;
  34.343 -            break;
  34.344 -        case CD_AS_PLAY_PAUSED:
  34.345 -            status = CD_PAUSED;
  34.346 -            break;
  34.347 -        default:
  34.348 -            status = CD_ERROR;
  34.349 -            break;
  34.350 -        }
  34.351 -    }
  34.352 -    if (position) {
  34.353 -        if (status == CD_PLAYING || (status == CD_PAUSED)) {
  34.354 -            *position =
  34.355 -                MSF_TO_FRAMES(data.what.position.absaddr.msf.minute,
  34.356 -                              data.what.position.absaddr.msf.second,
  34.357 -                              data.what.position.absaddr.msf.frame);
  34.358 -        } else {
  34.359 -            *position = 0;
  34.360 -        }
  34.361 -    }
  34.362 -    return (status);
  34.363 -}
  34.364 -
  34.365 -/* Start play */
  34.366 -static int
  34.367 -SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
  34.368 -{
  34.369 -    struct ioc_play_msf playtime;
  34.370 -
  34.371 -    FRAMES_TO_MSF(start,
  34.372 -                  &playtime.start_m, &playtime.start_s, &playtime.start_f);
  34.373 -    FRAMES_TO_MSF(start + length,
  34.374 -                  &playtime.end_m, &playtime.end_s, &playtime.end_f);
  34.375 -#ifdef DEBUG_CDROM
  34.376 -    fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
  34.377 -            playtime.start_m, playtime.start_s, playtime.start_f,
  34.378 -            playtime.end_m, playtime.end_s, playtime.end_f);
  34.379 -#endif
  34.380 -    ioctl(cdrom->id, CDIOCSTART, 0);
  34.381 -    return (SDL_SYS_CDioctl(cdrom->id, CDIOCPLAYMSF, &playtime));
  34.382 -}
  34.383 -
  34.384 -/* Pause play */
  34.385 -static int
  34.386 -SDL_SYS_CDPause(SDL_CD * cdrom)
  34.387 -{
  34.388 -    return (SDL_SYS_CDioctl(cdrom->id, CDIOCPAUSE, 0));
  34.389 -}
  34.390 -
  34.391 -/* Resume play */
  34.392 -static int
  34.393 -SDL_SYS_CDResume(SDL_CD * cdrom)
  34.394 -{
  34.395 -    return (SDL_SYS_CDioctl(cdrom->id, CDIOCRESUME, 0));
  34.396 -}
  34.397 -
  34.398 -/* Stop play */
  34.399 -static int
  34.400 -SDL_SYS_CDStop(SDL_CD * cdrom)
  34.401 -{
  34.402 -    return (SDL_SYS_CDioctl(cdrom->id, CDIOCSTOP, 0));
  34.403 -}
  34.404 -
  34.405 -/* Eject the CD-ROM */
  34.406 -static int
  34.407 -SDL_SYS_CDEject(SDL_CD * cdrom)
  34.408 -{
  34.409 -    return (SDL_SYS_CDioctl(cdrom->id, CDIOCEJECT, 0));
  34.410 -}
  34.411 -
  34.412 -/* Close the CD-ROM handle */
  34.413 -static void
  34.414 -SDL_SYS_CDClose(SDL_CD * cdrom)
  34.415 -{
  34.416 -    close(cdrom->id);
  34.417 -}
  34.418 -
  34.419 -void
  34.420 -SDL_SYS_CDQuit(void)
  34.421 -{
  34.422 -    int i;
  34.423 -
  34.424 -    if (SDL_numcds > 0) {
  34.425 -        for (i = 0; i < SDL_numcds; ++i) {
  34.426 -            SDL_free(SDL_cdlist[i]);
  34.427 -        }
  34.428 -        SDL_numcds = 0;
  34.429 -    }
  34.430 -}
  34.431 -
  34.432 -#endif /* SDL_CDROM_OPENBSD */
  34.433 -/* vi: set ts=4 sw=4 expandtab: */
    35.1 --- a/src/cdrom/os2/SDL_syscdrom.c	Sat Sep 05 09:03:35 2009 +0000
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,442 +0,0 @@
    35.4 -/*
    35.5 -    SDL - Simple DirectMedia Layer
    35.6 -    Copyright (C) 1997-2009 Sam Lantinga
    35.7 -
    35.8 -    This library is free software; you can redistribute it and/or
    35.9 -    modify it under the terms of the GNU Lesser General Public
   35.10 -    License as published by the Free Software Foundation; either
   35.11 -    version 2.1 of the License, or (at your option) any later version.
   35.12 -
   35.13 -    This library is distributed in the hope that it will be useful,
   35.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   35.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   35.16 -    Lesser General Public License for more details.
   35.17 -
   35.18 -    You should have received a copy of the GNU Lesser General Public
   35.19 -    License along with this library; if not, write to the Free Software
   35.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   35.21 -
   35.22 -    Sam Lantinga
   35.23 -    slouken@libsdl.org
   35.24 -*/
   35.25 -#include "SDL_config.h"
   35.26 -
   35.27 -#ifdef SDL_CDROM_OS2
   35.28 -
   35.29 -/* Functions for system-level CD-ROM audio control */
   35.30 -
   35.31 -#define INCL_MCIOS2
   35.32 -#include <os2.h>
   35.33 -#include <os2me.h>
   35.34 -
   35.35 -#include "SDL_cdrom.h"
   35.36 -#include "../SDL_syscdrom.h"
   35.37 -
   35.38 -/* Size of MCI result buffer (in bytes) */
   35.39 -#define MCI_CMDRETBUFSIZE	128
   35.40 -
   35.41 -/* The maximum number of CD-ROM drives we'll detect */
   35.42 -#define MAX_DRIVES	16
   35.43 -
   35.44 -/* A list of available CD-ROM drives */
   35.45 -static char *SDL_cdlist[MAX_DRIVES];
   35.46 -//static dev_t SDL_cdmode[MAX_DRIVES];
   35.47 -
   35.48 -/* The system-dependent CD control functions */
   35.49 -static const char *SDL_SYS_CDName(int drive);
   35.50 -static int SDL_SYS_CDOpen(int drive);
   35.51 -static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
   35.52 -static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
   35.53 -static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
   35.54 -static int SDL_SYS_CDPause(SDL_CD * cdrom);
   35.55 -static int SDL_SYS_CDResume(SDL_CD * cdrom);
   35.56 -static int SDL_SYS_CDStop(SDL_CD * cdrom);
   35.57 -static int SDL_SYS_CDEject(SDL_CD * cdrom);
   35.58 -static void SDL_SYS_CDClose(SDL_CD * cdrom);
   35.59 -
   35.60 -/* MCI Timing Functions */
   35.61 -#define	MCI_MMTIMEPERSECOND		3000
   35.62 -#define	FRAMESFROMMM(mmtime)		(((mmtime)*CD_FPS)/MCI_MMTIMEPERSECOND)
   35.63 -
   35.64 -
   35.65 -/* Ready for MCI CDAudio Devices */
   35.66 -int
   35.67 -SDL_SYS_CDInit(void)
   35.68 -{
   35.69 -    int i;                      /* generig counter */
   35.70 -    MCI_SYSINFO_PARMS msp;      /* Structure to MCI SysInfo parameters */
   35.71 -    CHAR SysInfoRet[MCI_CMDRETBUFSIZE]; /* Buffer for MCI Command result */
   35.72 -
   35.73 -/* Fill in our driver capabilities */
   35.74 -    SDL_CDcaps.Name = SDL_SYS_CDName;
   35.75 -    SDL_CDcaps.Open = SDL_SYS_CDOpen;
   35.76 -    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
   35.77 -    SDL_CDcaps.Status = SDL_SYS_CDStatus;
   35.78 -    SDL_CDcaps.Play = SDL_SYS_CDPlay;
   35.79 -    SDL_CDcaps.Pause = SDL_SYS_CDPause;
   35.80 -    SDL_CDcaps.Resume = SDL_SYS_CDResume;
   35.81 -    SDL_CDcaps.Stop = SDL_SYS_CDStop;
   35.82 -    SDL_CDcaps.Eject = SDL_SYS_CDEject;
   35.83 -    SDL_CDcaps.Close = SDL_SYS_CDClose;
   35.84 -
   35.85 -/* Get the number of CD ROMs in the System */
   35.86 -/* Clean SysInfo structure */
   35.87 -    SDL_memset(&msp, 0x00, sizeof(MCI_SYSINFO_PARMS));
   35.88 -/* Prepare structure to Ask Numer of Audio CDs */
   35.89 -    msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO;    /* CD Audio Type */
   35.90 -    msp.pszReturn = (PSZ) & SysInfoRet; /* Return Structure */
   35.91 -    msp.ulRetSize = MCI_CMDRETBUFSIZE;  /* Size of ret struct */
   35.92 -    if (LOUSHORT
   35.93 -        (mciSendCommand
   35.94 -         (0, MCI_SYSINFO, MCI_SYSINFO_QUANTITY | MCI_WAIT, (PVOID) & msp,
   35.95 -          0)) != MCIERR_SUCCESS)
   35.96 -        return (CD_ERROR);
   35.97 -    SDL_numcds = atoi(SysInfoRet);
   35.98 -    if (SDL_numcds > MAX_DRIVES)
   35.99 -        SDL_numcds = MAX_DRIVES;        /* Limit maximum CD number */
  35.100 -
  35.101 -/* Get and Add their system name to the SDL_cdlist */
  35.102 -    msp.pszReturn = (PSZ) & SysInfoRet; /* Return Structure */
  35.103 -    msp.ulRetSize = MCI_CMDRETBUFSIZE;  /* Size of ret struct */
  35.104 -    msp.usDeviceType = MCI_DEVTYPE_CD_AUDIO;    /* CD Audio Type */
  35.105 -    for (i = 0; i < SDL_numcds; i++) {
  35.106 -        msp.ulNumber = i + 1;
  35.107 -        mciSendCommand(0, MCI_SYSINFO, MCI_SYSINFO_NAME | MCI_WAIT, &msp, 0);
  35.108 -        SDL_cdlist[i] = SDL_strdup(SysInfoRet);
  35.109 -        if (SDL_cdlist[i] == NULL) {
  35.110 -            SDL_OutOfMemory();
  35.111 -            return (-1);
  35.112 -        }
  35.113 -    }
  35.114 -    return (0);
  35.115 -}
  35.116 -
  35.117 -/* Return CDAudio System Dependent Device Name - Ready for MCI*/
  35.118 -static const char *
  35.119 -SDL_SYS_CDName(int drive)
  35.120 -{
  35.121 -    return (SDL_cdlist[drive]);
  35.122 -}
  35.123 -
  35.124 -/* Open CDAudio Device - Ready for MCI */
  35.125 -static int
  35.126 -SDL_SYS_CDOpen(int drive)
  35.127 -{
  35.128 -    MCI_OPEN_PARMS mop;
  35.129 -    MCI_SET_PARMS msp;
  35.130 -    MCI_GENERIC_PARMS mgp;
  35.131 -
  35.132 -/* Open the device */
  35.133 -    mop.hwndCallback = (HWND) NULL;     // None
  35.134 -    mop.usDeviceID = (USHORT) NULL;     // Will be returned.
  35.135 -    mop.pszDeviceType = (PSZ) SDL_cdlist[drive];        // CDAudio Device
  35.136 -    if (LOUSHORT(mciSendCommand(0, MCI_OPEN, MCI_WAIT, &mop, 0)) !=
  35.137 -        MCIERR_SUCCESS)
  35.138 -        return (CD_ERROR);
  35.139 -/* Set time format */
  35.140 -    msp.hwndCallback = (HWND) NULL;     // None
  35.141 -    msp.ulTimeFormat = MCI_FORMAT_MSF;  // Minute : Second : Frame structure
  35.142 -    msp.ulSpeedFormat = (ULONG) NULL;   // No change
  35.143 -    msp.ulAudio = (ULONG) NULL; // No Channel
  35.144 -    msp.ulLevel = (ULONG) NULL; // No Volume
  35.145 -    msp.ulOver = (ULONG) NULL;  // No Delay
  35.146 -    msp.ulItem = (ULONG) NULL;  // No item
  35.147 -    msp.ulValue = (ULONG) NULL; // No value for item flag
  35.148 -    if (LOUSHORT
  35.149 -        (mciSendCommand
  35.150 -         (mop.usDeviceID, MCI_SET, MCI_WAIT | MCI_SET_TIME_FORMAT, &msp,
  35.151 -          0)) == MCIERR_SUCCESS)
  35.152 -        return (mop.usDeviceID);
  35.153 -/* Error setting time format? - Close opened device */
  35.154 -    mgp.hwndCallback = (HWND) NULL;     // None
  35.155 -    mciSendCommand(mop.usDeviceID, MCI_CLOSE, MCI_WAIT, &mgp, 0);
  35.156 -    return (CD_ERROR);
  35.157 -}
  35.158 -
  35.159 -/* Get CD Table Of Contents - Ready for MCI */
  35.160 -static int
  35.161 -SDL_SYS_CDGetTOC(SDL_CD * cdrom)
  35.162 -{
  35.163 -    MCI_TOC_PARMS mtp;
  35.164 -    MCI_STATUS_PARMS msp;
  35.165 -    MCI_TOC_REC *mtr;
  35.166 -    INT i;
  35.167 -
  35.168 -/* Correction because MCI cannot read TOC while CD is playing (it'll stop!) */
  35.169 -    if (cdrom->status == CD_PLAYING || cdrom->status == CD_PAUSED)
  35.170 -        return 0;
  35.171 -
  35.172 -/* Get Number of Tracks */
  35.173 -    msp.hwndCallback = (HWND) NULL;     /* None */
  35.174 -    msp.ulReturn = (ULONG) NULL;        /* We want this information */
  35.175 -    msp.ulItem = MCI_STATUS_NUMBER_OF_TRACKS;
  35.176 -    msp.ulValue = (ULONG) NULL; /* No additional information */
  35.177 -    if (LOUSHORT
  35.178 -        (mciSendCommand
  35.179 -         (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp,
  35.180 -          0)) != MCIERR_SUCCESS)
  35.181 -        return (CD_ERROR);
  35.182 -    cdrom->numtracks = msp.ulReturn;
  35.183 -    if (cdrom->numtracks > SDL_MAX_TRACKS) {
  35.184 -        cdrom->numtracks = SDL_MAX_TRACKS;
  35.185 -    }
  35.186 -/* Alocate space for TOC data */
  35.187 -    mtr = (MCI_TOC_REC *) SDL_malloc(cdrom->numtracks * sizeof(MCI_TOC_REC));
  35.188 -    if (mtr == NULL) {
  35.189 -        SDL_OutOfMemory();
  35.190 -        return (-1);
  35.191 -    }
  35.192 -/* Get TOC from CD */
  35.193 -    mtp.pBuf = mtr;
  35.194 -    mtp.ulBufSize = cdrom->numtracks * sizeof(MCI_TOC_REC);
  35.195 -    if (LOUSHORT(mciSendCommand(cdrom->id, MCI_GETTOC, MCI_WAIT, &mtp, 0))
  35.196 -        != MCIERR_SUCCESS) {
  35.197 -        SDL_OutOfMemory();
  35.198 -        SDL_free(mtr);
  35.199 -        return (CD_ERROR);
  35.200 -    }
  35.201 -/* Fill SDL Tracks Structure */
  35.202 -    for (i = 0; i < cdrom->numtracks; i++) {
  35.203 -        /* Set Track ID */
  35.204 -        cdrom->track[i].id = (mtr + i)->TrackNum;
  35.205 -        /* Set Track Type */
  35.206 -        msp.hwndCallback = (HWND) NULL; /* None */
  35.207 -        msp.ulReturn = (ULONG) NULL;    /* We want this information */
  35.208 -        msp.ulItem = MCI_CD_STATUS_TRACK_TYPE;
  35.209 -        msp.ulValue = (ULONG) ((mtr + i)->TrackNum);    /* Track Number? */
  35.210 -        if (LOUSHORT
  35.211 -            (mciSendCommand
  35.212 -             (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_TRACK | MCI_STATUS_ITEM,
  35.213 -              &msp, 0)) != MCIERR_SUCCESS) {
  35.214 -            SDL_free(mtr);
  35.215 -            return (CD_ERROR);
  35.216 -        }
  35.217 -        if (msp.ulReturn == MCI_CD_TRACK_AUDIO)
  35.218 -            cdrom->track[i].type = SDL_AUDIO_TRACK;
  35.219 -        else
  35.220 -            cdrom->track[i].type = SDL_DATA_TRACK;
  35.221 -        /* Set Track Length - values from MCI are in MMTIMEs - 3000 MMTIME = 1 second */
  35.222 -        cdrom->track[i].length =
  35.223 -            FRAMESFROMMM((mtr + i)->ulEndAddr - (mtr + i)->ulStartAddr);
  35.224 -        /* Set Track Offset */
  35.225 -        cdrom->track[i].offset = FRAMESFROMMM((mtr + i)->ulStartAddr);
  35.226 -    }
  35.227 -    SDL_free(mtr);
  35.228 -    return (0);
  35.229 -}
  35.230 -
  35.231 -
  35.232 -/* Get CD-ROM status - Ready for MCI */
  35.233 -static CDstatus
  35.234 -SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
  35.235 -{
  35.236 -    CDstatus status;
  35.237 -    MCI_STATUS_PARMS msp;
  35.238 -
  35.239 -/* Get Status from MCI */
  35.240 -    msp.hwndCallback = (HWND) NULL;     /* None */
  35.241 -    msp.ulReturn = (ULONG) NULL;        /* We want this information */
  35.242 -    msp.ulItem = MCI_STATUS_MODE;
  35.243 -    msp.ulValue = (ULONG) NULL; /* No additional information */
  35.244 -    if (LOUSHORT
  35.245 -        (mciSendCommand
  35.246 -         (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp,
  35.247 -          0)) != MCIERR_SUCCESS)
  35.248 -        status = CD_ERROR;
  35.249 -    else {
  35.250 -        switch (msp.ulReturn) {
  35.251 -        case MCI_MODE_NOT_READY:
  35.252 -            status = CD_TRAYEMPTY;
  35.253 -            break;
  35.254 -        case MCI_MODE_PAUSE:
  35.255 -            status = CD_PAUSED;
  35.256 -            break;
  35.257 -        case MCI_MODE_PLAY:
  35.258 -            status = CD_PLAYING;
  35.259 -            break;
  35.260 -        case MCI_MODE_STOP:
  35.261 -            status = CD_STOPPED;
  35.262 -            break;
  35.263 -            /* These cases should not occour */
  35.264 -        case MCI_MODE_RECORD:
  35.265 -        case MCI_MODE_SEEK:
  35.266 -        default:
  35.267 -            status = CD_ERROR;
  35.268 -            break;
  35.269 -        }
  35.270 -    }
  35.271 -
  35.272 -/* Determine position */
  35.273 -    if (position != NULL) {     /* The SDL $&$&%# CDROM call sends NULL pointer here! */
  35.274 -        if ((status == CD_PLAYING) || (status == CD_PAUSED)) {
  35.275 -            /* Get Position */
  35.276 -            msp.hwndCallback = (HWND) NULL;     /* None */
  35.277 -            msp.ulReturn = (ULONG) NULL;        /* We want this information */
  35.278 -            msp.ulItem = MCI_STATUS_POSITION;
  35.279 -            msp.ulValue = (ULONG) NULL; /* No additiona info */
  35.280 -            if (LOUSHORT
  35.281 -                (mciSendCommand
  35.282 -                 (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp,
  35.283 -                  0)) != MCIERR_SUCCESS)
  35.284 -                return (CD_ERROR);
  35.285 -            /* Convert from MSF (format selected in the Open process) to Frames (format that will be returned) */
  35.286 -            *position =
  35.287 -                MSF_TO_FRAMES(MSF_MINUTE(msp.ulReturn),
  35.288 -                              MSF_SECOND(msp.ulReturn),
  35.289 -                              MSF_FRAME(msp.ulReturn));
  35.290 -        } else
  35.291 -            *position = 0;
  35.292 -    }
  35.293 -    return (status);
  35.294 -}
  35.295 -
  35.296 -/* Start play - Ready for MCI */
  35.297 -static int
  35.298 -SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
  35.299 -{
  35.300 -    MCI_GENERIC_PARMS mgp;
  35.301 -    MCI_STATUS_PARMS msp;
  35.302 -    MCI_PLAY_PARMS mpp;
  35.303 -    ULONG min, sec, frm;
  35.304 -
  35.305 -/* Start MSF */
  35.306 -    FRAMES_TO_MSF(start, &min, &sec, &frm);
  35.307 -    MSF_MINUTE(mpp.ulFrom) = min;
  35.308 -    MSF_SECOND(mpp.ulFrom) = sec;
  35.309 -    MSF_FRAME(mpp.ulFrom) = frm;
  35.310 -/* End MSF */
  35.311 -    FRAMES_TO_MSF(start + length, &min, &sec, &frm);
  35.312 -    MSF_MINUTE(mpp.ulTo) = min;
  35.313 -    MSF_SECOND(mpp.ulTo) = sec;
  35.314 -    MSF_FRAME(mpp.ulTo) = frm;
  35.315 -#ifdef DEBUG_CDROM
  35.316 -    fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
  35.317 -            playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0,
  35.318 -            playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1);
  35.319 -#endif
  35.320 -/* Verifies if it is paused first... and if it is, unpause before stopping it. */
  35.321 -    msp.hwndCallback = (HWND) NULL;     /* None */
  35.322 -    msp.ulReturn = (ULONG) NULL;        /* We want this information */
  35.323 -    msp.ulItem = MCI_STATUS_MODE;
  35.324 -    msp.ulValue = (ULONG) NULL; /* No additional information */
  35.325 -    if (LOUSHORT
  35.326 -        (mciSendCommand
  35.327 -         (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp,
  35.328 -          0)) == MCIERR_SUCCESS) {
  35.329 -        if (msp.ulReturn == MCI_MODE_PAUSE) {
  35.330 -            mgp.hwndCallback = (HWND) NULL;     // None
  35.331 -            mciSendCommand(cdrom->id, MCI_RESUME, 0, &mgp, 0);
  35.332 -        }
  35.333 -    }
  35.334 -/* Now play it. */
  35.335 -    mpp.hwndCallback = (HWND) NULL;     // We do not want the info. temp
  35.336 -    if (LOUSHORT
  35.337 -        (mciSendCommand(cdrom->id, MCI_PLAY, MCI_FROM | MCI_TO, &mpp, 0)) ==
  35.338 -        MCIERR_SUCCESS)
  35.339 -        return 0;
  35.340 -    return (CD_ERROR);
  35.341 -}
  35.342 -
  35.343 -/* Pause play - Ready for MCI */
  35.344 -static int
  35.345 -SDL_SYS_CDPause(SDL_CD * cdrom)
  35.346 -{
  35.347 -    MCI_GENERIC_PARMS mgp;
  35.348 -
  35.349 -    mgp.hwndCallback = (HWND) NULL;     // None
  35.350 -    if (LOUSHORT(mciSendCommand(cdrom->id, MCI_PAUSE, MCI_WAIT, &mgp, 0)) ==
  35.351 -        MCIERR_SUCCESS)
  35.352 -        return 0;
  35.353 -    return (CD_ERROR);
  35.354 -}
  35.355 -
  35.356 -/* Resume play - Ready for MCI */
  35.357 -static int
  35.358 -SDL_SYS_CDResume(SDL_CD * cdrom)
  35.359 -{
  35.360 -    MCI_GENERIC_PARMS mgp;
  35.361 -
  35.362 -    mgp.hwndCallback = (HWND) NULL;     // None
  35.363 -    if (LOUSHORT(mciSendCommand(cdrom->id, MCI_RESUME, MCI_WAIT, &mgp, 0))
  35.364 -        == MCIERR_SUCCESS)
  35.365 -        return 0;
  35.366 -    return (CD_ERROR);
  35.367 -}
  35.368 -
  35.369 -/* Stop play - Ready for MCI */
  35.370 -static int
  35.371 -SDL_SYS_CDStop(SDL_CD * cdrom)
  35.372 -{
  35.373 -    MCI_GENERIC_PARMS mgp;
  35.374 -    MCI_STATUS_PARMS msp;
  35.375 -
  35.376 -/* Verifies if it is paused first... and if it is, unpause before stopping it. */
  35.377 -    msp.hwndCallback = (HWND) NULL;     /* None */
  35.378 -    msp.ulReturn = (ULONG) NULL;        /* We want this information */
  35.379 -    msp.ulItem = MCI_STATUS_MODE;
  35.380 -    msp.ulValue = (ULONG) NULL; /* No additional information */
  35.381 -    if (LOUSHORT
  35.382 -        (mciSendCommand
  35.383 -         (cdrom->id, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &msp,
  35.384 -          0)) == MCIERR_SUCCESS) {
  35.385 -        if (msp.ulReturn == MCI_MODE_PAUSE) {
  35.386 -            mgp.hwndCallback = (HWND) NULL;     // None
  35.387 -            mciSendCommand(cdrom->id, MCI_RESUME, 0, &mgp, 0);
  35.388 -        }
  35.389 -    }
  35.390 -/* Now stops the media */
  35.391 -    mgp.hwndCallback = (HWND) NULL;     // None
  35.392 -    if (LOUSHORT(mciSendCommand(cdrom->id, MCI_STOP, MCI_WAIT, &mgp, 0)) ==
  35.393 -        MCIERR_SUCCESS)
  35.394 -        return 0;
  35.395 -    return (CD_ERROR);
  35.396 -}
  35.397 -
  35.398 -/* Eject the CD-ROM - Ready for MCI */
  35.399 -static int
  35.400 -SDL_SYS_CDEject(SDL_CD * cdrom)
  35.401 -{
  35.402 -    MCI_SET_PARMS msp;
  35.403 -
  35.404 -    msp.hwndCallback = (HWND) NULL;     // None
  35.405 -    msp.ulTimeFormat = (ULONG) NULL;    // No change
  35.406 -    msp.ulSpeedFormat = (ULONG) NULL;   // No change
  35.407 -    msp.ulAudio = (ULONG) NULL; // No Channel
  35.408 -    msp.ulLevel = (ULONG) NULL; // No Volume
  35.409 -    msp.ulOver = (ULONG) NULL;  // No Delay
  35.410 -    msp.ulItem = (ULONG) NULL;  // No item
  35.411 -    msp.ulValue = (ULONG) NULL; // No value for item flag
  35.412 -    if (LOUSHORT
  35.413 -        (mciSendCommand
  35.414 -         (cdrom->id, MCI_SET, MCI_WAIT | MCI_SET_DOOR_OPEN, &msp,
  35.415 -          0)) == MCIERR_SUCCESS)
  35.416 -        return 0;
  35.417 -    return (CD_ERROR);
  35.418 -}
  35.419 -
  35.420 -/* Close the CD-ROM handle - Ready for MCI */
  35.421 -static void
  35.422 -SDL_SYS_CDClose(SDL_CD * cdrom)
  35.423 -{
  35.424 -    MCI_GENERIC_PARMS mgp;
  35.425 -
  35.426 -    mgp.hwndCallback = (HWND) NULL;     // None
  35.427 -    mciSendCommand(cdrom->id, MCI_CLOSE, MCI_WAIT, &mgp, 0);
  35.428 -}
  35.429 -
  35.430 -/* Finalize CDROM Subsystem - Ready for MCI */
  35.431 -void
  35.432 -SDL_SYS_CDQuit(void)
  35.433 -{
  35.434 -    int i;
  35.435 -
  35.436 -    if (SDL_numcds > 0) {
  35.437 -        for (i = 0; i < SDL_numcds; ++i) {
  35.438 -            SDL_free(SDL_cdlist[i]);
  35.439 -        }
  35.440 -        SDL_numcds = 0;
  35.441 -    }
  35.442 -}
  35.443 -
  35.444 -#endif /* SDL_CDROM_OS2 */
  35.445 -/* vi: set ts=4 sw=4 expandtab: */
    36.1 --- a/src/cdrom/osf/SDL_syscdrom.c	Sat Sep 05 09:03:35 2009 +0000
    36.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.3 @@ -1,464 +0,0 @@
    36.4 -/*
    36.5 -    Tru64 audio module for SDL (Simple DirectMedia Layer)
    36.6 -    Copyright (C) 2003
    36.7 -
    36.8 -    This library is free software; you can redistribute it and/or
    36.9 -    modify it under the terms of the GNU Library General Public
   36.10 -    License as published by the Free Software Foundation; either
   36.11 -    version 2 of the License, or (at your option) any later version.
   36.12 -
   36.13 -    This library is distributed in the hope that it will be useful,
   36.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   36.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   36.16 -    Library General Public License for more details.
   36.17 -
   36.18 -    You should have received a copy of the GNU Library General Public
   36.19 -    License along with this library; if not, write to the Free
   36.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   36.21 -
   36.22 -
   36.23 -*/
   36.24 -#include "SDL_config.h"
   36.25 -
   36.26 -#ifdef SDL_CDROM_OSF
   36.27 -
   36.28 -/* Functions for system-level CD-ROM audio control */
   36.29 -
   36.30 -/* #define DEBUG_CDROM 1 */
   36.31 -
   36.32 -#include <sys/types.h>
   36.33 -#include <dirent.h>
   36.34 -#include <sys/stat.h>
   36.35 -#include <fcntl.h>
   36.36 -#include <io/cam/cdrom.h>
   36.37 -#include <io/cam/rzdisk.h>
   36.38 -#include <io/common/devgetinfo.h>
   36.39 -
   36.40 -#include "SDL_cdrom.h"
   36.41 -#include "../SDL_syscdrom.h"
   36.42 -
   36.43 -/* The maximum number of CD-ROM drives we'll detect */
   36.44 -#define MAX_DRIVES 16
   36.45 -
   36.46 -/* A list of available CD-ROM drives */
   36.47 -static char *SDL_cdlist[MAX_DRIVES];
   36.48 -static dev_t SDL_cdmode[MAX_DRIVES];
   36.49 -
   36.50 -/* The system-dependent CD control functions */
   36.51 -static const char *SDL_SYS_CDName(int drive);
   36.52 -static int SDL_SYS_CDOpen(int drive);
   36.53 -static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
   36.54 -static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);