status_t AudioALSAPlaybackHandlerNormal::close()
{
    ALOGD("+%s()", __FUNCTION__);
    AudioAutoTimeoutLock _l(*AudioALSADriverUtility::getInstance()->getStreamSramDramLock());

    //============Voice UI&Unlock REFERECE=============
    AudioVUnlockDL *VUnlockhdl = AudioVUnlockDL::getInstance();
    if (VUnlockhdl != NULL)
    {
        VUnlockhdl->SetInputStandBy(true);
    }
    //===========================================


    // close codec driver
    mHardwareResourceManager->stopOutputDevice();

    // close pcm driver
    closePcmDriver();

    // disable lowjitter mode
    SetLowJitterMode(false, mStreamAttributeTarget.sample_rate);

    DeinitDataPending();

    // bit conversion
    deinitBitConverter();

    // SRC
    deinitBliSrc();

    // post processing
    deinitPostProcessing();

    // debug pcm dump
    ClosePCMDump();

    //release pmic clk
    mHardwareResourceManager->EnableAudBufClk(false);


    ALOGD("-%s()", __FUNCTION__);
    return NO_ERROR;
}
status_t AudioALSAPlaybackHandlerBTSCO::close()
{
    ALOGD("+%s()", __FUNCTION__);

    // close pcm driver
    closePcmDriver();


    // bit conversion
    deinitBitConverter();


    // SRC
    deinitBliSrc();


    // debug pcm dump
    ClosePCMDump();


    ALOGD("-%s()", __FUNCTION__);
    return NO_ERROR;
}
status_t AudioALSAPlaybackHandlerSphDL::close()
{
    ALOGD("+%s()", __FUNCTION__);

    // close codec driver
    // Don't stopoutputDevice here, let speech driver to open.
    mHardwareResourceManager->stopOutputDevice();

    //Echo reference path
    if (mixer_ctl_set_enum_by_string(mixer_get_ctl_by_name(mMixer, "Audio_Dl1_MD_Echo_Ref_Switch"), "Off"))
    {
        ALOGE("Error: Audio_Dl1_MD_Echo_Ref_Switch invalid value");
    }

    // close pcm driver
    closePcmDriver();


    // bit conversion
    deinitBitConverter();


    // SRC
    deinitBliSrc();


    // post processing
    deinitPostProcessing();


    // debug pcm dump
    ClosePCMDump();


    ALOGD("-%s()", __FUNCTION__);
    return NO_ERROR;
}
status_t AudioALSAPlaybackHandlerOffload::close()
{
    ALOGD("+%s()", __FUNCTION__);
    AudioAutoTimeoutLock _l(*AudioALSADriverUtility::getInstance()->getStreamSramDramLock());

	//close compress device driver
	send_offload_cmd(OFFLOAD_CMD_CLOSE);
    while(!threadExit)
    {
        usleep(1 * 1000);
    }
    pthread_join(offload_stream.offload_pthread, (void **) NULL);
    pthread_cond_destroy(&offload_stream.offload_cond);
    pthread_mutex_destroy(&offload_stream.offload_mutex);
    closeComprDriver();

    //============Voice UI&Unlock REFERECE=============
    AudioVUnlockDL *VUnlockhdl = AudioVUnlockDL::getInstance();
    if (VUnlockhdl != NULL)
    {
        VUnlockhdl->SetInputStandBy(true);
    }
    //===========================================


    // close codec driver
    mHardwareResourceManager->stopOutputDevice();

    // close pcm driver
    //closePcmDriver();

    // disable lowjitter mode  //doug to check
    SetLowJitterMode(false, mStreamAttributeTarget.sample_rate);

    DeinitDataPending();

    // bit conversion
    deinitBitConverter();

    // SRC
    deinitBliSrc();

    // post processing
    deinitPostProcessing();

    // debug pcm dump
    ClosePCMDump();

    //release pmic clk
    mHardwareResourceManager->EnableAudBufClk(false);
    //SetMHLChipEnable(false);   //doug to check

    //close decoder
    mDecHandler->DeinitAudioDecoder();
	
    //free codec params
    if(mDecBsbuf != NULL)
    {
        free(mDecBsbuf);
        mDecBsbuf = NULL;
    }
	
    if(mDecPcmbuf != NULL)
    {
        free(mDecPcmbuf);
		mDecPcmbuf = NULL;
    }

    ALOGD("%s(), mComprConfig.codec:%p", mComprConfig.codec);

	if(mComprConfig.codec)
    {
        free((void*)mComprConfig.codec);
        mComprConfig.codec = NULL;
    }

    memset(&mComprConfig,0, sizeof(mComprConfig));

//    offload_callback(STREAM_CBK_EVENT_WRITE_READY);
 //   usleep(1 * 1000);
   // offload_callback(STREAM_CBK_EVENT_DRAIN_READY);

    ALOGD("-%s()", __FUNCTION__);
    return NO_ERROR;
}