Changeset 3134 for pjproject/trunk
- Timestamp:
- Apr 7, 2010 10:24:41 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-audiodev/symb_aps_dev.cpp
r3116 r3134 45 45 #define BITS_PER_SAMPLE 16 46 46 47 47 48 #if 1 48 49 # define TRACE_(st) PJ_LOG(3, st) … … 414 415 TInt InitRecL(); 415 416 TInt StartStreamL(); 417 void Deinit(); 416 418 417 419 // Inherited from MQueueHandlerObserver … … 420 422 virtual void NotifyError(const TInt aError); 421 423 424 TBool session_opened; 422 425 State state_; 423 426 struct aps_stream *parentStrm_; … … 430 433 RMsgQueue<TAPSCommBuffer> iReadQ; 431 434 RMsgQueue<TAPSCommBuffer> iReadCommQ; 435 TBool readq_opened; 432 436 RMsgQueue<TAPSCommBuffer> iWriteQ; 433 437 RMsgQueue<TAPSCommBuffer> iWriteCommQ; 438 TBool writeq_opened; 434 439 435 440 CQueueHandler *iPlayCommHandler; … … 461 466 const CPjAudioSetting &setting) 462 467 : MQueueHandlerObserver(rec_cb, play_cb, user_data), 468 session_opened(EFalse), 463 469 state_(STATE_NULL), 464 470 parentStrm_(parent_strm), 465 471 setting_(setting), 472 readq_opened(EFalse), 473 writeq_opened(EFalse), 466 474 iPlayCommHandler(0), 467 475 iRecCommHandler(0), … … 472 480 CPjAudioEngine::~CPjAudioEngine() 473 481 { 474 Stop(); 475 476 delete iRecHandler; 477 delete iPlayCommHandler; 478 delete iRecCommHandler; 479 480 // On some devices, immediate closing after stopping may cause APS server 481 // panic KERN-EXEC 0, so let's wait for sometime before really closing 482 // the client session. 483 TTime start, now; 484 enum { APS_CLOSE_WAIT_TIME = 200 }; /* in msecs */ 485 486 start.UniversalTime(); 487 do { 488 pj_symbianos_poll(-1, APS_CLOSE_WAIT_TIME); 489 now.UniversalTime(); 490 } while (now.MicroSecondsFrom(start) < APS_CLOSE_WAIT_TIME * 1000); 491 492 iSession.Close(); 493 494 if (state_ == STATE_READY) { 495 if (parentStrm_->param.dir != PJMEDIA_DIR_PLAYBACK) { 496 iReadQ.Close(); 497 iReadCommQ.Close(); 498 } 499 iWriteQ.Close(); 500 iWriteCommQ.Close(); 501 } 502 482 Deinit(); 483 503 484 TRACE_((THIS_FILE, "Sound device destroyed")); 504 485 } … … 508 489 TInt err = iSession.InitializePlayer(iPlaySettings); 509 490 if (err != KErrNone) { 491 Deinit(); 510 492 snd_perror("Failed to initialize player", err); 511 493 return err; … … 522 504 while (iWriteCommQ.OpenGlobal(buf3)) 523 505 User::After(10); 506 507 writeq_opened = ETrue; 524 508 525 509 // Construct message queue handler … … 538 522 TInt err = iSession.InitializeRecorder(iRecSettings); 539 523 if (err != KErrNone && err != KErrAlreadyExists) { 524 Deinit(); 540 525 snd_perror("Failed to initialize recorder", err); 541 526 return err; … … 554 539 User::After(10); 555 540 541 readq_opened = ETrue; 542 556 543 // Construct message queue handlers 557 544 iRecHandler = CQueueHandler::NewL(this, &iReadQ, NULL, … … 574 561 PJ_ASSERT_RETURN(state_ == STATE_NULL, PJMEDIA_EAUD_INVOP); 575 562 563 if (!session_opened) { 564 TInt err = iSession.Connect(); 565 if (err != KErrNone) 566 return err; 567 session_opened = ETrue; 568 } 569 576 570 // Even if only capturer are opened, playback thread of APS Server need 577 571 // to be run(?). Since some messages will be delivered via play comm queue. … … 593 587 594 588 // Then wait until initialization done. 595 while (state_ != STATE_READY )589 while (state_ != STATE_READY && state_ != STATE_NULL) 596 590 pj_symbianos_poll(-1, 100); 597 591 } … … 618 612 619 613 User::LeaveIfError(iSession.Connect()); 614 session_opened = ETrue; 620 615 } 621 616 … … 648 643 } 649 644 645 void CPjAudioEngine::Deinit() 646 { 647 Stop(); 648 649 delete iRecHandler; 650 delete iPlayCommHandler; 651 delete iRecCommHandler; 652 653 if (session_opened) { 654 TTime start, now; 655 enum { APS_CLOSE_WAIT_TIME = 200 }; /* in msecs */ 656 657 // On some devices, immediate closing after stopping may cause 658 // APS server panic KERN-EXEC 0, so let's wait for sometime before 659 // closing the client session. 660 start.UniversalTime(); 661 do { 662 pj_symbianos_poll(-1, APS_CLOSE_WAIT_TIME); 663 now.UniversalTime(); 664 } while (now.MicroSecondsFrom(start) < APS_CLOSE_WAIT_TIME * 1000); 665 666 iSession.Close(); 667 session_opened = EFalse; 668 } 669 670 if (readq_opened) { 671 iReadQ.Close(); 672 iReadCommQ.Close(); 673 readq_opened = EFalse; 674 } 675 676 if (writeq_opened) { 677 iWriteQ.Close(); 678 iWriteCommQ.Close(); 679 writeq_opened = EFalse; 680 } 681 682 state_ = STATE_NULL; 683 } 684 650 685 void CPjAudioEngine::InputStreamInitialized(const TInt aStatus) 651 686 { … … 659 694 state_ = STATE_READY; 660 695 } 696 } else { 697 Deinit(); 661 698 } 662 699 } … … 676 713 } else 677 714 InitRecL(); 715 } else { 716 Deinit(); 678 717 } 679 718 } … … 681 720 void CPjAudioEngine::NotifyError(const TInt aError) 682 721 { 722 Deinit(); 683 723 snd_perror("Error from CQueueHandler", aError); 684 724 }
Note: See TracChangeset
for help on using the changeset viewer.