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 
16 #ifndef AUDIO_PROCESS_IN_CLIENT_H
17 #define AUDIO_PROCESS_IN_CLIENT_H
18 
19 #include <map>
20 #include <memory>
21 
22 #include "audio_info.h"
23 
24 namespace OHOS {
25 namespace AudioStandard {
26 class AudioDataCallback {
27 public:
28     virtual ~AudioDataCallback() = default;
29 
30     /**
31      * Called when request handle data.
32      *
33      * @param length Indicates requested buffer length.
34      */
35     virtual void OnHandleData(size_t length) = 0;
36 };
37 
38 class ClientUnderrunCallBack {
39     virtual ~ClientUnderrunCallBack() = default;
40 
41     /**
42      * Callback function when underrun occurs.
43      *
44      * @param posInFrames Indicates the postion when client handle underrun in frames.
45      */
46     virtual void OnUnderrun(size_t posInFrames) = 0;
47 };
48 
49 class AudioProcessInClient {
50 public:
51     static constexpr int32_t PROCESS_VOLUME_MAX = 1 << 16; // 0 ~ 65536
52     static bool CheckIfSupport(const AudioProcessConfig &config);
53     static std::shared_ptr<AudioProcessInClient> Create(const AudioProcessConfig &config);
54 
55     virtual ~AudioProcessInClient() = default;
56 
57     virtual int32_t SaveDataCallback(const std::shared_ptr<AudioDataCallback> &dataCallback) = 0;
58 
59     virtual int32_t SaveUnderrunCallback(const std::shared_ptr<ClientUnderrunCallBack> &underrunCallback) = 0;
60 
61     virtual int32_t GetBufferDesc(BufferDesc &bufDesc) const = 0;
62 
63     virtual int32_t Enqueue(const BufferDesc &bufDesc) const = 0;
64 
65     virtual int32_t SetVolume(int32_t vol) = 0;
66 
67     virtual int32_t Start() = 0;
68 
69     virtual int32_t Pause(bool isFlush = false) = 0;
70 
71     virtual int32_t Resume() = 0;
72 
73     virtual int32_t Stop() = 0;
74 
75     virtual int32_t Release(bool isSwitchStream = false) = 0;
76 
77     // methods for support IAudioStream
78     virtual int32_t GetSessionID(uint32_t &sessionID) = 0;
79 
80     virtual bool GetAudioTime(uint32_t &framePos, int64_t &sec, int64_t &nanoSec) = 0;
81 
82     virtual int32_t GetBufferSize(size_t &bufferSize) = 0;
83 
84     virtual int32_t GetFrameCount(uint32_t &frameCount) = 0;
85 
86     virtual int32_t GetLatency(uint64_t &latency) = 0;
87 
88     virtual int32_t SetVolume(float vol) = 0;
89 
90     virtual float GetVolume() = 0;
91 
92     virtual int32_t SetDuckVolume(float vol) = 0;
93 
94     virtual uint32_t GetUnderflowCount() = 0;
95 
96     virtual uint32_t GetOverflowCount() = 0;
97 
98     virtual void SetUnderflowCount(uint32_t underflowCount) = 0;
99 
100     virtual void SetOverflowCount(uint32_t overflowCount) = 0;
101 
102     virtual int64_t GetFramesWritten() = 0;
103 
104     virtual int64_t GetFramesRead() = 0;
105 
106     virtual void SetApplicationCachePath(const std::string &cachePath) = 0;
107 
108     virtual void SetPreferredFrameSize(int32_t frameSize) = 0;
109 
110     virtual void UpdateLatencyTimestamp(std::string &timestamp, bool isRenderer) = 0;
111 
112     virtual int32_t SetSilentModeAndMixWithOthers(bool on) = 0;
113 };
114 } // namespace AudioStandard
115 } // namespace OHOS
116 #endif // AUDIO_PROCESS_IN_CLIENT_H
117