Changeset 296:dc30103742b9

Show
Ignore:
Timestamp:
10/08/08 15:31:23 (3 months ago)
Author:
vadim@mbdsys.com
Message:

implement multicasting

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • phapi/phapi.c

    r286 r296  
    137137 
    138138static char*  _get_public_sip_port(); 
     139 
    139140 
    140141 
     
    193194ph_build_cname(char *buf, int n, struct vline *vl); 
    194195 
     196 
     197static  
     198void ph_msession_free(struct ph_msession_s *s); 
    195199 
    196200int phvlRegister(int vlid); 
     
    10171021phLinePlaceCall4(int vlid, const char *uri, void *userdata, int rcid, int streams, const char *adev, const char *audio_addr, const char *video_addr) 
    10181022{ 
    1019    return phLinePlaceCall_withCa(vlid, uri, userdata, rcid, streams, 0, 0, adev, 0, 0); 
     1023   return phLinePlaceCall_withCa(vlid, uri, userdata, rcid, streams, 0, adev, audio_addr, video_addr); 
     1024
     1025 
     1026 
     1027 
     1028MY_DLLEXPORT int  
     1029phLinePlaceMcCall(int vlid, const char *uri, void *userdata, int streams, const char *adev) 
     1030
     1031   return phLinePlaceCall_withCa(vlid, uri, userdata, 0,  
     1032                                 streams|PH_STREAM_MCRECV, 0, adev, 0, 0); 
    10201033} 
    10211034  
     1035 
     1036 
    10221037 
    10231038#define optional(x) (x[0] ? x : 0) 
     
    10921107  else 
    10931108    { 
    1094  
    10951109#ifdef STUN_ENABLE 
    10961110         
     
    10981112        { 
    10991113           
    1100           int ret = getPublicPort(local_voice_port, local_video_port, public_voice_port, public_video_port ); 
     1114          int ret = 0; 
     1115 
     1116          ret = getPublicPort(local_voice_port, local_video_port, public_voice_port, public_video_port ); 
    11011117           
     1118 
    11021119          if (ret <1) 
    11031120            { 
     
    15951612} 
    15961613 
     1614MY_DLLEXPORT int  
     1615phAcceptMcCall(int cid, const char *adev, const char *audioaddr, int port) 
     1616{ 
     1617   phcall_t *ca = ph_locate_call_by_cid(cid); 
     1618   char  local_voice_port[16] = "0"; 
     1619   int streams = PH_STREAM_AUDIO; 
     1620   phCallStateInfo_t info; 
     1621   int i; 
     1622   char *remoteUri; 
     1623    
     1624   snprintf(local_voice_port,16, "%d", port); 
     1625   eXosip_lock(); 
     1626    
     1627   i = eXosip_answer_call(ca->did, 200, local_voice_port, ph_get_call_contact(ca),  
     1628                         NULL,NULL,NULL, 
     1629                                 audioaddr, NULL); 
     1630           
     1631 
     1632  
     1633    if (i == 0) 
     1634      { 
     1635        char tmp[16]; 
     1636         
     1637        i = ph_call_retrieve_payloads(ca, NULL, streams); 
     1638 
     1639        _get_local_audio_sdp_port(tmp); 
     1640        ca->local_sdp_audio_port = atoi(tmp); 
     1641        ca->remote_sdp_audio_port = port; 
     1642        strncpy(ca->remote_sdp_audio_ip, audioaddr, sizeof(ca->remote_sdp_audio_ip)); 
     1643 
     1644      } 
     1645   
     1646    eXosip_unlock(); 
     1647 
     1648    if (adev) 
     1649      { 
     1650        if (ca->audiodev) free(ca->audiodev); 
     1651        ca->audiodev = strdup(adev); 
     1652      } 
     1653 
     1654    ph_call_media_start(ca, NULL, streams|PH_STREAM_MCSEND, 0);   
     1655 
     1656    eXosip_lock(); 
     1657    eXosip_retrieve_from(ca->did, &remoteUri); 
     1658    eXosip_unlock(); 
     1659 
     1660    clear(info); 
     1661 
     1662    info.u.remoteUri = remoteUri; 
     1663    info.event = phCALLOK; 
     1664    phcb->callProgress(cid, &info); 
     1665 
     1666    if (remoteUri) 
     1667      osip_free(remoteUri); 
     1668 
     1669    return 0; 
     1670 
     1671 
     1672} 
     1673 
     1674phAcceptMcastCall2(int cid, int mcid) 
     1675{ 
     1676 
     1677} 
    15971678 
    15981679static void  
     
    39304011 
    39314012    if (ca->mses) 
    3932     { 
    3933         if (!ca->audiodev) 
    3934           ca->audiodev = phcfg.audio_dev; 
    3935  
    3936         if (!ph_msession_stopped(ca->mses)) 
    3937         { 
    3938           ph_msession_stop(ca->mses, ca->audiodev); 
    3939         } 
    3940          
    3941         // cf allocation sequence for the ph_msession_s in phmedia.h 
    3942         g_mutex_free(ca->mses->critsec_mstream_init); 
    3943         free(ca->mses); 
    3944          
    3945         ca->mses = 0; 
    3946     } 
     4013      { 
     4014        if (ca->mses->refcnt == 1) 
     4015          { 
     4016            if (!ca->audiodev) 
     4017              ca->audiodev = phcfg.audio_dev; 
     4018 
     4019            if (!ph_msession_stopped(ca->mses)) 
     4020              { 
     4021                ph_msession_stop(ca->mses, ca->audiodev); 
     4022              } 
     4023          } 
     4024        ph_msession_free(ca->mses); 
     4025        ca->mses = 0; 
     4026      } 
     4027 
     4028    return 0; 
    39474029 
    39484030} 
     
    39794061 
    39804062} 
     4063 
     4064 
     4065 
     4066static  
     4067struct ph_msession_s *ph_msession_new() 
     4068{ 
     4069   struct ph_msession_s *s  = (struct ph_msession_s *)calloc(sizeof(struct ph_msession_s), 1); 
     4070   s->critsec_mstream_init = g_mutex_new(); 
     4071   s->refcnt = 1; 
     4072} 
     4073 
     4074 
     4075static  
     4076void ph_msession_free(struct ph_msession_s *s) 
     4077{ 
     4078  if (s) 
     4079    { 
     4080      g_mutex_lock(s->critsec_mstream_init); 
     4081      if (s->refcnt-- == 1) 
     4082        { 
     4083          g_mutex_unlock(s->critsec_mstream_init); 
     4084          free(s); 
     4085          return; 
     4086        } 
     4087      g_mutex_unlock(s->critsec_mstream_init); 
     4088    } 
     4089} 
     4090 
    39814091 
    39824092 
     
    40004110  if (!s) 
    40014111    { 
    4002         s = ca->mses = (struct ph_msession_s *)calloc(sizeof(struct ph_msession_s), 1); 
    4003         s->critsec_mstream_init = g_mutex_new(); 
     4112        s = ca->mses = ph_msession_new(); 
    40044113    } 
    40054114 
  • phapi/phapi.h

    r250 r296  
    173173#define PH_NOMEDIA_STREAMS (1 << 5) 
    174174#define PH_STREAM_DATA (1 << 6) 
     175#define PH_STREAM_MCSEND (1 << 7) 
     176#define PH_STREAM_MCRECV (1 << 8) 
     177 
    175178 
    176179/********************TELEPHONY*********************/ 
     
    258261MY_DLLEXPORT int phAcceptCall4(int cid, void *userData, int streams, const char *audio_addr, const char *video_addr); 
    259262MY_DLLEXPORT int phAcceptCall5(int cid, void *userData, int streams, ...); 
     263 
     264MY_DLLEXPORT int phAcceptMcCall(int cid, const char *adev, const char *audioaddr, int port); 
     265MY_DLLEXPORT int phLinePlaceMcCall(int vlid, const char *uri, void *userdata, int streams, const char *adev); 
     266 
    260267 
    261268#define phAcceptCall(cid) phAcceptCall2(cid, 0) 
  • phapi/phmedia-audio.c

    r272 r296  
    22182218} 
    22192219 
     2220 
     2221int ph_media_setup_mcast_send(int fd, ph_mstream_params_t *sp) 
     2222{ 
     2223  return 0; 
     2224} 
     2225 
     2226 
     2227int ph_media_setup_mcast_recv(int fd, ph_mstream_params_t *sp) 
     2228{ 
     2229     struct ip_mreq mreq; 
     2230 
     2231     memset(&mreq, 0, sizeof(mreq)); 
     2232     mreq.imr_multiaddr.s_addr=inet_addr(sp->remoteaddr); 
     2233     mreq.imr_interface.s_addr=htonl(INADDR_ANY); 
     2234     if (setsockopt(fd,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq)) < 0) 
     2235       return -1; 
     2236 
     2237     return 0; 
     2238 
     2239} 
    22202240 
    22212241 
     
    23362356          else 
    23372357#endif 
    2338             rtp_session_set_remote_addr(stream->ms.rtp_session, 
     2358            { 
     2359 
     2360              rtp_session_set_remote_addr(stream->ms.rtp_session, 
    23392361                                        stream->ms.remote_ip, 
    23402362                                        stream->ms.remote_port); 
     2363 
     2364              if (s->mcast_send) 
     2365                { 
     2366                  ph_media_setup_mcast_send(stream->ms.rtp_session->rtp.socket, sp); 
     2367                } 
     2368              else if (s->mcast_recv) 
     2369                { 
     2370                  ph_media_setup_mcast_recv(stream->ms.rtp_session->rtp.socket, sp); 
     2371                } 
     2372                 
     2373 
     2374 
     2375            } 
    23412376           
    23422377          DBG1_MEDIA_ENGINE("ph_msession_audio_start: audio stream reset done\n"); 
     
    24322467 
    24332468   
    2434    
    2435   session = rtp_session_new(RTP_SESSION_SENDRECV); 
     2469  if (s->mcast_send) 
     2470    session = rtp_session_new(RTP_SESSION_SENDONLY); 
     2471  else if (s->mcast_recv) 
     2472    session = rtp_session_new(RTP_SESSION_RECVONLY); 
     2473  else 
     2474    session = rtp_session_new(RTP_SESSION_SENDRECV); 
    24362475 
    24372476  DBG2_MEDIA_ENGINE("ph_msession_audio_start: rtpsession's qos: %d\n", s->qos); 
     
    25022541  stream->ms.running = 1; 
    25032542  stream->ms.rtp_session = session; 
     2543 
     2544  if (s->mcast_send) 
     2545    { 
     2546      ph_media_setup_mcast_send(stream->ms.rtp_session->rtp.socket, sp); 
     2547    } 
     2548  else if (s->mcast_recv) 
     2549    { 
     2550      ph_media_setup_mcast_recv(stream->ms.rtp_session->rtp.socket, sp); 
     2551    } 
     2552   
    25042553 
    25052554 
  • phapi/phmedia.c

    r278 r296  
    7272 
    7373  g_mutex_lock(s->critsec_mstream_init); 
     74  if (s->refcnt != 1) 
     75    { 
     76      g_mutex_unlock(s->critsec_mstream_init); 
     77      return 0; 
     78    } 
     79 
    7480 
    7581  ret1 = ph_msession_audio_start(s, deviceid); 
  • phapi/phmedia.h

    r279 r296  
    133133struct ph_msession_s 
    134134{ 
     135  int    refcnt;          /* reference count */ 
     136  int    mcast_send; 
     137  int    mcast_recv; 
    135138  int    activestreams;   /* bit mask of active streams */ 
    136139  int    newstreams;      /* bit mask of new streams to be activated */