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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 400 - (download) (annotate)
Tue Sep 15 13:24:29 2009 UTC (3 years, 8 months ago) by jtarlton
File size: 20680 byte(s)
basic recording
    1 /*
    2  * This file is part of Project DiaStar Server.
    3  *
    4  * More information about this project can be found at:
    5  * http://www.projectdiastar.org.
    6  *
    7  * Copyright (C) 2009 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        mmdevice.cxx
   30  * \brief       Dialogic Multimedia device
   31  * \author      Antony Martin <antony.martin@dialogic.com>
   32  * \author      John Tarlton <john.tarlton@dialogic.com>
   33  * \version     19-AUG-2009
   34  */
   35 
   36 /*------------------------------ Dependencies --------------------------------*/
   37 
   38 #include <srllib.h>
   39 #include <dxxxlib.h>
   40 
   41 #include "logger.h"
   42 
   43 #include "dialogicchannelmanager.h"
   44 #include "mmdevice.h"
   45 
   46 /*----------------------------------------------------------------------------*/
   47 
   48 /*
   49  * ctor
   50  */
   51 MmDevice::MmDevice( const std::string& name,
   52                       DialogicChannelManager& channelMgr )
   53   : DialogicDevice(name, channelMgr),
   54     playActive_ (false),
   55     recordActive_ (false),
   56     mediaIsMpeg4_ (false),
   57     mediaIsCif_ (false)
   58 {
   59 
   60 }
   61 
   62 
   63 /*
   64  * Open the device.
   65  */
   66 bool MmDevice::open()
   67 {
   68   LOGDEBUG("MmDevice::open() device: " << devName_);
   69   devHandle_ = mm_Open(devName_.c_str(), 0, NULL);
   70   if ( devHandle_ == EMM_ERROR )
   71   {
   72     LOGERROR("mm_Open() failed");
   73     return false;
   74   }
   75   return true;
   76 }
   77 
   78 
   79 /*
   80  * Close the device.
   81  */
   82 bool MmDevice::close()
   83 {
   84   LOGDEBUG("MmDevice::close() device: " << devName_);
   85   if ( devHandle_ > 0 )
   86   {
   87     if ( mm_Close(devHandle_, NULL) == EMM_ERROR )
   88     {
   89       LOGERROR("mm_Close() failed");
   90       return false;
   91     }
   92     devHandle_ = 0;
   93   }
   94   return true;
   95 }
   96 
   97 
   98 /*
   99  * Connect media.
  100  */
  101 bool MmDevice::listen( DialogicDevice* other )
  102 {
  103   LOGDEBUG("MmDevice::listen() device: " << devName_ <<
  104            " other: " << other->getDeviceName());
  105 
  106   if ( listening_ != other )
  107   {
  108     DM_PORT_CONNECT_INFO_LIST portConnectInfoList;
  109     INIT_DM_PORT_CONNECT_INFO_LIST(&portConnectInfoList);
  110 
  111     int count = 0;
  112 
  113     INIT_DM_PORT_CONNECT_INFO(&portConnectInfoList.port_connect_info[count]);
  114     portConnectInfoList.port_connect_info[count].unFlags = DMFL_TRANSCODE_ON;
  115     portConnectInfoList.port_connect_info[count].port_info_tx = getAudioTxPortInfo();
  116     portConnectInfoList.port_connect_info[count].port_info_rx = ((IpmDevice*)other)->getAudioRxPortInfo(); //XXX
  117     count++;
  118 
  119     INIT_DM_PORT_CONNECT_INFO(&portConnectInfoList.port_connect_info[count]);
  120     portConnectInfoList.port_connect_info[count].unFlags = DMFL_TRANSCODE_ON;
  121     portConnectInfoList.port_connect_info[count].port_info_tx = getVideoTxPortInfo();
  122     portConnectInfoList.port_connect_info[count].port_info_rx = ((IpmDevice*)other)->getVideoRxPortInfo(); //XXX
  123     count++;
  124 
  125     portConnectInfoList.unCount = count;;
  126     if ( dev_PortConnect(devHandle_, &portConnectInfoList, NULL) != DEV_SUCCESS )
  127     {
  128       LOGERROR("dev_PortConnect() failed on device: " << devName_ <<
  129                " " << ATDV_ERRMSGP(devHandle_));
  130       return false;
  131     }
  132 
  133     listening_ = other;
  134   }
  135   return true;
  136 }
  137 
  138 
  139 /*
  140  * Disconnect media.
  141  */
  142 bool MmDevice::unListen()
  143 {
  144   LOGDEBUG("MmDevice::unListen() device: " << devName_);
  145 
  146   if ( listening_ )
  147   {
  148     DM_PORT_CONNECT_INFO_LIST portConnectInfoList;
  149     INIT_DM_PORT_CONNECT_INFO_LIST(&portConnectInfoList);
  150     int count = 0;
  151 
  152     INIT_DM_PORT_CONNECT_INFO(&portConnectInfoList.port_connect_info[count]);
  153     portConnectInfoList.port_connect_info[count].port_info_tx = getAudioTxPortInfo();
  154     portConnectInfoList.port_connect_info[count].port_info_rx = ((IpmDevice*)listening_)->getAudioRxPortInfo(); //XXX
  155     count++;
  156 
  157     INIT_DM_PORT_CONNECT_INFO(&portConnectInfoList.port_connect_info[count]);
  158     portConnectInfoList.port_connect_info[count].port_info_tx = getVideoTxPortInfo();
  159     portConnectInfoList.port_connect_info[count].port_info_rx = ((IpmDevice*)listening_)->getVideoRxPortInfo(); //XXX
  160     count++;
  161 
  162     portConnectInfoList.unCount = count;
  163     if ( dev_PortDisconnect(devHandle_, &portConnectInfoList, NULL) != DEV_SUCCESS )
  164     {
  165       LOGERROR("dev_PortDisconnect() failed on device: " << devName_ <<
  166                " " << ATDV_ERRMSGP(devHandle_));
  167       return false;
  168     }
  169 
  170     listening_ = 0;
  171   }
  172   return true;
  173 }
  174 
  175 
  176 /*
  177  * handle events from Dialogic apiS
  178  */
  179 bool MmDevice::processEvent( METAEVENT& metaevent )
  180 {
  181   long evttype = metaevent.evttype;
  182 
  183   switch ( evttype )
  184   {
  185     case MMEV_OPEN:
  186       onOpen();
  187       break;
  188 
  189     case MMEV_PLAY: /* mm_Play() completed successfully */
  190       onPlay();
  191       break;
  192 
  193     case MMEV_PLAY_ACK: /* mm_Play() started successfully */
  194       LOGDEBUG("MmDevice::processEvent() MMEV_PLAY_ACK device: " << devName_);
  195       break;
  196 
  197     case MMEV_PLAY_FAIL:
  198       onPlayFail();
  199       break;
  200 
  201     case MMEV_PLAY_ACK_FAIL:
  202       onPlayAckFail();
  203       break;
  204 
  205     case MMEV_RECORD:
  206       onRecord();
  207       break;
  208 
  209     case MMEV_RECORD_ACK:
  210       LOGDEBUG("MmDevice::processEvent() MMEV_RECORD_ACK device: " << devName_);
  211       break;
  212 
  213     case MMEV_RECORD_FAIL:
  214       onRecordFail();
  215       break;
  216 
  217     case MMEV_RECORD_ACK_FAIL:
  218       LOGDEBUG("MmDevice::processEvent() MMEV_RECORD_ACK_FAIL device: " << devName_);
  219       break;
  220 
  221     case MMEV_VIDEO_RECORD_STARTED:
  222       LOGDEBUG("MmDevice::processEvent() MMEV_VIDEO_RECORD_STARTED device: " << devName_);
  223       break;
  224 
  225     case MMEV_VIDEO_RECORD_STARTED_FAIL:
  226       LOGDEBUG("MmDevice::processEvent() MMEV_VIDEO_RECORD_STARTED_FAIL device: " << devName_);
  227       onRecordFail();
  228       break;
  229 
  230     case MMEV_STOP_ACK:
  231       onStopAck();
  232       break;
  233 
  234     case MMEV_STOP_ACK_FAIL:
  235       onStopAckFail();
  236       break;
  237 
  238     case MMEV_RESET:
  239       onReset();
  240       break;
  241 
  242     case MMEV_ERROR:
  243       onError();
  244       break;
  245 
  246     case DMEV_PORT_CONNECT:
  247       break;
  248 
  249     case DMEV_PORT_CONNECT_FAIL:
  250       break;
  251 
  252     case DMEV_PORT_DISCONNECT:
  253       break;
  254 
  255     case DMEV_PORT_DISCONNECT_FAIL:
  256       break;
  257 
  258     case DMEV_GET_TX_PORT_INFO:
  259       onGetTxPortInfo((DM_PORT_INFO_LIST*)sr_getevtdatap());
  260       break;
  261 
  262     case DMEV_GET_RX_PORT_INFO:
  263       onGetRxPortInfo((DM_PORT_INFO_LIST*)sr_getevtdatap());
  264       break;
  265 
  266     default:
  267       LOGDEBUG("MmDevice::processEvent() Unhandled event: " <<
  268                std::hex << evttype << " " << ATDV_NAMEP(sr_getevtdev()));
  269       break;
  270   }
  271   return true;
  272 }
  273 
  274 
  275 /*
  276  * Handle MMEV_OPEN event.
  277  */
  278 void MmDevice::onOpen()
  279 {
  280   LOGDEBUG("MmDevice::processEvent() MMEV_OPEN device: " << devName_);
  281 
  282   /* Request port info
  283    */
  284   if ( dev_GetTransmitPortInfo(devHandle_, this) == -1 )
  285   {
  286     LOGERROR("dev_GetTransmitPortInfo() failed");
  287   }
  288   if ( dev_GetReceivePortInfo(devHandle_, this) == -1 )
  289   {
  290     LOGERROR("dev_GetReceivePortInfo() failed");
  291   }
  292 }
  293 
  294 
  295 /*
  296  * Handle MMEV_PLAY event.
  297  */
  298 void MmDevice::onPlay()
  299 {
  300   LOGINFO("MmDevice::onPlay() device: " << devName_);
  301   playActive_ = false;
  302   channelMgr_.onPlayCompleted(this);
  303 }
  304 
  305 
  306 /*
  307  * Handle MMEV_PLAY_ACK_FAIL event.
  308  */
  309 void MmDevice::onPlayAckFail()
  310 {
  311   LOGWARN("MmDevice::onPlayAckFail() device: " << devName_);
  312   playActive_ = false;
  313 }
  314 
  315 
  316 /*
  317  * Handle MMEV_PLAY_FAIL event.
  318  */
  319 void MmDevice::onPlayFail()
  320 {
  321   LOGWARN("MmDevice::onPlayFail() device: " << devName_);
  322   playActive_ = false;
  323   channelMgr_.onPlayCompleted(this);
  324 }
  325 
  326 
  327 /*
  328  * Handle MMEV_RECORD event.
  329  */
  330 void MmDevice::onRecord()
  331 {
  332   LOGINFO("MmDevice::onRecord() device: " << devName_);
  333   channelMgr_.onRecordCompleted(this);
  334 }
  335 
  336 
  337 /*
  338  * Handle MMEV_RECORD_FAIL event.
  339  */
  340 void MmDevice::onRecordFail()
  341 {
  342   LOGWARN("MmDevice::onRecordFail() device: " << devName_);
  343   recordActive_ = false;
  344   channelMgr_.onRecordCompleted(this);
  345 }
  346 
  347 
  348 /*
  349  * Handle MMEV_STOP_ACK event.
  350  */
  351 void MmDevice::onStopAck()
  352 {
  353   LOGINFO("MmDevice::onStopAck() device: " << devName_);
  354 }
  355 
  356 
  357 /*
  358  * Handle MMEV_STOP_ACK_FAIL event.
  359  */
  360 void MmDevice::onStopAckFail()
  361 {
  362   LOGWARN("MmDevice::onStopAckFail() device: " << devName_);
  363 }
  364 
  365 
  366 /*
  367  * Handle MMEV_RESET event.
  368  */
  369 void MmDevice::onReset()
  370 {
  371   LOGINFO("MmDevice::onReset() device: " << devName_);
  372 }
  373 
  374 
  375 /*
  376  * Handle MMEV_ERROR event.
  377  */
  378 void MmDevice::onError()
  379 {
  380   LOGINFO("MmDevice::onError() device: " << devName_);
  381 }
  382 
  383 
  384 /*
  385  * Handler for DMEV_GET_TX_PORT_INFO events.
  386  */
  387 void MmDevice::onGetTxPortInfo(DM_PORT_INFO_LIST* portInfoList )
  388 {
  389   LOGINFO("MmDevice::onGetTxPortInfo() device: " << devName_);
  390 
  391   txPortInfoList_ = *portInfoList;
  392   printPortInfo(&txPortInfoList_);
  393 
  394   for ( unsigned int i = 0; i < txPortInfoList_.unCount; i++ )
  395   {
  396     switch ( txPortInfoList_.port_info[i].port_media_type )
  397     {
  398       case DM_PORT_MEDIA_TYPE_AUDIO:
  399         memcpy(&audioPortTxInfo_, &txPortInfoList_.port_info[i], sizeof(DM_PORT_INFO));
  400         break;
  401 
  402       case DM_PORT_MEDIA_TYPE_VIDEO:
  403         memcpy(&videoPortTxInfo_, &txPortInfoList_.port_info[i], sizeof(DM_PORT_INFO));
  404         break;
  405 
  406       default:
  407         break;
  408     }
  409   }
  410 }
  411 
  412 
  413 /*
  414  * Handler for DMEV_GET_RX_PORT_INFO events.
  415  */
  416 void MmDevice::onGetRxPortInfo(DM_PORT_INFO_LIST* portInfoList )
  417 {
  418   LOGINFO("MmDevice::onGetRxPortInfo() device: " << devName_);
  419 
  420   rxPortInfoList_ = *portInfoList;
  421   printPortInfo(&rxPortInfoList_);
  422 
  423   for ( unsigned int i = 0; i < rxPortInfoList_.unCount; i++ )
  424   {
  425     switch ( rxPortInfoList_.port_info[i].port_media_type )
  426     {
  427       case DM_PORT_MEDIA_TYPE_AUDIO:
  428         memcpy(&audioPortRxInfo_, &rxPortInfoList_.port_info[i], sizeof(DM_PORT_INFO));
  429         break;
  430 
  431       case DM_PORT_MEDIA_TYPE_VIDEO:
  432         memcpy(&videoPortRxInfo_, &rxPortInfoList_.port_info[i], sizeof(DM_PORT_INFO));
  433         break;
  434 
  435       default:
  436         break;
  437     }
  438   }
  439 }
  440 
  441 
  442 /*
  443  * Debug aid.
  444  */
  445 void MmDevice::printPortInfo( DM_PORT_INFO_LIST* portInfo ) const
  446 {
  447   std::stringstream ss;
  448 
  449   for ( unsigned int i = 0; i < portInfo->unCount; i++ )
  450   {
  451     DM_PORT_INFO& info = portInfo->port_info[i];
  452     ss << "Port: " << i << " MediaType: " << info.port_media_type << " ";
  453     if ( info.port_media_type == DM_PORT_MEDIA_TYPE_AUDIO )
  454     {
  455       ss << "Audio";
  456     }
  457     else if ( info.port_media_type == DM_PORT_MEDIA_TYPE_VIDEO )
  458     {
  459       ss << "Video";
  460     }
  461     else if ( info.port_media_type == DM_PORT_MEDIA_TYPE_NBUP )
  462     {
  463       ss << "NBUP";
  464     }
  465     else
  466     {
  467       ss << info.port_media_type;
  468     }
  469     ss << std::endl;
  470   }
  471   LOGDEBUG(ss.str());
  472 }
  473 
  474 
  475 /*
  476  * Start playing.
  477  */
  478 bool MmDevice::play( const std::string& audioFile,
  479                      const std::string& videoFile )
  480 {
  481   LOGINFO("MmDevice::play()");
  482 
  483   MM_AUDIO_CODEC audioCodec;
  484   if ( videoFile.empty() )
  485   {
  486     INIT_MM_AUDIO_CODEC(&audioCodec);
  487     audioCodec.unCoding = MM_DATA_FORMAT_PCM;
  488     audioCodec.unSampleRate  = MM_DRT_8KHZ;
  489     audioCodec.unBitsPerSample = 16;
  490 
  491     INIT_MM_MEDIA_ITEM_LIST(&audioMediaList_);
  492     INIT_MM_MEDIA_AUDIO(&audioMediaList_.item.audio);
  493     audioMediaList_.ItemChain = EMM_ITEM_EOT;
  494     audioMediaList_.item.audio.szFileName = audioFile.c_str();
  495     audioMediaList_.item.audio.codec = audioCodec;
  496     audioMediaList_.item.audio.unMode = MM_MODE_AUD_FILE_TYPE_VOX;
  497     audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX;
  498     audioMediaList_.item.audio.unOffset = 0;
  499 
  500     INIT_MM_PLAY_RECORD_LIST(&playRecordList_[0]);
  501     playRecordList_[0].ItemType = EMM_MEDIA_TYPE_AUDIO;
  502     playRecordList_[0].list = &audioMediaList_;
  503     playRecordList_[0].ItemChain = EMM_ITEM_EOT;
  504 
  505     INIT_MM_PLAY_INFO(&playInfo_);
  506     playInfo_.eFileFormat = EMM_FILE_FORMAT_UNDEFINED;
  507     playInfo_.list = playRecordList_;
  508   }
  509   else
  510   {
  511     /* init audio
  512      */
  513     INIT_MM_AUDIO_CODEC(&audioCodec);
  514     audioCodec.unCoding = MM_DATA_FORMAT_PCM;
  515     audioCodec.unSampleRate = MM_DRT_8KHZ;
  516     audioCodec.unBitsPerSample = 16;
  517 
  518     INIT_MM_MEDIA_ITEM_LIST(&audioMediaList_);
  519     INIT_MM_MEDIA_AUDIO(&audioMediaList_.item.audio);
  520     audioMediaList_.ItemChain = EMM_ITEM_EOT;
  521     audioMediaList_.item.audio.szFileName = audioFile.c_str();
  522     audioMediaList_.item.audio.codec = audioCodec;
  523     audioMediaList_.item.audio.unMode = MM_MODE_AUD_FILE_TYPE_VOX;
  524     audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX;
  525     audioMediaList_.item.audio.unOffset = 0;
  526 
  527     /* init video
  528      */
  529     INIT_MM_MEDIA_ITEM_LIST(&videoMediaList_);
  530     INIT_MM_MEDIA_VIDEO(&videoMediaList_.item.video);
  531     videoMediaList_.ItemChain = EMM_ITEM_EOT;
  532     videoMediaList_.item.video.szFileName = videoFile.c_str();
  533 
  534     if ( mediaIsMpeg4_ )
  535     {
  536       if ( mediaIsCif_ )
  537       {
  538         LOGDEBUG("Using MPEG4 CIF Video clip");
  539         videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES;
  540         videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP3_MPEG4;
  541         videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352;
  542         videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_288;
  543         videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15;
  544       }
  545       else
  546       {
  547         LOGDEBUG("Using MPEG4 QCIF Video clip");
  548         videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES;
  549         videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP1_MPEG4;
  550         videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176;
  551         videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_144;
  552         videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15;
  553       }
  554     }
  555     else
  556     {
  557       if ( mediaIsCif_ )
  558       {
  559         LOGDEBUG("Using H.263 CIF Video clip");
  560         videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263;
  561         videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263;
  562         videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352;
  563         videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_288;
  564         videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15;
  565       }
  566       else
  567       {
  568         LOGDEBUG("Using H.263 QCIF Video clip");
  569         videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263;
  570         videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263;
  571         videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176;
  572         videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_144;
  573         videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_10;
  574       }
  575     }
  576 
  577     INIT_MM_PLAY_RECORD_LIST(&playRecordList_[0]);
  578     playRecordList_[0].ItemType = EMM_MEDIA_TYPE_AUDIO;
  579     playRecordList_[0].list = &audioMediaList_;
  580     playRecordList_[0].ItemChain = EMM_ITEM_CONT;
  581 
  582     INIT_MM_PLAY_RECORD_LIST(&playRecordList_[1]);
  583     playRecordList_[1].ItemType = EMM_MEDIA_TYPE_VIDEO;
  584     playRecordList_[1].list = &videoMediaList_;
  585     playRecordList_[1].ItemChain = EMM_ITEM_EOT;
  586 
  587     INIT_MM_PLAY_RECORD_INFO(&playInfo_);
  588     playInfo_.eFileFormat = EMM_FILE_FORMAT_UNDEFINED;
  589     playInfo_.list  = playRecordList_;
  590   }
  591 
  592   audioMediaList_.item.audio.szFileName = audioFile.c_str();
  593   videoMediaList_.item.video.szFileName = videoFile.c_str();
  594 
  595   LOGDEBUG("Playing: a=" << audioMediaList_.item.audio.szFileName <<
  596            ", v=" << videoMediaList_.item.video.szFileName);
  597   if ( mm_Play(devHandle_, &playInfo_, NULL, NULL) == EMM_ERROR )
  598   {
  599     LOGERROR("mm_Play() failed on device: " << getDeviceName());
  600     return false;
  601   }
  602   playActive_ = true;
  603   return true;
  604 }
  605 
  606 
  607 /*
  608  * Start recording.
  609  */
  610 bool MmDevice::record(const std::string& audioFile,
  611                       const std::string& videoFile )
  612 {
  613   LOGINFO("MmDevice::record()");
  614 
  615   /* init audio
  616    */
  617   MM_AUDIO_CODEC audioCodec;
  618   INIT_MM_AUDIO_CODEC(&audioCodec);
  619   audioCodec.unCoding = MM_DATA_FORMAT_PCM;
  620   audioCodec.unSampleRate = MM_DRT_8KHZ;
  621   audioCodec.unBitsPerSample = 16;
  622 
  623   INIT_MM_MEDIA_ITEM_LIST(&audioMediaList_);
  624   INIT_MM_MEDIA_AUDIO(&audioMediaList_.item.audio);
  625   audioMediaList_.ItemChain  = EMM_ITEM_EOT;
  626   audioMediaList_.item.audio.szFileName = audioFile.c_str();
  627   audioMediaList_.item.audio.codec = audioCodec;
  628   audioMediaList_.item.audio.unMode = MM_MODE_AUD_FILE_TYPE_VOX;
  629   audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX;
  630 
  631   /* init video
  632    */
  633   INIT_MM_MEDIA_ITEM_LIST(&videoMediaList_);
  634   INIT_MM_MEDIA_VIDEO(&videoMediaList_.item.video);
  635   if ( mediaIsMpeg4_ )
  636   {
  637     INIT_MM_MEDIA_ITEM_LIST(&videoMediaList_);
  638     INIT_MM_MEDIA_VIDEO(&videoMediaList_.item.video);
  639     if ( mediaIsCif_)
  640     {
  641       LOGDEBUG("Using MPEG4 CIF Video clip");
  642       videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES;
  643       videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP3_MPEG4;
  644       videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352;
  645       videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_288;
  646       videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15;
  647     }
  648     else
  649     {
  650       LOGDEBUG("Using MPEG4 QCIF Video clip");
  651       videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES;
  652       videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP1_MPEG4;
  653       videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176;
  654       videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_144;
  655       videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15;
  656     }
  657   }
  658   else
  659   {
  660     if ( mediaIsCif_ )
  661     {
  662       LOGDEBUG("Using H.263 CIF Video clip");
  663       videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263;
  664       videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263;
  665       videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352;
  666       videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_288;
  667       videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15;
  668     }
  669     else
  670     {
  671       LOGDEBUG("Using H.263 QCIF Video clip");
  672       videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263;
  673       videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263;
  674       videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176;
  675       videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_144;
  676       videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_10;
  677     }
  678   }
  679 
  680   videoMediaList_.ItemChain = EMM_ITEM_EOT;
  681   videoMediaList_.item.video.szFileName = videoFile.c_str();
  682   videoMediaList_.item.video.eFileFormat = EMM_FILE_FORMAT_PROPRIETARY;
  683   videoMediaList_.item.video.unMode = 0;
  684   videoMediaList_.item.video.unOffset = 0;
  685 
  686   INIT_MM_PLAY_RECORD_LIST(&playRecordList_[0]);
  687   playRecordList_[0].ItemType = EMM_MEDIA_TYPE_AUDIO;
  688   playRecordList_[0].list = &audioMediaList_;
  689   playRecordList_[0].ItemChain = EMM_ITEM_CONT;
  690 
  691   INIT_MM_PLAY_RECORD_LIST(&playRecordList_[1]);
  692   playRecordList_[1].ItemType = EMM_MEDIA_TYPE_VIDEO;
  693   playRecordList_[1].list = &videoMediaList_;
  694   playRecordList_[1].ItemChain = EMM_ITEM_EOT;
  695 
  696   INIT_MM_RECORD_INFO(&recordInfo_);
  697   recordInfo_.eFileFormat = EMM_FILE_FORMAT_UNDEFINED;
  698   recordInfo_.list = playRecordList_;
  699 
  700   // XXX sendIFrameRequest();
  701 
  702   LOGDEBUG("Recording: a=" << audioMediaList_.item.audio.szFileName <<
  703            ", v=" << videoMediaList_.item.video.szFileName);
  704   if ( mm_Record(devHandle_, &recordInfo_, NULL, 0) == EMM_ERROR )
  705   {
  706     LOGERROR("mm_Record() failed on device: " << getDeviceName());
  707     return false;
  708   }
  709 
  710   recordActive_ = true;
  711   return true;
  712 }
  713 
  714 
  715 /*
  716  * Stop current play.
  717  */
  718 bool MmDevice::stopPlay()
  719 {
  720   if ( playActive_ )
  721   {
  722     MM_STOP mmStopInfo[2];
  723     MM_STOP_DETAILS mmStopDetails;
  724     memset(&mmStopDetails, 0, sizeof(MM_STOP_DETAILS));
  725 
  726     mmStopInfo[0].unVersion = 0;
  727     mmStopInfo[0].ItemChain = EMM_ITEM_CONT;
  728     mmStopInfo[0].ItemType = EMM_STOP_VIDEO_PLAY;
  729     mmStopInfo[0].details = mmStopDetails;
  730     mmStopInfo[0].next = &mmStopInfo[1];
  731 
  732     mmStopInfo[1].unVersion = 0;
  733     mmStopInfo[1].ItemChain = EMM_ITEM_EOT;
  734     mmStopInfo[1].ItemType = EMM_STOP_AUDIO_PLAY;
  735     mmStopInfo[1].details = mmStopDetails;
  736     mmStopInfo[1].next = NULL;
  737 
  738     if ( mm_Stop(devHandle_, mmStopInfo, NULL) == EMM_ERROR )
  739     {
  740       LOGERROR("mm_Stop() failed on device: " << getDeviceName());
  741       return false;
  742     }
  743     playActive_= false;
  744   }
  745   return true;
  746 }
  747 
  748 
  749 /*
  750  * Stop current recording.
  751  */
  752 bool MmDevice::stopRecord()
  753 {
  754   LOGDEBUG("MmDevice::stopRecord() device: " << getDeviceName());
  755 
  756   if ( recordActive_ )
  757   {
  758     MM_STOP mmStopInfo[2];
  759     MM_STOP_DETAILS mmStopDetails;
  760     memset(&mmStopDetails, 0, sizeof(MM_STOP_DETAILS));
  761 
  762     mmStopInfo[0].unVersion = 0;
  763     mmStopInfo[0].ItemChain = EMM_ITEM_CONT;
  764     mmStopInfo[0].ItemType = EMM_STOP_VIDEO_RECORD;
  765     mmStopInfo[0].details = mmStopDetails;
  766     mmStopInfo[0].next = &mmStopInfo[1];
  767 
  768     mmStopInfo[1].unVersion = 0;
  769     mmStopInfo[1].ItemChain = EMM_ITEM_EOT;
  770     mmStopInfo[1].ItemType = EMM_STOP_AUDIO_RECORD;
  771     mmStopInfo[1].details = mmStopDetails;
  772     mmStopInfo[1].next = NULL;
  773 
  774     if ( mm_Stop(devHandle_, mmStopInfo, 0) == EMM_ERROR )
  775     {
  776       LOGERROR("mm_Stop() failed on device: " << getDeviceName());
  777       return false;
  778     }
  779     recordActive_ = false;
  780   }
  781   return true;
  782 }
  783 
  784 
  785 /* vim:ts=4:set nu:
  786  * EOF
  787  */

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