• 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 #include "parallel_stream_manager.h"
23 #include "media_utils.h"
24 #include "cpp/mutex.h"
25 #include "media_dfx.h"
26 
27 namespace OHOS {
28 namespace Media {
29 class SoundPool : public ISoundPool {
30 public:
31     SoundPool();
32     ~SoundPool();
33     static bool CheckInitParam(int maxStreams, AudioStandard::AudioRendererInfo audioRenderInfo);
34 
35     int32_t Init(int maxStreams, AudioStandard::AudioRendererInfo audioRenderInfo);
36 
37     int32_t InitParallel(int maxStreams, AudioStandard::AudioRendererInfo audioRenderInfo);
38 
39     int32_t Load(const std::string url) override;
40 
41     int32_t Load(int32_t fd, int64_t offset, int64_t length) override;
42 
43     int32_t Play(int32_t soundID, PlayParams playParameters) override;
44 
45     int32_t Stop(int32_t streamID) override;
46 
47     int32_t SetLoop(int32_t streamID, int32_t loop) override;
48 
49     int32_t SetPriority(int32_t streamID, int32_t priority) override;
50 
51     int32_t SetRate(int32_t streamID, AudioStandard::AudioRendererRate renderRate) override;
52 
53     int32_t SetVolume(int32_t streamID, float leftVolume, float rightVolume) override;
54 
55     int32_t Unload(int32_t soundID) override;
56 
57     int32_t Release() override;
58 
59     int32_t SetSoundPoolCallback(const std::shared_ptr<ISoundPoolCallback> &soundPoolCallback) override;
60 
61     int32_t SetSoundPoolFrameWriteCallback(
62         const std::shared_ptr<ISoundPoolFrameWriteCallback> &frameWriteCallback) override;
63 
64     void SetApiVersion(int32_t apiVersion);
65 
66 private:
67     bool CheckVolumeVaild(float *leftVol, float *rightVol);
68     static bool CheckRendererFlagsValid(AudioStandard::AudioRendererInfo audioRenderInfo);
69     int32_t ReleaseInner();
70     std::shared_ptr<SoundIDManager> soundIDManager_;
71     std::shared_ptr<StreamIDManager> streamIdManager_;
72     std::shared_ptr<ParallelStreamManager> parallelStreamManager_;
73     ffrt::mutex soundPoolLock_;
74     std::shared_ptr<ISoundPoolCallback> callback_ = nullptr;
75     std::shared_ptr<ISoundPoolFrameWriteCallback> frameWriteCallback_ = nullptr;
76     static constexpr int32_t MIN_STREAM_PRIORITY = 0;
77     int32_t apiVersion_ = 0;
78     bool parallelStreamFlag_ = false;
79     bool isReleased_ = false;
80 };
81 } // namespace Media
82 } // namespace OHOS
83 #endif // SOUNDPOOL_H
84