⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voice.cpp

📁 ril source code for Windows CE
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:

voice.cpp

Abstract:


Notes:


--*/


#include "precomp.h"

#include <gsmradio.h>

#ifndef _PREFAST_
#pragma warning( disable: 4068 )
#endif

#if defined (RIL_CACHE_AUDIO_MUTING)
// Cache the mute setting to avoid querying the radio
BOOL   g_fAudioMutingOn;
#endif

//
//
//
static HRESULT ParseGetAudioGain(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseGetAudioGain);
    UINT nValue;
    RILGAININFO* prgi = NULL;
    HRESULT hr = S_OK;

    pBlob = NULL;
    cbBlob = 0;

    prgi = (RILGAININFO*)AllocBlob(sizeof(RILGAININFO));
    if (!prgi) {
        hr = E_OUTOFMEMORY;
        goto Error;
    }
    memset(prgi, 0x00, sizeof(RILGAININFO));
    prgi->cbSize = sizeof(RILGAININFO);

    hr = PDD_GetDownlinkVolume(FALSE, nValue);
    if ( FAILED( hr ) )
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : ParseGetAudioGain : PDD_GetDownlinkVolume failed , hr = [0x%08x]\r\n"), hr));
        goto Error;
    }
    
    prgi->dwRxGain = (nValue << 24) | (nValue << 16) | (nValue << 8) | (nValue);
    prgi->dwParams |= RIL_PARAM_GI_RXGAIN;

    hr = PDD_GetUplinkVolume(nValue);
    if ( FAILED( hr ) )
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : ParseGetAudioGain : PDD_GetUplinkVolume failed , hr = [0x%08x]\r\n"), hr));
        goto Error;
    }

    prgi->dwTxGain = (nValue << 24) | (nValue << 16) | (nValue << 8) | (nValue);
    prgi->dwParams |= RIL_PARAM_GI_TXGAIN;

    pBlob = (void*)prgi;
    cbBlob = sizeof(RILGAININFO);

Error:
    if (FAILED(hr)) {
        FreeBlob(prgi);
    }
    return hr;
}


//
//
//
HRESULT RILDrv_GetAudioGain(DWORD dwParam)
{
    FUNCTION_TRACE(RILDrv_GetAudioGain);
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle) {
        hr = E_FAIL;
        goto Error;
    }

    if (!QueueCmd(pHandle, "AT\r", CMDOPT_NONE, APIID_GETAUDIOGAIN, ParseGetAudioGain, NULL, hr)) {
        hr = E_FAIL;
        goto Error;
    }

Error:
    return hr;
}


//
//
//
HRESULT RILDrv_SetAudioGain(DWORD dwParam, const RILGAININFO* lpGainInfo)
{
    FUNCTION_TRACE(RILDrv_SetAudioGain);
    char szCmd[MAX_PATH];
    LPSTR szWalk = szCmd;
    HRESULT hr = S_OK;
    UINT nValue = 0;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle || !lpGainInfo) {
        hr = E_FAIL;
        goto Error;
    }

    if (!(lpGainInfo->dwParams & RIL_PARAM_GI_RXGAIN) && !(lpGainInfo->dwParams & RIL_PARAM_GI_TXGAIN)) {
        hr = E_INVALIDARG;
        goto Error;
    }

    (void)strncpyz(szWalk, "AT", MAX_PATH - (szWalk - szCmd));
    szWalk = strchr(szWalk, '\0');  // NO_TYPO: 27
    DEBUGCHK(NULL != szWalk);

    if (lpGainInfo->dwParams & RIL_PARAM_GI_RXGAIN) {

        hr = PDD_SetDownlinkVolume (lpGainInfo->dwRxGain >> 24);
        if ( FAILED( hr ) )
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RILDrv_SetAudioGain : PDD_SetDownlinkVolume failed , hr = [0x%08x]\r\n"), hr));
            goto Error;
        }

        hr = PDD_GetDownlinkVolume(TRUE, nValue);
        if ( FAILED( hr ) )
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RILDrv_SetAudioGain : PDD_GetDownlinkVolume failed , hr = [0x%08x]\r\n"), hr));
            goto Error;
        }
            
        (void)_snprintfz(szWalk, MAX_PATH - (szWalk - szCmd), "+CLVL=%u", nValue);
        szWalk = strchr(szWalk, '\0');  // NO_TYPO: 27
        DEBUGCHK(NULL != szWalk);
    }

    hr = PDD_SetUplinkVolume(lpGainInfo->dwTxGain);
    if ( FAILED( hr ) )
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("RILDrv : E : RILDrv_SetAudioGain : PDD_SetUplinkVolume failed , hr = [0x%08x]\r\n"), hr));
        goto Error;
    }
        
    (void)strncpyz(szWalk, "\r", MAX_PATH - (szWalk - szCmd));  // NO_TYPO: 30

    if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_SETAUDIOGAIN, NULL, NULL, hr)) {
        hr = E_FAIL;
        goto Error;
    }

Error:
    return hr;
}


//
//
//
HRESULT RILDrv_SetAudioDevices(DWORD dwParam, const RILAUDIODEVICEINFO* lpAudioDeviceInfo)
{
    FUNCTION_TRACE(RILDrv_SetAudioDevices);

    HRESULT hr = S_OK;

    if (g_rppPDDParams->fSetAudioDevicesSupported) {
        DWORD dwDummy;
        CComHandle* pComDevice;
        CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
        if (!pHandle || !lpAudioDeviceInfo) {
            hr = E_FAIL;
            goto Error;
        }

        if (!(lpAudioDeviceInfo->dwParams & RIL_PARAM_ADI_TXDEVICE) &&
            !(lpAudioDeviceInfo->dwParams & RIL_PARAM_ADI_RXDEVICE)) {
            hr = E_INVALIDARG;
            goto Error;
        }

        if (lpAudioDeviceInfo->dwParams & RIL_PARAM_ADI_TXDEVICE) {
            DEBUGCHK(NULL != pHandle->GetDevice());
            DEBUGCHK(NULL != pHandle->GetDevice()->GetComDevice());
            pComDevice = pHandle->GetDevice()->GetComDevice();

            if (RIL_AUDIO_NONE == lpAudioDeviceInfo->dwTxDevice) {
#pragma prefast( suppress: 309, "PREfast noise: The NULL and 0 parameter values are intended." )
                (void)pComDevice->IOControl(IOCTL_SPKR_DISABLE, NULL, 0, NULL, 0, dwDummy);
            } else {
#pragma prefast( suppress: 309, "PREfast noise: The NULL and 0 parameter values are intended." )
                (void)pComDevice->IOControl(IOCTL_SPKR_ENABLE, NULL, 0, NULL, 0, dwDummy);
            }
        }

        // Send a no-op AT command to force an OK response
        if (!QueueCmd(pHandle, NULL, CMDOPT_NOOP, APIID_SETAUDIODEVICES, NULL, NULL, hr)) {
            hr = E_FAIL;
            goto Error;
        }
    }
    else {
        hr = E_NOTIMPL;
    }

Error:
    return hr;
}


//
//
//
static HRESULT ParseGetAudioMuting(LPCSTR szRsp, void*& pBlob, UINT& cbBlob)
{
    FUNCTION_TRACE(ParseGetAudioMuting);
    BOOL* pfEnabled = NULL;
    HRESULT hr = S_OK;

    pBlob = NULL;
    cbBlob = 0;

    pfEnabled = (BOOL*)AllocBlob(sizeof(BOOL));
    if (!pfEnabled) {
        hr = E_OUTOFMEMORY;
        goto Error;
    }
    memset(pfEnabled, 0x00, sizeof(BOOL));


#ifdef RIL_CACHE_AUDIO_MUTING

    *pfEnabled = g_fAudioMutingOn;

#else // RIL_CACHE_AUDIO_MUTING

    UINT nValue;

    // Parse "<prefix>+CMUT: <enabled><postfix>"
    if (!ParseRspPrefix(szRsp, szRsp)                           ||
        !MatchStringBeginning(szRsp, "+CMUT: ", szRsp)          ||
        !ParseUIntAndVerifyAbove(szRsp, TRUE, 2, nValue, szRsp) ||
        !ParseRspPostfix(szRsp, szRsp)) {
        hr = E_FAIL;
        goto Error;
    }
    *pfEnabled = (1 == nValue);

#endif // RIL_CACHE_AUDIO_MUTING

    pBlob = (void*)pfEnabled;
    cbBlob = sizeof(BOOL);

Error:
    if (FAILED(hr)) {
        FreeBlob(pfEnabled);
    }
    return hr;
}


//
//
//
HRESULT RILDrv_GetAudioMuting(DWORD dwParam)
{
    FUNCTION_TRACE(RILDrv_GetAudioMuting);
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle) {
        hr = E_FAIL;
        goto Error;
    }

#ifdef RIL_CACHE_AUDIO_MUTING

    if (!QueueCmd(pHandle,  NULL, CMDOPT_NOOP, APIID_GETAUDIOMUTING, ParseGetAudioMuting, NULL, hr)) {
        hr = E_FAIL;
        goto Error;
    }   

#else   // RIL_CACHE_AUDIO_MUTING

#ifdef RIL_RADIO_RESILIENCE
    if (ShouldSpoofCommand())
    {
        // If the radio was reset recently, just return unmuted.  Otherwise this may get
        // queued up after all the init commands, and take a long time to execute
        // This is bad, since we want to handle the RIL_NOTIFY_DISCONNECT 
        // that is sent up during reset so the UI can be updated quickly        
        BOOL* pfEnabled = (BOOL*)AllocBlob(sizeof(BOOL));
        if (!pfEnabled) {
            hr = E_OUTOFMEMORY;
            goto Error;
        }
        hr = pHandle->GetDevice()->GetNextCmdID();
        *pfEnabled = FALSE;
        pHandle->Notify(RIL_RESULT_OK, hr, pfEnabled, sizeof(BOOL));
    }
    else
#endif // RIL_RADIO_RESILIENCE
    {
        if (!QueueCmd(pHandle, "AT+CMUT?\r", CMDOPT_NONE, APIID_GETAUDIOMUTING, ParseGetAudioMuting, NULL, hr)) {
            hr = E_FAIL;
            goto Error;
        }
    }

#endif  // RIL_CACHE_AUDIO_MUTING

Error:
    return hr;
}


//
//
//
HRESULT RILDrv_SetAudioMuting(DWORD dwParam, BOOL fEnable)
{
    FUNCTION_TRACE(RILDrv_SetAudioMuting);
    char szCmd[MAX_PATH];
    HRESULT hr = S_OK;
    CRilInstanceHandle* pHandle = ExtractHandle(dwParam);
    if (!pHandle) {
        hr = E_FAIL;
        goto Error;
    }

    (void)_snprintfz(szCmd, MAX_PATH, "AT+CMUT=%u\r", (fEnable ? 1 : 0));
    if (!QueueCmd(pHandle, szCmd, CMDOPT_NONE, APIID_SETAUDIOMUTING, NULL, NULL, hr)) {
        hr = E_FAIL;
        goto Error;
    }
#if defined (RIL_CACHE_AUDIO_MUTING)    
    else {
        g_fAudioMutingOn = fEnable;
    }
#endif  // RIL_CACHE_AUDIO_MUTING

Error:
    return hr;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -