• 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 
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 
27 class FastAudioStream;
28 
29 class AudioDataCallback {
30 public:
31     virtual ~AudioDataCallback() = default;
32 
33     /**
34      * Called when request handle data.
35      *
36      * @param length Indicates requested buffer length.
37      */
38     virtual void OnHandleData(size_t length) = 0;
39 };
40 
41 class ClientUnderrunCallBack {
42     virtual ~ClientUnderrunCallBack() = default;
43 
44     /**
45      * Callback function when underrun occurs.
46      *
47      * @param posInFrames Indicates the postion when client handle underrun in frames.
48      */
49     virtual void OnUnderrun(size_t posInFrames) = 0;
50 };
51 
52 class AudioProcessInClient {
53 public:
54     static constexpr int32_t PROCESS_VOLUME_MAX = 1 << 16; // 0 ~ 65536
55     static bool CheckIfSupport(const AudioProcessConfig &config);
56     static std::shared_ptr<AudioProcessInClient> Create(const AudioProcessConfig &config,
57         std::weak_ptr<FastAudioStream> weakStream);
58 
59     virtual ~AudioProcessInClient() = default;
60 
61     virtual int32_t SaveDataCallback(const std::shared_ptr<AudioDataCallback> &dataCallback) = 0;
62 
63     virtual int32_t SaveUnderrunCallback(const std::shared_ptr<ClientUnderrunCallBack> &underrunCallback) = 0;
64 
65     virtual int32_t GetBufferDesc(BufferDesc &bufDesc) const = 0;
66 
67     virtual int32_t Enqueue(const BufferDesc &bufDesc) = 0;
68 
69     virtual int32_t SetVolume(int32_t vol) = 0;
70 
71     virtual int32_t SetSourceDuration(int64_t duration) = 0;
72 
73     virtual int32_t Start() = 0;
74 
75     virtual int32_t Pause(bool isFlush = false) = 0;
76 
77     virtual int32_t Resume() = 0;
78 
79     virtual int32_t Stop(AudioProcessStage stage = AUDIO_PROC_STAGE_STOP) = 0;
80 
81     virtual int32_t Release(bool isSwitchStream = false) = 0;
82 
83     // methods for support IAudioStream
84     virtual int32_t GetSessionID(uint32_t &sessionID) = 0;
85 
86     virtual bool GetAudioTime(uint32_t &framePos, int64_t &sec, int64_t &nanoSec) = 0;
87 
88     virtual int32_t GetBufferSize(size_t &bufferSize) = 0;
89 
90     virtual int32_t GetFrameCount(uint32_t &frameCount) = 0;
91 
92     virtual int32_t GetLatency(uint64_t &latency) = 0;
93 
94     virtual int32_t SetVolume(float vol) = 0;
95 
96     virtual float GetVolume() = 0;
97 
98     virtual int32_t SetDuckVolume(float vol) = 0;
99 
100     virtual float GetDuckVolume() = 0;
101 
102     virtual int32_t SetMute(bool mute) = 0;
103 
104     virtual bool GetMute() = 0;
105 
106     virtual uint32_t GetUnderflowCount() = 0;
107 
108     virtual uint32_t GetOverflowCount() = 0;
109 
110     virtual void SetUnderflowCount(uint32_t underflowCount) = 0;
111 
112     virtual void SetOverflowCount(uint32_t overflowCount) = 0;
113 
114     virtual int64_t GetFramesWritten() = 0;
115 
116     virtual int64_t GetFramesRead() = 0;
117 
118     virtual void SetPreferredFrameSize(int32_t frameSize) = 0;
119 
120     virtual void UpdateLatencyTimestamp(std::string &timestamp, bool isRenderer) = 0;
121 
122     virtual int32_t SetDefaultOutputDevice(const DeviceType defaultOutputDevice, bool skipForce = false) = 0;
123 
124     virtual int32_t SetSilentModeAndMixWithOthers(bool on) = 0;
125 
126     virtual void GetRestoreInfo(RestoreInfo &restoreInfo) = 0;
127 
128     virtual void SetRestoreInfo(RestoreInfo &restoreInfo) = 0;
129 
130     virtual RestoreStatus CheckRestoreStatus() = 0;
131 
132     virtual RestoreStatus SetRestoreStatus(RestoreStatus restoreStatus) = 0;
133 
134     virtual void SaveAdjustStreamVolumeInfo(float volume, uint32_t sessionId, std::string adjustTime,
135         uint32_t code) = 0;
136 
137     virtual int32_t RegisterThreadPriority(pid_t tid, const std::string &bundleName, BoostTriggerMethod method) = 0;
138 
139     virtual bool GetStopFlag() const = 0;
140 
141     virtual void JoinCallbackLoop() = 0;
142 
143     virtual void SetAudioHapticsSyncId(const int32_t &audioHapticsSyncId) = 0;
144 };
145 } // namespace AudioStandard
146 } // namespace OHOS
147 #endif // AUDIO_PROCESS_IN_CLIENT_H
148