• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 IPC_STREAM_H
17 #define IPC_STREAM_H
18 
19 #include <memory>
20 
21 #include "ipc_types.h"
22 #include "iremote_broker.h"
23 #include "iremote_proxy.h"
24 #include "iremote_stub.h"
25 
26 #include "audio_process_config.h"
27 #include "i_stream_listener.h"
28 #include "oh_audio_buffer.h"
29 
30 namespace OHOS {
31 namespace AudioStandard {
32 class IpcStream : public IRemoteBroker {
33 public:
34     virtual ~IpcStream() = default;
35 
36     virtual int32_t RegisterStreamListener(sptr<IRemoteObject> object) = 0;
37 
38     virtual int32_t ResolveBuffer(std::shared_ptr<OHAudioBuffer> &buffer) = 0;
39 
40     virtual int32_t UpdatePosition() = 0;
41 
42     virtual int32_t GetAudioSessionID(uint32_t &sessionId) = 0;
43 
44     virtual int32_t Start() = 0;
45 
46     virtual int32_t Pause() = 0;
47 
48     virtual int32_t Stop() = 0;
49 
50     virtual int32_t Release() = 0;
51 
52     virtual int32_t Flush() = 0;
53 
54     virtual int32_t Drain(bool stopFlag = false) = 0;
55 
56     virtual int32_t UpdatePlaybackCaptureConfig(const AudioPlaybackCaptureConfig &config) = 0;
57 
58     virtual int32_t GetAudioTime(uint64_t &framePos, uint64_t &timestamp) = 0;
59 
60     virtual int32_t GetAudioPosition(uint64_t &framePos, uint64_t &timestamp, uint64_t &latency) = 0;
61 
62     virtual int32_t GetLatency(uint64_t &latency) = 0;
63 
64     virtual int32_t SetRate(int32_t rate) = 0; // SetRenderRate
65 
66     virtual int32_t GetRate(int32_t &rate) = 0; // SetRenderRate
67 
68     virtual int32_t SetLowPowerVolume(float volume) = 0; // renderer only
69 
70     virtual int32_t GetLowPowerVolume(float &volume) = 0; // renderer only
71 
72     virtual int32_t SetAudioEffectMode(int32_t effectMode) = 0; // renderer only
73 
74     virtual int32_t GetAudioEffectMode(int32_t &effectMode) = 0; // renderer only
75 
76     virtual int32_t SetPrivacyType(int32_t privacyType) = 0; // renderer only
77 
78     virtual int32_t GetPrivacyType(int32_t &privacyType) = 0; // renderer only
79 
80     virtual int32_t SetOffloadMode(int32_t state, bool isAppBack) = 0; // renderer only
81 
82     virtual int32_t UnsetOffloadMode() = 0; // renderer only
83 
84     virtual int32_t GetOffloadApproximatelyCacheTime(uint64_t &timestamp, uint64_t &paWriteIndex,
85         uint64_t &cacheTimeDsp, uint64_t &cacheTimePa) = 0; // renderer only
86 
87     virtual int32_t UpdateSpatializationState(bool spatializationEnabled, bool headTrackingEnabled) = 0; // rendererOnly
88 
89     virtual int32_t GetStreamManagerType() = 0;
90 
91     virtual int32_t SetSilentModeAndMixWithOthers(bool on) = 0;
92 
93     virtual int32_t SetClientVolume() = 0;
94 
95     virtual int32_t SetMute(bool isMute) = 0;
96 
97     virtual int32_t SetDuckFactor(float duckFactor) = 0;
98 
99     virtual int32_t RegisterThreadPriority(uint32_t tid, const std::string &bundleName) = 0;
100 
101     virtual int32_t SetDefaultOutputDevice(const DeviceType defaultOutputDevice) = 0;
102 
103     virtual int32_t SetSourceDuration(int64_t duration) = 0;
104 
105     // IPC code.
106     enum IpcStreamMsg : uint32_t {
107         ON_REGISTER_STREAM_LISTENER = 0,
108         ON_RESOLVE_BUFFER,
109         ON_UPDATE_POSITION,
110         ON_GET_AUDIO_SESSIONID,
111         ON_START,
112         ON_PAUSE,
113         ON_STOP,
114         ON_RELEASE,
115         ON_FLUSH,
116         ON_DRAIN,
117         ON_UPDATA_PLAYBACK_CAPTURER_CONFIG,
118         OH_GET_AUDIO_TIME,
119         OH_GET_AUDIO_POSITION,
120         ON_GET_LATENCY,
121         ON_SET_RATE,
122         ON_GET_RATE,
123         ON_SET_LOWPOWER_VOLUME,
124         ON_GET_LOWPOWER_VOLUME,
125         ON_SET_EFFECT_MODE,
126         ON_GET_EFFECT_MODE,
127         ON_SET_PRIVACY_TYPE,
128         ON_GET_PRIVACY_TYPE,
129         ON_SET_OFFLOAD_MODE,
130         ON_UNSET_OFFLOAD_MODE,
131         ON_GET_OFFLOAD_APPROXIMATELY_CACHE_TIME,
132         ON_UPDATE_SPATIALIZATION_STATE,
133         ON_GET_STREAM_MANAGER_TYPE,
134         ON_SET_SILENT_MODE_AND_MIX_WITH_OTHERS,
135         ON_SET_CLIENT_VOLUME,
136         ON_SET_MUTE,
137         ON_SET_DUCK_FACTOR,
138         ON_REGISTER_THREAD_PRIORITY,
139         ON_SET_DEFAULT_OUTPUT_DEVICE,
140         ON_SET_SOURCE_DURATION,
141         IPC_STREAM_MAX_MSG
142     };
143 
144     DECLARE_INTERFACE_DESCRIPTOR(u"IpcStream");
145 };
146 
147 class IpcStreamListener : public IRemoteBroker, public IStreamListener {
148 public:
149     virtual ~IpcStreamListener() = default;
150 
151     // IPC code.
152     enum IpcStreamListenerMsg : uint32_t {
153         ON_OPERATION_HANDLED = 0,
154         IPC_STREAM_LISTENER_MAX_MSG
155     };
156     DECLARE_INTERFACE_DESCRIPTOR(u"IpcStreamListener");
157 };
158 } // namespace AudioStandard
159 } // namespace OHOS
160 #endif // IPC_STREAM_H
161