Mercurial > sdl-ios-xcode
annotate src/cdrom/macosx/AudioFileReaderThread.c @ 1780:7a36f01acf71
Fixed bug #49
Added support for non-blocking VT switching on the framebuffer console.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 08 May 2006 05:33:02 +0000 |
parents | dc6b59e925a2 |
children | 782fd950bd46 c121d94672cb a1b03ba2fcd0 |
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" |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 typedef struct S_FileReaderThread { |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
46 /*public:*/ |
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
|
47 SDLOSXCAGuard* (*GetGuard)(struct S_FileReaderThread *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
|
48 void (*AddReader)(struct S_FileReaderThread *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
|
49 void (*RemoveReader)(struct S_FileReaderThread *frt, AudioFileManager* 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
|
50 int (*TryNextRead)(struct S_FileReaderThread *frt, AudioFileManager* 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
|
51 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 int mThreadShouldDie; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
54 /*private:*/ |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
55 /*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
|
56 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 SDLOSXCAGuard *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
|
58 UInt32 mThreadPriority; |
71a2648acc75
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 int 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
|
61 FileData *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
|
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
|
63 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 void (*ReadNextChunk)(struct S_FileReaderThread *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
|
65 int (*StartFixedPriorityThread)(struct S_FileReaderThread *frt); |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
66 /*static*/ |
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
|
67 UInt32 (*GetThreadBasePriority)(pthread_t inThread); |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
68 /*static*/ |
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
|
69 void* (*DiskReaderEntry)(void *inRefCon); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 } 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
|
71 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
71a2648acc75
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 static SDLOSXCAGuard* FileReaderThread_GetGuard(FileReaderThread *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
|
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 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
|
76 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
78 /* returns 1 if succeeded */ |
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
|
79 static int FileReaderThread_TryNextRead (FileReaderThread *frt, AudioFileManager* 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
|
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 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
|
82 int succeeded = 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
|
83 if (frt->mGuard->Try(frt->mGuard, &didLock)) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 { |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
85 /*frt->mFileData.push_back (inItem);*/ |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
86 /* !!! 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
|
87 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
|
88 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
|
89 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1143
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 |
71a2648acc75
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 while (i != NULL) { prev = i; i = 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 frt->mGuard->Notify(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
|
101 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
|
102 |
71a2648acc75
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 (didLock) |
71a2648acc75
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->mGuard->Unlock(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
|
105 } |
71a2648acc75
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 |
71a2648acc75
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 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
|
108 } |
71a2648acc75
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 |
71a2648acc75
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 static void FileReaderThread_AddReader(FileReaderThread *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
|
111 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 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
|
113 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 frt->mThreadShouldDie = 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
|
115 frt->StartFixedPriorityThread (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
|
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 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
|
118 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
71a2648acc75
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 static void FileReaderThread_RemoveReader (FileReaderThread *frt, AudioFileManager* 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
|
121 { |
71a2648acc75
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 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
|
123 { |
71a2648acc75
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 int bNeedsRelease = frt->mGuard->Lock(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
|
125 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
126 /*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
|
127 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
|
128 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
|
129 while (i != 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
|
130 { |
71a2648acc75
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 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
|
132 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
|
133 prev = i; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
134 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
|
135 { |
71a2648acc75
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 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
|
137 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
|
138 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
|
139 prev->next = next; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1143
diff
changeset
|
140 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
|
141 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 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
|
143 } |
71a2648acc75
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 |
71a2648acc75
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 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
|
146 frt->mThreadShouldDie = 1; |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
147 frt->mGuard->Notify(frt->mGuard); /* wake up thread so it will quit */ |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
148 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
|
149 } |
71a2648acc75
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 if (bNeedsRelease) frt->mGuard->Unlock(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
|
152 } |
71a2648acc75
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 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 static int FileReaderThread_StartFixedPriorityThread (FileReaderThread *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
|
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 pthread_attr_t theThreadAttrs; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 pthread_t pThread; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 OSStatus result = pthread_attr_init(&theThreadAttrs); |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
161 if (result) 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
|
162 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 result = pthread_attr_setdetachstate(&theThreadAttrs, PTHREAD_CREATE_DETACHED); |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
164 if (result) return 0; /*THROW_RESULT("pthread_attr_setdetachstate - Thread attributes could not be detached.")*/ |
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 result = pthread_create (&pThread, &theThreadAttrs, frt->DiskReaderEntry, frt); |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
167 if (result) return 0; /*THROW_RESULT("pthread_create - Create and start 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
|
168 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 pthread_attr_destroy(&theThreadAttrs); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
171 /* 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
|
172 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
|
173 and we'll also make the thread fixed */ |
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
|
174 thread_extended_policy_data_t theFixedPolicy; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 thread_precedence_policy_data_t thePrecedencePolicy; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 SInt32 relativePriority; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
178 /* make thread fixed */ |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
179 theFixedPolicy.timeshare = 0; /* set to 1 for a non-fixed 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
|
180 result = thread_policy_set (pthread_mach_thread_np(pThread), THREAD_EXTENDED_POLICY, (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT); |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
181 if (result) return 0; /*THROW_RESULT("thread_policy - Couldn't set thread as fixed priority.")*/ |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
182 /* set priority */ |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
183 /* precedency policy's "importance" value is relative to spawning thread's 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
|
184 relativePriority = frt->mThreadPriority - frt->GetThreadBasePriority(pthread_self()); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 thePrecedencePolicy.importance = relativePriority; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 result = thread_policy_set (pthread_mach_thread_np(pThread), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&thePrecedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
188 if (result) 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
|
189 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 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
|
191 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 static UInt32 FileReaderThread_GetThreadBasePriority (pthread_t inThread) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 thread_basic_info_data_t threadInfo; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 policy_info_data_t thePolicyInfo; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 unsigned int count; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
198 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
199 /* 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
|
200 count = THREAD_BASIC_INFO_COUNT; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 thread_info (pthread_mach_thread_np (inThread), THREAD_BASIC_INFO, (integer_t*)&threadInfo, &count); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 switch (threadInfo.policy) { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 case POLICY_TIMESHARE: |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
205 count = POLICY_TIMESHARE_INFO_COUNT; |
71a2648acc75
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 thread_info(pthread_mach_thread_np (inThread), THREAD_SCHED_TIMESHARE_INFO, (integer_t*)&(thePolicyInfo.ts), &count); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 return thePolicyInfo.ts.base_priority; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 break; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 case POLICY_FIFO: |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 count = POLICY_FIFO_INFO_COUNT; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
212 thread_info(pthread_mach_thread_np (inThread), THREAD_SCHED_FIFO_INFO, (integer_t*)&(thePolicyInfo.fifo), &count); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 if (thePolicyInfo.fifo.depressed) { |
71a2648acc75
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 return thePolicyInfo.fifo.depress_priority; |
71a2648acc75
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 } 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
|
216 return thePolicyInfo.fifo.base_priority; |
71a2648acc75
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 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 break; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 |
71a2648acc75
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 case POLICY_RR: |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 count = POLICY_RR_INFO_COUNT; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
222 thread_info(pthread_mach_thread_np (inThread), THREAD_SCHED_RR_INFO, (integer_t*)&(thePolicyInfo.rr), &count); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
223 if (thePolicyInfo.rr.depressed) { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
224 return thePolicyInfo.rr.depress_priority; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
225 } 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
|
226 return thePolicyInfo.rr.base_priority; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 break; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 } |
71a2648acc75
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 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
|
232 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
233 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
234 static void *FileReaderThread_DiskReaderEntry (void *inRefCon) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
236 FileReaderThread *frt = (FileReaderThread *)inRefCon; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 frt->ReadNextChunk(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
|
238 #if DEBUG |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 printf ("finished with reading file\n"); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
240 #endif |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 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
|
243 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 static void FileReaderThread_ReadNextChunk (FileReaderThread *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
|
246 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 OSStatus 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
|
248 UInt32 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
|
249 AudioFileManager* theItem = 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
|
250 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 for (;;) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 { |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
253 { /* this is a scoped based lock */ |
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
|
254 int bNeedsRelease = frt->mGuard->Lock(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
|
255 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 if (frt->mThreadShouldDie) { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 frt->mGuard->Notify(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
|
258 if (bNeedsRelease) frt->mGuard->Unlock(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
|
259 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
|
260 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
262 /*if (frt->mFileData.empty())*/ |
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
|
263 if (frt->mFileData == 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
|
264 { |
71a2648acc75
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 frt->mGuard->Wait(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
|
266 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
268 /* kill 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
|
269 if (frt->mThreadShouldDie) { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
270 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 frt->mGuard->Notify(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
|
272 if (bNeedsRelease) frt->mGuard->Unlock(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
|
273 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
|
274 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
275 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
276 /*theItem = frt->mFileData.front();*/ |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
277 /*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
|
278 theItem = 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
|
279 if (frt->mFileData != 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
|
280 { |
71a2648acc75
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 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
|
282 theItem = frt->mFileData->obj; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1143
diff
changeset
|
283 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
|
284 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
|
285 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 if (bNeedsRelease) frt->mGuard->Unlock(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
|
288 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 |
71a2648acc75
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 ((theItem->mFileLength - theItem->mReadFilePosition) < theItem->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
|
291 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
|
292 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
|
293 dataChunkSize = theItem->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
|
294 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
295 /* 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
|
296 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
|
297 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
|
298 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
|
299 } |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
300 /* construct pointer */ |
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
|
301 char* writePtr = (char *) (theItem->GetFileBuffer(theItem) + |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
302 (theItem->mWriteToFirstBuffer ? 0 : theItem->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
|
303 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
304 /* read data */ |
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
|
305 result = theItem->Read(theItem, 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
|
306 if (result != noErr && 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
|
307 AudioFilePlayer *afp = (AudioFilePlayer *) theItem->GetParent(theItem); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
308 afp->DoNotification(afp, 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
|
309 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
|
310 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
311 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
312 if (dataChunkSize != theItem->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
|
313 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
314 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
|
315 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
316 /* can't exit yet.. we still have to pass the partial buffer back */ |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
317 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
|
318 } |
71a2648acc75
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 |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
320 theItem->mWriteToFirstBuffer = !theItem->mWriteToFirstBuffer; /* switch buffers */ |
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
|
321 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
322 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
|
323 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
|
324 else |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
325 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
|
326 } |
71a2648acc75
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 } |
71a2648acc75
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 |
71a2648acc75
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 void delete_FileReaderThread(FileReaderThread *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
|
330 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
331 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
|
332 { |
71a2648acc75
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 delete_SDLOSXCAGuard(frt->mGuard); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1143
diff
changeset
|
334 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
|
335 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
336 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
337 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
338 FileReaderThread *new_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
|
339 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1143
diff
changeset
|
340 FileReaderThread *frt = (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
|
341 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
|
342 return NULL; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1143
diff
changeset
|
343 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
|
344 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
345 frt->mGuard = new_SDLOSXCAGuard(); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
346 if (frt->mGuard == 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
|
347 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1143
diff
changeset
|
348 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
|
349 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
|
350 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
351 |
71a2648acc75
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 #define SET_FILEREADERTHREAD_METHOD(m) frt->m = FileReaderThread_##m |
71a2648acc75
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 SET_FILEREADERTHREAD_METHOD(GetGuard); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
354 SET_FILEREADERTHREAD_METHOD(AddReader); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
355 SET_FILEREADERTHREAD_METHOD(RemoveReader); |
71a2648acc75
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 SET_FILEREADERTHREAD_METHOD(TryNextRead); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
357 SET_FILEREADERTHREAD_METHOD(ReadNextChunk); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
358 SET_FILEREADERTHREAD_METHOD(StartFixedPriorityThread); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
359 SET_FILEREADERTHREAD_METHOD(GetThreadBasePriority); |
71a2648acc75
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 SET_FILEREADERTHREAD_METHOD(DiskReaderEntry); |
71a2648acc75
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 #undef SET_FILEREADERTHREAD_METHOD |
71a2648acc75
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
363 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
|
364 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
|
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
367 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
368 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
|
369 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
370 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
371 static int AudioFileManager_DoConnect (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
|
372 { |
71a2648acc75
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 if (!afm->mIsEngaged) |
71a2648acc75
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 { |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
375 OSStatus result; |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
376 |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
377 /*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
|
378 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
|
379 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
380 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
|
381 afm->mLockUnsuccessful = 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
|
382 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
383 UInt32 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
|
384 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
385 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
|
386 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
|
387 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
|
388 dataChunkSize = 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
|
389 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
390 result = afm->Read(afm, afm->mFileBuffer, &dataChunkSize); |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
391 if (result) 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
|
392 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
393 afm->mReadFilePosition += 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
|
394 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
395 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
|
396 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
|
397 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
398 sReaderThread->AddReader(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
|
399 |
71a2648acc75
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 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
|
401 } |
1487
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
402 /* |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
403 else |
dc6b59e925a2
Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
404 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
|
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 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
|
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
409 static void AudioFileManager_Disconnect (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
|
410 { |
71a2648acc75
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 if (afm->mIsEngaged) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
412 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
413 sReaderThread->RemoveReader (sReaderThread, 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
|
414 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
|
415 } |
71a2648acc75
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 } |
71a2648acc75
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 static OSStatus AudioFileManager_Read(AudioFileManager *afm, char *buffer, UInt32 *len) |
71a2648acc75
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 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
420 return FSReadFork (afm->mForkRefNum, |
71a2648acc75
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 fsFromStart, |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
422 afm->mReadFilePosition + afm->mAudioDataOffset, |
71a2648acc75
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 *len, |
71a2648acc75
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 buffer, |
71a2648acc75
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 len); |
71a2648acc75
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 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
427 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
428 static OSStatus AudioFileManager_GetFileData (AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
429 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
430 if (afm->mFinishedReadingData) |
71a2648acc75
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->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
|
433 *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
|
434 *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
|
435 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
|
436 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
437 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
438 if (afm->mReadFromFirstBuffer == afm->mWriteToFirstBuffer) { |
71a2648acc75
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 #if DEBUG |
71a2648acc75
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 printf ("* * * * * * * Can't keep up with reading file\n"); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
441 #endif |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
442 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
443 afm->mParent->DoNotification (afm->mParent, kAudioFilePlayErr_FilePlayUnderrun); |
71a2648acc75
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 *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
|
445 *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
|
446 } 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
|
447 *inOutDataSize = 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
|
448 *inOutData = afm->mReadFromFirstBuffer ? afm->mFileBuffer : (afm->mFileBuffer + 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
|
449 } |
71a2648acc75
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
451 afm->mLockUnsuccessful = !sReaderThread->TryNextRead (sReaderThread, 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
|
452 |
71a2648acc75
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->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
|
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 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
|
456 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
457 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
458 static void AudioFileManager_AfterRender (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
|
459 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
460 if (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
|
461 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
462 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
|
463 SDLOSXCAGuard *guard = sReaderThread->GetGuard(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
|
464 if (guard->Try(guard, &didLock)) { |
71a2648acc75
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 afm->mParent->DoNotification (afm->mParent, kAudioFilePlay_FileIsFinished); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
466 if (didLock) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
467 guard->Unlock(guard); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
468 } |
71a2648acc75
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 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
470 |
71a2648acc75
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 if (afm->mLockUnsuccessful) |
71a2648acc75
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 afm->mLockUnsuccessful = !sReaderThread->TryNextRead (sReaderThread, 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
|
473 } |
71a2648acc75
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 |
71a2648acc75
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 static void AudioFileManager_SetPosition (AudioFileManager *afm, SInt64 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
|
476 { |
71a2648acc75
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 (pos < 0 || 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
|
478 SDL_SetError ("AudioFileManager::SetPosition - position invalid: %d filelen=%d\n", |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
479 (unsigned int)pos, (unsigned int)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
|
480 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
|
481 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
482 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
483 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
|
484 } |
71a2648acc75
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 |
71a2648acc75
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 static void AudioFileManager_SetEndOfFile (AudioFileManager *afm, SInt64 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
|
487 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
488 if (pos <= 0 || 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
|
489 SDL_SetError ("AudioFileManager::SetEndOfFile - position beyond actual eof\n"); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
490 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
|
491 } |
71a2648acc75
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 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
|
494 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
495 |
71a2648acc75
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 static const char *AudioFileManager_GetFileBuffer(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
|
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 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
|
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
501 const AudioFilePlayer *AudioFileManager_GetParent(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
|
502 { |
71a2648acc75
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 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
|
504 } |
71a2648acc75
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
506 static int AudioFileManager_GetByteCounter(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
|
507 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
508 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
|
509 } |
71a2648acc75
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
511 |
71a2648acc75
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 static OSStatus AudioFileManager_FileInputProc (void *inRefCon, |
71a2648acc75
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 AudioUnitRenderActionFlags inActionFlags, |
71a2648acc75
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 const AudioTimeStamp *inTimeStamp, |
71a2648acc75
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 UInt32 inBusNumber, |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
516 AudioBuffer *ioData) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
517 { |
71a2648acc75
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 AudioFileManager* afm = (AudioFileManager*)inRefCon; |
71a2648acc75
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 return afm->Render(afm, ioData); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
520 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
521 |
71a2648acc75
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 static OSStatus AudioFileManager_Render (AudioFileManager *afm, AudioBuffer *ioData) |
71a2648acc75
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 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
524 OSStatus result = 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
|
525 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
526 if (afm->mBufferOffset >= afm->mBufferSize) { |
71a2648acc75
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 result = afm->GetFileData(afm, &afm->mTmpBuffer, &afm->mBufferSize); |
71a2648acc75
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 if (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
|
529 SDL_SetError ("AudioConverterFillBuffer:%ld\n", 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
|
530 afm->mParent->DoNotification(afm->mParent, 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
|
531 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
|
532 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
533 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
534 afm->mBufferOffset = 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
|
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
537 if (ioData->mDataByteSize > afm->mBufferSize - afm->mBufferOffset) |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
538 ioData->mDataByteSize = afm->mBufferSize - afm->mBufferOffset; |
71a2648acc75
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 ioData->mData = (char *)afm->mTmpBuffer + afm->mBufferOffset; |
71a2648acc75
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 afm->mBufferOffset += ioData->mDataByteSize; |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
541 |
71a2648acc75
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->mByteCounter += ioData->mDataByteSize; |
71a2648acc75
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 afm->AfterRender(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
|
544 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
|
545 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
546 |
71a2648acc75
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 void delete_AudioFileManager (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
|
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 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
|
551 if (afm->mFileBuffer) { |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
552 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
|
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 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1143
diff
changeset
|
555 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
|
556 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
557 } |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
558 |
71a2648acc75
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 AudioFileManager *new_AudioFileManager(AudioFilePlayer *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
|
561 SInt16 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
|
562 SInt64 inFileLength, |
71a2648acc75
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 UInt32 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
|
564 { |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
565 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
|
566 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
567 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
|
568 { |
71a2648acc75
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 sReaderThread = new_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
|
570 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
|
571 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
|
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 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1143
diff
changeset
|
574 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
|
575 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
|
576 return NULL; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1143
diff
changeset
|
577 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
|
578 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
579 #define SET_AUDIOFILEMANAGER_METHOD(m) afm->m = AudioFileManager_##m |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
580 SET_AUDIOFILEMANAGER_METHOD(Disconnect); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
581 SET_AUDIOFILEMANAGER_METHOD(DoConnect); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
582 SET_AUDIOFILEMANAGER_METHOD(Read); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
583 SET_AUDIOFILEMANAGER_METHOD(GetFileBuffer); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
584 SET_AUDIOFILEMANAGER_METHOD(GetParent); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
585 SET_AUDIOFILEMANAGER_METHOD(SetPosition); |
71a2648acc75
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 SET_AUDIOFILEMANAGER_METHOD(GetByteCounter); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
587 SET_AUDIOFILEMANAGER_METHOD(SetEndOfFile); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
588 SET_AUDIOFILEMANAGER_METHOD(Render); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
589 SET_AUDIOFILEMANAGER_METHOD(GetFileData); |
71a2648acc75
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 SET_AUDIOFILEMANAGER_METHOD(AfterRender); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
591 SET_AUDIOFILEMANAGER_METHOD(FileInputProc); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
592 #undef SET_AUDIOFILEMANAGER_METHOD |
71a2648acc75
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 |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
594 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
|
595 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
|
596 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
|
597 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
|
598 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
|
599 afm->mFileLength = inFileLength; |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
600 afm->mFileBuffer = (char*) SDL_malloc(afm->mChunkSize * 2); |
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
|
601 FSGetForkPosition(afm->mForkRefNum, &afm->mAudioDataOffset); |
71a2648acc75
Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
602 assert (afm->mFileBuffer != 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
|
603 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
|
604 } |
71a2648acc75
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 |