📄 perseq.c
字号:
#ifdef __cplusplus
extern "C" {
#endif
/*
***********************************************************************************
NOTICE:
This document contains information that is proprietary to RADVISION LTD..
No part of this publication may be reproduced in any form whatsoever without
written prior approval by RADVISION LTD..
RADVISION LTD. reserves the right to revise this publication and make changes
without obligation to notify any person of such revisions or changes.
***********************************************************************************
*/
/*
perSequence.c
Extension encoding:
-------------------
- encode field.
- complete encoding (padding).
- open type encoding (length prefix)
------------------------
| length | field | pad |
------------------------
| 1/2oc. | n octets |
------------------------
Ron S.
14 May 1996
____________________________________________________________________________
___________________________SEQUENCE_________________________________________
____________________________________________________________________________
Format:
+----------+-------------------+---------+ +---------+
| ext. bit | n bits (optional) | field-1 | ... | field-n |
+----------+-------------------+---------+ +---------+
Extensions:
+------------+---------------------+----------+ +----------+
| length (n) | n bits (Extensions) | Efield-1 | ... | Efield-n |
+------------+---------------------+----------+ +----------+
Efield-i: open type complete encoding.
+-----+--------+----------+-----+
| pad | length | encoding | pad |
+-----+--------+----------+-----+
*/
#include <stdio.h>
#include <perintr.h>
/*
Return: number of extended childs that actually exist in value tree.
*/
int
perGetNumOfExtendedChilds(IN HPER hPer,
IN int synParent,
IN int valParent)
{
perStruct *per = (perStruct *)hPer;
pstChildExt synChild;
int i, count=0;
int children;
RvUint32* iter;
children=pstGetNumberOfChildren(per->hSyn,synParent);
iter = pstGetChildExt(per->hSyn, synParent, 1, &synChild);
for (i=1; i<=children; i++)
{
if (synChild.isExtended && /* extended */
pvtGetChild(per->hVal, valParent, synChild.fieldId, NULL) >=0) /* exist */
{
count++;
}
iter = pstGetBrotherExt(per->hSyn, i+1, iter, &synChild);
}
return count;
}
/*
Desc: Encode the extended fields in a sequence type.
-- length: number of extended fields.
-- bit field: bit foreach extended field. true if exist.
-- list of extended fields, each as open type.
*/
int
perEncodeSequenceExt(IN HPER hPer,
IN int synParent,
IN int valParent,
IN RvInt32 fieldId)
{
perStruct *per = (perStruct *)hPer;
pstChildExt synChild;
int i, vtPath=-1, numOfExtendedChilds=0;
RvInt32 offset=-1;
RvUint8 ch=0;
int children;
RvUint32 * iter;
/* -- checks */
if (!per)
{
RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
"perEncodeSequenceExt: %s: Invalid parameters.",
pstGetFieldNamePtr(per->hSyn, fieldId)));
return RV_ERROR_UNKNOWN;
}
children=pstGetNumberOfChildren(per->hSyn,synParent);
/* -- length: 18.8: normally small length */
iter = pstGetChildExt(per->hSyn, synParent, 1, &synChild);
for (numOfExtendedChilds=0, i=1; i<=children; i++)
{
if (synChild.isExtended) numOfExtendedChilds++;
iter = pstGetBrotherExt(per->hSyn, i+1, iter, &synChild);
}
if (perEncodeLen(perLenTypeNORMALLY_SMALL, numOfExtendedChilds, 0, 0, per->hBB) < 0)
return RV_ERROR_UNKNOWN;
/* -- bit field:18.7 */
iter = pstGetChildExt(per->hSyn, synParent, 1, &synChild);
for (i=1; i<=children; i++)
{
if (synChild.isExtended)
{ /* extended */
perEncodeBool(
(pvtGetChild(per->hVal, valParent, synChild.fieldId, NULL) >=0) /* exist */,
per->hBB);
}
iter = pstGetBrotherExt(per->hSyn, i+1, iter, &synChild);
}
/* -- field encoding: 18.9 */
iter = pstGetChildExt(per->hSyn, synParent, 1, &synChild);
for (i=1; i<=children; i++)
{
if (synChild.isExtended)
{ /* extended */
if ((vtPath=pvtGetChild(per->hVal, valParent, synChild.fieldId,NULL)) >=0)
{ /* exist */
int childSynNodeId;
pstFieldSpeciality speciality=synChild.speciality;
RvBool wasTypeResolvedInRunTime=RV_FALSE;
if(bbAddTail(per->hBB, &ch, 0, RV_TRUE)<0) /* align buffer */
return RV_ERROR_UNKNOWN;
offset = bbBitsInUse(per->hBB);
if(speciality==pstDependingDependent || speciality==pstDependent)
{
pvtGet(per->hVal, vtPath, NULL, &childSynNodeId, NULL, NULL);
wasTypeResolvedInRunTime=RV_TRUE;
}
else
childSynNodeId=synChild.nodeId;
if (perEncNode(hPer, childSynNodeId, vtPath, synChild.fieldId, wasTypeResolvedInRunTime) < 0)
return RV_ERROR_UNKNOWN;
perEncodeComplete(hPer,(int)bbBitsInUse(per->hBB)-offset);
if (perEncodeOpenType(hPer, offset, synChild.fieldId)<0)
return RV_ERROR_UNKNOWN;
}
else
{ /* should be optional */
if ((synChild.isOptional == RV_FALSE) && (synChild.isDefault == RV_FALSE))
{ /* but is not */
RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
"perEncodeSequenceExt: non optional Child not found [%d]%s->%s.",
valParent, pstGetFieldNamePtr(per->hSyn, fieldId),
pstGetFieldNamePtr(per->hSyn, synChild.fieldId)));
return RV_ERROR_UNKNOWN;
}
}
}
iter = pstGetBrotherExt(per->hSyn, i+1, iter, &synChild);
}
return RV_TRUE;
}
/*
Desc: Encode a sequence node.
According to clause 18.
Node value has no meaning.
*/
int
perEncodeSequece(IN HPER hPer,
IN int synParent,
IN int valParent,
IN RvInt32 fieldId)
{
perStruct *per = (perStruct *)hPer;
pstChildExt synChild;
int i, vtPath=-1, numOfExtChilds=0;
int children;
RvUint32 * iter;
/* -- checks */
if (!per)
{
RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
"perEncodeSequence: Invalid parameters. [%s]",
pstGetFieldNamePtr(per->hSyn, fieldId)));
return RV_ERROR_UNKNOWN;
}
/* -- extension bit 18.1 */
if (pstGetIsExtended(per->hSyn,synParent) == RV_TRUE)
{ /* node has extension mark */
numOfExtChilds=perGetNumOfExtendedChilds(hPer, synParent, valParent);
perEncodeBool((numOfExtChilds>0) , per->hBB); /* has extended childs */
}
children=pstGetNumberOfChildren(per->hSyn,synParent);
/* -- preemble 18.2-18.3: bit for each optional child */
iter = pstGetChildExt(per->hSyn, synParent, 1, &synChild);
for (i=1; i<=children; i++)
{
if (synChild.isExtended == RV_FALSE && /* not extended */
((synChild.isOptional == RV_TRUE) || (synChild.isDefault == RV_TRUE))) /* optional child */
{
vtPath=pvtGetChild(per->hVal, valParent, synChild.fieldId, NULL);
perEncodeBool((vtPath>=0), per->hBB);/* exists */
}
iter = pstGetBrotherExt(per->hSyn, i+1, iter, &synChild);
}
/* -- preemble 18.4-18.6: encode fields */
iter = pstGetChildExt(per->hSyn, synParent, 1, &synChild);
for (i=1; i<=children; i++)
{
if (synChild.isExtended == RV_FALSE)
{ /* not extended */
if ((vtPath = pvtGetChild(per->hVal, valParent, synChild.fieldId, NULL)) >=0)
{/* exists */
int childSynNodeId;
RvBool wasTypeResolvedInRunTime=RV_FALSE;
if (synChild.speciality==pstDependingDependent ||
synChild.speciality==pstDependent)
{
pvtGet(per->hVal, vtPath, NULL, &childSynNodeId, NULL, NULL);
wasTypeResolvedInRunTime=RV_TRUE;
}
else
childSynNodeId=synChild.nodeId;
if (perEncNode(hPer, childSynNodeId, vtPath, synChild.fieldId, wasTypeResolvedInRunTime) < 0)
return RV_ERROR_UNKNOWN;
}
else
{
if ((synChild.isOptional == RV_FALSE) && (synChild.isDefault == RV_FALSE))
{ /* non-optional not found */
RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
"perEncodeSequence: Child not found %d->%s.",
valParent, pstGetFieldNamePtr(per->hSyn, synChild.fieldId)));
return RV_ERROR_UNKNOWN;
}
}
} /* not extended */
iter = pstGetBrotherExt(per->hSyn, i+1, iter, &synChild);
}
/* -- Extensions 18.7-18.9 */
if (numOfExtChilds >0)
if (perEncodeSequenceExt(hPer, synParent, valParent, fieldId)< 0)
return RV_ERROR_UNKNOWN;
return RV_TRUE;
}
/*_____________________________________decoding.........................................*/
/*
Desc: Decode a sequence node.
According to clause 18.
Node value has no meaning.
*/
int
perDecodeSequece(IN HPER hPer,
IN int synParent, /* parent in syntax tree */
IN int valParent, /* field parent in value tree */
IN RvInt32 fieldId) /* enum of current field */
{
perStruct *per = (perStruct *)hPer;
pstChildExt synChild;
RvBool isExtended=RV_FALSE; /* true if extensions exist */
RvBool optionalExist=RV_FALSE;
RvBool isExist=RV_FALSE;
RvUint32 dec = 0; /* decoded bits */
int i, vtPath, numOfOptionalChilds=0, extChild=-1;
RvUint32 from = per->decodingPosition; /* internal position */
RvInt32 saveLocation=-1;
RvUint32 extLen=0, fieldLen=0;
int children;
RvUint32* iter;
/* -- checks */
if (!per)
{
RvLogExcep(&rvPerErrLogSource, (&rvPerErrLogSource, "perDecodeSequece: Invalid parameters."));
return RV_ERROR_UNKNOWN;
}
/* -- add sequence value node */
vtPath=valParent;
if (fieldId!=RV_ERROR_UNKNOWN)
vtPath = pvtAdd(per->hVal, valParent, fieldId, -111, NULL, NULL);
/* -- first bit 18.1 */
if (pstGetIsExtended(per->hSyn,synParent) == RV_TRUE)
{ /* node has extension mark */
if (perDecodeBool(&isExtended, hPer, from, &dec) <0)
{
RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
"perDecodeSequece: extension bit missing [%s].",
pstGetFieldNamePtr(per->hSyn, fieldId)));
return RV_ERROR_UNKNOWN;
}
else from+=dec; /* advance decoding position */
}
/* -- preemble 18.2-18.6: bit for each optional child */
numOfOptionalChilds = pstGetNumberOfOptionalBeforeExtension(per->hSyn, synParent);
per->decodingPosition = from+numOfOptionalChilds; /* advance to end of bit field */
children= pstGetNumberOfChildren(per->hSyn,synParent);
iter = pstGetChildExt(per->hSyn, synParent, 1, &synChild);
for (i=1; i<=children; i++)
{
if (synChild.isExtended == RV_FALSE)
{ /* not extended */
if ((synChild.isOptional == RV_TRUE) || (synChild.isDefault == RV_TRUE))
{ /* optional child */
perDecodeBool(&optionalExist, hPer, from++, &dec);
if (optionalExist)
if (perDecNode(hPer, synChild.nodeId, synChild.speciality, vtPath, synChild.fieldId) <0)
return RV_ERROR_UNKNOWN;
}
else /* not optional */
if (perDecNode(hPer, synChild.nodeId, synChild.speciality, vtPath, synChild.fieldId) <0) return RV_ERROR_UNKNOWN;
}
iter = pstGetBrotherExt(per->hSyn, i+1, iter, &synChild);
} /* for */
/* -- extensions prefix: 18.7-18.8 */
if (!isExtended) return vtPath; /* no extensions */
from = per->decodingPosition;
/* -- length */
if (perDecodeLen(perLenTypeNORMALLY_SMALL, &extLen, 0, 0, hPer, from, &dec) <0)
{
RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
"perDecodeSequece: extension length missing [%s].",
pstGetFieldNamePtr(per->hSyn, fieldId)));
return RV_ERROR_UNKNOWN;
}
else from+=dec;
/* -- extension fields */
per->decodingPosition = from+extLen; /* skip bit field */
extChild = pstGetFirstExtendedChild(per->hSyn, synParent);
if (extChild<0) /* report WARNING */
{
RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
"perDecodeSequece: NO extensions for this version [%s].",
pstGetFieldNamePtr(per->hSyn, fieldId)));
}
/* -- decode extension fields: open type */
iter = pstGetChildExt(per->hSyn, synParent, extChild, &synChild);
for (i=0; i<(int)extLen; i++)
{
perDecodeBool(&isExist, hPer, from+i, &dec);
if (isExist)
{ /* extended child exist */
if (perDecodeLen(perLenTypeUNCONSTRAINED, &fieldLen, 0, 0, hPer,per->decodingPosition, &dec) <0)
{
RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
"perDecodeSequece: extended field length missing [%s/%d].",
pstGetFieldNamePtr(per->hSyn, fieldId), i));
return RV_ERROR_UNKNOWN;
}
per->decodingPosition+=dec;
saveLocation = per->decodingPosition;
if (extChild >0 && extChild+i <= children)
{ /* valid extended child */
if (perDecNode(hPer, synChild.nodeId, synChild.speciality, vtPath, synChild.fieldId) <0) return RV_ERROR_UNKNOWN;
}
else
{
RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
"perDecodeSequece: New extension (#%d) under [%s].",
i, pstGetFieldNamePtr(per->hSyn, fieldId)));
}
per->decodingPosition = saveLocation + fieldLen*8; /* skip field */
}
iter = pstGetBrotherExt(per->hSyn, extChild+i+1, iter, &synChild);
}
return vtPath;
}
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -