Andy Hung 77eb2bda0e SoundPool: Add clang-tidy and fix
Test: soundpool_stress
Test: SoundPoolAacTest
Test: SoundPoolHapticTest
Test: SoundPoolMidiTest
Test: SoundPoolOggTest
Bug: 157501605
Change-Id: I7bba857a8b44b6255d423086127da0e2df4ce1c4
2020-05-27 10:47:41 -07:00

53 lines
1.6 KiB
C++

/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "SoundPool.h"
#include <deque>
#include <mutex>
namespace android::soundpool {
/**
* SoundDecoder handles background decoding tasks.
*/
class SoundDecoder {
public:
SoundDecoder(SoundManager* soundManager, size_t threads);
~SoundDecoder();
void loadSound(int32_t soundID) NO_THREAD_SAFETY_ANALYSIS; // uses unique_lock
void quit();
private:
// The decode thread function.
void run(int32_t id) NO_THREAD_SAFETY_ANALYSIS; // uses unique_lock
SoundManager* const mSoundManager; // set in constructor, has own lock
std::unique_ptr<ThreadPool> mThreadPool; // set in constructor, has own lock
std::mutex mLock;
std::condition_variable mQueueSpaceAvailable GUARDED_BY(mLock);
std::condition_variable mQueueDataAvailable GUARDED_BY(mLock);
std::deque<int32_t> mSoundIDs GUARDED_BY(mLock);
bool mQuit GUARDED_BY(mLock) = false;
};
} // end namespace android::soundpool