Home | History | Annotate | Download | only in audio_a2dp_hw
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2009-2012 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 
     19 /*****************************************************************************
     20  *
     21  *  Filename:      audio_a2dp_hw.h
     22  *
     23  *  Description:
     24  *
     25  *****************************************************************************/
     26 
     27 #ifndef AUDIO_A2DP_HW_H
     28 #define AUDIO_A2DP_HW_H
     29 
     30 /*****************************************************************************
     31 **  Constants & Macros
     32 ******************************************************************************/
     33 
     34 #define A2DP_AUDIO_HARDWARE_INTERFACE "audio.a2dp"
     35 #define A2DP_CTRL_PATH "/data/misc/bluedroid/.a2dp_ctrl"
     36 #define A2DP_DATA_PATH "/data/misc/bluedroid/.a2dp_data"
     37 
     38 #define AUDIO_STREAM_DEFAULT_RATE          44100
     39 #define AUDIO_STREAM_DEFAULT_FORMAT        AUDIO_FORMAT_PCM_16_BIT
     40 #define AUDIO_STREAM_DEFAULT_CHANNEL_FLAG  AUDIO_CHANNEL_OUT_STEREO
     41 
     42 // AUDIO_STREAM_OUTPUT_BUFFER_SZ controls the size of the audio socket buffer.
     43 // If one assumes the write buffer is always full during normal BT playback,
     44 // then increasing this value increases our playback latency.
     45 //
     46 // FIXME: AUDIO_STREAM_OUTPUT_BUFFER_SZ should be controlled by the actual audio
     47 // sample rate rather than being constant.
     48 //
     49 // FIXME: The BT HAL should consume data at a constant rate.
     50 // AudioFlinger assumes that the HAL draws data at a constant rate, which is true
     51 // for most audio devices; however, the BT engine reads data at a variable rate
     52 // (over the short term), which confuses both AudioFlinger as well as applications
     53 // which deliver data at a (generally) fixed rate.
     54 //
     55 // 20 * 512 is not sufficient size to smooth the variability for some BT devices,
     56 // resulting in mixer sleep and throttling. We increase this to 28 * 512 to help
     57 // reduce the effect of variable data consumption.
     58 #define AUDIO_STREAM_OUTPUT_BUFFER_SZ      (28*512)
     59 
     60 // AUDIO_STREAM_OUTPUT_BUFFER_PERIODS controls how the socket buffer is divided
     61 // for AudioFlinger data delivery. The AudioFlinger mixer delivers data in chunks
     62 // of AUDIO_STREAM_OUTPUT_BUFFER_SZ / AUDIO_STREAM_OUTPUT_BUFFER_PERIODS. If
     63 // the number of periods is 2, the socket buffer represents "double buffering"
     64 // of the AudioFlinger mixer buffer.
     65 //
     66 // In general, AUDIO_STREAM_OUTPUT_BUFFER_PERIODS * 16 * 4 should be a divisor of
     67 // AUDIO_STREAM_OUTPUT_BUFFER_SZ.
     68 //
     69 // These values should be chosen such that
     70 //
     71 // AUDIO_STREAM_BUFFER_SIZE * 1000 / (AUDIO_STREAM_OUTPUT_BUFFER_PERIODS
     72 //         * AUDIO_STREAM_DEFAULT_RATE * 4) > 20 (ms)
     73 //
     74 // to avoid introducing the FastMixer in AudioFlinger. Using the FastMixer results in
     75 // unnecessary latency and CPU overhead for Bluetooth.
     76 #define AUDIO_STREAM_OUTPUT_BUFFER_PERIODS 4
     77 
     78 #define AUDIO_SKT_DISCONNECTED             (-1)
     79 
     80 typedef enum {
     81     A2DP_CTRL_CMD_NONE,
     82     A2DP_CTRL_CMD_CHECK_READY,
     83     A2DP_CTRL_CMD_START,
     84     A2DP_CTRL_CMD_STOP,
     85     A2DP_CTRL_CMD_SUSPEND,
     86     A2DP_CTRL_GET_AUDIO_CONFIG,
     87     A2DP_CTRL_CMD_OFFLOAD_START,
     88 } tA2DP_CTRL_CMD;
     89 
     90 typedef enum {
     91     A2DP_CTRL_ACK_SUCCESS,
     92     A2DP_CTRL_ACK_FAILURE,
     93     A2DP_CTRL_ACK_INCALL_FAILURE, /* Failure when in Call*/
     94     A2DP_CTRL_ACK_UNSUPPORTED
     95 } tA2DP_CTRL_ACK;
     96 
     97 
     98 /*****************************************************************************
     99 **  Type definitions for callback functions
    100 ******************************************************************************/
    101 
    102 /*****************************************************************************
    103 **  Type definitions and return values
    104 ******************************************************************************/
    105 
    106 /*****************************************************************************
    107 **  Extern variables and functions
    108 ******************************************************************************/
    109 
    110 /*****************************************************************************
    111 **  Functions
    112 ******************************************************************************/
    113 
    114 
    115 /*****************************************************************************
    116 **
    117 ** Function
    118 **
    119 ** Description
    120 **
    121 ** Returns
    122 **
    123 ******************************************************************************/
    124 
    125 #endif /* A2DP_AUDIO_HW_H */
    126 
    127