• 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 {
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 
AudioRendererChangeInfo(const AudioRendererChangeInfo & audioRendererChangeInfo)40     AudioRendererChangeInfo(const AudioRendererChangeInfo &audioRendererChangeInfo)
41     {
42         *this = audioRendererChangeInfo;
43     }
44     AudioRendererChangeInfo() = default;
45     ~AudioRendererChangeInfo() = default;
Marshalling(Parcel & parcel)46     bool Marshalling(Parcel &parcel) const
47     {
48         return parcel.WriteInt32(createrUID)
49             && parcel.WriteInt32(clientUID)
50             && parcel.WriteInt32(sessionId)
51             && parcel.WriteInt32(callerPid)
52             && parcel.WriteInt32(clientPid)
53             && parcel.WriteInt32(tokenId)
54             && parcel.WriteInt32(channelCount)
55             && parcel.WriteBool(backMute)
56             && parcel.WriteInt32(static_cast<int32_t>(rendererInfo.contentType))
57             && parcel.WriteInt32(static_cast<int32_t>(rendererInfo.streamUsage))
58             && parcel.WriteInt32(rendererInfo.rendererFlags)
59             && parcel.WriteInt32(rendererInfo.originalFlag)
60             && parcel.WriteInt32(rendererInfo.samplingRate)
61             && parcel.WriteInt32(rendererInfo.format)
62             && rendererInfo.Marshalling(parcel)
63             && parcel.WriteInt32(static_cast<int32_t>(rendererState))
64             && outputDeviceInfo.Marshalling(parcel)
65             && parcel.WriteInt32(appVolume);
66     }
Marshalling(Parcel & parcel,bool hasBTPermission,bool hasSystemPermission,int32_t apiVersion)67     bool Marshalling(Parcel &parcel, bool hasBTPermission, bool hasSystemPermission, int32_t apiVersion) const
68     {
69         return parcel.WriteInt32(createrUID)
70             && parcel.WriteInt32(hasSystemPermission ? clientUID : EMPTY_UID)
71             && parcel.WriteInt32(sessionId)
72             && parcel.WriteInt32(callerPid)
73             && parcel.WriteInt32(clientPid)
74             && parcel.WriteInt32(tokenId)
75             && parcel.WriteInt32(channelCount)
76             && parcel.WriteBool(backMute)
77             && parcel.WriteInt32(static_cast<int32_t>(rendererInfo.contentType))
78             && parcel.WriteInt32(static_cast<int32_t>(rendererInfo.streamUsage))
79             && parcel.WriteInt32(rendererInfo.rendererFlags)
80             && parcel.WriteInt32(rendererInfo.originalFlag)
81             && parcel.WriteInt32(rendererInfo.samplingRate)
82             && parcel.WriteInt32(rendererInfo.format)
83             && rendererInfo.Marshalling(parcel)
84             && parcel.WriteInt32(hasSystemPermission ? static_cast<int32_t>(rendererState) :
85                 RENDERER_INVALID)
86             && outputDeviceInfo.Marshalling(parcel, hasBTPermission, hasSystemPermission, apiVersion)
87             && parcel.WriteInt32(appVolume);
88     }
Unmarshalling(Parcel & parcel)89     void Unmarshalling(Parcel &parcel)
90     {
91         createrUID = parcel.ReadInt32();
92         clientUID = parcel.ReadInt32();
93         sessionId = parcel.ReadInt32();
94         callerPid = parcel.ReadInt32();
95         clientPid = parcel.ReadInt32();
96         tokenId = parcel.ReadInt32();
97         channelCount = parcel.ReadInt32();
98         backMute = parcel.ReadBool();
99 
100         rendererInfo.contentType = static_cast<ContentType>(parcel.ReadInt32());
101         rendererInfo.streamUsage = static_cast<StreamUsage>(parcel.ReadInt32());
102         rendererInfo.rendererFlags = parcel.ReadInt32();
103         rendererInfo.originalFlag = parcel.ReadInt32();
104         rendererInfo.samplingRate = static_cast<AudioSamplingRate>(parcel.ReadInt32());
105         rendererInfo.format = static_cast<AudioSampleFormat>(parcel.ReadInt32());
106         rendererInfo.Unmarshalling(parcel);
107 
108         rendererState = static_cast<RendererState>(parcel.ReadInt32());
109         outputDeviceInfo.Unmarshalling(parcel);
110         appVolume = parcel.ReadInt32();
111     }
112 };
113 
114 class AudioCapturerChangeInfo {
115 public:
116     int32_t createrUID;
117     int32_t clientUID;
118     int32_t sessionId;
119     int32_t callerPid;
120     int32_t clientPid;
121     AudioCapturerInfo capturerInfo;
122     CapturerState capturerState;
123     AudioDeviceDescriptor inputDeviceInfo = AudioDeviceDescriptor(AudioDeviceDescriptor::DEVICE_INFO);
124     bool muted;
125     uint32_t appTokenId;
126 
AudioCapturerChangeInfo(const AudioCapturerChangeInfo & audioCapturerChangeInfo)127     AudioCapturerChangeInfo(const AudioCapturerChangeInfo &audioCapturerChangeInfo)
128     {
129         *this = audioCapturerChangeInfo;
130     }
131     AudioCapturerChangeInfo() = default;
132     ~AudioCapturerChangeInfo() = default;
Marshalling(Parcel & parcel)133     bool Marshalling(Parcel &parcel) const
134     {
135         return parcel.WriteInt32(createrUID)
136             && parcel.WriteInt32(clientUID)
137             && parcel.WriteInt32(sessionId)
138             && parcel.WriteInt32(callerPid)
139             && parcel.WriteInt32(clientPid)
140             && capturerInfo.Marshalling(parcel)
141             && parcel.WriteInt32(static_cast<int32_t>(capturerState))
142             && inputDeviceInfo.Marshalling(parcel)
143             && parcel.WriteBool(muted)
144             && parcel.WriteUint32(appTokenId);
145     }
146 
Marshalling(Parcel & parcel,bool hasBTPermission,bool hasSystemPermission,int32_t apiVersion)147     bool Marshalling(Parcel &parcel, bool hasBTPermission, bool hasSystemPermission, int32_t apiVersion) const
148     {
149         return parcel.WriteInt32(createrUID)
150             && parcel.WriteInt32(hasSystemPermission ? clientUID : EMPTY_UID)
151             && parcel.WriteInt32(sessionId)
152             && parcel.WriteInt32(callerPid)
153             && parcel.WriteInt32(clientPid)
154             && capturerInfo.Marshalling(parcel)
155             && parcel.WriteInt32(hasSystemPermission ? static_cast<int32_t>(capturerState) : CAPTURER_INVALID)
156             && inputDeviceInfo.Marshalling(parcel, hasBTPermission, hasSystemPermission, apiVersion)
157             && parcel.WriteBool(muted)
158             && parcel.WriteUint32(appTokenId);
159     }
160 
Unmarshalling(Parcel & parcel)161     void Unmarshalling(Parcel &parcel)
162     {
163         createrUID = parcel.ReadInt32();
164         clientUID = parcel.ReadInt32();
165         sessionId = parcel.ReadInt32();
166         callerPid = parcel.ReadInt32();
167         clientPid = parcel.ReadInt32();
168         capturerInfo.Unmarshalling(parcel);
169         capturerState = static_cast<CapturerState>(parcel.ReadInt32());
170         inputDeviceInfo.Unmarshalling(parcel);
171         muted = parcel.ReadBool();
172         appTokenId = parcel.ReadUint32();
173     }
174 };
175 
176 struct AudioStreamChangeInfo {
177     AudioRendererChangeInfo audioRendererChangeInfo;
178     AudioCapturerChangeInfo audioCapturerChangeInfo;
179 };
180 } // namespace AudioStandard
181 } // namespace OHOS
182 #endif // AUDIO_STREAM_CHANGE_INFO_H