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

📄 tone.c

📁 telcobridges tone develop
💻 C
📖 第 1 页 / 共 5 页
字号:
		}

		TBX_FIFO_DESTROY(&msToneFifo);
	}

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  ToneFreeAllResAndConnection	:	Free all allocated resources and connections
 |
 |  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()
 |
 |
 |  Note					:	~
 |
 |  Return					:	TBX_RESULT_OK
 |								TBX_RESULT_FAIL
 |								or others
 |
 *------------------------------------------------------------------------------------------------------------------------------*/

TBX_RESULT ToneFreeAllResAndConnection (
  IN		TBX_LIB_HANDLE				in_hLib,
  IN		TBX_ADAPTER_HANDLE			in_hAdapter )
 {
	TBX_RESULT_API						Result;
	TBX_UINT32							un32FreedCnx;
	TBX_UINT32							un32FreedVpGrp;
	TBX_UINT32							un32FreedTrunkRes;
	TBX_UINT32							un32TotalCnx;
	TBX_UINT32							un32TotalVpGrp;
	TBX_UINT32							un32TotalTrunkRes;
	TBX_UINT32							un32TimeSlot;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		un32FreedCnx		= 0;
		un32FreedVpGrp		= 0;
		un32FreedTrunkRes	= 0;
		un32TotalCnx		= 0;
		un32TotalVpGrp		= 0;
		un32TotalTrunkRes	= 0;

		/* Free all connections */
		for( un32TimeSlot = 0; un32TimeSlot < sizeof(g_ahConn)/sizeof(*g_ahConn); un32TimeSlot++ )
		{
			if( g_ahConn[un32TimeSlot] != -1 )
			{
				Result = ToneDisconnect(in_hLib, in_hAdapter, g_ahConn[un32TimeSlot] );
				if( TBX_RESULT_SUCCESS(Result) )
				{
					g_ahConn[un32TimeSlot] = -1;
					un32FreedCnx++;
				}

				un32TotalCnx++;
			}
		}

		/* Free all stream Res */
		for( un32TimeSlot = 0; un32TimeSlot < sizeof(g_ahStrmRes)/sizeof(*g_ahStrmRes); un32TimeSlot++ )
		{
			if( g_ahStrmRes[un32TimeSlot] != -1 )
			{
				Result = StrmResFree(in_hLib, in_hAdapter, g_ahStrmRes[un32TimeSlot] );
				if( TBX_RESULT_SUCCESS(Result) )
				{
					g_ahStrmRes[un32TimeSlot] = -1;
					un32FreedCnx++;
				}

				un32TotalCnx++;
			}
		}

		for( un32TimeSlot = 0; un32TimeSlot < sizeof(g_ahVpGrp)/sizeof(*g_ahVpGrp); un32TimeSlot++ )
		{
			if( g_ahVpGrp[un32TimeSlot] != -1 )
			{
				Result = ToneVpGrpFree( in_hLib, in_hAdapter, g_ahVpGrp[un32TimeSlot] );
				if( TBX_RESULT_SUCCESS(Result) )
				{
					g_ahVpGrp[un32TimeSlot] = -1;
					un32FreedVpGrp++;
				}

				un32TotalVpGrp++;
			}

			if( g_ahTrunkRes[un32TimeSlot] != -1 )
			{
				Result = ToneTrunkResFree( in_hLib, in_hAdapter, g_ahTrunkRes[un32TimeSlot] );
				if( TBX_RESULT_SUCCESS(Result) )
				{
					g_ahTrunkRes[un32TimeSlot] = -1;
					un32FreedTrunkRes++;
				}

				un32TotalTrunkRes++;
			}
		}

		fprintf (stdout, "Freed %d/%d connections\n", un32FreedCnx, un32TotalCnx );
		fprintf (stdout, "Freed %d/%d Vp groups\n", un32FreedVpGrp, un32TotalVpGrp );
		fprintf (stdout, "Freed %d/%d trunk resources\n", un32FreedTrunkRes, un32TotalTrunkRes );

		/* 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;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  ToneCollectAllocate		:
 |
 |  Note					:	~
 |
 |  Return					:	TBX_RESULT_OK
 |								TBX_RESULT_FAIL
 |								or others
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT ToneCollectAllocate (
  IN	TBX_LIB_HANDLE				in_hLib,
  IN	TB640_VP_DIGIT_TYPE			in_TerminatingDigit,
  IN	TBX_UINT32					in_un32MsFirstDigitTimeout,
  IN	TBX_UINT32					in_un32MsInterDigitTimeout,
  IN	TBX_UINT32					in_un32NbToneMax,
  IN	TB640_RESOURCE_HANDLE		in_hRes )
{
	TBX_RESULT_API						Result;
	PTONE_MSG_COLLECTOR_ALLOC			pMsgCollectAlloc;
	TBX_MSG_HANDLE						hMsg;
	TBX_FILTER_HANDLE					hFilter;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		Result = TBXGetMsg( in_hLib, sizeof(*pMsgCollectAlloc), &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,
			TONE_MSG_ID_COLLECTOR_ALLOC,
			TBX_MSG_TYPE_REQUEST,
			sizeof(*pMsgCollectAlloc),
			TBX_HOSTLIB_ADAPTER_HANDLE,
			0,
			0);

		/* Fill the request */
		pMsgCollectAlloc = TBX_MSG_PAYLOAD_POINTER (hMsg);
		pMsgCollectAlloc->Request.un32MsgVersion 			= 1;
		pMsgCollectAlloc->Request.hRes						= in_hRes;
		pMsgCollectAlloc->Request.TerminatingDigit	 		= in_TerminatingDigit;
		pMsgCollectAlloc->Request.un32MsFirstDigitTimeout 	= in_un32MsFirstDigitTimeout;
		pMsgCollectAlloc->Request.un32MsInterDigitTimeout 	= in_un32MsInterDigitTimeout;
		pMsgCollectAlloc->Request.un32NbToneMax 			= in_un32NbToneMax;
		pMsgCollectAlloc->Request.un64UserCtx1 				= 0;
		pMsgCollectAlloc->Request.un64UserCtx2 				= 0;

		Result = TBXSendMsg( in_hLib, hMsg, &hFilter );
		if( TBX_RESULT_FAILURE( Result ) )
		{
			TBX_EXIT_ERROR(Result, 0, "Error 0x%X in TBXSendMsg" );
		}

		/* 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 */
			pMsgCollectAlloc = TBX_MSG_PAYLOAD_POINTER (hMsg);

			Result = pMsgCollectAlloc->Response.Result;
		}

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

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

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		fprintf( stderr, "ToneCollectAllocate: %s\n", TBX_ERROR_DESCRIPTION );
 	}

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

	}

	RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  StrmResAllocate		:
 |
 |  Note					:	~
 |
 |  Return					:	TBX_RESULT_OK
 |								TBX_RESULT_FAIL
 |								or others
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_UINT16 g_udpPort = 20000;
TBX_RESULT StrmResAllocate (
  IN	TBX_LIB_HANDLE				in_hLib,
  IN	TBX_ADAPTER_HANDLE			in_hAdapter,
  OUT	PTB640_RESOURCE_HANDLE		out_phRes )
{
	TBX_RESULT_API						Result;
	PTB640_MSG_STREAM_RES_ALLOC			pMsgStrmResAlloc;
	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(*pMsgStrmResAlloc), &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_ALLOC,
				TBX_MSG_TYPE_REQUEST,
				sizeof(*pMsgStrmResAlloc),
				in_hAdapter,
				0,
				0);

			/* Fill the request */
			pMsgStrmResAlloc = TBX_MSG_PAYLOAD_POINTER (hMsg);
			pMsgStrmResAlloc->Request.un32MsgVersion = 1;
			pMsgStrmResAlloc->Request.StreamResParams.ResType			= TB640_RESDEF_TYPE_FD;
			pMsgStrmResAlloc->Request.StreamResParams.PacketDurationMs 	= TBX_STREAM_PACKET_DURATION_160MS;
			pMsgStrmResAlloc->Request.StreamResParams.PacketType	   	= TBX_STREAM_PACKET_TYPE_PCMU;
			pMsgStrmResAlloc->Request.StreamResParams.Interface			= TB640_STREAM_INTERFACE_TYPE_BASE;
			pMsgStrmResAlloc->Request.StreamResParams.RedundancyMode	= TBX_STREAM_NETWORK_REDUNDANCY_MODE_DUPLICATE;
			pMsgStrmResAlloc->Request.StreamResParams.fUseRtpOverRawIp	= TBX_TRUE;
			pMsgStrmResAlloc->Request.StreamResParams.fUseRtcp			= TBX_FALSE;
			pMsgStrmResAlloc->Request.StreamResParams.un16FromNetworkIPPort		= g_udpPort;
			pMsgStrmResAlloc->Request.StreamResParams.un16ToNetworkIPPort		= g_udpPort++;
			strcpy( pMsgStrmResAlloc->Request.StreamResParams.szIPAddr0, "10.0.0.197" );
			strcpy( pMsgStrmResAlloc->Request.StreamResParams.szIPAddr1, "10.0.0.197" );

			/* Send the request */
			Result = TBXSendMsg (in_hLib, hMsg, &hFilter);
			hMsg = TBX_HANDLE_INVALID;
			if (TBX_RESULT_SUCCESS (Result))
			{
				pMsgStrmResAlloc = 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 */
					pMsgStrmResAlloc = TBX_MSG_PAYLOAD_POINTER (hMsg);

					Result = pMsgStrmResAlloc->Response.Result;
					*out_phRes = pMsgStrmResAlloc->Response.hStreamRes;
				}
			}

			/* 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, "StrmResAllocate Failed");
		}

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

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

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

	}

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  StrmResFree		:
 |
 |  Note					:	~
 |
 |  Return					:	TBX_RESULT_OK
 |								TBX_RESULT_FAIL
 |								or others
 |
 *------------------------------------------------------------------------------------------------------------------------------*/

TBX_RESULT StrmResFree (
  IN	TBX_LIB_HANDLE				in_hLib,
  IN	TBX_ADAPTER_HANDLE			in_hAdapter,
  IN	TB640_RESOURCE_HANDLE		in_hRes )
{
	TBX_RESULT_API						Result;

⌨️ 快捷键说明

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