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

📄 voip_raw_data_file.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 5 页
字号:
		(
			in_pAdapterContext,
			TRACE_LEVEL_ERROR,
			"VoipHandleStreamStopConfirmed:%s (Result 0x%X)\n",
			TBX_ERROR_DESCRIPTION,
			(int)TBX_ERROR_RESULT
		);
	}

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

	RETURN;
}

/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStreamLibGetDataAddrCallback	:	Sample TBX Stream library callback.
 |
 |	in_hPlay					:	Handle of the playback that requires more data to play.
 |	in_un64UserContext			:	User context for that port passed when called TBXStreamPlay()
 |  in_hAcknowledge				:	Acknowledge handle: Handle that must be used when
 |									TBXStreamAcknowledgeCallback() is called.
 |	out_ppBuffer				:	Pointer to fill with the pointer to the next data to send
 |
 |  Note						:	This callbacks expects a context that is a file pointer (FILE*).
 |									This callback reads a chunk of data from the file, then acknowledges
 |									the stream library that the data is ready.
 |
 |  Return						:	TBX_RESULT_API_OK
 |									TBX_RESULT_API_NULL_PARAM
 |									TBX_RESULT_API_NOT_ENOUGH_MEMORY
 |									TBX_RESULT_API_INVALID_TRANSPORT_TYPE
 |									TBX_RESULT_API_GATEWAY_NOT_FOUND
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipStreamLibGetDataAddrCallback(
	IN		TBX_STREAM_LIB_HANDLE		in_hLib,
	IN		TBX_STREAM_LIB_PLAY_HANDLE	in_hPlay,
	IN		TBX_STREAM_LIB_ACK_HANDLE	in_hAcknowledge,
	IN		TBX_UINT64					in_un64UserContext,
	OUT		PTBX_VOID*					out_ppBuffer)
{
	TBX_RESULT							Result;
	PVOIP_EVT_OP_STREAMING_GET_DATA_ADDR	pEvt;
	TBX_MSG_HANDLE						hMsg;
	TBX_UINT32							un32MsgSize;
	PVOIP_CLI_CONTEXT					pCliContext;
	TBX_ADAPTER_HANDLE					hAdapter;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		pCliContext	= &g_pContext->CliContext;
		pEvt		= NULL;

		TbxCliToolsLogPrint
		(
			pCliContext->hCliTools,
			TRACE_LEVEL_2, NULL,
			"VoipStreamLibGetDataAddrCallback\n"
		);

		hAdapter = (TBX_UINT32)(in_un64UserContext >> 32) & 0xFFFFFFFF;

		/* Allocate a message buffer */
		un32MsgSize = sizeof(*pEvt);
		Result = TBXGetMsg (g_pContext->hTbxLib, un32MsgSize , &hMsg);
		if (TBX_RESULT_FAILURE (Result))
		{
			TBX_EXIT_ERROR (Result, 0, "Failed to get message buffer.");
		}

		/* 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,
			VOIP_MSG_ID_OP_STREAM_GET_DATA_ADDR,
			TBX_MSG_TYPE_REQUEST,
			un32MsgSize,
			TBX_HOSTLIB_ADAPTER_HANDLE,
			hAdapter,
			0
		);

		/* Fill the request */

		pEvt = (PVOIP_EVT_OP_STREAMING_GET_DATA_ADDR) TBX_MSG_PAYLOAD_POINTER (hMsg);
		pEvt->un32MsgVersion		= 1;
		pEvt->hAcknowledge			= in_hAcknowledge;
		pEvt->hPlay					= in_hPlay;
		pEvt->ppBuffer				= out_ppBuffer;
		pEvt->un64Id				= in_un64UserContext;

		/* Send the message */
		Result	= TBXSendMsg (g_pContext->hTbxLib, hMsg, NULL);
		hMsg	= TBX_HANDLE_INVALID;
		pEvt	= NULL;

		if (TBX_RESULT_FAILURE (Result))
		{
			TBX_EXIT_ERROR (Result, 0, "Failed to send message buffer.");
		}

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		TbxCliToolsLogPrint
		(
			pCliContext->hCliTools,
			TRACE_LEVEL_ERROR, NULL,
			"VoipStreamLibGetDataAddrCallback: %s, result 0x%08X\n",
			TBX_ERROR_DESCRIPTION,
			(int)TBX_ERROR_RESULT
		);

		/* Force an acknowledge to the stream lib */
		TBXStreamAcknowledgeCallback
		(
			g_pContext->hStreamLib,
			in_hAcknowledge,
			0,
			0,	/* Offset in buffer: 0 */
			TBX_TRUE
		);

	}

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipHandleStreamGetDataAddr:	Handles a request from the steam lib to get new data.
 |
 |  io_pAdapterContext		:	Context of the adapter
 |	in_hMsg					:	Message received for this adapter
 |
 |  Note					:	~
 |
 |  Return					:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipHandleStreamGetDataAddr(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_MSG_HANDLE			in_hMsg)
{
	PVOIP_EVT_OP_STREAMING_GET_DATA_ADDR	pEvent;
	PVOIP_RAW_DATA_FILE_CONTEXT				pRawDataFileContext;
	TBX_BOOL								fLastBuffer;
	TBX_UINT32								un32DataSize;
	TBX_BOOL								fRepetitionCompleted;
										
	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		fLastBuffer					= TBX_FALSE;
		pEvent						= TBX_MSG_PAYLOAD_POINTER( in_hMsg );
		un32DataSize				= 0;
		fRepetitionCompleted		= TBX_FALSE;

		VoipCliAdapterStatePrint
		( 
			in_pAdapterContext,
			TRACE_LEVEL_2,
			"Get data request from streamlib for raw data file %u on adapter %s.\n",
			(unsigned int)pEvent->un64Id & 0xFFFFFFFF,
			in_pAdapterContext->AdapterInfo.szSerialNumber
		);

		TBXHash64Find
		(
			in_pAdapterContext->CurrentConfig.hRawDataFileIdHash64,
			(TBX_HASH_64_KEY)pEvent->un64Id,
			&pRawDataFileContext
		);
		if( !pRawDataFileContext || !pRawDataFileContext->fAllocated )
		{
		    TBX_EXIT_ERROR( TBX_RESULT_FAIL, 0, "Could not find raw data file context!" );
		}

		if( pRawDataFileContext->PlayContext.fStopping || pRawDataFileContext->fCleanupPending )
		{
			/* No more data or test is stopping. */
			/* Acknowledge the stream library. */
			TBXStreamAcknowledgeCallback
			(
				g_pContext->hStreamLib,
				pEvent->hAcknowledge,
				0,
				0,	/* Offset in buffer: 0 */
				TBX_TRUE
			);
			TBX_EXIT_SUCCESS( TBX_RESULT_OK );
		}

		/* Update test context */
		if( pRawDataFileContext->PlayContext.un32RepeatCount != VOIP_DURATION_INFINITE &&
			pRawDataFileContext->PlayContext.un32CurrentRepetition > pRawDataFileContext->PlayContext.un32RepeatCount )
		{
			/* All data has been sent. Return 0 byte. */
			un32DataSize = 0;
			fLastBuffer = TBX_TRUE;
		}
		else
		{
			/* There is still data to be sent. */
			pRawDataFileContext->PlayContext.fPlaying = TBX_TRUE;
			un32DataSize = pRawDataFileContext->PlayContext.un32DataSize;

			/* Verify is this buffer is the last one */
			if( pRawDataFileContext->PlayContext.un32RepeatCount == VOIP_DURATION_INFINITE ||
				pRawDataFileContext->PlayContext.un32CurrentRepetition < pRawDataFileContext->PlayContext.un32RepeatCount )
			{
				/* Clear the last buffer flag */
				fLastBuffer = TBX_FALSE;
			}
			else
			{
				
				/* Test is finished after this buffer*/
				fLastBuffer = TBX_TRUE;
			}

			/* Increment current repetition */
			pRawDataFileContext->PlayContext.un32CurrentRepetition++;
		}

		/* Acknowledge the stream library */
		*pEvent->ppBuffer = pRawDataFileContext->PlayContext.pData;
		TBXStreamAcknowledgeCallback
		(
			g_pContext->hStreamLib,
			pEvent->hAcknowledge,
			un32DataSize,
			0,	/* Offset in buffer: 0 */
			fLastBuffer
		);


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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		VoipCliAdapterStatePrint
		(
			in_pAdapterContext,
			TRACE_LEVEL_ERROR,
			"VoipHandleStreamGetDataAddr:%s (Result 0x%X)\n",
			TBX_ERROR_DESCRIPTION,
			(int)TBX_ERROR_RESULT
		);
	}

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipHandleRawDataFileReceivedData:	Handles data received on a channel of type data.
 |
 |  io_pAdapterContext		:	Context of the adapter
 |	in_hMsg					:	Message received for this adapter
 |
 |  Note					:	~
 |
 |  Return					:	~
 |
 *-------------------------------------------------------------------------------------------------------------------------------*/
static TBX_RESULT	VoipHandleRawDataFileReceivedData
(
	IN		PVOIP_ADAPTER_CONTEXT		in_pAdapterContext,
	IN		PVOIP_RAW_DATA_FILE_CONTEXT	in_pRawDataFileContext,
	IN		PTBX_BYTE					in_pbyBuffer,
	IN		TBX_UINT32					in_un32BufferLen
)
{
									
	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */

		if( in_pRawDataFileContext->RecordContext.hRecord != (TBX_STREAM_LIB_PLAY_HANDLE) TBX_HANDLE_INVALID )
		{
			VoipCliAdapterStatePrint
			(
				in_pAdapterContext,
				TRACE_LEVEL_1,
				"Save packet request from streamlib for raw data file %u on adapter %s.\n",
				(unsigned int)in_pRawDataFileContext->un64Id & 0xFFFFFFFF,
				in_pAdapterContext->AdapterInfo.szSerialNumber
			);
		}
		else
		{
			VoipCliAdapterStatePrint
			(
				in_pAdapterContext,
				TRACE_LEVEL_1,
				"%d bytes received for raw data file %d on adapter %s.\n",
				(unsigned int)in_un32BufferLen,
				(unsigned int)in_pRawDataFileContext->un64Id,
				in_pAdapterContext->AdapterInfo.szSerialNumber
			);
			TBX_EXIT_SUCCESS( TBX_RESULT_OK );
		}


		/* Write data to file */
		if( in_pRawDataFileContext->RecordContext.pFile )
		{
			fwrite( in_pbyBuffer, 1, in_un32BufferLen, in_pRawDataFileContext->RecordContext.pFile );
		}

		/* Update start time */
		if( in_pRawDataFileContext->RecordContext.un32StartTime == 0 )
		{
			in_pRawDataFileContext->RecordContext.un32StartTime = g_pContext->un32TimerCurrentTime;
		}

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--

⌨️ 快捷键说明

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