The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef SOUNDPOOLTHREAD_H_ |
| 18 | #define SOUNDPOOLTHREAD_H_ |
| 19 | |
| 20 | #include <utils/threads.h> |
| 21 | #include <utils/Vector.h> |
| 22 | #include <media/AudioTrack.h> |
| 23 | |
| 24 | #include "SoundPool.h" |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | class SoundPoolMsg { |
| 29 | public: |
Dave Sparks | f6e43bf | 2009-12-08 08:10:42 -0800 | [diff] [blame] | 30 | enum MessageType { INVALID, KILL, LOAD_SAMPLE }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | SoundPoolMsg() : mMessageType(INVALID), mData(0) {} |
| 32 | SoundPoolMsg(MessageType MessageType, int data) : |
| 33 | mMessageType(MessageType), mData(data) {} |
Eric Laurent | a60e212 | 2010-12-28 16:49:07 -0800 | [diff] [blame] | 34 | uint16_t mMessageType; |
| 35 | uint16_t mData; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | /* |
| 39 | * This class handles background requests from the SoundPool |
| 40 | */ |
| 41 | class SoundPoolThread { |
| 42 | public: |
| 43 | SoundPoolThread(SoundPool* SoundPool); |
| 44 | ~SoundPoolThread(); |
| 45 | void loadSample(int sampleID); |
Dave Sparks | f6e43bf | 2009-12-08 08:10:42 -0800 | [diff] [blame] | 46 | void quit(); |
| 47 | void write(SoundPoolMsg msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | static const size_t maxMessages = 5; |
| 51 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | static int beginThread(void* arg); |
| 53 | int run(); |
| 54 | void doLoadSample(int sampleID); |
Dave Sparks | f6e43bf | 2009-12-08 08:10:42 -0800 | [diff] [blame] | 55 | const SoundPoolMsg read(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | |
Dave Sparks | f6e43bf | 2009-12-08 08:10:42 -0800 | [diff] [blame] | 57 | Mutex mLock; |
| 58 | Condition mCondition; |
| 59 | Vector<SoundPoolMsg> mMsgQueue; |
| 60 | SoundPool* mSoundPool; |
| 61 | bool mRunning; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | } // end namespace android |
| 65 | |
| 66 | #endif /*SOUNDPOOLTHREAD_H_*/ |