1 /*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "IAudioPolicyServiceClient"
18 #include <utils/Log.h>
19
20 #include <stdint.h>
21 #include <sys/types.h>
22
23 #include <binder/Parcel.h>
24
25 #include <media/IAudioPolicyServiceClient.h>
26 #include <media/AudioSystem.h>
27
28 namespace android {
29
30 enum {
31 PORT_LIST_UPDATE = IBinder::FIRST_CALL_TRANSACTION,
32 PATCH_LIST_UPDATE,
33 MIX_STATE_UPDATE,
34 RECORDING_CONFIGURATION_UPDATE
35 };
36
37 // ----------------------------------------------------------------------
readAudioConfigBaseFromParcel(const Parcel & data,audio_config_base_t * config)38 inline void readAudioConfigBaseFromParcel(const Parcel& data, audio_config_base_t *config) {
39 config->sample_rate = data.readUint32();
40 config->channel_mask = (audio_channel_mask_t) data.readInt32();
41 config->format = (audio_format_t) data.readInt32();
42 }
43
writeAudioConfigBaseToParcel(Parcel & data,const audio_config_base_t * config)44 inline void writeAudioConfigBaseToParcel(Parcel& data, const audio_config_base_t *config)
45 {
46 data.writeUint32(config->sample_rate);
47 data.writeInt32((int32_t) config->channel_mask);
48 data.writeInt32((int32_t) config->format);
49 }
50
readRecordClientInfoFromParcel(const Parcel & data,record_client_info_t * clientInfo)51 inline void readRecordClientInfoFromParcel(const Parcel& data, record_client_info_t *clientInfo) {
52 clientInfo->uid = (uid_t) data.readUint32();
53 clientInfo->session = (audio_session_t) data.readInt32();
54 clientInfo->source = (audio_source_t) data.readInt32();
55 }
56
writeRecordClientInfoFromParcel(Parcel & data,const record_client_info_t * clientInfo)57 inline void writeRecordClientInfoFromParcel(Parcel& data, const record_client_info_t *clientInfo) {
58 data.writeUint32((uint32_t) clientInfo->uid);
59 data.writeInt32((int32_t) clientInfo->session);
60 data.writeInt32((int32_t) clientInfo->source);
61 }
62
63 // ----------------------------------------------------------------------
64 class BpAudioPolicyServiceClient : public BpInterface<IAudioPolicyServiceClient>
65 {
66 public:
BpAudioPolicyServiceClient(const sp<IBinder> & impl)67 explicit BpAudioPolicyServiceClient(const sp<IBinder>& impl)
68 : BpInterface<IAudioPolicyServiceClient>(impl)
69 {
70 }
71
onAudioPortListUpdate()72 void onAudioPortListUpdate()
73 {
74 Parcel data, reply;
75 data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor());
76 remote()->transact(PORT_LIST_UPDATE, data, &reply, IBinder::FLAG_ONEWAY);
77 }
78
onAudioPatchListUpdate()79 void onAudioPatchListUpdate()
80 {
81 Parcel data, reply;
82 data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor());
83 remote()->transact(PATCH_LIST_UPDATE, data, &reply, IBinder::FLAG_ONEWAY);
84 }
85
onDynamicPolicyMixStateUpdate(String8 regId,int32_t state)86 void onDynamicPolicyMixStateUpdate(String8 regId, int32_t state)
87 {
88 Parcel data, reply;
89 data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor());
90 data.writeString8(regId);
91 data.writeInt32(state);
92 remote()->transact(MIX_STATE_UPDATE, data, &reply, IBinder::FLAG_ONEWAY);
93 }
94
onRecordingConfigurationUpdate(int event,const record_client_info_t * clientInfo,const audio_config_base_t * clientConfig,const audio_config_base_t * deviceConfig,audio_patch_handle_t patchHandle)95 void onRecordingConfigurationUpdate(int event, const record_client_info_t *clientInfo,
96 const audio_config_base_t *clientConfig,
97 const audio_config_base_t *deviceConfig, audio_patch_handle_t patchHandle) {
98 Parcel data, reply;
99 data.writeInterfaceToken(IAudioPolicyServiceClient::getInterfaceDescriptor());
100 data.writeInt32(event);
101 writeRecordClientInfoFromParcel(data, clientInfo);
102 writeAudioConfigBaseToParcel(data, clientConfig);
103 writeAudioConfigBaseToParcel(data, deviceConfig);
104 data.writeInt32(patchHandle);
105 remote()->transact(RECORDING_CONFIGURATION_UPDATE, data, &reply, IBinder::FLAG_ONEWAY);
106 }
107 };
108
109 IMPLEMENT_META_INTERFACE(AudioPolicyServiceClient, "android.media.IAudioPolicyServiceClient");
110
111 // ----------------------------------------------------------------------
112
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)113 status_t BnAudioPolicyServiceClient::onTransact(
114 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
115 {
116 switch (code) {
117 case PORT_LIST_UPDATE: {
118 CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply);
119 onAudioPortListUpdate();
120 return NO_ERROR;
121 } break;
122 case PATCH_LIST_UPDATE: {
123 CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply);
124 onAudioPatchListUpdate();
125 return NO_ERROR;
126 } break;
127 case MIX_STATE_UPDATE: {
128 CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply);
129 String8 regId = data.readString8();
130 int32_t state = data.readInt32();
131 onDynamicPolicyMixStateUpdate(regId, state);
132 return NO_ERROR;
133 } break;
134 case RECORDING_CONFIGURATION_UPDATE: {
135 CHECK_INTERFACE(IAudioPolicyServiceClient, data, reply);
136 int event = (int) data.readInt32();
137 record_client_info_t clientInfo;
138 audio_config_base_t clientConfig;
139 audio_config_base_t deviceConfig;
140 readRecordClientInfoFromParcel(data, &clientInfo);
141 readAudioConfigBaseFromParcel(data, &clientConfig);
142 readAudioConfigBaseFromParcel(data, &deviceConfig);
143 audio_patch_handle_t patchHandle = (audio_patch_handle_t) data.readInt32();
144 onRecordingConfigurationUpdate(event, &clientInfo, &clientConfig, &deviceConfig,
145 patchHandle);
146 return NO_ERROR;
147 } break;
148 default:
149 return BBinder::onTransact(code, data, reply, flags);
150 }
151 }
152
153 // ----------------------------------------------------------------------------
154
155 } // namespace android
156