osip_rfc3264.c

来自「最新osip源代码」· C语言 代码 · 共 1,093 行 · 第 1/2 页

C
1,093
字号
  audio_tab[0] = NULL;  if (cnf == NULL)    return -1;  /* search for the audio media line */  pos = 0;  while (!osip_list_eol (remote_med->m_payloads, pos))    {      char *payload = (char *) osip_list_get (remote_med->m_payloads, pos);      sdp_media_t *local_med;      char *rtpmap = NULL;      int posattr = 0;      /* search for the rtpmap associated to the payload */      while (!osip_list_eol (remote_med->a_attributes, posattr))        {          sdp_attribute_t *attr =            (sdp_attribute_t *) osip_list_get (remote_med->a_attributes,                                               posattr);          if (0 == osip_strncasecmp (attr->a_att_field, "rtpmap", 6))            {              if (attr->a_att_value != NULL &&                  0 == osip_strncasecmp (attr->a_att_value, payload,                                         strlen (payload)))                {                  /* TODO check if it was not like 101: == 10 */                  rtpmap = attr->a_att_value;                  break;                }            }          posattr++;        }      local_med = osip_rfc3264_find_audio (config, payload, rtpmap);      if (local_med != NULL)        {          /* found a supported codec? */          audio_tab[num] = local_med;          num++;        }      /* search for support of this codec in local media list */      pos++;    }  audio_tab[num] = NULL;  return 0;}/** * Compare remote sdp packet against local supported media for video. * @param config The element to work on. * @param remote_sdp The remote SDP packet. * @param remote_med The remote Media SDP line. * @param video_tab The local list of media supported by both side. */intosip_rfc3264_match_video (struct osip_rfc3264 *config,                          sdp_message_t * remote_sdp,                          sdp_media_t * remote_med, sdp_media_t * video_tab[]){  osip_rfc3264_t *cnf = (osip_rfc3264_t *) config;  int num = 0;  int pos;  video_tab[0] = NULL;  if (cnf == NULL)    return -1;  /* search for the video media line */  pos = 0;  while (!osip_list_eol (remote_med->m_payloads, pos))    {      char *payload = (char *) osip_list_get (remote_med->m_payloads, pos);      sdp_media_t *local_med;      char *rtpmap = NULL;      int posattr = 0;      /* search for the rtpmap associated to the payload */      while (!osip_list_eol (remote_med->a_attributes, posattr))        {          sdp_attribute_t *attr =            (sdp_attribute_t *) osip_list_get (remote_med->a_attributes,                                               posattr);          if (0 == osip_strncasecmp (attr->a_att_field, "rtpmap", 6))            {              if (attr->a_att_value != NULL &&                  0 == osip_strncasecmp (attr->a_att_value, payload,                                         strlen (payload)))                {                  /* TODO check if it was not like 101: == 10 */                  rtpmap = attr->a_att_value;                  break;                }            }          posattr++;        }      local_med = osip_rfc3264_find_video (config, payload, rtpmap);      if (local_med != NULL)        {          /* found a supported codec? */          video_tab[num] = local_med;          num++;        }      /* search for support of this codec in local media list */      pos++;    }  video_tab[num] = NULL;  return 0;}/** * Compare remote sdp packet against local supported media for t38. * @param config The element to work on. * @param remote_sdp The remote SDP packet. * @param remote_med The remote Media SDP line. * @param t38_tab The local list of media supported by both side. */intosip_rfc3264_match_t38 (struct osip_rfc3264 *config,                        sdp_message_t * remote_sdp,                        sdp_media_t * remote_med, sdp_media_t * t38_tab[]){  osip_rfc3264_t *cnf = (osip_rfc3264_t *) config;  t38_tab[0] = NULL;  if (cnf == NULL)    return -1;  return 0;}/** * Compare remote sdp packet against local supported media for application. * @param config The element to work on. * @param remote_sdp The remote SDP packet. * @param remote_med The remote Media SDP line. * @param app_tab The local list of media supported by both side. */intosip_rfc3264_match_app (struct osip_rfc3264 *config,                        sdp_message_t * remote_sdp,                        sdp_media_t * remote_med, sdp_media_t * app_tab[]){  osip_rfc3264_t *cnf = (osip_rfc3264_t *) config;  app_tab[0] = NULL;  if (cnf == NULL)    return -1;  return 0;}/** * Prepare an uncomplete answer. * @param config The element to work on. * @param remote_sdp The remote SDP packet. * @param local_sdp The local SDP packet to prepare. * @param length The local SDP packet's length. */intosip_rfc3264_prepare_answer (struct osip_rfc3264 *config,                             sdp_message_t * remote_sdp,                             char *local_sdp, int length){  int pos, pos2;  if (config == NULL)    return -1;  if (remote_sdp == NULL)    return -1;  if (osip_list_size (remote_sdp->t_descrs) > 0)#if !defined __PALMOS__ && (defined WIN32 || defined _WIN32_WCE)    _snprintf (local_sdp, 4096, "v=0\r\n\o=userX 20000001 20000001 IN IP4 TOREPLACE\r\n\s=-\r\n\c=IN IP4 TOREPLACE\r\n");#else    snprintf (local_sdp, 4096, "v=0\r\n\o=userX 20000001 20000001 IN IP4 TOREPLACE\r\n\s=-\r\n\c=IN IP4 TOREPLACE\r\n");#endif  /* Fill t= (and r=) fields */  pos = 0;  while (!osip_list_eol (remote_sdp->t_descrs, pos))    {      char tmp[100];      sdp_time_descr_t *td;      td = (sdp_time_descr_t *) osip_list_get (remote_sdp->t_descrs, pos);      if (td->t_start_time != NULL && td->t_stop_time != NULL)#if !defined __PALMOS__ && (defined WIN32 || defined _WIN32_WCE)        _snprintf (tmp, 100, "t=%s %s\r\n", td->t_start_time, td->t_stop_time);#else        snprintf (tmp, 100, "t=%s %s\r\n", td->t_start_time, td->t_stop_time);#endif      else#if !defined __PALMOS__ && (defined WIN32 || defined _WIN32_WCE)        _snprintf (tmp, 100, "t=0 0\r\n");#else        snprintf (tmp, 100, "t=0 0\r\n");#endif      if ((int) (strlen (local_sdp) + strlen (tmp) + 1) < length)        {          strcat (local_sdp, tmp);          pos2 = 0;          while (!osip_list_eol (td->r_repeats, pos2))            {              char *str = (char *) osip_list_get (td->r_repeats, pos2);              if ((int) (strlen (local_sdp) + strlen (str) + 5 + 1) < length)                {                  strcat (local_sdp, "r=");                  strcat (local_sdp, str);                  strcat (local_sdp, "\r\n");              } else                return -1;              pos2++;            }      } else        return -1;      pos++;    }  pos = 0;  while (!osip_list_eol (remote_sdp->m_medias, pos))    {      int posattr = 0;      char tmp[200];      char tmp2[200];      char inactive = 'X';      sdp_media_t *med;#if !defined __PALMOS__ && (defined WIN32 || defined _WIN32_WCE)      _snprintf (tmp2, 199, "\r\n");#else      snprintf (tmp2, 199, "\r\n");#endif      med = (sdp_media_t *) osip_list_get (remote_sdp->m_medias, pos);      /* search for the rtpmap associated to the payload */      while (!osip_list_eol (med->a_attributes, posattr))        {          sdp_attribute_t *attr =            (sdp_attribute_t *) osip_list_get (med->a_attributes, posattr);          if (strlen (attr->a_att_field) == 8 && attr->a_att_value == NULL)            {              if (0 == osip_strncasecmp (attr->a_att_field, "sendonly", 8))                {#if !defined __PALMOS__ && (defined WIN32 || defined _WIN32_WCE)                  _snprintf (tmp2, 199, "\r\na=recvonly\r\n");#else                  snprintf (tmp2, 199, "\r\na=recvonly\r\n");#endif                  break;              } else if (0 == osip_strncasecmp (attr->a_att_field, "recvonly", 8))                {#if !defined __PALMOS__ && (defined WIN32 || defined _WIN32_WCE)                  _snprintf (tmp2, 199, "\r\na=sendonly\r\n");#else                  snprintf (tmp2, 199, "\r\na=sendonly\r\n");#endif                  break;              } else if (0 == osip_strncasecmp (attr->a_att_field, "sendrecv", 8))                {                  break;              } else if (0 == osip_strncasecmp (attr->a_att_field, "inactive", 8))                {#if !defined __PALMOS__ && (defined WIN32 || defined _WIN32_WCE)                  _snprintf (tmp2, 199, "\r\na=inactive\r\n");#else                  snprintf (tmp2, 199, "\r\na=inactive\r\n");#endif                  inactive = '0';                  break;                }            }          posattr++;        }      if (med->m_media != NULL && med->m_proto != NULL          && med->m_number_of_port == NULL)        {#if !defined __PALMOS__ && (defined WIN32 || defined _WIN32_WCE)          _snprintf (tmp, 199, "m=%s %c %s ", med->m_media, inactive,                     med->m_proto);#else          snprintf (tmp, 199, "m=%s %c %s ", med->m_media, inactive, med->m_proto);#endif      } else if (med->m_media != NULL && med->m_proto != NULL                 && med->m_number_of_port != NULL)        {#if !defined __PALMOS__ && (defined WIN32 || defined _WIN32_WCE)          _snprintf (tmp, 199, "m=%s %c %s/%s ", med->m_media, inactive,                     med->m_proto, med->m_number_of_port);#else          snprintf (tmp, 199, "m=%s %c %s/%s ", med->m_media, inactive,                    med->m_proto, med->m_number_of_port);#endif      } else        return -1;      if ((int) (strlen (local_sdp) + strlen (tmp) + 1) < length)        strcat (local_sdp, tmp);      else        return -1;      if ((int) (strlen (local_sdp) + strlen (tmp2) + 1) < length)        strcat (local_sdp, tmp2);      else        return -1;      pos++;    }  return 0;}/** * Agree to support a specific codec. *   This method should be called for each codec returned by *   osip_rfc3264_match(...) that the calle agree to support. * * @param config The element to work on. * @param remote_sdp The remote SDP packet. * @param local_sdp The local SDP packet to complete. * @param med One of the media returned by osip_rfc3264_match. * @param mline The position of the media line to complete. */intosip_rfc3264_complete_answer (struct osip_rfc3264 *config,                              sdp_message_t * remote_sdp,                              sdp_message_t * local_sdp,                              sdp_media_t * med, int mline){  osip_rfc3264_t *cnf = (osip_rfc3264_t *) config;  sdp_media_t *remote_med = NULL;  sdp_media_t *local_med = NULL;  int pos;  if (cnf == NULL)    return -1;  if (remote_sdp == NULL)    return -1;  if (med == NULL)    return -1;  if (mline < 0)    return -1;  if (local_sdp == NULL)    return -1;  pos = 0;  while (!osip_list_eol (remote_sdp->m_medias, pos))    {      remote_med = (sdp_media_t *) osip_list_get (remote_sdp->m_medias, pos);      local_med = (sdp_media_t *) osip_list_get (local_sdp->m_medias, pos);      if (pos == mline)        break;      remote_med = NULL;      local_med = NULL;      pos++;    }  if (remote_med == NULL)    return -1;  pos = 0;  while (!osip_list_eol (med->a_attributes, pos))    {      sdp_attribute_t *attr =        (sdp_attribute_t *) osip_list_get (med->a_attributes, pos);      if (0 == osip_strcasecmp ("rtpmap", attr->a_att_field)          && attr->a_att_value != NULL)        {          sdp_attribute_t *mattr;          char *tmp;          /* fill the m= line */          tmp = (char *) osip_list_get (med->m_payloads, 0);          if (tmp != NULL)            osip_list_add (local_med->m_payloads, osip_strdup (tmp), -1);          else            return -1;          sdp_attribute_init (&mattr);          mattr->a_att_field = osip_strdup (attr->a_att_field);          mattr->a_att_value = osip_strdup (attr->a_att_value);          /* fill the a= line */          osip_list_add (local_med->a_attributes, mattr, -1);          return 0;        }    }  return -1;                    /* no rtpmap found? It is mandatory in audio and video media */}/** * Agree to support a specific codec. *   This method should be called for each codec returned by *   osip_rfc3264_match(...) * * @param config The element to work on. * @param med One of the media returned by osip_rfc3264_match * @param remote_sdp The remote SDP packet. * @param local_sdp The local SDP packet to prepare. */intosip_rfc3264_accept_codec (struct osip_rfc3264 *config,                           sdp_media_t * med,                           sdp_message_t * remote_sdp, sdp_message_t * local_sdp){  if (config == NULL)    return -1;  return 0;}/* #ifdef RFC3264_DEBUG *//** * List supported codecs. (for debugging purpose only) * * @param config The element to work on. */int__osip_rfc3264_print_codecs (struct osip_rfc3264 *config){  osip_rfc3264_t *cnf = (osip_rfc3264_t *) config;  int i, pos;  if (config == NULL)    return -1;  fprintf (stdout, "Audio codecs Supported:\n");  for (i = 0; i < MAX_AUDIO_CODECS; i++)    {      if (cnf->audio_medias[i] != NULL)        {          sdp_media_t *med = cnf->audio_medias[i];          char *str = (char *) osip_list_get (med->m_payloads, 0);          fprintf (stdout, "\tm=%s %s %s %s\n",                   med->m_media, med->m_port, med->m_proto, str);          pos = 0;          while (!osip_list_eol (med->a_attributes, pos))            {              sdp_attribute_t *attr =                (sdp_attribute_t *) osip_list_get (med->a_attributes, pos);              fprintf (stdout, "\ta=%s:%s\n",                       attr->a_att_field, attr->a_att_value);              pos++;            }          fprintf (stdout, "\n");        }    }  fprintf (stdout, "Video codecs Supported:\n");  for (i = 0; i < MAX_VIDEO_CODECS; i++)    {      if (cnf->video_medias[i] != NULL)        {          sdp_media_t *med = cnf->video_medias[i];          char *str = (char *) osip_list_get (med->m_payloads, 0);          fprintf (stdout, "\tm=%s %s %s %s\n",                   med->m_media, med->m_port, med->m_proto, str);          pos = 0;          while (!osip_list_eol (med->a_attributes, pos))            {              sdp_attribute_t *attr =                (sdp_attribute_t *) osip_list_get (med->a_attributes, pos);              fprintf (stdout, "\ta=%s:%s\n",                       attr->a_att_field, attr->a_att_value);              pos++;            }          fprintf (stdout, "\n");        }    }  fprintf (stdout, "t38 configs Supported:\n");  for (i = 0; i < MAX_T38_CODECS; i++)    {      if (cnf->t38_medias[i] != NULL)        {          sdp_media_t *med = cnf->t38_medias[i];          fprintf (stdout, "m=%s %s %s X\n",                   med->m_media, med->m_port, med->m_proto);          pos = 0;          while (!osip_list_eol (med->a_attributes, pos))            {              sdp_attribute_t *attr =                (sdp_attribute_t *) osip_list_get (med->a_attributes, pos);              fprintf (stdout, "\ta=%s:%s\n",                       attr->a_att_field, attr->a_att_value);              pos++;            }          fprintf (stdout, "\n");        }    }  fprintf (stdout, "Application config Supported:\n");  for (i = 0; i < MAX_APP_CODECS; i++)    {      if (cnf->app_medias[i] != NULL)        {          sdp_media_t *med = cnf->app_medias[i];          fprintf (stdout, "m=%s %s %s X\n",                   med->m_media, med->m_port, med->m_proto);          pos = 0;          while (!osip_list_eol (med->a_attributes, pos))            {              sdp_attribute_t *attr =                (sdp_attribute_t *) osip_list_get (med->a_attributes, pos);              fprintf (stdout, "\ta=%s:%s\n",                       attr->a_att_field, attr->a_att_value);              pos++;            }          fprintf (stdout, "\n");        }    }  return 0;}/* #endif */

⌨️ 快捷键说明

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