• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "audio_routing_manager_listener_proxy.h"
17 #include "audio_routing_manager.h"
18 #include "audio_system_manager.h"
19 #include "audio_log.h"
20 
21 namespace OHOS {
22 namespace AudioStandard {
AudioRoutingManagerListenerProxy(const sptr<IRemoteObject> & impl)23 AudioRoutingManagerListenerProxy::AudioRoutingManagerListenerProxy(const sptr<IRemoteObject> &impl)
24     : IRemoteProxy<IStandardAudioRoutingManagerListener>(impl)
25 {
26     AUDIO_DEBUG_LOG("Instances create");
27 }
28 
~AudioRoutingManagerListenerProxy()29 AudioRoutingManagerListenerProxy::~AudioRoutingManagerListenerProxy()
30 {
31     AUDIO_DEBUG_LOG("~AudioRoutingManagerListenerProxy: Instance destroy");
32 }
33 
OnMicStateUpdated(const MicStateChangeEvent & micStateChangeEvent)34 void AudioRoutingManagerListenerProxy::OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent)
35 {
36     MessageParcel data;
37     MessageParcel reply;
38     MessageOption option(MessageOption::TF_ASYNC);
39     if (!data.WriteInterfaceToken(GetDescriptor())) {
40         AUDIO_ERR_LOG("AudioPolicyManagerListenerProxy: WriteInterfaceToken failed");
41         return;
42     }
43 
44     data.WriteBool(micStateChangeEvent.mute);
45     int error = Remote()->SendRequest(ON_MIC_STATE_UPDATED, data, reply, option);
46     if (error != ERR_NONE) {
47         AUDIO_ERR_LOG("OnMicStateUpdated failed, error: %{public}d", error);
48     }
49 }
50 
51 
OnPreferredOutputDeviceUpdated(const std::vector<sptr<AudioDeviceDescriptor>> & desc)52 void AudioRoutingManagerListenerProxy::OnPreferredOutputDeviceUpdated(
53     const std::vector<sptr<AudioDeviceDescriptor>> &desc)
54 {
55     MessageParcel data;
56     MessageParcel reply;
57     MessageOption option(MessageOption::TF_ASYNC);
58     if (!data.WriteInterfaceToken(GetDescriptor())) {
59         AUDIO_ERR_LOG("AudioPolicyManagerListenerProxy: WriteInterfaceToken failed");
60         return;
61     }
62 
63     int32_t size = static_cast<int32_t>(desc.size());
64     data.WriteInt32(size);
65     for (int i = 0; i < size; i++) {
66         desc[i]->Marshalling(data);
67     }
68     int error = Remote()->SendRequest(ON_ACTIVE_OUTPUT_DEVICE_UPDATED, data, reply, option);
69     if (error != ERR_NONE) {
70         AUDIO_ERR_LOG("OnPreferredOutputDeviceUpdated failed, error: %{public}d", error);
71     }
72 }
73 
OnPreferredInputDeviceUpdated(const std::vector<sptr<AudioDeviceDescriptor>> & desc)74 void AudioRoutingManagerListenerProxy::OnPreferredInputDeviceUpdated(
75     const std::vector<sptr<AudioDeviceDescriptor>> &desc)
76 {
77     MessageParcel data;
78     MessageParcel reply;
79     MessageOption option(MessageOption::TF_ASYNC);
80     if (!data.WriteInterfaceToken(GetDescriptor())) {
81         AUDIO_ERR_LOG("OnPreferredInputDeviceUpdated: WriteInterfaceToken failed");
82         return;
83     }
84 
85     size_t size = desc.size();
86     data.WriteInt32(static_cast<int32_t>(size));
87     for (size_t i = 0; i < size; i++) {
88         desc[i]->Marshalling(data);
89     }
90     int error = Remote()->SendRequest(ON_ACTIVE_INPUT_DEVICE_UPDATED, data, reply, option);
91     if (error != ERR_NONE) {
92         AUDIO_ERR_LOG("OnPreferredInputDeviceUpdated failed, error: %{public}d", error);
93     }
94 }
95 
AudioRoutingManagerListenerCallback(const sptr<IStandardAudioRoutingManagerListener> & listener)96 AudioRoutingManagerListenerCallback::AudioRoutingManagerListenerCallback(
97     const sptr<IStandardAudioRoutingManagerListener> &listener) : listener_(listener)
98 {
99         AUDIO_DEBUG_LOG("AudioRoutingManagerListenerCallback: Instance create");
100 }
101 
~AudioRoutingManagerListenerCallback()102 AudioRoutingManagerListenerCallback::~AudioRoutingManagerListenerCallback()
103 {
104     AUDIO_DEBUG_LOG("AudioRoutingManagerListenerCallback: Instance destroy");
105 }
106 
OnMicStateUpdated(const MicStateChangeEvent & micStateChangeEvent)107 void AudioRoutingManagerListenerCallback::OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent)
108 {
109     if (listener_ != nullptr) {
110         listener_->OnMicStateUpdated(micStateChangeEvent);
111     }
112 }
113 } // namespace AudioStandard
114 } // namespace OHOS
115