Commit 633d7102 authored by Sam Lantinga's avatar Sam Lantinga

CD-ROM support is so passé :)

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403773
parent 8c260f6e
......@@ -50,4 +50,4 @@ we should do it though, since the 1.2 series should not break binary
compatibility in this way.
Requests:
* PCM and CDROM volume control (deprecated, but possible)
* PCM volume control (deprecated, but possible)
......@@ -206,7 +206,6 @@ fi
# Standard C sources
SOURCES="$SOURCES $srcdir/src/*.c"
SOURCES="$SOURCES $srcdir/src/audio/*.c"
SOURCES="$SOURCES $srcdir/src/cdrom/*.c"
SOURCES="$SOURCES $srcdir/src/cpuinfo/*.c"
SOURCES="$SOURCES $srcdir/src/events/*.c"
SOURCES="$SOURCES $srcdir/src/file/*.c"
......@@ -265,12 +264,6 @@ if test x$enable_power != xyes; then
else
SOURCES="$SOURCES $srcdir/src/power/*.c"
fi
AC_ARG_ENABLE(cdrom,
AC_HELP_STRING([--enable-cdrom], [Enable the cdrom subsystem [[default=yes]]]),
, enable_cdrom=yes)
if test x$enable_cdrom != xyes; then
AC_DEFINE(SDL_CDROM_DISABLED)
fi
AC_ARG_ENABLE(threads,
AC_HELP_STRING([--enable-threads], [Enable the threading subsystem [[default=yes]]]),
, enable_threads=yes)
......@@ -2481,41 +2474,6 @@ case "$host" in
;;
esac
fi
# Set up files for the cdrom library
if test x$enable_cdrom = xyes; then
case $ARCH in
linux|solaris)
AC_DEFINE(SDL_CDROM_LINUX)
SOURCES="$SOURCES $srcdir/src/cdrom/linux/*.c"
have_cdrom=yes
;;
*freebsd*)
AC_DEFINE(SDL_CDROM_FREEBSD)
SOURCES="$SOURCES $srcdir/src/cdrom/freebsd/*.c"
have_cdrom=yes
;;
*openbsd*|*netbsd*)
AC_DEFINE(SDL_CDROM_OPENBSD)
SOURCES="$SOURCES $srcdir/src/cdrom/openbsd/*.c"
have_cdrom=yes
;;
bsdi)
AC_DEFINE(SDL_CDROM_BSDI)
SOURCES="$SOURCES $srcdir/src/cdrom/bsdi/*.c"
have_cdrom=yes
;;
aix)
AC_DEFINE(SDL_CDROM_AIX)
SOURCES="$SOURCES $srcdir/src/cdrom/aix/*.c"
have_cdrom=yes
;;
osf)
AC_DEFINE(SDL_CDROM_OSF)
SOURCES="$SOURCES $srcdir/src/cdrom/osf/*.c"
have_cdrom=yes
;;
esac
fi
# Set up files for the thread library
if test x$enable_threads = xyes -a x$use_pthreads != xyes -a x$use_pth != xyes -a x$ARCH = xirix; then
AC_DEFINE(SDL_THREAD_SPROC)
......@@ -2560,12 +2518,6 @@ case "$host" in
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lasound"
have_audio=yes
fi
# Set up files for the cdrom library
if test x$enable_cdrom = xyes; then
AC_DEFINE(SDL_CDROM_QNX)
SOURCES="$SOURCES $srcdir/src/cdrom/qnx/*.c"
have_cdrom=yes
fi
# Set up files for the timer library
if test x$enable_timers = xyes; then
AC_DEFINE(SDL_TIMER_UNIX)
......@@ -2743,12 +2695,6 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
SOURCES="$SOURCES $srcdir/src/power/windows/SDL_syspower.c"
have_power=yes
fi
# Set up files for the cdrom library
if test x$enable_cdrom = xyes; then
AC_DEFINE(SDL_CDROM_WIN32)
SOURCES="$SOURCES $srcdir/src/cdrom/win32/*.c"
have_cdrom=yes
fi
# Set up files for the thread library
if test x$enable_threads = xyes; then
AC_DEFINE(SDL_THREAD_WIN32)
......@@ -2801,12 +2747,6 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
SOURCES="$SOURCES $srcdir/src/joystick/beos/*.cc"
have_joystick=yes
fi
# Set up files for the cdrom library
if test x$enable_cdrom = xyes; then
AC_DEFINE(SDL_CDROM_BEOS)
SOURCES="$SOURCES $srcdir/src/cdrom/beos/*.cc"
have_cdrom=yes
fi
# Set up files for the thread library
if test x$enable_threads = xyes; then
AC_DEFINE(SDL_THREAD_BEOS)
......@@ -2910,12 +2850,6 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
SOURCES="$SOURCES $srcdir/src/power/macosx/*.c"
have_power=yes
fi
# Set up files for the cdrom library
if test x$enable_cdrom = xyes; then
AC_DEFINE(SDL_CDROM_MACOSX)
SOURCES="$SOURCES $srcdir/src/cdrom/macosx/*.c"
have_cdrom=yes
fi
# Set up files for the timer library
if test x$enable_timers = xyes; then
AC_DEFINE(SDL_TIMER_UNIX)
......@@ -2929,7 +2863,7 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,Carbon"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,IOKit"
# If either the audio or CD driver is used, add the AudioUnit framework
if test x$enable_audio = xyes -o x$enable_cdrom = xyes; then
if test x$enable_audio = xyes; then
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit"
fi
;;
......@@ -2959,12 +2893,6 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
SOURCES="$SOURCES $srcdir/src/joystick/mint/*.c"
have_joystick=yes
fi
# Set up files for the cdrom library
if test x$enable_cdrom = xyes; then
AC_DEFINE(SDL_CDROM_MINT)
SOURCES="$SOURCES $srcdir/src/cdrom/mint/*.c"
have_cdrom=yes
fi
# Set up files for the timer library
if test x$enable_timers = xyes; then
if test x$enable_threads = xyes -a x$enable_pth = xyes; then
......@@ -3025,12 +2953,6 @@ if test x$have_haptic != xyes; then
fi
SOURCES="$SOURCES $srcdir/src/haptic/dummy/*.c"
fi
if test x$have_cdrom != xyes; then
if test x$enable_cdrom = xyes; then
AC_DEFINE(SDL_CDROM_DISABLED)
fi
SOURCES="$SOURCES $srcdir/src/cdrom/dummy/*.c"
fi
if test x$have_threads != xyes; then
if test x$enable_threads = xyes; then
AC_DEFINE(SDL_THREADS_DISABLED)
......
......@@ -78,7 +78,6 @@ Enjoy!
#include "SDL_stdinc.h"
#include "SDL_atomic.h"
#include "SDL_audio.h"
#include "SDL_cdrom.h"
#include "SDL_cpuinfo.h"
#include "SDL_endian.h"
#include "SDL_error.h"
......@@ -109,7 +108,6 @@ extern "C" {
#define SDL_INIT_TIMER 0x00000001
#define SDL_INIT_AUDIO 0x00000010
#define SDL_INIT_VIDEO 0x00000020
#define SDL_INIT_CDROM 0x00000100
#define SDL_INIT_JOYSTICK 0x00000200
#define SDL_INIT_HAPTIC 0x00001000
#define SDL_INIT_NOPARACHUTE 0x00100000 /* Don't catch fatal signals */
......
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
/**
* \file SDL_cdrom.h
*
* This is the CD-audio control API for Simple DirectMedia Layer
*/
#ifndef _SDL_cdrom_h
#define _SDL_cdrom_h
#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
/* In order to use these functions, SDL_Init() must have been called
with the SDL_INIT_CDROM flag. This causes SDL to scan the system
for CD-ROM drives, and load appropriate drivers.
*/
/* The maximum number of CD-ROM tracks on a disk */
#define SDL_MAX_TRACKS 99
/* The types of CD-ROM track possible */
#define SDL_AUDIO_TRACK 0x00
#define SDL_DATA_TRACK 0x04
/* The possible states which a CD-ROM drive can be in. */
typedef enum
{
CD_TRAYEMPTY,
CD_STOPPED,
CD_PLAYING,
CD_PAUSED,
CD_ERROR = -1
} CDstatus;
/* Given a status, returns true if there's a disk in the drive */
#define CD_INDRIVE(status) ((int)(status) > 0)
typedef struct SDL_CDtrack
{
Uint8 id; /* Track number */
Uint8 type; /* Data or audio track */
Uint16 unused;
Uint32 length; /* Length, in frames, of this track */
Uint32 offset; /* Offset, in frames, from start of disk */
} SDL_CDtrack;
/* This structure is only current as of the last call to SDL_CDStatus() */
typedef struct SDL_CD
{
int id; /* Private drive identifier */
CDstatus status; /* Current drive status */
/* The rest of this structure is only valid if there's a CD in drive */
int numtracks; /* Number of tracks on disk */
int cur_track; /* Current track position */
int cur_frame; /* Current frame offset within current track */
SDL_CDtrack track[SDL_MAX_TRACKS + 1];
} SDL_CD;
/* Conversion functions from frames to Minute/Second/Frames and vice versa */
#define CD_FPS 75
#define FRAMES_TO_MSF(f, M,S,F) { \
int value = f; \
*(F) = value%CD_FPS; \
value /= CD_FPS; \
*(S) = value%60; \
value /= 60; \
*(M) = value; \
}
#define MSF_TO_FRAMES(M, S, F) ((M)*60*CD_FPS+(S)*CD_FPS+(F))
/* CD-audio API functions: */
/* Returns the number of CD-ROM drives on the system, or -1 if
SDL_Init() has not been called with the SDL_INIT_CDROM flag.
*/
extern DECLSPEC int SDLCALL SDL_CDNumDrives(void);
/* Returns a human-readable, system-dependent identifier for the CD-ROM.
Example:
"/dev/cdrom"
"E:"
"/dev/disk/ide/1/master"
*/
extern DECLSPEC const char *SDLCALL SDL_CDName(int drive);
/* Opens a CD-ROM drive for access. It returns a drive handle on success,
or NULL if the drive was invalid or busy. This newly opened CD-ROM
becomes the default CD used when other CD functions are passed a NULL
CD-ROM handle.
Drives are numbered starting with 0. Drive 0 is the system default CD-ROM.
*/
extern DECLSPEC SDL_CD *SDLCALL SDL_CDOpen(int drive);
/* This function returns the current status of the given drive.
If the drive has a CD in it, the table of contents of the CD and current
play position of the CD will be stored in the SDL_CD structure.
*/
extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD * cdrom);
/* Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks'
tracks and 'nframes' frames. If both 'ntrack' and 'nframe' are 0, play
until the end of the CD. This function will skip data tracks.
This function should only be called after calling SDL_CDStatus() to
get track information about the CD.
For example:
// Play entire CD:
if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
SDL_CDPlayTracks(cdrom, 0, 0, 0, 0);
// Play last track:
if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0);
}
// Play first and second track and 10 seconds of third track:
if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
SDL_CDPlayTracks(cdrom, 0, 0, 2, 10);
This function returns 0, or -1 if there was an error.
*/
extern DECLSPEC int SDLCALL SDL_CDPlayTracks(SDL_CD * cdrom,
int start_track,
int start_frame, int ntracks,
int nframes);
/* Play the given CD starting at 'start' frame for 'length' frames.
It returns 0, or -1 if there was an error.
*/
extern DECLSPEC int SDLCALL SDL_CDPlay(SDL_CD * cdrom, int start, int length);
/* Pause play -- returns 0, or -1 on error */
extern DECLSPEC int SDLCALL SDL_CDPause(SDL_CD * cdrom);
/* Resume play -- returns 0, or -1 on error */
extern DECLSPEC int SDLCALL SDL_CDResume(SDL_CD * cdrom);
/* Stop play -- returns 0, or -1 on error */
extern DECLSPEC int SDLCALL SDL_CDStop(SDL_CD * cdrom);
/* Eject CD-ROM -- returns 0, or -1 on error */
extern DECLSPEC int SDLCALL SDL_CDEject(SDL_CD * cdrom);
/* Closes the handle for the CD-ROM drive */
extern DECLSPEC void SDLCALL SDL_CDClose(SDL_CD * cdrom);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"
#endif /* _SDL_video_h */
/* vi: set ts=4 sw=4 expandtab: */
......@@ -160,7 +160,6 @@
/* Allow disabling of core subsystems */
#undef SDL_AUDIO_DISABLED
#undef SDL_CDROM_DISABLED
#undef SDL_CPUINFO_DISABLED
#undef SDL_EVENTS_DISABLED
#undef SDL_FILE_DISABLED
......@@ -204,22 +203,6 @@
#undef SDL_AUDIO_DRIVER_FUSIONSOUND
#undef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
/* Enable various cdrom drivers */
#undef SDL_CDROM_AIX
#undef SDL_CDROM_BEOS
#undef SDL_CDROM_BSDI
#undef SDL_CDROM_DC
#undef SDL_CDROM_DUMMY
#undef SDL_CDROM_FREEBSD
#undef SDL_CDROM_LINUX
#undef SDL_CDROM_MACOSX
#undef SDL_CDROM_MINT
#undef SDL_CDROM_OPENBSD
#undef SDL_CDROM_OS2
#undef SDL_CDROM_OSF
#undef SDL_CDROM_QNX
#undef SDL_CDROM_WIN32
/* Enable various input drivers */
#undef SDL_INPUT_LINUXEV
#undef SDL_INPUT_TSLIB
......
......@@ -88,9 +88,6 @@ typedef unsigned long uintptr_t;
#define SDL_AUDIO_DRIVER_DISK 1
#define SDL_AUDIO_DRIVER_DUMMY 1
/* Enable various cdrom drivers */
#define SDL_CDROM_DC 1
/* Enable various input drivers */
#define SDL_JOYSTICK_DC 1
#define SDL_HAPTIC_DUMMY 1
......
......@@ -106,9 +106,6 @@ typedef unsigned long uintptr_t;
/* Enable the dummy audio driver (src/audio/dummy/\*.c) */
#define SDL_AUDIO_DRIVER_DUMMY 1
/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */
#define SDL_CDROM_DISABLED 1
/* Enable the stub haptic driver (src/haptic/dummy/\*.c) */
#define SDL_HAPTIC_DISABLED 1
......
......@@ -106,9 +106,6 @@
#define SDL_AUDIO_DRIVER_DISK 1
#define SDL_AUDIO_DRIVER_DUMMY 1
/* Enable various cdrom drivers */
#define SDL_CDROM_MACOSX 1
/* Enable various input drivers */
#define SDL_JOYSTICK_IOKIT 1
#define SDL_HAPTIC_IOKIT 1
......
......@@ -43,9 +43,6 @@ typedef unsigned long uintptr_t;
/* Enable the dummy audio driver (src/audio/dummy/\*.c) */
#define SDL_AUDIO_DRIVER_DUMMY 1
/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */
#define SDL_CDROM_DISABLED 1
/* Enable the stub joystick driver (src/joystick/dummy/\*.c) */
#define SDL_JOYSTICK_DISABLED 1
......
......@@ -96,9 +96,6 @@ typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
#define SDL_AUDIO_DRIVER_NDS 1
/*#define SDL_AUDIO_DRIVER_DUMMY 1 TODO: uncomment this later*/
/* DS doesn't have optical media */
#define SDL_CDROM_DISABLED 1
/* Enable various input drivers */
#define SDL_JOYSTICK_NDS 1
/*#define SDL_JOYSTICK_DUMMY 1 TODO: uncomment this later*/
......
......@@ -116,9 +116,6 @@ typedef unsigned long long uint64_t;
#define SDL_AUDIO_DRIVER_DISK 1
#define SDL_AUDIO_DRIVER_DUMMY 1
/* Enable various cdrom drivers */
#define SDL_CDROM_OS2 1
/* Enable various input drivers */
#define SDL_JOYSTICK_OS2 1
#define SDL_HAPTIC_DUMMY 1
......
......@@ -95,7 +95,6 @@
#define HAVE_SETJMP 1
#define HAVE_NANOSLEEP 1
#define SDL_CDROM_DISABLED 1
#define SDL_AUDIO_DRIVER_DUMMY 1
#define SDL_AUDIO_DRIVER_OSS 1
......
......@@ -150,13 +150,6 @@ typedef unsigned int uintptr_t;
#define SDL_AUDIO_DRIVER_DISK 1
#define SDL_AUDIO_DRIVER_DUMMY 1
/* Enable various cdrom drivers */
#ifdef _WIN32_WCE
#define SDL_CDROM_DISABLED 1
#else
#define SDL_CDROM_WIN32 1
#endif
/* Enable various input drivers */
#ifdef _WIN32_WCE
#define SDL_JOYSTICK_DISABLED 1
......
......@@ -42,10 +42,6 @@ extern void SDL_JoystickQuit(void);
extern int SDL_HapticInit(void);
extern int SDL_HapticQuit(void);
#endif
#if !SDL_CDROM_DISABLED
extern int SDL_CDROMInit(void);
extern void SDL_CDROMQuit(void);
#endif
#if !SDL_TIMERS_DISABLED
extern void SDL_StartTicks(void);
extern int SDL_TimerInit(void);
......@@ -145,22 +141,6 @@ SDL_InitSubSystem(Uint32 flags)
return (-1);
}
#endif
#if !SDL_CDROM_DISABLED
/* Initialize the CD-ROM subsystem */
if ((flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM)) {
if (SDL_CDROMInit() < 0) {
return (-1);
}
SDL_initialized |= SDL_INIT_CDROM;
}
#else
if (flags & SDL_INIT_CDROM) {
SDL_SetError("SDL not built with cdrom support");
return (-1);
}
#endif
return (0);
}
......@@ -198,12 +178,6 @@ void
SDL_QuitSubSystem(Uint32 flags)
{
/* Shut down requested initialized subsystems */
#if !SDL_CDROM_DISABLED
if ((flags & SDL_initialized & SDL_INIT_CDROM)) {
SDL_CDROMQuit();
SDL_initialized &= ~SDL_INIT_CDROM;
}
#endif
#if !SDL_JOYSTICK_DISABLED
if ((flags & SDL_initialized & SDL_INIT_JOYSTICK)) {
SDL_JoystickQuit();
......
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/* This is the CD-audio control API for Simple DirectMedia Layer */
#include "SDL_cdrom.h"
#include "SDL_syscdrom.h"
#define CLIP_FRAMES 10 /* Some CD-ROMs won't go all the way */
static int SDL_cdinitted = 0;
static SDL_CD *default_cdrom;
/* The system level CD-ROM control functions */
struct CDcaps SDL_CDcaps = {
NULL, /* Name */
NULL, /* Open */
NULL, /* GetTOC */
NULL, /* Status */
NULL, /* Play */
NULL, /* Pause */
NULL, /* Resume */
NULL, /* Stop */
NULL, /* Eject */
NULL, /* Close */
};
int SDL_numcds;
int
SDL_CDROMInit(void)
{
int retval;
SDL_numcds = 0;
retval = SDL_SYS_CDInit();
if (retval == 0) {
SDL_cdinitted = 1;
}
default_cdrom = NULL;
return (retval);
}
/* Check to see if the CD-ROM subsystem has been initialized */
static int
CheckInit(int check_cdrom, SDL_CD ** cdrom)
{
int okay;
okay = SDL_cdinitted;
if (check_cdrom && (*cdrom == NULL)) {
*cdrom = default_cdrom;
if (*cdrom == NULL) {
SDL_SetError("CD-ROM not opened");
okay = 0;
}
}
if (!SDL_cdinitted) {
SDL_SetError("CD-ROM subsystem not initialized");
}
return (okay);
}
int
SDL_CDNumDrives(void)
{
if (!CheckInit(0, NULL)) {
return (-1);
}
return (SDL_numcds);
}
const char *
SDL_CDName(int drive)
{
if (!CheckInit(0, NULL)) {
return (NULL);
}
if (drive >= SDL_numcds) {
SDL_SetError("Invalid CD-ROM drive index");
return (NULL);
}
if (SDL_CDcaps.Name) {
return (SDL_CDcaps.Name(drive));
} else {
return ("");
}
}
SDL_CD *
SDL_CDOpen(int drive)
{
struct SDL_CD *cdrom;
if (!CheckInit(0, NULL)) {
return (NULL);
}
if (drive >= SDL_numcds) {
SDL_SetError("Invalid CD-ROM drive index");
return (NULL);
}
cdrom = (SDL_CD *) SDL_malloc(sizeof(*cdrom));
if (cdrom == NULL) {
SDL_OutOfMemory();
return (NULL);
}
SDL_memset(cdrom, 0, sizeof(*cdrom));
cdrom->id = SDL_CDcaps.Open(drive);
if (cdrom->id < 0) {
SDL_free(cdrom);
return (NULL);
}
default_cdrom = cdrom;
return (cdrom);
}
CDstatus
SDL_CDStatus(SDL_CD * cdrom)
{
CDstatus status;
int i;
Uint32 position;
/* Check if the CD-ROM subsystem has been initialized */
if (!CheckInit(1, &cdrom)) {
return (CD_ERROR);
}
/* Get the current status of the drive */
cdrom->numtracks = 0;
cdrom->cur_track = 0;
cdrom->cur_frame = 0;
status = SDL_CDcaps.Status(cdrom, &i);
position = (Uint32) i;
cdrom->status = status;
/* Get the table of contents, if there's a CD available */
if (CD_INDRIVE(status)) {
if (SDL_CDcaps.GetTOC(cdrom) < 0) {
status = CD_ERROR;
}
/* If the drive is playing, get current play position */
if ((status == CD_PLAYING) || (status == CD_PAUSED)) {
for (i = 1; cdrom->track[i].offset <= position; ++i) {
/* Keep looking */ ;
}
#ifdef DEBUG_CDROM
fprintf(stderr,
"Current position: %d, track = %d (offset is %d)\n",
position, i - 1, cdrom->track[i - 1].offset);
#endif
cdrom->cur_track = i - 1;
position -= cdrom->track[cdrom->cur_track].offset;
cdrom->cur_frame = position;
}
}
return (status);
}
int
SDL_CDPlayTracks(SDL_CD * cdrom,
int strack, int sframe, int ntracks, int nframes)
{
int etrack, eframe;
int start, length;
/* Check if the CD-ROM subsystem has been initialized */
if (!CheckInit(1, &cdrom)) {
return (CD_ERROR);
}
/* Determine the starting and ending tracks */
if ((strack < 0) || (strack >= cdrom->numtracks)) {
SDL_SetError("Invalid starting track");
return (CD_ERROR);
}
if (!ntracks && !nframes) {
etrack = cdrom->numtracks;
eframe = 0;
} else {
etrack = strack + ntracks;
if (etrack == strack) {
eframe = sframe + nframes;
} else {
eframe = nframes;
}
}
if (etrack > cdrom->numtracks) {
SDL_SetError("Invalid play length");
return (CD_ERROR);
}
/* Skip data tracks and verify frame offsets */
while ((strack <= etrack) &&
(cdrom->track[strack].type == SDL_DATA_TRACK)) {
++strack;
}
if (sframe >= (int) cdrom->track[strack].length) {
SDL_SetError("Invalid starting frame for track %d", strack);
return (CD_ERROR);
}
while ((etrack > strack) &&
(cdrom->track[etrack - 1].type == SDL_DATA_TRACK)) {
--etrack;
}
if (eframe > (int) cdrom->track[etrack].length) {
SDL_SetError("Invalid ending frame for track %d", etrack);
return (CD_ERROR);
}
/* Determine start frame and play length */
start = (cdrom->track[strack].offset + sframe);
length = (cdrom->track[etrack].offset + eframe) - start;
#ifdef CLIP_FRAMES
/* I've never seen this necessary, but xmcd does it.. */
length -= CLIP_FRAMES; /* CLIP_FRAMES == 10 */
#endif
if (length < 0) {
return (0);
}
/* Play! */
#ifdef DEBUG_CDROM
fprintf(stderr, "Playing %d frames at offset %d\n", length, start);
#endif
return (SDL_CDcaps.Play(cdrom, start, length));
}
int
SDL_CDPlay(SDL_CD * cdrom, int sframe, int length)
{
/* Check if the CD-ROM subsystem has been initialized */
if (!CheckInit(1, &cdrom)) {
return (CD_ERROR);
}
return (SDL_CDcaps.Play(cdrom, sframe, length));
}
int
SDL_CDPause(SDL_CD * cdrom)
{
CDstatus status;
int retval;
/* Check if the CD-ROM subsystem has been initialized */
if (!CheckInit(1, &cdrom)) {
return (CD_ERROR);
}
status = SDL_CDcaps.Status(cdrom, NULL);
switch (status) {
case CD_PLAYING:
retval = SDL_CDcaps.Pause(cdrom);
break;
default:
retval = 0;
break;
}
return (retval);
}
int
SDL_CDResume(SDL_CD * cdrom)
{
CDstatus status;
int retval;
/* Check if the CD-ROM subsystem has been initialized */
if (!CheckInit(1, &cdrom)) {
return (CD_ERROR);
}
status = SDL_CDcaps.Status(cdrom, NULL);
switch (status) {
case CD_PAUSED:
retval = SDL_CDcaps.Resume(cdrom);
default:
retval = 0;
break;
}
return (retval);
}
int
SDL_CDStop(SDL_CD * cdrom)
{
CDstatus status;
int retval;
/* Check if the CD-ROM subsystem has been initialized */
if (!CheckInit(1, &cdrom)) {
return (CD_ERROR);
}
status = SDL_CDcaps.Status(cdrom, NULL);
switch (status) {
case CD_PLAYING:
case CD_PAUSED:
retval = SDL_CDcaps.Stop(cdrom);
default:
retval = 0;
break;
}
return (retval);
}
int
SDL_CDEject(SDL_CD * cdrom)
{
/* Check if the CD-ROM subsystem has been initialized */
if (!CheckInit(1, &cdrom)) {
return (CD_ERROR);
}
return (SDL_CDcaps.Eject(cdrom));
}
void
SDL_CDClose(SDL_CD * cdrom)
{
/* Check if the CD-ROM subsystem has been initialized */
if (!CheckInit(1, &cdrom)) {
return;
}
SDL_CDcaps.Close(cdrom);
SDL_free(cdrom);
default_cdrom = NULL;
}
void
SDL_CDROMQuit(void)
{
SDL_SYS_CDQuit();
SDL_cdinitted = 0;
}
/* vi: set ts=4 sw=4 expandtab: */
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is SDL_free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/* This is the system specific header for the SDL CD-ROM API */
/* Structure of CD audio control functions */
extern struct CDcaps
{
/* Get the name of the specified drive */
const char *(*Name) (int drive);
/* Open the specified drive, returning a drive id, or -1 on error */
int (*Open) (int drive);
/* Get table-of-contents (number of tracks + track info) for disk.
The TOC information should be stored in the cdrom structure.
This function should return 0 on success, or -1 on error.
*/
int (*GetTOC) (SDL_CD * cdrom);
/* Return the current status and play position, in frames, of the
drive. 'position' may be NULL, and if so, should be ignored.
*/
CDstatus(*Status) (SDL_CD * cdrom, int *position);
/* Play from frame 'start' to 'start+len' */
int (*Play) (SDL_CD * cdrom, int start, int len);
/* Pause play */
int (*Pause) (SDL_CD * cdrom);
/* Resume play */
int (*Resume) (SDL_CD * cdrom);
/* Stop play */
int (*Stop) (SDL_CD * cdrom);
/* Eject the current disk */
int (*Eject) (SDL_CD * cdrom);
/* Close the specified drive */
void (*Close) (SDL_CD * cdrom);
} SDL_CDcaps;
/* The number of available CD-ROM drives on the system */
extern int SDL_numcds;
/* Function to scan the system for CD-ROM drives and fill SDL_CDcaps.
* This function should set SDL_numcds to the number of available CD
* drives. Drive 0 should be the system default CD-ROM.
* It should return 0, or -1 on an unrecoverable fatal error.
*/
extern int SDL_SYS_CDInit(void);
/* Function to perform any system-specific CD-ROM related cleanup */
extern void SDL_SYS_CDQuit(void);
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifdef SDL_CDROM_DC
/* Functions for system-level CD-ROM audio control */
#include <dc/cdrom.h>
#include <dc/spu.h>
#include "SDL_cdrom.h"
#include "../SDL_syscdrom.h"
/* The system-dependent CD control functions */
static const char *SDL_SYS_CDName(int drive);
static int SDL_SYS_CDOpen(int drive);
static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
static int SDL_SYS_CDPause(SDL_CD * cdrom);
static int SDL_SYS_CDResume(SDL_CD * cdrom);
static int SDL_SYS_CDStop(SDL_CD * cdrom);
static int SDL_SYS_CDEject(SDL_CD * cdrom);
static void SDL_SYS_CDClose(SDL_CD * cdrom);
int
SDL_SYS_CDInit(void)
{
/* Fill in our driver capabilities */
SDL_CDcaps.Name = SDL_SYS_CDName;
SDL_CDcaps.Open = SDL_SYS_CDOpen;
SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
SDL_CDcaps.Status = SDL_SYS_CDStatus;
SDL_CDcaps.Play = SDL_SYS_CDPlay;
SDL_CDcaps.Pause = SDL_SYS_CDPause;
SDL_CDcaps.Resume = SDL_SYS_CDResume;
SDL_CDcaps.Stop = SDL_SYS_CDStop;
SDL_CDcaps.Eject = SDL_SYS_CDEject;
SDL_CDcaps.Close = SDL_SYS_CDClose;
return (0);
}
static const char *
SDL_SYS_CDName(int drive)
{
return "/cd";
}
static int
SDL_SYS_CDOpen(int drive)
{
return (drive);
}
#define TRACK_CDDA 0
static int
SDL_SYS_CDGetTOC(SDL_CD * cdrom)
{
CDROM_TOC toc;
int ret, i;
ret = cdrom_read_toc(&toc, 0);
if (ret != ERR_OK) {
return -1;
}
cdrom->numtracks = TOC_TRACK(toc.last) - TOC_TRACK(toc.first) + 1;
for (i = 0; i < cdrom->numtracks; i++) {
unsigned long entry = toc.entry[i];
cdrom->track[i].id = i + 1;
cdrom->track[i].type =
(TOC_CTRL(toc.entry[i]) ==
TRACK_CDDA) ? SDL_AUDIO_TRACK : SDL_DATA_TRACK;
cdrom->track[i].offset = TOC_LBA(entry) - 150;
cdrom->track[i].length =
TOC_LBA((i + 1 <
toc.last) ? toc.entry[i + 1] : toc.leadout_sector) -
TOC_LBA(entry);
}
return 0;
}
/* Get CD-ROM status */
static CDstatus
SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
{
int ret, dc_status, disc_type;
ret = cdrom_get_status(&dc_status, &disc_type);
if (ret != ERR_OK)
return CD_ERROR;
switch (dc_status) {
// case CD_STATUS_BUSY:
case CD_STATUS_PAUSED:
return CD_PAUSED;
case CD_STATUS_STANDBY:
return CD_STOPPED;
case CD_STATUS_PLAYING:
return CD_PLAYING;
// case CD_STATUS_SEEKING:
// case CD_STATUS_SCANING:
case CD_STATUS_OPEN:
case CD_STATUS_NO_DISC:
return CD_TRAYEMPTY;
default:
return CD_ERROR;
}
}
/* Start play */
static int
SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
{
int ret =
cdrom_cdda_play(start - 150, start - 150 + length, 1, CDDA_SECTORS);
return ret == ERR_OK ? 0 : -1;
}
/* Pause play */
static int
SDL_SYS_CDPause(SDL_CD * cdrom)
{
int ret = cdrom_cdda_pause();
return ret == ERR_OK ? 0 : -1;
}
/* Resume play */
static int
SDL_SYS_CDResume(SDL_CD * cdrom)
{
int ret = cdrom_cdda_resume();
return ret == ERR_OK ? 0 : -1;
}
/* Stop play */
static int
SDL_SYS_CDStop(SDL_CD * cdrom)
{
int ret = cdrom_spin_down();
return ret == ERR_OK ? 0 : -1;
}
/* Eject the CD-ROM */
static int
SDL_SYS_CDEject(SDL_CD * cdrom)
{
return -1;
}
/* Close the CD-ROM handle */
static void
SDL_SYS_CDClose(SDL_CD * cdrom)
{
}
void
SDL_SYS_CDQuit(void)
{
}
#endif /* SDL_CDROM_DC */
/* vi: set ts=4 sw=4 expandtab: */
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#if defined(SDL_CDROM_DUMMY) || defined(SDL_CDROM_DISABLED)
/* Stub functions for system-level CD-ROM audio control */
#include "SDL_cdrom.h"
#include "../SDL_syscdrom.h"
int
SDL_SYS_CDInit(void)
{
return (0);
}
void
SDL_SYS_CDQuit(void)
{
return;
}
#endif /* SDL_CDROM_DUMMY || SDL_CDROM_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
This file based on Apple sample code. We haven't changed the file name,
so if you want to see the original search for it on apple.com/developer
*/
#include "SDL_config.h"
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AudioFilePlayer.h
*/
#ifndef __AudioFilePlayer_H__
#define __AudioFilePlayer_H__
#include <CoreServices/CoreServices.h>
#include <AudioUnit/AudioUnit.h>
#ifdef AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
#include <AudioUnit/AUNTComponent.h>
#endif
#include "SDL_error.h"
const char *AudioFilePlayerErrorStr(OSStatus error);
/*
void ThrowResult (OSStatus result, const char *str);
#define THROW_RESULT(str) \
if (result) { \
ThrowResult (result, str); \
}
*/
typedef void (*AudioFilePlayNotifier) (void *inRefCon, OSStatus inStatus);
enum
{
kAudioFilePlayErr_FilePlayUnderrun = -10000,
kAudioFilePlay_FileIsFinished = -10001,
kAudioFilePlay_PlayerIsUninitialized = -10002
};
struct S_AudioFileManager;
#pragma mark __________ AudioFilePlayer
typedef struct S_AudioFilePlayer
{
/*public:*/
int (*SetDestination) (struct S_AudioFilePlayer * afp,
AudioUnit * inDestUnit);
void (*SetNotifier) (struct S_AudioFilePlayer * afp,
AudioFilePlayNotifier inNotifier, void *inRefCon);
void (*SetStartFrame) (struct S_AudioFilePlayer * afp, int frame); /* seek in the file */
int (*GetCurrentFrame) (struct S_AudioFilePlayer * afp); /* get the current frame position */
void (*SetStopFrame) (struct S_AudioFilePlayer * afp, int frame); /* set limit in the file */
int (*Connect) (struct S_AudioFilePlayer * afp);
void (*Disconnect) (struct S_AudioFilePlayer * afp);
void (*DoNotification) (struct S_AudioFilePlayer * afp, OSStatus inError);
int (*IsConnected) (struct S_AudioFilePlayer * afp);
AudioUnit(*GetDestUnit) (struct S_AudioFilePlayer * afp);
void (*Print) (struct S_AudioFilePlayer * afp);
/*private:*/
AudioUnit mPlayUnit;
SInt16 mForkRefNum;
AudioUnitInputCallback mInputCallback;
AudioStreamBasicDescription mFileDescription;
int mConnected;
struct S_AudioFileManager *mAudioFileManager;
AudioFilePlayNotifier mNotifier;
void *mRefCon;
int mStartFrame;
#pragma mark __________ Private_Methods
int (*OpenFile) (struct S_AudioFilePlayer * afp, const FSRef * inRef,
SInt64 * outFileSize);
} AudioFilePlayer;
AudioFilePlayer *new_AudioFilePlayer(const FSRef * inFileRef);
void delete_AudioFilePlayer(AudioFilePlayer * afp);
#pragma mark __________ AudioFileManager
typedef struct S_AudioFileManager
{
/*public:*/
/* this method should NOT be called by an object of this class
as it is called by the parent's Disconnect() method */
void (*Disconnect) (struct S_AudioFileManager * afm);
int (*DoConnect) (struct S_AudioFileManager * afm);
OSStatus(*Read) (struct S_AudioFileManager * afm, char *buffer,
UInt32 * len);
const char *(*GetFileBuffer) (struct S_AudioFileManager * afm);
const AudioFilePlayer *(*GetParent) (struct S_AudioFileManager * afm);
void (*SetPosition) (struct S_AudioFileManager * afm, SInt64 pos); /* seek/rewind in the file */
int (*GetByteCounter) (struct S_AudioFileManager * afm); /* return actual bytes streamed to audio hardware */
void (*SetEndOfFile) (struct S_AudioFileManager * afm, SInt64 pos); /* set the "EOF" (will behave just like it reached eof) */
/*protected:*/
AudioFilePlayer *mParent;
SInt16 mForkRefNum;
SInt64 mAudioDataOffset;
char *mFileBuffer;
int mByteCounter;
int mReadFromFirstBuffer;
int mLockUnsuccessful;
int mIsEngaged;
int mNumTimesAskedSinceFinished;
void *mTmpBuffer;
UInt32 mBufferSize;
UInt32 mBufferOffset;
/*public:*/
UInt32 mChunkSize;
SInt64 mFileLength;
SInt64 mReadFilePosition;
int mWriteToFirstBuffer;
int mFinishedReadingData;
/*protected:*/
OSStatus(*Render) (struct S_AudioFileManager * afm,
AudioBuffer * ioData);
OSStatus(*GetFileData) (struct S_AudioFileManager * afm,
void **inOutData, UInt32 * inOutDataSize);
void (*AfterRender) (struct S_AudioFileManager * afm);
/*public:*/
/*static */
OSStatus(*FileInputProc) (void *inRefCon,
AudioUnitRenderActionFlags inActionFlags,
const AudioTimeStamp * inTimeStamp,
UInt32 inBusNumber, AudioBuffer * ioData);
} AudioFileManager;
AudioFileManager *new_AudioFileManager(AudioFilePlayer * inParent,
SInt16 inForkRefNum,
SInt64 inFileLength,
UInt32 inChunkSize);
void delete_AudioFileManager(AudioFileManager * afm);
#endif
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifndef __CDPlayer__H__
#define __CDPlayer__H__ 1
#include <string.h>
#include <Carbon/Carbon.h>
#include <CoreFoundation/CoreFoundation.h>
#include <AudioUnit/AudioUnit.h>
#include "SDL_cdrom.h"
#include "SDL_thread.h"
#include "SDL_mutex.h"
#ifdef __cplusplus
extern "C"
{
#endif
typedef void (*CDPlayerCompletionProc) (SDL_CD * cdrom);
void Lock();
void Unlock();
int LoadFile(const FSRef * ref, int startFrame, int endFrame); /* pass -1 to do nothing */
int ReleaseFile();
int PlayFile();
int PauseFile();
void SetCompletionProc(CDPlayerCompletionProc proc, SDL_CD * cdrom);
int ReadTOCData(FSVolumeRefNum theVolume, SDL_CD * theCD);
int ListTrackFiles(FSVolumeRefNum theVolume, FSRef * trackFiles,
int numTracks);
int DetectAudioCDVolumes(FSVolumeRefNum * volumes, int numVolumes);
int GetCurrentFrame();
#ifdef __cplusplus
};
#endif
#endif /* __CD_Player__H__ */
/* vi: set ts=4 sw=4 expandtab: */
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/*
Note: This file hasn't been modified so technically we have to keep the disclaimer :-(
Copyright: © Copyright 2002 Apple Computer, Inc. All rights reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
copyrights in this original Apple software (the "Apple Software"), to use,
reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks or logos of
Apple Computer, Inc. may be used to endorse or promote products derived from the
Apple Software without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any patent rights that
may be infringed by your derivative works or by other works in which the Apple
Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=============================================================================
CAGuard.cp
=============================================================================*/
/*=============================================================================
Includes
=============================================================================*/
/*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
*/
#include "SDL_stdinc.h"
/*#define NDEBUG 1*/
/*
#include <assert.h>
*/
#define assert(X)
#include "SDLOSXCAGuard.h"
/*#warning Need a try-based Locker too*/
/*=============================================================================
SDLOSXCAGuard
=============================================================================*/
static int
SDLOSXCAGuard_Lock(SDLOSXCAGuard * cag)
{
int theAnswer = 0;
if (pthread_self() != cag->mOwner) {
OSStatus theError = pthread_mutex_lock(&cag->mMutex);
(void) theError;
assert(theError == 0);
cag->mOwner = pthread_self();
theAnswer = 1;
}
return theAnswer;
}
static void
SDLOSXCAGuard_Unlock(SDLOSXCAGuard * cag)
{
OSStatus theError;
assert(pthread_self() == cag->mOwner);
cag->mOwner = 0;
theError = pthread_mutex_unlock(&cag->mMutex);
(void) theError;
assert(theError == 0);
}
static int
SDLOSXCAGuard_Try(SDLOSXCAGuard * cag, int *outWasLocked)
{
int theAnswer = 0;
*outWasLocked = 0;
if (pthread_self() == cag->mOwner) {
theAnswer = 1;
*outWasLocked = 0;
} else {
OSStatus theError = pthread_mutex_trylock(&cag->mMutex);
if (theError == 0) {
cag->mOwner = pthread_self();
theAnswer = 1;
*outWasLocked = 1;
}
}
return theAnswer;
}
static void
SDLOSXCAGuard_Wait(SDLOSXCAGuard * cag)
{
OSStatus theError;
assert(pthread_self() == cag->mOwner);
cag->mOwner = 0;
theError = pthread_cond_wait(&cag->mCondVar, &cag->mMutex);
(void) theError;
assert(theError == 0);
cag->mOwner = pthread_self();
}
static void
SDLOSXCAGuard_Notify(SDLOSXCAGuard * cag)
{
OSStatus theError = pthread_cond_signal(&cag->mCondVar);
(void) theError;
assert(theError == 0);
}
SDLOSXCAGuard *
new_SDLOSXCAGuard(void)
{
OSStatus theError;
SDLOSXCAGuard *cag = (SDLOSXCAGuard *) SDL_malloc(sizeof(SDLOSXCAGuard));
if (cag == NULL)
return NULL;
SDL_memset(cag, '\0', sizeof(*cag));
#define SET_SDLOSXCAGUARD_METHOD(m) cag->m = SDLOSXCAGuard_##m
SET_SDLOSXCAGUARD_METHOD(Lock);
SET_SDLOSXCAGUARD_METHOD(Unlock);
SET_SDLOSXCAGUARD_METHOD(Try);
SET_SDLOSXCAGUARD_METHOD(Wait);
SET_SDLOSXCAGUARD_METHOD(Notify);
#undef SET_SDLOSXCAGUARD_METHOD
theError = pthread_mutex_init(&cag->mMutex, NULL);
(void) theError;
assert(theError == 0);
theError = pthread_cond_init(&cag->mCondVar, NULL);
(void) theError;
assert(theError == 0);
cag->mOwner = 0;
return cag;
}
void
delete_SDLOSXCAGuard(SDLOSXCAGuard * cag)
{
if (cag != NULL) {
pthread_mutex_destroy(&cag->mMutex);
pthread_cond_destroy(&cag->mCondVar);
SDL_free(cag);
}
}
/* vi: set ts=4 sw=4 expandtab: */
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/*
Note: This file hasn't been modified so technically we have to keep the disclaimer :-(
Copyright: © Copyright 2002 Apple Computer, Inc. All rights reserved.
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
("Apple") in consideration of your agreement to the following terms, and your
use, installation, modification or redistribution of this Apple software
constitutes acceptance of these terms. If you do not agree with these terms,
please do not use, install, modify or redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and subject
to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
copyrights in this original Apple software (the "Apple Software"), to use,
reproduce, modify and redistribute the Apple Software, with or without
modifications, in source and/or binary forms; provided that if you redistribute
the Apple Software in its entirety and without modifications, you must retain
this notice and the following text and disclaimers in all such redistributions of
the Apple Software. Neither the name, trademarks, service marks or logos of
Apple Computer, Inc. may be used to endorse or promote products derived from the
Apple Software without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or implied,
are granted by Apple herein, including but not limited to any patent rights that
may be infringed by your derivative works or by other works in which the Apple
Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*=============================================================================
CAGuard.h
=============================================================================*/
#if !defined(__CAGuard_h__)
#define __CAGuard_h__
/*=============================================================================
Includes
=============================================================================*/
#include <CoreAudio/CoreAudioTypes.h>
#include <pthread.h>
/*=============================================================================
CAGuard
This is your typical mutex with signalling implemented via pthreads.
Lock() will return true if and only if the guard is locked on that call.
A thread that already has the guard will receive 'false' if it locks it
again. Use of the stack-based CAGuard::Locker class is highly recommended
to properly manage the recursive nesting. The Wait calls with timeouts
will return true if and only if the timeout period expired. They will
return false if they receive notification any other way.
=============================================================================*/
typedef struct S_SDLOSXCAGuard
{
/* Construction/Destruction */
/*public:*/
/* Actions */
/*public:*/
int (*Lock) (struct S_SDLOSXCAGuard * cag);
void (*Unlock) (struct S_SDLOSXCAGuard * cag);
int (*Try) (struct S_SDLOSXCAGuard * cag, int *outWasLocked); /* returns true if lock is free, false if not */
void (*Wait) (struct S_SDLOSXCAGuard * cag);
void (*Notify) (struct S_SDLOSXCAGuard * cag);
/* Implementation */
/*protected:*/
pthread_mutex_t mMutex;
pthread_cond_t mCondVar;
pthread_t mOwner;
} SDLOSXCAGuard;
SDLOSXCAGuard *new_SDLOSXCAGuard(void);
void delete_SDLOSXCAGuard(SDLOSXCAGuard * cag);
#endif
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/* This is the Mac OS X / CoreAudio specific header for the SDL CD-ROM API
Contributed by Darrell Walisser and Max Horn
*/
/***********************************************************************************
Implementation Notes
*********************
This code has several limitations currently (all of which are proabaly fixable):
1. A CD-ROM device is inferred from a mounted cdfs volume, so device 0 is
not necessarily the first CD-ROM device on the system. (Somewhat easy to fix
by useing the device name from the volume id's to reorder the volumes)
2. You can only open and control 1 CD-ROM device at a time. (Challenging to fix,
due to extensive code restructuring)
3. The status reported by SDL_CDStatus only changes to from CD_PLAYING to CD_STOPPED in
1-second intervals (because the audio is buffered in 1-second chunks) If
the audio data is less than 1 second, the remainder is filled with silence.
If you need to play sequences back-to-back that are less that 1 second long,
use the frame position to determine when to play the next sequence, instead
of SDL_CDStatus.
This may be possible to fix with a clever usage of the AudioUnit API.
4. When new volumes are inserted, our volume information is not updated. The only way
to refresh this information is to reinit the CD-ROM subsystem of SDL. To fix this,
one would probably have to fix point 1 above first, then figure out how to register
for a notification when new media is mounted in order to perform an automatic
rescan for cdfs volumes.
So, here comes a description of how this all works.
< Initializing >
To get things rolling, we have to locate mounted volumes that contain
audio (since nearly all Macs don't have analog audio-in on the sound card).
That's easy, since these volumes have a flag that indicates this special
filesystem. See DetectAudioCDVolumes() in CDPlayer.cpp for this code.
Next, we parse the invisible .TOC.plist in the root of the volume, which gets us
the track information (number, offset, length, leadout, etc). See ReadTOCData() in
CDPlayer.cpp for the skinny on this.
< The Playback Loop >
Now come the tricky parts. Let's start with basic audio playback. When a frame
range to play is requested, we must first find the .aiff files on the volume,
hopefully in the right order. Since these files all begin with a number "1 Audio Track",
etc, this is used to determine the correct track order.
Once all files are determined, we have to find what file corresponds to the start
and length parameter to SDL_SYS_CDPlay(). Again, this is quite simple by walking the
cdrom's track list. At this point, we also save the offset to the next track and frames
remaining, if we're going to have to play another file after the first one. See
GetFileForOffset() for this code.
At this point we have all info needed to start playback, so we hand off to the LoadFile()
function, which proceeds to do its magic and plays back the file.
When the file is finished playing, CompletionProc() is invoked, at which time we can
play the next file if the previously saved next track and frames remaining
indicates that we should.
< Magic >
OK, so it's not really magic, but since I don't fully understand all the hidden details it
seems like it to me ;-) The API's involved are the AudioUnit and AudioFile API's. These
appear to be an extension of CoreAudio for creating modular playback and f/x entities.
The important thing is that CPU usage is very low and reliability is very high. You'd
be hard-pressed to find a way to stutter the playback with other CPU-intensive tasks.
One part of this magic is that it uses multiple threads, which carries the usual potential
for disaster if not handled carefully. Playback currently requires 4 additional threads:
1. The coreaudio runloop thread
2. The coreaudio device i/o thread
3. The file streaming thread
4. The notification/callback thread
The first 2 threads are necessary evil - CoreAudio creates this no matter what the situation
is (even the SDL sound implementation creates theses suckers). The last two are are created
by us.
The file is streamed from disk using a threaded double-buffer approach.
This way, the high latency operation of reading from disk can be performed without interrupting
the real-time device thread (which amounts to avoiding dropouts). The device thread grabs the
buffer that isn't being read and sends it to the CoreAudio mixer where it eventually gets
to the sound card.
The device thread posts a notification when the file streaming thread is out of data. This
notification must be handled in a separate thread to avoid potential deadlock in the
device thread. That's where the notification thread comes in. This thread is signaled
whenever a notification needs to be processed, so another file can be played back if need be.
The API in CDPlayer.cpp contains synchronization because otherwise both the notification thread
and main thread (or another other thread using the SDL CD api) can potentially call it at the same time.
************************************************************************************/
#include "SDL_cdrom.h"
#include "../SDL_syscdrom.h"
#include "CDPlayer.h"
#define kErrorFakeDevice "Error: Cannot proceed since we're faking a CD-ROM device. Reinit the CD-ROM subsystem to scan for new volumes."
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -7,7 +7,7 @@ EXE = @EXE@
CFLAGS = @CFLAGS@
LIBS = @LIBS@
TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testresample$(EXE) testaudioinfo$(EXE) testmultiaudio$(EXE) testpower$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testcursor$(EXE) testintersections$(EXE) testdraw2$(EXE) testdyngl$(EXE) testdyngles$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testgl2$(EXE) testgles$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testsprite2$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) testwm2$(EXE) threadwin$(EXE) torturethread$(EXE) testloadso$(EXE) testhaptic$(EXE) testmmousetablet$(EXE) testatomic$(EXE)
TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testresample$(EXE) testaudioinfo$(EXE) testmultiaudio$(EXE) testpower$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcursor$(EXE) testintersections$(EXE) testdraw2$(EXE) testdyngl$(EXE) testdyngles$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testgl2$(EXE) testgles$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testsprite2$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) testwm2$(EXE) threadwin$(EXE) torturethread$(EXE) testloadso$(EXE) testhaptic$(EXE) testmmousetablet$(EXE) testatomic$(EXE)
all: Makefile $(TARGETS)
......@@ -44,9 +44,6 @@ testbitmap$(EXE): $(srcdir)/testbitmap.c
testblitspeed$(EXE): $(srcdir)/testblitspeed.c
$(CC) -o $@ $? $(CFLAGS) $(LIBS)
testcdrom$(EXE): $(srcdir)/testcdrom.c
$(CC) -o $@ $? $(CFLAGS) $(LIBS)
testcursor$(EXE): $(srcdir)/testcursor.c
$(CC) -o $@ $? $(CFLAGS) $(LIBS)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment