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

📄 tone.c

📁 telcobridges tone develop
💻 C
📖 第 1 页 / 共 5 页
字号:
	PTB640_MSG_STREAM_RES_FREE			pMsgStrmResFree;
	TBX_MSG_HANDLE						hMsg;
	TBX_FILTER_HANDLE					hFilter;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		hFilter = TBX_HANDLE_INVALID;
		hMsg 	= TBX_HANDLE_INVALID;

		/* Get a message buffer */
		Result = TBXGetMsg (in_hLib, sizeof(*pMsgStrmResFree), &hMsg);

		if (TBX_RESULT_SUCCESS (Result))
		{
			/* Clear the buffer... */
			memset (TBX_MSG_PAYLOAD_POINTER (hMsg), 0, TBX_MSG_PAYLOAD_MAX_LENGTH_GET (hMsg));

			/* Set the message header */
			TBX_FORMAT_MSG_HEADER (
				hMsg,
				TB640_MSG_ID_STREAM_RES_FREE,
				TBX_MSG_TYPE_REQUEST,
				sizeof(*pMsgStrmResFree),
				in_hAdapter,
				0,
				0);

			/* Fill the request */
			pMsgStrmResFree = TBX_MSG_PAYLOAD_POINTER (hMsg);
			pMsgStrmResFree->Request.un32MsgVersion = 1;
			pMsgStrmResFree->Request.hStreamRes		= in_hRes;

			/* Send the request */
			Result = TBXSendMsg (in_hLib, hMsg, &hFilter);
			hMsg = TBX_HANDLE_INVALID;
			if (TBX_RESULT_SUCCESS (Result))
			{
				pMsgStrmResFree = NULL;

				/* Wait for the response synchronously */
				Result = TBXReceiveMsg (in_hLib, hFilter, TB640_TONE_RECEIVE_TIMEOUT_MSEC, &hMsg);
				if (TBX_RESULT_SUCCESS (Result))
				{
					/* We got the response */
					pMsgStrmResFree = TBX_MSG_PAYLOAD_POINTER (hMsg);

					Result = pMsgStrmResFree->Response.Result;
				}
			}

			/* Release the filter */
			if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
			{
				TBXDestroyMsgFilter (in_hLib, hFilter);
				hFilter = TBX_HANDLE_INVALID;
			}
		}

		/* Free the message buffer */
		if (hMsg != TBX_HANDLE_INVALID)
		{
			/* Free the message */
			TBXReleaseMsg (in_hLib, hMsg);
			hMsg = TBX_HANDLE_INVALID;
		}

		/* Was there an error along in the process ? */
		if (TBX_RESULT_FAILURE (Result))
		{
			TBX_EXIT_ERROR (Result, 0, "StrmResFree Failed");
		}

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
 	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
	}

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  ToneResAllocate			:	Allocates many Vp Tone Resource in a async way
 |
 |  in_hLib					:	Handle to the TBX library returned by TBXOpenLib()
 |  in_hAdapter				:	Handle to an adapter that was previously selected and attached to by SelectAdapter()
 |	in_ToneType				:	Tone Detection type
 |	in_un64UserCtx			:	User context for events on this resource
 |	out_phTdmRes			:	Returned Tdm (tone) resource handle of the allocated Vp Group
 |	out_phGroupRes			:	Returned Vp group handle.
 |
 |
 |  Note					:	~
 |
 |  Return					:	TBX_RESULT_OK
 |								TBX_RESULT_FAIL
 |								or others
 |
 *------------------------------------------------------------------------------------------------------------------------------*/

TBX_RESULT ToneResAllocate (
  IN		TBX_LIB_HANDLE				in_hLib,
  IN		TBX_ADAPTER_HANDLE			in_hAdapter,
  IN		TB640_VP_TONE_DETECT_TYPE	in_ToneType,
  IN		TBX_UINT64					in_un64UserCtx,
  IN		TBX_UINT32					in_un32Count,
  OUT		PTB640_RESOURCE_HANDLE 		out_phTdmRes,
  OUT		PTB640_RESOURCE_HANDLE 		out_phStrmRes,
  OUT		PTB640_RESOURCE_HANDLE 		out_phGroupRes )
 {
	TBX_RESULT_API						Result;
	PTB640_MSG_VP_GROUP_ALLOC			pMsgVpResAlloc;
	TBX_MSG_HANDLE						hMsg;
	PTB640_VP_GROUP0_RES_PARAMS			pParams;
	TBX_UINT32							un32MsgSize;
	TBX_UINT32							un32ResIndex;
	TBX_UINT32							un32SendMsgCnt;
	TBX_BOOL							fEarlyDtmfDetectionEnabled;
	PTBX_FILTER_HANDLE					pahFilter;


	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Get a message buffer */
		Result = TBX_RESULT_OK;
		hMsg 	= TBX_HANDLE_INVALID;
		pahFilter = NULL;
		un32SendMsgCnt = 0;
		fEarlyDtmfDetectionEnabled = TBX_FALSE;
		un32MsgSize = sizeof( *pMsgVpResAlloc );
		if( out_phStrmRes )
			un32MsgSize += sizeof(*pMsgVpResAlloc->Request.aResourcesParam);

		pahFilter = calloc( sizeof(*pahFilter), in_un32Count );
		if( !pahFilter )
		{
			TBX_EXIT_ERROR (TBX_RESULT_NOT_ENOUGH_MEMORY, 0, "calloc Failed");
		}

		if( in_ToneType & TONE_SHORT_DTMF_FLAG )
		{
			fEarlyDtmfDetectionEnabled= TBX_TRUE;
			in_ToneType &= ~TONE_SHORT_DTMF_FLAG;
		}

		for( un32ResIndex = 0; un32ResIndex < in_un32Count; un32ResIndex++ )
		{
			Result = TBXGetMsg (in_hLib, un32MsgSize, &hMsg);
			if (TBX_RESULT_FAILURE(Result))
			{
				TBX_EXIT_ERROR (Result, 0, "TBXGetMsg Failed");
			}

			/* Clear the buffer... */
			memset (TBX_MSG_PAYLOAD_POINTER (hMsg), 0, TBX_MSG_PAYLOAD_MAX_LENGTH_GET (hMsg));

			/* Set the message header */
			TBX_FORMAT_MSG_HEADER (
				hMsg,
				TB640_MSG_ID_VP_GROUP_ALLOC,
				TBX_MSG_TYPE_REQUEST,
				un32MsgSize,
				in_hAdapter,
				0,
				0);

			/* Fill the request */
			pMsgVpResAlloc = TBX_MSG_PAYLOAD_POINTER (hMsg);
			pMsgVpResAlloc->Request.un32MsgVersion 		= 1;
			pMsgVpResAlloc->Request.un32NbResources 	= out_phStrmRes ? 2 : 1;
			pMsgVpResAlloc->Request.GroupParams.GroupType = TB640_VP_GROUP_TYPE_0;
			pParams 									= &pMsgVpResAlloc->Request.aResourcesParam[0].Group0;
			pParams->ResType 							= TB640_VP_RES_TYPE_TDM;
			pParams->un64UserContext1					= in_un64UserCtx+un32ResIndex;
			pParams->un64UserContext2					= 0xDEADBEEF;
			pParams->Tdm.Tone.fGenerationEnabled 		= TBX_TRUE;
			pParams->Tdm.Tone.fDetectionEnabled 		= TBX_TRUE;
			pParams->Tdm.Tone.DetectionTypeMask			= in_ToneType;
			pParams->Tdm.Tone.fSuppressionEnabled		= TBX_FALSE;
			pParams->Tdm.Tone.fShortDetection			= fEarlyDtmfDetectionEnabled;
			if( out_phStrmRes )
			{
				pParams++;
				pParams->ResType 							= TB640_VP_RES_TYPE_STREAM;
				pParams->un64UserContext1					= in_un64UserCtx+un32ResIndex;
				pParams->Stream.Tone.fGenerationEnabled 	= TBX_FALSE;
				pParams->Stream.Tone.fDetectionEnabled 		= TBX_FALSE;
				pParams->Stream.Tone.DetectionTypeMask		= in_ToneType;
				pParams->Stream.Tone.fSuppressionEnabled	= TBX_FALSE;
				pParams->Stream.fPlaybackEnabled  			= TBX_TRUE;
				pParams->Stream.fRecordEnabled				= TBX_TRUE;
				pParams->Stream.PacketType					= TBX_STREAM_PACKET_TYPE_PCMU;
				pParams->Stream.PacketDurationMs 			= TBX_STREAM_PACKET_DURATION_160MS;
				pParams->Stream.un32JitterBufferSize 		= 4;
			}

			/* Send the request */
			Result = TBXSendMsg (in_hLib, hMsg, &pahFilter[un32ResIndex]);
			hMsg = TBX_HANDLE_INVALID;
			if (TBX_RESULT_FAILURE(Result) )
				break;

			un32SendMsgCnt++;
		}

		for( un32ResIndex = 0; un32ResIndex < un32SendMsgCnt; un32ResIndex++ )
		{
			pMsgVpResAlloc = NULL;

			/* Wait for the response synchronously */
			hMsg = TBX_HANDLE_INVALID;
			Result = TBXReceiveMsg (in_hLib, pahFilter[un32ResIndex], TB640_TONE_RECEIVE_TIMEOUT_MSEC, &hMsg);
			if (TBX_RESULT_SUCCESS (Result))
			{
				/* We got the response */
				pMsgVpResAlloc = TBX_MSG_PAYLOAD_POINTER (hMsg);

				Result = pMsgVpResAlloc->Response.Result;
				if (TBX_RESULT_SUCCESS (Result))
				{
					if( out_phTdmRes )
						out_phTdmRes[un32ResIndex] = pMsgVpResAlloc->Response.ahResources[0];

					if( out_phStrmRes )
						out_phStrmRes[un32ResIndex] = pMsgVpResAlloc->Response.ahResources[1];

					if( out_phGroupRes )
						out_phGroupRes[un32ResIndex] = pMsgVpResAlloc->Response.hVPGroup;
				}
			}

			/* Release the filter */
			if( pahFilter[un32ResIndex] != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID )
			{
				TBXDestroyMsgFilter (in_hLib, pahFilter[un32ResIndex]);
				pahFilter[un32ResIndex] = TBX_HANDLE_INVALID;
			}

			/* Free the message buffer */
			if( hMsg != TBX_HANDLE_INVALID )
			{
				/* Free the message */
				TBXReleaseMsg (in_hLib, hMsg);
				hMsg = TBX_HANDLE_INVALID;
			}
		}

		if( pahFilter )
			free( pahFilter );

		/* Was there an error along in the process ? */
		if (TBX_RESULT_FAILURE (Result))
		{
			TBX_EXIT_ERROR (Result, 0, "ToneResAllocate Failed");
		}

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print the error to the user */
		/*fprintf (stderr, "%s\n", TBX_ERROR_DESCRIPTION);*/
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{

	}

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  ToneVpGrpFree			:	Frees a Vp Group
 |
 |  in_hLib					:	Handle to the TBX library returned by TBXOpenLib()
 |  in_hAdapter				:	Handle to an adapter that was previously selected and attached to by SelectAdapter()
 |  in_hVpGrp				:	Vp Group to free
 |
 |  Note					:	~
 |
 |  Return					:	TBX_RESULT_OK
 |								TBX_RESULT_FAIL
 |								or others
 |
 *------------------------------------------------------------------------------------------------------------------------------*/

TBX_RESULT ToneVpGrpFree (
  IN		TBX_LIB_HANDLE				in_hLib,
  IN		TBX_ADAPTER_HANDLE			in_hAdapter,
  IN		TB640_RESOURCE_HANDLE 		in_hVpGrp )
{
	TBX_RESULT_API						Result;
	PTB640_MSG_VP_GROUP_FREE		pMsgToneVpGrpFree;
	TBX_MSG_HANDLE						hMsg;
	TBX_FILTER_HANDLE					hFilter;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Get a message buffer */
		Result = TBXGetMsg (in_hLib, sizeof(*pMsgToneVpGrpFree), &hMsg);

		if (TBX_RESULT_SUCCESS (Result))
		{
			/* Clear the buffer... */
			memset (TBX_MSG_PAYLOAD_POINTER (hMsg), 0, TBX_MSG_PAYLOAD_MAX_LENGTH_GET (hMsg));

			/* Set the message header */
			TBX_FORMAT_MSG_HEADER (
				hMsg,
				TB640_MSG_ID_VP_GROUP_FREE,
				TBX_MSG_TYPE_REQUEST,
				sizeof(*pMsgToneVpGrpFree),
				in_hAdapter,
				0,
				0);

			/* Fill the request */
			pMsgToneVpGrpFree = TBX_MSG_PAYLOAD_POINTER (hMsg);
			pMsgToneVpGrpFree->Request.un32MsgVersion = 1;
			pMsgToneVpGrpFree->Request.hVPGroup = in_hVpGrp;

			/* Send the request */
			Result = TBXSendMsg (in_hLib, hMsg, &hFilter);
			hMsg = TBX_HANDLE_INVALID;
			if (TBX_RESULT_SUCCESS (Result))
			{
				pMsgToneVpGrpFree = NULL;

				/* Wait for the response synchronously */
				Result = TBXReceiveMsg (in_hLib, hFilter, TB640_TONE_RECEIVE_TIMEOUT_MSEC, &hMsg);
				if (TBX_RESULT_SUCCESS (Result))
				{
					/* We got the response */
					pMsgToneVpGrpFree = TBX_MSG_PAYLOAD_POINTER (hMsg);

					Result = pMsgToneVpGrpFree->Response.Result;
				}
			}

			/* Release the filter */
			if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
			{
				TBXDestroyMsgFilter (in_hLib, hFilter);
				hFilter = TBX_HANDLE_INVALID;
			}
		}

		/* Free the message buffer */
		if (hMsg != TBX_HANDLE_INVALID)
		{
			/* Free the message */
			TBXReleaseMsg (in_hLib, hMsg);
			hMsg = TBX_HANDLE_INVALID;
		}

		/* Was there an error along in the process ? */
		if (TBX_RESULT_FAILURE (Result))
		{

⌨️ 快捷键说明

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