/*----------------------------------------------------------------------------*
 * No Warranty                                                                *
 * Except as may be otherwise agreed to in writing, no warranties of any      *
 * kind, whether express or implied, are given by MTK with respect to any MTK *
 * Deliverables or any use thereof, and MTK Deliverables are provided on an   *
 * "AS IS" basis.  MTK hereby expressly disclaims all such warranties,        *
 * including any implied warranties of merchantability, non-infringement and  *
 * fitness for a particular purpose and any warranties arising out of course  *
 * of performance, course of dealing or usage of trade.  Parties further      *
 * acknowledge that Company may, either presently and/or in the future,       *
 * instruct MTK to assist it in the development and the implementation, in    *
 * accordance with Company's designs, of certain softwares relating to        *
 * Company's product(s) (the "Services").  Except as may be otherwise agreed  *
 * to in writing, no warranties of any kind, whether express or implied, are  *
 * given by MTK with respect to the Services provided, and the Services are   *
 * provided on an "AS IS" basis.  Company further acknowledges that the       *
 * Services may contain errors, that testing is important and Company is      *
 * solely responsible for fully testing the Services and/or derivatives       *
 * thereof before they are used, sublicensed or distributed.  Should there be *
 * any third party action brought against MTK, arising out of or relating to  *
 * the Services, Company agree to fully indemnify and hold MTK harmless.      *
 * If the parties mutually agree to enter into or continue a business         *
 * relationship or other arrangement, the terms and conditions set forth      *
 * hereunder shall remain effective and, unless explicitly stated otherwise,  *
 * shall prevail in the event of a conflict in the terms in any agreements    *
 * entered into between the parties.                                          *
 *---------------------------------------------------------------------------*/

/*****************************************************************************
*  Maple Aud command
*****************************************************************************/
#define CC_CLI
#include "x_lint.h"

LINT_SAVE_AND_DISABLE

#ifdef __MW_CLI_DEF__
#include "x_mid_cli.h"
#else
#include "x_drv_cli.h"
#endif

#include "x_os.h"
#include "x_printf.h"
#include "x_stl_lib.h"
#include "drv_MapleAudApi.h"

static INT32 _i4RegisterBeAudFunc(INT32 i4Argc, const CHAR ** szArgv)
{
    SONY_BE_AUD_FUNC_T* pBeAud = NULL;

    DRVCUST_RegisterBeAudFunc(pBeAud);
    Printf("DRVCUST_RegisterBeAudFunc OK\n");
#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_reg\n");
#endif
    return 0;
}

static INT32 _i4DeRegisterBeAudFunc(INT32 i4Argc, const CHAR ** szArgv)
{
    DRVCUST_DeregisterBeAudFunc();
    Printf("DRVCUST_DeregisterBeAudFunc OK\n");
#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_dereg\n");
#endif
    return 0;
}

static INT32 _i4GetAudioInputType(INT32 i4Argc, const CHAR ** szArgv)
{
    CUST_AUD_INPUT_T eAudioInput;

    eAudioInput.eAudioInputType = E_CUST_AUD_INPUT_TYPE_OTHERS;
    DRVCUST_GetAudioInputType(0, &eAudioInput);
    Printf("eAudioInput.eAudioInputType = %d\n",eAudioInput.eAudioInputType);
#ifdef CC_MTK_AUTO_TEST
    if (eAudioInput.eAudioInputType == E_CUST_AUD_INPUT_TYPE_DIGITAL_TUNER)
    {
        Printf("PASS_type\n");
    }
#endif
    return 0;
}

static INT32 _i4GetAudioSignalFormat(INT32 i4Argc, const CHAR ** szArgv)
{
    CUST_AUD_FMT_T eSignalFormat;

    eSignalFormat.eSigSta = E_CUST_AUD_SIG_STA_UNKNOWN;
    eSignalFormat.eChConf = E_CUST_AUD_CH_CONF_UNKNOWN;
    DRVCUST_GetAudioSignalFormat(0, &eSignalFormat);
    Printf("eSignalFormat.eSigSta = %d\n", eSignalFormat.eSigSta);
#ifdef CC_MTK_AUTO_TEST
    if (eSignalFormat.eSigSta == E_CUST_AUD_SIG_STA_STABLE)
    {
        Printf("PASS_sfmt\n");
    }
#endif
    return 0;
}

static INT32 _i4GetAudioDelay(INT32 i4Argc, const CHAR ** szArgv)
{
    UINT32 u4Delay = 0;

    u4Delay = DRVCUST_GetAudioDelay();
    Printf("DRVCUST_GetAudioDelay = %d\n", u4Delay);
#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_delay\n");
#endif
    return 0;
}

static INT32 _i4GetAudioOutputFormat(INT32 i4Argc, const CHAR ** szArgv)
{
    CUST_AUD_OUT_FORMAT_T eOutFormat;

    eOutFormat.eSamplingRate = E_CUST_AUD_FS_UNKNOWN;
    DRVCUST_GetAudioOutputFormat(&eOutFormat);
    Printf("eSamplingRate = %d, eDoutPath = %d\n", eOutFormat.eSamplingRate, eOutFormat.eDoutPath);
#ifdef CC_MTK_AUTO_TEST
    if (eOutFormat.eSamplingRate != E_CUST_AUD_FS_UNKNOWN)
    {
        Printf("PASS_ofmt\n");
    }
#endif
    return 0;
}

static INT32 _i4GetVolume(INT32 i4Argc, const CHAR ** szArgv)
{
    CUST_AUD_VOLUME_T eVolume;

    eVolume.u4SpeakerVolume = 0;
    DRVCUST_GetVolume(&eVolume);
    Printf("eVolume.u4SpeakerVolume = %d\n", eVolume.u4SpeakerVolume);
#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_vol\n");
#endif
    return 0;
}

static INT32 _i4GetSoundSetting(INT32 i4Argc, const CHAR ** szArgv)
{
    CUST_AUD_SOUND_SETTING_T eSoundSetting;

    DRVCUST_GetSoundSetting(&eSoundSetting);
    Printf("eSoundMode              =%d\n", eSoundSetting.eSoundMode              );
    Printf("eAutoSurround           =%d\n", eSoundSetting.eAutoSurround           );
    Printf("i1SurroundEffect        =%d\n", eSoundSetting.i1SurroundEffect        );
    Printf("eSoundUpScaling         =%d\n", eSoundSetting.eSoundUpScaling         );
    Printf("i1VoiceZoom             =%d\n", eSoundSetting.i1VoiceZoom             );
    Printf("eSceneSelectAuto        =%d\n", eSoundSetting.eSceneSelectAuto        );
    Printf("eNightMode              =%d\n", eSoundSetting.eNightMode              );
    Printf("eSubwooferPowerSetting  =%d\n", eSoundSetting.eSubwooferPowerSetting  );
    Printf("eAutoVolume             =%d\n", eSoundSetting.eAutoVolume             );
    Printf("i1LRBalance             =%d\n", eSoundSetting.i1LRBalance             );
    Printf("i1InputLevelOffset      =%d\n", eSoundSetting.i1InputLevelOffset      );
    Printf("eDolbyDynamicRange      =%d\n", eSoundSetting.eDolbyDynamicRange      );
    Printf("i1MpegAudioLevel        =%d\n", eSoundSetting.i1MpegAudioLevel        );
    Printf("i1HeAacAudioLevel       =%d\n", eSoundSetting.i1HeAacAudioLevel       );
    Printf("eDynamicRange           =%d\n", eSoundSetting.eDynamicRange           );
    Printf("i1DlnaVolumeCautionLevel=%d\n", eSoundSetting.i1DlnaVolumeCautionLevel);
    Printf("i1Eq100                 =%d\n", eSoundSetting.i1Eq100                 );
    Printf("i1Eq200                 =%d\n", eSoundSetting.i1Eq200                 );
    Printf("i1Eq500                 =%d\n", eSoundSetting.i1Eq500                 );
    Printf("i1Eq1K                  =%d\n", eSoundSetting.i1Eq1K                  );
    Printf("i1Eq2K                  =%d\n", eSoundSetting.i1Eq2K                  );
    Printf("i1Eq5K                  =%d\n", eSoundSetting.i1Eq5K                  );
    Printf("i1Eq10K                 =%d\n", eSoundSetting.i1Eq10K                 );
    Printf("eLfmNarrationCancel     =%d\n", eSoundSetting.eLfmNarrationCancel     );
    Printf("i1SubwooferVolume       =%d\n", eSoundSetting.i1SubwooferVolume       );
    Printf("u1SubwooferCutoff       =%d\n", eSoundSetting.u1SubwooferCutoff       );
    Printf("i1SubwooferDelay        =%d\n", eSoundSetting.i1SubwooferDelay        );
    Printf("eSubwooferPhase         =%d\n", eSoundSetting.eSubwooferPhase         );
    Printf("eDualSound              =%d\n", eSoundSetting.eDualSound              );
    Printf("eSpeakers               =%d\n", eSoundSetting.eSpeakers               );
    Printf("eHpAudioOut             =%d\n", eSoundSetting.eHpAudioOut             );
    Printf("eHpSpLink               =%d\n", eSoundSetting.eHpSpLink               );
    Printf("eHdmiDviAudioSource     =%d\n", eSoundSetting.eHdmiDviAudioSource     );
    Printf("eDigitalAudioOut        =%d\n", eSoundSetting.eDigitalAudioOut        );
    Printf("eKeyTone                =%d\n", eSoundSetting.eKeyTone                );
    Printf("eTvPosition             =%d\n", eSoundSetting.eTvPosition             );
    Printf("u1SubwooferEnable       =%d\n", eSoundSetting.u1SubwooferEnable       );
    Printf("u1MeasureMode           =%d\n", eSoundSetting.u1MeasureMode           );
    Printf("u1BtConect              =%d\n", eSoundSetting.u1BtConect              );
    Printf("bHpDetect               =%d\n", eSoundSetting.bHpDetect               );
    Printf("bBtDelayMode            =%d\n", eSoundSetting.bBtDelayMode            );
    Printf("ePostMode               =%d\n", eSoundSetting.ePostMode               );
    Printf("eExtCenterSpMode        =%d\n", eSoundSetting.eExtCenterSpMode        );
    Printf("eDialogEnhancer         =%d\n", eSoundSetting.eDialogEnhancer         );
    Printf("eBitstreamOutMode       =%d\n", eSoundSetting.eBitstreamOutMode       );
#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_set\n");
#endif
    return 0;
}

static INT32 _i4GetAudioChannelMuteState(INT32 i4Argc, const CHAR ** szArgv)
{
    CUST_AUD_CH_MUTE_STATE_T eMuteState;

    DRVCUST_GetAudioChannelMuteState(0, &eMuteState);
    Printf("eMuteState.eMuteState = %d", eMuteState.eMuteState);
#ifdef CC_MTK_AUTO_TEST
    if (eMuteState.eMuteState == E_CUST_AUD_MUTE_STATE_UNMUTE)
    {
        Printf("PASS_mute\n");
    }
#endif
    return 0;
}

static INT32 _i4GetAudioPlayState(INT32 i4Argc, const CHAR ** szArgv)
{

    CUST_AUD_PLAY_STATE_T ePlayState;
    ePlayState.eAudioState = E_CUST_AUD_PLAY_STATE_STOP;
    DRVCUST_GetAudioPlayState(0, &ePlayState);
    Printf("ePlayState.eAudioState = %d\n", ePlayState.eAudioState);
#ifdef CC_MTK_AUTO_TEST
    if (ePlayState.eAudioState == E_CUST_AUD_PLAY_STATE_PLAY)
    {
        Printf("PASS_play\n");
    }
#endif
    return 0;
}

static INT32 _i4GetAudioMixState(INT32 i4Argc, const CHAR ** szArgv)
{
    CUST_AUD_MIX_STATE_T eState;

    DRVCUST_GetAudioMixState(&eState);
    Printf("eSkypeMixState = %d, eAudioDescriptionMixState=%d\n",
            eState.eSkypeMixState ,eState.eAudioDescriptionMixState);
#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_mix\n");
#endif
    return 0;
}

static INT32 _i4GetServiceModeState(INT32 i4Argc, const CHAR ** szArgv)
{
    CUST_AUD_SERVICE_MODE_STATE_T eState;

    DRVCUST_GetServiceModeState(&eState);
    Printf("eServiceModeState = %d\n", eState.eServiceModeState);

#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_service\n");
#endif
    return 0;
}

static INT32 _i4GetSubwooferState(INT32 i4Argc, const CHAR ** szArgv)
{
    CUST_AUD_SUBWOOFER_STATE_T eState;

    DRVCUST_GetSubwooferState(&eState);
    Printf("eSubwooferState = %d", eState.eSubwooferState);
#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_sub\n");
#endif
    return 0;
}

static INT32 _i4GetMCKState(INT32 i4Argc, const CHAR ** szArgv)
{

    BOOL bMck = FALSE;

    bMck = DRVCUST_GetMCKState();
    Printf("DRVCUST_GetMCKState = %d", bMck);
#ifdef CC_MTK_AUTO_TEST
    if (bMck == TRUE)
    {
        Printf("PASS_mck\n");
    }
#endif
    return 0;
}

static INT32 _i4SendAudEvent(INT32 i4Argc, const CHAR ** szArgv)
{
    DRVCUST_SendAudEvent(E_CUST_AUD_NO_EVEMT, 0);
    Printf("DRVCUST_SendAudEvent\n");
#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_audevt\n");
#endif
    return 0;
}

static INT32 _i4SendSAPostEvent(INT32 i4Argc, const CHAR ** szArgv)
{
    //DRVCUST_SendSAPostEvent();
#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_sapost\n");
#endif
    return 0;
}

static INT32 _i4SetSAPostStreamInfo(INT32 i4Argc, const CHAR ** szArgv)
{
    //DRVCUST_SetSAPostStreamInfo();
#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_sinfo\n");
#endif
    return 0;
}

static INT32 _i4SetBeMuteState(INT32 i4Argc, const CHAR ** szArgv)
{
    //DRVCUST_SetBeMuteState();
#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_bemute\n");
#endif
    return 0;
}

static INT32 _i4SetBeDelay(INT32 i4Argc, const CHAR ** szArgv)
{
    DRVCUST_SetBeDelay(0);
    Printf("DRVCUST_SetBeDelay(0)\n");
#ifdef CC_MTK_AUTO_TEST
    Printf("PASS_bedelay\n");
#endif
    return 0;
}

CLI_EXEC_T arCmdMapleAudTbl[] = {
    {"Register", "reg",  _i4RegisterBeAudFunc, NULL, "DRVCUST_RegisterBeAudFunc",    CLI_GUEST},
    {"Deregister", "dereg",  _i4DeRegisterBeAudFunc, NULL, "DRVCUST_DeregisterBeAudFunc",    CLI_GUEST},
    {"Input type", "type",  _i4GetAudioInputType, NULL, "DRVCUST_GetAudioInputType",    CLI_GUEST},
    {"Signal format", "sfmt",  _i4GetAudioSignalFormat, NULL, "DRVCUST_GetAudioSignalFormat",    CLI_GUEST},
    {"Delay", "delay",  _i4GetAudioDelay, NULL, "DRVCUST_GetAudioDelay",    CLI_GUEST},
    {"Output format", "ofmt",  _i4GetAudioOutputFormat, NULL, "DRVCUST_GetAudioOutputFormat",    CLI_GUEST},
    {"Volume", "vol",  _i4GetVolume, NULL, "DRVCUST_GetVolume",    CLI_GUEST},
    {"Sound setting", "set",  _i4GetSoundSetting, NULL, "DRVCUST_GetSoundSetting",    CLI_GUEST},
    {"Get mute", "mute",  _i4GetAudioChannelMuteState, NULL, "DRVCUST_GetAudioChannelMuteState",    CLI_GUEST},
    {"Play state", "play",  _i4GetAudioPlayState, NULL, "DRVCUST_GetAudioPlayState",    CLI_GUEST},
    {"Mix state", "mix",  _i4GetAudioMixState, NULL, "DRVCUST_GetAudioMixState",    CLI_GUEST},
    {"Service mode", "service",  _i4GetServiceModeState, NULL, "DRVCUST_GetServiceModeState",    CLI_GUEST},
    {"Subwoofer state", "sub",  _i4GetSubwooferState, NULL, "DRVCUST_GetSubwooferState",    CLI_GUEST},
    {"MCLK state", "mck",  _i4GetMCKState, NULL, "DRVCUST_GetMCKState",    CLI_GUEST},
    {"Audio event", "audevt",  _i4SendAudEvent, NULL, "DRVCUST_SendAudEvent",    CLI_GUEST},
    {"SAPost event", "sapost",  _i4SendSAPostEvent, NULL, "DRVCUST_SendSAPostEvent",    CLI_GUEST},
    {"Stream info", "sinfo",  _i4SetSAPostStreamInfo, NULL, "DRVCUST_SetSAPostStreamInfo",    CLI_GUEST},
    {"BE mute", "bemute",  _i4SetBeMuteState, NULL, "DRVCUST_SetBeMuteState",    CLI_GUEST},
    {"BE delay", "bedelay",  _i4SetBeDelay, NULL, "DRVCUST_SetBeDelay",    CLI_GUEST},

    {NULL, NULL, NULL, NULL, NULL, CLI_SUPERVISOR}
};
