1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/****************************************************************************
* *
* OpenNI 1.x Alpha *
* Copyright (C) 2011 PrimeSense Ltd. *
* *
* This file is part of OpenNI. *
* *
* OpenNI is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* OpenNI is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
* *
****************************************************************************/
#include "MockAudioGenerator.h"
#include <XnPropNames.h>
#include <XnOS.h>
#include <XnLog.h>
MockAudioGenerator::MockAudioGenerator(xn::Context& context, const XnChar* strName) :
MockGenerator(context, strName, TRUE),
m_pSupportedOutputModes(NULL),
m_nSupportedOutputModesCount(0),
m_bSupportedOutputModesCountReceived(FALSE)
{
xnOSMemSet(&m_waveOutputMode, 0, sizeof(m_waveOutputMode));
}
MockAudioGenerator::~MockAudioGenerator()
{
}
XnUChar* MockAudioGenerator::GetAudioBuffer()
{
return (XnUChar*)GetData();
}
XnUInt32 MockAudioGenerator::GetSupportedWaveOutputModesCount()
{
return m_nSupportedOutputModesCount;
}
XnStatus MockAudioGenerator::GetSupportedWaveOutputModes(XnWaveOutputMode aSupportedModes[], XnUInt32& nCount)
{
XN_VALIDATE_PTR(m_pSupportedOutputModes, XN_STATUS_PROPERTY_NOT_SET);
nCount = XN_MIN(nCount, m_nSupportedOutputModesCount);
xnOSMemCopy(aSupportedModes, m_pSupportedOutputModes, nCount * sizeof(m_pSupportedOutputModes[0]));
return XN_STATUS_OK;
}
XnStatus MockAudioGenerator::SetWaveOutputMode(const XnWaveOutputMode& OutputMode)
{
XnStatus nRetVal = XN_STATUS_OK;
if (xnOSMemCmp(&OutputMode, &m_waveOutputMode, sizeof(OutputMode)) != 0)
{
m_waveOutputMode = OutputMode;
nRetVal = m_outputModeChangeEvent.Raise();
XN_IS_STATUS_OK(nRetVal);
}
return XN_STATUS_OK;
}
XnStatus MockAudioGenerator::GetWaveOutputMode(XnWaveOutputMode& OutputMode)
{
OutputMode = m_waveOutputMode;
return XN_STATUS_OK;
}
XnStatus MockAudioGenerator::RegisterToWaveOutputModeChanges(XnModuleStateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
{
return m_outputModeChangeEvent.Register(handler, pCookie, hCallback);
}
void MockAudioGenerator::UnregisterFromWaveOutputModeChanges(XnCallbackHandle hCallback)
{
m_outputModeChangeEvent.Unregister(hCallback);
}
XnStatus MockAudioGenerator::SetIntProperty( const XnChar* strName, XnUInt64 nValue )
{
if (strcmp(strName, XN_PROP_WAVE_SUPPORTED_OUTPUT_MODES_COUNT) == 0 ||
strcmp(strName, XN_PROP_SUPPORTED_USER_POSITIONS_COUNT) == 0) // Bug workaround: old files wrote down bad name
{
m_nSupportedOutputModesCount = (XnUInt32)nValue;
m_bSupportedOutputModesCountReceived = TRUE;
}
else
{
return MockGenerator::SetIntProperty(strName, nValue);
}
return XN_STATUS_OK;
}
XnStatus MockAudioGenerator::SetGeneralProperty(const XnChar* strName, XnUInt32 nBufferSize, const void* pBuffer)
{
XN_VALIDATE_INPUT_PTR(strName);
XN_VALIDATE_INPUT_PTR(pBuffer);
XnStatus nRetVal = XN_STATUS_OK;
if (strcmp(strName, XN_PROP_WAVE_OUTPUT_MODE) == 0)
{
if (nBufferSize != sizeof(m_waveOutputMode))
{
XN_LOG_ERROR_RETURN(XN_STATUS_INVALID_BUFFER_SIZE, XN_MASK_OPEN_NI, "Cannot set XN_PROP_WAVE_OUTPUT_MODE - buffer size is incorrect");
}
const XnWaveOutputMode* pOutputMode = (const XnWaveOutputMode*)pBuffer;
nRetVal = SetWaveOutputMode(*pOutputMode);
XN_IS_STATUS_OK(nRetVal);
}
else if (strcmp(strName, XN_PROP_WAVE_SUPPORTED_OUTPUT_MODES) == 0)
{
if (m_bSupportedOutputModesCountReceived)
{
m_bSupportedOutputModesCountReceived = FALSE; //For next time
if (nBufferSize != m_nSupportedOutputModesCount * sizeof(XnWaveOutputMode))
{
XN_LOG_ERROR_RETURN(XN_STATUS_INVALID_BUFFER_SIZE, XN_MASK_OPEN_NI, "Cannot set XN_PROP_SUPPORTED_WAVE_OUTPUT_MODES - buffer size is incorrect");
}
XN_DELETE_ARR(m_pSupportedOutputModes);
m_pSupportedOutputModes = XN_NEW_ARR(XnWaveOutputMode, m_nSupportedOutputModesCount);
XN_VALIDATE_ALLOC_PTR(m_pSupportedOutputModes);
xnOSMemCopy(m_pSupportedOutputModes, pBuffer, nBufferSize);
}
else
{
XN_ASSERT(FALSE);
XN_LOG_ERROR_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_OPEN_NI, "Got XN_PROP_SUPPORTED_WAVE_OUTPUT_MODES without XN_PROP_SUPPORTED_WAVE_OUTPUT_MODES_COUNT before it");
}
}
else if (strcmp(strName, XN_PROP_WAVE_SUPPORTED_OUTPUT_MODES_COUNT) == 0)
{
// Bug workaround: old files wrote down bad name with invalid value. Just ignore
}
else
{
nRetVal = MockGenerator::SetGeneralProperty(strName, nBufferSize, pBuffer);
XN_IS_STATUS_OK(nRetVal);
}
return XN_STATUS_OK;
}
|