| 40 |
|
|
| 41 |
#include "logger.h" |
#include "logger.h" |
| 42 |
|
|
| 43 |
|
#include "mediafinder.h" |
| 44 |
#include "dialogicchannelmanager.h" |
#include "dialogicchannelmanager.h" |
| 45 |
#include "ipmdevice.h" |
#include "ipmdevice.h" |
| 46 |
#include "mmdevice.h" |
#include "mmdevice.h" |
| 59 |
mediaIsCif_ (true) |
mediaIsCif_ (true) |
| 60 |
{ |
{ |
| 61 |
busy_ = false; |
busy_ = false; |
| 62 |
|
|
| 63 |
|
std::string media_dir("/var/lib/diastar/media"); |
| 64 |
|
std::string lang("en_US"); |
| 65 |
|
mediaFinder_ = new MediaFinder(media_dir, lang); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
/* |
| 70 |
|
* dtor |
| 71 |
|
*/ |
| 72 |
|
MmDevice::~MmDevice() |
| 73 |
|
{ |
| 74 |
|
delete mediaFinder_; |
| 75 |
} |
} |
| 76 |
|
|
| 77 |
|
|
| 78 |
/* |
/* |
| 79 |
* Process a command that was queueued because an async operation was in progress |
* Process a command that was queueued because an async operation was in progress |
| 80 |
* when it was initially requested. |
* when it was initially requested. |
| 81 |
|
* XXX if queued op fails send -ve completion event |
| 82 |
*/ |
*/ |
| 83 |
void MmDevice::processPendingCommand() |
void MmDevice::processPendingCommand() |
| 84 |
{ |
{ |
| 90 |
case MmCommand::CONNECT: |
case MmCommand::CONNECT: |
| 91 |
connect(pending_.front().other); |
connect(pending_.front().other); |
| 92 |
break; |
break; |
| 93 |
|
|
| 94 |
case MmCommand::DISCONNECT: |
case MmCommand::DISCONNECT: |
| 95 |
disconnect(); |
disconnect(); |
| 96 |
break; |
break; |
| 97 |
|
|
| 98 |
case MmCommand::PLAY: |
case MmCommand::PLAY: |
| 99 |
play(pending_.front().audioFile, pending_.front().videoFile); |
play(pending_.front().audioFile, |
| 100 |
|
pending_.front().audioCoder, |
| 101 |
|
pending_.front().videoFile, |
| 102 |
|
pending_.front().videoCoder, |
| 103 |
|
pending_.front().lang); |
| 104 |
break; |
break; |
| 105 |
|
|
| 106 |
case MmCommand::RECORD: |
case MmCommand::RECORD: |
| 107 |
record(pending_.front().audioFile, pending_.front().videoFile); |
record(pending_.front().audioFile, |
| 108 |
|
pending_.front().videoFile); |
| 109 |
break; |
break; |
| 110 |
|
|
| 111 |
case MmCommand::STOPPLAY: |
case MmCommand::STOPPLAY: |
| 112 |
stopPlay(); |
stopPlay(); |
| 113 |
break; |
break; |
| 114 |
|
|
| 115 |
case MmCommand::STOPRECORD: |
case MmCommand::STOPRECORD: |
| 116 |
stopRecord(); |
stopRecord(); |
| 117 |
break; |
break; |
| 118 |
|
|
| 119 |
default: |
default: |
| 120 |
break; |
break; |
| 121 |
} |
} |
| 610 |
* Start playing. |
* Start playing. |
| 611 |
*/ |
*/ |
| 612 |
bool MmDevice::play( const std::string& audioFile, |
bool MmDevice::play( const std::string& audioFile, |
| 613 |
const std::string& videoFile ) |
const AudioCoderInfo& audioCoder, |
| 614 |
|
const std::string& videoFile, |
| 615 |
|
const VideoCoderInfo& videoCoder, |
| 616 |
|
const std::string& lang ) |
| 617 |
{ |
{ |
| 618 |
if ( busy_ ) |
if ( busy_ ) |
| 619 |
{ |
{ |
| 620 |
pending_.push(MmCommand(MmCommand::PLAY, audioFile, videoFile)); |
pending_.push(MmCommand(MmCommand::PLAY, audioFile, audioCoder, videoFile, videoCoder, lang)); |
| 621 |
return true; |
return true; |
| 622 |
} |
} |
| 623 |
|
|
| 624 |
MM_AUDIO_CODEC audioCodec; |
std::string foundAudioFile, foundVideoFile; |
| 625 |
if ( videoFile.empty() ) |
|
| 626 |
|
int count = 0; /* index for playRecordList_ */ |
| 627 |
|
|
| 628 |
|
/* init audio |
| 629 |
|
*/ |
| 630 |
|
if ( !audioFile.empty() ) |
| 631 |
{ |
{ |
| 632 |
INIT_MM_AUDIO_CODEC(&audioCodec); |
std::string foundAudioEncoding; |
| 633 |
audioCodec.unCoding = MM_DATA_FORMAT_PCM; |
|
| 634 |
audioCodec.unSampleRate = MM_DRT_8KHZ; |
if ( !mediaFinder_->find(audioFile, |
| 635 |
audioCodec.unBitsPerSample = 16; |
audioCoder.encoding, |
| 636 |
|
lang, |
| 637 |
|
foundAudioFile, |
| 638 |
|
foundAudioEncoding) ) |
| 639 |
|
{ |
| 640 |
|
return false; |
| 641 |
|
} |
| 642 |
|
|
| 643 |
INIT_MM_MEDIA_ITEM_LIST(&audioMediaList_); |
INIT_MM_MEDIA_ITEM_LIST(&audioMediaList_); |
| 644 |
INIT_MM_MEDIA_AUDIO(&audioMediaList_.item.audio); |
INIT_MM_MEDIA_AUDIO(&audioMediaList_.item.audio); |
| 645 |
audioMediaList_.ItemChain = EMM_ITEM_EOT; |
audioMediaList_.ItemChain = EMM_ITEM_EOT; |
| 646 |
audioMediaList_.item.audio.szFileName = audioFile.c_str(); |
audioMediaList_.item.audio.szFileName = foundAudioFile.c_str(); |
| 647 |
audioMediaList_.item.audio.codec = audioCodec; |
|
| 648 |
audioMediaList_.item.audio.unMode = MM_MODE_AUD_FILE_TYPE_VOX; |
if ( foundAudioEncoding == "vox" ) |
| 649 |
|
{ |
| 650 |
|
audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_PCM; |
| 651 |
|
audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ; |
| 652 |
|
audioMediaList_.item.audio.codec.unBitsPerSample = 16; |
| 653 |
audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX; |
audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX; |
| 654 |
audioMediaList_.item.audio.unOffset = 0; |
audioMediaList_.item.audio.unOffset = 0; |
|
|
|
|
INIT_MM_PLAY_RECORD_LIST(&playRecordList_[0]); |
|
|
playRecordList_[0].ItemType = EMM_MEDIA_TYPE_AUDIO; |
|
|
playRecordList_[0].list = &audioMediaList_; |
|
|
playRecordList_[0].ItemChain = EMM_ITEM_EOT; |
|
|
|
|
|
INIT_MM_PLAY_INFO(&playInfo_); |
|
|
playInfo_.eFileFormat = EMM_FILE_FORMAT_UNDEFINED; |
|
|
playInfo_.list = playRecordList_; |
|
| 655 |
} |
} |
| 656 |
else |
else if ( foundAudioEncoding == "pcma" ) |
| 657 |
{ |
{ |
| 658 |
/* init audio |
audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_ALAW; |
| 659 |
*/ |
audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ; |
| 660 |
INIT_MM_AUDIO_CODEC(&audioCodec); |
audioMediaList_.item.audio.codec.unBitsPerSample = 8; |
|
audioCodec.unCoding = MM_DATA_FORMAT_PCM; |
|
|
audioCodec.unSampleRate = MM_DRT_8KHZ; |
|
|
audioCodec.unBitsPerSample = 16; |
|
|
|
|
|
INIT_MM_MEDIA_ITEM_LIST(&audioMediaList_); |
|
|
INIT_MM_MEDIA_AUDIO(&audioMediaList_.item.audio); |
|
|
audioMediaList_.ItemChain = EMM_ITEM_EOT; |
|
|
audioMediaList_.item.audio.szFileName = audioFile.c_str(); |
|
|
audioMediaList_.item.audio.codec = audioCodec; |
|
|
audioMediaList_.item.audio.unMode = MM_MODE_AUD_FILE_TYPE_VOX; |
|
| 661 |
audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX; |
audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX; |
| 662 |
audioMediaList_.item.audio.unOffset = 0; |
audioMediaList_.item.audio.unOffset = 0; |
| 663 |
|
} |
| 664 |
|
else if ( foundAudioEncoding == "pcmu" ) |
| 665 |
|
{ |
| 666 |
|
audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_MULAW; |
| 667 |
|
audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ; |
| 668 |
|
audioMediaList_.item.audio.codec.unBitsPerSample = 8; |
| 669 |
|
audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX; |
| 670 |
|
audioMediaList_.item.audio.unOffset = 0; |
| 671 |
|
} |
| 672 |
|
else |
| 673 |
|
{ |
| 674 |
|
return false; |
| 675 |
|
} |
| 676 |
|
|
| 677 |
|
INIT_MM_PLAY_RECORD_LIST(&playRecordList_[count]); |
| 678 |
|
playRecordList_[count].ItemType = EMM_MEDIA_TYPE_AUDIO; |
| 679 |
|
playRecordList_[count].list = &audioMediaList_; |
| 680 |
|
playRecordList_[count].ItemChain = EMM_ITEM_EOT; |
| 681 |
|
} |
| 682 |
|
|
| 683 |
/* init video |
/* init video |
| 684 |
*/ |
*/ |
| 685 |
|
if ( !videoFile.empty() ) |
| 686 |
|
{ |
| 687 |
|
std::string foundVideoEncoding; |
| 688 |
|
unsigned int foundSize; |
| 689 |
|
|
| 690 |
|
if ( !mediaFinder_->find(videoFile, |
| 691 |
|
videoCoder.encoding, |
| 692 |
|
videoCoder.active_fmt.imageWidth, |
| 693 |
|
lang, |
| 694 |
|
foundVideoFile, |
| 695 |
|
foundVideoEncoding, |
| 696 |
|
foundSize) ) |
| 697 |
|
{ |
| 698 |
|
return false; |
| 699 |
|
} |
| 700 |
|
|
| 701 |
INIT_MM_MEDIA_ITEM_LIST(&videoMediaList_); |
INIT_MM_MEDIA_ITEM_LIST(&videoMediaList_); |
| 702 |
INIT_MM_MEDIA_VIDEO(&videoMediaList_.item.video); |
INIT_MM_MEDIA_VIDEO(&videoMediaList_.item.video); |
| 703 |
videoMediaList_.ItemChain = EMM_ITEM_EOT; |
videoMediaList_.ItemChain = EMM_ITEM_EOT; |
| 704 |
videoMediaList_.item.video.szFileName = videoFile.c_str(); |
videoMediaList_.item.video.szFileName = foundVideoFile.c_str(); |
| 705 |
|
|
| 706 |
if ( mediaIsMpeg4_ ) |
if ( foundVideoEncoding == "mpv4-es" ) |
| 707 |
{ |
{ |
| 708 |
if ( mediaIsCif_ ) |
if ( foundSize == VIDEO_IMAGE_WIDTH_352 ) |
| 709 |
{ |
{ |
|
LOGDEBUG("MmDevice::play() Using MPEG4 CIF device: " << getDeviceName()); |
|
| 710 |
videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES; |
videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES; |
| 711 |
videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP3_MPEG4; |
videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP3_MPEG4; |
| 712 |
videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352; |
videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352; |
| 715 |
} |
} |
| 716 |
else |
else |
| 717 |
{ |
{ |
|
LOGDEBUG("MmDevice::play() Using MPEG4 QCIF device: " << getDeviceName()); |
|
| 718 |
videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES; |
videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES; |
| 719 |
videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP1_MPEG4; |
videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP1_MPEG4; |
| 720 |
videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176; |
videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176; |
| 722 |
videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15; |
videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15; |
| 723 |
} |
} |
| 724 |
} |
} |
| 725 |
else |
else /* h263 */ |
| 726 |
{ |
{ |
| 727 |
if ( mediaIsCif_ ) |
if ( foundSize == VIDEO_IMAGE_WIDTH_352 ) |
| 728 |
{ |
{ |
|
LOGDEBUG("MmDevice::play() Using H.263 CIF device: " << getDeviceName()); |
|
| 729 |
videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263; |
videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263; |
| 730 |
videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263; |
videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263; |
| 731 |
videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352; |
videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352; |
| 734 |
} |
} |
| 735 |
else |
else |
| 736 |
{ |
{ |
|
LOGDEBUG("MmDevice::play() Using H.263 QCIF device: " << getDeviceName()); |
|
| 737 |
videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263; |
videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263; |
| 738 |
videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263; |
videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263; |
| 739 |
videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176; |
videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176; |
| 742 |
} |
} |
| 743 |
} |
} |
| 744 |
|
|
| 745 |
INIT_MM_PLAY_RECORD_LIST(&playRecordList_[0]); |
/* append */ |
| 746 |
playRecordList_[0].ItemType = EMM_MEDIA_TYPE_AUDIO; |
playRecordList_[count++].ItemChain = EMM_ITEM_CONT; |
|
playRecordList_[0].list = &audioMediaList_; |
|
|
playRecordList_[0].ItemChain = EMM_ITEM_CONT; |
|
| 747 |
|
|
| 748 |
INIT_MM_PLAY_RECORD_LIST(&playRecordList_[1]); |
INIT_MM_PLAY_RECORD_LIST(&playRecordList_[count]); |
| 749 |
playRecordList_[1].ItemType = EMM_MEDIA_TYPE_VIDEO; |
playRecordList_[count].ItemType = EMM_MEDIA_TYPE_VIDEO; |
| 750 |
playRecordList_[1].list = &videoMediaList_; |
playRecordList_[count].list = &videoMediaList_; |
| 751 |
playRecordList_[1].ItemChain = EMM_ITEM_EOT; |
playRecordList_[count].ItemChain = EMM_ITEM_EOT; |
| 752 |
|
} |
| 753 |
|
|
| 754 |
INIT_MM_PLAY_RECORD_INFO(&playInfo_); |
INIT_MM_PLAY_RECORD_INFO(&playInfo_); |
| 755 |
playInfo_.eFileFormat = EMM_FILE_FORMAT_UNDEFINED; |
playInfo_.eFileFormat = EMM_FILE_FORMAT_UNDEFINED; |
| 756 |
playInfo_.list = playRecordList_; |
playInfo_.list = playRecordList_; |
|
} |
|
|
|
|
|
audioMediaList_.item.audio.szFileName = audioFile.c_str(); |
|
|
videoMediaList_.item.video.szFileName = videoFile.c_str(); |
|
| 757 |
|
|
| 758 |
LOGDEBUG("MmDevice::play() device: " << getDeviceName() << |
LOGDEBUG("MmDevice::play() device: " << getDeviceName() << |
| 759 |
" a=" << audioMediaList_.item.audio.szFileName << |
" a=" << audioMediaList_.item.audio.szFileName << |
| 760 |
", v=" << videoMediaList_.item.video.szFileName); |
", v=" << videoMediaList_.item.video.szFileName); |
| 761 |
|
|
| 762 |
if ( mm_Play(devHandle_, &playInfo_, NULL, NULL) == EMM_ERROR ) |
if ( mm_Play(devHandle_, &playInfo_, NULL, NULL) == EMM_ERROR ) |
| 763 |
{ |
{ |
| 764 |
LOGERROR("mm_Play() failed on device: " << getDeviceName()); |
LOGERROR("mm_Play() failed on device: " << getDeviceName()); |