📄 cmutils.c
字号:
}
#endif /* (RV_LOGMASK_COMPILEMASK & (RV_LOGLEVEL_DEBUG | RV_LOGLEVEL_ERROR)) */
/* non standard parameter________________________________________________________________________________ */
RVAPI int RVCALLCONV /* RV_TRUE or RV_ERROR_UNKNOWN */
cmNonStandardParameterCreate(
/* Create NonStandardParameter tree */
IN HPVT hVal,
IN int rootId, /* nonStandardData */
IN cmNonStandardIdentifier *identifier,
IN char *data,
IN int dataLength /* in bytes */
)
{
int ret = -1;
if (!hVal || rootId<0 || !data || dataLength<0 || !identifier) return RV_ERROR_UNKNOWN;
if (identifier->objectLength >0) {
char buff[128];
int buffLen;
strcpy(buff, "");
buffLen = oidEncodeOID(sizeof(buff), buff, identifier->object);
if (buffLen>0)
{
pvtBuildByPath(hVal, rootId, "data", dataLength, data);
ret=pvtBuildByPath(hVal, rootId, "nonStandardIdentifier.object", buffLen, buff);
}
}
else {
int h221Id = pvtBuildByPath(hVal, rootId, "nonStandardIdentifier.h221NonStandard", 0, NULL);
int iCountryCode = identifier->t35CountryCode;
int iExtension = identifier->t35Extension;
int iManufacturerCode = identifier->manufacturerCode;
pvtBuildByPath(hVal, rootId, "data", dataLength, data);
pvtBuildByPath(hVal, h221Id, "t35CountryCode", iCountryCode, NULL);
pvtBuildByPath(hVal, h221Id, "t35Extension", iExtension, NULL);
ret=pvtBuildByPath(hVal, h221Id, "manufacturerCode", iManufacturerCode, NULL);
}
return ret;
}
RVAPI int RVCALLCONV /* RV_TRUE or RV_ERROR_UNKNOWN */
cmNonStandardParameterGet(
/* Convert NonStandardParameter tree to C structures */
IN HPVT hVal,
IN int rootId, /* nonStandardData */
OUT cmNonStandardIdentifier *identifier,
OUT char *data,
INOUT RvInt32 *dataLength /* (in bytes) IN: data allocation. OUT: correct size */
)
{
int id;
int len;
if (!hVal ||
!data || !dataLength || *dataLength<0 ||
!identifier) return RV_ERROR_UNKNOWN;
if (rootId<0)
{
*dataLength=RV_ERROR_UNKNOWN;
return RV_ERROR_UNKNOWN;
}
id = pvtGetByPath(hVal, rootId, "data", NULL, &len, NULL);
pvtGetString(hVal, id, *dataLength, data);
*dataLength = len;
/* -- object id */
identifier->object[0]=0;
identifier->objectLength=0;
if ( (id = pvtGetByPath(hVal, rootId, "nonStandardIdentifier.object", NULL, NULL, NULL)) >0) {
char buff[128];
int buffLen;
strcpy(buff, "");
buffLen=pvtGetString(hVal, id, sizeof(buff), buff);
oidDecodeOID(buffLen, buff, sizeof(identifier->object), identifier->object, numberForm);
identifier->objectLength=strlen(identifier->object);
}
/* -- h221 id */
identifier->t35CountryCode=0;
identifier->t35Extension=0;
identifier->manufacturerCode=0;
if ( (id = pvtGetByPath(hVal, rootId, "nonStandardIdentifier.h221NonStandard", NULL, NULL, NULL)) >0) {
RvInt32 value;
pvtGetByPath(hVal, id, "t35CountryCode", NULL, &value, NULL);
identifier->t35CountryCode=(RvUint8)value;
pvtGetByPath(hVal, id, "t35Extension", NULL, &value, NULL);
identifier->t35Extension=(RvUint8)value;
pvtGetByPath(hVal, id, "manufacturerCode", NULL, &value, NULL);
identifier->manufacturerCode=(RvUint16)value;
}
return RV_TRUE;
}
/********************************************************************************************
* freeThreadBuffer
* An exit callback of a specific thread encode/decode buffer.
* This function frees the allocation of the encode/decode buffer
* context - The pointer to the buffer to free
********************************************************************************************/
static void freeThreadBuffer(IN RvThread* thread, IN void * context, IN RvUint32 index)
{
cmThreadCoderLocalStorage* cmTls = (cmThreadCoderLocalStorage *)context;
RV_UNUSED_ARG(thread);
RV_UNUSED_ARG(index);
if (cmTls == NULL)
return;
if(cmTls->buffer != NULL)
{
RvMemoryFree(cmTls->buffer);
cmTls->buffer = NULL;
}
RvMemoryFree(cmTls);
}
/**************************************************************************************
* encodeDecodeBufferInit
*
* Purpose: To initialize the buffer for coding purposes.
*
* Input: none
*
* Output: none
*
**************************************************************************************/
void encodeDecodeBufferInit(void)
{
if(timesTlsInitialized == 0)
{
if(RvThreadCreateVar(freeThreadBuffer, "RvEdmBuffer", &rvEncoderTlsIndex) != RV_OK)
return;
}
timesTlsInitialized++;
}
/**************************************************************************************
* getEncodeDecodeBuffer
*
* Purpose: To get the buffer for coding purposes.
*
* Input: bufferSize - The size of buffer required.
* buffer - A pointer to the buffer.
*
*
* Output: buffer - A pointer to the buffer .
*
**************************************************************************************/
void getEncodeDecodeBuffer(IN int bufferSize, OUT RvUint8 **buffer)
{
RvThread* curThread;
cmThreadCoderLocalStorage* cmTls;
if (buffer)
*buffer = NULL;
/* First, make sure we have a thread object for this thread. */
curThread = RvThreadCurrent();
if (curThread == NULL)
{
static int appThreadNum = 0;
RvChar threadName[20];
RvStatus status;
/* Seems like we'll need to create one on our own. */
status = RvMemoryAlloc(NULL, (void**)&curThread, sizeof(RvThread));
if (status != RV_OK)
return;
status = RvThreadConstructFromUserThread(curThread);
if (status == RV_OK)
status = RvThreadSetAutoDelete(curThread, RV_TRUE);
if (status == RV_OK)
{
RvSprintf(threadName, "%d H323User", appThreadNum);
status = RvThreadSetName(curThread, threadName);
}
if (status != RV_OK)
{
RvMemoryFree(curThread);
return;
}
}
if((timesTlsInitialized <= 0) ||
(RvThreadGetVar(rvEncoderTlsIndex, (void**)&cmTls) != RV_OK))
{
return;
}
if(cmTls == NULL)
{
RvMemoryAlloc(NULL, (void**)&cmTls, sizeof(cmThreadCoderLocalStorage));
memset((void*)cmTls, 0, sizeof(cmThreadCoderLocalStorage));
RvThreadSetVar(rvEncoderTlsIndex, (void*)cmTls);
}
if((cmTls->buffer != NULL) && ((int)cmTls->bufferSize < bufferSize))
{
/* Current allocation too small - make sure we fix this situation... */
RvMemoryFree(cmTls->buffer);
cmTls->buffer = NULL;
}
if (cmTls->buffer == NULL)
{
cmTls->bufferSize = bufferSize;
if(RvMemoryAlloc(NULL, (void**)&cmTls->buffer, cmTls->bufferSize) != RV_OK)
return;
}
if (buffer)
*buffer = cmTls->buffer;
}
/**************************************************************************************
* encodeDecodeBufferEnd
*
* Purpose: close down the local storage.
*
* Input: none.
* Output: none.
*
**************************************************************************************/
void encodeDecodeBufferEnd(void)
{
timesTlsInitialized--;
if(timesTlsInitialized == 0)
RvThreadDeleteVar(rvEncoderTlsIndex);
}
/**************************************************************************************
* cleanMessage
*
* Purpose: Deletes all tunneling elements (H.245, H.450, annex M, annex L) from the
* given message. This is to avoid resending tunneled messages when reusing
* messages from the cm Property tree.
*
* Input: hPvt - handle to the PVT of the message
* message - A pvt node to the message.
*
* Output: None.
*
**************************************************************************************/
void cleanMessage(IN HPVT hPvt, IN int message)
{
int messageBodyNode;
int node;
/* position on the UU-IE part of the message */
__pvtGetNodeIdByFieldIds( messageBodyNode,
hPvt,
message,
{ _q931(message)
_anyField
_q931(userUser)
_q931(h323_UserInformation)
_q931(h323_uu_pdu)
LAST_TOKEN
});
if (messageBodyNode < 0)
return;
/* Clean the parallel tunneling element, if exists */
__pvtGetNodeIdByFieldIds( node,
hPvt,
messageBodyNode,
{ _q931(h323_message_body)
_q931(setup)
_q931(parallelH245Control)
LAST_TOKEN
});
if (node >= 0)
pvtDelete(hPvt, node);
/* Clean the H.245 tunneling element, if exists */
__pvtGetNodeIdByFieldIds( node,
hPvt,
messageBodyNode,
{ _q931(h245Control)
LAST_TOKEN
});
if (node >= 0)
pvtDelete(hPvt, node);
/* Clean the H.450 element, if exists */
__pvtGetNodeIdByFieldIds( node,
hPvt,
messageBodyNode,
{ _q931(h4501SupplementaryService)
LAST_TOKEN
});
if (node >= 0)
pvtDelete(hPvt, node);
/* Clean the Annex L element, if exists */
__pvtGetNodeIdByFieldIds( node,
hPvt,
messageBodyNode,
{ _q931(stimulusControl)
LAST_TOKEN
});
if (node >= 0)
pvtDelete(hPvt, node);
/* Clean the annex M element, if exists */
__pvtGetNodeIdByFieldIds( node,
hPvt,
messageBodyNode,
{ _q931(tunnelledSignallingMessage)
LAST_TOKEN
});
if (node >= 0)
pvtDelete(hPvt, node);
}
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -