AudioPolicyService.h revision eba51fb3a361f67a6a64d5a16eba6084fe27d60e
165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian/*
265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * Copyright (C) 2009 The Android Open Source Project
365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian *
465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * you may not use this file except in compliance with the License.
665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * You may obtain a copy of the License at
765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian *
865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian *
1065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * Unless required by applicable law or agreed to in writing, software
1165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
1265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * See the License for the specific language governing permissions and
1465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian * limitations under the License.
1565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian */
1665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
1765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#ifndef ANDROID_AUDIOPOLICYSERVICE_H
1865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#define ANDROID_AUDIOPOLICYSERVICE_H
1965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
207c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent#include <cutils/misc.h>
217c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent#include <cutils/config_utils.h>
22d1d8f23dde239289ba8c0de0944baaca3586c880Glenn Kasten#include <utils/String8.h>
2365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/Vector.h>
247c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent#include <utils/SortedVector.h>
25d2dcb08808aed82218b258726fa66f8e095a3f9cGlenn Kasten#include <binder/BinderService.h>
2664760240f931714858a59c1579f07264d7182ba2Dima Zavin#include <system/audio.h>
277394a4f358fa9908a9f0a7c954b65c399f4268e6Dima Zavin#include <system/audio_policy.h>
28fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin#include <hardware/audio_policy.h>
297c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent#include <media/IAudioPolicyService.h>
307c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent#include <media/ToneGenerator.h>
317c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent#include <media/AudioEffect.h>
32fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin
3365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopiannamespace android {
3465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
3565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ----------------------------------------------------------------------------
3665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
37d2dcb08808aed82218b258726fa66f8e095a3f9cGlenn Kastenclass AudioPolicyService :
38d2dcb08808aed82218b258726fa66f8e095a3f9cGlenn Kasten    public BinderService<AudioPolicyService>,
39d2dcb08808aed82218b258726fa66f8e095a3f9cGlenn Kasten    public BnAudioPolicyService,
40fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin//    public AudioPolicyClientInterface,
41de070137f11d346fba77605bd76a44c040a618fcEric Laurent    public IBinder::DeathRecipient
4265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{
43d2dcb08808aed82218b258726fa66f8e095a3f9cGlenn Kasten    friend class BinderService<AudioPolicyService>;
4465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
4565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianpublic:
46d2dcb08808aed82218b258726fa66f8e095a3f9cGlenn Kasten    // for BinderService
47d2dcb08808aed82218b258726fa66f8e095a3f9cGlenn Kasten    static const char *getServiceName() { return "media.audio_policy"; }
4865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
4965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t    dump(int fd, const Vector<String16>& args);
5065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
5165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    //
5265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // BnAudioPolicyService (see AudioPolicyInterface for method descriptions)
5365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    //
5465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
55fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t setDeviceConnectionState(audio_devices_t device,
56fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                              audio_policy_dev_state_t state,
5765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                              const char *device_address);
58fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual audio_policy_dev_state_t getDeviceConnectionState(
59fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                                                audio_devices_t device,
60de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                                                const char *device_address);
61f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kasten    virtual status_t setPhoneState(audio_mode_t state);
62fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config);
63fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage);
64fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual audio_io_handle_t getOutput(audio_stream_type_t stream,
6565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        uint32_t samplingRate = 0,
6658f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                        audio_format_t format = AUDIO_FORMAT_DEFAULT,
6765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                        uint32_t channels = 0,
68fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                        audio_policy_output_flags_t flags =
69fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                            AUDIO_POLICY_OUTPUT_FLAG_INDIRECT);
70de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual status_t startOutput(audio_io_handle_t output,
71fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                 audio_stream_type_t stream,
72de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                 int session = 0);
73de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual status_t stopOutput(audio_io_handle_t output,
74fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                audio_stream_type_t stream,
75de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                int session = 0);
7665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual void releaseOutput(audio_io_handle_t output);
77eba51fb3a361f67a6a64d5a16eba6084fe27d60eGlenn Kasten    virtual audio_io_handle_t getInput(audio_source_t inputSource,
7865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    uint32_t samplingRate = 0,
7958f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten                                    audio_format_t format = AUDIO_FORMAT_DEFAULT,
8065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                    uint32_t channels = 0,
81fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                                    audio_in_acoustics_t acoustics =
827c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                            (audio_in_acoustics_t)0,
837c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                    int audioSession = 0);
8465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t startInput(audio_io_handle_t input);
8565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t stopInput(audio_io_handle_t input);
8665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual void releaseInput(audio_io_handle_t input);
87fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t initStreamVolume(audio_stream_type_t stream,
8865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                      int indexMin,
8965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                      int indexMax);
9083844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent    virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
9183844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                          int index,
9283844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                          audio_devices_t device);
9383844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent    virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
9483844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                          int *index,
9583844cc2f95dc279015b47fd1e18c7cb4eabe9a1Eric Laurent                                          audio_devices_t device);
9665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
97fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual uint32_t getStrategyForStream(audio_stream_type_t stream);
98fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual uint32_t getDevicesForStream(audio_stream_type_t stream);
99de070137f11d346fba77605bd76a44c040a618fcEric Laurent
100de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc);
101de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual status_t registerEffect(effect_descriptor_t *desc,
1027c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                                    audio_io_handle_t io,
103de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                    uint32_t strategy,
104de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                    int session,
105de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                    int id);
106de070137f11d346fba77605bd76a44c040a618fcEric Laurent    virtual status_t unregisterEffect(int id);
107db7c079f284f6e91266f6653ae0ec198b1c5006eEric Laurent    virtual status_t setEffectEnabled(int id, bool enabled);
108fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten    virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const;
109de070137f11d346fba77605bd76a44c040a618fcEric Laurent
11057dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent    virtual status_t queryDefaultPreProcessing(int audioSession,
11157dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent                                              effect_descriptor_t *descriptors,
11257dae99c9fcd6becd2b5ed0c53f277ba4d7dbcfcEric Laurent                                              uint32_t *count);
11365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     status_t    onTransact(
11465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                uint32_t code,
11565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                const Parcel& data,
11665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                Parcel* reply,
11765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                                uint32_t flags);
11865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
11965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // IBinder::DeathRecipient
12065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual     void        binderDied(const wp<IBinder>& who);
12165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
12265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    //
123fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    // Helpers for the struct audio_policy_service_ops implementation.
124fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    // This is used by the audio policy manager for certain operations that
125fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    // are implemented by the policy service.
12665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    //
127fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual void setParameters(audio_io_handle_t ioHandle,
128fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                               const char *keyValuePairs,
129fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                               int delayMs);
130fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin
131fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t setStreamVolume(audio_stream_type_t stream,
132de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                     float volume,
133de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                     audio_io_handle_t output,
134de070137f11d346fba77605bd76a44c040a618fcEric Laurent                                     int delayMs = 0);
135fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream);
13665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t stopTone();
13765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual status_t setVoiceVolume(float volume, int delayMs = 0);
13865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
13965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianprivate:
14065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                        AudioPolicyService();
14165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    virtual             ~AudioPolicyService();
14265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
14365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            status_t dumpInternals(int fd);
14465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
14565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // Thread used for tone playback and to send audio config commands to audio flinger
14665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // For tone playback, using a separate thread is necessary to avoid deadlock with mLock because startTone()
14765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // and stopTone() are normally called with mLock locked and requesting a tone start or stop will cause
14865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // calls to AudioPolicyService and an attempt to lock mLock.
14965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // For audio config commands, it is necessary because audio flinger requires that the calling process (user)
15065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // has permission to modify audio settings.
15165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    class AudioCommandThread : public Thread {
15265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        class AudioCommand;
15365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    public:
15465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
15565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // commands for tone AudioCommand
15665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        enum {
15765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            START_TONE,
15865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            STOP_TONE,
15965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            SET_VOLUME,
16065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            SET_PARAMETERS,
16165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            SET_VOICE_VOLUME
16265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
16365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
16465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AudioCommandThread (String8 name);
16565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual             ~AudioCommandThread();
16665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
16765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    status_t    dump(int fd);
16865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
16965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // Thread virtuals
17065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     void        onFirstRef();
17165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        virtual     bool        threadLoop();
17265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
17365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        exit();
174fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten                    void        startToneCommand(int type = 0, audio_stream_type_t stream = AUDIO_STREAM_VOICE_CALL);
17565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        stopToneCommand();
176fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten                    status_t    volumeCommand(audio_stream_type_t stream, float volume, int output, int delayMs = 0);
177fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin                    status_t    parametersCommand(int ioHandle, const char *keyValuePairs, int delayMs = 0);
17865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    status_t    voiceVolumeCommand(float volume, int delayMs = 0);
17965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian                    void        insertCommand_l(AudioCommand *command, int delayMs = 0);
18065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
18165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    private:
18265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        // descriptor for requested tone playback event
18365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        class AudioCommand {
18465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
18565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        public:
18665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            AudioCommand()
18765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            : mCommand(-1) {}
18865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
18965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            void dump(char* buffer, size_t size);
19065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
19165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int mCommand;   // START_TONE, STOP_TONE ...
19265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            nsecs_t mTime;  // time stamp
19365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            Condition mCond; // condition for status return
19465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            status_t mStatus; // command status
19565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            bool mWaitStatus; // true if caller is waiting for status
19665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            void *mParam;     // command parameter (ToneData, VolumeData, ParametersData)
19765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
19865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
19965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        class ToneData {
20065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        public:
20165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int mType;      // tone type (START_TONE only)
202fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten            audio_stream_type_t mStream;    // stream type (START_TONE only)
20365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
20465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
20565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        class VolumeData {
20665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        public:
207fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten            audio_stream_type_t mStream;
20865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            float mVolume;
20965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int mIO;
21065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
21165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
21265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        class ParametersData {
21365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        public:
21465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            int mIO;
21565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            String8 mKeyValuePairs;
21665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
21765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
21865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        class VoiceVolumeData {
21965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        public:
22065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian            float mVolume;
22165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        };
22265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
22365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        Mutex   mLock;
22465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        Condition mWaitWorkCV;
22565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        Vector <AudioCommand *> mAudioCommands; // list of pending commands
22665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        ToneGenerator *mpToneGenerator;     // the tone generator
22765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        AudioCommand mLastCommand;          // last processed command (used by dump)
22865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian        String8 mName;                      // string used by wake lock fo delayed commands
22965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    };
23065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
2317c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    class EffectDesc {
2327c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    public:
2337c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        EffectDesc() {}
2347c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual ~EffectDesc() {}
2357c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        char *mName;
2367c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        effect_uuid_t mUuid;
2377c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        Vector <effect_param_t *> mParams;
2387c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    };
2397c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
2407c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    class InputSourceDesc {
2417c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    public:
2427c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        InputSourceDesc() {}
2437c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual ~InputSourceDesc() {}
2447c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        Vector <EffectDesc *> mEffects;
2457c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    };
2467c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
2477c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
2487c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    class InputDesc {
2497c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    public:
2507c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        InputDesc() {}
2517c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        virtual ~InputDesc() {}
2527c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        int mSessionId;
2537c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent        Vector< sp<AudioEffect> >mEffects;
2547c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    };
2557c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
2568dad0e31c2366c501bd1d600261d0af35a6ca786Glenn Kasten    static const char * const kInputSourceNames[AUDIO_SOURCE_CNT -1];
2577c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
2587c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    void setPreProcessorEnabled(InputDesc *inputDesc, bool enabled);
2597c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    status_t loadPreProcessorConfig(const char *path);
2607c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    status_t loadEffects(cnode *root, Vector <EffectDesc *>& effects);
2617c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    EffectDesc *loadEffect(cnode *root);
2627c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    status_t loadInputSources(cnode *root, const Vector <EffectDesc *>& effects);
2637c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    audio_source_t inputSourceNameToEnum(const char *name);
2647c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    InputSourceDesc *loadInputSource(cnode *root, const Vector <EffectDesc *>& effects);
2657c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    void loadEffectParameters(cnode *root, Vector <effect_param_t *>& params);
2667c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    effect_param_t *loadEffectParameter(cnode *root);
2677c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    size_t readParamValue(cnode *node,
2687c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                          char *param,
2697c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                          size_t *curSize,
2707c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                          size_t *totSize);
2717c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    size_t growParamSize(char *param,
2727c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                         size_t size,
2737c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                         size_t *curSize,
2747c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent                         size_t *totSize);
2757c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent
27665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    // Internal dump utilities.
27765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    status_t dumpPermissionDenial(int fd);
27865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
27965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
280eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent    mutable Mutex mLock;    // prevents concurrent access to AudioPolicy manager functions changing
281eda6c364c253ba97ee45a3adeb8c2b45db1f81dbEric Laurent                            // device connection state  or routing
28265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    sp <AudioCommandThread> mAudioCommandThread;    // audio commands thread
28365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian    sp <AudioCommandThread> mTonePlaybackThread;     // tone playback thread
284fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    struct audio_policy_device *mpAudioPolicyDev;
285fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin    struct audio_policy *mpAudioPolicy;
2867c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    KeyedVector< audio_source_t, InputSourceDesc* > mInputSources;
2877c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent    KeyedVector< audio_io_handle_t, InputDesc* > mInputs;
28865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian};
28965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
29065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}; // namespace android
29165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian
29265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#endif // ANDROID_AUDIOPOLICYSERVICE_H
293