1 /*
2  * Copyright (c) 2024 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 
16 #ifndef ST_OFFLINE_AUDIO_EFFECT_MANAGER_H
17 #define ST_OFFLINE_AUDIO_EFFECT_MANAGER_H
18 
19 #include <vector>
20 
21 #include "audio_info.h"
22 #include "offline_stream_in_client.h"
23 
24 namespace OHOS {
25 namespace AudioStandard {
26 class OfflineAudioEffectChain {
27 public:
28     /**
29      * @brief Configure the audio stream information
30      *
31      * @param inInfo Input audio stream information
32      * @param outInfo Output audio stream information
33      * @return The result of the config, 0 for success, other for error code
34      * @since 15
35      */
36     virtual int32_t Configure(const AudioStreamInfo &inInfo, const AudioStreamInfo &outInfo) = 0;
37 
38     /**
39      * @brief Prepare the offline audio effect chain
40      *
41      * @return The result of the preparation, 0 for success, other for error code
42      * @since 15
43      */
44     virtual int32_t Prepare() = 0;
45 
46     /**
47      * @brief Get the size of the audio effect buffer
48      *
49      * @param inBufferSize Size of the input buffer
50      * @param outBufferSize Size of the output buffer
51      * @return The result of the retrieval, 0 for success, other for error code
52      * @since 15
53      */
54     virtual int32_t GetEffectBufferSize(uint32_t &inBufferSize, uint32_t &outBufferSize) = 0;
55 
56     /**
57      * @brief Process the audio data
58      *
59      * @param inBuffer Input audio data buffer
60      * @param inSize Size of the input audio data
61      * @param outBuffer Output audio data buffer
62      * @param outSize Size of the output audio data
63      * @return The result of processing, 0 for success, other for error code
64      * @since 15
65      */
66     virtual int32_t Process(uint8_t *inBuffer, int32_t inSize, uint8_t *outBuffer, int32_t outSize) = 0;
67 
68     /**
69      * @brief Release the resources of the audio effect chain
70      *
71      * @since 15
72      */
73     virtual void Release() = 0;
74 
75     virtual ~OfflineAudioEffectChain() = default;
76 };
77 
78 class OfflineAudioEffectManager {
79 public:
80     /**
81      * @brief Get all offline audio effect chain names
82      *
83      * @return Returns all offline audio effect chains avalible.
84      * @since 15
85      */
86     std::vector<std::string> GetOfflineAudioEffectChains();
87 
88     /**
89      * @brief Creata an offline audio effect chain
90      *
91      * @return Returns offload audio effect chain with chainName provided, nullptr if failed
92      * @since 15
93      */
94     std::unique_ptr<OfflineAudioEffectChain> CreateOfflineAudioEffectChain(const std::string &chainName);
95 };
96 } // namespace AudioStandard
97 } // namespace OHOS
98 #endif // ST_AUDIO_SPATIALIZATION_MANAGER_H
99