annotate src/cdrom/macosx/AudioFileReaderThread.c @ 1723:4bdbb9b2bd0a SDL-1.3

(none)
author Sam Lantinga <slouken@libsdl.org>
date Thu, 06 Jul 2006 05:53:32 +0000
parents 4da1ee79c9af
children
rev   line source
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 Library General Public License for more details.
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 Sam Lantinga
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 slouken@libsdl.org
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
22 This file based on Apple sample code. We haven't changed the file name,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23 so if you want to see the original search for it on apple.com/developer
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
24 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1338
diff changeset
25 #include "SDL_config.h"
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
27 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
28 AudioFileManager.cpp
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
29 */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 #include "AudioFilePlayer.h"
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
31 #include <mach/mach.h> /* used for setting policy of thread */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 #include "SDLOSXCAGuard.h"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 #include <pthread.h>
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
35 /*#include <list>*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
37 /*typedef void *FileData;*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 typedef struct S_FileData
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 AudioFileManager *obj;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 struct S_FileData *next;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 } FileData;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
45 typedef struct S_FileReaderThread
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
46 {
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
47 /*public:*/
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
48 SDLOSXCAGuard *(*GetGuard) (struct S_FileReaderThread * frt);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
49 void (*AddReader) (struct S_FileReaderThread * frt);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
50 void (*RemoveReader) (struct S_FileReaderThread * frt,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
51 AudioFileManager * inItem);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
52 int (*TryNextRead) (struct S_FileReaderThread * frt,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
53 AudioFileManager * inItem);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
55 int mThreadShouldDie;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
56
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
57 /*private:*/
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
58 /*typedef std::list<AudioFileManager*> FileData; */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
60 SDLOSXCAGuard *mGuard;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
61 UInt32 mThreadPriority;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
62
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
63 int mNumReaders;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
64 FileData *mFileData;
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
67 void (*ReadNextChunk) (struct S_FileReaderThread * frt);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
68 int (*StartFixedPriorityThread) (struct S_FileReaderThread * frt);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
69 /*static */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
70 UInt32(*GetThreadBasePriority) (pthread_t inThread);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
71 /*static */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
72 void *(*DiskReaderEntry) (void *inRefCon);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 } FileReaderThread;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
76 static SDLOSXCAGuard *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
77 FileReaderThread_GetGuard(FileReaderThread * frt)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 return frt->mGuard;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
82 /* returns 1 if succeeded */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
83 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
84 FileReaderThread_TryNextRead(FileReaderThread * frt,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
85 AudioFileManager * inItem)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 int didLock = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 int succeeded = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
89 if (frt->mGuard->Try(frt->mGuard, &didLock)) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
90 /*frt->mFileData.push_back (inItem); */
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
91 /* !!! FIXME: this could be faster with a "tail" member. --ryan. */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 FileData *i = frt->mFileData;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 FileData *prev = NULL;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
95 FileData *newfd = (FileData *) SDL_malloc(sizeof(FileData));
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 newfd->obj = inItem;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 newfd->next = NULL;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
99 while (i != NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
100 prev = i;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
101 i = i->next;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
102 }
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 if (prev == NULL)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 frt->mFileData = newfd;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 else
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 prev->next = newfd;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
108 frt->mGuard->Notify(frt->mGuard);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 succeeded = 1;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 if (didLock)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
112 frt->mGuard->Unlock(frt->mGuard);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
114
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 return succeeded;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
118 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
119 FileReaderThread_AddReader(FileReaderThread * frt)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
121 if (frt->mNumReaders == 0) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 frt->mThreadShouldDie = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
123 frt->StartFixedPriorityThread(frt);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 frt->mNumReaders++;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
128 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
129 FileReaderThread_RemoveReader(FileReaderThread * frt,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
130 AudioFileManager * inItem)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
132 if (frt->mNumReaders > 0) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
133 int bNeedsRelease = frt->mGuard->Lock(frt->mGuard);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
134
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
135 /*frt->mFileData.remove (inItem); */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 FileData *i = frt->mFileData;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 FileData *prev = NULL;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
138 while (i != NULL) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 FileData *next = i->next;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 if (i->obj != inItem)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 prev = i;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
142 else {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 if (prev == NULL)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 frt->mFileData = next;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 else
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 prev->next = next;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
147 SDL_free(i);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 i = next;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 if (--frt->mNumReaders == 0) {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 frt->mThreadShouldDie = 1;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
154 frt->mGuard->Notify(frt->mGuard); /* wake up thread so it will quit */
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
155 frt->mGuard->Wait(frt->mGuard); /* wait for thread to die */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
158 if (bNeedsRelease)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
159 frt->mGuard->Unlock(frt->mGuard);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
160 }
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
163 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
164 FileReaderThread_StartFixedPriorityThread(FileReaderThread * frt)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
166 pthread_attr_t theThreadAttrs;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
167 pthread_t pThread;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
168
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
169 OSStatus result = pthread_attr_init(&theThreadAttrs);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
170 if (result)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
171 return 0; /*THROW_RESULT("pthread_attr_init - Thread attributes could not be created.") */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
173 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
174 pthread_attr_setdetachstate(&theThreadAttrs, PTHREAD_CREATE_DETACHED);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
175 if (result)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
176 return 0; /*THROW_RESULT("pthread_attr_setdetachstate - Thread attributes could not be detached.") */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
177
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
178 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
179 pthread_create(&pThread, &theThreadAttrs, frt->DiskReaderEntry, frt);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
180 if (result)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
181 return 0; /*THROW_RESULT("pthread_create - Create and start the thread.") */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
182
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
183 pthread_attr_destroy(&theThreadAttrs);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
184
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
185 /* we've now created the thread and started it
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
186 we'll now set the priority of the thread to the nominated priority
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
187 and we'll also make the thread fixed */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
188 thread_extended_policy_data_t theFixedPolicy;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
189 thread_precedence_policy_data_t thePrecedencePolicy;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
190 SInt32 relativePriority;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
191
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
192 /* make thread fixed */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
193 theFixedPolicy.timeshare = 0; /* set to 1 for a non-fixed thread */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
194 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
195 thread_policy_set(pthread_mach_thread_np(pThread),
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
196 THREAD_EXTENDED_POLICY,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
197 (thread_policy_t) & theFixedPolicy,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
198 THREAD_EXTENDED_POLICY_COUNT);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
199 if (result)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
200 return 0; /*THROW_RESULT("thread_policy - Couldn't set thread as fixed priority.") */
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
201 /* set priority */
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
202 /* precedency policy's "importance" value is relative to spawning thread's priority */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
203 relativePriority =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
204 frt->mThreadPriority - frt->GetThreadBasePriority(pthread_self());
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
205
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 thePrecedencePolicy.importance = relativePriority;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
207 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
208 thread_policy_set(pthread_mach_thread_np(pThread),
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
209 THREAD_PRECEDENCE_POLICY,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
210 (thread_policy_t) & thePrecedencePolicy,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
211 THREAD_PRECEDENCE_POLICY_COUNT);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
212 if (result)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
213 return 0; /*THROW_RESULT("thread_policy - Couldn't set thread priority.") */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 return 1;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
218 static UInt32
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
219 FileReaderThread_GetThreadBasePriority(pthread_t inThread)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
221 thread_basic_info_data_t threadInfo;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
222 policy_info_data_t thePolicyInfo;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
223 unsigned int count;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
224
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
225 /* get basic info */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 count = THREAD_BASIC_INFO_COUNT;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
227 thread_info(pthread_mach_thread_np(inThread), THREAD_BASIC_INFO,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
228 (integer_t *) & threadInfo, &count);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
229
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 switch (threadInfo.policy) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
231 case POLICY_TIMESHARE:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
232 count = POLICY_TIMESHARE_INFO_COUNT;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
233 thread_info(pthread_mach_thread_np(inThread),
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
234 THREAD_SCHED_TIMESHARE_INFO,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
235 (integer_t *) & (thePolicyInfo.ts), &count);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
236 return thePolicyInfo.ts.base_priority;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
237 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
238
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
239 case POLICY_FIFO:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
240 count = POLICY_FIFO_INFO_COUNT;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
241 thread_info(pthread_mach_thread_np(inThread),
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
242 THREAD_SCHED_FIFO_INFO,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
243 (integer_t *) & (thePolicyInfo.fifo), &count);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
244 if (thePolicyInfo.fifo.depressed) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
245 return thePolicyInfo.fifo.depress_priority;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
246 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
247 return thePolicyInfo.fifo.base_priority;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
248 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
249 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
250
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
251 case POLICY_RR:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
252 count = POLICY_RR_INFO_COUNT;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
253 thread_info(pthread_mach_thread_np(inThread),
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
254 THREAD_SCHED_RR_INFO,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
255 (integer_t *) & (thePolicyInfo.rr), &count);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
256 if (thePolicyInfo.rr.depressed) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
257 return thePolicyInfo.rr.depress_priority;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
258 } else {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
259 return thePolicyInfo.rr.base_priority;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
260 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
261 break;
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264 return 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
267 static void *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
268 FileReaderThread_DiskReaderEntry(void *inRefCon)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
269 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
270 FileReaderThread *frt = (FileReaderThread *) inRefCon;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
271 frt->ReadNextChunk(frt);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
272 #if DEBUG
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
273 printf("finished with reading file\n");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
274 #endif
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
275
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
276 return 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
277 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
278
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
279 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
280 FileReaderThread_ReadNextChunk(FileReaderThread * frt)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281 {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282 OSStatus result;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
283 UInt32 dataChunkSize;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
284 AudioFileManager *theItem = 0;
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
286 for (;;) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
287 { /* this is a scoped based lock */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
288 int bNeedsRelease = frt->mGuard->Lock(frt->mGuard);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
289
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290 if (frt->mThreadShouldDie) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
291 frt->mGuard->Notify(frt->mGuard);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
292 if (bNeedsRelease)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
293 frt->mGuard->Unlock(frt->mGuard);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294 return;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
297 /*if (frt->mFileData.empty()) */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
298 if (frt->mFileData == NULL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
299 frt->mGuard->Wait(frt->mGuard);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
300 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
301
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
302 /* kill thread */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
303 if (frt->mThreadShouldDie) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
304
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
305 frt->mGuard->Notify(frt->mGuard);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
306 if (bNeedsRelease)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
307 frt->mGuard->Unlock(frt->mGuard);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
308 return;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
309 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
310
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
311 /*theItem = frt->mFileData.front(); */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
312 /*frt->mFileData.pop_front(); */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313 theItem = NULL;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
314 if (frt->mFileData != NULL) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
315 FileData *next = frt->mFileData->next;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
316 theItem = frt->mFileData->obj;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
317 SDL_free(frt->mFileData);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
318 frt->mFileData = next;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
319 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
321 if (bNeedsRelease)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
322 frt->mGuard->Unlock(frt->mGuard);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
323 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
324
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
325 if ((theItem->mFileLength - theItem->mReadFilePosition) <
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
326 theItem->mChunkSize)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
327 dataChunkSize = theItem->mFileLength - theItem->mReadFilePosition;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
328 else
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
329 dataChunkSize = theItem->mChunkSize;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
330
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
331 /* this is the exit condition for the thread */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
332 if (dataChunkSize <= 0) {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
333 theItem->mFinishedReadingData = 1;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
334 continue;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
335 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
336 /* construct pointer */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
337 char *writePtr = (char *) (theItem->GetFileBuffer(theItem) +
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
338 (theItem->
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
339 mWriteToFirstBuffer ? 0 : theItem->
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
340 mChunkSize));
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
341
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
342 /* read data */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
343 result = theItem->Read(theItem, writePtr, &dataChunkSize);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
344 if (result != noErr && result != eofErr) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
345 AudioFilePlayer *afp =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
346 (AudioFilePlayer *) theItem->GetParent(theItem);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
347 afp->DoNotification(afp, result);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
348 continue;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
349 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
350
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
351 if (dataChunkSize != theItem->mChunkSize) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
352 writePtr += dataChunkSize;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
353
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
354 /* can't exit yet.. we still have to pass the partial buffer back */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
355 SDL_memset(writePtr, 0, (theItem->mChunkSize - dataChunkSize));
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
356 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
357
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
358 theItem->mWriteToFirstBuffer = !theItem->mWriteToFirstBuffer; /* switch buffers */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
359
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
360 if (result == eofErr)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
361 theItem->mReadFilePosition = theItem->mFileLength;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
362 else
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
363 theItem->mReadFilePosition += dataChunkSize; /* increment count */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
364 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
365 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
366
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
367 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
368 delete_FileReaderThread(FileReaderThread * frt)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
369 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
370 if (frt != NULL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
371 delete_SDLOSXCAGuard(frt->mGuard);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
372 SDL_free(frt);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
373 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
375
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
376 FileReaderThread *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
377 new_FileReaderThread()
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
378 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
379 FileReaderThread *frt =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
380 (FileReaderThread *) SDL_malloc(sizeof(FileReaderThread));
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
381 if (frt == NULL)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
382 return NULL;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
383 SDL_memset(frt, '\0', sizeof(*frt));
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
384
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
385 frt->mGuard = new_SDLOSXCAGuard();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
386 if (frt->mGuard == NULL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
387 SDL_free(frt);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
388 return NULL;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
389 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
390 #define SET_FILEREADERTHREAD_METHOD(m) frt->m = FileReaderThread_##m
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
391 SET_FILEREADERTHREAD_METHOD(GetGuard);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
392 SET_FILEREADERTHREAD_METHOD(AddReader);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
393 SET_FILEREADERTHREAD_METHOD(RemoveReader);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
394 SET_FILEREADERTHREAD_METHOD(TryNextRead);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
395 SET_FILEREADERTHREAD_METHOD(ReadNextChunk);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
396 SET_FILEREADERTHREAD_METHOD(StartFixedPriorityThread);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
397 SET_FILEREADERTHREAD_METHOD(GetThreadBasePriority);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
398 SET_FILEREADERTHREAD_METHOD(DiskReaderEntry);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
399 #undef SET_FILEREADERTHREAD_METHOD
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
400
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401 frt->mThreadPriority = 62;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402 return frt;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
403 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
404
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
405
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
406 static FileReaderThread *sReaderThread;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
407
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
409 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
410 AudioFileManager_DoConnect(AudioFileManager * afm)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
412 if (!afm->mIsEngaged) {
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
413 OSStatus result;
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
414
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
415 /*afm->mReadFilePosition = 0; */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416 afm->mFinishedReadingData = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
418 afm->mNumTimesAskedSinceFinished = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
419 afm->mLockUnsuccessful = 0;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
420
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
421 UInt32 dataChunkSize;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
422
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
423 if ((afm->mFileLength - afm->mReadFilePosition) < afm->mChunkSize)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
424 dataChunkSize = afm->mFileLength - afm->mReadFilePosition;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
425 else
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
426 dataChunkSize = afm->mChunkSize;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
427
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
428 result = afm->Read(afm, afm->mFileBuffer, &dataChunkSize);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
429 if (result)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
430 return 0; /*THROW_RESULT("AudioFileManager::DoConnect(): Read") */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
431
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
432 afm->mReadFilePosition += dataChunkSize;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
433
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
434 afm->mWriteToFirstBuffer = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
435 afm->mReadFromFirstBuffer = 1;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
436
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
437 sReaderThread->AddReader(sReaderThread);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
438
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
439 afm->mIsEngaged = 1;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
440 }
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
441 /*
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
442 else
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
443 throw static_cast<OSStatus>(-1); *//* thread has already been started */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
444
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
445 return 1;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
446 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
447
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
448 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
449 AudioFileManager_Disconnect(AudioFileManager * afm)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
450 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
451 if (afm->mIsEngaged) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
452 sReaderThread->RemoveReader(sReaderThread, afm);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
453 afm->mIsEngaged = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
454 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
455 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
456
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
457 static OSStatus
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
458 AudioFileManager_Read(AudioFileManager * afm, char *buffer, UInt32 * len)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
459 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
460 return FSReadFork(afm->mForkRefNum,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
461 fsFromStart,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
462 afm->mReadFilePosition + afm->mAudioDataOffset,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
463 *len, buffer, len);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
464 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
465
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
466 static OSStatus
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
467 AudioFileManager_GetFileData(AudioFileManager * afm, void **inOutData,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
468 UInt32 * inOutDataSize)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
469 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
470 if (afm->mFinishedReadingData) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
471 ++afm->mNumTimesAskedSinceFinished;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
472 *inOutDataSize = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
473 *inOutData = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
474 return noErr;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
475 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
476
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
477 if (afm->mReadFromFirstBuffer == afm->mWriteToFirstBuffer) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
478 #if DEBUG
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
479 printf("* * * * * * * Can't keep up with reading file\n");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
480 #endif
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
481
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
482 afm->mParent->DoNotification(afm->mParent,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
483 kAudioFilePlayErr_FilePlayUnderrun);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
484 *inOutDataSize = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
485 *inOutData = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
486 } else {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
487 *inOutDataSize = afm->mChunkSize;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
488 *inOutData =
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
489 afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm->
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
490 mFileBuffer +
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
491 afm->mChunkSize);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
492 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
493
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
494 afm->mLockUnsuccessful = !sReaderThread->TryNextRead(sReaderThread, afm);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
495
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
496 afm->mReadFromFirstBuffer = !afm->mReadFromFirstBuffer;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
497
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
498 return noErr;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
499 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
500
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
501 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
502 AudioFileManager_AfterRender(AudioFileManager * afm)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
503 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
504 if (afm->mNumTimesAskedSinceFinished > 0) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
505 int didLock = 0;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
506 SDLOSXCAGuard *guard = sReaderThread->GetGuard(sReaderThread);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
507 if (guard->Try(guard, &didLock)) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
508 afm->mParent->DoNotification(afm->mParent,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
509 kAudioFilePlay_FileIsFinished);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
510 if (didLock)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
511 guard->Unlock(guard);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
512 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
513 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
514
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
515 if (afm->mLockUnsuccessful)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
516 afm->mLockUnsuccessful =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
517 !sReaderThread->TryNextRead(sReaderThread, afm);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
518 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
519
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
520 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
521 AudioFileManager_SetPosition(AudioFileManager * afm, SInt64 pos)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
522 {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
523 if (pos < 0 || pos >= afm->mFileLength) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
524 SDL_SetError
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
525 ("AudioFileManager::SetPosition - position invalid: %d filelen=%d\n",
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
526 (unsigned int) pos, (unsigned int) afm->mFileLength);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
527 pos = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
528 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
529
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
530 afm->mReadFilePosition = pos;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
531 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
532
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
533 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
534 AudioFileManager_SetEndOfFile(AudioFileManager * afm, SInt64 pos)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
535 {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
536 if (pos <= 0 || pos > afm->mFileLength) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
537 SDL_SetError
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
538 ("AudioFileManager::SetEndOfFile - position beyond actual eof\n");
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
539 pos = afm->mFileLength;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
540 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
541
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
542 afm->mFileLength = pos;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
543 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
544
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
545 static const char *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
546 AudioFileManager_GetFileBuffer(AudioFileManager * afm)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
547 {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
548 return afm->mFileBuffer;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
549 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
550
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
551 const AudioFilePlayer *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
552 AudioFileManager_GetParent(AudioFileManager * afm)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
553 {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
554 return afm->mParent;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
555 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
556
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
557 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
558 AudioFileManager_GetByteCounter(AudioFileManager * afm)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
559 {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
560 return afm->mByteCounter;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
561 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
562
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
563
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
564 static OSStatus
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
565 AudioFileManager_FileInputProc(void *inRefCon,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
566 AudioUnitRenderActionFlags inActionFlags,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
567 const AudioTimeStamp * inTimeStamp,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
568 UInt32 inBusNumber, AudioBuffer * ioData)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
569 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
570 AudioFileManager *afm = (AudioFileManager *) inRefCon;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
571 return afm->Render(afm, ioData);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
572 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
573
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
574 static OSStatus
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
575 AudioFileManager_Render(AudioFileManager * afm, AudioBuffer * ioData)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
576 {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
577 OSStatus result = noErr;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
578
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
579 if (afm->mBufferOffset >= afm->mBufferSize) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
580 result = afm->GetFileData(afm, &afm->mTmpBuffer, &afm->mBufferSize);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
581 if (result) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
582 SDL_SetError("AudioConverterFillBuffer:%ld\n", result);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
583 afm->mParent->DoNotification(afm->mParent, result);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
584 return result;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
585 }
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
586
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
587 afm->mBufferOffset = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
588 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
589
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
590 if (ioData->mDataByteSize > afm->mBufferSize - afm->mBufferOffset)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
591 ioData->mDataByteSize = afm->mBufferSize - afm->mBufferOffset;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
592 ioData->mData = (char *) afm->mTmpBuffer + afm->mBufferOffset;
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
593 afm->mBufferOffset += ioData->mDataByteSize;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
594
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
595 afm->mByteCounter += ioData->mDataByteSize;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
596 afm->AfterRender(afm);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
597 return result;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
598 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
599
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
600
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
601 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
602 delete_AudioFileManager(AudioFileManager * afm)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
603 {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
604 if (afm != NULL) {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
605 if (afm->mFileBuffer) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
606 free(afm->mFileBuffer);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
607 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
608
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
609 SDL_free(afm);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
610 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
611 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
612
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
613
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
614 AudioFileManager *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
615 new_AudioFileManager(AudioFilePlayer * inParent,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
616 SInt16 inForkRefNum,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
617 SInt64 inFileLength, UInt32 inChunkSize)
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
618 {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
619 AudioFileManager *afm;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
620
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
621 if (sReaderThread == NULL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
622 sReaderThread = new_FileReaderThread();
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
623 if (sReaderThread == NULL)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
624 return NULL;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
625 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
626
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
627 afm = (AudioFileManager *) SDL_malloc(sizeof(AudioFileManager));
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
628 if (afm == NULL)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
629 return NULL;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
630 SDL_memset(afm, '\0', sizeof(*afm));
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
631
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
632 #define SET_AUDIOFILEMANAGER_METHOD(m) afm->m = AudioFileManager_##m
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
633 SET_AUDIOFILEMANAGER_METHOD(Disconnect);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
634 SET_AUDIOFILEMANAGER_METHOD(DoConnect);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
635 SET_AUDIOFILEMANAGER_METHOD(Read);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
636 SET_AUDIOFILEMANAGER_METHOD(GetFileBuffer);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
637 SET_AUDIOFILEMANAGER_METHOD(GetParent);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
638 SET_AUDIOFILEMANAGER_METHOD(SetPosition);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
639 SET_AUDIOFILEMANAGER_METHOD(GetByteCounter);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
640 SET_AUDIOFILEMANAGER_METHOD(SetEndOfFile);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
641 SET_AUDIOFILEMANAGER_METHOD(Render);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
642 SET_AUDIOFILEMANAGER_METHOD(GetFileData);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
643 SET_AUDIOFILEMANAGER_METHOD(AfterRender);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
644 SET_AUDIOFILEMANAGER_METHOD(FileInputProc);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
645 #undef SET_AUDIOFILEMANAGER_METHOD
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
646
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
647 afm->mParent = inParent;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
648 afm->mForkRefNum = inForkRefNum;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
649 afm->mBufferSize = inChunkSize;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
650 afm->mBufferOffset = inChunkSize;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
651 afm->mChunkSize = inChunkSize;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
652 afm->mFileLength = inFileLength;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
653 afm->mFileBuffer = (char *) SDL_malloc(afm->mChunkSize * 2);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
654 FSGetForkPosition(afm->mForkRefNum, &afm->mAudioDataOffset);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
655 assert(afm->mFileBuffer != NULL);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
656 return afm;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
657 }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
658
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
659 /* vi: set ts=4 sw=4 expandtab: */