• 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 #include "policy_provider_proxy.h"
17 #include "audio_log.h"
18 #include "audio_errors.h"
19 
20 namespace OHOS {
21 namespace AudioStandard {
PolicyProviderProxy(const sptr<IRemoteObject> & impl)22 PolicyProviderProxy::PolicyProviderProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IPolicyProviderIpc>(impl)
23 {
24     AUDIO_INFO_LOG("PolicyProviderProxy()");
25 }
26 
~PolicyProviderProxy()27 PolicyProviderProxy::~PolicyProviderProxy()
28 {
29     AUDIO_INFO_LOG("~PolicyProviderProxy()");
30 }
31 
GetProcessDeviceInfo(const AudioProcessConfig & config,DeviceInfo & deviceInfo)32 int32_t PolicyProviderProxy::GetProcessDeviceInfo(const AudioProcessConfig &config, DeviceInfo &deviceInfo)
33 {
34     MessageParcel data;
35     MessageParcel reply;
36     MessageOption option;
37 
38     CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "Write descriptor failed!");
39 
40     ProcessConfig::WriteConfigToParcel(config, data);
41     int ret = Remote()->SendRequest(IPolicyProviderMsg::GET_DEVICE_INFO, data, reply, option);
42     CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, ERR_OPERATION_FAILED, "GetProcessDeviceInfo failed, error: %{public}d",
43         ret);
44 
45     deviceInfo.deviceType = static_cast<DeviceType>(reply.ReadInt32());
46     deviceInfo.deviceRole = static_cast<DeviceRole>(reply.ReadInt32());
47     deviceInfo.deviceId = reply.ReadInt32();
48     deviceInfo.channelMasks = reply.ReadInt32();
49     deviceInfo.deviceName = reply.ReadString();
50     deviceInfo.macAddress = reply.ReadString();
51 
52     // AudioStreamInfo
53     deviceInfo.audioStreamInfo.samplingRate = static_cast<AudioSamplingRate>(reply.ReadInt32());
54     deviceInfo.audioStreamInfo.encoding = static_cast<AudioEncodingType>(reply.ReadInt32());
55     deviceInfo.audioStreamInfo.format = static_cast<AudioSampleFormat>(reply.ReadInt32());
56     deviceInfo.audioStreamInfo.channels = static_cast<AudioChannel>(reply.ReadInt32());
57 
58     deviceInfo.networkId = reply.ReadString();
59     deviceInfo.displayName = reply.ReadString();
60     deviceInfo.interruptGroupId = reply.ReadInt32();
61     deviceInfo.volumeGroupId = reply.ReadInt32();
62     deviceInfo.isLowLatencyDevice = reply.ReadBool();
63 
64     return SUCCESS;
65 }
66 
InitSharedVolume(std::shared_ptr<AudioSharedMemory> & buffer)67 int32_t PolicyProviderProxy::InitSharedVolume(std::shared_ptr<AudioSharedMemory> &buffer)
68 {
69     MessageParcel data;
70     MessageParcel reply;
71     MessageOption option;
72 
73     CHECK_AND_RETURN_RET_LOG(data.WriteInterfaceToken(GetDescriptor()), ERROR, "Write descriptor failed!");
74 
75     int ret = Remote()->SendRequest(IPolicyProviderMsg::INIT_VOLUME_MAP, data, reply, option);
76     CHECK_AND_RETURN_RET_LOG(ret == AUDIO_OK, ERR_OPERATION_FAILED, "InitSharedVolume failed, error: %{public}d", ret);
77     buffer = AudioSharedMemory::ReadFromParcel(reply);
78     CHECK_AND_RETURN_RET_LOG(buffer != nullptr, ERR_OPERATION_FAILED, "ReadFromParcel failed");
79     return SUCCESS;
80 }
81 } // namespace AudioStandard
82 } // namespace OHOS
83