ooh245.c

来自「一个非常美妙的proxy。功能强大。基于sip的协议。如果还要的话」· C语言 代码 · 共 1,743 行 · 第 1/5 页

C
1,743
字号
   memset(request, 0, sizeof(H245RequestMessage));   if(request == NULL)   {      OOTRACEERR3("ERROR: No memory allocated for request message (%s, %s)\n",                   call->callType, call->callToken);      return OO_FAILED;   }      request->t = T_H245RequestMessage_terminalCapabilitySet;   request->u.terminalCapabilitySet = (H245TerminalCapabilitySet*)                  memAlloc(pctxt, sizeof(H245TerminalCapabilitySet));    termCap = request->u.terminalCapabilitySet;   memset(termCap, 0, sizeof(H245TerminalCapabilitySet));   termCap->m.multiplexCapabilityPresent = 0;   termCap->m.capabilityTablePresent = 1;   termCap->m.capabilityDescriptorsPresent = 1;   termCap->sequenceNumber = ++(call->localTermCapSeqNo);     termCap->protocolIdentifier = gh245ProtocolID; /* protocol id */   /* Add audio Capabilities */    dListInit(&(termCap->capabilityTable));   for(k=0; k<(int)call->capPrefs.index; k++)   {      if(call->ourCaps)         epCap = call->ourCaps;      else         epCap = gH323ep.myCaps;      while(epCap) { 	  if(epCap->cap == call->capPrefs.order[k])             break;         epCap = epCap->next;      }      if(!epCap)      {         OOTRACEWARN4("WARN:Preferred capability %d not supported.(%s, %s)\n",                     call->capPrefs.order[k],call->callType, call->callToken);         continue;      }      if(epCap->capType == OO_CAP_TYPE_AUDIO)      {         /* Create audio capability. If capability supports receive, we only             add it as receive capability in TCS. However, if it supports only             transmit, we add it as transmit capability in TCS.         */         if((epCap->dir & OORX))         {            OOTRACEDBGC4("Sending receive capability %s in TCS.(%s, %s)\n",                ooGetCapTypeText(epCap->cap), call->callType, call->callToken);            audioCap = ooCapabilityCreateAudioCapability(epCap, pctxt, OORX);            if(!audioCap)            {               OOTRACEWARN4("WARN:Failed to create audio capability %s "                            "(%s, %s)\n", ooGetCapTypeText(epCap->cap),                             call->callType, call->callToken);               continue;            }         }else if(epCap->dir & OOTX)         {            OOTRACEDBGC4("Sending transmit capability %s in TCS.(%s, %s)\n",                ooGetCapTypeText(epCap->cap), call->callType, call->callToken);            audioCap = ooCapabilityCreateAudioCapability(epCap, pctxt, OOTX);            if(!audioCap)            {               OOTRACEWARN4("WARN:Failed to create audio capability %s "                            "(%s, %s)\n", ooGetCapTypeText(epCap->cap),                            call->callType, call->callToken);               continue;            }              }else{            OOTRACEWARN3("Warn:Capability is not RX/TX/RXANDTX. Symmetric "                         "capabilities are not supported.(%s, %s)\n",                          call->callType, call->callToken);            continue;         }         /* Add  Capabilities to Capability Table */         entry = (H245CapabilityTableEntry*) memAlloc(pctxt,                         sizeof(H245CapabilityTableEntry));         if(!entry)         {            OOTRACEERR3("Error:Memory - ooSendTermCapMsg - entry(audio Cap)."                        "(%s, %s)\n", call->callType, call->callToken);            return OO_FAILED;         }         memset(entry, 0, sizeof(H245CapabilityTableEntry));         entry->m.capabilityPresent = 1;         if((epCap->dir & OORX))         {            entry->capability.t = T_H245Capability_receiveAudioCapability;            entry->capability.u.receiveAudioCapability = audioCap;         }else{            entry->capability.t = T_H245Capability_transmitAudioCapability;            entry->capability.u.transmitAudioCapability = audioCap;         }         entry->capabilityTableEntryNumber = i+1;         dListAppend(pctxt , &(termCap->capabilityTable), entry);         i++;      }else if(epCap->capType == OO_CAP_TYPE_VIDEO)      {         if((epCap->dir & OORX))         {            OOTRACEDBGC4("Sending receive capability %s in TCS.(%s, %s)\n",                ooGetCapTypeText(epCap->cap), call->callType, call->callToken);            videoCap = ooCapabilityCreateVideoCapability(epCap, pctxt, OORX);            if(!videoCap)            {               OOTRACEWARN4("WARN:Failed to create Video capability %s "                            "(%s, %s)\n", ooGetCapTypeText(epCap->cap),                           call->callType, call->callToken);               continue;            }         }else if(epCap->dir & OOTX)         {            OOTRACEDBGC4("Sending transmit capability %s in TCS.(%s, %s)\n",                ooGetCapTypeText(epCap->cap), call->callType, call->callToken);            videoCap = ooCapabilityCreateVideoCapability(epCap, pctxt, OOTX);            if(!videoCap)            {               OOTRACEWARN4("WARN:Failed to create video capability %s "                            "(%s, %s)\n", ooGetCapTypeText(epCap->cap),                           call->callType, call->callToken);               continue;            }              }else{            OOTRACEWARN3("Warn:Capability is not RX/TX/RXANDTX. Symmetric "                         "capabilities are not supported.(%s, %s)\n",                          call->callType, call->callToken);            continue;         }         /* Add Video capabilities to Capability Table */         entry = (H245CapabilityTableEntry*) memAlloc(pctxt,                            sizeof(H245CapabilityTableEntry));         if(!entry)         {            OOTRACEERR3("Error:Memory - ooSendTermCapMsg - entry(video Cap)."                        "(%s, %s)\n", call->callType, call->callToken);            return OO_FAILED;         }         memset(entry, 0, sizeof(H245CapabilityTableEntry));         entry->m.capabilityPresent = 1;         if((epCap->dir & OORX))         {            entry->capability.t = T_H245Capability_receiveVideoCapability;            entry->capability.u.receiveVideoCapability = videoCap;         }else{            entry->capability.t = T_H245Capability_transmitVideoCapability;            entry->capability.u.transmitVideoCapability = videoCap;         }         entry->capabilityTableEntryNumber = i+1;         dListAppend(pctxt , &(termCap->capabilityTable), entry);         i++;      }   }   /* Add dtmf capability, if any */   if(call->dtmfmode & OO_CAP_DTMF_RFC2833)   {      ateCap = (H245AudioTelephonyEventCapability*)                  ooCapabilityCreateDTMFCapability(OO_CAP_DTMF_RFC2833, pctxt);      if(!ateCap)      {         OOTRACEWARN3("WARN:Failed to add RFC2833 cap to TCS(%s, %s)\n",                     call->callType, call->callToken);      }else {         entry = (H245CapabilityTableEntry*) memAlloc(pctxt,                      sizeof(H245CapabilityTableEntry));         if(!entry)         {            OOTRACEERR3("Error:Failed to allocate memory for new capability "                        "table entry. (%s, %s)\n", call->callType,                         call->callToken);            ooFreeH245Message(call, ph245msg);            return OO_FAILED;         }                     memset(entry, 0, sizeof(H245CapabilityTableEntry));         entry->m.capabilityPresent = 1;         entry->capability.t = T_H245Capability_receiveRTPAudioTelephonyEventCapability;         entry->capability.u.receiveRTPAudioTelephonyEventCapability = ateCap;               entry->capabilityTableEntryNumber = i+1;         dListAppend(pctxt , &(termCap->capabilityTable), entry);         i++;      }   }   if(call->dtmfmode & OO_CAP_DTMF_H245_alphanumeric)   {      userInputCap = (H245UserInputCapability*)ooCapabilityCreateDTMFCapability                                        (OO_CAP_DTMF_H245_alphanumeric, pctxt);      if(!userInputCap)      {         OOTRACEWARN3("WARN:Failed to add H245(alphanumeric) cap to "                      "TCS(%s, %s)\n", call->callType, call->callToken);      }else {         entry = (H245CapabilityTableEntry*) memAlloc(pctxt,                      sizeof(H245CapabilityTableEntry));         if(!entry)         {            OOTRACEERR3("Error:Failed to allocate memory for new capability "                        "table entry. (%s, %s)\n", call->callType,                         call->callToken);            ooFreeH245Message(call, ph245msg);            return OO_FAILED;         }                     memset(entry, 0, sizeof(H245CapabilityTableEntry));         entry->m.capabilityPresent = 1;         entry->capability.t = T_H245Capability_receiveUserInputCapability;         entry->capability.u.receiveUserInputCapability = userInputCap;               entry->capabilityTableEntryNumber = i+1;         dListAppend(pctxt , &(termCap->capabilityTable), entry);         i++;      }   }   userInputCap = NULL;   if(call->dtmfmode & OO_CAP_DTMF_H245_signal)   {      userInputCap = (H245UserInputCapability*)ooCapabilityCreateDTMFCapability                                        (OO_CAP_DTMF_H245_signal, pctxt);      if(!userInputCap)      {         OOTRACEWARN3("WARN:Failed to add H245(signal) cap to "                      "TCS(%s, %s)\n", call->callType, call->callToken);      }else {         entry = (H245CapabilityTableEntry*) memAlloc(pctxt,                      sizeof(H245CapabilityTableEntry));         if(!entry)         {            OOTRACEERR3("Error:Failed to allocate memory for new capability "                        "table entry. (%s, %s)\n", call->callType,                         call->callToken);            ooFreeH245Message(call, ph245msg);            return OO_FAILED;         }                     memset(entry, 0, sizeof(H245CapabilityTableEntry));         entry->m.capabilityPresent = 1;         entry->capability.t = T_H245Capability_receiveUserInputCapability;         entry->capability.u.receiveUserInputCapability = userInputCap;               entry->capabilityTableEntryNumber = i+1;         dListAppend(pctxt , &(termCap->capabilityTable), entry);         i++;      }   }             /*TODO:Add Video and Data capabilities, if required*/   if(i==0)   {      OOTRACEERR3("Error:No capabilities found to send in TCS message."                  " (%s, %s)\n", call->callType, call->callToken);      ooFreeH245Message(call,ph245msg);      return OO_FAILED;   }	      /* Define capability descriptior */   capDesc = (H245CapabilityDescriptor*)             memAlloc(pctxt, sizeof(H245CapabilityDescriptor));   memset(capDesc, 0, sizeof(H245CapabilityDescriptor));   capDesc->m.simultaneousCapabilitiesPresent = 1;   capDesc->capabilityDescriptorNumber = 1;   dListInit(&(capDesc->simultaneousCapabilities));   /* Add Alternative Capability Set.      TODO: Right now all capabilities are added in separate            alternate capabilities set. Need a way for application            developer to specify the alternative capability sets.   */   for(j=0; j<i; j++)   {      altSet = (H245AlternativeCapabilitySet*)               memAlloc(pctxt, sizeof(H245AlternativeCapabilitySet));      memset(altSet, 0, sizeof(H245AlternativeCapabilitySet));      altSet->n = 1;      altSet->elem[0] = j+1;         dListAppend(pctxt, &(capDesc->simultaneousCapabilities), altSet);   }   dListInit(&(termCap->capabilityDescriptors));   dListAppend(pctxt, &(termCap->capabilityDescriptors), capDesc);   OOTRACEDBGA3("Built terminal capability set message (%s, %s)\n",                  call->callType, call->callToken);   ret = ooSendH245Msg(call, ph245msg);   if(ret != OO_OK)   {      OOTRACEERR3("Error:Failed to enqueue TCS message to outbound queue. "                  "(%s, %s)\n", call->callType, call->callToken);   }else      call->localTermCapState = OO_LocalTermCapSetSent;      ooFreeH245Message(call,ph245msg);   return ret;}ASN1UINT ooGenerateStatusDeterminationNumber(){   ASN1UINT statusDeterminationNumber;   ASN1UINT random_factor = getpid();#ifdef _WIN32   SYSTEMTIME systemTime;   GetLocalTime(&systemTime);   srand((systemTime.wMilliseconds ^ systemTime.wSecond) + random_factor);#else   struct timeval tv;   gettimeofday(&tv, NULL);   srand((tv.tv_usec ^ tv.tv_sec) + random_factor );#endif   statusDeterminationNumber = rand()%16777215;   return statusDeterminationNumber;}/* TODO: Should Send MasterSlave Release when no response from          Remote endpoint after MasterSlaveDetermination sent within         timeout.*/int ooHandleMasterSlave(OOH323CallData *call, void * pmsg,                           int msgType){   H245MasterSlaveDetermination *masterSlave;   H245MasterSlaveDeterminationAck *masterSlaveAck;   ASN1UINT statusDeterminationNumber;   switch(msgType)   {      case OOMasterSlaveDetermination:         OOTRACEINFO3("Master Slave Determination received (%s, %s)\n",                       call->callType, call->callToken);                  masterSlave = (H245MasterSlaveDetermination*)pmsg;                  if(masterSlave->terminalType < gH323ep.termType)         {            ooSendMasterSlaveDeterminationAck(call, "slave");

⌨️ 快捷键说明

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