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

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

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

revision 656, Mon Mar 29 15:56:12 2010 UTC revision 657, Mon Mar 29 15:57:09 2010 UTC
# Line 35  Line 35 
35    
36  /*------------------------------ Dependencies --------------------------------*/  /*------------------------------ Dependencies --------------------------------*/
37    
 #include <sys/stat.h>  
 #include <errno.h>  
   
 #include <srllib.h>  
 #include <dxxxlib.h>  
   
38  #include "logger.h"  #include "logger.h"
39    
 #include "mediafinder.h"  
40  #include "dialogicchannelmanager.h"  #include "dialogicchannelmanager.h"
 #include "ipmdevice.h"  
41  #include "mmdevice.h"  #include "mmdevice.h"
42    
43  /*----------------------------------------------------------------------------*/  /*----------------------------------------------------------------------------*/
# Line 82  Line 74 
74                  switch( pending_.front().cmd )                  switch( pending_.front().cmd )
75                  {                  {
76                          case MmCommand::CONNECT:                          case MmCommand::CONNECT:
77                                  connect(pending_.front().other.audio, pending_.front().other.video);                                  connect(pending_.front().other.audio,
78                                            pending_.front().other.video,
79                                            pending_.front().other.transcode_audio,
80                                            pending_.front().other.transcode_video);
81                                  break;                                  break;
82    
83                          case MmCommand::DISCONNECT:                          case MmCommand::DISCONNECT:
# Line 91  Line 86 
86    
87                          case MmCommand::PLAY:                          case MmCommand::PLAY:
88                                  if ( !play(pending_.front().audioFile,                                  if ( !play(pending_.front().audioFile,
89                                             pending_.front().audioCoder,                                             pending_.front().audioEncoding,
90                                             pending_.front().videoFile,                                             pending_.front().videoFile,
91                                             pending_.front().videoCoder,                                             pending_.front().videoEncoding,
92                                             pending_.front().lang) )                                             pending_.front().videoSize) )
93                                  {                                  {
94                                          channelMgr_.onPlayCompleted(this, PLAY_ERROR, 0);                                          channelMgr_.onPlayCompleted(this, PLAY_ERROR, 0);
95                                  }                                  }
# Line 102  Line 97 
97    
98                          case MmCommand::RECORD:                          case MmCommand::RECORD:
99                                  if ( !record(pending_.front().audioFile,                                  if ( !record(pending_.front().audioFile,
100                                               pending_.front().audioCoder,                                               pending_.front().audioEncoding,
101                                               pending_.front().videoFile,                                               pending_.front().videoFile,
102                                               pending_.front().videoCoder,                                               pending_.front().videoEncoding,
103                                               pending_.front().lang) )                                               pending_.front().videoSize) )
104                                  {                                  {
105                                          channelMgr_.onRecordCompleted(this, RECORD_ERROR, 0);                                          channelMgr_.onRecordCompleted(this, RECORD_ERROR, 0);
106                                  }                                  }
# Line 172  Line 167 
167  {  {
168          if ( busy_ )          if ( busy_ )
169          {          {
170                  pending_.push(MmCommand(MmCommand::CONNECT, other_audio, other_video));                  pending_.push(MmCommand(MmCommand::CONNECT,
171                                            other_audio,
172                                            other_video,
173                                            transcode_audio,
174                                            transcode_video));
175                  return true;                  return true;
176          }          }
177    
# Line 180  Line 179 
179          {          {
180                  LOGDEBUG("MmDevice::connect() device: " << getDeviceName() <<                  LOGDEBUG("MmDevice::connect() device: " << getDeviceName() <<
181                           " other_audio: " << (other_audio ? other_audio->getDeviceName() : "n/a") <<                           " other_audio: " << (other_audio ? other_audio->getDeviceName() : "n/a") <<
182                           " other_video: " << (other_video ? other_video->getDeviceName() : "n/a"));                           " other_video: " << (other_video ? other_video->getDeviceName() : "n/a") <<
183                             " transcode_audio: " << (transcode_audio ? "Y" : "N") <<
184                             " transcode_video: " << (transcode_video ? "Y" : "N"));
185    
186                  DM_PORT_CONNECT_INFO_LIST portConnectInfoList;                  DM_PORT_CONNECT_INFO_LIST portConnectInfoList;
187                  INIT_DM_PORT_CONNECT_INFO_LIST(&portConnectInfoList);                  INIT_DM_PORT_CONNECT_INFO_LIST(&portConnectInfoList);
# Line 290  Line 291 
291   * Start playing.   * Start playing.
292   */   */
293  bool MmDevice::play( const std::string& audioFile,  bool MmDevice::play( const std::string& audioFile,
294                       const AudioCoderInfo& audioCoder,                       const std::string& audioEncoding,
295                       const std::string& videoFile,                       const std::string& videoFile,
296                       const VideoCoderInfo& videoCoder,                       const std::string& videoEncoding,
297                       const std::string& lang )                       unsigned int videoSize )
298  {  {
299          if ( busy_ )          if ( busy_ )
300          {          {
301                  pending_.push(MmCommand(MmCommand::PLAY, audioFile, audioCoder, videoFile, videoCoder, lang));                  pending_.push(MmCommand(MmCommand::PLAY,
302                                            audioFile,
303                                            audioEncoding,
304                                            videoFile,
305                                            videoEncoding,
306                                            videoSize));
307                  return true;                  return true;
308          }          }
309    
         std::string foundAudioFile, foundVideoFile;  
   
310          int count = 0;  /* index for playRecordList_ */          int count = 0;  /* index for playRecordList_ */
311    
312          /* init audio          /* init audio
313           */           */
314          if ( !audioFile.empty() )          if ( !audioFile.empty() )
315          {          {
                 std::string foundAudioEncoding;  
   
                 if ( !channelMgr_.getMediaFinder().find(audioFile,  
                                                         audioCoder.encoding,  
                                                         lang,  
                                                         foundAudioFile,  
                                                         foundAudioEncoding) )  
                 {  
                         LOGERROR("MmDevice::play() device: " << getDeviceName() <<  
                                  " audio file not found: \"" << audioFile << "\"");  
                         return false;  
                 }  
   
316                  INIT_MM_MEDIA_ITEM_LIST(&audioMediaList_);                  INIT_MM_MEDIA_ITEM_LIST(&audioMediaList_);
317                  INIT_MM_MEDIA_AUDIO(&audioMediaList_.item.audio);                  INIT_MM_MEDIA_AUDIO(&audioMediaList_.item.audio);
318                  audioMediaList_.ItemChain = EMM_ITEM_EOT;                  audioMediaList_.ItemChain = EMM_ITEM_EOT;
319                  audioMediaList_.item.audio.szFileName = foundAudioFile.c_str();                  audioMediaList_.item.audio.szFileName = audioFile.c_str();
320    
321                  if ( foundAudioEncoding == "vox" ) /* 8kHz, 16bit, signed-linear */                  if ( audioEncoding == "vox" ) /* 8kHz, 16bit, signed-linear */
322                  {                  {
323                          audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_PCM;                          audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_PCM;
324                          audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ;                          audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ;
# Line 335  Line 326 
326                          audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX;                          audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX;
327                          audioMediaList_.item.audio.unOffset = 0;                          audioMediaList_.item.audio.unOffset = 0;
328                  }                  }
329                  else if ( foundAudioEncoding == "pcma" )                  else if ( audioEncoding == "pcma" )
330                  {                  {
331                          audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_ALAW;                          audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_ALAW;
332                          audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ;                          audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ;
# Line 343  Line 334 
334                          audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX;                          audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX;
335                          audioMediaList_.item.audio.unOffset = 0;                          audioMediaList_.item.audio.unOffset = 0;
336                  }                  }
337                  else if ( foundAudioEncoding == "pcmu" )                  else if ( audioEncoding == "pcmu" )
338                  {                  {
339                          audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_MULAW;                          audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_MULAW;
340                          audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ;                          audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ;
# Line 370  Line 361 
361           */           */
362          if ( !videoFile.empty() )          if ( !videoFile.empty() )
363          {          {
                 std::string foundVideoEncoding;  
                 unsigned int foundSize;  
   
                 if ( !channelMgr_.getMediaFinder().find(videoFile,  
                                                         videoCoder.encoding,  
                                                         videoCoder.active_fmt.imageWidth,  
                                                         lang,  
                                                         foundVideoFile,  
                                                         foundVideoEncoding,  
                                                         foundSize) )  
                 {  
                         LOGERROR("MmDevice::play() device: " << getDeviceName() <<  
                                  " video file not found: \"" << videoFile << "\"");  
                         return false;  
                 }  
   
364                  INIT_MM_MEDIA_ITEM_LIST(&videoMediaList_);                  INIT_MM_MEDIA_ITEM_LIST(&videoMediaList_);
365                  videoMediaList_.ItemChain = EMM_ITEM_EOT;                  videoMediaList_.ItemChain = EMM_ITEM_EOT;
366                  if ( foundVideoEncoding == "jpeg" )                  if ( videoEncoding == "jpeg" )
367                  {                  {
368                          INIT_MM_MEDIA_IMAGE(&videoMediaList_.item.image);                          INIT_MM_MEDIA_IMAGE(&videoMediaList_.item.image);
369    
370                          videoMediaList_.item.image.eFormat = eMTK_IMAGE_FORMAT_JPEG;                          videoMediaList_.item.image.eFormat = eMTK_IMAGE_FORMAT_JPEG;
371                          videoMediaList_.item.image.unAccessMode = MM_MEDIA_ACCESS_MODE_FILE;                          videoMediaList_.item.image.unAccessMode = MM_MEDIA_ACCESS_MODE_FILE;
372                          videoMediaList_.item.image.szFileName = foundVideoFile.c_str();                          videoMediaList_.item.image.szFileName = videoFile.c_str();
373    
374                          LOGINFO("MmDevice::play() device: " << getDeviceName() <<                          LOGINFO("MmDevice::play() device: " << getDeviceName() <<
375                                  ", v=" <<  foundVideoFile);                                  ", v=" <<  videoMediaList_.item.image.szFileName);
376    
377                          /* append */                          /* append */
378                          if ( count > 0 )                          if ( count > 0 )
# Line 413  Line 388 
388                  else /*  video */                  else /*  video */
389                  {                  {
390                          INIT_MM_MEDIA_VIDEO(&videoMediaList_.item.video);                          INIT_MM_MEDIA_VIDEO(&videoMediaList_.item.video);
391                          videoMediaList_.item.video.szFileName = foundVideoFile.c_str();                          videoMediaList_.item.video.szFileName = videoFile.c_str();
392    
393                          if ( foundVideoEncoding == "mpv4-es" )                          if ( videoEncoding == "mpv4-es" )
394                          {                          {
395                                  if ( foundSize == VIDEO_IMAGE_WIDTH_352 )                                  if ( videoSize == VIDEO_IMAGE_WIDTH_352 )
396                                  {                                  {
397                                          videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES;                                          videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES;
398                                          videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP3_MPEG4;                                          videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP3_MPEG4;
# Line 436  Line 411 
411                          }                          }
412                          else /* h263 */                          else /* h263 */
413                          {                          {
414                                  if ( foundSize == VIDEO_IMAGE_WIDTH_352 )                                  if ( videoSize == VIDEO_IMAGE_WIDTH_352 )
415                                  {                                  {
416                                          videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263;                                          videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263;
417                                          videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263;                                          videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263;
# Line 487  Line 462 
462   * Start recording.   * Start recording.
463   */   */
464  bool MmDevice::record( const std::string& audioFile,  bool MmDevice::record( const std::string& audioFile,
465                         const AudioCoderInfo& audioCoder,                         const std::string& audioEncoding,
466                         const std::string& videoFile,                         const std::string& videoFile,
467                         const VideoCoderInfo& videoCoder,                         const std::string& videoEncoding,
468                         const std::string& lang )                         unsigned int videoSize )
469  {  {
470          if ( busy_ )          if ( busy_ )
471          {          {
472                  pending_.push(MmCommand(MmCommand::RECORD, audioFile, audioCoder, videoFile, videoCoder, lang));                  pending_.push(MmCommand(MmCommand::RECORD,
473                                            audioFile,
474                                            audioEncoding,
475                                            videoFile,
476                                            videoEncoding,
477                                            videoSize));
478                  return true;                  return true;
479          }          }
480    
         std::string audioFilePath = channelMgr_.getMediaFinder().getMediaDir();  
         std::string videoFilePath = channelMgr_.getMediaFinder().getMediaDir();  
   
481          int count = 0;  /* index for playRecordList_ */          int count = 0;  /* index for playRecordList_ */
482    
483          /* init audio          /* init audio
484           */           */
485          if ( !audioFile.empty() )          if ( !audioFile.empty() )
486          {          {
                 audioFilePath += '/';  
                 if ( !lang.empty() )  
                 {  
                         audioFilePath += lang;  
                 }  
                 else  
                 {  
                         audioFilePath += channelMgr_.getMediaFinder().getLanguage();  
                 }  
                 audioFilePath += '/';  
   
                 audioFilePath += audioCoder.encoding;  
                 audioFilePath += '/';  
                 audioFilePath += audioFile;  
   
                 std::string dirPath = audioFilePath.substr(0, audioFilePath.rfind('/'));  
                 struct stat st;  
                 if ( lstat(dirPath.c_str(), &st) != 0 )  
                 {  
                         LOGERROR("MmDevice::record() bad path: " << dirPath);  
                         return false;  
                 }  
   
487                  INIT_MM_MEDIA_ITEM_LIST(&audioMediaList_);                  INIT_MM_MEDIA_ITEM_LIST(&audioMediaList_);
488                  INIT_MM_MEDIA_AUDIO(&audioMediaList_.item.audio);                  INIT_MM_MEDIA_AUDIO(&audioMediaList_.item.audio);
489                  audioMediaList_.ItemChain = EMM_ITEM_EOT;                  audioMediaList_.ItemChain = EMM_ITEM_EOT;
490    
491                  if ( audioCoder.encoding == "vox" )                  if ( audioEncoding == "vox" )
492                  {                  {
493                          audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_PCM;                          audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_PCM;
494                          audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ;                          audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ;
# Line 542  Line 496 
496                          audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX;                          audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX;
497                          audioMediaList_.item.audio.unOffset = 0;                          audioMediaList_.item.audio.unOffset = 0;
498                  }                  }
499                  else if ( audioCoder.encoding == "pcma" )                  else if ( audioEncoding == "pcma" )
500                  {                  {
501                          audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_ALAW;                          audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_ALAW;
502                          audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ;                          audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ;
# Line 550  Line 504 
504                          audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX;                          audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX;
505                          audioMediaList_.item.audio.unOffset = 0;                          audioMediaList_.item.audio.unOffset = 0;
506                  }                  }
507                  else if ( audioCoder.encoding == "pcmu" )                  else if ( audioEncoding == "pcmu" )
508                  {                  {
509                          audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_MULAW;                          audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_MULAW;
510                          audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ;                          audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ;
# Line 563  Line 517 
517                          return false;                          return false;
518                  }                  }
519    
520                  audioMediaList_.item.audio.szFileName = audioFilePath.c_str();                  audioMediaList_.item.audio.szFileName = audioFile.c_str();
521    
522                  INIT_MM_PLAY_RECORD_LIST(&playRecordList_[count]);                  INIT_MM_PLAY_RECORD_LIST(&playRecordList_[count]);
523                  playRecordList_[count].ItemType = EMM_MEDIA_TYPE_AUDIO;                  playRecordList_[count].ItemType = EMM_MEDIA_TYPE_AUDIO;
# Line 575  Line 529 
529           */           */
530          if ( !videoFile.empty() )          if ( !videoFile.empty() )
531          {          {
                 videoFilePath += '/';  
                 if ( !lang.empty() )  
                 {  
                         videoFilePath += lang;  
                 }  
                 else  
                 {  
                         videoFilePath += channelMgr_.getMediaFinder().getLanguage();  
                 }  
                 videoFilePath += '/';  
   
                 videoFilePath += videoCoder.encoding;  
                 videoFilePath += '/';  
   
532                  INIT_MM_MEDIA_ITEM_LIST(&videoMediaList_);                  INIT_MM_MEDIA_ITEM_LIST(&videoMediaList_);
533                  INIT_MM_MEDIA_VIDEO(&videoMediaList_.item.video);                  INIT_MM_MEDIA_VIDEO(&videoMediaList_.item.video);
534                  videoMediaList_.ItemChain = EMM_ITEM_EOT;                  videoMediaList_.ItemChain = EMM_ITEM_EOT;
535    
536                  if ( videoCoder.encoding == "mpv4-es" )                  if ( videoEncoding == "mpv4-es" )
537                  {                  {
538                          if ( videoCoder.active_fmt.imageWidth == VIDEO_IMAGE_WIDTH_352 )                          if ( videoSize == VIDEO_IMAGE_WIDTH_352 )
539                          {                          {
                                 videoFilePath += "CIF/";  
540                                  videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES;                                  videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES;
541                                  videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP3_MPEG4;                                  videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP3_MPEG4;
542                                  videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352;                                  videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352;
# Line 606  Line 545 
545                          }                          }
546                          else                          else
547                          {                          {
                                 videoFilePath += "QCIF/";  
548                                  videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES;                                  videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES;
549                                  videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP1_MPEG4;                                  videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP1_MPEG4;
550                                  videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176;                                  videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176;
# Line 616  Line 554 
554                  }                  }
555                  else /* h263 */                  else /* h263 */
556                  {                  {
557                          if ( videoCoder.active_fmt.imageWidth == VIDEO_IMAGE_WIDTH_352 )                          if ( videoSize == VIDEO_IMAGE_WIDTH_352 )
558                          {                          {
                                 videoFilePath += "CIF/";  
559                                  videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263;                                  videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263;
560                                  videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263;                                  videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263;
561                                  videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352;                                  videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352;
# Line 627  Line 564 
564                          }                          }
565                          else                          else
566                          {                          {
                                 videoFilePath += "QCIF/";  
567                                  videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263;                                  videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263;
568                                  videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263;                                  videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263;
569                                  videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176;                                  videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176;
# Line 636  Line 572 
572                          }                          }
573                  }                  }
574    
575                  videoFilePath += videoFile;                  videoMediaList_.item.video.szFileName = videoFile.c_str();
   
                 std::string dirPath = videoFilePath.substr(0, videoFilePath.rfind('/'));  
                 struct stat st;  
                 if ( lstat(dirPath.c_str(), &st) != 0 )  
                 {  
                         LOGERROR("MmDevice::record() bad path: " << dirPath);  
                         return false;  
                 }  
   
                 videoMediaList_.item.video.szFileName = videoFilePath.c_str();  
576    
577                  /* append */                  /* append */
578                  playRecordList_[count++].ItemChain = EMM_ITEM_CONT;                  playRecordList_[count++].ItemChain = EMM_ITEM_CONT;
# Line 872  Line 798 
798   */   */
799  void MmDevice::onOpen()  void MmDevice::onOpen()
800  {  {
801          LOGDEBUG("MmDevice::processEvent() MMEV_OPEN device: " << getDeviceName());          LOGDEBUG("MmDevice::onOpen() MMEV_OPEN device: " << getDeviceName());
802    
803          /* Request port info          /* Request port info
804           */           */

Legend:
Removed from v.656  
changed lines
  Added in v.657

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