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

📄 payload.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 2 页
字号:

        hPtr[1]=bitfieldSet(hPtr[1],h263a->a,28,1);
        hPtr[1]=bitfieldSet(hPtr[1],h263a->s,29,1);
        hPtr[1]=bitfieldSet(hPtr[1],h263a->u,30,1);
        hPtr[1]=bitfieldSet(hPtr[1],h263a->i,31,1);
    }

    if (!h263a->f && !h263a->p)
    {
        dwords=1;
        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 containning the required parameters for DTMF events.
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
RVAPI
RvInt32 RVCALLCONV rtpDtmfEventPack(
        IN  void *      buf,
        IN  RvInt32     len,
        IN  rtpParam *  p,
        IN  void     *  param)
{
    rtpDtmfEventParams *dtmf = (rtpDtmfEventParams *)param;
    RvUint32*hPtr;
   RvUint32 temp1, temp2;
   
    RV_UNUSED_ARG(len);

    p->sByte-=4;
    hPtr=(RvUint32*)((RvUint8*)buf+p->sByte);
    hPtr[0]=bitfieldSet(0, dtmf->event, 0, 8);         /* event identifier */
	hPtr[0]=bitfieldSet(hPtr[0], dtmf->volume, 8, 6); /* volume - end bit */
	 
	 hPtr[0]=bitfieldSet(hPtr[0], 0, 14, 1);                /* R - always 0 */
    hPtr[0]=bitfieldSet(hPtr[0], dtmf->end, 15, 1);     /* E - end bit */ 
hPtr[0]=bitfieldSet(hPtr[0], dtmf->duration, 16, 16);
    
   temp1 = hPtr[0] >> 24;
   temp2 = hPtr[0] >> 16;
   hPtr[0] &= 0x0000ffff;
   hPtr[0] = (temp2 << 24) | (temp1 << 16) | hPtr[0];
 /*  printf("fujiangdong: hPtr[0] = 0x%x\n", hPtr[0]);*/
     /* duration - end bit */

   /*ConvertToNetwork(hPtr, 0, 1);*/

    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
 ************************************************************************/
RVAPI
RvInt32 RVCALLCONV rtpDtmfEventUnpack(
        OUT  void *      buf,
        IN   RvInt32     len,
        OUT  rtpParam *  p,
        OUT  void *      param)
{
    rtpDtmfEventParams *dtmf = (rtpDtmfEventParams *)param;
    RvUint32*hPtr=(RvUint32*)((RvUint8*)buf+p->sByte);

    RV_UNUSED_ARG(len);

    p->sByte+=4;
   ConvertFromNetwork(hPtr, 0, 1);

    dtmf->event = bitfieldGet(hPtr[0],0,8);
    dtmf->end = bitfieldGet(hPtr[0],8,1);
    dtmf->volume = bitfieldGet(hPtr[0],10,6);
    dtmf->duration = bitfieldGet(hPtr[0],16,16);

    return RV_OK;
}


/* 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 containning 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.
 ************************************************************************/
RVAPI
RvInt32 RVCALLCONV rtpDtmfTonesPack(
        IN  void *      buf,
        IN  RvInt32     len,
        IN  rtpParam *  p,
        IN  void     *  param)
{
    rtpDtmfTonesParams *dtmf = (rtpDtmfTonesParams *)param;
    RvUint32*hPtr;
    RvUint32 dwords = 1;
    RvUint32 listLen = 0;

    RV_UNUSED_ARG(len);

    p->sByte-=(4 + (((dtmf->freqListLength+1)/2)*4));
    hPtr=(RvUint32*)((RvUint8*)buf+p->sByte);
    hPtr[0]=bitfieldSet(0, dtmf->modulation, 0, 9);        /* mudulation */
    hPtr[0]=bitfieldSet(hPtr[0], dtmf->T, 9, 1);           /* divide by three flag */
    hPtr[0]=bitfieldSet(hPtr[0], dtmf->volume, 10, 6);     /* volume */
    hPtr[0]=bitfieldSet(hPtr[0], dtmf->duration, 16, 16);  /* duration */

    while (listLen < dtmf->freqListLength)
    {
        hPtr[dwords] = 0;                                       /* 'R R R R' are set */
        hPtr[dwords]=bitfieldSet(hPtr[dwords], dtmf->freqList[listLen++], 4, 12); /* frequency */
        if (listLen < dtmf->freqListLength)
            hPtr[dwords]=bitfieldSet(hPtr[dwords], dtmf->freqList[listLen++], 20, 12); /* frequency */
        dwords++;
    }

    ConvertToNetwork(hPtr, 0, dwords);
    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
 ************************************************************************/
RVAPI
RvInt32 RVCALLCONV rtpDtmfTonesUnpack(
        IN   void *      buf,
        IN   RvInt32     len,
        OUT  rtpParam *  p,
        OUT  void *      param)
{
    rtpDtmfTonesParams *dtmf = (rtpDtmfTonesParams *)param;
    RvUint32*hPtr=(RvUint32*)((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;
    ConvertFromNetwork(hPtr, 0, 1);

    dtmf->modulation = bitfieldGet(hPtr[0],0,9);
    dtmf->T = bitfieldGet(hPtr[0],9,1);
    dtmf->volume = bitfieldGet(hPtr[0],10,6);
    dtmf->duration = bitfieldGet(hPtr[0],16,16);

    p->len-=16; /* removing RTP header and 4 first bytes of telephoney 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 frquency in the received message.
 *
 * input  : buf - the received buffer.
 *          index - index of the frequency indside the frequency list.
 *          p - RTP header parameters that were received.
 *          param - the received parameters for telephony tones.
 * output : frequency - The requested frquency
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
RVAPI
RvStatus RVCALLCONV rtpDtmfTonesGetByIndex(
        IN   void *      buf,
        IN   RvUint32    index,
        IN   rtpParam *  p,
        IN   void *      param,
        OUT  RvUint16 *  frequency)
{
    rtpDtmfTonesParams *dtmf = (rtpDtmfTonesParams *)param;
    RvUint32*hPtr=(RvUint32*)((RvUint8*)buf+p->sByte);
    RvUint32 level;

    if ((index<0) || (index>dtmf->freqListLength))
        return RV_ERROR_OUTOFRANGE;

    level = index>>1;

    if (index % 2 == 0)
    {
        /* only convert to it (to network order) at first frequency of this 32bit array */
        /* (there are 2 frequencies at each 32bit array) */
        ConvertFromNetwork(hPtr, level, 1);
    }

    /* get the right freuency from inside the header */
    *frequency = (index % 2) ? bitfieldGet(hPtr[level], 20, 12) : bitfieldGet(hPtr[level], 4, 12);

    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.
 *
 * input  : buf - buffer pointer that will be sent
 *          len - length of the buffer.
 *          p - RTP header default parameters.
 *          param - a structure containning the required parameters for fecc.
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
RVAPI
RvInt32 RVCALLCONV rtpAnnexQMessagePack(
        IN  void *      buf,
        IN  RvInt32     len,
        IN  rtpParam *  p,
        IN  void     *  params)
{
    rtpAnnexQParam *param = (rtpAnnexQParam *)params;
    RvUint8*hPtr;

    RV_UNUSED_ARG(len);

    p->sByte-=2;
    if (param->procedure == rtpAnnexQProceduresStartAction)
        p->sByte-=1;

    hPtr=(RvUint8*)((RvUint8*)buf+p->sByte);
    hPtr[0]=param->procedure;

    if (param->procedure == rtpAnnexQProceduresStartAction ||
        param->procedure == rtpAnnexQProceduresContinueAction ||
        param->procedure == rtpAnnexQProceduresStopAction)
    {
        hPtr[1]=bitfieldSet(0, param->action.pan, 0, 2);        /* set pan   */
        hPtr[1]=bitfieldSet(hPtr[1], param->action.tilt, 2, 2); /* set tilt  */
        hPtr[1]=bitfieldSet(hPtr[1], param->action.zoom, 4, 2); /* set zoom  */
        hPtr[1]=bitfieldSet(hPtr[1], param->action.focus, 6, 2);/* set focus */
    }

    if (param->procedure == rtpAnnexQProceduresStartAction)
        hPtr[2]=bitfieldSet(0, param->timeOut, 4, 4);    /* set timeout */

    if (param->procedure == rtpAnnexQProceduresSelectVideoSource ||
        param->procedure == rtpAnnexQProceduresVideoSourceSwitched)
    {
        hPtr[1]=bitfieldSet(0, param->videoSource, 0, 4);    /* set video source */
        hPtr[1]=bitfieldSet(hPtr[1], param->mode.stillImage, 6, 1); /* set M1 */
        hPtr[1]=bitfieldSet(hPtr[1], param->mode.doubleResolutionStillImage, 7, 1); /* set M0 */
    }

    if (param->procedure == rtpAnnexQProceduresStoreAsPreset ||
        param->procedure == rtpAnnexQProceduresActivatePreset)
            hPtr[1]=bitfieldSet(0, param->preset, 0, 4);     /* set preset */

    ConvertToNetwork(hPtr, 0, 1);
    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
 ************************************************************************/
RVAPI
RvInt32 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);

    param->procedure = hPtr[0];

    if (param->procedure == rtpAnnexQProceduresStartAction ||
        param->procedure == rtpAnnexQProceduresContinueAction ||
        param->procedure == rtpAnnexQProceduresStopAction)
    {
        param->action.pan= bitfieldGet(hPtr[1],0,2);    /* get pan */
        param->action.tilt= bitfieldGet(hPtr[1],2,2);   /* get tilt */
        param->action.zoom= bitfieldGet(hPtr[1],4,2);   /* get zoom */
        param->action.focus= bitfieldGet(hPtr[1],6,2);  /* get focus */
    }

    if (param->procedure == rtpAnnexQProceduresStartAction)
    {
        param->timeOut = bitfieldGet(hPtr[2],4,4);  /* get timeout */
        p->sByte+=1;
    }

    if (param->procedure == rtpAnnexQProceduresSelectVideoSource ||
        param->procedure == rtpAnnexQProceduresVideoSourceSwitched)
    {
        param->videoSource = bitfieldGet(hPtr[1],0,4);  /* get video source */
        param->mode.stillImage = bitfieldGet(hPtr[1],6,1);  /* get M1 */
        param->mode.doubleResolutionStillImage = bitfieldGet(hPtr[1],7,1);  /* get M2 */
    }

    if (param->procedure == rtpAnnexQProceduresStoreAsPreset ||
        param->procedure == rtpAnnexQProceduresActivatePreset)
            param->preset = bitfieldGet(hPtr[1],0,4);   /* get preset */

    return RV_OK;
}

⌨️ 快捷键说明

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