AudioSystem.h revision f0ee6f4055e26fb35d9c526a596668a4dc9da5ba
189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project/*
289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project *
489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * you may not use this file except in compliance with the License.
689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * You may obtain a copy of the License at
789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project *
889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project *
1089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
1189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
1289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * See the License for the specific language governing permissions and
1489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project * limitations under the License.
1589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project */
1689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
1789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#ifndef ANDROID_AUDIOSYSTEM_H_
1889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#define ANDROID_AUDIOSYSTEM_H_
1989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
2089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#include <utils/RefBase.h>
2189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#include <utils/threads.h>
2289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#include <media/IAudioFlinger.h>
2389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
2489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectnamespace android {
2589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
2689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projecttypedef void (*audio_error_callback)(status_t err);
27fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurenttypedef int audio_io_handle_t;
28c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
29c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentclass IAudioPolicyService;
30c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentclass String8;
3189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
3289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectclass AudioSystem
3389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project{
3489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectpublic:
3589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
3689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    enum stream_type {
37c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEFAULT          =-1,
38c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        VOICE_CALL       = 0,
39c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        SYSTEM           = 1,
40c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        RING             = 2,
41c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        MUSIC            = 3,
42c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        ALARM            = 4,
43c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        NOTIFICATION     = 5,
44c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        BLUETOOTH_SCO    = 6,
4529a65006e517ae5bb164e973b2d805ebfa834a2eEric Laurent        ENFORCED_AUDIBLE = 7, // Sounds that cannot be muted by user and must be routed to speaker
46c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DTMF             = 8,
47c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        TTS              = 9,
4889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        NUM_STREAM_TYPES
4989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    };
5089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
51c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // Audio sub formats (see AudioSystem::audio_format).
52c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    enum pcm_sub_format {
53c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        PCM_SUB_16_BIT          = 0x1, // must be 1 for backward compatibility
54c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        PCM_SUB_8_BIT           = 0x2, // must be 2 for backward compatibility
55c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
56c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
57c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // MP3 sub format field definition : can use 11 LSBs in the same way as MP3 frame header to specify
58c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // bit rate, stereo mode, version...
59c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    enum mp3_sub_format {
60c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        //TODO
61c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
62c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
63c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // AMR NB/WB sub format field definition: specify frame block interleaving, bandwidth efficient or octet aligned,
64c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // encoding mode for recording...
65c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    enum amr_sub_format {
66c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        //TODO
67c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
68c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
69c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // AAC sub format field definition: specify profile or bitrate for recording...
70c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    enum aac_sub_format {
71c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        //TODO
7289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    };
7389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
74c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // VORBIS sub format field definition: specify quality for recording...
75c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    enum vorbis_sub_format {
76c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        //TODO
77c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
78c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
79c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // Audio format consists in a main format field (upper 8 bits) and a sub format field (lower 24 bits).
80c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // The main format indicates the main codec type. The sub format field indicates options and parameters
81c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // for each format. The sub format is mainly used for record to indicate for instance the requested bitrate
82c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // or profile. It can also be used for certain formats to give informations not present in the encoded
83c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // audio stream (e.g. octet alignement for AMR).
8489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    enum audio_format {
85c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        INVALID_FORMAT      = -1,
86c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        FORMAT_DEFAULT      = 0,
87c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        PCM                 = 0x00000000, // must be 0 for backward compatibility
88c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        MP3                 = 0x01000000,
89c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        AMR_NB              = 0x02000000,
90c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        AMR_WB              = 0x03000000,
91c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        AAC                 = 0x04000000,
92c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        HE_AAC_V1           = 0x05000000,
93c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        HE_AAC_V2           = 0x06000000,
94c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        VORBIS              = 0x07000000,
95c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        MAIN_FORMAT_MASK    = 0xFF000000,
96c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        SUB_FORMAT_MASK     = 0x00FFFFFF,
97c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        // Aliases
98c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        PCM_16_BIT          = (PCM|PCM_SUB_16_BIT),
99c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        PCM_8_BIT          = (PCM|PCM_SUB_8_BIT)
100c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
101c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
102c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
103c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // Channel mask definitions must be kept in sync with JAVA values in /media/java/android/media/AudioFormat.java
104c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    enum audio_channels {
105c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        // output channels
1069a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_OUT_FRONT_LEFT = 0x4,
1079a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_OUT_FRONT_RIGHT = 0x8,
1089a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_OUT_FRONT_CENTER = 0x10,
1099a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_OUT_LOW_FREQUENCY = 0x20,
1109a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_OUT_BACK_LEFT = 0x40,
1119a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_OUT_BACK_RIGHT = 0x80,
1129a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100,
1139a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200,
1149a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_OUT_BACK_CENTER = 0x400,
115c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT,
116c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT),
117c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
118c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
119c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        CHANNEL_OUT_SURROUND = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
120c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_BACK_CENTER),
121c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        CHANNEL_OUT_5POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
122c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
123c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        CHANNEL_OUT_7POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
124c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
125c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER),
126c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        CHANNEL_OUT_ALL = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
127c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
128c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | CHANNEL_OUT_BACK_CENTER),
129c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
130c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        // input channels
1319a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_LEFT = 0x4,
1329a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_RIGHT = 0x8,
1339a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_FRONT = 0x10,
1349a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_BACK = 0x20,
1359a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_LEFT_PROCESSED = 0x40,
1369a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_RIGHT_PROCESSED = 0x80,
1379a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_FRONT_PROCESSED = 0x100,
1389a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_BACK_PROCESSED = 0x200,
1399a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_PRESSURE = 0x400,
1409a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_X_AXIS = 0x800,
1419a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_Y_AXIS = 0x1000,
1429a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_Z_AXIS = 0x2000,
1439a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_VOICE_UPLINK = 0x4000,
1449a92037bd6477533062d635b676a6c9833aab96eEric Laurent        CHANNEL_IN_VOICE_DNLINK = 0x8000,
145c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        CHANNEL_IN_MONO = CHANNEL_IN_FRONT,
146c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        CHANNEL_IN_STEREO = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT),
147c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        CHANNEL_IN_ALL = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT | CHANNEL_IN_FRONT | CHANNEL_IN_BACK|
148c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                CHANNEL_IN_LEFT_PROCESSED | CHANNEL_IN_RIGHT_PROCESSED | CHANNEL_IN_FRONT_PROCESSED | CHANNEL_IN_BACK_PROCESSED|
149c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                CHANNEL_IN_PRESSURE | CHANNEL_IN_X_AXIS | CHANNEL_IN_Y_AXIS | CHANNEL_IN_Z_AXIS |
150c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                CHANNEL_IN_VOICE_UPLINK | CHANNEL_IN_VOICE_DNLINK)
15189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    };
15289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
15389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    enum audio_mode {
15489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        MODE_INVALID = -2,
15589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        MODE_CURRENT = -1,
15689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        MODE_NORMAL = 0,
15789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        MODE_RINGTONE,
15889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        MODE_IN_CALL,
15989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        NUM_MODES  // not a valid entry, denotes end-of-list
16089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    };
16189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
16289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    enum audio_in_acoustics {
16389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        AGC_ENABLE    = 0x0001,
16489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        AGC_DISABLE   = 0,
16589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        NS_ENABLE     = 0x0002,
16689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        NS_DISABLE    = 0,
16789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        TX_IIR_ENABLE = 0x0004,
16889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        TX_DISABLE    = 0
16989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    };
17089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
17189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    /* These are static methods to control the system-wide AudioFlinger
17289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project     * only privileged processes can have access to them
17389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project     */
17489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
175c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // mute/unmute microphone
17689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static status_t muteMicrophone(bool state);
17789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static status_t isMicrophoneMuted(bool *state);
17889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
179c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // set/get master volume
18089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static status_t setMasterVolume(float value);
18189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static status_t getMasterVolume(float* volume);
182c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // mute/unmute audio outputs
183c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t setMasterMute(bool mute);
18489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static status_t getMasterMute(bool* mute);
18589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
186c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // set/get stream volume on specified output
187fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent    static status_t setStreamVolume(int stream, float value, int output);
188fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent    static status_t getStreamVolume(int stream, float* volume, int output);
189c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
190c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // mute/unmute stream
19189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static status_t setStreamMute(int stream, bool mute);
19289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static status_t getStreamMute(int stream, bool* mute);
19389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
194c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // set audio mode in audio hardware (see AudioSystem::audio_mode)
19589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static status_t setMode(int mode);
19689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
197c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // returns true if tracks are active on AudioSystem::MUSIC stream
19889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static status_t isMusicActive(bool *state);
19989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
200c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // set/get audio hardware parameters. The function accepts a list of parameters
201c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // key value pairs in the form: key1=value1;key2=value2;...
202c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // Some keys are reserved for standard parameters (See AudioParameter class).
203c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs);
204c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static String8  getParameters(audio_io_handle_t ioHandle, const String8& keys);
205c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
20689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static void setErrorCallback(audio_error_callback cb);
20789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
20889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    // helper function to obtain AudioFlinger service handle
20989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static const sp<IAudioFlinger>& get_audio_flinger();
21089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
21189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static float linearToLog(int volume);
21289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static int logToLinear(float volume);
21389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
21489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static status_t getOutputSamplingRate(int* samplingRate, int stream = DEFAULT);
21589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static status_t getOutputFrameCount(int* frameCount, int stream = DEFAULT);
21689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static status_t getOutputLatency(uint32_t* latency, int stream = DEFAULT);
21789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
21889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static bool routedToA2dpOutput(int streamType);
219c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
220c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount,
22189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        size_t* buffSize);
22289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
223f0ee6f4055e26fb35d9c526a596668a4dc9da5baEric Laurent    static status_t setVoiceVolume(float volume);
224c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
225c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    //
226c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // AudioPolicyService interface
227c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    //
228c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
229c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    enum audio_devices {
230c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        // output devices
231c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_EARPIECE = 0x1,
232c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_SPEAKER = 0x2,
233c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_WIRED_HEADSET = 0x4,
234c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_WIRED_HEADPHONE = 0x8,
235c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_BLUETOOTH_SCO = 0x10,
236c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
237c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
238c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
239c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
240c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
241c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_AUX_DIGITAL = 0x400,
242c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_FM_HEADPHONE = 0x800,
243c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_FM_SPEAKER = 0x1000,
244c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_TTY = 0x2000,
245c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_DEFAULT = 0x8000,
246c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
247c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
248c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                DEVICE_OUT_BLUETOOTH_SCO_CARKIT | DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
249c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL | DEVICE_OUT_FM_HEADPHONE |
250c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                DEVICE_OUT_FM_SPEAKER | DEVICE_OUT_TTY | DEVICE_OUT_DEFAULT),
251c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
252c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        // input devices
253c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_IN_COMMUNICATION = 0x10000,
254c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_IN_AMBIENT = 0x20000,
255c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_IN_BUILTIN_MIC = 0x40000,
256c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000,
257c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_IN_WIRED_HEADSET = 0x100000,
258c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_IN_AUX_DIGITAL = 0x200000,
259c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_IN_VOICE_CALL = 0x400000,
260c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_IN_DEFAULT = 0x80000000,
261c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
262c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_IN_ALL = (DEVICE_IN_COMMUNICATION | DEVICE_IN_AMBIENT | DEVICE_IN_BUILTIN_MIC |
263c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                DEVICE_IN_BLUETOOTH_SCO_HEADSET | DEVICE_IN_WIRED_HEADSET | DEVICE_IN_AUX_DIGITAL |
264c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                DEVICE_IN_VOICE_CALL| DEVICE_IN_DEFAULT)
265c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
266c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
267c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // device connection states used for setDeviceConnectionState()
268c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    enum device_connection_state {
269c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_STATE_UNAVAILABLE,
270c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        DEVICE_STATE_AVAILABLE,
271c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        NUM_DEVICE_STATES
272c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
273c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
274c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // request to open a direct output with getOutput() (by opposition to sharing an output with other AudioTracks)
275c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    enum output_flags {
276c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        OUTPUT_FLAG_INDIRECT = 0x0,
277c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        OUTPUT_FLAG_DIRECT = 0x1
278c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
279c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
280c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // device categories used for setForceUse()
281c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    enum forced_config {
282c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        FORCE_NONE,
283c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        FORCE_SPEAKER,
284c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        FORCE_HEADPHONES,
285c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        FORCE_BT_SCO,
286c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        FORCE_BT_A2DP,
287c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        FORCE_WIRED_ACCESSORY,
288c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        NUM_FORCE_CONFIG,
289c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        FORCE_DEFAULT = FORCE_NONE
290c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
291c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
292c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // usages used for setForceUse()
293c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    enum force_use {
294c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        FOR_COMMUNICATION,
295c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        FOR_MEDIA,
296c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        FOR_RECORD,
297c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        NUM_FORCE_USE
298c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
299c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
300c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // types of io configuration change events received with ioConfigChanged()
301c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    enum io_config_event {
302c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        OUTPUT_OPENED,
303c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        OUTPUT_CLOSED,
304c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        OUTPUT_CONFIG_CHANGED,
305c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        INPUT_OPENED,
306c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        INPUT_CLOSED,
307c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        INPUT_CONFIG_CHANGED,
308c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        STREAM_CONFIG_CHANGED,
309c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        NUM_CONFIG_EVENTS
310c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
311c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
312c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // audio output descritor used to cache output configurations in client process to avoid frequent calls
313c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // through IAudioFlinger
314c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    class OutputDescriptor {
315c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    public:
316c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        OutputDescriptor()
317c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        : samplingRate(0), format(0), channels(0), frameCount(0), latency(0)  {}
318c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
319c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        uint32_t samplingRate;
320c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        int32_t format;
321c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        int32_t channels;
322c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        size_t frameCount;
323c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        uint32_t latency;
324c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
325c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
326c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    //
327c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // IAudioPolicyService interface (see AudioPolicyInterface for method descriptions)
328c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    //
329c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t setDeviceConnectionState(audio_devices device, device_connection_state state, const char *device_address);
330c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static device_connection_state getDeviceConnectionState(audio_devices device, const char *device_address);
331c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t setPhoneState(int state);
332c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t setRingerMode(uint32_t mode, uint32_t mask);
333c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t setForceUse(force_use usage, forced_config config);
334c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static forced_config getForceUse(force_use usage);
335c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static audio_io_handle_t getOutput(stream_type stream,
336c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                        uint32_t samplingRate = 0,
337c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                        uint32_t format = FORMAT_DEFAULT,
338c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                        uint32_t channels = CHANNEL_OUT_STEREO,
339c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                        output_flags flags = OUTPUT_FLAG_INDIRECT);
340c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t startOutput(audio_io_handle_t output, AudioSystem::stream_type stream);
341c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t stopOutput(audio_io_handle_t output, AudioSystem::stream_type stream);
342c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static void releaseOutput(audio_io_handle_t output);
343c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static audio_io_handle_t getInput(int inputSource,
344c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    uint32_t samplingRate = 0,
345c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    uint32_t format = FORMAT_DEFAULT,
346c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    uint32_t channels = CHANNEL_IN_MONO,
347c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                    audio_in_acoustics acoustics = (audio_in_acoustics)0);
348c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t startInput(audio_io_handle_t input);
349c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t stopInput(audio_io_handle_t input);
350c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static void releaseInput(audio_io_handle_t input);
351c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t initStreamVolume(stream_type stream,
352c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                      int indexMin,
353c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent                                      int indexMax);
354c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t setStreamVolumeIndex(stream_type stream, int index);
355c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static status_t getStreamVolumeIndex(stream_type stream, int *index);
356c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
357c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static const sp<IAudioPolicyService>& get_audio_policy_service();
358c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
35989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    // ----------------------------------------------------------------------------
36089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
361c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static uint32_t popCount(uint32_t u);
362c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static bool isOutputDevice(audio_devices device);
363c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static bool isInputDevice(audio_devices device);
364c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static bool isA2dpDevice(audio_devices device);
365c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static bool isBluetoothScoDevice(audio_devices device);
366c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static bool isLowVisibility(stream_type stream);
367c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static bool isOutputChannel(uint32_t channel);
368c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static bool isInputChannel(uint32_t channel);
369c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static bool isValidFormat(uint32_t format);
370c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static bool isLinearPCM(uint32_t format);
371c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
37289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Projectprivate:
37389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
37489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    class AudioFlingerClient: public IBinder::DeathRecipient, public BnAudioFlingerClient
37589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    {
37689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    public:
377c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        AudioFlingerClient() {
37889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        }
379c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
38089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        // DeathRecipient
38189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        virtual void binderDied(const wp<IBinder>& who);
382c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
38389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project        // IAudioFlingerClient
384c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
385c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        // indicate a change in the configuration of an output or input: keeps the cached
386c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        // values for output/input parameters upto date in client process
387fa2877b9ea48baed934b866d2ab3658b69c4c869Eric Laurent        virtual void ioConfigChanged(int event, int ioHandle, void *param2);
38889fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    };
38989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
390c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    class AudioPolicyServiceClient: public IBinder::DeathRecipient
391c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    {
392c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    public:
393c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        AudioPolicyServiceClient() {
394c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        }
39589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
396c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        // DeathRecipient
397c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent        virtual void binderDied(const wp<IBinder>& who);
398c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    };
399c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
400c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static sp<AudioFlingerClient> gAudioFlingerClient;
401c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static sp<AudioPolicyServiceClient> gAudioPolicyServiceClient;
40289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    friend class AudioFlingerClient;
403c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    friend class AudioPolicyServiceClient;
40489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
40589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static Mutex gLock;
40689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static sp<IAudioFlinger> gAudioFlinger;
40789fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static audio_error_callback gAudioErrorCallback;
408c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
40989fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static size_t gInBuffSize;
41089fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    // previous parameters for recording buffer size queries
41189fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static uint32_t gPrevInSamplingRate;
41289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static int gPrevInFormat;
41389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project    static int gPrevInChannelCount;
41489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
415c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static sp<IAudioPolicyService> gAudioPolicyService;
416c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
417c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // mapping between stream types and outputs
418c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static DefaultKeyedVector<int, audio_io_handle_t> gStreamOutputMap;
419c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // list of output descritor containing cached parameters (sampling rate, framecount, channel count...)
420c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static DefaultKeyedVector<audio_io_handle_t, OutputDescriptor *> gOutputs;
421c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent};
422c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
423c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentclass AudioParameter {
424c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
425c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentpublic:
426c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    AudioParameter() {}
427c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    AudioParameter(const String8& keyValuePairs);
428c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    virtual ~AudioParameter();
429c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
430c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // reserved parameter keys for changeing standard parameters with setParameters() function.
431c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // Using these keys is mandatory for AudioFlinger to properly monitor audio output/input
432c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    // configuration changes and act accordingly.
433c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    //  keyRouting: to change audio routing, value is an int in AudioSystem::audio_devices
434c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    //  keySamplingRate: to change sampling rate routing, value is an int
435c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    //  keyFormat: to change audio format, value is an int in AudioSystem::audio_format
436c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    //  keyChannels: to change audio channel configuration, value is an int in AudioSystem::audio_channels
437c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    //  keyFrameCount: to change audio output frame count, value is an int
438c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static const char *keyRouting;
439c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static const char *keySamplingRate;
440c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static const char *keyFormat;
441c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static const char *keyChannels;
442c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    static const char *keyFrameCount;
443c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
444c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    String8 toString();
445c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
446c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    status_t add(const String8& key, const String8& value);
447c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    status_t addInt(const String8& key, const int value);
448c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    status_t addFloat(const String8& key, const float value);
449c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
450c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    status_t remove(const String8& key);
451c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
452c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    status_t get(const String8& key, String8& value);
453c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    status_t getInt(const String8& key, int& value);
454c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    status_t getFloat(const String8& key, float& value);
455a9c322e398a1f5fdcace3b8b73967f010b1c31caEric Laurent    status_t getAt(size_t index, String8& key, String8& value);
456c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
457c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    size_t size() { return mParameters.size(); }
458c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent
459c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurentprivate:
460c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    String8 mKeyValuePairs;
461c2f1f07084818942352c6bbfb36af9b6b330eb4eEric Laurent    KeyedVector <String8, String8> mParameters;
46289fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project};
46389fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
46489fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project};  // namespace android
46589fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project
46689fa4ad53f2f4d57adbc97ae1149fc00c9b6f3c5The Android Open Source Project#endif  /*ANDROID_AUDIOSYSTEM_H_*/
467