• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 namespace OHOS {
24 namespace Media {
25 class SoundPool : public ISoundPool {
26 public:
27     SoundPool();
28     ~SoundPool();
29     static bool CheckInitParam(int maxStreams, AudioStandard::AudioRendererInfo audioRenderInfo);
30 
31     int32_t Init(int maxStreams, AudioStandard::AudioRendererInfo audioRenderInfo);
32 
33     int32_t Load(const std::string url) override;
34 
35     int32_t Load(int32_t fd, int64_t offset, int64_t length) override;
36 
37     int32_t Play(int32_t soundID, PlayParams playParameters) override;
38 
39     int32_t Stop(int32_t streamID) override;
40 
41     int32_t SetLoop(int32_t streamID, int32_t loop) override;
42 
43     int32_t SetPriority(int32_t streamID, int32_t priority) override;
44 
45     int32_t SetRate(int32_t streamID, AudioStandard::AudioRendererRate renderRate) override;
46 
47     int32_t SetVolume(int32_t streamID, float leftVolume, float rightVolume) override;
48 
49     int32_t Unload(int32_t soundID) override;
50 
51     int32_t Release() override;
52 
53     int32_t SetSoundPoolCallback(const std::shared_ptr<ISoundPoolCallback> &soundPoolCallback) override;
54 
55     int32_t SetSoundPoolFrameWriteCallback(
56         const std::shared_ptr<ISoundPoolFrameWriteCallback> &frameWriteCallback) override;
57 
58 private:
59     bool CheckVolumeVaild(float *leftVol, float *rightVol);
60     int32_t ReleaseInner();
61     std::shared_ptr<SoundIDManager> soundIDManager_;
62     std::shared_ptr<StreamIDManager> streamIdManager_;
63     std::mutex soundPoolLock_;
64     std::shared_ptr<ISoundPoolCallback> callback_ = nullptr;
65     std::shared_ptr<ISoundPoolFrameWriteCallback> frameWriteCallback_ = nullptr;
66     static constexpr int32_t MIN_STREAM_PRIORITY = 0;
67 };
68 } // namespace Media
69 } // namespace OHOS
70 #endif // SOUNDPOOL_H
71