• 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_STREAM_CHANGE_INFO_H
17 #define AUDIO_STREAM_CHANGE_INFO_H
18 
19 #include "audio_info.h"
20 #include "audio_device_descriptor.h"
21 
22 namespace OHOS {
23 namespace AudioStandard {
24 class AudioRendererChangeInfo : public Parcelable {
25 public:
26     int32_t createrUID;
27     int32_t clientUID;
28     int32_t sessionId;
29     int32_t callerPid;
30     int32_t clientPid;
31     int32_t tokenId;
32     int32_t channelCount;
33     AudioRendererInfo rendererInfo;
34     RendererState rendererState;
35     AudioDeviceDescriptor outputDeviceInfo = AudioDeviceDescriptor(AudioDeviceDescriptor::DEVICE_INFO);
36     bool prerunningState = false;
37     bool backMute = false;
38     int32_t appVolume;
39     mutable std::shared_ptr<AudioDeviceDescriptor::ClientInfo> clientInfo_ = nullptr;
40 
AudioRendererChangeInfo(const AudioRendererChangeInfo & audioRendererChangeInfo)41     AudioRendererChangeInfo(const AudioRendererChangeInfo &audioRendererChangeInfo)
42     {
43         *this = audioRendererChangeInfo;
44     }
45     AudioRendererChangeInfo() = default;
46     ~AudioRendererChangeInfo() = default;
47 
SetClientInfo(std::shared_ptr<AudioDeviceDescriptor::ClientInfo> clientInfo)48     void SetClientInfo(std::shared_ptr<AudioDeviceDescriptor::ClientInfo> clientInfo) const
49     {
50         clientInfo_ = clientInfo;
51         outputDeviceInfo.SetClientInfo(clientInfo);
52     }
53 
Marshalling(Parcel & parcel)54     bool Marshalling(Parcel &parcel) const override
55     {
56         int32_t clientUIDTemp = clientUID;
57         RendererState rendererStateTemp = rendererState;
58         if (clientInfo_ != nullptr) {
59             clientUIDTemp = clientInfo_->hasSystemPermission_ ? clientUID : EMPTY_UID;
60             rendererStateTemp = clientInfo_->hasSystemPermission_ ? rendererState : RENDERER_INVALID;
61             clientInfo_ = nullptr;
62         }
63         return parcel.WriteInt32(createrUID)
64             && parcel.WriteInt32(clientUIDTemp)
65             && parcel.WriteInt32(sessionId)
66             && parcel.WriteInt32(callerPid)
67             && parcel.WriteInt32(clientPid)
68             && parcel.WriteInt32(tokenId)
69             && parcel.WriteInt32(channelCount)
70             && parcel.WriteBool(backMute)
71             && parcel.WriteInt32(static_cast<int32_t>(rendererInfo.contentType))
72             && parcel.WriteInt32(static_cast<int32_t>(rendererInfo.streamUsage))
73             && parcel.WriteInt32(rendererInfo.rendererFlags)
74             && parcel.WriteInt32(rendererInfo.originalFlag)
75             && parcel.WriteInt32(rendererInfo.samplingRate)
76             && parcel.WriteInt32(rendererInfo.format)
77             && rendererInfo.Marshalling(parcel)
78             && parcel.WriteInt32(static_cast<int32_t>(rendererStateTemp))
79             && outputDeviceInfo.Marshalling(parcel)
80             && parcel.WriteInt32(appVolume);
81     }
82 
UnmarshallingSelf(Parcel & parcel)83     void UnmarshallingSelf(Parcel &parcel)
84     {
85         createrUID = parcel.ReadInt32();
86         clientUID = parcel.ReadInt32();
87         sessionId = parcel.ReadInt32();
88         callerPid = parcel.ReadInt32();
89         clientPid = parcel.ReadInt32();
90         tokenId = parcel.ReadInt32();
91         channelCount = parcel.ReadInt32();
92         backMute = parcel.ReadBool();
93 
94         rendererInfo.contentType = static_cast<ContentType>(parcel.ReadInt32());
95         rendererInfo.streamUsage = static_cast<StreamUsage>(parcel.ReadInt32());
96         rendererInfo.rendererFlags = parcel.ReadInt32();
97         rendererInfo.originalFlag = parcel.ReadInt32();
98         rendererInfo.samplingRate = static_cast<AudioSamplingRate>(parcel.ReadInt32());
99         rendererInfo.format = static_cast<AudioSampleFormat>(parcel.ReadInt32());
100         rendererInfo.UnmarshallingSelf(parcel);
101         rendererState = static_cast<RendererState>(parcel.ReadInt32());
102         outputDeviceInfo.UnmarshallingSelf(parcel);
103         appVolume = parcel.ReadInt32();
104     }
105 
Unmarshalling(Parcel & parcel)106     static AudioRendererChangeInfo *Unmarshalling(Parcel &parcel)
107     {
108         auto info = new(std::nothrow) AudioRendererChangeInfo();
109         if (info == nullptr) {
110             return nullptr;
111         }
112         info->UnmarshallingSelf(parcel);
113         return info;
114     }
115 };
116 
117 class AudioCapturerChangeInfo : public Parcelable {
118 public:
119     int32_t createrUID;
120     int32_t clientUID;
121     int32_t sessionId;
122     int32_t callerPid;
123     int32_t clientPid;
124     AudioCapturerInfo capturerInfo;
125     CapturerState capturerState;
126     AudioDeviceDescriptor inputDeviceInfo = AudioDeviceDescriptor(AudioDeviceDescriptor::DEVICE_INFO);
127     bool prerunningState = false;
128     bool muted;
129     uint32_t appTokenId;
130     mutable std::shared_ptr<AudioDeviceDescriptor::ClientInfo> clientInfo_ = nullptr;
131 
AudioCapturerChangeInfo(const AudioCapturerChangeInfo & audioCapturerChangeInfo)132     AudioCapturerChangeInfo(const AudioCapturerChangeInfo &audioCapturerChangeInfo)
133     {
134         *this = audioCapturerChangeInfo;
135     }
136     AudioCapturerChangeInfo() = default;
137     ~AudioCapturerChangeInfo() = default;
138 
SetClientInfo(std::shared_ptr<AudioDeviceDescriptor::ClientInfo> clientInfo)139     void SetClientInfo(std::shared_ptr<AudioDeviceDescriptor::ClientInfo> clientInfo) const
140     {
141         clientInfo_ = clientInfo;
142         inputDeviceInfo.SetClientInfo(clientInfo);
143     }
144 
Marshalling(Parcel & parcel)145     bool Marshalling(Parcel &parcel) const override
146     {
147         int32_t clientUIDTemp = clientUID;
148         CapturerState capturerStateTemp = capturerState;
149         if (clientInfo_ != nullptr) {
150             clientUIDTemp = clientInfo_->hasSystemPermission_ ? clientUID : EMPTY_UID;
151             capturerStateTemp = clientInfo_->hasSystemPermission_ ? capturerState : CAPTURER_INVALID;
152             clientInfo_ = nullptr;
153         }
154         return parcel.WriteInt32(createrUID)
155             && parcel.WriteInt32(clientUIDTemp)
156             && parcel.WriteInt32(sessionId)
157             && parcel.WriteInt32(callerPid)
158             && parcel.WriteInt32(clientPid)
159             && capturerInfo.Marshalling(parcel)
160             && parcel.WriteInt32(static_cast<int32_t>(capturerStateTemp))
161             && inputDeviceInfo.Marshalling(parcel)
162             && parcel.WriteBool(muted)
163             && parcel.WriteUint32(appTokenId);
164     }
165 
UnmarshallingSelf(Parcel & parcel)166     void UnmarshallingSelf(Parcel &parcel)
167     {
168         createrUID = parcel.ReadInt32();
169         clientUID = parcel.ReadInt32();
170         sessionId = parcel.ReadInt32();
171         callerPid = parcel.ReadInt32();
172         clientPid = parcel.ReadInt32();
173         capturerInfo.UnmarshallingSelf(parcel);
174         capturerState = static_cast<CapturerState>(parcel.ReadInt32());
175         inputDeviceInfo.UnmarshallingSelf(parcel);
176         muted = parcel.ReadBool();
177         appTokenId = parcel.ReadUint32();
178     }
179 
Unmarshalling(Parcel & parcel)180     static AudioCapturerChangeInfo *Unmarshalling(Parcel &parcel)
181     {
182         auto info = new(std::nothrow) AudioCapturerChangeInfo();
183         if (info == nullptr) {
184             return nullptr;
185         }
186         info->UnmarshallingSelf(parcel);
187         return info;
188     }
189 };
190 
191 struct AudioStreamChangeInfo : public Parcelable {
192     AudioRendererChangeInfo audioRendererChangeInfo;
193     AudioCapturerChangeInfo audioCapturerChangeInfo;
194 
MarshallingAudioStreamChangeInfo195     bool Marshalling(Parcel &parcel) const override
196     {
197         return audioRendererChangeInfo.Marshalling(parcel)
198             && audioCapturerChangeInfo.Marshalling(parcel);
199     }
200 
UnmarshallingAudioStreamChangeInfo201     static AudioStreamChangeInfo *Unmarshalling(Parcel &parcel)
202     {
203         auto info = new(std::nothrow) AudioStreamChangeInfo();
204         if (info == nullptr) {
205             return nullptr;
206         }
207         info->audioRendererChangeInfo.UnmarshallingSelf(parcel);
208         info->audioCapturerChangeInfo.UnmarshallingSelf(parcel);
209         return info;
210     }
211 };
212 } // namespace AudioStandard
213 } // namespace OHOS
214 #endif // AUDIO_STREAM_CHANGE_INFO_H