📄 payload.c
字号:
p->sByte-=4; hPtr=(RvUint32*)((RvUint8*)buf+p->sByte); hPtr[0]=bitfieldSet( 0,h263a->a,17,1); hPtr[0]=bitfieldSet(hPtr[0],h263a->s,18,1); hPtr[0]=bitfieldSet(hPtr[0],h263a->u,19,1); hPtr[0]=bitfieldSet(hPtr[0],h263a->i,20,1); ; } hPtr[0]=bitfieldSet(hPtr[0],h263a->f,31,1); hPtr[0]=bitfieldSet(hPtr[0],h263a->p,30,1); hPtr[0]=bitfieldSet(hPtr[0],h263a->sBit,27,3); hPtr[0]=bitfieldSet(hPtr[0],h263a->eBit,24,3); hPtr[0]=bitfieldSet(hPtr[0],h263a->src,21,3); p->payload=H263; ConvertToNetwork(hPtr, 0, dwords); return RV_OK;}RvInt32 RVCALLCONV rtpH263aUnpack( OUT void*buf, IN RvInt32 len, OUT rtpParam*p, OUT void*param){ H263aparam*h263a=(H263aparam*)param; RvUint32*hPtr=(RvUint32*)((RvUint8*)buf+p->sByte); RV_UNUSED_ARG(len); p->sByte+=4; ConvertFromNetwork(hPtr, 0, 1); h263a->f=bitfieldGet(hPtr[0],31,1); h263a->p=bitfieldGet(hPtr[0],30,1); h263a->sBit=bitfieldGet(hPtr[0],27,3); h263a->eBit=bitfieldGet(hPtr[0],24,3); h263a->src=bitfieldGet(hPtr[0],21,3); if (h263a->f) { int aDwords=h263a->p+1; ConvertFromNetwork(hPtr, 1, aDwords); p->sByte+=4*aDwords; h263a->mbaP=bitfieldGet(hPtr[0],2,9); h263a->gobN=bitfieldGet(hPtr[0],11,5); h263a->quant=bitfieldGet(hPtr[0],16,5); h263a->vMv2=bitfieldGet(hPtr[1],0,7); h263a->hMv2=bitfieldGet(hPtr[1],7,7); h263a->vMv1=bitfieldGet(hPtr[1],14,7); h263a->hMv1=bitfieldGet(hPtr[1],21,7); h263a->i=bitfieldGet(hPtr[1],31,1); h263a->u=bitfieldGet(hPtr[1],30,1); h263a->s=bitfieldGet(hPtr[1],29,1); h263a->a=bitfieldGet(hPtr[1],28,1); hPtr=(RvUint32*)((RvUint8*)buf+p->sByte-4); } if (h263a->p) { h263a->dbq=bitfieldGet(hPtr[0],11,2); h263a->trb=bitfieldGet(hPtr[0],8,3); h263a->tr=bitfieldGet(hPtr[0],0,8); } if (!h263a->f && !h263a->p) { h263a->i=bitfieldGet(hPtr[0],20,1); h263a->u=bitfieldGet(hPtr[0],19,1); h263a->s=bitfieldGet(hPtr[0],18,1); h263a->a=bitfieldGet(hPtr[0],17,1); } return RV_OK;}RvInt32 RVCALLCONV rtpH263aGetHeaderLength(){ return rtpGetHeaderLength()+12;}/* ==== DTMF inBand (via RTP payload) - RFC 2833 ==== *//************************************************************************ * rtpDtmfEventPack * * purpose: set the payload format, for sending DTMF events inband, * as described in RFC2833, section 3.5. * * input : buf - buffer pointer that will be sent * len - length of the buffer. * p - RTP header default parameters. * param - a structure containing the required parameters for DTMF events. * output : none * return : Non-negative value on success * Negative value on failure ************************************************************************/RVAPIRvInt32 RVCALLCONV rtpDtmfEventPack( IN void * buf, IN RvInt32 len, IN rtpParam * p, IN void * param){ rtpDtmfEventParams *dtmf = (rtpDtmfEventParams *)param; RvUint8*hPtr; RV_UNUSED_ARG(len); p->sByte -= 4; hPtr = (RvUint8*)buf + p->sByte; /* Due to some issues with the ordering of bytes that wasn't easy to fix using "conventional" means we deal with this as a bytes buffer... */ /* 0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7 Original: | event |E|R| volume | duration | */ hPtr[0] = (RvUint8)(dtmf->event); hPtr[1] = (RvUint8)((RvUint8)((dtmf->end & 1) << 7) | (RvUint8)(dtmf->volume & 0x3f)); hPtr[2] = (RvUint8)((dtmf->duration >> 8) & 0xff); hPtr[3] = (RvUint8)(dtmf->duration & 0xff); return RV_OK;}/************************************************************************ * rtpDtmfEventUnpack * * purpose: evaluates the DTMF events from the received packed. * * input : len - length of the buffer. * output : buf - the received buffer. * p - RTP header parameters that were received. * param - the received parameters for DTMF events. * return : Non-negative value on success * Negative value on failure ************************************************************************/RVAPIRvInt32 RVCALLCONV rtpDtmfEventUnpack( OUT void * buf, IN RvInt32 len, OUT rtpParam * p, OUT void * param){ rtpDtmfEventParams *dtmf = (rtpDtmfEventParams *)param; RvUint8*hPtr = (RvUint8*)buf + p->sByte; RV_UNUSED_ARG(len); p->sByte += 4; /* See Pack() function for explanation on ordering */ dtmf->event = (rtpDtmfEvent)hPtr[0]; dtmf->end = (RvBool)(hPtr[1] >> 7); dtmf->volume = (RvUint8)(hPtr[1] & 0x3f); dtmf->duration = ((RvUint32)hPtr[2] << 8) | (RvUint32)hPtr[3]; return RV_OK;}/****************************************************************************** * rtpDtmfEventGetHeaderLength * ---------------------------------------------------------------------------- * General: Returns the length of a DTMF event payload. * This length should be placed as the len parameter to rtpWrite(). * * Return Value: Length of a DTMF event payload. * ---------------------------------------------------------------------------- * Arguments: * Input: none. * Output: none. *****************************************************************************/RVAPIRvInt32 RVCALLCONV rtpDtmfEventGetHeaderLength(void){ return rtpGetHeaderLength() + 4;}/* Telephony Tones according to RFC2833 *//************************************************************************ * rtpDtmfTonesPack * * purpose: set the payload format, for sending telephony tones inband, * as described in RFC2833, section 4.4. * * input : buf - buffer pointer that will be sent * len - length of the buffer. * p - RTP header default parameters. * param - a structure containing the required parameters for telephony tones. * output : none * return : Non-negative value on success * Negative value on failure * * Important: one of the members of the 'rtpDtmfTonesParams' struct(param) is a pointer * notes to an integer array, that symbolizes the frequencies that form the tone. * the array is not limited in size, since a single tone can contain any * number of frequencies. this is the reason there is a member 'freqListLength' * in the struct as well. ************************************************************************/RVAPIRvInt32 RVCALLCONV rtpDtmfTonesPack( IN void * buf, IN RvInt32 len, IN rtpParam * p, IN void * param){ rtpDtmfTonesParams *dtmf = (rtpDtmfTonesParams *)param; RvUint8* hPtr; RvUint32 listLen = 0; RV_UNUSED_ARG(len); /* We place the bytes in "wrong order" - the ConvertToNetwork function is going to change the bytes position anyway... */ /* 0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7 Original: | modulation |T| volume | duration | */ p->sByte -= (4 + (((dtmf->freqListLength + 1) / 2) * 4)); hPtr = (RvUint8*)buf + p->sByte; hPtr[0] = (RvUint8)((dtmf->modulation >> 1) & 0xff); hPtr[1] = (RvUint8)(((dtmf->modulation & 1) << 7) | ((dtmf->T & 1)<< 6) | (dtmf->volume & 0x3f)); hPtr[2] = (RvUint8)((dtmf->duration >> 8) & 0xff); hPtr[3] = (RvUint8)(dtmf->duration & 0xff); hPtr += 4; while (listLen < dtmf->freqListLength) { /* 0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7 Original: |R R R R| frequency |R R R R| frequency | */ hPtr[0] = (RvUint8)((dtmf->freqList[listLen] >> 8) & 0x0f); hPtr[1] = (RvUint8)(dtmf->freqList[listLen] & 0xff); hPtr += 2; listLen++; } return RV_OK;}/************************************************************************ * rtpDtmfTonesUnpack * * purpose: evaluates the telephony tones from the received packed. * * input : len - length of the buffer. * output : buf - the received buffer. * p - RTP header parameters that were received. * param - the received parameters for telephony tones. * return : Non-negative value on success * Negative value on failure ************************************************************************/RVAPIRvInt32 RVCALLCONV rtpDtmfTonesUnpack( IN void * buf, IN RvInt32 len, OUT rtpParam * p, OUT void * param){ rtpDtmfTonesParams *dtmf = (rtpDtmfTonesParams *)param; RvUint8*hPtr = (RvUint8*)buf + p->sByte; RV_UNUSED_ARG(len); /* set the offset right after the tone's first header, and before the frequencies list */ p->sByte += 4; /* See Pack() function for explanation on ordering */ dtmf->modulation = (RvUint16)((hPtr[1] >> 7) | ((RvUint16)hPtr[0] << 1)); dtmf->T = (RvBool)((hPtr[2] & 0x40) != 0); dtmf->volume = (RvUint8)(hPtr[1] & 0x3f); dtmf->duration = ((RvUint32)hPtr[2] << 8) | (RvUint32)hPtr[3]; p->len -= 16; /* removing RTP header and 4 first bytes of telephony tones header */ p->len >>= 1; /* find out of many frequencies are there in the payload - divide by 2 */ dtmf->freqListLength = p->len; return RV_OK;}/************************************************************************ * rtpDtmfTonesGetByIndex * * purpose: find the requested frequency in the received message. * * input : buf - the received buffer. * index - index of the frequency inside the frequency list. * p - RTP header parameters that were received. * param - the received parameters for telephony tones. * output : frequency - The requested frequency * return : Non-negative value on success * Negative value on failure ************************************************************************/RVAPIRvStatus RVCALLCONV rtpDtmfTonesGetByIndex( IN void * buf, IN RvUint32 index, IN rtpParam * p, IN void * param, OUT RvUint16 * frequency){ rtpDtmfTonesParams *dtmf = (rtpDtmfTonesParams *)param; RvUint8 *hPtr = (RvUint8*)buf + p->sByte; RvUint32 level; if (index > dtmf->freqListLength) return RV_ERROR_OUTOFRANGE; level = index << 1; /* Get the right frequency from inside the header */ *frequency = (RvUint16)(((((RvUint16)hPtr[level]) << 8) | hPtr[level+1]) & 0x0fff); return RV_OK;}/* ==== Annex Q & H.281 - Far End Camera Control (FECC) ==== *//************************************************************************ * rtpAnnexQMessagePack * * purpose: Set the payload format, for sending Far end camera commands inband, * as described in H.281. * Several AnnexQ commands can be sent in the same packet. Using * rtpAnnexQMessagePack on the same buffer for several such messages * places them in reverse order. * * input : buf - buffer pointer that will be sent * len - length of the buffer. * p - RTP header default parameters. * param - a structure containing the required parameters for FECC. * output : none * return : Non-negative value on success * Negative value on failure ************************************************************************/RVAPIRvInt32 RVCALLCONV rtpAnnexQMessagePack( IN void * buf, IN RvInt32 len, IN rtpParam * p, IN void * params){ rtpAnnexQParam *param = (rtpAnnexQParam *)params; RvUint8*hPtr; RvInt32 length = 2; RV_UNUSED_ARG(len); p->sByte-=2; if (param->procedure == rtpAnnexQProceduresStartAction) p->sByte-=1; hPtr=(RvUint8*)((RvUint8*)buf+p->sByte); hPtr[0]=(RvUint8)(param->procedure); switch (param->procedure) { case rtpAnnexQProceduresStartAction: length++; hPtr[2]=(RvUint8)(bitfieldSet(0, param->timeOut, 0, 4)); /* set timeout */ /* No break - we continue as if it's a continue or a stop action */ case rtpAnnexQProceduresContinueAction: case rtpAnnexQProceduresStopAction: hPtr[1]=(RvUint8)bitfieldSet(0, param->action.pan, 6, 2); /* set pan */ hPtr[1]=(RvUint8)bitfieldSet(hPtr[1], param->action.tilt, 4, 2); /* set tilt */ hPtr[1]=(RvUint8)bitfieldSet(hPtr[1], param->action.zoom, 2, 2); /* set zoom */ hPtr[1]=(RvUint8)bitfieldSet(hPtr[1], param->action.focus, 0, 2);/* set focus */ break; case rtpAnnexQProceduresSelectVideoSource: case rtpAnnexQProceduresVideoSourceSwitched: hPtr[1]=(RvUint8)bitfieldSet(0, param->videoSource, 4, 4); /* set video source */ hPtr[1]=(RvUint8)bitfieldSet(hPtr[1], param->mode.stillImage, 1, 1); /* set M1 */ hPtr[1]=(RvUint8)bitfieldSet(hPtr[1], param->mode.doubleResolutionStillImage, 0, 1); /* set M0 */ break; case rtpAnnexQProceduresStoreAsPreset: case rtpAnnexQProceduresActivatePreset: hPtr[1]=(RvUint8)bitfieldSet(0, param->preset, 4, 4); /* set preset */ } /*ConvertToNetwork(hPtr, 0, 1); Already in network format */ return RV_OK;}/************************************************************************ * rtpAnnexQMessageUnpack * * purpose: evaluates the FECC commands from the received packed. * * input : len - length of the buffer. * output : buf - the received buffer. * p - RTP header parameters that were received. * param - the received parameters for FECC. * return : Non-negative value on success * Negative value on failure ************************************************************************/RVAPIRvInt32 RVCALLCONV rtpAnnexQMessageUnpack( OUT void * buf, IN RvInt32 len, OUT rtpParam * p, OUT void * params){ rtpAnnexQParam *param = (rtpAnnexQParam *)params; RvUint8*hPtr=(RvUint8*)((RvUint8*)buf+p->sByte); RV_UNUSED_ARG(len); p->sByte+=2; /* ConvertFromNetwork(hPtr, 0, 1); Read directly from network format */ param->procedure = (rtpAnnexQProcedures)hPtr[0]; switch (param->procedure) { case rtpAnnexQProceduresStartAction: param->timeOut = (RvUint8)bitfieldGet(hPtr[2],0,4); /* get timeout */ p->sByte++; /* No break - we continue as if it's a continue or a stop action */ case rtpAnnexQProceduresContinueAction: case rtpAnnexQProceduresStopAction: param->action.pan= (rtpAnnexQMoveCamera)bitfieldGet(hPtr[1],6,2); /* get pan */ param->action.tilt= (rtpAnnexQMoveCamera)bitfieldGet(hPtr[1],4,2); /* get tilt */ param->action.zoom= (rtpAnnexQMoveCamera)bitfieldGet(hPtr[1],2,2); /* get zoom */ param->action.focus= (rtpAnnexQMoveCamera)bitfieldGet(hPtr[1],0,2); /* get focus */ break; case rtpAnnexQProceduresSelectVideoSource: case rtpAnnexQProceduresVideoSourceSwitched: param->videoSource = (RvUint8)bitfieldGet(hPtr[1],4,4); /* get video source */ param->mode.stillImage = bitfieldGet(hPtr[1],1,1); /* get M1 */ param->mode.doubleResolutionStillImage = bitfieldGet(hPtr[1],0,1); /* get M0 */ break; case rtpAnnexQProceduresStoreAsPreset: case rtpAnnexQProceduresActivatePreset: param->preset = (RvUint8)bitfieldGet(hPtr[1],4,4); /* get preset */ break; } return RV_OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -