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     enum audio_devices {
    230         // output devices
    231         DEVICE_OUT_EARPIECE = 0x1,
    232         DEVICE_OUT_SPEAKER = 0x2,
    233         DEVICE_OUT_WIRED_HEADSET = 0x4,
    234         DEVICE_OUT_WIRED_HEADPHONE = 0x8,
    235         DEVICE_OUT_BLUETOOTH_SCO = 0x10,
    236         DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
    237         DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
    238         DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
    239         DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
    240         DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
    241         DEVICE_OUT_AUX_DIGITAL = 0x400,
    242         DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
    243         DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
    244         DEVICE_OUT_DEFAULT = 0x8000,
    245         DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
    246                 DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
    247                 DEVICE_OUT_BLUETOOTH_SCO_CARKIT | DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
    248                 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL |
    249                 DEVICE_OUT_ANLG_DOCK_HEADSET | DEVICE_OUT_DGTL_DOCK_HEADSET |
    250                 DEVICE_OUT_DEFAULT),
    251         DEVICE_OUT_ALL_A2DP = (DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
    252                 DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
    253 
    254         // input devices
    255         DEVICE_IN_COMMUNICATION = 0x10000,
    256         DEVICE_IN_AMBIENT = 0x20000,
    257         DEVICE_IN_BUILTIN_MIC = 0x40000,
    258         DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000,
    259         DEVICE_IN_WIRED_HEADSET = 0x100000,
    260         DEVICE_IN_AUX_DIGITAL = 0x200000,
    261         DEVICE_IN_VOICE_CALL = 0x400000,
    262         DEVICE_IN_BACK_MIC = 0x800000,
    263         DEVICE_IN_DEFAULT = 0x80000000,
    264 
    265         DEVICE_IN_ALL = (DEVICE_IN_COMMUNICATION | DEVICE_IN_AMBIENT | DEVICE_IN_BUILTIN_MIC |
    266                 DEVICE_IN_BLUETOOTH_SCO_HEADSET | DEVICE_IN_WIRED_HEADSET | DEVICE_IN_AUX_DIGITAL |
    267                 DEVICE_IN_VOICE_CALL | DEVICE_IN_BACK_MIC | DEVICE_IN_DEFAULT)
    268     };
    269 
    270     // request to open a direct output with getOutput() (by opposition to sharing an output with other AudioTracks)
    271     enum output_flags {
    272         OUTPUT_FLAG_INDIRECT = 0x0,
    273         OUTPUT_FLAG_DIRECT = 0x1
    274     };
    275 
    276     // device categories used for setForceUse()
    277     enum forced_config {
    278         FORCE_NONE,
    279         FORCE_SPEAKER,
    280         FORCE_HEADPHONES,
    281         FORCE_BT_SCO,
    282         FORCE_BT_A2DP,
    283         FORCE_WIRED_ACCESSORY,
    284         FORCE_BT_CAR_DOCK,
    285         FORCE_BT_DESK_DOCK,
    286         FORCE_ANALOG_DOCK,
    287         FORCE_DIGITAL_DOCK,
    288         NUM_FORCE_CONFIG,
    289         FORCE_DEFAULT = FORCE_NONE
    290     };
    291 
    292     // usages used for setForceUse()
    293     enum force_use {
    294         FOR_COMMUNICATION,
    295         FOR_MEDIA,
    296         FOR_RECORD,
    297         FOR_DOCK,
    298         NUM_FORCE_USE
    299     };
    300 
    301     //
    302     // AudioPolicyService interface
    303     //
    304 
    305     // device connection states used for setDeviceConnectionState()
    306     enum device_connection_state {
    307         DEVICE_STATE_UNAVAILABLE,
    308         DEVICE_STATE_AVAILABLE,
    309         NUM_DEVICE_STATES
    310     };
    311 
    312 #endif
    313 
    314     static uint32_t popCount(uint32_t u) {
    315         return popcount(u);
    316     }
    317 
    318 #if 1
    319     static bool isOutputDevice(audio_devices device) {
    320         return audio_is_output_device((audio_devices_t)device);
    321     }
    322     static bool isInputDevice(audio_devices device) {
    323         return audio_is_input_device((audio_devices_t)device);
    324     }
    325     static bool isA2dpDevice(audio_devices device) {
    326         return audio_is_a2dp_device((audio_devices_t)device);
    327     }
    328     static bool isBluetoothScoDevice(audio_devices device) {
    329         return audio_is_bluetooth_sco_device((audio_devices_t)device);
    330     }
    331     static bool isLowVisibility(stream_type stream) {
    332         return audio_is_low_visibility((audio_stream_type_t)stream);
    333     }
    334     static bool isValidFormat(uint32_t format) {
    335         return audio_is_valid_format(format);
    336     }
    337     static bool isLinearPCM(uint32_t format) {
    338         return audio_is_linear_pcm(format);
    339     }
    340     static bool isOutputChannel(uint32_t channel) {
    341         return audio_is_output_channel(channel);
    342     }
    343     static bool isInputChannel(uint32_t channel) {
    344         return audio_is_input_channel(channel);
    345     }
    346 
    347 #endif
    348 };
    349 
    350 };  // namespace android
    351 
    352 #endif // ANDROID_AUDIOSYSTEM_LEGACY_H_
    353