IAudioPolicyService.cpp revision 57dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfc
1c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent/*
2c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent**
3c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent** Copyright 2009, The Android Open Source Project
4c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent**
5c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent** Licensed under the Apache License, Version 2.0 (the "License");
6c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent** you may not use this file except in compliance with the License.
7c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent** You may obtain a copy of the License at
8c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent**
9c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent**     http://www.apache.org/licenses/LICENSE-2.0
10c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent**
11c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent** Unless required by applicable law or agreed to in writing, software
12c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent** distributed under the License is distributed on an "AS IS" BASIS,
13c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent** See the License for the specific language governing permissions and
15c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent** limitations under the License.
16c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent*/
17c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
18c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent#define LOG_TAG "IAudioPolicyService"
19c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent#include <utils/Log.h>
20c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
21c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent#include <stdint.h>
22c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent#include <sys/types.h>
23c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
24c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent#include <binder/Parcel.h>
25c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
26c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent#include <media/IAudioPolicyService.h>
27c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
2864760240f931714858a59c1579f07264d7182ba2Dima Zavin#include <system/audio.h>
29fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin
30c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentnamespace android {
31c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
32c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentenum {
33c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    SET_DEVICE_CONNECTION_STATE = IBinder::FIRST_CALL_TRANSACTION,
34c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    GET_DEVICE_CONNECTION_STATE,
35c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    SET_PHONE_STATE,
36c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    SET_RINGER_MODE,
37c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    SET_FORCE_USE,
38c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    GET_FORCE_USE,
39c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    GET_OUTPUT,
40c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    START_OUTPUT,
41c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    STOP_OUTPUT,
42c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    RELEASE_OUTPUT,
43c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    GET_INPUT,
44c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    START_INPUT,
45c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    STOP_INPUT,
46c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    RELEASE_INPUT,
47c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    INIT_STREAM_VOLUME,
48c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    SET_STREAM_VOLUME,
49de070137f11d346fba77605bd76a44c040a618fcEric Laurent    GET_STREAM_VOLUME,
50de070137f11d346fba77605bd76a44c040a618fcEric Laurent    GET_STRATEGY_FOR_STREAM,
51de070137f11d346fba77605bd76a44c040a618fcEric Laurent    GET_OUTPUT_FOR_EFFECT,
52de070137f11d346fba77605bd76a44c040a618fcEric Laurent    REGISTER_EFFECT,
53eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent    UNREGISTER_EFFECT,
546b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten    IS_STREAM_ACTIVE,
556b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten    GET_DEVICES_FOR_STREAM,
5657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    QUERY_DEFAULT_PRE_PROCESSING
57c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent};
58c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
59c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentclass BpAudioPolicyService : public BpInterface<IAudioPolicyService>
60c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent{
61c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentpublic:
62c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    BpAudioPolicyService(const sp<IBinder>& impl)
63c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        : BpInterface<IAudioPolicyService>(impl)
64c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
65c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
66c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
67c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual status_t setDeviceConnectionState(
68fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                    audio_devices_t device,
69fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                    audio_policy_dev_state_t state,
70c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    const char *device_address)
71c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
72c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
73c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
74c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(device));
75c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(state));
76c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeCString(device_address);
77c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
78c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
79c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
80c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
81fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual audio_policy_dev_state_t getDeviceConnectionState(
82fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                    audio_devices_t device,
83c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    const char *device_address)
84c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
85c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
86c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
87c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(device));
88c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeCString(device_address);
89c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
90fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        return static_cast <audio_policy_dev_state_t>(reply.readInt32());
91c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
92c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
93c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual status_t setPhoneState(int state)
94c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
95c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
96c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
97c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(state);
98c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(SET_PHONE_STATE, data, &reply);
99c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
100c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
101c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
102c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual status_t setRingerMode(uint32_t mode, uint32_t mask)
103c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
104c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
105c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
106c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(mode);
107c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(mask);
108c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(SET_RINGER_MODE, data, &reply);
109c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
110c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
111c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
112fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
113c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
114c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
115c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
116c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(usage));
117c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(config));
118c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(SET_FORCE_USE, data, &reply);
119c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
120c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
121c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
122fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
123c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
124c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
125c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
126c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(usage));
127c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(GET_FORCE_USE, data, &reply);
128fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
129c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
130c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
131c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual audio_io_handle_t getOutput(
132fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                        audio_stream_type_t stream,
133c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                        uint32_t samplingRate,
134c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                        uint32_t format,
135c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                        uint32_t channels,
136fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                        audio_policy_output_flags_t flags)
137c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
138c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
139c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
140c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(stream));
141c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(samplingRate);
142c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(format));
143c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(channels);
144c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(flags));
145c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(GET_OUTPUT, data, &reply);
146fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        return static_cast <audio_io_handle_t> (reply.readInt32());
147c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
148c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
149de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual status_t startOutput(audio_io_handle_t output,
150fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                 audio_stream_type_t stream,
151de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                 int session)
152c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
153c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
154c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
155fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        data.writeInt32(output);
156c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(stream);
157de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(session);
158c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(START_OUTPUT, data, &reply);
159c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
160c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
161c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
162de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual status_t stopOutput(audio_io_handle_t output,
163fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                audio_stream_type_t stream,
164de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                int session)
165c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
166c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
167c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
168fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        data.writeInt32(output);
169c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(stream);
170de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(session);
171c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(STOP_OUTPUT, data, &reply);
172c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
173c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
174c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
175c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual void releaseOutput(audio_io_handle_t output)
176c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
177c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
178c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
179fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        data.writeInt32(output);
180c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(RELEASE_OUTPUT, data, &reply);
181c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
182c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
183c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual audio_io_handle_t getInput(
184c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    int inputSource,
185c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    uint32_t samplingRate,
186c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    uint32_t format,
187c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    uint32_t channels,
1887c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                    audio_in_acoustics_t acoustics,
1897c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                    int audioSession)
190c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
191c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
192c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
193c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(inputSource);
194c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(samplingRate);
195c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(format));
196c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(channels);
197c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(acoustics));
1987c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        data.writeInt32(audioSession);
199c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(GET_INPUT, data, &reply);
200fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        return static_cast <audio_io_handle_t> (reply.readInt32());
201c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
202c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
203c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual status_t startInput(audio_io_handle_t input)
204c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
205c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
206c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
207fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        data.writeInt32(input);
208c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(START_INPUT, data, &reply);
209c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
210c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
211c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
212c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual status_t stopInput(audio_io_handle_t input)
213c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
214c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
215c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
216fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        data.writeInt32(input);
217c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(STOP_INPUT, data, &reply);
218c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
219c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
220c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
221c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual void releaseInput(audio_io_handle_t input)
222c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
223c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
224c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
225fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        data.writeInt32(input);
226c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(RELEASE_INPUT, data, &reply);
227c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
228c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
229fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t initStreamVolume(audio_stream_type_t stream,
230c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    int indexMin,
231c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    int indexMax)
232c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
233c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
234c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
235c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(stream));
236c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(indexMin);
237c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(indexMax);
238c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(INIT_STREAM_VOLUME, data, &reply);
239c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
240c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
241c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
242fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t setStreamVolumeIndex(audio_stream_type_t stream, int index)
243c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
244c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
245c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
246c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(stream));
247c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(index);
248c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(SET_STREAM_VOLUME, data, &reply);
249c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
250c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
251c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
252fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t getStreamVolumeIndex(audio_stream_type_t stream, int *index)
253c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
254c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
255c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
256c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(stream));
257c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(GET_STREAM_VOLUME, data, &reply);
258c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        int lIndex = reply.readInt32();
259c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        if (index) *index = lIndex;
260c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
261c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
262de070137f11d346fba77605bd76a44c040a618fcEric Laurent
263fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
264de070137f11d346fba77605bd76a44c040a618fcEric Laurent    {
265de070137f11d346fba77605bd76a44c040a618fcEric Laurent        Parcel data, reply;
266de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
267de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(static_cast <uint32_t>(stream));
268de070137f11d346fba77605bd76a44c040a618fcEric Laurent        remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
269de070137f11d346fba77605bd76a44c040a618fcEric Laurent        return reply.readInt32();
270de070137f11d346fba77605bd76a44c040a618fcEric Laurent    }
271de070137f11d346fba77605bd76a44c040a618fcEric Laurent
272fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual uint32_t getDevicesForStream(audio_stream_type_t stream)
2736b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten    {
2746b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        Parcel data, reply;
2756b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
2766b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        data.writeInt32(static_cast <uint32_t>(stream));
2776b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
2786b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        return (uint32_t) reply.readInt32();
2796b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten    }
2806b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten
281de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc)
282de070137f11d346fba77605bd76a44c040a618fcEric Laurent    {
283de070137f11d346fba77605bd76a44c040a618fcEric Laurent        Parcel data, reply;
284de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
285de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.write(desc, sizeof(effect_descriptor_t));
286de070137f11d346fba77605bd76a44c040a618fcEric Laurent        remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
287de070137f11d346fba77605bd76a44c040a618fcEric Laurent        return static_cast <audio_io_handle_t> (reply.readInt32());
288de070137f11d346fba77605bd76a44c040a618fcEric Laurent    }
289de070137f11d346fba77605bd76a44c040a618fcEric Laurent
290de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual status_t registerEffect(effect_descriptor_t *desc,
2917c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                        audio_io_handle_t io,
292de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                        uint32_t strategy,
293de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                        int session,
294de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                        int id)
295de070137f11d346fba77605bd76a44c040a618fcEric Laurent    {
296de070137f11d346fba77605bd76a44c040a618fcEric Laurent        Parcel data, reply;
297de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
298de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.write(desc, sizeof(effect_descriptor_t));
2997c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        data.writeInt32(io);
300de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(strategy);
301de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(session);
302de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(id);
303de070137f11d346fba77605bd76a44c040a618fcEric Laurent        remote()->transact(REGISTER_EFFECT, data, &reply);
304de070137f11d346fba77605bd76a44c040a618fcEric Laurent        return static_cast <status_t> (reply.readInt32());
305de070137f11d346fba77605bd76a44c040a618fcEric Laurent    }
306de070137f11d346fba77605bd76a44c040a618fcEric Laurent
307de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual status_t unregisterEffect(int id)
308de070137f11d346fba77605bd76a44c040a618fcEric Laurent    {
309de070137f11d346fba77605bd76a44c040a618fcEric Laurent        Parcel data, reply;
310de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
311de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(id);
312de070137f11d346fba77605bd76a44c040a618fcEric Laurent        remote()->transact(UNREGISTER_EFFECT, data, &reply);
313de070137f11d346fba77605bd76a44c040a618fcEric Laurent        return static_cast <status_t> (reply.readInt32());
314de070137f11d346fba77605bd76a44c040a618fcEric Laurent    }
315de070137f11d346fba77605bd76a44c040a618fcEric Laurent
316eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent    virtual bool isStreamActive(int stream, uint32_t inPastMs) const
317eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent    {
318eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        Parcel data, reply;
319eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
320eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        data.writeInt32(stream);
321eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        data.writeInt32(inPastMs);
322eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        remote()->transact(IS_STREAM_ACTIVE, data, &reply);
323eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        return reply.readInt32();
324eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent    }
32557dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent
32657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    virtual status_t queryDefaultPreProcessing(int audioSession,
32757dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent                                               effect_descriptor_t *descriptors,
32857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent                                               uint32_t *count)
32957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    {
33057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        if (descriptors == NULL || count == NULL) {
33157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            return BAD_VALUE;
33257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        }
33357dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        Parcel data, reply;
33457dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
33557dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        data.writeInt32(audioSession);
33657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        data.writeInt32(*count);
33757dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
33857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        if (status != NO_ERROR) {
33957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            return status;
34057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        }
34157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        status = static_cast <status_t> (reply.readInt32());
34257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        uint32_t retCount = reply.readInt32();
34357dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        if (retCount != 0) {
34457dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            uint32_t numDesc = (retCount < *count) ? retCount : *count;
34557dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
34657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        }
34757dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        *count = retCount;
34857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        return status;
34957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    }
350c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent};
351c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
352c2f1f07084818942352c6bbfb36af9b6b330eb4eEric LaurentIMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
353c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
354c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent// ----------------------------------------------------------------------
355c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
356c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
357c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentstatus_t BnAudioPolicyService::onTransact(
358c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
359c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent{
360c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    switch(code) {
361c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case SET_DEVICE_CONNECTION_STATE: {
362c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
363fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_devices_t device =
364fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_devices_t>(data.readInt32());
365fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_policy_dev_state_t state =
366fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_policy_dev_state_t>(data.readInt32());
367c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            const char *device_address = data.readCString();
368de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
369de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                              state,
370de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                              device_address)));
371c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
372c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
373c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
374c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case GET_DEVICE_CONNECTION_STATE: {
375c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
376fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_devices_t device =
377fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast<audio_devices_t> (data.readInt32());
378c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            const char *device_address = data.readCString();
379de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
380de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                              device_address)));
381c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
382c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
383c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
384c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case SET_PHONE_STATE: {
385c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
386c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(setPhoneState(data.readInt32())));
387c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
388c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
389c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
390c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case SET_RINGER_MODE: {
391c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
392c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t mode = data.readInt32();
393c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t mask = data.readInt32();
394c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(setRingerMode(mode, mask)));
395c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
396c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
397c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
398c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case SET_FORCE_USE: {
399c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
400fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(data.readInt32());
401fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_policy_forced_cfg_t config =
402fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_policy_forced_cfg_t>(data.readInt32());
403c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
404c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
405c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
406c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
407c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case GET_FORCE_USE: {
408c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
409fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(data.readInt32());
410c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
411c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
412c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
413c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
414c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case GET_OUTPUT: {
415c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
416fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_stream_type_t stream =
417fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_stream_type_t>(data.readInt32());
418c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t samplingRate = data.readInt32();
419c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t format = data.readInt32();
420c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t channels = data.readInt32();
421fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_policy_output_flags_t flags =
422fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_policy_output_flags_t>(data.readInt32());
423c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
424c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            audio_io_handle_t output = getOutput(stream,
425c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                                 samplingRate,
426c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                                 format,
427c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                                 channels,
428c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                                 flags);
429fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            reply->writeInt32(static_cast <int>(output));
430c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
431c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
432c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
433c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case START_OUTPUT: {
434c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
435fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
436c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t stream = data.readInt32();
437de070137f11d346fba77605bd76a44c040a618fcEric Laurent            int session = data.readInt32();
438de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast <uint32_t>(startOutput(output,
439fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                                                 (audio_stream_type_t)stream,
440de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                 session)));
441c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
442c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
443c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
444c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case STOP_OUTPUT: {
445c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
446fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
447c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t stream = data.readInt32();
448de070137f11d346fba77605bd76a44c040a618fcEric Laurent            int session = data.readInt32();
449de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
450fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                                                (audio_stream_type_t)stream,
451de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                session)));
452c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
453c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
454c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
455c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case RELEASE_OUTPUT: {
456c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
457fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
458c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            releaseOutput(output);
459c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
460c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
461c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
462c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case GET_INPUT: {
463c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
464c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            int inputSource = data.readInt32();
465c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t samplingRate = data.readInt32();
466c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t format = data.readInt32();
467c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t channels = data.readInt32();
468fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_in_acoustics_t acoustics =
469fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_in_acoustics_t>(data.readInt32());
4707c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            int audioSession = data.readInt32();
471c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            audio_io_handle_t input = getInput(inputSource,
472c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                               samplingRate,
473c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                               format,
474c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                               channels,
4757c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                               acoustics,
4767c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                               audioSession);
477fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            reply->writeInt32(static_cast <int>(input));
478c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
479c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
480c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
481c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case START_INPUT: {
482c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
483fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
484c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(startInput(input)));
485c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
486c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
487c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
488c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case STOP_INPUT: {
489c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
490fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
491c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(stopInput(input)));
492c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
493c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
494c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
495c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case RELEASE_INPUT: {
496c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
497fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
498c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            releaseInput(input);
499c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
500c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
501c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
502c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case INIT_STREAM_VOLUME: {
503c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
504fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_stream_type_t stream =
505fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_stream_type_t>(data.readInt32());
506c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            int indexMin = data.readInt32();
507c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            int indexMax = data.readInt32();
508c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
509c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
510c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
511c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
512c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case SET_STREAM_VOLUME: {
513c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
514fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_stream_type_t stream =
515fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_stream_type_t>(data.readInt32());
516c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            int index = data.readInt32();
517c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream, index)));
518c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
519c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
520c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
521c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case GET_STREAM_VOLUME: {
522c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
523fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_stream_type_t stream =
524fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_stream_type_t>(data.readInt32());
525c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            int index;
526c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            status_t status = getStreamVolumeIndex(stream, &index);
527c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(index);
528c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(status));
529c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
530c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
531c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
532de070137f11d346fba77605bd76a44c040a618fcEric Laurent        case GET_STRATEGY_FOR_STREAM: {
533de070137f11d346fba77605bd76a44c040a618fcEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
534fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_stream_type_t stream =
535fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_stream_type_t>(data.readInt32());
536de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(getStrategyForStream(stream));
537de070137f11d346fba77605bd76a44c040a618fcEric Laurent            return NO_ERROR;
538de070137f11d346fba77605bd76a44c040a618fcEric Laurent        } break;
539de070137f11d346fba77605bd76a44c040a618fcEric Laurent
5406b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        case GET_DEVICES_FOR_STREAM: {
5416b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten            CHECK_INTERFACE(IAudioPolicyService, data, reply);
542fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_stream_type_t stream =
543fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_stream_type_t>(data.readInt32());
5446b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten            reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
5456b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten            return NO_ERROR;
5466b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        } break;
5476b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten
548de070137f11d346fba77605bd76a44c040a618fcEric Laurent        case GET_OUTPUT_FOR_EFFECT: {
549de070137f11d346fba77605bd76a44c040a618fcEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
550de070137f11d346fba77605bd76a44c040a618fcEric Laurent            effect_descriptor_t desc;
551de070137f11d346fba77605bd76a44c040a618fcEric Laurent            data.read(&desc, sizeof(effect_descriptor_t));
552de070137f11d346fba77605bd76a44c040a618fcEric Laurent            audio_io_handle_t output = getOutputForEffect(&desc);
553de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast <int>(output));
554de070137f11d346fba77605bd76a44c040a618fcEric Laurent            return NO_ERROR;
555de070137f11d346fba77605bd76a44c040a618fcEric Laurent        } break;
556de070137f11d346fba77605bd76a44c040a618fcEric Laurent
557de070137f11d346fba77605bd76a44c040a618fcEric Laurent        case REGISTER_EFFECT: {
558de070137f11d346fba77605bd76a44c040a618fcEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
559de070137f11d346fba77605bd76a44c040a618fcEric Laurent            effect_descriptor_t desc;
560de070137f11d346fba77605bd76a44c040a618fcEric Laurent            data.read(&desc, sizeof(effect_descriptor_t));
5617c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent            audio_io_handle_t io = data.readInt32();
562de070137f11d346fba77605bd76a44c040a618fcEric Laurent            uint32_t strategy = data.readInt32();
563de070137f11d346fba77605bd76a44c040a618fcEric Laurent            int session = data.readInt32();
564de070137f11d346fba77605bd76a44c040a618fcEric Laurent            int id = data.readInt32();
565de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
5667c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                                                   io,
567de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                   strategy,
568de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                   session,
569de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                   id)));
570de070137f11d346fba77605bd76a44c040a618fcEric Laurent            return NO_ERROR;
571de070137f11d346fba77605bd76a44c040a618fcEric Laurent        } break;
572de070137f11d346fba77605bd76a44c040a618fcEric Laurent
573de070137f11d346fba77605bd76a44c040a618fcEric Laurent        case UNREGISTER_EFFECT: {
574de070137f11d346fba77605bd76a44c040a618fcEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
575de070137f11d346fba77605bd76a44c040a618fcEric Laurent            int id = data.readInt32();
576de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
577de070137f11d346fba77605bd76a44c040a618fcEric Laurent            return NO_ERROR;
578de070137f11d346fba77605bd76a44c040a618fcEric Laurent        } break;
579de070137f11d346fba77605bd76a44c040a618fcEric Laurent
580eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        case IS_STREAM_ACTIVE: {
581eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
582eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent            int stream = data.readInt32();
583eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent            uint32_t inPastMs = (uint32_t)data.readInt32();
584eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent            reply->writeInt32( isStreamActive(stream, inPastMs) );
585eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent            return NO_ERROR;
586eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        } break;
587eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent
58857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        case QUERY_DEFAULT_PRE_PROCESSING: {
58957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
59057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            int audioSession = data.readInt32();
59157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            uint32_t count = data.readInt32();
59257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            uint32_t retCount = count;
59357dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            effect_descriptor_t *descriptors =
59457dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent                    (effect_descriptor_t *)new char[count * sizeof(effect_descriptor_t)];
59557dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
59657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            reply->writeInt32(status);
59757dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            if (status != NO_ERROR && status != NO_MEMORY) {
59857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent                retCount = 0;
59957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            }
60057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            reply->writeInt32(retCount);
60157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            if (retCount) {
60257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent                if (retCount < count) {
60357dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent                    count = retCount;
60457dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent                }
60557dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent                reply->write(descriptors, sizeof(effect_descriptor_t) * count);
60657dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            }
60757dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            delete[] descriptors;
60857dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent            return status;
60957dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent        }
61057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent
611c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        default:
612c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return BBinder::onTransact(code, data, reply, flags);
613c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
614c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent}
615c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
616c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent// ----------------------------------------------------------------------------
617c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
618c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent}; // namespace android
619