wavemain.cpp

来自「i.mx27 soc for wince 6.0」· C++ 代码 · 共 796 行 · 第 1/2 页

CPP
796
字号
            {
                pDeviceContext = g_pHWContext->GetInputDeviceContext(uDeviceId);
            }

            dwRet = pDeviceContext->GetDevCaps((PVOID)dwParam1,dwParam2);
            break;
        }

    case WODM_GETEXTDEVCAPS:
        {
            DeviceContext *pDeviceContext;

            if (pStreamContext)
            {
                pDeviceContext=pStreamContext->GetDeviceContext();
            }
            else
            {
                pDeviceContext = g_pHWContext->GetOutputDeviceContext(uDeviceId);
            }

            dwRet = pDeviceContext->GetExtDevCaps((PVOID)dwParam1,dwParam2);
            break;
        }

    case WODM_OPEN:
        {
            // DEBUGMSG(1, (TEXT("WODM_OPEN\r\n"));
            DeviceContext *pDeviceContext = g_pHWContext->GetOutputDeviceContext(uDeviceId);
            dwRet = pDeviceContext->OpenStream((LPWAVEOPENDESC)dwParam1, dwParam2, (StreamContext **)dwUser);                        
            break;
        }

#ifdef AUDIO_RECORDING_ENABLED
    case WIDM_OPEN:
        {
            // DEBUGMSG(1, (TEXT("WIDM_OPEN\r\n"));            
            DeviceContext *pDeviceContext = g_pHWContext->GetInputDeviceContext(uDeviceId);                        
            dwRet = pDeviceContext->OpenStream((LPWAVEOPENDESC)dwParam1, dwParam2, (StreamContext **)dwUser);                        
            // For some reason, even we pass correct error code, waveInOpen return different value (32)
            if (dwRet != MMSYSERR_NOERROR)
            {                      
                SetLastError(dwRet);                
                bRet = FALSE;
            }
            break;
        }

    case WIDM_CLOSE:
       {
            // We must stop the input DMA operation and disable all associated
            // hardware components now that we've finished recording.            
            DeviceContext *pDeviceContext = g_pHWContext->GetInputDeviceContext(uDeviceId);                        
            g_pHWContext->StopInputDMA();

            dwRet = pStreamContext->Close();
            
            if (dwRet==MMSYSERR_NOERROR)
            {
                pStreamContext->Release();
#ifdef AUDIO_IN_LIMIT_OPEN
                pDeviceContext->CloseStreamCount();  
#endif
            }



            break;
        }

#endif // #ifdef AUDIO_RECORDING_ENABLED

    case WODM_CLOSE:
        {
            // Close the audio I/O stream here (for both input and output
            // streams).
            //
            // Note that for audio output streams, the required StopOutputDMA()
            // is made in the interrupt handler when we've finished transmitting
            // the last piece of the output audio stream.
            dwRet = pStreamContext->Close();
            
            // Release stream context here, rather than inside
            // StreamContext::Close, so that if someone (like CMidiStream)
            // has subclassed Close there's no chance that the object will
            // get released out from under them.
            if (dwRet==MMSYSERR_NOERROR)
            {
                pStreamContext->Release();
            }
            break;
        }

    case WODM_RESTART:
    case WIDM_START:
        {
            dwRet = pStreamContext->Run();
            break;
        }

    case WODM_PAUSE:
    case WIDM_STOP:
        {
            dwRet = pStreamContext->Stop();
            break;
        }

    case WODM_GETPOS:
    case WIDM_GETPOS:
        {
            dwRet = pStreamContext->GetPos((PMMTIME)dwParam1);
            break;
        }

    case WODM_RESET:
    case WIDM_RESET:
        {
            dwRet = pStreamContext->Reset();
            break;
        }

    case WODM_WRITE:
    case WIDM_ADDBUFFER:
        {
            //DEBUGMSG(1, (TEXT("WODM_WRITE/WIDM_ADDBUFFER, Buffer=0x%x\r\n"),dwParam1);
            dwRet = pStreamContext->QueueBuffer((LPWAVEHDR)dwParam1);
            break;
        }

    case WODM_GETVOLUME:
        {
            PULONG pdwGain = (PULONG)dwParam1;

            if (pStreamContext)
            {
                *pdwGain = pStreamContext->GetGain();
            }
            else
            {
                // Handle device gain in hardware
                *pdwGain = g_pHWContext->GetOutputGain();
                // Handle device gain in software
                //DeviceContext *pDeviceContext = g_pHWContext->GetOutputDeviceContext(uDeviceId);
                //*pdwGain = pDeviceContext->GetGain();
            }
            dwRet = MMSYSERR_NOERROR;
            break;
        } 

    case WODM_SETVOLUME:
        {
            LONG dwGain = dwParam1;
            if (pStreamContext)
            {
                dwRet = pStreamContext->SetGain(dwGain);
            }
            else
            {
                // Handle device gain in hardware
                dwRet = g_pHWContext->SetOutputGain(dwGain);
                // Handle device gain in software
                //DeviceContext *pDeviceContext = g_pHWContext->GetOutputDeviceContext(uDeviceId);
                //dwRet = pDeviceContext->SetGain(dwGain);
            }
            break;
        }

    case WODM_BREAKLOOP:
        {
            dwRet = pStreamContext->BreakLoop();
            break;
        }

    case WODM_SETPLAYBACKRATE:
        {
            WaveStreamContext *pWaveStream = (WaveStreamContext *)dwUser;
            dwRet = pWaveStream->SetRate(dwParam1);
            break;
        }

    case WODM_GETPLAYBACKRATE:
        {
            WaveStreamContext *pWaveStream = (WaveStreamContext *)dwUser;
            dwRet = pWaveStream->GetRate((DWORD *)dwParam1);
            break;
        }

    case MM_WOM_SETSECONDARYGAINCLASS:
        {
            dwRet = pStreamContext->SetSecondaryGainClass(dwParam1);
            break;
        }

    case MM_WOM_SETSECONDARYGAINLIMIT:
        {
            DeviceContext *pDeviceContext;
            if (pStreamContext)
            {
                pDeviceContext = pStreamContext->GetDeviceContext();
            }
            else
            {
                pDeviceContext = g_pHWContext->GetOutputDeviceContext(uDeviceId);
            }
            dwRet = pDeviceContext->SetSecondaryGainLimit(dwParam1,dwParam2);
            break;
        }

    case MM_MOM_MIDIMESSAGE:
        {
            CMidiStream *pMidiStream = (CMidiStream *)dwUser;
            dwRet = pMidiStream->MidiMessage(dwParam1);
            break;
        }
// unsupported messages
    case WODM_GETPITCH:
    case WODM_SETPITCH:
    case WODM_PREPARE:
    case WODM_UNPREPARE:
    case WIDM_PREPARE:
    case WIDM_UNPREPARE:
    default:
        dwRet  = MMSYSERR_NOTSUPPORTED;
    }
    g_pHWContext->Unlock();

    // Pass the return code back via pBufOut
    if (pdwResult)
    {  
        *pdwResult = dwRet;
    }

    return(bRet);
}

// -----------------------------------------------------------------------------
//
//  @doc    WDEV_EXT
//
//  @func   BOOL | WAV_IOControl | Device IO control routine
//
//  @parm   DWORD | dwOpenData | Value returned from WAV_Open call
//
//  @parm   DWORD | dwCode |
//          IO control code for the function to be performed. WAV_IOControl only
//          supports one IOCTL value (IOCTL_WAV_MESSAGE)
//
//  @parm   PBYTE | pBufIn |
//          Pointer to the input parameter structure (<t MMDRV_MESSAGE_PARAMS>).
//
//  @parm   DWORD | dwLenIn |
//          Size in bytes of input parameter structure (sizeof(<t MMDRV_MESSAGE_PARAMS>)).
//
//  @parm   PBYTE | pBufOut | Pointer to the return value (DWORD).
//
//  @parm   DWORD | dwLenOut | Size of the return value variable (sizeof(DWORD)).
//
//  @parm   PDWORD | pdwActualOut | Unused
//
//  @rdesc  Returns TRUE for success, FALSE for failure
//
//  @xref   <t Wave Input Driver Messages> (WIDM_XXX) <nl>
//          <t Wave Output Driver Messages> (WODM_XXX)
//
// -----------------------------------------------------------------------------
extern "C" BOOL WAV_IOControl(PDWORD  pdwOpenData,
                   DWORD  dwCode,
                   PBYTE  pBufIn,
                   DWORD  dwLenIn,
                   PBYTE  pBufOut,
                   DWORD  dwLenOut,
                   PDWORD pdwActualOut)
{    
    UNREFERENCED_PARAMETER(dwLenIn);

	DWORD  dwErr = ERROR_INVALID_PARAMETER;    

    // Check caller trust. If context hasn't been initialized, load from
    // CeGetCallerTrust.
    if (*pdwOpenData != OEM_CERTIFY_TRUST) {
        if (OEM_CERTIFY_TRUST != (*pdwOpenData = CeGetCallerTrust())) {
            PRINTMSG(ZONE_WARN, (TEXT("WAV_IoControl: untrusted process\n")));
            SetLastError(ERROR_ACCESS_DENIED);
            return FALSE;
        }
    }

    _try
    {
        switch (dwCode)
        {
        case IOCTL_MIX_MESSAGE:
            return HandleMixerMessage((PMMDRV_MESSAGE_PARAMS)pBufIn, (DWORD *)pBufOut);

        case IOCTL_WAV_MESSAGE:
            {
                BOOL ret = TRUE;
                ret = HandleWaveMessage((PMMDRV_MESSAGE_PARAMS)pBufIn, (DWORD *)pBufOut);            
                *pdwActualOut = sizeof(DWORD);            
                return ret;
            }



        case IOCTL_POWER_CAPABILITIES:
            // tell the power manager about ourselves.
            if ( pBufOut != NULL && 
                 dwLenOut >= sizeof(POWER_CAPABILITIES) && 
                 pdwActualOut != NULL)
            {
                PPOWER_CAPABILITIES ppc = (PPOWER_CAPABILITIES) pBufOut;
                memset(ppc, 0, sizeof(POWER_CAPABILITIES));
                ppc->DeviceDx = 0x11;   // support D0, D4
                ppc->WakeFromDx = 0x00; // No wake capability
                ppc->InrushDx = 0x00;       // No in rush requirement
                ppc->Power[D0] = 600;                   // 0.6W
                ppc->Power[D1] = (DWORD)PwrDeviceUnspecified;
                ppc->Power[D2] = (DWORD)PwrDeviceUnspecified;
                ppc->Power[D3] = (DWORD)PwrDeviceUnspecified;
                ppc->Power[D4] = 0;
                ppc->Latency[D0] = 0;
                ppc->Latency[D1] = (DWORD)PwrDeviceUnspecified;
                ppc->Latency[D2] = (DWORD)PwrDeviceUnspecified;
                ppc->Latency[D3] = (DWORD)PwrDeviceUnspecified;
                ppc->Latency[D4] = 0;
                ppc->Flags = 0;
                *pdwActualOut = sizeof(POWER_CAPABILITIES);
                dwErr = ERROR_SUCCESS;
            }
            break;

        case IOCTL_POWER_SET: 
            if ( pBufOut != NULL && 
                 dwLenOut == sizeof(CEDEVICE_POWER_STATE) && 
                 pdwActualOut != NULL)
            {
                CEDEVICE_POWER_STATE NewDx = *(PCEDEVICE_POWER_STATE)pBufOut;
                if (NewDx != CurDx)
                {
                    if (NewDx == D0)
                    {
						g_pHWContext->PowerUp();
                    }
                    else
                    {
                        // if asked for a state we don't support, go to the next lower one
                        // which is D4
                        NewDx = D4;
						g_pHWContext->PowerDown();
                    }
                    CurDx = NewDx;
                    *(PCEDEVICE_POWER_STATE)pBufOut = CurDx;
                }
                *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
                dwErr = ERROR_SUCCESS;
            }
            break;

        case IOCTL_POWER_GET: 
            if ( pBufOut != NULL && 
                 dwLenOut == sizeof(CEDEVICE_POWER_STATE) && 
                 pdwActualOut != NULL)
            {
                // just return our CurrentDx value
                *(PCEDEVICE_POWER_STATE)pBufOut = CurDx;
                *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
                dwErr = ERROR_SUCCESS;
            }
            break;


        case IOCTL_POWER_QUERY: 
            if ( pBufOut != NULL && 
                 dwLenOut == sizeof(CEDEVICE_POWER_STATE) && 
                 pdwActualOut != NULL)
            {
                CEDEVICE_POWER_STATE NewDx = *(PCEDEVICE_POWER_STATE)pBufOut;
                
                if (VALID_DX(NewDx))
                {
                    // this is a valid Dx state so return a good status
                    *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
                    dwErr = ERROR_SUCCESS;
                }
            }
            break;
    }
	}
    _except (GetExceptionCode() == STATUS_ACCESS_VIOLATION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
    {
        RETAILMSG(1, (TEXT("EXCEPTION IN WAV_IOControl!!!!\r\n")));
        SetLastError((DWORD)E_FAIL);
    }

    return(FALSE);
}

⌨️ 快捷键说明

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