1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef SOUNDPOOL_H 16 #define SOUNDPOOL_H 17 18 #include "isoundpool.h" 19 #include "audio_renderer.h" 20 #include "stream_id_manager.h" 21 #include "sound_id_manager.h" 22 #include "media_utils.h" 23 #include "cpp/mutex.h" 24 #include "media_dfx.h" 25 26 namespace OHOS { 27 namespace Media { 28 class SoundPool : public ISoundPool { 29 public: 30 SoundPool(); 31 ~SoundPool(); 32 static bool CheckInitParam(int maxStreams, AudioStandard::AudioRendererInfo audioRenderInfo); 33 34 int32_t Init(int maxStreams, AudioStandard::AudioRendererInfo audioRenderInfo); 35 36 int32_t Load(const std::string url) override; 37 38 int32_t Load(int32_t fd, int64_t offset, int64_t length) override; 39 40 int32_t Play(int32_t soundID, PlayParams playParameters) override; 41 42 int32_t Stop(int32_t streamID) override; 43 44 int32_t SetLoop(int32_t streamID, int32_t loop) override; 45 46 int32_t SetPriority(int32_t streamID, int32_t priority) override; 47 48 int32_t SetRate(int32_t streamID, AudioStandard::AudioRendererRate renderRate) override; 49 50 int32_t SetVolume(int32_t streamID, float leftVolume, float rightVolume) override; 51 52 int32_t Unload(int32_t soundID) override; 53 54 int32_t Release() override; 55 56 int32_t SetSoundPoolCallback(const std::shared_ptr<ISoundPoolCallback> &soundPoolCallback) override; 57 58 int32_t SetSoundPoolFrameWriteCallback( 59 const std::shared_ptr<ISoundPoolFrameWriteCallback> &frameWriteCallback) override; 60 61 void SetApiVersion(int32_t apiVersion); 62 63 private: 64 bool CheckVolumeVaild(float *leftVol, float *rightVol); 65 int32_t ReleaseInner(); 66 std::shared_ptr<SoundIDManager> soundIDManager_; 67 std::shared_ptr<StreamIDManager> streamIdManager_; 68 ffrt::mutex soundPoolLock_; 69 std::shared_ptr<ISoundPoolCallback> callback_ = nullptr; 70 std::shared_ptr<ISoundPoolFrameWriteCallback> frameWriteCallback_ = nullptr; 71 static constexpr int32_t MIN_STREAM_PRIORITY = 0; 72 int32_t apiVersion_ = 0; 73 }; 74 } // namespace Media 75 } // namespace OHOS 76 #endif // SOUNDPOOL_H 77