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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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