IAudioPolicyService.cpp revision fce7a473248381cc83a01855f92581077d3c9ee2
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
28fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin#include <hardware/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,
56c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent};
57c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
58c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentclass BpAudioPolicyService : public BpInterface<IAudioPolicyService>
59c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent{
60c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentpublic:
61c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    BpAudioPolicyService(const sp<IBinder>& impl)
62c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        : BpInterface<IAudioPolicyService>(impl)
63c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
64c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
65c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
66c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual status_t setDeviceConnectionState(
67fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                    audio_devices_t device,
68fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                    audio_policy_dev_state_t state,
69c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    const char *device_address)
70c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
71c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
72c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
73c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(device));
74c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(state));
75c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeCString(device_address);
76c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(SET_DEVICE_CONNECTION_STATE, data, &reply);
77c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
78c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
79c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
80fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual audio_policy_dev_state_t getDeviceConnectionState(
81fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                    audio_devices_t device,
82c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    const char *device_address)
83c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
84c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
85c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
86c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(device));
87c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeCString(device_address);
88c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(GET_DEVICE_CONNECTION_STATE, data, &reply);
89fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        return static_cast <audio_policy_dev_state_t>(reply.readInt32());
90c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
91c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
92c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual status_t setPhoneState(int state)
93c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
94c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
95c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
96c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(state);
97c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(SET_PHONE_STATE, data, &reply);
98c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
99c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
100c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
101c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual status_t setRingerMode(uint32_t mode, uint32_t mask)
102c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
103c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
104c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
105c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(mode);
106c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(mask);
107c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(SET_RINGER_MODE, data, &reply);
108c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
109c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
110c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
111fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config)
112c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
113c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
114c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
115c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(usage));
116c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(config));
117c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(SET_FORCE_USE, data, &reply);
118c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
119c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
120c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
121fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage)
122c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
123c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
124c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
125c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(usage));
126c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(GET_FORCE_USE, data, &reply);
127fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin        return static_cast <audio_policy_forced_cfg_t> (reply.readInt32());
128c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
129c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
130c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual audio_io_handle_t getOutput(
131fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                        audio_stream_type_t stream,
132c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                        uint32_t samplingRate,
133c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                        uint32_t format,
134c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                        uint32_t channels,
135fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                        audio_policy_output_flags_t flags)
136c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
137c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
138c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
139c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(stream));
140c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(samplingRate);
141c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(format));
142c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(channels);
143c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(flags));
144c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(GET_OUTPUT, data, &reply);
145fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        return static_cast <audio_io_handle_t> (reply.readInt32());
146c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
147c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
148de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual status_t startOutput(audio_io_handle_t output,
149fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                 audio_stream_type_t stream,
150de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                 int session)
151c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
152c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
153c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
154fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        data.writeInt32(output);
155c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(stream);
156de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(session);
157c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(START_OUTPUT, data, &reply);
158c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
159c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
160c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
161de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual status_t stopOutput(audio_io_handle_t output,
162fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                audio_stream_type_t stream,
163de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                int session)
164c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
165c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
166c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
167fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        data.writeInt32(output);
168c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(stream);
169de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(session);
170c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(STOP_OUTPUT, data, &reply);
171c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
172c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
173c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
174c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual void releaseOutput(audio_io_handle_t output)
175c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
176c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
177c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
178fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        data.writeInt32(output);
179c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(RELEASE_OUTPUT, data, &reply);
180c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
181c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
182c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual audio_io_handle_t getInput(
183c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    int inputSource,
184c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    uint32_t samplingRate,
185c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    uint32_t format,
186c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    uint32_t channels,
187fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                    audio_in_acoustics_t acoustics)
188c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
189c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
190c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
191c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(inputSource);
192c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(samplingRate);
193c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(format));
194c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(channels);
195c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(acoustics));
196c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(GET_INPUT, data, &reply);
197fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        return static_cast <audio_io_handle_t> (reply.readInt32());
198c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
199c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
200c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual status_t startInput(audio_io_handle_t input)
201c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
202c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
203c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
204fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        data.writeInt32(input);
205c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(START_INPUT, data, &reply);
206c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
207c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
208c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
209c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual status_t stopInput(audio_io_handle_t input)
210c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
211c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
212c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
213fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        data.writeInt32(input);
214c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(STOP_INPUT, data, &reply);
215c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
216c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
217c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
218c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual void releaseInput(audio_io_handle_t input)
219c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
220c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
221c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
222fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        data.writeInt32(input);
223c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(RELEASE_INPUT, data, &reply);
224c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
225c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
226fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t initStreamVolume(audio_stream_type_t stream,
227c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    int indexMin,
228c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    int indexMax)
229c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
230c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
231c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
232c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(stream));
233c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(indexMin);
234c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(indexMax);
235c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(INIT_STREAM_VOLUME, data, &reply);
236c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
237c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
238c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
239fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t setStreamVolumeIndex(audio_stream_type_t stream, int index)
240c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
241c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
242c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
243c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(stream));
244c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(index);
245c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(SET_STREAM_VOLUME, data, &reply);
246c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
247c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
248c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
249fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t getStreamVolumeIndex(audio_stream_type_t stream, int *index)
250c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
251c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        Parcel data, reply;
252c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
253c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        data.writeInt32(static_cast <uint32_t>(stream));
254c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        remote()->transact(GET_STREAM_VOLUME, data, &reply);
255c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        int lIndex = reply.readInt32();
256c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        if (index) *index = lIndex;
257c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        return static_cast <status_t> (reply.readInt32());
258c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
259de070137f11d346fba77605bd76a44c040a618fcEric Laurent
260fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual uint32_t getStrategyForStream(audio_stream_type_t stream)
261de070137f11d346fba77605bd76a44c040a618fcEric Laurent    {
262de070137f11d346fba77605bd76a44c040a618fcEric Laurent        Parcel data, reply;
263de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
264de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(static_cast <uint32_t>(stream));
265de070137f11d346fba77605bd76a44c040a618fcEric Laurent        remote()->transact(GET_STRATEGY_FOR_STREAM, data, &reply);
266de070137f11d346fba77605bd76a44c040a618fcEric Laurent        return reply.readInt32();
267de070137f11d346fba77605bd76a44c040a618fcEric Laurent    }
268de070137f11d346fba77605bd76a44c040a618fcEric Laurent
269fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual uint32_t getDevicesForStream(audio_stream_type_t stream)
2706b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten    {
2716b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        Parcel data, reply;
2726b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
2736b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        data.writeInt32(static_cast <uint32_t>(stream));
2746b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
2756b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        return (uint32_t) reply.readInt32();
2766b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten    }
2776b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten
278de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc)
279de070137f11d346fba77605bd76a44c040a618fcEric Laurent    {
280de070137f11d346fba77605bd76a44c040a618fcEric Laurent        Parcel data, reply;
281de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
282de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.write(desc, sizeof(effect_descriptor_t));
283de070137f11d346fba77605bd76a44c040a618fcEric Laurent        remote()->transact(GET_OUTPUT_FOR_EFFECT, data, &reply);
284de070137f11d346fba77605bd76a44c040a618fcEric Laurent        return static_cast <audio_io_handle_t> (reply.readInt32());
285de070137f11d346fba77605bd76a44c040a618fcEric Laurent    }
286de070137f11d346fba77605bd76a44c040a618fcEric Laurent
287de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual status_t registerEffect(effect_descriptor_t *desc,
288de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                        audio_io_handle_t output,
289de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                        uint32_t strategy,
290de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                        int session,
291de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                        int id)
292de070137f11d346fba77605bd76a44c040a618fcEric Laurent    {
293de070137f11d346fba77605bd76a44c040a618fcEric Laurent        Parcel data, reply;
294de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
295de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.write(desc, sizeof(effect_descriptor_t));
296de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(output);
297de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(strategy);
298de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(session);
299de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(id);
300de070137f11d346fba77605bd76a44c040a618fcEric Laurent        remote()->transact(REGISTER_EFFECT, data, &reply);
301de070137f11d346fba77605bd76a44c040a618fcEric Laurent        return static_cast <status_t> (reply.readInt32());
302de070137f11d346fba77605bd76a44c040a618fcEric Laurent    }
303de070137f11d346fba77605bd76a44c040a618fcEric Laurent
304de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual status_t unregisterEffect(int id)
305de070137f11d346fba77605bd76a44c040a618fcEric Laurent    {
306de070137f11d346fba77605bd76a44c040a618fcEric Laurent        Parcel data, reply;
307de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
308de070137f11d346fba77605bd76a44c040a618fcEric Laurent        data.writeInt32(id);
309de070137f11d346fba77605bd76a44c040a618fcEric Laurent        remote()->transact(UNREGISTER_EFFECT, data, &reply);
310de070137f11d346fba77605bd76a44c040a618fcEric Laurent        return static_cast <status_t> (reply.readInt32());
311de070137f11d346fba77605bd76a44c040a618fcEric Laurent    }
312de070137f11d346fba77605bd76a44c040a618fcEric Laurent
313eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent    virtual bool isStreamActive(int stream, uint32_t inPastMs) const
314eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent    {
315eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        Parcel data, reply;
316eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
317eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        data.writeInt32(stream);
318eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        data.writeInt32(inPastMs);
319eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        remote()->transact(IS_STREAM_ACTIVE, data, &reply);
320eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        return reply.readInt32();
321eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent    }
322c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent};
323c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
324c2f1f07084818942352c6bbfb36af9b6b330eb4eEric LaurentIMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
325c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
326c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent// ----------------------------------------------------------------------
327c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
328c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
329c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentstatus_t BnAudioPolicyService::onTransact(
330c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
331c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent{
332c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    switch(code) {
333c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case SET_DEVICE_CONNECTION_STATE: {
334c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
335fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_devices_t device =
336fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_devices_t>(data.readInt32());
337fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_policy_dev_state_t state =
338fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_policy_dev_state_t>(data.readInt32());
339c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            const char *device_address = data.readCString();
340de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast<uint32_t> (setDeviceConnectionState(device,
341de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                              state,
342de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                              device_address)));
343c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
344c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
345c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
346c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case GET_DEVICE_CONNECTION_STATE: {
347c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
348fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_devices_t device =
349fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast<audio_devices_t> (data.readInt32());
350c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            const char *device_address = data.readCString();
351de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast<uint32_t> (getDeviceConnectionState(device,
352de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                              device_address)));
353c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
354c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
355c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
356c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case SET_PHONE_STATE: {
357c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
358c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(setPhoneState(data.readInt32())));
359c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
360c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
361c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
362c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case SET_RINGER_MODE: {
363c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
364c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t mode = data.readInt32();
365c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t mask = data.readInt32();
366c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(setRingerMode(mode, mask)));
367c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
368c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
369c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
370c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case SET_FORCE_USE: {
371c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
372fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(data.readInt32());
373fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_policy_forced_cfg_t config =
374fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_policy_forced_cfg_t>(data.readInt32());
375c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(setForceUse(usage, config)));
376c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
377c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
378c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
379c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case GET_FORCE_USE: {
380c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
381fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_policy_force_use_t usage = static_cast <audio_policy_force_use_t>(data.readInt32());
382c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(getForceUse(usage)));
383c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
384c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
385c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
386c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case GET_OUTPUT: {
387c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
388fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_stream_type_t stream =
389fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_stream_type_t>(data.readInt32());
390c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t samplingRate = data.readInt32();
391c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t format = data.readInt32();
392c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t channels = data.readInt32();
393fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_policy_output_flags_t flags =
394fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_policy_output_flags_t>(data.readInt32());
395c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
396c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            audio_io_handle_t output = getOutput(stream,
397c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                                 samplingRate,
398c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                                 format,
399c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                                 channels,
400c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                                 flags);
401fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            reply->writeInt32(static_cast <int>(output));
402c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
403c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
404c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
405c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case START_OUTPUT: {
406c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
407fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
408c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t stream = data.readInt32();
409de070137f11d346fba77605bd76a44c040a618fcEric Laurent            int session = data.readInt32();
410de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast <uint32_t>(startOutput(output,
411fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                                                 (audio_stream_type_t)stream,
412de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                 session)));
413c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
414c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
415c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
416c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case STOP_OUTPUT: {
417c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
418fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
419c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t stream = data.readInt32();
420de070137f11d346fba77605bd76a44c040a618fcEric Laurent            int session = data.readInt32();
421de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast <uint32_t>(stopOutput(output,
422fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                                                (audio_stream_type_t)stream,
423de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                session)));
424c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
425c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
426c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
427c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case RELEASE_OUTPUT: {
428c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
429fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            audio_io_handle_t output = static_cast <audio_io_handle_t>(data.readInt32());
430c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            releaseOutput(output);
431c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
432c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
433c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
434c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case GET_INPUT: {
435c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
436c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            int inputSource = data.readInt32();
437c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t samplingRate = data.readInt32();
438c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t format = data.readInt32();
439c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            uint32_t channels = data.readInt32();
440fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_in_acoustics_t acoustics =
441fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_in_acoustics_t>(data.readInt32());
442c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            audio_io_handle_t input = getInput(inputSource,
443c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                               samplingRate,
444c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                               format,
445c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                               channels,
446c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                               acoustics);
447fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            reply->writeInt32(static_cast <int>(input));
448c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
449c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
450c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
451c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case START_INPUT: {
452c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
453fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
454c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(startInput(input)));
455c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
456c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
457c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
458c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case STOP_INPUT: {
459c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
460fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
461c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(stopInput(input)));
462c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
463c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
464c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
465c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case RELEASE_INPUT: {
466c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
467fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent            audio_io_handle_t input = static_cast <audio_io_handle_t>(data.readInt32());
468c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            releaseInput(input);
469c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
470c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
471c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
472c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case INIT_STREAM_VOLUME: {
473c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
474fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_stream_type_t stream =
475fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_stream_type_t>(data.readInt32());
476c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            int indexMin = data.readInt32();
477c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            int indexMax = data.readInt32();
478c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(initStreamVolume(stream, indexMin,indexMax)));
479c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
480c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
481c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
482c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case SET_STREAM_VOLUME: {
483c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
484fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_stream_type_t stream =
485fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_stream_type_t>(data.readInt32());
486c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            int index = data.readInt32();
487c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(setStreamVolumeIndex(stream, index)));
488c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
489c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
490c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
491c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        case GET_STREAM_VOLUME: {
492c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
493fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_stream_type_t stream =
494fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_stream_type_t>(data.readInt32());
495c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            int index;
496c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            status_t status = getStreamVolumeIndex(stream, &index);
497c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(index);
498c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            reply->writeInt32(static_cast <uint32_t>(status));
499c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return NO_ERROR;
500c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        } break;
501c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
502de070137f11d346fba77605bd76a44c040a618fcEric Laurent        case GET_STRATEGY_FOR_STREAM: {
503de070137f11d346fba77605bd76a44c040a618fcEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
504fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_stream_type_t stream =
505fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_stream_type_t>(data.readInt32());
506de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(getStrategyForStream(stream));
507de070137f11d346fba77605bd76a44c040a618fcEric Laurent            return NO_ERROR;
508de070137f11d346fba77605bd76a44c040a618fcEric Laurent        } break;
509de070137f11d346fba77605bd76a44c040a618fcEric Laurent
5106b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        case GET_DEVICES_FOR_STREAM: {
5116b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten            CHECK_INTERFACE(IAudioPolicyService, data, reply);
512fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin            audio_stream_type_t stream =
513fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    static_cast <audio_stream_type_t>(data.readInt32());
5146b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten            reply->writeInt32(static_cast <int>(getDevicesForStream(stream)));
5156b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten            return NO_ERROR;
5166b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten        } break;
5176b2718c67aa7b1a8e3b0f25a73a0d5f72c59ffc3Glenn Kasten
518de070137f11d346fba77605bd76a44c040a618fcEric Laurent        case GET_OUTPUT_FOR_EFFECT: {
519de070137f11d346fba77605bd76a44c040a618fcEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
520de070137f11d346fba77605bd76a44c040a618fcEric Laurent            effect_descriptor_t desc;
521de070137f11d346fba77605bd76a44c040a618fcEric Laurent            data.read(&desc, sizeof(effect_descriptor_t));
522de070137f11d346fba77605bd76a44c040a618fcEric Laurent            audio_io_handle_t output = getOutputForEffect(&desc);
523de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast <int>(output));
524de070137f11d346fba77605bd76a44c040a618fcEric Laurent            return NO_ERROR;
525de070137f11d346fba77605bd76a44c040a618fcEric Laurent        } break;
526de070137f11d346fba77605bd76a44c040a618fcEric Laurent
527de070137f11d346fba77605bd76a44c040a618fcEric Laurent        case REGISTER_EFFECT: {
528de070137f11d346fba77605bd76a44c040a618fcEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
529de070137f11d346fba77605bd76a44c040a618fcEric Laurent            effect_descriptor_t desc;
530de070137f11d346fba77605bd76a44c040a618fcEric Laurent            data.read(&desc, sizeof(effect_descriptor_t));
531de070137f11d346fba77605bd76a44c040a618fcEric Laurent            audio_io_handle_t output = data.readInt32();
532de070137f11d346fba77605bd76a44c040a618fcEric Laurent            uint32_t strategy = data.readInt32();
533de070137f11d346fba77605bd76a44c040a618fcEric Laurent            int session = data.readInt32();
534de070137f11d346fba77605bd76a44c040a618fcEric Laurent            int id = data.readInt32();
535de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast <int32_t>(registerEffect(&desc,
536de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                   output,
537de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                   strategy,
538de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                   session,
539de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                   id)));
540de070137f11d346fba77605bd76a44c040a618fcEric Laurent            return NO_ERROR;
541de070137f11d346fba77605bd76a44c040a618fcEric Laurent        } break;
542de070137f11d346fba77605bd76a44c040a618fcEric Laurent
543de070137f11d346fba77605bd76a44c040a618fcEric Laurent        case UNREGISTER_EFFECT: {
544de070137f11d346fba77605bd76a44c040a618fcEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
545de070137f11d346fba77605bd76a44c040a618fcEric Laurent            int id = data.readInt32();
546de070137f11d346fba77605bd76a44c040a618fcEric Laurent            reply->writeInt32(static_cast <int32_t>(unregisterEffect(id)));
547de070137f11d346fba77605bd76a44c040a618fcEric Laurent            return NO_ERROR;
548de070137f11d346fba77605bd76a44c040a618fcEric Laurent        } break;
549de070137f11d346fba77605bd76a44c040a618fcEric Laurent
550eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        case IS_STREAM_ACTIVE: {
551eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent            CHECK_INTERFACE(IAudioPolicyService, data, reply);
552eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent            int stream = data.readInt32();
553eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent            uint32_t inPastMs = (uint32_t)data.readInt32();
554eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent            reply->writeInt32( isStreamActive(stream, inPastMs) );
555eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent            return NO_ERROR;
556eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent        } break;
557eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent
558c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        default:
559c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent            return BBinder::onTransact(code, data, reply, flags);
560c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    }
561c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent}
562c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
563c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent// ----------------------------------------------------------------------------
564c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
565c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent}; // namespace android
566