[server] / trunk / server / src / confpartydevice.cxx Repository:
ViewVC logotype

View of /trunk/server/src/confpartydevice.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 959 - (download) (annotate)
Tue Oct 26 16:20:50 2010 UTC (2 years, 6 months ago) by jtarlton
File size: 12025 byte(s)
Regenerate caption after bridging external ipm device to a conf channel.
    1 /*
    2  * This file is part of Dialogic DiaStar Server project.
    3  *
    4  * More information about this project can be found at:
    5  * http://www.projectdiastar.org.
    6  *
    7  * Copyright (C) 2010 Dialogic Corp.
    8  *
    9  * This program is free software; you can redistribute it and/or
   10  * modify it under the terms of the GNU General Public License
   11  * as published by the Free Software Foundation; either version 2
   12  * of the License, or (at your option) any later version.
   13  *
   14  * This program is distributed in the hope that it will be useful,
   15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17  * GNU General Public License for more details.
   18  *
   19  * You should have received a copy of the GNU General Public License
   20  * along with this program; if not, write to the Free Software
   21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   22  * 02110-1301, USA.
   23  * Alternatively see <http://www.gnu.org/licenses/>.
   24  * Or see the LICENSE file included within the source tree.
   25  *
   26  */
   27 
   28 /*!
   29  * \file        confpartydevice.cxx
   30  * \brief       Conference party device
   31  * \author      John Tarlton <john.tarlton@dialogic.com>
   32  * \version     15-JAN-2010
   33  */
   34 
   35 /*-------------------------------- Dependencies ------------------------------*/
   36 
   37 #include <string.h>
   38 #include "cnfevts.h"
   39 #include "devmgmt.h"
   40 
   41 #include "logger.h"
   42 
   43 #include "confpartydevice.h"
   44 #include "confboard.h"
   45 
   46 /*----------------------------------------------------------------------------*/
   47 
   48 /*
   49  * ctor
   50  */
   51 ConfPartyDevice::ConfPartyDevice( const std::string& name,
   52                                   ConfBoard& confBoard,
   53                                   DialogicChannelManager& channelMgr )
   54    : DialogicDevice(name, channelMgr),
   55      confBoard_ (confBoard),
   56      busy_ (false),
   57      agc_ (true),
   58      ec_ (true),
   59      role_ (ConfPartyDevice::PRESENTER),
   60      position_ (0)
   61 {
   62 }
   63 
   64 
   65 /*
   66  * dtor, close the device.
   67  */
   68 ConfPartyDevice::~ConfPartyDevice()
   69 {
   70   close();
   71 }
   72 
   73 
   74 /*
   75  * Process a command that was queued because an async operation was in progress
   76  * when it was initially requested.
   77  */
   78 void ConfPartyDevice::processPendingCommand()
   79 {
   80   while ( !busy_ && !pending_.empty() )
   81   {
   82     switch( pending_.front().cmd )
   83     {
   84       case ConfPartyCommand::CONNECT:
   85         connect(pending_.front().other.audio, pending_.front().other.video);
   86         break;
   87 
   88       case ConfPartyCommand::DISCONNECT:
   89         disconnect();
   90         break;
   91 
   92       default:
   93         break;
   94     }
   95     pending_.pop();
   96   }
   97 }
   98 
   99 
  100 /*
  101  * Open conference party device.
  102  */
  103 bool ConfPartyDevice::open()
  104 {
  105   SRL_DEVICE_HANDLE res = cnf_OpenParty(confBoard_.getBoardHandle(), 0, 0, this);
  106   if ( res == CNF_ERROR )
  107   {
  108     LOGERROR("ConfPartyDevice::open() failed on device: " << getDeviceName());
  109     return false;
  110   }
  111   devHandle_ = res;
  112   LOGDEBUG("ConfPartyDevice::open() device: " << getDeviceName());
  113   return true;
  114 }
  115 
  116 
  117 /*
  118  * Close the conference party device.
  119  */
  120 bool ConfPartyDevice::close()
  121 {
  122   if ( devHandle_ != -1 )
  123   {
  124     if ( cnf_CloseParty(devHandle_, 0) == CNF_ERROR )
  125     {
  126       LOGERROR("ConfPartyDevice::close() failed on device: " << getDeviceName());
  127       return false;
  128     }
  129     LOGDEBUG("ConfPartyDevice::close() device: " << getDeviceName());
  130     devHandle_ = -1;
  131   }
  132   return true;
  133 }
  134 
  135 
  136 /*
  137  * Connect media.
  138  */
  139 bool ConfPartyDevice::connect( DialogicDevice* other_audio,
  140                                DialogicDevice* other_video )
  141 {
  142   if ( busy_ )
  143   {
  144     pending_.push(ConfPartyCommand(ConfPartyCommand::CONNECT, other_audio, other_video));
  145     return true;
  146   }
  147 
  148   bool transcode_audio = true;
  149     bool transcode_video = true;
  150 
  151   if ( !other_audio_ && !other_video_ )
  152   {
  153     LOGDEBUG("ConfPartyDevice::connect() device: " << getDeviceName() <<
  154              " other_audio: " << (other_audio ? other_audio->getDeviceName() : "n/a") <<
  155              " other_video: " << (other_video ? other_video->getDeviceName() : "n/a"));
  156 
  157     DM_PORT_CONNECT_INFO_LIST portConnectInfoList;
  158     INIT_DM_PORT_CONNECT_INFO_LIST(&portConnectInfoList);
  159 
  160     int count = 0;
  161 
  162     if ( other_audio )
  163     {
  164       INIT_DM_PORT_CONNECT_INFO(&portConnectInfoList.port_connect_info[count]);
  165       portConnectInfoList.port_connect_info[count].unFlags = transcode_audio ? DMFL_TRANSCODE_ON : DMFL_TRANSCODE_NATIVE;
  166       portConnectInfoList.port_connect_info[count].port_info_tx = getAudioTxPortInfo();
  167       portConnectInfoList.port_connect_info[count].port_info_rx = other_audio->getAudioRxPortInfo();
  168       count++;
  169     }
  170     if ( other_video )
  171     {
  172       INIT_DM_PORT_CONNECT_INFO(&portConnectInfoList.port_connect_info[count]);
  173       portConnectInfoList.port_connect_info[count].unFlags = transcode_video ? DMFL_TRANSCODE_ON : DMFL_TRANSCODE_NATIVE;
  174       portConnectInfoList.port_connect_info[count].port_info_tx = getVideoTxPortInfo();
  175       portConnectInfoList.port_connect_info[count].port_info_rx = other_video->getVideoRxPortInfo();
  176       count++;
  177     }
  178 
  179     portConnectInfoList.unCount = count;;
  180     if ( dev_PortConnect(devHandle_, &portConnectInfoList, NULL) != DEV_SUCCESS )
  181     {
  182       LOGERROR("ConfPartyDevice::connect() dev_PortConnect() failed on device: " <<
  183                getDeviceName() << " " << ATDV_ERRMSGP(devHandle_));
  184       return false;
  185     }
  186 
  187     other_audio_ = other_audio;
  188     other_video_ = other_video;
  189     busy_ = true;
  190   }
  191   else
  192   {
  193     LOGERROR("ConfPartyDevice::connect() device: " << getDeviceName() << " already connected"
  194              ", other_audio: " << (other_audio_ ? other_audio_->getDeviceName() : "n/a") <<
  195              ", other_video: " << (other_video_ ? other_video_->getDeviceName() : "n/a"));
  196     return false;
  197    }
  198    return true;
  199 }
  200 
  201 
  202 /*
  203  * Disconnect media.
  204  */
  205 bool ConfPartyDevice::disconnect()
  206 {
  207   if ( busy_ )
  208   {
  209     pending_.push(ConfPartyCommand(ConfPartyCommand::DISCONNECT));
  210     return true;
  211   }
  212 
  213   if ( other_audio_ || other_video_ )
  214   {
  215     LOGDEBUG("ConfPartyDevice::disconnect() device: " << getDeviceName() <<
  216              " other_audio: " << (other_audio_ ? other_audio_->getDeviceName() : "n/a") <<
  217              " other_video: " << (other_video_ ? other_video_->getDeviceName() : "n/a"));
  218 
  219     DM_PORT_CONNECT_INFO_LIST portConnectInfoList;
  220     INIT_DM_PORT_CONNECT_INFO_LIST(&portConnectInfoList);
  221     int count = 0;
  222 
  223     if ( other_audio_ )
  224     {
  225       INIT_DM_PORT_CONNECT_INFO(&portConnectInfoList.port_connect_info[count]);
  226       portConnectInfoList.port_connect_info[count].port_info_tx = getAudioTxPortInfo();
  227       portConnectInfoList.port_connect_info[count].port_info_rx = other_audio_->getAudioRxPortInfo();
  228       count++;
  229     }
  230     if ( other_video_ )
  231     {
  232       INIT_DM_PORT_CONNECT_INFO(&portConnectInfoList.port_connect_info[count]);
  233       portConnectInfoList.port_connect_info[count].port_info_tx = getVideoTxPortInfo();
  234       portConnectInfoList.port_connect_info[count].port_info_rx = other_video_->getVideoRxPortInfo();
  235       count++;
  236     }
  237     portConnectInfoList.unCount = count;
  238     if ( dev_PortDisconnect(devHandle_, &portConnectInfoList, NULL) != DEV_SUCCESS )
  239     {
  240       LOGERROR("ConfPartyDevice::disconnect() dev_PortDisconnect() failed on device: " <<
  241                getDeviceName() << " " << ATDV_ERRMSGP(devHandle_));
  242       return false;
  243     }
  244 
  245     other_audio_ = 0;
  246     other_video_ = 0;
  247     busy_ = true;
  248   }
  249   return true;
  250 }
  251 
  252 
  253 /*
  254  * Process an event
  255  */
  256 bool ConfPartyDevice::processEvent( METAEVENT& metaevent )
  257 {
  258   switch ( metaevent.evttype )
  259   {
  260     case CNFEV_OPEN_PARTY:
  261       onOpenParty(metaevent);
  262       break;
  263 
  264     case CNFEV_OPEN_PARTY_FAIL:
  265       LOGERROR("CNFEV_OPEN_PARTY_FAIL");
  266       close();
  267       break;
  268 
  269     case CNFEV_ERROR:
  270       LOGERROR("CNFEV_ERROR");
  271       break;
  272 
  273     case CNFEV_SET_ATTRIBUTE:
  274       break;
  275 
  276     case CNFEV_SET_ATTRIBUTE_FAIL:
  277       LOGERROR("ConfPartyDevice::processEvent() CNFEV_SET_ATTRIBUTE_FAIL on device: " << getDeviceName());
  278       break;
  279 
  280     case DMEV_GET_RX_PORT_INFO:
  281       onGetRxPortInfo(static_cast<DM_PORT_INFO_LIST*>(sr_getevtdatap()));
  282       break;
  283 
  284     case DMEV_GET_RX_PORT_INFO_FAIL:
  285       LOGERROR("DMEV_GET_RX_PORT_INFO_FAIL");
  286       break;
  287 
  288     case DMEV_GET_TX_PORT_INFO:
  289       onGetTxPortInfo(static_cast<DM_PORT_INFO_LIST*>(sr_getevtdatap()));
  290       break;
  291 
  292     case DMEV_GET_TX_PORT_INFO_FAIL:
  293       LOGERROR("DMEV_GET_TX_PORT_INFO_FAIL");
  294       break;
  295 
  296     case DMEV_PORT_CONNECT:
  297       onPortConnect();
  298       break;
  299 
  300     case DMEV_PORT_CONNECT_FAIL:
  301       onPortConnectFail();
  302       break;
  303 
  304     case DMEV_PORT_DISCONNECT:
  305       onPortDisconnect();
  306       break;
  307 
  308     case DMEV_PORT_DISCONNECT_FAIL:
  309       onPortDisconnectFail();
  310       break;
  311 
  312     default:
  313       LOGWARN("ConfPartyDevice::processEvent() unhandled event:" << std::hex << metaevent.evttype);
  314       break;
  315   }
  316   return true;
  317 }
  318 
  319 
  320 /*
  321  *  Handle a CNFEV_OPEN_PARTY event.
  322  */
  323 void ConfPartyDevice::onOpenParty( METAEVENT& metaevent )
  324 {
  325   LOGINFO("ConfPartyDevice::onOpenParty() device: " << getDeviceName() << ", " << ATDV_NAMEP(devHandle_));
  326 
  327   /* Request port info
  328    */
  329   if ( dev_GetTransmitPortInfo(devHandle_, this) == -1 )
  330   {
  331     LOGERROR("dev_GetTransmitPortInfo() failed");
  332   }
  333   if ( dev_GetReceivePortInfo(devHandle_, this) == -1 )
  334   {
  335     LOGERROR("dev_GetReceivePortInfo() failed");
  336   }
  337 
  338   /* make available */
  339   confBoard_.freePartyDevice(this);
  340 
  341   setDeviceName(ATDV_NAMEP(devHandle_));
  342   channelMgr_.addDevice(this);
  343 
  344   CNF_ATTR attrs[10];
  345   memset(&attrs, 0, sizeof(CNF_ATTR));
  346 
  347   attrs[0].unVersion = CNF_ATTR_VERSION_0;
  348   attrs[0].unAttribute = ECNF_PARTY_ATTR_AGC;
  349   attrs[0].unValue = agc_ ? ECNF_ATTR_STATE_ENABLED : ECNF_ATTR_STATE_DISABLED;
  350 
  351   attrs[1].unVersion = CNF_ATTR_VERSION_0;
  352   attrs[1].unAttribute = ECNF_PARTY_ATTR_ECHO_CANCEL;
  353   attrs[1].unValue = ec_ ? ECNF_ATTR_STATE_ENABLED : ECNF_ATTR_STATE_DISABLED;
  354 
  355   CNF_ATTR_INFO attrInfo;
  356   memset(&attrInfo, 0, sizeof(CNF_ATTR_INFO));
  357 
  358   attrInfo.unVersion = CNF_ATTR_INFO_VERSION_0;
  359   attrInfo.unAttrCount = 2;
  360   attrInfo.pAttrList = attrs;
  361 
  362   if ( cnf_SetAttributes(getDeviceHandle(), &attrInfo, NULL) == CNF_ERROR )
  363   {
  364     LOGERROR("ConfPartyDevice::onOpenParty() cnf_SetAttributes() failed on device: " << getDeviceName());
  365   }
  366 }
  367 
  368 
  369 /*
  370  * Handler for DMEV_GET_TX_PORT_INFO events.
  371  */
  372 void ConfPartyDevice::onGetTxPortInfo( DM_PORT_INFO_LIST* portInfoList )
  373 {
  374   LOGINFO("ConfPartyDevice::onGetTxPortInfo() device: " << getDeviceName());
  375 
  376   txPortInfoList_ = *portInfoList;
  377   LOGDEBUG(std::endl << txPortInfoList_);
  378 
  379   for ( unsigned int i = 0; i < txPortInfoList_.unCount; i++ )
  380   {
  381     switch ( txPortInfoList_.port_info[i].port_media_type )
  382     {
  383       case DM_PORT_MEDIA_TYPE_AUDIO:
  384         audioPortTxInfo_ = txPortInfoList_.port_info[i];
  385         break;
  386 
  387       case DM_PORT_MEDIA_TYPE_VIDEO:
  388         videoPortTxInfo_ = txPortInfoList_.port_info[i];
  389         break;
  390 
  391       default:
  392         break;
  393     }
  394   }
  395 }
  396 
  397 
  398 /*
  399  * Handler for DMEV_GET_RX_PORT_INFO events.
  400  */
  401 void ConfPartyDevice::onGetRxPortInfo( DM_PORT_INFO_LIST* portInfoList )
  402 {
  403   LOGINFO("ConfPartyDevice::onGetRxPortInfo() device: " << getDeviceName());
  404 
  405   rxPortInfoList_ = *portInfoList;
  406   LOGDEBUG(std::endl << rxPortInfoList_);
  407 
  408   for ( unsigned int i = 0; i < rxPortInfoList_.unCount; i++ )
  409   {
  410     switch ( rxPortInfoList_.port_info[i].port_media_type )
  411     {
  412       case DM_PORT_MEDIA_TYPE_AUDIO:
  413         audioPortRxInfo_ = rxPortInfoList_.port_info[i];
  414         break;
  415 
  416       case DM_PORT_MEDIA_TYPE_VIDEO:
  417         videoPortRxInfo_ = rxPortInfoList_.port_info[i];
  418         break;
  419 
  420       default:
  421         break;
  422     }
  423   }
  424 }
  425 
  426 
  427 /*
  428  * Handle DMEV_PORT_CONNECT event.
  429  */
  430 void ConfPartyDevice::onPortConnect()
  431 {
  432   LOGINFO("ConfPartyDevice::onPortConnect() device: " << getDeviceName());
  433 
  434   if ( channel_ )
  435   {
  436     channel_->onConnectCompleted(this);
  437   }
  438   busy_ = false;
  439   processPendingCommand();
  440 }
  441 
  442 
  443 /*
  444  * Handle DMEV_PORT_CONNECT_FAIL event.
  445  */
  446 void ConfPartyDevice::onPortConnectFail()
  447 {
  448   LOGWARN("ConfPartyDevice::onPortConnectFail() device: " << getDeviceName());
  449   busy_ = false;
  450   processPendingCommand();
  451 }
  452 
  453 
  454 /*
  455  * Handle DMEV_PORT_DISCONNECT event.
  456  */
  457 void ConfPartyDevice::onPortDisconnect()
  458 {
  459   LOGINFO("ConfPartyDevice::onPortDisconnect() device: " << getDeviceName());
  460 
  461   if ( channel_ )
  462   {
  463     channel_->onDisconnectCompleted(this);
  464   }
  465   busy_ = false;
  466   processPendingCommand();
  467 }
  468 
  469 
  470 /*
  471  * Handle DMEV_PORT_DISCONNECT_FAIL event.
  472  */
  473 void ConfPartyDevice::onPortDisconnectFail()
  474 {
  475   LOGWARN("ConfPartyDevice::onPortDisconnectFail() device: " << getDeviceName());
  476   busy_ = false;
  477   processPendingCommand();
  478 }
  479 
  480 
  481 /* vim:ts=4:set nu:
  482  * EOF
  483  */

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