Parent Directory
|
Revision Log
Revision 666 - (view) (download)
| 1 : | amartin | 378 | /* |
| 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 "logger.h" | ||
| 39 : | |||
| 40 : | #include "dialogicchannelmanager.h" | ||
| 41 : | #include "mmdevice.h" | ||
| 42 : | |||
| 43 : | /*----------------------------------------------------------------------------*/ | ||
| 44 : | |||
| 45 : | /* | ||
| 46 : | * ctor | ||
| 47 : | */ | ||
| 48 : | MmDevice::MmDevice( const std::string& name, | ||
| 49 : | jtarlton | 536 | DialogicChannelManager& channelMgr ) |
| 50 : | amartin | 378 | : DialogicDevice(name, channelMgr), |
| 51 : | jtarlton | 390 | playActive_ (false), |
| 52 : | jtarlton | 538 | recordActive_ (false) |
| 53 : | amartin | 378 | { |
| 54 : | amartin | 403 | busy_ = false; |
| 55 : | } | ||
| 56 : | amartin | 378 | |
| 57 : | jtarlton | 536 | |
| 58 : | amartin | 403 | /* |
| 59 : | jtarlton | 536 | * dtor |
| 60 : | */ | ||
| 61 : | MmDevice::~MmDevice() | ||
| 62 : | { | ||
| 63 : | } | ||
| 64 : | |||
| 65 : | |||
| 66 : | /* | ||
| 67 : | jtarlton | 596 | * Process a command that was queued because an async operation was in progress |
| 68 : | amartin | 403 | * when it was initially requested. |
| 69 : | */ | ||
| 70 : | void MmDevice::processPendingCommand() | ||
| 71 : | { | ||
| 72 : | jtarlton | 418 | while ( !busy_ && !pending_.empty() ) |
| 73 : | amartin | 403 | { |
| 74 : | switch( pending_.front().cmd ) | ||
| 75 : | { | ||
| 76 : | case MmCommand::CONNECT: | ||
| 77 : | jtarlton | 657 | connect(pending_.front().other.audio, |
| 78 : | pending_.front().other.video, | ||
| 79 : | jtarlton | 666 | pending_.front().other.transcodeAudio, |
| 80 : | pending_.front().other.transcodeVideo); | ||
| 81 : | amartin | 403 | break; |
| 82 : | jtarlton | 536 | |
| 83 : | amartin | 403 | case MmCommand::DISCONNECT: |
| 84 : | disconnect(); | ||
| 85 : | break; | ||
| 86 : | jtarlton | 536 | |
| 87 : | amartin | 403 | case MmCommand::PLAY: |
| 88 : | jtarlton | 557 | if ( !play(pending_.front().audioFile, |
| 89 : | jtarlton | 657 | pending_.front().audioEncoding, |
| 90 : | jtarlton | 557 | pending_.front().videoFile, |
| 91 : | jtarlton | 657 | pending_.front().videoEncoding, |
| 92 : | pending_.front().videoSize) ) | ||
| 93 : | jtarlton | 557 | { |
| 94 : | jtarlton | 640 | channelMgr_.onPlayCompleted(this, PLAY_ERROR, 0); |
| 95 : | jtarlton | 557 | } |
| 96 : | amartin | 403 | break; |
| 97 : | jtarlton | 536 | |
| 98 : | amartin | 403 | case MmCommand::RECORD: |
| 99 : | jtarlton | 557 | if ( !record(pending_.front().audioFile, |
| 100 : | jtarlton | 657 | pending_.front().audioEncoding, |
| 101 : | jtarlton | 557 | pending_.front().videoFile, |
| 102 : | jtarlton | 657 | pending_.front().videoEncoding, |
| 103 : | jtarlton | 663 | pending_.front().videoSize, |
| 104 : | pending_.front().beep) ) | ||
| 105 : | jtarlton | 557 | { |
| 106 : | jtarlton | 640 | channelMgr_.onRecordCompleted(this, RECORD_ERROR, 0); |
| 107 : | jtarlton | 557 | } |
| 108 : | amartin | 403 | break; |
| 109 : | jtarlton | 536 | |
| 110 : | jtarlton | 642 | case MmCommand::STOPPLAY: |
| 111 : | stopPlay(pending_.front().reason); | ||
| 112 : | break; | ||
| 113 : | |||
| 114 : | case MmCommand::STOPRECORD: | ||
| 115 : | stopRecord(pending_.front().reason); | ||
| 116 : | break; | ||
| 117 : | |||
| 118 : | amartin | 403 | default: |
| 119 : | break; | ||
| 120 : | } | ||
| 121 : | pending_.pop(); | ||
| 122 : | } | ||
| 123 : | amartin | 378 | } |
| 124 : | |||
| 125 : | jtarlton | 596 | |
| 126 : | amartin | 378 | /* |
| 127 : | * Open the device. | ||
| 128 : | */ | ||
| 129 : | bool MmDevice::open() | ||
| 130 : | { | ||
| 131 : | jtarlton | 455 | LOGDEBUG("MmDevice::open() device: " << getDeviceName()); |
| 132 : | devHandle_ = mm_Open(getDeviceName().c_str(), 0, NULL); | ||
| 133 : | jtarlton | 390 | if ( devHandle_ == EMM_ERROR ) |
| 134 : | { | ||
| 135 : | LOGERROR("mm_Open() failed"); | ||
| 136 : | return false; | ||
| 137 : | } | ||
| 138 : | amartin | 378 | return true; |
| 139 : | } | ||
| 140 : | |||
| 141 : | |||
| 142 : | /* | ||
| 143 : | * Close the device. | ||
| 144 : | */ | ||
| 145 : | bool MmDevice::close() | ||
| 146 : | { | ||
| 147 : | jtarlton | 455 | LOGDEBUG("MmDevice::close() device: " << getDeviceName()); |
| 148 : | jtarlton | 400 | if ( devHandle_ > 0 ) |
| 149 : | jtarlton | 390 | { |
| 150 : | jtarlton | 400 | if ( mm_Close(devHandle_, NULL) == EMM_ERROR ) |
| 151 : | { | ||
| 152 : | LOGERROR("mm_Close() failed"); | ||
| 153 : | return false; | ||
| 154 : | } | ||
| 155 : | devHandle_ = 0; | ||
| 156 : | jtarlton | 390 | } |
| 157 : | amartin | 378 | return true; |
| 158 : | } | ||
| 159 : | |||
| 160 : | |||
| 161 : | /* | ||
| 162 : | * Connect media. | ||
| 163 : | */ | ||
| 164 : | jtarlton | 548 | bool MmDevice::connect( DialogicDevice* other_audio, |
| 165 : | jtarlton | 644 | DialogicDevice* other_video, |
| 166 : | bool transcode_audio, | ||
| 167 : | bool transcode_video ) | ||
| 168 : | amartin | 378 | { |
| 169 : | jtarlton | 413 | if ( busy_ ) |
| 170 : | { | ||
| 171 : | jtarlton | 657 | pending_.push(MmCommand(MmCommand::CONNECT, |
| 172 : | other_audio, | ||
| 173 : | other_video, | ||
| 174 : | transcode_audio, | ||
| 175 : | transcode_video)); | ||
| 176 : | jtarlton | 413 | return true; |
| 177 : | } | ||
| 178 : | |||
| 179 : | jtarlton | 548 | if ( !other_audio_ && !other_video_ ) |
| 180 : | amartin | 403 | { |
| 181 : | jtarlton | 455 | LOGDEBUG("MmDevice::connect() device: " << getDeviceName() << |
| 182 : | jtarlton | 548 | " other_audio: " << (other_audio ? other_audio->getDeviceName() : "n/a") << |
| 183 : | jtarlton | 657 | " other_video: " << (other_video ? other_video->getDeviceName() : "n/a") << |
| 184 : | " transcode_audio: " << (transcode_audio ? "Y" : "N") << | ||
| 185 : | " transcode_video: " << (transcode_video ? "Y" : "N")); | ||
| 186 : | jtarlton | 390 | |
| 187 : | jtarlton | 393 | DM_PORT_CONNECT_INFO_LIST portConnectInfoList; |
| 188 : | INIT_DM_PORT_CONNECT_INFO_LIST(&portConnectInfoList); | ||
| 189 : | |||
| 190 : | int count = 0; | ||
| 191 : | |||
| 192 : | jtarlton | 548 | if ( other_audio ) |
| 193 : | { | ||
| 194 : | INIT_DM_PORT_CONNECT_INFO(&portConnectInfoList.port_connect_info[count]); | ||
| 195 : | jtarlton | 661 | audioConnectFlags_ = transcode_audio ? DMFL_TRANSCODE_ON : DMFL_TRANSCODE_NATIVE; |
| 196 : | portConnectInfoList.port_connect_info[count].unFlags = audioConnectFlags_; | ||
| 197 : | jtarlton | 548 | portConnectInfoList.port_connect_info[count].port_info_tx = getAudioTxPortInfo(); |
| 198 : | portConnectInfoList.port_connect_info[count].port_info_rx = other_audio->getAudioRxPortInfo(); | ||
| 199 : | count++; | ||
| 200 : | } | ||
| 201 : | if ( other_video ) | ||
| 202 : | { | ||
| 203 : | INIT_DM_PORT_CONNECT_INFO(&portConnectInfoList.port_connect_info[count]); | ||
| 204 : | jtarlton | 661 | videoConnectFlags_ = transcode_video ? DMFL_TRANSCODE_ON : DMFL_TRANSCODE_NATIVE; |
| 205 : | portConnectInfoList.port_connect_info[count].unFlags = videoConnectFlags_; | ||
| 206 : | jtarlton | 548 | portConnectInfoList.port_connect_info[count].port_info_tx = getVideoTxPortInfo(); |
| 207 : | portConnectInfoList.port_connect_info[count].port_info_rx = other_video->getVideoRxPortInfo(); | ||
| 208 : | count++; | ||
| 209 : | } | ||
| 210 : | jtarlton | 393 | |
| 211 : | portConnectInfoList.unCount = count;; | ||
| 212 : | if ( dev_PortConnect(devHandle_, &portConnectInfoList, NULL) != DEV_SUCCESS ) | ||
| 213 : | { | ||
| 214 : | jtarlton | 455 | LOGERROR("MmDevice::connect() dev_PortConnect() failed on device: " << |
| 215 : | getDeviceName() << " " << ATDV_ERRMSGP(devHandle_)); | ||
| 216 : | jtarlton | 393 | return false; |
| 217 : | } | ||
| 218 : | |||
| 219 : | jtarlton | 548 | other_audio_ = other_audio; |
| 220 : | other_video_ = other_video; | ||
| 221 : | amartin | 403 | busy_ = true; |
| 222 : | jtarlton | 393 | } |
| 223 : | amartin | 405 | else |
| 224 : | { | ||
| 225 : | jtarlton | 548 | if ( other_audio && other_audio_ && (other_audio != other_audio_) ) |
| 226 : | jtarlton | 417 | { |
| 227 : | jtarlton | 455 | LOGERROR("MmDevice::connect() " << getDeviceName() << |
| 228 : | jtarlton | 548 | " unable to connect audio to device: " << other_audio->getDeviceName() << |
| 229 : | " already connected to device: " << other_audio_->getDeviceName()); | ||
| 230 : | jtarlton | 417 | } |
| 231 : | jtarlton | 548 | if ( other_video && other_video_ && (other_video != other_video_) ) |
| 232 : | { | ||
| 233 : | LOGERROR("MmDevice::connect() " << getDeviceName() << | ||
| 234 : | " unable to connect video to device: " << other_video->getDeviceName() << | ||
| 235 : | " already connected to device: " << other_video_->getDeviceName()); | ||
| 236 : | } | ||
| 237 : | amartin | 405 | } |
| 238 : | return true; | ||
| 239 : | amartin | 378 | } |
| 240 : | |||
| 241 : | |||
| 242 : | /* | ||
| 243 : | * Disconnect media. | ||
| 244 : | */ | ||
| 245 : | jtarlton | 401 | bool MmDevice::disconnect() |
| 246 : | amartin | 378 | { |
| 247 : | jtarlton | 413 | if ( busy_ ) |
| 248 : | jtarlton | 393 | { |
| 249 : | jtarlton | 413 | pending_.push(MmCommand(MmCommand::DISCONNECT)); |
| 250 : | return true; | ||
| 251 : | } | ||
| 252 : | amartin | 403 | |
| 253 : | jtarlton | 548 | if ( other_audio_ || other_video_ ) |
| 254 : | jtarlton | 413 | { |
| 255 : | jtarlton | 548 | LOGDEBUG("MmDevice::disconnect() device: " << getDeviceName() << |
| 256 : | " other_audio: " << (other_audio_ ? other_audio_->getDeviceName() : "n/a") << | ||
| 257 : | " other_video: " << (other_video_ ? other_video_->getDeviceName() : "n/a")); | ||
| 258 : | jtarlton | 455 | |
| 259 : | jtarlton | 393 | DM_PORT_CONNECT_INFO_LIST portConnectInfoList; |
| 260 : | INIT_DM_PORT_CONNECT_INFO_LIST(&portConnectInfoList); | ||
| 261 : | int count = 0; | ||
| 262 : | |||
| 263 : | jtarlton | 548 | if ( other_audio_ ) |
| 264 : | { | ||
| 265 : | INIT_DM_PORT_CONNECT_INFO(&portConnectInfoList.port_connect_info[count]); | ||
| 266 : | jtarlton | 661 | portConnectInfoList.port_connect_info[count].unFlags = audioConnectFlags_; |
| 267 : | jtarlton | 548 | portConnectInfoList.port_connect_info[count].port_info_tx = getAudioTxPortInfo(); |
| 268 : | portConnectInfoList.port_connect_info[count].port_info_rx = other_audio_->getAudioRxPortInfo(); | ||
| 269 : | count++; | ||
| 270 : | } | ||
| 271 : | if ( other_video_ ) | ||
| 272 : | { | ||
| 273 : | INIT_DM_PORT_CONNECT_INFO(&portConnectInfoList.port_connect_info[count]); | ||
| 274 : | jtarlton | 661 | portConnectInfoList.port_connect_info[count].unFlags = videoConnectFlags_; |
| 275 : | jtarlton | 548 | portConnectInfoList.port_connect_info[count].port_info_tx = getVideoTxPortInfo(); |
| 276 : | portConnectInfoList.port_connect_info[count].port_info_rx = other_video_->getVideoRxPortInfo(); | ||
| 277 : | count++; | ||
| 278 : | } | ||
| 279 : | jtarlton | 393 | portConnectInfoList.unCount = count; |
| 280 : | if ( dev_PortDisconnect(devHandle_, &portConnectInfoList, NULL) != DEV_SUCCESS ) | ||
| 281 : | { | ||
| 282 : | jtarlton | 455 | LOGERROR("MmDevice::disconnect() dev_PortDisconnect() failed on device: " << |
| 283 : | getDeviceName() << " " << ATDV_ERRMSGP(devHandle_)); | ||
| 284 : | jtarlton | 393 | return false; |
| 285 : | } | ||
| 286 : | |||
| 287 : | jtarlton | 548 | other_audio_ = 0; |
| 288 : | other_video_ = 0; | ||
| 289 : | amartin | 403 | busy_ = true; |
| 290 : | jtarlton | 393 | } |
| 291 : | return true; | ||
| 292 : | amartin | 378 | } |
| 293 : | |||
| 294 : | |||
| 295 : | jtarlton | 390 | /* |
| 296 : | * Start playing. | ||
| 297 : | */ | ||
| 298 : | bool MmDevice::play( const std::string& audioFile, | ||
| 299 : | jtarlton | 657 | const std::string& audioEncoding, |
| 300 : | jtarlton | 536 | const std::string& videoFile, |
| 301 : | jtarlton | 657 | const std::string& videoEncoding, |
| 302 : | unsigned int videoSize ) | ||
| 303 : | jtarlton | 390 | { |
| 304 : | amartin | 403 | if ( busy_ ) |
| 305 : | { | ||
| 306 : | jtarlton | 657 | pending_.push(MmCommand(MmCommand::PLAY, |
| 307 : | audioFile, | ||
| 308 : | audioEncoding, | ||
| 309 : | videoFile, | ||
| 310 : | videoEncoding, | ||
| 311 : | videoSize)); | ||
| 312 : | amartin | 403 | return true; |
| 313 : | } | ||
| 314 : | jtarlton | 390 | |
| 315 : | jtarlton | 536 | int count = 0; /* index for playRecordList_ */ |
| 316 : | |||
| 317 : | /* init audio | ||
| 318 : | */ | ||
| 319 : | if ( !audioFile.empty() ) | ||
| 320 : | jtarlton | 390 | { |
| 321 : | INIT_MM_MEDIA_ITEM_LIST(&audioMediaList_); | ||
| 322 : | INIT_MM_MEDIA_AUDIO(&audioMediaList_.item.audio); | ||
| 323 : | audioMediaList_.ItemChain = EMM_ITEM_EOT; | ||
| 324 : | jtarlton | 657 | audioMediaList_.item.audio.szFileName = audioFile.c_str(); |
| 325 : | jtarlton | 390 | |
| 326 : | jtarlton | 657 | if ( audioEncoding == "vox" ) /* 8kHz, 16bit, signed-linear */ |
| 327 : | jtarlton | 536 | { |
| 328 : | audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_PCM; | ||
| 329 : | audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ; | ||
| 330 : | audioMediaList_.item.audio.codec.unBitsPerSample = 16; | ||
| 331 : | audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX; | ||
| 332 : | audioMediaList_.item.audio.unOffset = 0; | ||
| 333 : | } | ||
| 334 : | jtarlton | 657 | else if ( audioEncoding == "pcma" ) |
| 335 : | jtarlton | 536 | { |
| 336 : | audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_ALAW; | ||
| 337 : | audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ; | ||
| 338 : | audioMediaList_.item.audio.codec.unBitsPerSample = 8; | ||
| 339 : | audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX; | ||
| 340 : | audioMediaList_.item.audio.unOffset = 0; | ||
| 341 : | } | ||
| 342 : | jtarlton | 657 | else if ( audioEncoding == "pcmu" ) |
| 343 : | jtarlton | 536 | { |
| 344 : | audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_MULAW; | ||
| 345 : | audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ; | ||
| 346 : | audioMediaList_.item.audio.codec.unBitsPerSample = 8; | ||
| 347 : | audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX; | ||
| 348 : | audioMediaList_.item.audio.unOffset = 0; | ||
| 349 : | } | ||
| 350 : | else | ||
| 351 : | { | ||
| 352 : | return false; | ||
| 353 : | } | ||
| 354 : | jtarlton | 390 | |
| 355 : | jtarlton | 640 | LOGINFO("MmDevice::play() device: " << getDeviceName() << |
| 356 : | ", a=" << audioMediaList_.item.audio.szFileName); | ||
| 357 : | jtarlton | 548 | |
| 358 : | jtarlton | 536 | INIT_MM_PLAY_RECORD_LIST(&playRecordList_[count]); |
| 359 : | playRecordList_[count].ItemType = EMM_MEDIA_TYPE_AUDIO; | ||
| 360 : | playRecordList_[count].list = &audioMediaList_; | ||
| 361 : | playRecordList_[count].ItemChain = EMM_ITEM_EOT; | ||
| 362 : | jtarlton | 552 | count++; |
| 363 : | jtarlton | 390 | } |
| 364 : | jtarlton | 536 | |
| 365 : | /* init video | ||
| 366 : | */ | ||
| 367 : | if ( !videoFile.empty() ) | ||
| 368 : | jtarlton | 390 | { |
| 369 : | INIT_MM_MEDIA_ITEM_LIST(&videoMediaList_); | ||
| 370 : | videoMediaList_.ItemChain = EMM_ITEM_EOT; | ||
| 371 : | jtarlton | 657 | if ( videoEncoding == "jpeg" ) |
| 372 : | jtarlton | 607 | { |
| 373 : | INIT_MM_MEDIA_IMAGE(&videoMediaList_.item.image); | ||
| 374 : | jtarlton | 390 | |
| 375 : | jtarlton | 607 | videoMediaList_.item.image.eFormat = eMTK_IMAGE_FORMAT_JPEG; |
| 376 : | videoMediaList_.item.image.unAccessMode = MM_MEDIA_ACCESS_MODE_FILE; | ||
| 377 : | jtarlton | 657 | videoMediaList_.item.image.szFileName = videoFile.c_str(); |
| 378 : | jtarlton | 607 | |
| 379 : | jtarlton | 640 | LOGINFO("MmDevice::play() device: " << getDeviceName() << |
| 380 : | jtarlton | 657 | ", v=" << videoMediaList_.item.image.szFileName); |
| 381 : | jtarlton | 607 | |
| 382 : | /* append */ | ||
| 383 : | if ( count > 0 ) | ||
| 384 : | jtarlton | 390 | { |
| 385 : | jtarlton | 607 | playRecordList_[count-1].ItemChain = EMM_ITEM_CONT; |
| 386 : | jtarlton | 390 | } |
| 387 : | jtarlton | 607 | |
| 388 : | INIT_MM_PLAY_RECORD_LIST(&playRecordList_[count]); | ||
| 389 : | playRecordList_[count].ItemType = EMM_MEDIA_TYPE_IMAGE; | ||
| 390 : | playRecordList_[count].list = &videoMediaList_; | ||
| 391 : | playRecordList_[count].ItemChain = EMM_ITEM_EOT; | ||
| 392 : | jtarlton | 390 | } |
| 393 : | jtarlton | 607 | else /* video */ |
| 394 : | jtarlton | 390 | { |
| 395 : | jtarlton | 607 | INIT_MM_MEDIA_VIDEO(&videoMediaList_.item.video); |
| 396 : | jtarlton | 657 | videoMediaList_.item.video.szFileName = videoFile.c_str(); |
| 397 : | jtarlton | 607 | |
| 398 : | jtarlton | 657 | if ( videoEncoding == "mpv4-es" ) |
| 399 : | jtarlton | 390 | { |
| 400 : | jtarlton | 657 | if ( videoSize == VIDEO_IMAGE_WIDTH_352 ) |
| 401 : | jtarlton | 607 | { |
| 402 : | videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES; | ||
| 403 : | videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP3_MPEG4; | ||
| 404 : | videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352; | ||
| 405 : | videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_288; | ||
| 406 : | videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15; | ||
| 407 : | } | ||
| 408 : | else | ||
| 409 : | { | ||
| 410 : | videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES; | ||
| 411 : | videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP1_MPEG4; | ||
| 412 : | videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176; | ||
| 413 : | videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_144; | ||
| 414 : | videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15; | ||
| 415 : | } | ||
| 416 : | jtarlton | 390 | } |
| 417 : | jtarlton | 607 | else /* h263 */ |
| 418 : | jtarlton | 390 | { |
| 419 : | jtarlton | 657 | if ( videoSize == VIDEO_IMAGE_WIDTH_352 ) |
| 420 : | jtarlton | 607 | { |
| 421 : | videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263; | ||
| 422 : | videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263; | ||
| 423 : | videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352; | ||
| 424 : | videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_288; | ||
| 425 : | videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15; | ||
| 426 : | } | ||
| 427 : | else | ||
| 428 : | { | ||
| 429 : | videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263; | ||
| 430 : | videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263; | ||
| 431 : | videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176; | ||
| 432 : | videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_144; | ||
| 433 : | videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_10; | ||
| 434 : | } | ||
| 435 : | jtarlton | 390 | } |
| 436 : | jtarlton | 640 | LOGINFO("MmDevice::play() device: " << getDeviceName() << |
| 437 : | ", v=" << videoMediaList_.item.video.szFileName); | ||
| 438 : | jtarlton | 390 | |
| 439 : | jtarlton | 607 | /* append */ |
| 440 : | if ( count > 0 ) | ||
| 441 : | { | ||
| 442 : | playRecordList_[count-1].ItemChain = EMM_ITEM_CONT; | ||
| 443 : | } | ||
| 444 : | INIT_MM_PLAY_RECORD_LIST(&playRecordList_[count]); | ||
| 445 : | playRecordList_[count].ItemType = EMM_MEDIA_TYPE_VIDEO; | ||
| 446 : | playRecordList_[count].list = &videoMediaList_; | ||
| 447 : | playRecordList_[count].ItemChain = EMM_ITEM_EOT; | ||
| 448 : | jtarlton | 548 | } |
| 449 : | jtarlton | 390 | } |
| 450 : | jtarlton | 536 | INIT_MM_PLAY_RECORD_INFO(&playInfo_); |
| 451 : | playInfo_.eFileFormat = EMM_FILE_FORMAT_UNDEFINED; | ||
| 452 : | playInfo_.list = playRecordList_; | ||
| 453 : | jtarlton | 390 | |
| 454 : | if ( mm_Play(devHandle_, &playInfo_, NULL, NULL) == EMM_ERROR ) | ||
| 455 : | { | ||
| 456 : | LOGERROR("mm_Play() failed on device: " << getDeviceName()); | ||
| 457 : | return false; | ||
| 458 : | } | ||
| 459 : | jtarlton | 637 | reason_ = PLAY_END_MEDIA; |
| 460 : | jtarlton | 390 | playActive_ = true; |
| 461 : | amartin | 403 | busy_ = true; |
| 462 : | jtarlton | 390 | return true; |
| 463 : | } | ||
| 464 : | |||
| 465 : | |||
| 466 : | /* | ||
| 467 : | * Start recording. | ||
| 468 : | */ | ||
| 469 : | jtarlton | 455 | bool MmDevice::record( const std::string& audioFile, |
| 470 : | jtarlton | 657 | const std::string& audioEncoding, |
| 471 : | jtarlton | 538 | const std::string& videoFile, |
| 472 : | jtarlton | 657 | const std::string& videoEncoding, |
| 473 : | jtarlton | 663 | unsigned int videoSize, |
| 474 : | bool beep ) | ||
| 475 : | jtarlton | 390 | { |
| 476 : | amartin | 403 | if ( busy_ ) |
| 477 : | { | ||
| 478 : | jtarlton | 657 | pending_.push(MmCommand(MmCommand::RECORD, |
| 479 : | audioFile, | ||
| 480 : | audioEncoding, | ||
| 481 : | videoFile, | ||
| 482 : | videoEncoding, | ||
| 483 : | jtarlton | 663 | videoSize, |
| 484 : | beep)); | ||
| 485 : | amartin | 403 | return true; |
| 486 : | } | ||
| 487 : | |||
| 488 : | jtarlton | 538 | int count = 0; /* index for playRecordList_ */ |
| 489 : | jtarlton | 390 | |
| 490 : | jtarlton | 538 | /* init audio |
| 491 : | jtarlton | 390 | */ |
| 492 : | jtarlton | 538 | if ( !audioFile.empty() ) |
| 493 : | jtarlton | 390 | { |
| 494 : | jtarlton | 538 | INIT_MM_MEDIA_ITEM_LIST(&audioMediaList_); |
| 495 : | INIT_MM_MEDIA_AUDIO(&audioMediaList_.item.audio); | ||
| 496 : | audioMediaList_.ItemChain = EMM_ITEM_EOT; | ||
| 497 : | |||
| 498 : | jtarlton | 657 | if ( audioEncoding == "vox" ) |
| 499 : | jtarlton | 538 | { |
| 500 : | audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_PCM; | ||
| 501 : | audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ; | ||
| 502 : | audioMediaList_.item.audio.codec.unBitsPerSample = 16; | ||
| 503 : | audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX; | ||
| 504 : | audioMediaList_.item.audio.unOffset = 0; | ||
| 505 : | } | ||
| 506 : | jtarlton | 657 | else if ( audioEncoding == "pcma" ) |
| 507 : | jtarlton | 538 | { |
| 508 : | audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_ALAW; | ||
| 509 : | audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ; | ||
| 510 : | audioMediaList_.item.audio.codec.unBitsPerSample = 8; | ||
| 511 : | audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX; | ||
| 512 : | audioMediaList_.item.audio.unOffset = 0; | ||
| 513 : | } | ||
| 514 : | jtarlton | 657 | else if ( audioEncoding == "pcmu" ) |
| 515 : | jtarlton | 538 | { |
| 516 : | audioMediaList_.item.audio.codec.unCoding = MM_DATA_FORMAT_MULAW; | ||
| 517 : | audioMediaList_.item.audio.codec.unSampleRate = MM_DRT_8KHZ; | ||
| 518 : | audioMediaList_.item.audio.codec.unBitsPerSample = 8; | ||
| 519 : | audioMediaList_.item.audio.eFileFormat = EMM_AUD_FILEFORMAT_VOX; | ||
| 520 : | audioMediaList_.item.audio.unOffset = 0; | ||
| 521 : | } | ||
| 522 : | jtarlton | 390 | else |
| 523 : | { | ||
| 524 : | jtarlton | 538 | return false; |
| 525 : | jtarlton | 390 | } |
| 526 : | jtarlton | 538 | |
| 527 : | jtarlton | 663 | audioMediaList_.item.audio.unMode = MM_MODE_AUD_FILE_TYPE_VOX | MM_MODE_AUD_AGC_ON; |
| 528 : | if ( beep ) | ||
| 529 : | { | ||
| 530 : | audioMediaList_.item.audio.unMode |= MM_MODE_AUD_BEEPINITIATED; | ||
| 531 : | } | ||
| 532 : | jtarlton | 657 | audioMediaList_.item.audio.szFileName = audioFile.c_str(); |
| 533 : | jtarlton | 538 | |
| 534 : | INIT_MM_PLAY_RECORD_LIST(&playRecordList_[count]); | ||
| 535 : | playRecordList_[count].ItemType = EMM_MEDIA_TYPE_AUDIO; | ||
| 536 : | playRecordList_[count].list = &audioMediaList_; | ||
| 537 : | playRecordList_[count].ItemChain = EMM_ITEM_EOT; | ||
| 538 : | jtarlton | 390 | } |
| 539 : | jtarlton | 538 | |
| 540 : | /* init video | ||
| 541 : | */ | ||
| 542 : | if ( !videoFile.empty() ) | ||
| 543 : | jtarlton | 390 | { |
| 544 : | jtarlton | 538 | INIT_MM_MEDIA_ITEM_LIST(&videoMediaList_); |
| 545 : | INIT_MM_MEDIA_VIDEO(&videoMediaList_.item.video); | ||
| 546 : | videoMediaList_.ItemChain = EMM_ITEM_EOT; | ||
| 547 : | |||
| 548 : | jtarlton | 657 | if ( videoEncoding == "mpv4-es" ) |
| 549 : | jtarlton | 390 | { |
| 550 : | jtarlton | 657 | if ( videoSize == VIDEO_IMAGE_WIDTH_352 ) |
| 551 : | jtarlton | 538 | { |
| 552 : | videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES; | ||
| 553 : | videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP3_MPEG4; | ||
| 554 : | videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352; | ||
| 555 : | videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_288; | ||
| 556 : | videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15; | ||
| 557 : | } | ||
| 558 : | else | ||
| 559 : | { | ||
| 560 : | videoMediaList_.item.video.codec.Coding = VIDEO_CODING_MP4V_ES; | ||
| 561 : | videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_LEVEL_SP1_MPEG4; | ||
| 562 : | videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176; | ||
| 563 : | videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_144; | ||
| 564 : | videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15; | ||
| 565 : | } | ||
| 566 : | jtarlton | 390 | } |
| 567 : | jtarlton | 538 | else /* h263 */ |
| 568 : | { | ||
| 569 : | jtarlton | 657 | if ( videoSize == VIDEO_IMAGE_WIDTH_352 ) |
| 570 : | jtarlton | 538 | { |
| 571 : | videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263; | ||
| 572 : | videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263; | ||
| 573 : | videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_352; | ||
| 574 : | videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_288; | ||
| 575 : | videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_15; | ||
| 576 : | } | ||
| 577 : | else | ||
| 578 : | { | ||
| 579 : | videoMediaList_.item.video.codec.Coding = VIDEO_CODING_H263; | ||
| 580 : | videoMediaList_.item.video.codec.Profile = VIDEO_PROFILE_0_H263; | ||
| 581 : | videoMediaList_.item.video.codec.ImageWidth = VIDEO_IMAGE_WIDTH_176; | ||
| 582 : | videoMediaList_.item.video.codec.ImageHeight = VIDEO_IMAGE_HEIGHT_144; | ||
| 583 : | videoMediaList_.item.video.codec.FramesPerSec = VIDEO_FRAMESPERSEC_10; | ||
| 584 : | } | ||
| 585 : | } | ||
| 586 : | jtarlton | 390 | |
| 587 : | jtarlton | 665 | videoMediaList_.item.video.unMode = beep ? 0 : MM_MODE_VID_NOIFRMBEEPINITIATED; |
| 588 : | jtarlton | 657 | videoMediaList_.item.video.szFileName = videoFile.c_str(); |
| 589 : | jtarlton | 647 | |
| 590 : | jtarlton | 538 | /* append */ |
| 591 : | playRecordList_[count++].ItemChain = EMM_ITEM_CONT; | ||
| 592 : | jtarlton | 390 | |
| 593 : | jtarlton | 538 | INIT_MM_PLAY_RECORD_LIST(&playRecordList_[count]); |
| 594 : | playRecordList_[count].ItemType = EMM_MEDIA_TYPE_VIDEO; | ||
| 595 : | playRecordList_[count].list = &videoMediaList_; | ||
| 596 : | playRecordList_[count].ItemChain = EMM_ITEM_EOT; | ||
| 597 : | } | ||
| 598 : | jtarlton | 390 | |
| 599 : | jtarlton | 393 | INIT_MM_RECORD_INFO(&recordInfo_); |
| 600 : | jtarlton | 390 | recordInfo_.eFileFormat = EMM_FILE_FORMAT_UNDEFINED; |
| 601 : | recordInfo_.list = playRecordList_; | ||
| 602 : | |||
| 603 : | jtarlton | 640 | LOGINFO("MmDevice::record() device: " << getDeviceName() << |
| 604 : | " a=" << audioMediaList_.item.audio.szFileName << | ||
| 605 : | ", v=" << videoMediaList_.item.video.szFileName); | ||
| 606 : | jtarlton | 538 | |
| 607 : | jtarlton | 390 | if ( mm_Record(devHandle_, &recordInfo_, NULL, 0) == EMM_ERROR ) |
| 608 : | { | ||
| 609 : | LOGERROR("mm_Record() failed on device: " << getDeviceName()); | ||
| 610 : | return false; | ||
| 611 : | } | ||
| 612 : | jtarlton | 637 | reason_ = RECORD_STOPPED; |
| 613 : | jtarlton | 390 | recordActive_ = true; |
| 614 : | amartin | 403 | busy_ = true; |
| 615 : | jtarlton | 390 | return true; |
| 616 : | } | ||
| 617 : | |||
| 618 : | |||
| 619 : | /* | ||
| 620 : | * Stop current play. | ||
| 621 : | */ | ||
| 622 : | jtarlton | 637 | bool MmDevice::stopPlay( const std::string& reason ) |
| 623 : | jtarlton | 390 | { |
| 624 : | jtarlton | 642 | if ( busy_ ) |
| 625 : | { | ||
| 626 : | pending_.push(MmCommand(MmCommand::STOPPLAY, reason)); | ||
| 627 : | return true; | ||
| 628 : | } | ||
| 629 : | jtarlton | 390 | if ( playActive_ ) |
| 630 : | { | ||
| 631 : | jtarlton | 626 | LOGDEBUG("MmDevice::stopPlay() device: " << getDeviceName()); |
| 632 : | jtarlton | 455 | |
| 633 : | jtarlton | 390 | MM_STOP_DETAILS mmStopDetails; |
| 634 : | jtarlton | 626 | INIT_MM_STOP_DETAILS(&mmStopDetails); |
| 635 : | jtarlton | 390 | |
| 636 : | jtarlton | 626 | MM_STOP mmStopInfo[2]; |
| 637 : | |||
| 638 : | INIT_MM_STOP(&mmStopInfo[0]); | ||
| 639 : | jtarlton | 390 | mmStopInfo[0].ItemChain = EMM_ITEM_CONT; |
| 640 : | mmStopInfo[0].ItemType = EMM_STOP_VIDEO_PLAY; | ||
| 641 : | mmStopInfo[0].details = mmStopDetails; | ||
| 642 : | mmStopInfo[0].next = &mmStopInfo[1]; | ||
| 643 : | |||
| 644 : | jtarlton | 626 | INIT_MM_STOP(&mmStopInfo[1]); |
| 645 : | jtarlton | 390 | mmStopInfo[1].ItemChain = EMM_ITEM_EOT; |
| 646 : | mmStopInfo[1].ItemType = EMM_STOP_AUDIO_PLAY; | ||
| 647 : | mmStopInfo[1].details = mmStopDetails; | ||
| 648 : | mmStopInfo[1].next = NULL; | ||
| 649 : | |||
| 650 : | if ( mm_Stop(devHandle_, mmStopInfo, NULL) == EMM_ERROR ) | ||
| 651 : | { | ||
| 652 : | LOGERROR("mm_Stop() failed on device: " << getDeviceName()); | ||
| 653 : | return false; | ||
| 654 : | } | ||
| 655 : | jtarlton | 637 | reason_ = reason; |
| 656 : | amartin | 403 | busy_ = true; |
| 657 : | jtarlton | 390 | } |
| 658 : | return true; | ||
| 659 : | } | ||
| 660 : | |||
| 661 : | |||
| 662 : | /* | ||
| 663 : | * Stop current recording. | ||
| 664 : | */ | ||
| 665 : | jtarlton | 637 | bool MmDevice::stopRecord( const std::string& reason ) |
| 666 : | jtarlton | 390 | { |
| 667 : | jtarlton | 642 | if ( busy_ ) |
| 668 : | { | ||
| 669 : | pending_.push(MmCommand(MmCommand::STOPRECORD, reason)); | ||
| 670 : | return true; | ||
| 671 : | } | ||
| 672 : | jtarlton | 390 | if ( recordActive_ ) |
| 673 : | { | ||
| 674 : | jtarlton | 626 | LOGDEBUG("MmDevice::stopRecord() device: " << getDeviceName()); |
| 675 : | jtarlton | 455 | |
| 676 : | jtarlton | 390 | MM_STOP_DETAILS mmStopDetails; |
| 677 : | jtarlton | 626 | INIT_MM_STOP_DETAILS(&mmStopDetails); |
| 678 : | jtarlton | 390 | |
| 679 : | jtarlton | 626 | MM_STOP mmStopInfo[2]; |
| 680 : | |||
| 681 : | INIT_MM_STOP(&mmStopInfo[0]); | ||
| 682 : | jtarlton | 390 | mmStopInfo[0].ItemChain = EMM_ITEM_CONT; |
| 683 : | mmStopInfo[0].ItemType = EMM_STOP_VIDEO_RECORD; | ||
| 684 : | mmStopInfo[0].details = mmStopDetails; | ||
| 685 : | mmStopInfo[0].next = &mmStopInfo[1]; | ||
| 686 : | |||
| 687 : | jtarlton | 626 | INIT_MM_STOP(&mmStopInfo[1]); |
| 688 : | jtarlton | 390 | mmStopInfo[1].ItemChain = EMM_ITEM_EOT; |
| 689 : | mmStopInfo[1].ItemType = EMM_STOP_AUDIO_RECORD; | ||
| 690 : | mmStopInfo[1].details = mmStopDetails; | ||
| 691 : | mmStopInfo[1].next = NULL; | ||
| 692 : | |||
| 693 : | if ( mm_Stop(devHandle_, mmStopInfo, 0) == EMM_ERROR ) | ||
| 694 : | { | ||
| 695 : | LOGERROR("mm_Stop() failed on device: " << getDeviceName()); | ||
| 696 : | return false; | ||
| 697 : | } | ||
| 698 : | jtarlton | 637 | reason_ = reason; |
| 699 : | amartin | 403 | busy_ = true; |
| 700 : | jtarlton | 390 | } |
| 701 : | return true; | ||
| 702 : | } | ||
| 703 : | |||
| 704 : | |||
| 705 : | jtarlton | 597 | /* |
| 706 : | * handle events from Dialogic apiS | ||
| 707 : | */ | ||
| 708 : | bool MmDevice::processEvent( METAEVENT& metaevent ) | ||
| 709 : | { | ||
| 710 : | long evttype = metaevent.evttype; | ||
| 711 : | |||
| 712 : | switch ( evttype ) | ||
| 713 : | { | ||
| 714 : | case MMEV_OPEN: | ||
| 715 : | onOpen(); | ||
| 716 : | break; | ||
| 717 : | |||
| 718 : | case MMEV_PLAY: | ||
| 719 : | /* mm_Play() completed successfully */ | ||
| 720 : | jtarlton | 600 | onPlay(static_cast<MM_PLAY_RECORD_CMPLT*>(sr_getevtdatap())); |
| 721 : | jtarlton | 597 | break; |
| 722 : | |||
| 723 : | jtarlton | 663 | case MMEV_PLAY_FAIL: |
| 724 : | onPlayFail(); | ||
| 725 : | break; | ||
| 726 : | |||
| 727 : | jtarlton | 597 | case MMEV_PLAY_ACK: |
| 728 : | /* mm_Play() started successfully */ | ||
| 729 : | onPlayAck(); | ||
| 730 : | break; | ||
| 731 : | |||
| 732 : | case MMEV_PLAY_ACK_FAIL: | ||
| 733 : | onPlayAckFail(); | ||
| 734 : | break; | ||
| 735 : | |||
| 736 : | case MMEV_RECORD: | ||
| 737 : | jtarlton | 600 | onRecord(static_cast<MM_PLAY_RECORD_CMPLT*>(sr_getevtdatap())); |
| 738 : | jtarlton | 597 | break; |
| 739 : | |||
| 740 : | jtarlton | 663 | case MMEV_RECORD_FAIL: |
| 741 : | onRecordFail(static_cast<MM_PLAY_RECORD_CMPLT*>(sr_getevtdatap())); | ||
| 742 : | break; | ||
| 743 : | |||
| 744 : | jtarlton | 597 | case MMEV_RECORD_ACK: |
| 745 : | jtarlton | 661 | /* mm_Record() started successfully */ |
| 746 : | onRecordAck(); | ||
| 747 : | jtarlton | 597 | break; |
| 748 : | |||
| 749 : | case MMEV_RECORD_ACK_FAIL: | ||
| 750 : | jtarlton | 661 | onRecordAckFail(); |
| 751 : | jtarlton | 597 | break; |
| 752 : | |||
| 753 : | case MMEV_VIDEO_RECORD_STARTED: | ||
| 754 : | LOGDEBUG("MmDevice::processEvent() MMEV_VIDEO_RECORD_STARTED device: " << getDeviceName()); | ||
| 755 : | break; | ||
| 756 : | |||
| 757 : | case MMEV_VIDEO_RECORD_STARTED_FAIL: | ||
| 758 : | jtarlton | 663 | /* |
| 759 : | * intermediate (non-terminating) failure notification event that is | ||
| 760 : | * reserved for future use. | ||
| 761 : | */ | ||
| 762 : | jtarlton | 597 | break; |
| 763 : | |||
| 764 : | case MMEV_STOP_ACK: | ||
| 765 : | onStopAck(); | ||
| 766 : | break; | ||
| 767 : | |||
| 768 : | case MMEV_STOP_ACK_FAIL: | ||
| 769 : | onStopAckFail(); | ||
| 770 : | break; | ||
| 771 : | |||
| 772 : | case MMEV_RESET: | ||
| 773 : | onReset(); | ||
| 774 : | break; | ||
| 775 : | |||
| 776 : | case MMEV_ERROR: | ||
| 777 : | onError(); | ||
| 778 : | break; | ||
| 779 : | |||
| 780 : | case DMEV_PORT_CONNECT: | ||
| 781 : | onPortConnect(); | ||
| 782 : | break; | ||
| 783 : | |||
| 784 : | case DMEV_PORT_CONNECT_FAIL: | ||
| 785 : | onPortConnectFail(); | ||
| 786 : | break; | ||
| 787 : | |||
| 788 : | case DMEV_PORT_DISCONNECT: | ||
| 789 : | onPortDisconnect(); | ||
| 790 : | break; | ||
| 791 : | |||
| 792 : | case DMEV_PORT_DISCONNECT_FAIL: | ||
| 793 : | onPortDisconnectFail(); | ||
| 794 : | break; | ||
| 795 : | |||
| 796 : | case DMEV_GET_TX_PORT_INFO: | ||
| 797 : | jtarlton | 600 | onGetTxPortInfo(static_cast<DM_PORT_INFO_LIST*>(sr_getevtdatap())); |
| 798 : | jtarlton | 597 | break; |
| 799 : | |||
| 800 : | case DMEV_GET_RX_PORT_INFO: | ||
| 801 : | jtarlton | 600 | onGetRxPortInfo(static_cast<DM_PORT_INFO_LIST*>(sr_getevtdatap())); |
| 802 : | jtarlton | 597 | break; |
| 803 : | |||
| 804 : | default: | ||
| 805 : | LOGDEBUG("MmDevice::processEvent() Unhandled event: " << | ||
| 806 : | std::hex << evttype << " " << ATDV_NAMEP(sr_getevtdev())); | ||
| 807 : | break; | ||
| 808 : | } | ||
| 809 : | return true; | ||
| 810 : | } | ||
| 811 : | |||
| 812 : | |||
| 813 : | /* | ||
| 814 : | * Handle MMEV_OPEN event. | ||
| 815 : | */ | ||
| 816 : | void MmDevice::onOpen() | ||
| 817 : | { | ||
| 818 : | jtarlton | 657 | LOGDEBUG("MmDevice::onOpen() MMEV_OPEN device: " << getDeviceName()); |
| 819 : | jtarlton | 597 | |
| 820 : | /* Request port info | ||
| 821 : | */ | ||
| 822 : | if ( dev_GetTransmitPortInfo(devHandle_, this) == -1 ) | ||
| 823 : | { | ||
| 824 : | LOGERROR("dev_GetTransmitPortInfo() failed"); | ||
| 825 : | } | ||
| 826 : | if ( dev_GetReceivePortInfo(devHandle_, this) == -1 ) | ||
| 827 : | { | ||
| 828 : | LOGERROR("dev_GetReceivePortInfo() failed"); | ||
| 829 : | } | ||
| 830 : | } | ||
| 831 : | |||
| 832 : | |||
| 833 : | /* | ||
| 834 : | * Handle DMEV_PORT_CONNECT event. | ||
| 835 : | */ | ||
| 836 : | void MmDevice::onPortConnect() | ||
| 837 : | { | ||
| 838 : | LOGINFO("MmDevice::onPortConnect() device: " << getDeviceName()); | ||
| 839 : | busy_ = false; | ||
| 840 : | processPendingCommand(); | ||
| 841 : | } | ||
| 842 : | |||
| 843 : | |||
| 844 : | /* | ||
| 845 : | * Handle DMEV_PORT_CONNECT_FAIL event. | ||
| 846 : | */ | ||
| 847 : | void MmDevice::onPortConnectFail() | ||
| 848 : | { | ||
| 849 : | LOGWARN("MmDevice::onPortConnectFail() device: " << getDeviceName()); | ||
| 850 : | busy_ = false; | ||
| 851 : | processPendingCommand(); | ||
| 852 : | } | ||
| 853 : | |||
| 854 : | |||
| 855 : | /* | ||
| 856 : | * Handle DMEV_PORT_DISCONNECT event. | ||
| 857 : | */ | ||
| 858 : | void MmDevice::onPortDisconnect() | ||
| 859 : | { | ||
| 860 : | LOGINFO("MmDevice::onPortDisconnect() device: " << getDeviceName()); | ||
| 861 : | busy_ = false; | ||
| 862 : | processPendingCommand(); | ||
| 863 : | } | ||
| 864 : | |||
| 865 : | |||
| 866 : | /* | ||
| 867 : | * Handle DMEV_PORT_DISCONNECT_FAIL event. | ||
| 868 : | */ | ||
| 869 : | void MmDevice::onPortDisconnectFail() | ||
| 870 : | { | ||
| 871 : | LOGWARN("MmDevice::onPortDisconnectFail() device: " << getDeviceName()); | ||
| 872 : | busy_ = false; | ||
| 873 : | processPendingCommand(); | ||
| 874 : | } | ||
| 875 : | |||
| 876 : | |||
| 877 : | /* | ||
| 878 : | jtarlton | 642 | * Handle MMEV_PLAY event. Normal completion, notify channel manager. |
| 879 : | jtarlton | 597 | */ |
| 880 : | void MmDevice::onPlay( MM_PLAY_RECORD_CMPLT* cmplt ) | ||
| 881 : | { | ||
| 882 : | LOGINFO("MmDevice::onPlay() device: " << getDeviceName()); | ||
| 883 : | jtarlton | 661 | #if 0 |
| 884 : | jtarlton | 597 | LOGDEBUG(std::endl << *cmplt); |
| 885 : | jtarlton | 661 | #endif |
| 886 : | jtarlton | 637 | if ( playActive_ ) |
| 887 : | jtarlton | 597 | { |
| 888 : | playActive_ = false; | ||
| 889 : | jtarlton | 640 | |
| 890 : | unsigned int duration = 0; | ||
| 891 : | if ( cmplt->unCount > 0 ) | ||
| 892 : | { | ||
| 893 : | duration = cmplt->details[0].unDuration; | ||
| 894 : | } | ||
| 895 : | channelMgr_.onPlayCompleted(this, reason_, duration); | ||
| 896 : | jtarlton | 597 | } |
| 897 : | } | ||
| 898 : | |||
| 899 : | |||
| 900 : | /* | ||
| 901 : | * Handle MMEV_PLAY_ACK event. | ||
| 902 : | */ | ||
| 903 : | void MmDevice::onPlayAck() | ||
| 904 : | { | ||
| 905 : | LOGINFO("MmDevice::onPlayAck() device: " << getDeviceName()); | ||
| 906 : | jtarlton | 642 | busy_ = false; |
| 907 : | processPendingCommand(); | ||
| 908 : | jtarlton | 597 | } |
| 909 : | |||
| 910 : | |||
| 911 : | /* | ||
| 912 : | * Handle MMEV_PLAY_ACK_FAIL event. | ||
| 913 : | */ | ||
| 914 : | void MmDevice::onPlayAckFail() | ||
| 915 : | { | ||
| 916 : | LOGWARN("MmDevice::onPlayAckFail() device: " << getDeviceName()); | ||
| 917 : | playActive_ = false; | ||
| 918 : | jtarlton | 642 | channelMgr_.onPlayCompleted(this, PLAY_ERROR, 0); |
| 919 : | jtarlton | 597 | busy_ = false; |
| 920 : | processPendingCommand(); | ||
| 921 : | } | ||
| 922 : | |||
| 923 : | |||
| 924 : | /* | ||
| 925 : | * Handle MMEV_PLAY_FAIL event. | ||
| 926 : | */ | ||
| 927 : | void MmDevice::onPlayFail() | ||
| 928 : | { | ||
| 929 : | LOGWARN("MmDevice::onPlayFail() device: " << getDeviceName()); | ||
| 930 : | playActive_ = false; | ||
| 931 : | jtarlton | 640 | channelMgr_.onPlayCompleted(this, PLAY_ERROR, 0); |
| 932 : | jtarlton | 597 | } |
| 933 : | |||
| 934 : | |||
| 935 : | /* | ||
| 936 : | jtarlton | 642 | * Handle MMEV_RECORD event. Normal completion, notify channel manager. |
| 937 : | jtarlton | 597 | */ |
| 938 : | void MmDevice::onRecord( MM_PLAY_RECORD_CMPLT* cmplt ) | ||
| 939 : | { | ||
| 940 : | LOGINFO("MmDevice::onRecord() device: " << getDeviceName()); | ||
| 941 : | jtarlton | 661 | #if 0 |
| 942 : | jtarlton | 597 | LOGDEBUG(std::endl << *cmplt); |
| 943 : | jtarlton | 661 | #endif |
| 944 : | jtarlton | 642 | if ( recordActive_ ) |
| 945 : | jtarlton | 597 | { |
| 946 : | recordActive_ = false; | ||
| 947 : | jtarlton | 640 | |
| 948 : | unsigned int duration = 0; | ||
| 949 : | if ( cmplt->unCount > 0 ) | ||
| 950 : | { | ||
| 951 : | duration = cmplt->details[0].unDuration; | ||
| 952 : | } | ||
| 953 : | channelMgr_.onRecordCompleted(this, reason_, duration); | ||
| 954 : | jtarlton | 597 | } |
| 955 : | } | ||
| 956 : | |||
| 957 : | |||
| 958 : | /* | ||
| 959 : | * Handle MMEV_RECORD_FAIL event. | ||
| 960 : | */ | ||
| 961 : | jtarlton | 663 | void MmDevice::onRecordFail( MM_PLAY_RECORD_CMPLT* cmplt ) |
| 962 : | jtarlton | 597 | { |
| 963 : | jtarlton | 663 | if ( recordActive_ ) |
| 964 : | { | ||
| 965 : | recordActive_ = false; | ||
| 966 : | reason_ = RECORD_ERROR; | ||
| 967 : | |||
| 968 : | unsigned int duration = 0; | ||
| 969 : | if ( cmplt->unCount > 0 ) | ||
| 970 : | { | ||
| 971 : | duration = cmplt->details[0].unDuration; | ||
| 972 : | if ( cmplt->details[0].Reason == EMM_TR_USERSTOP ) | ||
| 973 : | { | ||
| 974 : | reason_ = RECORD_STOPPED; | ||
| 975 : | LOGINFO("MmDevice::onRecordFail() USERSTOP on device: " << getDeviceName()); | ||
| 976 : | } | ||
| 977 : | else | ||
| 978 : | { | ||
| 979 : | LOGWARN("MmDevice::onRecordFail() device: " << getDeviceName()); | ||
| 980 : | LOGDEBUG(std::endl << *cmplt); | ||
| 981 : | } | ||
| 982 : | } | ||
| 983 : | channelMgr_.onRecordCompleted(this, reason_, duration); | ||
| 984 : | } | ||
| 985 : | jtarlton | 597 | } |
| 986 : | |||
| 987 : | |||
| 988 : | /* | ||
| 989 : | jtarlton | 661 | * Handle MMEV_RECORD_ACK event. |
| 990 : | */ | ||
| 991 : | void MmDevice::onRecordAck() | ||
| 992 : | { | ||
| 993 : | LOGINFO("MmDevice::onRecordAck() device: " << getDeviceName()); | ||
| 994 : | busy_ = false; | ||
| 995 : | processPendingCommand(); | ||
| 996 : | } | ||
| 997 : | |||
| 998 : | |||
| 999 : | /* | ||
| 1000 : | * Handle MMEV_RECORD_ACK_FAIL event. | ||
| 1001 : | */ | ||
| 1002 : | void MmDevice::onRecordAckFail() | ||
| 1003 : | { | ||
| 1004 : | LOGWARN("MmDevice::onRecordAckFail() device: " << getDeviceName()); | ||
| 1005 : | jtarlton | 663 | recordActive_ = false; |
| 1006 : | jtarlton | 661 | channelMgr_.onRecordCompleted(this, RECORD_ERROR, 0); |
| 1007 : | busy_ = false; | ||
| 1008 : | processPendingCommand(); | ||
| 1009 : | } | ||
| 1010 : | |||
| 1011 : | |||
| 1012 : | /* | ||
| 1013 : | jtarlton | 597 | * Handle MMEV_STOP_ACK event. |
| 1014 : | */ | ||
| 1015 : | void MmDevice::onStopAck() | ||
| 1016 : | { | ||
| 1017 : | LOGINFO("MmDevice::onStopAck() device: " << getDeviceName()); | ||
| 1018 : | jtarlton | 642 | busy_ = false; |
| 1019 : | processPendingCommand(); | ||
| 1020 : | jtarlton | 597 | } |
| 1021 : | |||
| 1022 : | |||
| 1023 : | /* | ||
| 1024 : | * Handle MMEV_STOP_ACK_FAIL event. | ||
| 1025 : | */ | ||
| 1026 : | void MmDevice::onStopAckFail() | ||
| 1027 : | { | ||
| 1028 : | LOGWARN("MmDevice::onStopAckFail() device: " << getDeviceName()); | ||
| 1029 : | busy_ = false; | ||
| 1030 : | processPendingCommand(); | ||
| 1031 : | } | ||
| 1032 : | |||
| 1033 : | |||
| 1034 : | /* | ||
| 1035 : | * Handle MMEV_RESET event. | ||
| 1036 : | */ | ||
| 1037 : | void MmDevice::onReset() | ||
| 1038 : | { | ||
| 1039 : | LOGINFO("MmDevice::onReset() device: " << getDeviceName()); | ||
| 1040 : | } | ||
| 1041 : | |||
| 1042 : | |||
| 1043 : | /* | ||
| 1044 : | * Handle MMEV_ERROR event. | ||
| 1045 : | */ | ||
| 1046 : | void MmDevice::onError() | ||
| 1047 : | { | ||
| 1048 : | jtarlton | 642 | LOGERROR("MmDevice::onError() device: " << getDeviceName()); |
| 1049 : | jtarlton | 597 | } |
| 1050 : | |||
| 1051 : | |||
| 1052 : | /* | ||
| 1053 : | * Handler for DMEV_GET_TX_PORT_INFO events. | ||
| 1054 : | */ | ||
| 1055 : | void MmDevice::onGetTxPortInfo( DM_PORT_INFO_LIST* portInfoList ) | ||
| 1056 : | { | ||
| 1057 : | LOGINFO("MmDevice::onGetTxPortInfo() device: " << getDeviceName()); | ||
| 1058 : | |||
| 1059 : | txPortInfoList_ = *portInfoList; | ||
| 1060 : | LOGDEBUG(std::endl << txPortInfoList_); | ||
| 1061 : | |||
| 1062 : | for ( unsigned int i = 0; i < txPortInfoList_.unCount; i++ ) | ||
| 1063 : | { | ||
| 1064 : | switch ( txPortInfoList_.port_info[i].port_media_type ) | ||
| 1065 : | { | ||
| 1066 : | case DM_PORT_MEDIA_TYPE_AUDIO: | ||
| 1067 : | audioPortTxInfo_ = txPortInfoList_.port_info[i]; | ||
| 1068 : | break; | ||
| 1069 : | |||
| 1070 : | case DM_PORT_MEDIA_TYPE_VIDEO: | ||
| 1071 : | videoPortTxInfo_ = txPortInfoList_.port_info[i]; | ||
| 1072 : | break; | ||
| 1073 : | |||
| 1074 : | default: | ||
| 1075 : | break; | ||
| 1076 : | } | ||
| 1077 : | } | ||
| 1078 : | } | ||
| 1079 : | |||
| 1080 : | |||
| 1081 : | /* | ||
| 1082 : | * Handler for DMEV_GET_RX_PORT_INFO events. | ||
| 1083 : | */ | ||
| 1084 : | void MmDevice::onGetRxPortInfo( DM_PORT_INFO_LIST* portInfoList ) | ||
| 1085 : | { | ||
| 1086 : | LOGINFO("MmDevice::onGetRxPortInfo() device: " << getDeviceName()); | ||
| 1087 : | |||
| 1088 : | rxPortInfoList_ = *portInfoList; | ||
| 1089 : | LOGDEBUG(std::endl << rxPortInfoList_); | ||
| 1090 : | |||
| 1091 : | for ( unsigned int i = 0; i < rxPortInfoList_.unCount; i++ ) | ||
| 1092 : | { | ||
| 1093 : | switch ( rxPortInfoList_.port_info[i].port_media_type ) | ||
| 1094 : | { | ||
| 1095 : | case DM_PORT_MEDIA_TYPE_AUDIO: | ||
| 1096 : | audioPortRxInfo_ = rxPortInfoList_.port_info[i]; | ||
| 1097 : | break; | ||
| 1098 : | |||
| 1099 : | case DM_PORT_MEDIA_TYPE_VIDEO: | ||
| 1100 : | videoPortRxInfo_ = rxPortInfoList_.port_info[i]; | ||
| 1101 : | break; | ||
| 1102 : | |||
| 1103 : | default: | ||
| 1104 : | break; | ||
| 1105 : | } | ||
| 1106 : | } | ||
| 1107 : | } | ||
| 1108 : | |||
| 1109 : | |||
| 1110 : | amartin | 378 | /* vim:ts=4:set nu: |
| 1111 : | * EOF | ||
| 1112 : | */ |
| No admin address has been configured | ViewVC Help |
| Powered by ViewVC 1.0.8 |