• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 #pragma once
18 
19 #include "SoundPool.h"
20 
21 #include <deque>
22 #include <mutex>
23 
24 namespace android::soundpool {
25 
26 /**
27  * SoundDecoder handles background decoding tasks.
28  */
29 class SoundDecoder {
30 public:
31     SoundDecoder(SoundManager* soundManager, size_t threads, int32_t threadPriority);
32     ~SoundDecoder();
33     void loadSound(int32_t soundID) NO_THREAD_SAFETY_ANALYSIS; // uses unique_lock
34     void quit();
35 
36 private:
37     // The decode thread function.
38     void run(int32_t id) NO_THREAD_SAFETY_ANALYSIS; // uses unique_lock
39 
40     SoundManager* const     mSoundManager;      // set in constructor, has own lock
41     std::unique_ptr<ThreadPool> mThreadPool;    // set in constructor, has own lock
42 
43     std::mutex              mLock;
44     std::condition_variable mQueueSpaceAvailable GUARDED_BY(mLock);
45     std::condition_variable mQueueDataAvailable GUARDED_BY(mLock);
46 
47     std::deque<int32_t>     mSoundIDs GUARDED_BY(mLock);
48     bool                    mQuit GUARDED_BY(mLock) = false;
49 };
50 
51 } // end namespace android::soundpool
52 
53