/*  Copyright (C) 2016-2017, The Linux Foundation. All rights reserved.
 *
 *  Not a Contribution
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted (subject to the limitations in the
 *  disclaimer below) provided that the following conditions are met:

      * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.

      * Redistributions in binary form must reproduce the above
        copyright notice, this list of conditions and the following
        disclaimer in the documentation and/or other materials provided
        with the distribution.

      * Neither the name of The Linux Foundation nor the names of its
        contributors may be used to endorse or promote products derived
        from this software without specific prior written permission.

 *  NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
 *  GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
 *  HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 *****************************************************************************/
/*****************************************************************************
 *  Copyright (C) 2009-2012 Broadcom Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/
/*      bthost_ipc.c
 *
 *  Description:   Implements IPC interface between HAL and BT host
 *
 *****************************************************************************/
#include <time.h>
#include <unistd.h>

#include "ldac_level_bit_rate_lookup.h"
#include "bthost_ipc.h"
#include <errno.h>
#include <inttypes.h>
#include <pthread.h>
#include <stdint.h>
#include <sys/errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <system/audio.h>
#include <hardware/audio.h>

#include <hardware/hardware.h>
#include <log/log.h>
#include <cutils/properties.h>

#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "bthost_ipc"

bool DEBUG = false;
static int bt_split_a2dp_enabled = 0;
/*****************************************************************************
**  Constants & Macros
******************************************************************************/
/* Below two values adds up to 8 sec retry to address IOT issues*/
#define STREAM_START_MAX_RETRY_COUNT 10
#define STREAM_START_MAX_RETRY_LOOPER 8
#define CTRL_CHAN_RETRY_COUNT 3
#define CHECK_A2DP_READY_MAX_COUNT 20

#define CASE_RETURN_STR(const) case const: return #const;

#define FNLOG()             ALOGW(LOG_TAG, "%s", __FUNCTION__);
#define DEBUG(fmt, ...)     ALOGD(LOG_TAG, "%s: " fmt,__FUNCTION__, ## __VA_ARGS__)
#define INFO(fmt, ...)      ALOGI(LOG_TAG, "%s: " fmt,__FUNCTION__, ## __VA_ARGS__)
#define WARN(fmt, ...)      ALOGW(LOG_TAG, "%s: " fmt,__FUNCTION__, ## __VA_ARGS__)
#define ERROR(fmt, ...)     ALOGE(LOG_TAG, "%s: " fmt,__FUNCTION__, ## __VA_ARGS__)

#define ASSERTC(cond, msg, val) if (!(cond)) {ERROR("### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);}

/*****************************************************************************
**  Local type definitions
******************************************************************************/

struct a2dp_stream_common audio_stream;
bt_lib_callback_t *stack_cb = NULL;
static volatile unsigned char ack_recvd = 0;
pthread_cond_t ack_cond = PTHREAD_COND_INITIALIZER;
static int test = 0;
static bool update_initial_sink_latency = false;
int wait_for_stack_response(uint8_t time_to_wait);
bool resp_received = false;
static char a2dp_hal_imp[PROPERTY_VALUE_MAX] = "false";
/*****************************************************************************
**  Static functions
******************************************************************************/

audio_sbc_encoder_config_t sbc_codec;
audio_aptx_encoder_config_t aptx_codec;
audio_aptx_adaptive_encoder_config_t aptx_adaptive_codec;
audio_aptx_tws_encoder_config_t aptx_tws_codec;
audio_aac_encoder_config_t aac_codec;
audio_ldac_encoder_config_t ldac_codec;
audio_celt_encoder_config_t celt_codec;
/*****************************************************************************
**  Functions
******************************************************************************/
void a2dp_open_ctrl_path(struct a2dp_stream_common *common);
void ldac_codec_parser(uint8_t *codec_cfg);
/*****************************************************************************
**   Miscellaneous helper functions
******************************************************************************/
static const char* dump_a2dp_ctrl_event(char event)
{
    switch(event)
    {
        CASE_RETURN_STR(A2DP_CTRL_CMD_NONE)
        CASE_RETURN_STR(A2DP_CTRL_CMD_CHECK_READY)
        CASE_RETURN_STR(A2DP_CTRL_CMD_START)
        CASE_RETURN_STR(A2DP_CTRL_CMD_STOP)
        CASE_RETURN_STR(A2DP_CTRL_CMD_SUSPEND)
        CASE_RETURN_STR(A2DP_CTRL_CMD_OFFLOAD_SUPPORTED)
        CASE_RETURN_STR(A2DP_CTRL_CMD_OFFLOAD_NOT_SUPPORTED)
        CASE_RETURN_STR(A2DP_CTRL_CMD_CHECK_STREAM_STARTED)
        CASE_RETURN_STR(A2DP_CTRL_GET_CODEC_CONFIG)
        CASE_RETURN_STR(A2DP_CTRL_GET_MULTICAST_STATUS)
        CASE_RETURN_STR(A2DP_CTRL_GET_CONNECTION_STATUS)
        default:
            return "UNKNOWN MSG ID";
    }
}

static const char* dump_a2dp_ctrl_ack(tA2DP_CTRL_ACK resp)
{
    switch(resp)
    {
        CASE_RETURN_STR(A2DP_CTRL_ACK_SUCCESS)
        CASE_RETURN_STR(A2DP_CTRL_ACK_FAILURE)
        CASE_RETURN_STR(A2DP_CTRL_ACK_INCALL_FAILURE)
        CASE_RETURN_STR(A2DP_CTRL_ACK_UNSUPPORTED)
        CASE_RETURN_STR(A2DP_CTRL_ACK_PENDING)
        CASE_RETURN_STR(A2DP_CTRL_ACK_DISCONNECT_IN_PROGRESS)
        CASE_RETURN_STR(A2DP_CTRL_ACK_PREVIOUS_COMMAND_PENDING)
        CASE_RETURN_STR(A2DP_CTRL_SKT_DISCONNECTED)
        CASE_RETURN_STR(A2DP_CTRL_ACK_UNKNOWN)
        default:
            return "UNKNOWN ACK ID";
    }
}

static const char* dump_a2dp_hal_state(int event)
{
    switch(event)
    {
        CASE_RETURN_STR(AUDIO_A2DP_STATE_STARTING)
        CASE_RETURN_STR(AUDIO_A2DP_STATE_STARTED)
        CASE_RETURN_STR(AUDIO_A2DP_STATE_STOPPING)
        CASE_RETURN_STR(AUDIO_A2DP_STATE_STOPPED)
        CASE_RETURN_STR(AUDIO_A2DP_STATE_SUSPENDED)
        CASE_RETURN_STR(AUDIO_A2DP_STATE_STANDBY)
        default:
            return "UNKNOWN STATE ID";
    }
}
static void* a2dp_codec_parser(uint8_t *codec_cfg, audio_format_t *codec_type,
                                                   uint32_t *sample_freq)
{
    char byte,len;
    uint8_t *p_cfg = codec_cfg;
    ALOGW("%s",__func__);
    ALOGW("%s: codec_type = %x",__func__, codec_cfg[CODEC_OFFSET]);
    if (codec_cfg[CODEC_OFFSET] == CODEC_TYPE_PCM)
    {
        *codec_type = AUDIO_FORMAT_PCM_16_BIT;
        //For the time being Audio does not require any param to be passed for PCM so returning null
        return NULL;
    }
    else if (codec_cfg[CODEC_OFFSET] == CODEC_TYPE_SBC)
    {
        memset(&sbc_codec,0,sizeof(audio_sbc_encoder_config_t));
        p_cfg++;//skip dev idx
        len = *p_cfg++;
        p_cfg++;//skip media type
        len--;
        p_cfg++;
        len--;
        byte = *p_cfg++;
        len--;
        switch (byte & A2D_SBC_FREQ_MASK)
        {
            case A2D_SBC_SAMP_FREQ_48:
                 sbc_codec.sampling_rate = 48000;
                 break;
            case A2D_SBC_SAMP_FREQ_44:
                 sbc_codec.sampling_rate = 44100;
                 break;
            case A2D_SBC_SAMP_FREQ_32:
                 sbc_codec.sampling_rate = 3200;
                 break;
            case A2D_SBC_SAMP_FREQ_16:
                 sbc_codec.sampling_rate = 16000;
                 break;
            default:
                 ALOGE("SBC:Unkown sampling rate");
        }

        switch (byte & A2D_SBC_CHN_MASK)
        {
            case A2D_SBC_CH_MD_JOINT:
                 sbc_codec.channels = 3;
                 break;
            case A2D_SBC_CH_MD_STEREO:
                 sbc_codec.channels = 2;
                 break;
            case A2D_SBC_CH_MD_DUAL:
                 sbc_codec.channels = 1;
                 break;
            case A2D_SBC_CH_MD_MONO:
                 sbc_codec.channels = 0;
                 break;
            default:
                 ALOGE("SBC:Unknow channel mode");
        }
        byte = *p_cfg++;
        len--;
        switch (byte & A2D_SBC_BLK_MASK)
        {
            case A2D_SBC_BLOCKS_16:
                sbc_codec.blk_len = 16;
                break;
            case A2D_SBC_BLOCKS_12:
                sbc_codec.blk_len = 12;
                break;
            case A2D_SBC_BLOCKS_8:
                sbc_codec.blk_len = 8;
                break;
            case A2D_SBC_BLOCKS_4:
                sbc_codec.blk_len = 4;
                break;
            default:
                ALOGE("SBD:Unknown block length");
        }

        switch (byte & A2D_SBC_SUBBAND_MASK)
        {
            case A2D_SBC_SUBBAND_8:
                sbc_codec.subband = 8;
                break;
            case A2D_SBC_SUBBAND_4:
                sbc_codec.subband = 4;
                break;
            default:
                ALOGE("SBD:Unknown subband");
        }
        switch (byte & A2D_SBC_ALLOC_MASK)
        {
            case A2D_SBC_ALLOC_MD_L:
                sbc_codec.alloc = 1;
                break;
            case A2D_SBC_ALLOC_MD_S:
                sbc_codec.alloc = 2;
            default:
                ALOGE("SBD:Unknown alloc method");
        }
        sbc_codec.min_bitpool = *p_cfg++;
        len--;
        sbc_codec.max_bitpool = *p_cfg++;
        len--;
        if (len == 0)
        {
            ALOGW("Copied codec config");
        }
        p_cfg += 2; //skip mtu
        sbc_codec.bitrate = *p_cfg++;
        sbc_codec.bitrate |= (*p_cfg++ << 8);
        sbc_codec.bitrate |= (*p_cfg++ << 16);
        sbc_codec.bitrate |= (*p_cfg++ << 24);
        sbc_codec.bits_per_sample = *(uint32_t *)p_cfg;
        *codec_type = AUDIO_FORMAT_SBC;

        if(sample_freq) *sample_freq = sbc_codec.sampling_rate;

        ALOGW("SBC: Done copying full codec config bits_per_sample : %d", sbc_codec.bits_per_sample);
        return ((void *)(&sbc_codec));
    } else if (codec_cfg[CODEC_OFFSET] == CODEC_TYPE_AAC)
    {
        uint16_t aac_samp_freq = 0;
        uint32_t aac_bit_rate = 0;
        memset(&aac_codec,0,sizeof(audio_aac_encoder_config_t));
        p_cfg++;//skip dev idx
        len = *p_cfg++;
        p_cfg++;//skip media type
        len--;
        p_cfg++;//skip codec type
        len--;
        byte = *p_cfg++;
        len--;
        switch (byte & A2D_AAC_IE_OBJ_TYPE_MSK)
        {
            case A2D_AAC_IE_OBJ_TYPE_MPEG_2_AAC_LC:
                aac_codec.enc_mode = AUDIO_FORMAT_AAC_SUB_LC;
                break;
            case A2D_AAC_IE_OBJ_TYPE_MPEG_4_AAC_LC:
                aac_codec.enc_mode = AUDIO_FORMAT_AAC_SUB_LC;
                break;
            case A2D_AAC_IE_OBJ_TYPE_MPEG_4_AAC_LTP:
                aac_codec.enc_mode = AUDIO_FORMAT_AAC_SUB_LTP;
                break;
            case A2D_AAC_IE_OBJ_TYPE_MPEG_4_AAC_SCA:
                aac_codec.enc_mode = AUDIO_FORMAT_AAC_SUB_SCALABLE;
                break;
            default:
                ALOGE("AAC:Unknown encoder mode");
        }
        //USE 0 (AAC_LC) as hardcoded value till Audio
        //define constants
        aac_codec.enc_mode = 0;
        //USE LOAS(1) or LATM(4) hardcoded values till
        //Audio define proper constants
        aac_codec.format_flag = 4;
        byte = *p_cfg++;
        len--;
        aac_samp_freq = byte << 8; //1st byte of sample_freq
        byte = *p_cfg++;
        len--;
        aac_samp_freq |= byte & 0x00F0; //1st nibble of second byte of samp_freq

        switch (aac_samp_freq) {
            case 0x8000: aac_codec.sampling_rate = 8000; break;
            case 0x4000: aac_codec.sampling_rate = 11025; break;
            case 0x2000: aac_codec.sampling_rate = 12000; break;
            case 0x1000: aac_codec.sampling_rate = 16000; break;
            case 0x0800: aac_codec.sampling_rate = 22050; break;
            case 0x0400: aac_codec.sampling_rate = 24000; break;
            case 0x0200: aac_codec.sampling_rate = 32000; break;
            case 0x0100: aac_codec.sampling_rate = 44100; break;
            case 0x0080: aac_codec.sampling_rate = 48000; break;
            case 0x0040: aac_codec.sampling_rate = 64000; break;
            case 0x0020: aac_codec.sampling_rate = 88200; break;
            case 0x0010: aac_codec.sampling_rate = 96000; break;
            default:
                ALOGE("Invalid sample_freq: %x", aac_samp_freq);
        }

        switch (byte & A2D_AAC_IE_CHANNELS_MSK)
        {
            case A2D_AAC_IE_CHANNELS_1:
                 aac_codec.channels = 1;
                 break;
            case A2D_AAC_IE_CHANNELS_2:
                 aac_codec.channels = 2;
                 break;
            default:
                 ALOGE("AAC:Unknown channel mode");
        }
        byte = *p_cfg++; //Move to VBR byte
        len--;
        switch (byte & A2D_AAC_IE_VBR_MSK)
        {
            case A2D_AAC_IE_VBR:
                break;
            default:
                ALOGE("AAC:VBR not supported");
        }
        aac_bit_rate = 0x7F&byte;
        //Move it 2nd byte of 32 bit word. leaving the VBR bit
        aac_bit_rate = aac_bit_rate << 16;
        byte = *p_cfg++; //Move to 2nd byteof bitrate
        len--;

        //Move it to 3rd byte of 32bit word
        aac_bit_rate |= 0x0000FF00 & (((uint32_t)byte)<<8);
        byte = *p_cfg++; //Move to 3rd byte of bitrate
        len--;

        aac_bit_rate |= 0x000000FF & (((uint32_t)byte));
        aac_codec.bitrate = aac_bit_rate;
        aac_codec.bits_per_sample = *(uint32_t *)p_cfg;
        *codec_type = AUDIO_FORMAT_AAC;

        if(sample_freq) *sample_freq = aac_codec.sampling_rate;
        ALOGW("AAC: Done copying full codec config bits_per_sample : %d", aac_codec.bits_per_sample);
        return ((void *)(&aac_codec));
    }
    else if (codec_cfg[CODEC_OFFSET] == NON_A2DP_CODEC_TYPE)
    {
        uint32_t vendor_ldac_id = 0x0;
        vendor_ldac_id =  (codec_cfg[VENDOR_ID_OFFSET] & 0x000000FF) |
                   ((codec_cfg[VENDOR_ID_OFFSET + 1]) << 8 & 0x0000FF00) |
                   ((codec_cfg[VENDOR_ID_OFFSET + 2]) << 16 & 0x00FF0000) |
                   ((codec_cfg[VENDOR_ID_OFFSET + 3]) << 24 & 0xFF000000);

        if (codec_cfg[VENDOR_ID_OFFSET] == VENDOR_APTX &&
            codec_cfg[CODEC_ID_OFFSET] == APTX_CODEC_ID)
        {
            ALOGW("AptX-classic codec");
            *codec_type = AUDIO_FORMAT_APTX;
        }
        if (codec_cfg[VENDOR_ID_OFFSET] == VENDOR_APTX_HD &&
            codec_cfg[CODEC_ID_OFFSET] == APTX_HD_CODEC_ID)
        {
            ALOGW("AptX-HD codec");
            *codec_type = AUDIO_FORMAT_APTX_HD;
        }

        if (codec_cfg[VENDOR_ID_OFFSET] == VENDOR_APTX_ADAPTIVE &&
            codec_cfg[CODEC_ID_OFFSET] == APTX_ADAPTIVE_CODEC_ID)
        {
            ALOGW("AptX-Adaptive codec");
            *codec_type = ENC_CODEC_TYPE_APTX_ADAPTIVE;

            memset(&aptx_adaptive_codec, 0, sizeof(audio_aptx_adaptive_encoder_config_t));
            p_cfg++; //skip dev_idx
            len = *p_cfg++;//LOSC
            p_cfg++; // Skip media type
            len--;
            p_cfg++; //codec_type
            len--;
            p_cfg+=4;//skip vendor id
            len -= 4;
            p_cfg += 2; //skip codec id
            len -= 2;

            switch(*p_cfg++ & A2D_APTX_ADAPTIVE_SAMP_FREQ_MASK)
            {
                case A2DP_APTX_ADAPTIVE_SAMPLERATE_44100:
                     aptx_adaptive_codec.sampling_rate = 0x2;
                     if(sample_freq) *sample_freq = 44100;
                     break;
                case A2DP_APTX_ADAPTIVE_SAMPLERATE_48000:
                     aptx_adaptive_codec.sampling_rate = 0x1;
                     if(sample_freq) *sample_freq = 48000;
                     break;
                case A2DP_APTX_ADAPTIVE_SAMPLERATE_88000:
                     aptx_adaptive_codec.sampling_rate = 0;
                     break;
                case A2DP_APTX_ADAPTIVE_SAMPLERATE_192000:
                     aptx_adaptive_codec.sampling_rate = 0;
                     break;
                default:
                     ALOGE("Unknown sampling rate");
            }
            len--;

            switch(*p_cfg++ & A2D_APTX_ADAPTIVE_CHAN_MASK)
            {
                case A2DP_APTX_ADAPTIVE_CHANNELS_MONO:
                     aptx_adaptive_codec.channel_mode = 1;
                     break;
                /*case A2DP_APTX_ADAPTIVE_CHANNELS_STEREO:
                     aptx_adaptive_codec.channel_mode = 2;
                     break;*/
                case A2DP_APTX_ADAPTIVE_CHANNELS_JOINT_STEREO:
                     aptx_adaptive_codec.channel_mode = 0;
                     break;
                case A2DP_APTX_ADAPTIVE_CHANNELS_TWS_STEREO:
                     aptx_adaptive_codec.channel_mode = 4;
                     break;
                default:
                     ALOGE("Unknown sampling rate");
            }
            len--;

            aptx_adaptive_codec.min_sink_buffering_LL = 20; // gghai temp setting to default value
            aptx_adaptive_codec.max_sink_buffering_LL = 50;
            aptx_adaptive_codec.min_sink_buffering_HQ = 20;
            aptx_adaptive_codec.max_sink_buffering_HQ = 50;
            aptx_adaptive_codec.min_sink_buffering_TWS = 20;
            aptx_adaptive_codec.max_sink_buffering_TWS = 50;

            aptx_adaptive_codec.TTP_LL_low = *(p_cfg ++);
            aptx_adaptive_codec.TTP_LL_high = *(p_cfg ++);
            aptx_adaptive_codec.TTP_HQ_low = *(p_cfg ++);
            aptx_adaptive_codec.TTP_HQ_high = *(p_cfg ++);
            aptx_adaptive_codec.TTP_TWS_low = *(p_cfg ++);
            aptx_adaptive_codec.TTP_TWS_high = *(p_cfg ++);
            len -= 6;

            p_cfg += 3; // ignoring eoc bits
            len -= 3;
            ALOGW("%s: ## aptXAdaptive ## sampleRate 0x%x", __func__, aptx_adaptive_codec.sampling_rate);
            ALOGW("%s: ## aptXAdaptive ## channelMode 0x%x", __func__, aptx_adaptive_codec.channel_mode);
            ALOGW("%s: ## aptXAdaptive ## ttp_ll_0 0x%x", __func__, aptx_adaptive_codec.TTP_LL_low);
            ALOGW("%s: ## aptXAdaptive ## ttp_ll_1 0x%x", __func__, aptx_adaptive_codec.TTP_LL_high);
            ALOGW("%s: ## aptXAdaptive ## ttp_hq_0 0x%x", __func__, aptx_adaptive_codec.TTP_HQ_low);
            ALOGW("%s: ## aptXAdaptive ## ttp_hq_1 0x%x", __func__, aptx_adaptive_codec.TTP_HQ_high);
            ALOGW("%s: ## aptXAdaptive ## ttp_tws_0 0x%x", __func__, aptx_adaptive_codec.TTP_TWS_low);
            ALOGW("%s: ## aptXAdaptive ## ttp_tws_1 0x%x", __func__, aptx_adaptive_codec.TTP_TWS_high);

            if(len == 0)
                ALOGW("%s: codec config copied", __func__);
            else
                ALOGW("%s: codec config length error: %d", __func__, len);

            return ((void *)&aptx_adaptive_codec);
        }

        if (vendor_ldac_id == VENDOR_LDAC &&
            codec_cfg[CODEC_ID_OFFSET] == LDAC_CODEC_ID)
        {
            ALOGW("LDAC codec");
            *codec_type = AUDIO_FORMAT_LDAC;
            ldac_codec_parser(codec_cfg);
            if (sample_freq) *sample_freq = ldac_codec.sampling_rate;
            return ((void *)&ldac_codec);
        }
        if (codec_cfg[VENDOR_ID_OFFSET] == VENDOR_APTX_HD &&
            codec_cfg[CODEC_ID_OFFSET] == APTX_TWS_CODEC_ID)
        {
            ALOGW("AptX-TWS codec");
            *codec_type = ENC_CODEC_TYPE_APTX_DUAL_MONO;
            //aptx_codec.sync_mode = 0x01;
        }
        memset(&aptx_codec,0,sizeof(audio_aptx_encoder_config_t));
        p_cfg++; //skip dev_idx
        len = *p_cfg++;//LOSC
        p_cfg++; // Skip media type
        len--;
        p_cfg++; //codec_type
        len--;
        p_cfg+=4;//skip vendor id
        len -= 4;
        p_cfg += 2; //skip codec id
        len -= 2;
        byte = *p_cfg++;
        len--;
        switch (byte & A2D_APTX_SAMP_FREQ_MASK)
        {
            case A2D_APTX_SAMP_FREQ_48:
                 aptx_codec.sampling_rate = 48000;
                 break;
            case A2D_APTX_SAMP_FREQ_44:
                 aptx_codec.sampling_rate = 44100;
                 break;
            default:
                 ALOGE("Unknown sampling rate");
        }
        switch (byte & A2D_APTX_CHAN_MASK)
        {
            case A2D_APTX_CHAN_STEREO:
            case A2D_APTX_TWS_CHAN_MODE:
                 aptx_codec.channels = 2;
                 break;
            case A2D_APTX_CHAN_MONO:
                 aptx_codec.channels = 1;
                 break;
            default:
                 ALOGE("Unknown channel mode");
        }
        if (*codec_type == AUDIO_FORMAT_APTX_HD) {
            p_cfg += 4;
            len -= 4;//ignore 4 bytes not used
        }
        if (len == 0)
        {
            ALOGW("Codec config copied");
        }
        p_cfg += 2; //skip mtu

        aptx_codec.bitrate = *p_cfg++;
        aptx_codec.bitrate |= (*p_cfg++ << 8);
        aptx_codec.bitrate |= (*p_cfg++ << 16);
        aptx_codec.bitrate |= (*p_cfg++ << 24);
        aptx_codec.bits_per_sample = *(uint32_t *)p_cfg;
        if(sample_freq) *sample_freq = aptx_codec.sampling_rate;
        ALOGW("APTx: Done copying full codec config bits_per_sample : %d", aptx_codec.bits_per_sample);
        if (*codec_type == ENC_CODEC_TYPE_APTX_DUAL_MONO)
        {
            memset(&aptx_tws_codec, 0, sizeof(audio_aptx_tws_encoder_config_t));
            memcpy(&aptx_tws_codec, &aptx_codec, sizeof(aptx_codec));
            aptx_tws_codec.sync_mode = 0x02;
            return ((void *)&aptx_tws_codec);
        }
        return ((void *)&aptx_codec);
    }
    else if (codec_cfg[CODEC_OFFSET] == CODEC_TYPE_CELT)
    {
        uint8_t celt_samp_freq = 0;
        uint32_t celt_bit_rate = 0;
        memset(&celt_codec,0,sizeof(audio_celt_encoder_config_t));
        switch(codec_cfg[4] & A2D_CELT_SAMP_FREQ_MASK)
        {
        case A2D_CELT_SAMP_FREQ_48:
            celt_codec.sampling_rate = 48000;
            break;
        case A2D_CELT_SAMP_FREQ_44:
            celt_codec.sampling_rate = 44100;
            break;
        case A2D_CELT_SAMP_FREQ_32:
            celt_codec.sampling_rate = 32000;
            break;
        default:
            ALOGE("CELT: unknown sampl freq");
        }
        switch(codec_cfg[4] & A2D_CELT_CHANNEL_MASK)
        {
        case A2D_CELT_CH_MONO:
            celt_codec.channels = 1;
            break;
        case A2D_CELT_CH_STEREO:
            celt_codec.channels = 2;
            break;
        default:
            ALOGE("CELT: unknown channel");
        }
        switch(codec_cfg[5] & A2D_CELT_FRAME_SIZE_MASK)
        {
        case A2D_CELT_FRAME_SIZE_64:
            celt_codec.frame_size = 64;
            break;
        case A2D_CELT_FRAME_SIZE_128:
            celt_codec.frame_size = 128;
            break;
        case A2D_CELT_FRAME_SIZE_256:
            celt_codec.frame_size = 256;
            break;
        case A2D_CELT_FRAME_SIZE_512:
            celt_codec.frame_size = 512;
            break;
        default:
            ALOGE("CELT: unknown frame size");
        }
        celt_codec.complexity = codec_cfg[5] & A2D_CELT_COMPLEXITY_MASK;
        celt_codec.prediction_mode =
                (codec_cfg[6] & A2D_CELT_PREDICTION_MODE_MASK) >> 4;
        celt_codec.vbr_flag = codec_cfg[6] & A2D_CELT_VBR_MASK;

        celt_codec.bitrate |= codec_cfg[7];
        celt_codec.bitrate = celt_codec.bitrate << 8;
        celt_codec.bitrate |= codec_cfg[8];
        celt_codec.bitrate = celt_codec.bitrate << 8;
        celt_codec.bitrate |= codec_cfg[9];
        celt_codec.bitrate = celt_codec.bitrate << 8;
        celt_codec.bitrate |= codec_cfg[10];
        *codec_type = AUDIO_CODEC_TYPE_CELT;

        ALOGE("CELT Bitrate: 0%x", celt_codec.bitrate);
        ALOGE("CELT channel: 0%x", celt_codec.channels);
        ALOGE("CELT complexity: 0%x", celt_codec.complexity);
        ALOGE("CELT frame_size: 0%x", celt_codec.frame_size);
        ALOGE("CELT prediction_mode: 0%x", celt_codec.prediction_mode);
        ALOGE("CELT sampl_freq: 0%x", celt_codec.sampling_rate);
        ALOGE("CELT vbr_flag: 0%x", celt_codec.vbr_flag);
        ALOGE("CELT codec_type: 0%x", codec_type);
        return ((void *)(&celt_codec));
    }
    return NULL;
}

int a2dp_read_codec_config(struct a2dp_stream_common *common,uint8_t idx)
{
    char cmd[2];//,ack;
    int i,len = 0;
    uint8_t *p_codec_cfg = common->codec_cfg;
    cmd[0] = A2DP_CTRL_GET_CODEC_CONFIG;
    cmd[1] = idx;
    ALOGW("%s",__func__);
    memset(p_codec_cfg,0,MAX_CODEC_CFG_SIZE);
    tA2DP_CTRL_ACK status = A2DP_CTRL_ACK_FAILURE;

    if(stack_cb)
    {
        ALOGW("Calling get_codec_cfg_cb");
        resp_received = false;
        stack_cb->get_codec_cfg_cb();
        ack_recvd = 0;
        if (resp_received == false)
        {
            ALOGW("%s: stack resp not received",__func__);
            wait_for_stack_response(1);
        }
        status = common->ack_status;
        common->ack_status = A2DP_CTRL_ACK_UNKNOWN;
        ALOGW("get_codec_cfg_cb returned: status = %s",dump_a2dp_ctrl_ack(status));
    }
    return status;
}

void a2dp_get_multicast_status(uint8_t *mcast_status)
{
    ALOGW("%s",__func__);
    if (stack_cb)
    {
        resp_received = false;
        stack_cb->get_mcast_status_cb();
        ack_recvd = 0;
        if (resp_received == false)
        {
            ALOGW("%s: stack resp not received",__func__);
            wait_for_stack_response(1);
        }
        *mcast_status = audio_stream.multicast;
    }
    else
        *mcast_status  = 0;
}

void a2dp_get_num_connected_devices(uint8_t *num_dev)
{
    ALOGW("%s",__func__);
    if (stack_cb)
    {
        resp_received = false;
        stack_cb->get_connected_device_cb();
        ack_recvd = 0;
        if (resp_received == false)
        {
            ALOGW("%s: stack resp not received",__func__);
            wait_for_stack_response(1);
        }
        *num_dev = 1;
    }
}
/*****************************************************************************
**
** AUDIO DATA PATH
**
*****************************************************************************/

void a2dp_stream_common_init(struct a2dp_stream_common *common)
{
    pthread_mutexattr_t lock_attr;

    //FNLOG();
    ALOGW("%s",__func__);

    pthread_mutexattr_init(&lock_attr);
    pthread_mutexattr_settype(&lock_attr, PTHREAD_MUTEX_RECURSIVE);
    pthread_mutex_init(&common->lock, &lock_attr);
    pthread_mutexattr_destroy(&lock_attr);
    common->state = AUDIO_A2DP_STATE_STOPPED;
    common->sink_latency = A2DP_DEFAULT_SINK_LATENCY;

    bt_split_a2dp_enabled = false;
}

int wait_for_stack_response(uint8_t time_to_wait)
{
    ALOGW("wait_for_stack_response");
    struct timespec now,wait_time;
    uint8_t retry = 0;
    pthread_mutex_lock(&audio_stream.ack_lock);
    if (stack_cb == NULL)
    {
        ALOGE("stack deinitialized");
        pthread_mutex_unlock(&audio_stream.ack_lock);
        return retry;
    }
    // in race condition, ack_status is updated as SUCCESS
    // without ack_recvd made 0.
    if (audio_stream.ack_status == A2DP_CTRL_ACK_SUCCESS)
    {
        ALOGE("ACK Success, no need to wait");
        pthread_mutex_unlock(&audio_stream.ack_lock);
        return retry;
    }
    while (retry < CTRL_CHAN_RETRY_COUNT &&
              ack_recvd == 0)
    {
        ALOGW("entering coditional wait: retry = %d, ack_recvd = %d",retry,ack_recvd);
        clock_gettime(CLOCK_REALTIME, &now);
        now.tv_sec += time_to_wait;
        pthread_cond_timedwait(&ack_cond, &audio_stream.ack_lock, &now);
        retry++;
    }
    pthread_mutex_unlock(&audio_stream.ack_lock);
    if (ack_recvd) {
        ALOGV("wait_for_stack_response: ack received");
    }
    ALOGV("wait_for_stack_response returning retry = %d",retry);
    return retry;
}
static void copy_status(tA2DP_CTRL_ACK status)
{
    ALOGW("copy_status: status = %d",status);
    pthread_mutex_lock(&audio_stream.ack_lock);
    audio_stream.ack_status = status;
    if (!ack_recvd)
    {
        ack_recvd = 1;
        pthread_cond_signal(&ack_cond);
    }
    pthread_mutex_unlock(&audio_stream.ack_lock);
}
void bt_stack_init(bt_lib_callback_t *lib_cb)
{
    ALOGW("bt_stack_init");
    int ret = 0;
    stack_cb = lib_cb;
}
void bt_stack_deinit(tA2DP_CTRL_ACK status)
{
    ALOGW("bt_stack_deinit");
    pthread_mutex_lock(&audio_stream.ack_lock);
    stack_cb = NULL;
    audio_stream.ack_status = status;
    if (!ack_recvd)
    {
        ack_recvd = 1;
        pthread_cond_signal(&ack_cond);
    }
    pthread_mutex_unlock(&audio_stream.ack_lock);
}

void bt_stack_on_stream_started(tA2DP_CTRL_ACK status)
{
    ALOGW("bt_stack_on_stream_started: status = %d",status);
    pthread_mutex_lock(&audio_stream.ack_lock);
    if ((audio_stream.ack_status != A2DP_CTRL_ACK_UNKNOWN) && (status == A2DP_CTRL_ACK_PENDING)) {
        ALOGW("status already changed to = %d, don't update pending",audio_stream.ack_status);
    }
    else {
        audio_stream.ack_status = status;
    }
    resp_received = true;
    if (!ack_recvd)
    {
        ack_recvd = 1;
        pthread_cond_signal(&ack_cond);
    }
    pthread_mutex_unlock(&audio_stream.ack_lock);
}

void bt_stack_on_stream_suspended(tA2DP_CTRL_ACK status)
{
    ALOGW("bt_stack_on_stream_suspended status = %d, ack_status = %d ", status, audio_stream.ack_status);
    pthread_mutex_lock(&audio_stream.ack_lock);
    if ((audio_stream.ack_status != A2DP_CTRL_ACK_UNKNOWN) && (status == A2DP_CTRL_ACK_PENDING)) {
        ALOGW("status already changed to = %d, don't update pending",audio_stream.ack_status);
    }
    else {
        audio_stream.ack_status = status;
        ALOGW("bt_stack_on_stream_suspended updating  ack_status = %d ", audio_stream.ack_status);
    }
    resp_received = true;
    if (!ack_recvd)
    {
        ack_recvd = 1;
        ALOGW("bt_stack_on_stream_suspended signalling pthread ");
        pthread_cond_signal(&ack_cond);
    }
    pthread_mutex_unlock(&audio_stream.ack_lock);
    ALOGW("bt_stack_on_stream_suspended mutex unlocked ");
}

void bt_stack_on_stream_stopped(tA2DP_CTRL_ACK status)
{
    ALOGW("bt_stack_on_stream_stopped");
    pthread_mutex_lock(&audio_stream.ack_lock);
    if ((audio_stream.ack_status != A2DP_CTRL_ACK_UNKNOWN) && (status == A2DP_CTRL_ACK_PENDING)) {
        ALOGW("status already changed to = %d, don't update pending",audio_stream.ack_status);
    }
    else {
        audio_stream.ack_status = status;
    }
    resp_received = true;
    if (!ack_recvd)
    {
        ack_recvd = 1;
        pthread_cond_signal(&ack_cond);
    }
    pthread_mutex_unlock(&audio_stream.ack_lock);
}

void bt_stack_on_get_codec_cfg(tA2DP_CTRL_ACK status, const char *p_cfg,
                                  size_t len)
{
    ALOGW("bt_stack_on_get_codec_config status %s",dump_a2dp_ctrl_ack(status));
    if (status != A2DP_CTRL_ACK_PENDING)
    {
        pthread_mutex_lock(&audio_stream.ack_lock);
        audio_stream.ack_status = status;
        ALOGW("bt_stack_on_get_codec_config len = %d",len);
        if (len > MAX_CODEC_CFG_SIZE) {
          ALOGE("codec config length > MAX_CODEC_CFG_SIZE");
          status = A2DP_CTRL_ACK_FAILURE;
        }
        if (status == A2DP_CTRL_ACK_SUCCESS)
        {
            memcpy(audio_stream.codec_cfg,p_cfg,len);
            for (int i = 0; i < len; i++) {
                ALOGV("audio_stream.codec_cfg[%d] = %x",i,audio_stream.codec_cfg[i]);
            }
        }
        resp_received = true;
        if (!ack_recvd)
        {
            ack_recvd = 1;
            pthread_cond_signal(&ack_cond);
        }
        pthread_mutex_unlock(&audio_stream.ack_lock);
    }
    else
    {
        ALOGW("bt_stack_on_get_codec_cfg status pending");
    }
}

void bt_stack_on_get_mcast_status(uint8_t status)
{
    ALOGW("bt_stack_on_get_mcast_status");
    pthread_mutex_lock(&audio_stream.ack_lock);
    audio_stream.multicast = status;
    resp_received = true;
    if (!ack_recvd)
    {
        ack_recvd = 1;
        pthread_cond_signal(&ack_cond);
    }
    pthread_mutex_unlock(&audio_stream.ack_lock);
}

void bt_stack_on_get_num_connected_devices(uint8_t num_dev)
{
    ALOGW("bt_stack_on_get_num_connected_devices");
    pthread_mutex_lock(&audio_stream.ack_lock);
    audio_stream.num_conn_dev = num_dev;
    resp_received = true;
    if (!ack_recvd)
    {
        ack_recvd = 1;
        pthread_cond_signal(&ack_cond);
    }
    pthread_mutex_unlock(&audio_stream.ack_lock);
}

void bt_stack_on_get_connection_status(tA2DP_CTRL_ACK status)
{
    ALOGW("bt_stack_on_get_connection_status");
    pthread_mutex_lock(&audio_stream.ack_lock);
    audio_stream.ack_status = status;
    resp_received = true;
    if (!ack_recvd)
    {
        ack_recvd = 1;
        pthread_cond_signal(&ack_cond);
    }
    pthread_mutex_unlock(&audio_stream.ack_lock);
}
void bt_stack_on_check_a2dp_ready(tA2DP_CTRL_ACK status)
{
    ALOGW("bt_stack_on_check_a2dp_ready");
    pthread_mutex_lock(&audio_stream.ack_lock);
    audio_stream.ack_status = status;
    resp_received = true;
    if (!ack_recvd)
    {
        ack_recvd = 1;
        pthread_cond_signal(&ack_cond);
    }
    pthread_mutex_unlock(&audio_stream.ack_lock);
}

void bt_stack_on_get_sink_latency(uint16_t latency)
{
    ALOGW("bt_stack_on_get_sink_latency");
    pthread_mutex_lock(&audio_stream.ack_lock);
    audio_stream.sink_latency = latency;
    resp_received = true;
    if (!ack_recvd)
    {
        ack_recvd = 1;
        pthread_cond_signal(&ack_cond);
    }
    pthread_mutex_unlock(&audio_stream.ack_lock);
}

int audio_start_stream()
{
    int i, j, ack_ret;
    tA2DP_CTRL_ACK status = A2DP_CTRL_ACK_SUCCESS;
    ALOGW("%s: state = %s",__func__,dump_a2dp_hal_state(audio_stream.state));
    pthread_mutex_lock(&audio_stream.lock);
    if (audio_stream.state == AUDIO_A2DP_STATE_SUSPENDED)
    {
        ALOGW("stream suspended");
        pthread_mutex_unlock(&audio_stream.lock);
        return -1;
    }
    if (property_get("persist.vendor.bluetooth.a2dp.hal.implementation", a2dp_hal_imp, "false") &&
            !strcmp(a2dp_hal_imp, "true"))
    {
      if (audio_stream.state == AUDIO_A2DP_STATE_STARTED)
      {
          INFO("stream already started");
          pthread_mutex_unlock(&audio_stream.lock);
          return 0;
      }
    }
    for (j = 0; j <STREAM_START_MAX_RETRY_LOOPER; j++) {
        for (i = 0; i < STREAM_START_MAX_RETRY_COUNT; i++)
        {
            if (stack_cb)
            {
                audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
                resp_received = false;
                stack_cb->start_req_cb();
                ack_recvd = 0;
                if (!resp_received)
                {
                    ack_ret = wait_for_stack_response(1);
                    if (ack_ret == CTRL_CHAN_RETRY_COUNT && !ack_recvd)
                    {
                        ALOGE("audio_start_stream: Failed to get ack from stack");
                        status = -1;
                        goto end;
                    }
                }
                status = audio_stream.ack_status;
                audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
                ALOGW("audio_start_stream status = %s",dump_a2dp_ctrl_ack(status));
                if (status == A2DP_CTRL_ACK_PENDING)
                {
                    ALOGW("waiting in pending");
                    ack_recvd = 0;
                    if (property_get("persist.vendor.bluetooth.a2dp.hal.implementation", a2dp_hal_imp, "false") &&
                            !strcmp(a2dp_hal_imp, "true"))
                    {
                        wait_for_stack_response(1);
                        if (audio_stream.ack_status == A2DP_CTRL_ACK_UNKNOWN)
                        {
                            ALOGW("audio_start_stream ack not received, fake as success");
                            status = A2DP_CTRL_ACK_SUCCESS;
                        }
                        else
                        {
                            status = audio_stream.ack_status;
                        }
                    }
                    else
                    {
                        wait_for_stack_response(5);
                        status = audio_stream.ack_status;
                    }
                    ALOGW("done waiting in pending status = %s",dump_a2dp_ctrl_ack(status));
                    audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
                }

                if (status == A2DP_CTRL_ACK_SUCCESS)
                {
                    ALOGW("a2dp stream started successfully");
                    audio_stream.state = AUDIO_A2DP_STATE_STARTED;
                    goto end;
                }
                else if (status == A2DP_CTRL_ACK_INCALL_FAILURE ||
                         status == A2DP_CTRL_ACK_UNSUPPORTED ||
                         status == A2DP_CTRL_ACK_DISCONNECT_IN_PROGRESS ||
                         status == A2DP_CTRL_ACK_UNKNOWN)
                {
                    ALOGW("a2dp stream start failed: status = %s",dump_a2dp_ctrl_ack(status));
                    audio_stream.state = AUDIO_A2DP_STATE_STOPPED;
                    goto end;
                }
                else if (property_get("persist.vendor.bluetooth.a2dp.hal.implementation", a2dp_hal_imp, "false") &&
                        !strcmp(a2dp_hal_imp, "true") &&
                        status == A2DP_CTRL_ACK_PREVIOUS_COMMAND_PENDING)
                {
                    ALOGW("a2dp stream start exited as prev command is pending, fake as success");
                    audio_stream.state = AUDIO_A2DP_STATE_STARTED;
                    goto end;
                }
                else if (status == A2DP_CTRL_ACK_FAILURE)
                {
                    ALOGW("a2dp stream start failed: generic failure");
                }
            }
            else
            {
                ALOGW("%s:Stack shutdown",__func__);
                pthread_mutex_unlock(&audio_stream.lock);
                return A2DP_CTRL_SKT_DISCONNECTED;
            }
            ALOGW("%s: a2dp stream not started,wait 100mse & retry", __func__);
            usleep(100000);
        }
        ALOGW("%s: Check if valid connection is still up or not", __func__);

        // For every 1 sec check if a2dp is still up, to avoid
        // blocking the audio thread forever if a2dp connection is closed
        // for some reason
        audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
        resp_received = false;
        stack_cb->get_connection_status_cb();
        ack_recvd = 0;
        if (!resp_received)
        {
            ack_ret = wait_for_stack_response(1);
            if (ack_ret == CTRL_CHAN_RETRY_COUNT && !ack_recvd)
            {
                ALOGE("audio_start_stream: Failed to get ack from stack");
                status = -1;
                goto end;
            }
        }
        status = audio_stream.ack_status;
        audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
        if (status != A2DP_CTRL_ACK_SUCCESS)
        {
            ALOGE("%s: No valid a2dp connection\n", __func__);
            pthread_mutex_unlock(&audio_stream.lock);
            return -1;
        }
    }
end:
    if (audio_stream.state != AUDIO_A2DP_STATE_STARTED)
    {
        ALOGE("%s: Failed to start a2dp stream", __func__);
        pthread_mutex_unlock(&audio_stream.lock);
        return status;
    }
    pthread_mutex_unlock(&audio_stream.lock);
    INFO("stream successfully started");
    return status;
}

int audio_stream_open()
{
    ALOGW("%s",__func__);
    a2dp_stream_common_init(&audio_stream);
    bt_split_a2dp_enabled = true;
    if (stack_cb != NULL)
    {
        ALOGW("audio_stream_open: Success");
        return 0;
    }
    ALOGW("audio_stream_open: Failed");
    return -1;
}

int audio_stream_close()
{
    ALOGW("%s",__func__);
    tA2DP_CTRL_ACK status = A2DP_CTRL_ACK_SUCCESS;
    pthread_mutex_lock(&audio_stream.lock);
    if (audio_stream.state == AUDIO_A2DP_STATE_STARTED ||
        audio_stream.state == AUDIO_A2DP_STATE_STOPPING)
    {
        ALOGW("%s: Suspending audio stream",__func__);
        if (stack_cb)
        {
            int ack_ret = 0;
            audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
            resp_received = false;
            stack_cb->suspend_req_cb();
            ack_recvd = 0;
            if (!resp_received)
            {
                ack_ret = wait_for_stack_response(1);
                if (ack_ret == 3 &&
                    audio_stream.ack_status == A2DP_CTRL_ACK_UNKNOWN)
                {
                    ALOGE("audio_stream_close: Failed to get ack from stack");
                    pthread_mutex_unlock(&audio_stream.lock);
                    return -1;
                }
            }
        }
    }
    pthread_mutex_unlock(&audio_stream.lock);
    return 0;
}
int audio_stop_stream()
{
    ALOGW("%s",__func__);
    int ret = -1;
    tA2DP_CTRL_ACK status;
    pthread_mutex_lock(&audio_stream.lock);
    if (stack_cb)
    {
        if (audio_stream.state != AUDIO_A2DP_STATE_SUSPENDED)
        {
            int ack_ret = 0;
            ack_recvd = 0;
            resp_received = false;
            audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
            stack_cb->suspend_req_cb();
            if (!resp_received)
            {
                ack_ret = wait_for_stack_response(1);
                if (ack_ret == CTRL_CHAN_RETRY_COUNT && !ack_recvd)
                {
                    ALOGE("audio_stop_stream: Failed to get ack from stack");
                    pthread_mutex_unlock(&audio_stream.lock);
                    return -1;
                }
            }
            status = audio_stream.ack_status;
            audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
            ALOGW("audio_stop_stream: ack status = %s",dump_a2dp_ctrl_ack(status));
            if (status == A2DP_CTRL_ACK_PENDING)
            {
                ack_recvd = 0;
                if (property_get("persist.vendor.bluetooth.a2dp.hal.implementation", a2dp_hal_imp, "false") &&
                        !strcmp(a2dp_hal_imp, "true"))
                {
                    wait_for_stack_response(1);
                }
                else
                {
                    wait_for_stack_response(5);
                }
                status = audio_stream.ack_status;
                audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
                if (status == A2DP_CTRL_ACK_SUCCESS) ret = 0;
            }

            if (status == A2DP_CTRL_ACK_SUCCESS)
            {
                ALOGW("audio stop stream successful");
                audio_stream.state = AUDIO_A2DP_STATE_STANDBY;
                pthread_mutex_unlock(&audio_stream.lock);
                return 0;
            }
            else if (property_get("persist.vendor.bluetooth.a2dp.hal.implementation", a2dp_hal_imp, "false") &&
                    !strcmp(a2dp_hal_imp, "true") &&
                    status == A2DP_CTRL_ACK_PREVIOUS_COMMAND_PENDING)
            {
                ALOGW("a2dp stream stop exited as prev command is pending, fake as success");
                audio_stream.state = AUDIO_A2DP_STATE_STANDBY;
                pthread_mutex_unlock(&audio_stream.lock);
                return 0;
            }
            else
            {
                ALOGW("audio stop stream failed");
                audio_stream.state = AUDIO_A2DP_STATE_STOPPED;
                pthread_mutex_unlock(&audio_stream.lock);
                return -1;
            }
        }
    }
    else
        ALOGW("stack is down");
    audio_stream.state = AUDIO_A2DP_STATE_STOPPED;
    pthread_mutex_unlock(&audio_stream.lock);
    return ret;
}

int audio_suspend_stream()
{
    ALOGW("%s",__func__);
    tA2DP_CTRL_ACK status;

    pthread_mutex_lock(&audio_stream.lock);
    if (stack_cb)
    {
        if (audio_stream.state != AUDIO_A2DP_STATE_SUSPENDED)
        {
            int ack_ret = 0;
            ack_recvd = 0;
            resp_received = false;
            audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
            stack_cb->suspend_req_cb();
            if (!resp_received)
            {
                ack_ret = wait_for_stack_response(1);
                if (ack_ret == CTRL_CHAN_RETRY_COUNT && !ack_recvd)
                {
                    ALOGE("audio_suspend_stream: Failed to get ack from stack");
                    pthread_mutex_unlock(&audio_stream.lock);
                    return -1;
                }
            }
            status = audio_stream.ack_status;
            audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
            ALOGW("audio_suspend_stream: ack status = %s",dump_a2dp_ctrl_ack(status));
            if (status == A2DP_CTRL_ACK_PENDING)
            {
                //TODO wait for the response;
                ack_recvd = 0;
                if (property_get("persist.vendor.bluetooth.a2dp.hal.implementation", a2dp_hal_imp, "false") &&
                        !strcmp(a2dp_hal_imp, "true"))
                {
                    wait_for_stack_response(1);
                }
                else
                {
                    wait_for_stack_response(5);
                }
                status = audio_stream.ack_status;
                audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
            }

            if (status == A2DP_CTRL_ACK_SUCCESS)
            {
                ALOGW("audio suspend stream successful");
                audio_stream.state = AUDIO_A2DP_STATE_SUSPENDED;
                pthread_mutex_unlock(&audio_stream.lock);
                return 0;
            }
            else if (property_get("persist.vendor.bluetooth.a2dp.hal.implementation", a2dp_hal_imp, "false") &&
                    !strcmp(a2dp_hal_imp, "true") &&
                    status == A2DP_CTRL_ACK_PREVIOUS_COMMAND_PENDING)
            {
                ALOGW("a2dp stream suspend exited as prev command is pending, fake as success");
                pthread_mutex_unlock(&audio_stream.lock);
                audio_stream.state = AUDIO_A2DP_STATE_SUSPENDED;
                return 0;
            }
            else
            {
                ALOGW("audio suspend stream failed");
                pthread_mutex_unlock(&audio_stream.lock);
                return -1;
            }
        }
    }
    else
        ALOGW("stack is down");
    pthread_mutex_unlock(&audio_stream.lock);
    return -1;
}

void audio_handoff_triggered()
{
    ALOGW("%s state = %s",__func__,dump_a2dp_hal_state(audio_stream.state));
    pthread_mutex_lock(&audio_stream.lock);
    if (audio_stream.state != AUDIO_A2DP_STATE_STOPPED ||
        audio_stream.state != AUDIO_A2DP_STATE_STOPPING)
    {
        audio_stream.state = AUDIO_A2DP_STATE_STOPPED;
    }
    pthread_mutex_unlock(&audio_stream.lock);
}

void clear_a2dpsuspend_flag()
{
    ALOGW("%s: state = %s",__func__,dump_a2dp_hal_state(audio_stream.state));
    pthread_mutex_lock(&audio_stream.lock);
    if (audio_stream.state == AUDIO_A2DP_STATE_SUSPENDED)
        audio_stream.state = AUDIO_A2DP_STATE_STOPPED;
    pthread_mutex_unlock(&audio_stream.lock);
}

void * audio_get_codec_config(uint8_t *multicast_status, uint8_t *num_dev,
                              audio_format_t *codec_type)
{
    int i, status;
    ALOGW("%s: state = %s",__func__,dump_a2dp_hal_state(audio_stream.state));

    pthread_mutex_lock(&audio_stream.lock);
    a2dp_get_multicast_status(multicast_status);
    if (*multicast_status)
    {
        a2dp_get_num_connected_devices(num_dev);
    }
    else
        *num_dev = 1;
    ALOGW("got multicast status = %d dev = %d",*multicast_status,*num_dev);
    update_initial_sink_latency = true;

    for (i = 0; i < STREAM_START_MAX_RETRY_COUNT; i++)
    {
        status = a2dp_read_codec_config(&audio_stream, 0);
        if (status == A2DP_CTRL_ACK_SUCCESS)
        {
            pthread_mutex_unlock(&audio_stream.lock);
            if (stack_cb == NULL) {
               ALOGW("get codec config returned due to stack deinit");
               return NULL;
            }
            return (a2dp_codec_parser(&audio_stream.codec_cfg[0], codec_type, NULL));
        }
        INFO("%s: a2dp stream not configured,wait 100mse & retry", __func__);
        usleep(100000);
    }
    pthread_mutex_unlock(&audio_stream.lock);
    return NULL;
}

void* audio_get_next_codec_config(uint8_t idx, audio_format_t *codec_type)
{
    int i, status;
    ALOGW("%s",__func__);
    pthread_mutex_lock(&audio_stream.lock);
    for (i = 0; i < STREAM_START_MAX_RETRY_COUNT; i++)
    {
        status = a2dp_read_codec_config(&audio_stream,idx);
        if (status == A2DP_CTRL_ACK_SUCCESS)
        {
            pthread_mutex_unlock(&audio_stream.lock);
            return (a2dp_codec_parser(&audio_stream.codec_cfg[0], codec_type, NULL));
        }
        INFO("%s: a2dp stream not configured,wait 100mse & retry", __func__);
        usleep(100000);
    }
    pthread_mutex_unlock(&audio_stream.lock);
    return NULL;
}

int audio_check_a2dp_ready()
{
    int i, ack_ret;
    ALOGW("audio_check_a2dp_ready: state %s", dump_a2dp_hal_state(audio_stream.state));
    tA2DP_CTRL_ACK status;
    pthread_mutex_lock(&audio_stream.lock);
    if (property_get("persist.vendor.bluetooth.a2dp.hal.implementation", a2dp_hal_imp, "false") &&
            !strcmp(a2dp_hal_imp, "true") &&
            audio_stream.state == AUDIO_A2DP_STATE_SUSPENDED)
    {
        INFO("stream not ready to start");
        pthread_mutex_unlock(&audio_stream.lock);
        return 0;
    }

    for (i = 0; i < CHECK_A2DP_READY_MAX_COUNT; i++)
    {
        pthread_mutex_lock(&audio_stream.ack_lock);
        if (stack_cb != NULL) {
            audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
            ack_recvd = 0;
            stack_cb->a2dp_check_ready_cb();
            pthread_mutex_unlock(&audio_stream.ack_lock);
        } else {
            ALOGW("audio_check_a2dp_ready = NOT ready - callbacks not registered");
            pthread_mutex_unlock(&audio_stream.ack_lock);
            pthread_mutex_unlock(&audio_stream.lock);
            return 0;
        }

        ack_ret = wait_for_stack_response(1);
        status = audio_stream.ack_status;
        if (status == A2DP_CTRL_ACK_SUCCESS)
        {
            ALOGW("audio_check_a2dp_ready : %s",dump_a2dp_ctrl_ack(status));
            pthread_mutex_unlock(&audio_stream.lock);
            return 1;
        }
        if (ack_ret == CTRL_CHAN_RETRY_COUNT && !ack_recvd)
        {
            ALOGE("audio_check_a2dp_ready: Failed to get ack from stack");
            pthread_mutex_unlock(&audio_stream.lock);
            return 0;
        }
        ALOGW("audio_check_a2dp_ready(): a2dp stream not ready, wait 200msec & retry");
        usleep(200000);
    }
    audio_stream.ack_status = A2DP_CTRL_ACK_UNKNOWN;
    ALOGW("audio_check_a2dp_ready = %s",dump_a2dp_ctrl_ack(status));

    pthread_mutex_unlock(&audio_stream.lock);
    return status == A2DP_CTRL_ACK_SUCCESS;
}

uint16_t audio_get_a2dp_sink_latency()
{
    ALOGD_IF(DEBUG, "%s: state = %s",__func__,dump_a2dp_hal_state(audio_stream.state));
    pthread_mutex_lock(&audio_stream.lock);
    if (update_initial_sink_latency)
    {
        if (stack_cb)
        {
            resp_received = false;
            stack_cb->get_sink_latency_cb();
            ack_recvd = 0;
            if (resp_received == false)
                wait_for_stack_response(1);
        }
        else
            audio_stream.sink_latency = A2DP_DEFAULT_SINK_LATENCY;
        update_initial_sink_latency = false;
    }
    pthread_mutex_unlock(&audio_stream.lock);
    return audio_stream.sink_latency;
}

bool audio_is_scrambling_enabled(void)
{
    audio_format_t codec_type = AUDIO_FORMAT_DEFAULT;
    int i;
    char value[PROPERTY_VALUE_MAX];
    uint8_t *codec_cfg = NULL;
    uint32_t sample_freq = 0;
    memset(value, '\0', sizeof(char)*PROPERTY_VALUE_MAX);
    ALOGW("audio_is_scrambling_enabled: state %s",
                    dump_a2dp_hal_state(audio_stream.state));
    tA2DP_CTRL_ACK status = A2DP_CTRL_ACK_UNKNOWN;

    if (stack_cb == NULL)
    {
        ALOGW("audio_is_scrambling_enabled returned false due to stack deinit");
        return false;
    }

    if( property_get("persist.vendor.bluetooth.soc.scram_freqs", value, "false") &&
        !strcmp(value, "false"))
    {
        property_get("persist.vendor.bt.soc.scram_freqs", value, "false");
        if(!strcmp(value, "false"))
        {
            ALOGW("persist.vendor.bt.soc.scram_freqs is not set");
            return false;
        }
    }
    else
    {
        ALOGE("Error in fetching persist.vendor.bluetooth.soc.scram_freqs property");
        return false;
    }
	ALOGE("scram_freqs Prop value = %s", value);

    pthread_mutex_lock(&audio_stream.lock);
    for (i = 0; i < STREAM_START_MAX_RETRY_COUNT; i++)
    {
        status = a2dp_read_codec_config(&audio_stream, 0);
        if (status == A2DP_CTRL_ACK_SUCCESS)
        {
            if(!a2dp_codec_parser(&audio_stream.codec_cfg[0],
                        &codec_type, &sample_freq)) {
                status = A2DP_CTRL_ACK_UNKNOWN;
            }
            break;
        }
        INFO("%s: a2dp stream not configured,wait 100mse & retry", __func__);
        usleep(100000);
    }
    if (codec_type == ENC_CODEC_TYPE_APTX_DUAL_MONO) {
        INFO("%s:TWSP codec, return false",__func__);
        pthread_mutex_unlock(&audio_stream.lock);
        return false;
    }
    if (codec_type == ENC_CODEC_TYPE_APTX_ADAPTIVE) {
        ALOGW("%s:aptX Adaptive codec, return false",__func__);
        pthread_mutex_unlock(&audio_stream.lock);
        return false;
    }

    if(status == A2DP_CTRL_ACK_SUCCESS) {

        if (codec_type == CODEC_TYPE_CELT) {
           INFO("%s: BA going on,return false", __func__);
           pthread_mutex_unlock(&audio_stream.lock);
           return false;
        }

        ALOGW("audio_is_scrambling_enabled sample_freq %ld",sample_freq);
        switch (sample_freq) {
            case 44100:
                if(!strstr(value, "441")) status = A2DP_CTRL_ACK_UNKNOWN;
                break;
            case 48000:
                if(!strstr(value, "48")) status = A2DP_CTRL_ACK_UNKNOWN;
                break;
            case 88200:
                if(!strstr(value, "882")) status = A2DP_CTRL_ACK_UNKNOWN;
                break;
            case 96000:
                if(!strstr(value, "96")) status = A2DP_CTRL_ACK_UNKNOWN;
                break;
            case 176400:
                if(!strstr(value, "1764")) status = A2DP_CTRL_ACK_UNKNOWN;
                break;
            case 192000:
                if(!strstr(value, "192")) status = A2DP_CTRL_ACK_UNKNOWN;
                break;
            default:
                ALOGE("Invalid sampling freqency, return A2DP_CTRL_ACK_UNKNOWN");
                status = A2DP_CTRL_ACK_UNKNOWN;
                break;
        }
    }
    ALOGW("audio_is_scrambling_enabled = %s",dump_a2dp_ctrl_ack(status));
    pthread_mutex_unlock(&audio_stream.lock);
    return status == A2DP_CTRL_ACK_SUCCESS;
}

void ldac_codec_parser(uint8_t *codec_cfg)
{
    char byte,len;
    uint8_t *p_cfg = codec_cfg;
    memset(&ldac_codec,0,sizeof(audio_ldac_encoder_config_t));
    p_cfg++; //skip dev_idx
    len = *p_cfg++;//LOSC
    p_cfg++; // Skip media type
    len--;
    p_cfg++; //codec_type
    len--;
    p_cfg+=4;//skip vendor id
    len -= 4;
    p_cfg += 2; //skip codec id
    len -= 2;
    byte = *p_cfg++;
    len--;
    switch (byte & A2D_LDAC_SAMP_FREQ_MASK)
    {
        case A2D_LDAC_SAMP_FREQ_44:
             ldac_codec.sampling_rate = 44100;
             break;
        case A2D_LDAC_SAMP_FREQ_48:
             ldac_codec.sampling_rate = 48000;
             break;
        case A2D_LDAC_SAMP_FREQ_88:
             ldac_codec.sampling_rate = 88200;
             break;
        case A2D_LDAC_SAMP_FREQ_96:
             ldac_codec.sampling_rate = 96000;
             break;
        case A2D_LDAC_SAMP_FREQ_176:
             ldac_codec.sampling_rate = 176400;
             break;
        case A2D_LDAC_SAMP_FREQ_192:
             ldac_codec.sampling_rate = 192000;
             break;
        default:
             ALOGE("Unknown sampling rate");
    }
    ALOGW("%s: LDAC: sample rate: %lu", __func__, ldac_codec.sampling_rate);
    byte = *p_cfg++;
    len--;
    ldac_codec.channel_mode = (byte & A2D_LDAC_CHAN_MASK);
    if (len == 0)
    {
        ALOGW("Codec config copied");
    }
    ldac_codec.mtu = DEFAULT_MTU_SIZE;
    p_cfg += 2;

    ldac_codec.bitrate = *p_cfg++;
    ldac_codec.bitrate |= (*p_cfg++ << 8);
    ldac_codec.bitrate |= (*p_cfg++ << 16);
    ldac_codec.bitrate |= (*p_cfg++ << 24);

    ldac_codec.is_abr_enabled = (ldac_codec.bitrate == 0);
    ldac_codec.bits_per_sample = *(uint32_t *)p_cfg;
    ALOGW("Create Lookup for %d with ABR %d, bits_per_sample %d", ldac_codec.sampling_rate, ldac_codec.is_abr_enabled, ldac_codec.bits_per_sample);
    if (ldac_codec.sampling_rate == 44100 ||
            ldac_codec.sampling_rate == 88200) {
        int num_of_level_entries =
            sizeof(bit_rate_level_44_1k_88_2k_database)/sizeof(bit_rate_level_44_1k_88_2k_table_t);
        ldac_codec.level_to_bitrate_map.num_levels = num_of_level_entries;
        if (ldac_codec.is_abr_enabled) {
         ldac_codec.bitrate = bit_rate_level_44_1k_88_2k_database[0].bit_rate_value;
         ALOGW("Send start highest bit-rate value %d", ldac_codec.bitrate);
        }
        for (int i = 0; i < num_of_level_entries; i++) {
            ldac_codec.level_to_bitrate_map.bit_rate_level_map[i].link_quality_level =
                bit_rate_level_44_1k_88_2k_database[i].level_value;
            ldac_codec.level_to_bitrate_map.bit_rate_level_map[i].bitrate =
                bit_rate_level_44_1k_88_2k_database[i].bit_rate_value;
            ALOGW("Level: %d, bit-rate: %d",
                ldac_codec.level_to_bitrate_map.bit_rate_level_map[i].link_quality_level,
                ldac_codec.level_to_bitrate_map.bit_rate_level_map[i].bitrate);
        }
    } else if (ldac_codec.sampling_rate == 48000 ||
            ldac_codec.sampling_rate == 96000) {
        int num_of_level_entries =
            sizeof(bit_rate_level_48k_96k_database)/sizeof(bit_rate_level_48k_96k_table_t);
        ldac_codec.level_to_bitrate_map.num_levels = num_of_level_entries;
        if (ldac_codec.is_abr_enabled) {
         ldac_codec.bitrate = bit_rate_level_48k_96k_database[0].bit_rate_value;
         ALOGW("Send start highest bit-rate value %d", ldac_codec.bitrate);
        }
        for (int i = 0; i < num_of_level_entries; i++) {
            ldac_codec.level_to_bitrate_map.bit_rate_level_map[i].link_quality_level =
                bit_rate_level_48k_96k_database[i].level_value;
            ldac_codec.level_to_bitrate_map.bit_rate_level_map[i].bitrate =
                bit_rate_level_48k_96k_database[i].bit_rate_value;
            ALOGW("Level: %d, bit-rate: %d",
                ldac_codec.level_to_bitrate_map.bit_rate_level_map[i].link_quality_level,
                ldac_codec.level_to_bitrate_map.bit_rate_level_map[i].bitrate);
        }
    } else {
        ALOGW("Unsupported Invalid frequency");
    }
    ALOGW("%s: LDAC: bitrate: %lu", __func__, ldac_codec.bitrate);
    ALOGW("LDAC: Done copying full codec config");
}
