Home | History | Annotate | Download | only in hardware_legacy
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef ANDROID_AUDIOSYSTEM_LEGACY_H_
     18 #define ANDROID_AUDIOSYSTEM_LEGACY_H_
     19 
     20 #include <utils/Errors.h>
     21 #include <media/AudioParameter.h>
     22 
     23 #include <system/audio.h>
     24 #include <system/audio_policy.h>
     25 
     26 namespace android_audio_legacy {
     27 
     28 using android::status_t;
     29 using android::AudioParameter;
     30 
     31 enum {
     32     OK                  = android::OK,
     33     NO_ERROR            = android::NO_ERROR,
     34 
     35     UNKNOWN_ERROR       = android::UNKNOWN_ERROR,
     36 
     37     NO_MEMORY           = android::NO_MEMORY,
     38     INVALID_OPERATION   = android::INVALID_OPERATION,
     39     BAD_VALUE           = android::BAD_VALUE,
     40     BAD_TYPE            = android::BAD_TYPE,
     41     NAME_NOT_FOUND      = android::NAME_NOT_FOUND,
     42     PERMISSION_DENIED   = android::PERMISSION_DENIED,
     43     NO_INIT             = android::NO_INIT,
     44     ALREADY_EXISTS      = android::ALREADY_EXISTS,
     45     DEAD_OBJECT         = android::DEAD_OBJECT,
     46     FAILED_TRANSACTION  = android::FAILED_TRANSACTION,
     47     JPARKS_BROKE_IT     = android::JPARKS_BROKE_IT,
     48     BAD_INDEX           = android::BAD_INDEX,
     49     NOT_ENOUGH_DATA     = android::NOT_ENOUGH_DATA,
     50     WOULD_BLOCK         = android::WOULD_BLOCK,
     51     TIMED_OUT           = android::TIMED_OUT,
     52     UNKNOWN_TRANSACTION = android::UNKNOWN_TRANSACTION,
     53 };
     54 
     55 enum audio_source {
     56     AUDIO_SOURCE_DEFAULT = 0,
     57     AUDIO_SOURCE_MIC = 1,
     58     AUDIO_SOURCE_VOICE_UPLINK = 2,
     59     AUDIO_SOURCE_VOICE_DOWNLINK = 3,
     60     AUDIO_SOURCE_VOICE_CALL = 4,
     61     AUDIO_SOURCE_CAMCORDER = 5,
     62     AUDIO_SOURCE_VOICE_RECOGNITION = 6,
     63     AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
     64     AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_COMMUNICATION,
     65 
     66     AUDIO_SOURCE_LIST_END  // must be last - used to validate audio source type
     67 };
     68 
     69 class AudioSystem {
     70 public:
     71 #if 1
     72     enum stream_type {
     73         DEFAULT          =-1,
     74         VOICE_CALL       = 0,
     75         SYSTEM           = 1,
     76         RING             = 2,
     77         MUSIC            = 3,
     78         ALARM            = 4,
     79         NOTIFICATION     = 5,
     80         BLUETOOTH_SCO    = 6,
     81         ENFORCED_AUDIBLE = 7, // Sounds that cannot be muted by user and must be routed to speaker
     82         DTMF             = 8,
     83         TTS              = 9,
     84         NUM_STREAM_TYPES
     85     };
     86 
     87     // Audio sub formats (see AudioSystem::audio_format).
     88     enum pcm_sub_format {
     89         PCM_SUB_16_BIT          = 0x1, // must be 1 for backward compatibility
     90         PCM_SUB_8_BIT           = 0x2, // must be 2 for backward compatibility
     91     };
     92 
     93     enum audio_sessions {
     94         SESSION_OUTPUT_STAGE = AUDIO_SESSION_OUTPUT_STAGE,
     95         SESSION_OUTPUT_MIX = AUDIO_SESSION_OUTPUT_MIX,
     96     };
     97 
     98     // MP3 sub format field definition : can use 11 LSBs in the same way as MP3 frame header to specify
     99     // bit rate, stereo mode, version...
    100     enum mp3_sub_format {
    101         //TODO
    102     };
    103 
    104     // AMR NB/WB sub format field definition: specify frame block interleaving, bandwidth efficient or octet aligned,
    105     // encoding mode for recording...
    106     enum amr_sub_format {
    107         //TODO
    108     };
    109 
    110     // AAC sub format field definition: specify profile or bitrate for recording...
    111     enum aac_sub_format {
    112         //TODO
    113     };
    114 
    115     // VORBIS sub format field definition: specify quality for recording...
    116     enum vorbis_sub_format {
    117         //TODO
    118     };
    119 
    120     // Audio format consists in a main format field (upper 8 bits) and a sub format field (lower 24 bits).
    121     // The main format indicates the main codec type. The sub format field indicates options and parameters
    122     // for each format. The sub format is mainly used for record to indicate for instance the requested bitrate
    123     // or profile. It can also be used for certain formats to give informations not present in the encoded
    124     // audio stream (e.g. octet alignement for AMR).
    125     enum audio_format {
    126         INVALID_FORMAT      = -1,
    127         FORMAT_DEFAULT      = 0,
    128         PCM                 = 0x00000000, // must be 0 for backward compatibility
    129         MP3                 = 0x01000000,
    130         AMR_NB              = 0x02000000,
    131         AMR_WB              = 0x03000000,
    132         AAC                 = 0x04000000,
    133         HE_AAC_V1           = 0x05000000,
    134         HE_AAC_V2           = 0x06000000,
    135         VORBIS              = 0x07000000,
    136         MAIN_FORMAT_MASK    = 0xFF000000,
    137         SUB_FORMAT_MASK     = 0x00FFFFFF,
    138         // Aliases
    139         PCM_16_BIT          = (PCM|PCM_SUB_16_BIT),
    140         PCM_8_BIT          = (PCM|PCM_SUB_8_BIT)
    141     };
    142 
    143     enum audio_channels {
    144         // output channels
    145         CHANNEL_OUT_FRONT_LEFT            = 0x1,
    146         CHANNEL_OUT_FRONT_RIGHT           = 0x2,
    147         CHANNEL_OUT_FRONT_CENTER          = 0x4,
    148         CHANNEL_OUT_LOW_FREQUENCY         = 0x8,
    149         CHANNEL_OUT_BACK_LEFT             = 0x10,
    150         CHANNEL_OUT_BACK_RIGHT            = 0x20,
    151         CHANNEL_OUT_FRONT_LEFT_OF_CENTER  = 0x40,
    152         CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80,
    153         CHANNEL_OUT_BACK_CENTER           = 0x100,
    154         CHANNEL_OUT_SIDE_LEFT             = 0x200,
    155         CHANNEL_OUT_SIDE_RIGHT            = 0x400,
    156         CHANNEL_OUT_TOP_CENTER            = 0x800,
    157         CHANNEL_OUT_TOP_FRONT_LEFT        = 0x1000,
    158         CHANNEL_OUT_TOP_FRONT_CENTER      = 0x2000,
    159         CHANNEL_OUT_TOP_FRONT_RIGHT       = 0x4000,
    160         CHANNEL_OUT_TOP_BACK_LEFT         = 0x8000,
    161         CHANNEL_OUT_TOP_BACK_CENTER       = 0x10000,
    162         CHANNEL_OUT_TOP_BACK_RIGHT        = 0x20000,
    163 
    164         CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT,
    165         CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT),
    166         CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
    167                 CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
    168         CHANNEL_OUT_SURROUND = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
    169                 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_BACK_CENTER),
    170         CHANNEL_OUT_5POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
    171                 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY |
    172                 CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT),
    173         // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1
    174         CHANNEL_OUT_7POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
    175                 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY |
    176                 CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
    177                 CHANNEL_OUT_SIDE_LEFT | CHANNEL_OUT_SIDE_RIGHT),
    178         CHANNEL_OUT_ALL = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
    179                 CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT |
    180                 CHANNEL_OUT_BACK_RIGHT | CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
    181                 CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | CHANNEL_OUT_BACK_CENTER |
    182                 CHANNEL_OUT_SIDE_LEFT | CHANNEL_OUT_SIDE_RIGHT | CHANNEL_OUT_TOP_CENTER |
    183                 CHANNEL_OUT_TOP_FRONT_LEFT | CHANNEL_OUT_TOP_FRONT_CENTER |
    184                 CHANNEL_OUT_TOP_FRONT_RIGHT | CHANNEL_OUT_TOP_BACK_LEFT |
    185                 CHANNEL_OUT_TOP_BACK_CENTER | CHANNEL_OUT_TOP_BACK_RIGHT),
    186 
    187         // input channels
    188         CHANNEL_IN_LEFT = 0x4,
    189         CHANNEL_IN_RIGHT = 0x8,
    190         CHANNEL_IN_FRONT = 0x10,
    191         CHANNEL_IN_BACK = 0x20,
    192         CHANNEL_IN_LEFT_PROCESSED = 0x40,
    193         CHANNEL_IN_RIGHT_PROCESSED = 0x80,
    194         CHANNEL_IN_FRONT_PROCESSED = 0x100,
    195         CHANNEL_IN_BACK_PROCESSED = 0x200,
    196         CHANNEL_IN_PRESSURE = 0x400,
    197         CHANNEL_IN_X_AXIS = 0x800,
    198         CHANNEL_IN_Y_AXIS = 0x1000,
    199         CHANNEL_IN_Z_AXIS = 0x2000,
    200         CHANNEL_IN_VOICE_UPLINK = 0x4000,
    201         CHANNEL_IN_VOICE_DNLINK = 0x8000,
    202         CHANNEL_IN_MONO = CHANNEL_IN_FRONT,
    203         CHANNEL_IN_STEREO = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT),
    204         CHANNEL_IN_ALL = (CHANNEL_IN_LEFT | CHANNEL_IN_RIGHT | CHANNEL_IN_FRONT | CHANNEL_IN_BACK|
    205                 CHANNEL_IN_LEFT_PROCESSED | CHANNEL_IN_RIGHT_PROCESSED | CHANNEL_IN_FRONT_PROCESSED | CHANNEL_IN_BACK_PROCESSED|
    206                 CHANNEL_IN_PRESSURE | CHANNEL_IN_X_AXIS | CHANNEL_IN_Y_AXIS | CHANNEL_IN_Z_AXIS |
    207                 CHANNEL_IN_VOICE_UPLINK | CHANNEL_IN_VOICE_DNLINK)
    208     };
    209 
    210     enum audio_mode {
    211         MODE_INVALID = -2,
    212         MODE_CURRENT = -1,
    213         MODE_NORMAL = 0,
    214         MODE_RINGTONE,
    215         MODE_IN_CALL,
    216         MODE_IN_COMMUNICATION,
    217         NUM_MODES  // not a valid entry, denotes end-of-list
    218     };
    219 
    220     enum audio_in_acoustics {
    221         AGC_ENABLE    = 0x0001,
    222         AGC_DISABLE   = 0,
    223         NS_ENABLE     = 0x0002,
    224         NS_DISABLE    = 0,
    225         TX_IIR_ENABLE = 0x0004,
    226         TX_DISABLE    = 0
    227     };
    228 
    229     // DO NOT USE: the "audio_devices" enumeration below is obsolete, use type "audio_devices_t" and
    230     //   audio device enumeration from system/audio.h instead.
    231     enum audio_devices {
    232         // output devices
    233         DEVICE_OUT_EARPIECE = 0x1,
    234         DEVICE_OUT_SPEAKER = 0x2,
    235         DEVICE_OUT_WIRED_HEADSET = 0x4,
    236         DEVICE_OUT_WIRED_HEADPHONE = 0x8,
    237         DEVICE_OUT_BLUETOOTH_SCO = 0x10,
    238         DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
    239         DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
    240         DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
    241         DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
    242         DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
    243         DEVICE_OUT_AUX_DIGITAL = 0x400,
    244         DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
    245         DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
    246         DEVICE_OUT_DEFAULT = 0x8000,
    247         DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
    248                 DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
    249                 DEVICE_OUT_BLUETOOTH_SCO_CARKIT | DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
    250                 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL |
    251                 DEVICE_OUT_ANLG_DOCK_HEADSET | DEVICE_OUT_DGTL_DOCK_HEADSET |
    252                 DEVICE_OUT_DEFAULT),
    253         DEVICE_OUT_ALL_A2DP = (DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
    254                 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
    255 
    256         // input devices
    257         DEVICE_IN_COMMUNICATION = 0x10000,
    258         DEVICE_IN_AMBIENT = 0x20000,
    259         DEVICE_IN_BUILTIN_MIC = 0x40000,
    260         DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000,
    261         DEVICE_IN_WIRED_HEADSET = 0x100000,
    262         DEVICE_IN_AUX_DIGITAL = 0x200000,
    263         DEVICE_IN_VOICE_CALL = 0x400000,
    264         DEVICE_IN_BACK_MIC = 0x800000,
    265         DEVICE_IN_DEFAULT = 0x80000000,
    266 
    267         DEVICE_IN_ALL = (DEVICE_IN_COMMUNICATION | DEVICE_IN_AMBIENT | DEVICE_IN_BUILTIN_MIC |
    268                 DEVICE_IN_BLUETOOTH_SCO_HEADSET | DEVICE_IN_WIRED_HEADSET | DEVICE_IN_AUX_DIGITAL |
    269                 DEVICE_IN_VOICE_CALL | DEVICE_IN_BACK_MIC | DEVICE_IN_DEFAULT)
    270     };
    271 
    272     // request to open a direct output with getOutput() (by opposition to sharing an output with other AudioTracks)
    273     enum output_flags {
    274         OUTPUT_FLAG_INDIRECT = 0x0,
    275         OUTPUT_FLAG_DIRECT = 0x1
    276     };
    277 
    278     // device categories used for setForceUse()
    279     enum forced_config {
    280         FORCE_NONE,
    281         FORCE_SPEAKER,
    282         FORCE_HEADPHONES,
    283         FORCE_BT_SCO,
    284         FORCE_BT_A2DP,
    285         FORCE_WIRED_ACCESSORY,
    286         FORCE_BT_CAR_DOCK,
    287         FORCE_BT_DESK_DOCK,
    288         FORCE_ANALOG_DOCK,
    289         FORCE_DIGITAL_DOCK,
    290         FORCE_NO_BT_A2DP,
    291         FORCE_SYSTEM_ENFORCED,
    292         NUM_FORCE_CONFIG,
    293         FORCE_DEFAULT = FORCE_NONE
    294     };
    295 
    296     // usages used for setForceUse()
    297     enum force_use {
    298         FOR_COMMUNICATION,
    299         FOR_MEDIA,
    300         FOR_RECORD,
    301         FOR_DOCK,
    302         FOR_SYSTEM,
    303         NUM_FORCE_USE
    304     };
    305 
    306     //
    307     // AudioPolicyService interface
    308     //
    309 
    310     // device connection states used for setDeviceConnectionState()
    311     enum device_connection_state {
    312         DEVICE_STATE_UNAVAILABLE,
    313         DEVICE_STATE_AVAILABLE,
    314         NUM_DEVICE_STATES
    315     };
    316 
    317 #endif
    318 
    319     static uint32_t popCount(uint32_t u) {
    320         return popcount(u);
    321     }
    322 
    323 #if 1
    324     static bool isOutputDevice(audio_devices device) {
    325         if ((popcount(device) == 1) && ((device & ~DEVICE_OUT_ALL) == 0))
    326              return true;
    327          else
    328              return false;
    329     }
    330     static bool isInputDevice(audio_devices device) {
    331         if ((popcount(device) == 1) && ((device & ~DEVICE_IN_ALL) == 0))
    332              return true;
    333          else
    334              return false;
    335     }
    336     static bool isA2dpDevice(audio_devices device) {
    337         return audio_is_a2dp_device((audio_devices_t)device);
    338     }
    339     static bool isBluetoothScoDevice(audio_devices device) {
    340         return audio_is_bluetooth_sco_device((audio_devices_t)device);
    341     }
    342     static bool isLowVisibility(stream_type stream) {
    343         return audio_is_low_visibility((audio_stream_type_t)stream);
    344     }
    345     static bool isValidFormat(uint32_t format) {
    346         return audio_is_valid_format((audio_format_t) format);
    347     }
    348     static bool isLinearPCM(uint32_t format) {
    349         return audio_is_linear_pcm((audio_format_t) format);
    350     }
    351     static bool isOutputChannel(uint32_t channel) {
    352         return audio_is_output_channel(channel);
    353     }
    354     static bool isInputChannel(uint32_t channel) {
    355         return audio_is_input_channel(channel);
    356     }
    357 
    358 #endif
    359 };
    360 
    361 };  // namespace android
    362 
    363 #endif // ANDROID_AUDIOSYSTEM_LEGACY_H_
    364