1049e185fSopenharmony_ci/* 2049e185fSopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd. 3049e185fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4049e185fSopenharmony_ci * you may not use this file except in compliance with the License. 5049e185fSopenharmony_ci * You may obtain a copy of the License at 6049e185fSopenharmony_ci * 7049e185fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8049e185fSopenharmony_ci * 9049e185fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10049e185fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11049e185fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12049e185fSopenharmony_ci * See the License for the specific language governing permissions and 13049e185fSopenharmony_ci * limitations under the License. 14049e185fSopenharmony_ci */ 15049e185fSopenharmony_ci#ifndef SOUNDPOOL_H 16049e185fSopenharmony_ci#define SOUNDPOOL_H 17049e185fSopenharmony_ci 18049e185fSopenharmony_ci#include "isoundpool.h" 19049e185fSopenharmony_ci#include "audio_renderer.h" 20049e185fSopenharmony_ci#include "stream_id_manager.h" 21049e185fSopenharmony_ci#include "sound_id_manager.h" 22049e185fSopenharmony_ci#include "cpp/mutex.h" 23049e185fSopenharmony_ci#include "media_dfx.h" 24049e185fSopenharmony_ci 25049e185fSopenharmony_cinamespace OHOS { 26049e185fSopenharmony_cinamespace Media { 27049e185fSopenharmony_ciclass SoundPool : public ISoundPool { 28049e185fSopenharmony_cipublic: 29049e185fSopenharmony_ci SoundPool(); 30049e185fSopenharmony_ci ~SoundPool(); 31049e185fSopenharmony_ci static bool CheckInitParam(int maxStreams, AudioStandard::AudioRendererInfo audioRenderInfo); 32049e185fSopenharmony_ci 33049e185fSopenharmony_ci int32_t Init(int maxStreams, AudioStandard::AudioRendererInfo audioRenderInfo); 34049e185fSopenharmony_ci 35049e185fSopenharmony_ci int32_t Load(const std::string url) override; 36049e185fSopenharmony_ci 37049e185fSopenharmony_ci int32_t Load(int32_t fd, int64_t offset, int64_t length) override; 38049e185fSopenharmony_ci 39049e185fSopenharmony_ci int32_t Play(int32_t soundID, PlayParams playParameters) override; 40049e185fSopenharmony_ci 41049e185fSopenharmony_ci int32_t Stop(int32_t streamID) override; 42049e185fSopenharmony_ci 43049e185fSopenharmony_ci int32_t SetLoop(int32_t streamID, int32_t loop) override; 44049e185fSopenharmony_ci 45049e185fSopenharmony_ci int32_t SetPriority(int32_t streamID, int32_t priority) override; 46049e185fSopenharmony_ci 47049e185fSopenharmony_ci int32_t SetRate(int32_t streamID, AudioStandard::AudioRendererRate renderRate) override; 48049e185fSopenharmony_ci 49049e185fSopenharmony_ci int32_t SetVolume(int32_t streamID, float leftVolume, float rightVolume) override; 50049e185fSopenharmony_ci 51049e185fSopenharmony_ci int32_t Unload(int32_t soundID) override; 52049e185fSopenharmony_ci 53049e185fSopenharmony_ci int32_t Release() override; 54049e185fSopenharmony_ci 55049e185fSopenharmony_ci int32_t SetSoundPoolCallback(const std::shared_ptr<ISoundPoolCallback> &soundPoolCallback) override; 56049e185fSopenharmony_ci 57049e185fSopenharmony_ci int32_t SetSoundPoolFrameWriteCallback( 58049e185fSopenharmony_ci const std::shared_ptr<ISoundPoolFrameWriteCallback> &frameWriteCallback) override; 59049e185fSopenharmony_ci 60049e185fSopenharmony_ciprivate: 61049e185fSopenharmony_ci bool CheckVolumeVaild(float *leftVol, float *rightVol); 62049e185fSopenharmony_ci int32_t ReleaseInner(); 63049e185fSopenharmony_ci std::shared_ptr<SoundIDManager> soundIDManager_; 64049e185fSopenharmony_ci std::shared_ptr<StreamIDManager> streamIdManager_; 65049e185fSopenharmony_ci ffrt::mutex soundPoolLock_; 66049e185fSopenharmony_ci std::shared_ptr<ISoundPoolCallback> callback_ = nullptr; 67049e185fSopenharmony_ci std::shared_ptr<ISoundPoolFrameWriteCallback> frameWriteCallback_ = nullptr; 68049e185fSopenharmony_ci static constexpr int32_t MIN_STREAM_PRIORITY = 0; 69049e185fSopenharmony_ci}; 70049e185fSopenharmony_ci} // namespace Media 71049e185fSopenharmony_ci} // namespace OHOS 72049e185fSopenharmony_ci#endif // SOUNDPOOL_H 73