[server] / trunk / clients / freeswitch / mod_woomera / mod_woomera.c Repository:
ViewVC logotype

Diff of /trunk/clients/freeswitch/mod_woomera/mod_woomera.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 810, Tue Jul 13 15:26:37 2010 UTC revision 811, Wed Jul 14 16:52:35 2010 UTC
# Line 47  Line 47 
47  #define WOOMERA_HARD_TIMEOUT -10000  #define WOOMERA_HARD_TIMEOUT -10000
48  #define WOOMERA_QLEN 10  #define WOOMERA_QLEN 10
49  #define WOOMERA_RECONNECT_TIME 5000000  #define WOOMERA_RECONNECT_TIME 5000000
 //#define MEDIA_ANSWER "ANSWER"  
 // THE ONE ABOVE OR THE 2 BELOW BUT NOT BOTH  
 #define MEDIA_ANSWER "ANSWER"  
 #define USE_ANSWER 1  
50    
51  SWITCH_MODULE_LOAD_FUNCTION(mod_woomera_load);  SWITCH_MODULE_LOAD_FUNCTION(mod_woomera_load);
52  SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_woomera_shutdown);  SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_woomera_shutdown);
# Line 62  Line 58 
58    
59  #define STRLEN 15  #define STRLEN 15
60  #define FRAME_LEN 480  #define FRAME_LEN 480
 //static int WFORMAT = AST_FORMAT_SLINEAR;  
61    
62  static char *woomeraplaybackdesc = "Play audio and / or video on the Woomera Server\n";  static char *woomeraplaybackdesc = "Play audio and / or video on the Woomera Server\n";
63  static char *woomeraplaybackapp = "WoomeraPlayback";  static char *woomeraplaybackapp = "WoomeraPlayback";
# Line 131  Line 126 
126          TFLAG_STOP_COMPLETED = (1 << 17),          TFLAG_STOP_COMPLETED = (1 << 17),
127          TFLAG_TONE_EVENTS_ON = (1 << 18),          TFLAG_TONE_EVENTS_ON = (1 << 18),
128          TFLAG_TONE_EVENTS_OFF = (1 << 19),          TFLAG_TONE_EVENTS_OFF = (1 << 19),
129          TFLAG_WAITFORTONE = (1 << 20)          TFLAG_WAITFORTONE = (1 << 20),
130            TFLAG_BRIDGE = (1 << 21),
131            TFLAG_CONNECTED = (1 << 22)
132  } TFLAGS;  } TFLAGS;
133    
134  struct woomera_message {  struct woomera_message {
# Line 213  Line 210 
210          switch_rtp_t *rtp_session;          switch_rtp_t *rtp_session;
211          switch_port_t audio_local_port;          switch_port_t audio_local_port;
212          switch_port_t audio_remote_port;          switch_port_t audio_remote_port;
213            switch_port_t audio_bridge_port;
214          switch_payload_t audio_codec_num;          switch_payload_t audio_codec_num;
215          char *audio_codec_name;          char *audio_codec_name;
216          char *audio_codec_format;          char *audio_codec_format;
# Line 222  Line 220 
220          switch_rtp_t *vrtp_session;          switch_rtp_t *vrtp_session;
221          switch_port_t video_local_port;          switch_port_t video_local_port;
222          switch_port_t video_remote_port;          switch_port_t video_remote_port;
223            switch_port_t video_bridge_port;
224          switch_payload_t video_codec_num;          switch_payload_t video_codec_num;
225          char *video_codec_name;          char *video_codec_name;
226          char *video_codec_format;          char *video_codec_format;
# Line 253  Line 252 
252  static switch_status_t woomera_on_routing(switch_core_session_t *session);  static switch_status_t woomera_on_routing(switch_core_session_t *session);
253  static switch_status_t woomera_on_exchange_media(switch_core_session_t *session);  static switch_status_t woomera_on_exchange_media(switch_core_session_t *session);
254  static switch_status_t woomera_on_soft_execute(switch_core_session_t *session);  static switch_status_t woomera_on_soft_execute(switch_core_session_t *session);
255    static switch_status_t woomera_on_reset(switch_core_session_t *session);
256  static switch_status_t woomera_on_destroy(switch_core_session_t *session);  static switch_status_t woomera_on_destroy(switch_core_session_t *session);
257    
258  static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,  static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session, switch_event_t *var_event,
# Line 333  Line 333 
333          return SWITCH_STATUS_SUCCESS;          return SWITCH_STATUS_SUCCESS;
334  }  }
335    
336    static switch_status_t woomera_on_reset(switch_core_session_t *session)
337    {
338            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_on_reset()\n");
339            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s WOOMERA RESET\n", switch_channel_get_name(switch_core_session_get_channel(session)));
340            return SWITCH_STATUS_SUCCESS;
341    }
342    
343    
344  static switch_status_t woomera_on_hangup(switch_core_session_t *session)  static switch_status_t woomera_on_hangup(switch_core_session_t *session)
345  {  {
346          switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_on_hangup()\n");          switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_on_hangup()\n");
# Line 486  Line 494 
494                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "woomera_receive_message() - SWITCH_MESSAGE_INDICATE_ANSWER\n");                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "woomera_receive_message() - SWITCH_MESSAGE_INDICATE_ANSWER\n");
495                  break;                  break;
496          case SWITCH_MESSAGE_INDICATE_BRIDGE:          case SWITCH_MESSAGE_INDICATE_BRIDGE:
                 /*  
                    if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {  
                    switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);  
                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "De-activate timed RTP!\n");  
                    //switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK);  
                    }  
                  */  
497                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "woomera_receive_message() - SWITCH_MESSAGE_INDICATE_BRIDGE\n");                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "woomera_receive_message() - SWITCH_MESSAGE_INDICATE_BRIDGE\n");
498                    if (switch_channel_test_flag(channel, CF_BRIDGE_ORIGINATOR)) {
499                            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "woomera_receive_message() - BRIDGE CALL\n");
500    
501                            switch_core_session_message_t smsg = { 0 };
502                            smsg.message_id = SWITCH_MESSAGE_INDICATE_SIMPLIFY;
503                            smsg.from = __FILE__;
504                            switch_core_session_receive_message(session, &smsg);
505                    }
506                  break;                  break;
507          case SWITCH_MESSAGE_INDICATE_UNBRIDGE:          case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
                 /*  
                    if (tech_pvt->rtp_session && switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {  
                    switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_USE_TIMER);  
                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-activate timed RTP!\n");  
                    //switch_rtp_clear_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_TIMER_RECLOCK);  
                    }  
                  */  
508                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "woomera_receive_message() - SWITCH_MESSAGE_INDICATE_UNBRIDGE\n");                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "woomera_receive_message() - SWITCH_MESSAGE_INDICATE_UNBRIDGE\n");
509                  break;                  break;
510    
# Line 575  Line 577 
577                  break;                  break;
578          case SWITCH_MESSAGE_INDICATE_SIMPLIFY:          case SWITCH_MESSAGE_INDICATE_SIMPLIFY:
579                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "woomera_receive_message() - SWITCH_MESSAGE_INDICATE_SIMPLIFY\n");                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "woomera_receive_message() - SWITCH_MESSAGE_INDICATE_SIMPLIFY\n");
580                    const char *uuid;
581                    if ((uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
582                            switch_core_session_t *rsession;
583                            if ((rsession = switch_core_session_locate(uuid))) {
584                                    struct private_object *rtech_pvt = switch_core_session_get_private(rsession);
585                                    switch_assert(rtech_pvt != NULL);
586    
587                                    tech_pvt->audio_bridge_port = rtech_pvt->audio_remote_port;
588                                    tech_pvt->video_bridge_port = rtech_pvt->video_remote_port;
589    
590                                    rtech_pvt->audio_bridge_port = tech_pvt->audio_remote_port;
591                                    rtech_pvt->video_bridge_port = tech_pvt->video_remote_port;
592    
593                                    switch_set_flag(tech_pvt, TFLAG_BRIDGE);
594                                    switch_set_flag(rtech_pvt, TFLAG_BRIDGE);
595                                    switch_core_session_rwunlock(rsession);
596                            }
597                    }
598                  break;                  break;
599          case SWITCH_MESSAGE_INDICATE_DEBUG_AUDIO:          case SWITCH_MESSAGE_INDICATE_DEBUG_AUDIO:
600                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "woomera_receive_message() - SWITCH_MESSAGE_INDICATE_DEBUG_AUDIO\n");                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "woomera_receive_message() - SWITCH_MESSAGE_INDICATE_DEBUG_AUDIO\n");
# Line 604  Line 624 
624  static switch_status_t woomera_receive_event(switch_core_session_t *session, switch_event_t *event)  static switch_status_t woomera_receive_event(switch_core_session_t *session, switch_event_t *event)
625  {  {
626          switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_receive_event()\n");          switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_receive_event()\n");
         struct private_object *tech_pvt = switch_core_session_get_private(session);  
         char *subject, *body;  
   
         switch_assert(tech_pvt != NULL);  
   
   
         if (!(body = switch_event_get_body(event))) {  
                 body = "";  
         }  
   
         if (!(subject = switch_event_get_header(event, "subject"))) {  
                 subject = "None";  
         }  
   
         /*TODO*/  
         //ldl_session_send_msg(tech_pvt->dlsession, subject, body);  
   
627          return SWITCH_STATUS_SUCCESS;          return SWITCH_STATUS_SUCCESS;
628  }  }
629    
# Line 639  Line 642 
642    
643  static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)  static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
644  {  {
645          switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_read_frame()\n", pthread_self());  //      switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_read_frame()\n", pthread_self());
646          struct private_object *tech_pvt = switch_core_session_get_private(session);          struct private_object *tech_pvt = switch_core_session_get_private(session);
647          switch_channel_t *channel = switch_core_session_get_channel(session);          switch_channel_t *channel = switch_core_session_get_channel(session);
648          switch_frame_t *pframe;          switch_frame_t *pframe;
649          switch_size_t len;          switch_status_t status;
650    
651          switch_assert(tech_pvt != NULL);          switch_assert(tech_pvt != NULL);
652    
         if (!tech_pvt->audio_udp_socket && !tech_pvt->rtp_session) {  
                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_read_frame - SWITCH_STATUS_GENERR\n");  
                 return SWITCH_STATUS_GENERR;  
         }  
   
         pframe = &tech_pvt->audio_frame;  
         *frame = pframe;  
   
         if (tech_pvt->audio_udp_socket)  
         {  
                 len = sizeof(tech_pvt->audio_udpbuf);  
                 if (switch_socket_recvfrom(tech_pvt->audio_udpread, tech_pvt->audio_udp_socket, 0, tech_pvt->audio_udpbuf, &len) == SWITCH_STATUS_SUCCESS) {  
                         pframe->datalen = (uint32_t) len;  
                         pframe->samples = (int) pframe->datalen / 2;  
                         return SWITCH_STATUS_SUCCESS;  
                 }  
         }  
         else //RTP  
         {  
653                  while (!(tech_pvt->audio_codec.implementation && switch_rtp_ready(tech_pvt->rtp_session))) {                  while (!(tech_pvt->audio_codec.implementation && switch_rtp_ready(tech_pvt->rtp_session))) {
654                          if (switch_channel_ready(channel)) {                          if (switch_channel_ready(channel)) {
655                                  switch_yield(10000);                                  switch_yield(10000);
656                          } else {                          } else {
                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_read_frame - SWITCH_STATUS_GENERR2\n");  
657                                  return SWITCH_STATUS_GENERR;                                  return SWITCH_STATUS_GENERR;
658                          }                          }
659                  }                  }
660                  switch_status_t status;  
661                  switch_assert(tech_pvt->rtp_session != NULL);                  switch_assert(tech_pvt->rtp_session != NULL);
662            pframe = &tech_pvt->audio_frame;
663    
664                  pframe->datalen = 0;                  pframe->datalen = 0;
665    
666                  while (pframe->datalen == 0)                  while (pframe->datalen == 0)
667                  {                  {
668                          pframe->flags = SFF_NONE;                          pframe->flags = SFF_NONE;
   
669                          status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, pframe, flags);                          status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, pframe, flags);
670                          if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {                          if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
671                                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_read_frame - SWITCH_STATUS_FALSE\n");                          return status;
                                 return SWITCH_STATUS_FALSE;  
672                          }                          }
                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_read_frame - status:%d\n", pthread_self(), status);  
   
                         if (switch_rtp_has_dtmf(tech_pvt->rtp_session)) {  
                                 switch_dtmf_t dtmf = { 0 };  
                                 switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, &dtmf);  
                                 switch_channel_queue_dtmf(channel, &dtmf);  
673                          }                          }
674    
                         if (pframe->datalen > 0) {  
675                                  size_t bytes = 0;                                  size_t bytes = 0;
676                                  int frames = 1;                                  int frames = 1;
677    
# Line 705  Line 681 
681                                          }                                          }
682                                          pframe->samples = (int) (frames * tech_pvt->audio_codec.implementation->samples_per_packet);                                          pframe->samples = (int) (frames * tech_pvt->audio_codec.implementation->samples_per_packet);
683                                  }                                  }
684                                  break;  
685                          }          *frame = pframe;
686                  }  //      switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_read_frame - EXIT - len:%d\n", pthread_self(), pframe->datalen);
                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_read_frame - EXIT - len:%d\n", pthread_self(), pframe->datalen);  
687                  return SWITCH_STATUS_SUCCESS;                  return SWITCH_STATUS_SUCCESS;
688          }          }
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_read_frame - SWITCH_STATUS_FALSE2\n");  
         return SWITCH_STATUS_FALSE;  
 }  
689    
690    
691  static switch_status_t woomera_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)  static switch_status_t woomera_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
692  {  {
693          switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_write_frame()\n", pthread_self());  //      switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_write_frame()\n", pthread_self());
694          struct private_object *tech_pvt = switch_core_session_get_private(session);;          struct private_object *tech_pvt = switch_core_session_get_private(session);;
695          switch_channel_t *channel = switch_core_session_get_channel(session);          switch_channel_t *channel = switch_core_session_get_channel(session);
         switch_size_t len;  
         int bytes = 0, frames = 0;  
696    
697          switch_assert(tech_pvt != NULL);          switch_assert(tech_pvt != NULL);
698    
         if (!tech_pvt->audio_udp_socket && !tech_pvt->rtp_session) {  
                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_write_frame - SWITCH_STATUS_GENERR\n");  
                 return SWITCH_STATUS_GENERR;  
         }  
   
         if (tech_pvt->audio_udp_socket)  
         {  
                 if (switch_test_flag(tech_pvt, TFLAG_ABORT) || !tech_pvt->audio_udp_socket) {  
                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_write_frame - SWITCH_STATUS_GENERR2\n");  
                         return SWITCH_STATUS_GENERR;  
                 }  
   
                 if (!switch_test_flag(tech_pvt, TFLAG_MEDIA)) {  
                         return SWITCH_STATUS_SUCCESS;  
                 }  
   
                 len = frame->datalen;  
                 if (switch_socket_sendto(tech_pvt->audio_udp_socket, tech_pvt->audio_udpwrite, 0, frame->data, &len) == SWITCH_STATUS_SUCCESS) {  
                         frame->datalen = (uint32_t) len;  
                         return SWITCH_STATUS_SUCCESS;  
                 }  
                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_write_frame - SWITCH_STATUS_GENERR3\n");  
                 return SWITCH_STATUS_GENERR;  
         }  
         else // RTP  
         {  
699                  while (!(tech_pvt->audio_codec.implementation && switch_rtp_ready(tech_pvt->rtp_session)))                  while (!(tech_pvt->audio_codec.implementation && switch_rtp_ready(tech_pvt->rtp_session)))
700                  {                  {
701                          if (switch_channel_ready(channel)) {                          if (switch_channel_ready(channel)) {
# Line 767  Line 711 
711                          return SWITCH_STATUS_GENERR;                          return SWITCH_STATUS_GENERR;
712                  }                  }
713    
                 switch_set_flag_locked(tech_pvt, TFLAG_WRITING);  
                 if (!switch_test_flag(frame, SFF_CNG)) {  
                         if (tech_pvt->audio_codec.implementation->encoded_bytes_per_packet) {  
                                 bytes = tech_pvt->audio_codec.implementation->encoded_bytes_per_packet;  
                                 frames = ((int) frame->datalen / bytes);  
                         }  
                         else {  
                                 frames = 1;  
                         }  
                 }  
   
714                  if (switch_rtp_write_frame(tech_pvt->rtp_session, frame) < 0) {                  if (switch_rtp_write_frame(tech_pvt->rtp_session, frame) < 0) {
715                          switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_write_frame - SWITCH_STATUS_GENERR6\n");                          switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "woomera_write_frame - SWITCH_STATUS_GENERR6\n");
716                          return SWITCH_STATUS_GENERR;                          return SWITCH_STATUS_GENERR;
717                  }                  }
                 switch_clear_flag_locked(tech_pvt, TFLAG_WRITING);  
718    
719                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_write_frame() -  EXIT \n", pthread_self());  //      switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_write_frame() -  EXIT \n", pthread_self());
720                  return SWITCH_STATUS_SUCCESS;                  return SWITCH_STATUS_SUCCESS;
721          }          }
722  }  
723    
724    
725  static switch_status_t woomera_read_video_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)  static switch_status_t woomera_read_video_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id)
726  {  {
727          switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_read_video_frame()\n", pthread_self());  //      switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_read_video_frame()\n", pthread_self());
728          struct private_object *tech_pvt = switch_core_session_get_private(session);          struct private_object *tech_pvt = switch_core_session_get_private(session);
729          switch_channel_t *channel = switch_core_session_get_channel(session);          switch_channel_t *channel = switch_core_session_get_channel(session);
730          switch_frame_t *pframe;          switch_frame_t *pframe;
# Line 828  Line 760 
760                          }                          }
761                          return status;                          return status;
762                  }                  }
   
                 if (pframe->datalen > 0) {  
                         break;  
                 }  
         }  
   
         if (pframe->datalen == 0) {  
                 *frame = NULL;  
                 return SWITCH_STATUS_GENERR;  
763          }          }
764    
765          *frame = pframe;          *frame = pframe;
766          switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_read_video_frame() - EXIT\n", pthread_self());  //      switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_read_video_frame() - EXIT\n", pthread_self());
767          return SWITCH_STATUS_SUCCESS;          return SWITCH_STATUS_SUCCESS;
768  }  }
769    
770    
771  static switch_status_t woomera_write_video_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)  static switch_status_t woomera_write_video_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id)
772  {  {
773          switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_write_video_frame()\n", pthread_self());  //      switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_write_video_frame()\n", pthread_self());
774          struct private_object *tech_pvt = switch_core_session_get_private(session);          struct private_object *tech_pvt = switch_core_session_get_private(session);
775          switch_channel_t *channel = switch_core_session_get_channel(session);          switch_channel_t *channel = switch_core_session_get_channel(session);
776    
# Line 865  Line 788 
788                  return SWITCH_STATUS_GENERR;                  return SWITCH_STATUS_GENERR;
789          }          }
790    
         if (!switch_test_flag(frame, SFF_CNG)) {  
791                  if (switch_rtp_write_frame(tech_pvt->vrtp_session, frame) < 0 ) {                  if (switch_rtp_write_frame(tech_pvt->vrtp_session, frame) < 0 ) {
792                          return SWITCH_STATUS_GENERR;                          return SWITCH_STATUS_GENERR;
793                  }                  }
794          }  //      switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_write_video_frame() - EXIT\n", pthread_self());
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[%lu] woomera_write_video_frame() - EXIT\n", pthread_self());  
795          return SWITCH_STATUS_SUCCESS;          return SWITCH_STATUS_SUCCESS;
796  }  }
797    
# Line 883  Line 804 
804          /*.on_soft_execute */ woomera_on_soft_execute,          /*.on_soft_execute */ woomera_on_soft_execute,
805          /*.on_consume_media*/ NULL,          /*.on_consume_media*/ NULL,
806          /*.on_hibernate*/ NULL,          /*.on_hibernate*/ NULL,
807          /*.on_reset*/ NULL,          /*.on_reset*/ woomera_on_reset,
808          /*.on_park*/ NULL,          /*.on_park*/ NULL,
809          /*.on_reporting*/ NULL,          /*.on_reporting*/ NULL,
810          /*.on_destroy*/ woomera_on_destroy          /*.on_destroy*/ woomera_on_destroy
# Line 1110  Line 1031 
1031                  ptr++;                  ptr++;
1032                  bytes++;                  bytes++;
1033          }          }
         //*eor = '\0';  
1034          next = buf;          next = buf;
1035    
1036          if (globals.debug) {          if (globals.debug) {
# Line 1245  Line 1165 
1165          switch_socket_timeout_set((*new_sock), 10000000);          switch_socket_timeout_set((*new_sock), 10000000);
1166          switch_socket_opt_set((*new_sock), SWITCH_SO_KEEPALIVE, 1);          switch_socket_opt_set((*new_sock), SWITCH_SO_KEEPALIVE, 1);
1167    
         /*  
            status = switch_socket_bind((*new_sock), sa);  
            if (0 && status != SWITCH_STATUS_SUCCESS) {  
            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Can't Bind to %s:%d!\n", profile->woomera_host, profile->woomera_port);  
            return -1;  
            }  
          */  
1168          if (switch_socket_connect((*new_sock), sa) != SWITCH_STATUS_SUCCESS) {          if (switch_socket_connect((*new_sock), sa) != SWITCH_STATUS_SUCCESS) {
1169                  return -1;                  return -1;
1170          }          }
# Line 1300  Line 1213 
1213                                          if (*woomera_socket) {                                          if (*woomera_socket) {
1214                                                  woomera_socket_close(woomera_socket);                                                  woomera_socket_close(woomera_socket);
1215                                          }                                          }
   
1216                                          continue;                                          continue;
1217                                  }                                  }
1218                          }                          }
# Line 1626  Line 1538 
1538                                                 WOOMERA_RECORD_SEPERATOR                                                 WOOMERA_RECORD_SEPERATOR
1539                                                 );                                                 );
1540                          }                          }
   
1541                          woomera_message_parse(tech_pvt->woomera_socket, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue);                          woomera_message_parse(tech_pvt->woomera_socket, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue);
                 } else {  
                         //switch_set_flag_locked(tech_pvt, TFLAG_INCOMING);  
                         /* woomera_printf(tech_pvt->profile, tech_pvt->woomera_socket, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);  
                         if (woomera_message_parse(tech_pvt->woomera_socket, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {  
                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name);  
                                 switch_set_flag_locked(tech_pvt, TFLAG_ABORT);  
                                 globals.panic = 1;  
                         }*/  
1542                  }                  }
1543          } else {          }
1544            else
1545            {
1546                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Where's my tech_pvt?\n");                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Where's my tech_pvt?\n");
1547          }          }
   
1548          return 0;          return 0;
1549  }  }
1550    
# Line 1676  Line 1580 
1580                          switch_clear_flag_locked(tech_pvt, TFLAG_INCOMING);                          switch_clear_flag_locked(tech_pvt, TFLAG_INCOMING);
1581    
1582                          if (switch_test_flag(tech_pvt->profile, PFLAG_VIDEORTP)) {                          if (switch_test_flag(tech_pvt->profile, PFLAG_VIDEORTP)) {
   
1583                                  woomera_printf(tech_pvt->profile, tech_pvt->woomera_socket,                                  woomera_printf(tech_pvt->profile, tech_pvt->woomera_socket,
1584                                                             "ACCEPT %s%s"                                                             "ACCEPT %s%s"
1585                                                             "RTP-Audio: %s:%d%s"                                                             "RTP-Audio: %s:%d%s"
# Line 1748  Line 1651 
1651                                  }                                  }
1652                          }                          }
1653                          create_rtp(tech_pvt);                          create_rtp(tech_pvt);
 //                      switch_channel_set_state(channel, CS_ROUTING);  
1654                  }                  }
1655    
1656                  if (switch_test_flag(tech_pvt, TFLAG_ANSWER)) {                  if (switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
# Line 1797  Line 1699 
1699                                  continue;                                  continue;
1700                          }                          }
1701                          switch_clear_flag_locked(tech_pvt, TFLAG_ANSWER);                          switch_clear_flag_locked(tech_pvt, TFLAG_ANSWER);
1702                            switch_set_flag_locked(tech_pvt, TFLAG_CONNECTED);
1703                  }                  }
1704    
1705                  if (switch_test_flag(tech_pvt, TFLAG_DTMF)) {                  if (switch_test_flag(tech_pvt, TFLAG_DTMF)) {
# Line 1815  Line 1718 
1718                  }                  }
1719    
1720                  if (switch_test_flag(tech_pvt, TFLAG_PLAY)) {                  if (switch_test_flag(tech_pvt, TFLAG_PLAY)) {
 //                      switch_mutex_lock(tech_pvt->iolock);  
1721                          woomera_printf(tech_pvt->profile, tech_pvt->woomera_socket,                          woomera_printf(tech_pvt->profile, tech_pvt->woomera_socket,
1722                                         "PLAY%s"                                         "PLAY%s"
1723                                         "Unique-Call-Id: %s%s"                                         "Unique-Call-Id: %s%s"
# Line 1842  Line 1744 
1744                                         WOOMERA_RECORD_SEPERATOR                                         WOOMERA_RECORD_SEPERATOR
1745                                         );                                         );
1746                          switch_clear_flag_locked(tech_pvt, TFLAG_PLAY);                          switch_clear_flag_locked(tech_pvt, TFLAG_PLAY);
 //                      memset(tech_pvt->audio_uri, 0, sizeof(tech_pvt->audio_uri));  
 //                      memset(tech_pvt->video_uri, 0, sizeof(tech_pvt->video_uri));  
 //                      switch_mutex_unlock(tech_pvt->iolock);  
1747                          if (woomera_message_parse(tech_pvt->woomera_socket, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {                          if (woomera_message_parse(tech_pvt->woomera_socket, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
1748                                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} PLAY ABORT!\n", tech_pvt->profile->name);                                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} PLAY ABORT!\n", tech_pvt->profile->name);
1749                                  switch_set_flag_locked(tech_pvt, TFLAG_ABORT);                                  switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
# Line 1881  Line 1780 
1780                                               WOOMERA_RECORD_SEPERATOR                                               WOOMERA_RECORD_SEPERATOR
1781                                              );                                              );
1782                          switch_clear_flag(tech_pvt, TFLAG_RECORD);                          switch_clear_flag(tech_pvt, TFLAG_RECORD);
                         //memset(tech_pvt->audio_uri, 0, sizeof(tech_pvt->audio_uri));  
                         //memset(tech_pvt->video_uri, 0, sizeof(tech_pvt->video_uri));  
1783                          if (woomera_message_parse(tech_pvt->woomera_socket, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {                          if (woomera_message_parse(tech_pvt->woomera_socket, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
1784                                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} RECORD ABORT!\n", tech_pvt->profile->name);                                  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} RECORD ABORT!\n", tech_pvt->profile->name);
1785                                  switch_set_flag_locked(tech_pvt, TFLAG_ABORT);                                  switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
# Line 1963  Line 1860 
1860                                  continue;                                  continue;
1861                          }                          }
1862                  }                  }
1863                    if (switch_test_flag(tech_pvt, TFLAG_BRIDGE) && switch_test_flag(tech_pvt, TFLAG_CONNECTED)) {
1864                            woomera_printf(tech_pvt->profile, tech_pvt->woomera_socket,
1865                                           "UPDATE%s"
1866                                           "Unique-Call-Id: %s%s"
1867                                           "RTP-Audio: %s:%d%s"
1868                                           "RTP-Video: %s:%d%s",
1869                                           WOOMERA_LINE_SEPERATOR,
1870                                           tech_pvt->call_info.callid,
1871                                           WOOMERA_LINE_SEPERATOR,
1872                                           tech_pvt->profile->woomera_host,
1873                                           tech_pvt->audio_bridge_port,
1874                                           WOOMERA_LINE_SEPERATOR,
1875                                           tech_pvt->profile->woomera_host,
1876                                           tech_pvt->video_bridge_port,
1877                                           WOOMERA_RECORD_SEPERATOR
1878                                           );
1879                            switch_clear_flag_locked(tech_pvt, TFLAG_BRIDGE);
1880                            if (woomera_message_parse(tech_pvt->woomera_socket, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
1881                                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} BRIDGE ABORT!\n", tech_pvt->profile->name);
1882                                    switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
1883                                    globals.panic = 1;
1884                                    continue;
1885                            }
1886                    }
1887    
1888                  if (!tech_pvt->woomera_socket) {                  if (!tech_pvt->woomera_socket) {
1889                          break;                          break;
# Line 2000  Line 1921 
1921                          } else if (!strcasecmp(wmsg.command, "PROCEED")) {                          } else if (!strcasecmp(wmsg.command, "PROCEED")) {
1922                                  /* This packet has lots of info so well keep it */                                  /* This packet has lots of info so well keep it */
1923                                  tech_pvt->call_info = wmsg;                                  tech_pvt->call_info = wmsg;
1924  //                              switch_core_session_queue_indication(tech_pvt->session, SWITCH_MESSAGE_INDICATE_RINGING);                                  char *callid = woomera_message_header(&wmsg, "Unique-Call-Id");
1925  //                              switch_channel_mark_ring_ready(channel);                                  if (callid)
1926                                  switch_channel_mark_pre_answered(channel);                                  {
1927                                            switch_copy_string(tech_pvt->call_info.callid, callid, sizeof(wmsg.callid));
1928                                            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "OUTBOUND CallID:%s\n", tech_pvt->call_info.callid);
1929                                    }
1930    //                              switch_channel_mark_pre_answered(channel);
1931    
1932                          } else if (!strcasecmp(wmsg.command, "RING")) {                          } else if (!strcasecmp(wmsg.command, "RING")) {
1933                                  switch_channel_mark_ring_ready(channel);  //                              switch_channel_mark_ring_ready(channel);
1934    
1935                          } else if (!strcasecmp(wmsg.command, "CONNECT")) {                          } else if (!strcasecmp(wmsg.command, "CONNECT")) {
1936    
# Line 2014  Line 1939 
1939                                          switch_channel_set_variable(channel, "CONNECTIONTYPE", connection_type);                                          switch_channel_set_variable(channel, "CONNECTIONTYPE", connection_type);
1940                                          /* TODO Signal to API? */                                          /* TODO Signal to API? */
1941                                  }                                  }
1942                                    switch_set_flag_locked(tech_pvt, TFLAG_CONNECTED);
1943                                  switch_channel_mark_answered(channel);                                  switch_channel_mark_answered(channel);
1944    
1945                          } else if (!strcasecmp(wmsg.command, "MEDIA")) {                          } else if (!strcasecmp(wmsg.command, "MEDIA")) {
# Line 2237  Line 2163 
2163                                  }                                  }
2164                          }                          }
2165                  }                  }
                 /*  
                 if (globals.debug > 2) {  
                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Main Thread {%s} Select Return %d\n", profile->name, res);  
                 }  
                 */  
2166                  switch_yield(100);                  switch_yield(100);
2167          }          }
2168    

Legend:
Removed from v.810  
changed lines
  Added in v.811

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.8