- Timestamp:
- Aug 31, 2007 3:04:52 PM (17 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 4 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/symbian_sound.cpp
r1242 r1428 116 116 117 117 118 /* 119 * Utility: print sound device error 120 */ 121 static void snd_perror(const char *title, TInt rc) 122 { 123 PJ_LOG(1,(THIS_FILE, "%s: error code %d", title, rc)); 124 } 125 118 126 ////////////////////////////////////////////////////////////////////////////// 119 127 // … … 122 130 * Implementation: Symbian Input Stream. 123 131 */ 124 class CPjAudioInputEngine : public MMdaAudioInputStreamCallback132 class CPjAudioInputEngine : public CBase, MMdaAudioInputStreamCallback 125 133 { 126 134 public: … … 144 152 void Stop(); 145 153 146 p ublic:154 private: 147 155 State state_; 148 156 pjmedia_snd_stream *parentStrm_; … … 159 167 void *user_data); 160 168 void ConstructL(); 169 TPtr8 & GetFrame(); 161 170 162 171 public: … … 172 181 void *user_data) 173 182 : state_(STATE_INACTIVE), parentStrm_(parent_strm), recCb_(rec_cb), 174 iInputStream_(NULL), iStreamBuffer_(NULL), iFramePtr_( NULL, 0),183 iInputStream_(NULL), iStreamBuffer_(NULL), iFramePtr_(0, 0), 175 184 userData_(user_data), lastError_(KErrNone), timeStamp_(0) 176 185 { … … 181 190 Stop(); 182 191 delete iStreamBuffer_; 192 iStreamBuffer_ = NULL; 183 193 } 184 194 185 195 void CPjAudioInputEngine::ConstructL() 186 196 { 187 iStreamBuffer_ = HBufC8::New MaxL(parentStrm_->samples_per_frame *188 189 197 iStreamBuffer_ = HBufC8::NewL(parentStrm_->samples_per_frame * 198 parentStrm_->channel_count * 199 BYTES_PER_SAMPLE); 190 200 } 191 201 … … 242 252 iStreamSettings.iSampleRate != 0); 243 253 244 // Create timeout timer to wait for Open to complete245 RTimer timer;246 TRequestStatus reqStatus;247 TInt rc;248 249 rc = timer.CreateLocal();250 if (rc != KErrNone) {251 delete iInputStream_;252 iInputStream_ = NULL;253 return PJ_RETURN_OS_ERROR(rc);254 }255 256 254 PJ_LOG(4,(THIS_FILE, "Opening sound device for capture, " 257 255 "clock rate=%d, channel count=%d..", … … 262 260 lastError_ = KRequestPending; 263 261 iInputStream_->Open(&iStreamSettings); 264 265 // Wait until callback is called. 266 if (lastError_ == KRequestPending) { 267 timer.After(reqStatus, 5 * 1000 * 1000); 268 269 do { 270 User::WaitForAnyRequest(); 271 } while (lastError_==KRequestPending && reqStatus==KRequestPending); 272 273 if (reqStatus==KRequestPending) 274 timer.Cancel(); 275 } 276 277 // Close timer 278 timer.Close(); 279 280 // Handle timeout 281 if (lastError_ == KRequestPending) { 282 iInputStream_->Stop(); 283 delete iInputStream_; 284 iInputStream_ = NULL; 285 return PJ_ETIMEDOUT; 286 } 287 else if (lastError_ != KErrNone) { 288 // Handle failure. 289 delete iInputStream_; 290 iInputStream_ = NULL; 291 return PJ_RETURN_OS_ERROR(lastError_); 292 } 293 294 // Feed the first frame. 295 iFramePtr_ = iStreamBuffer_->Des(); 296 iInputStream_->ReadL(iFramePtr_); 297 262 298 263 // Success 299 264 PJ_LOG(4,(THIS_FILE, "Sound capture started.")); … … 323 288 324 289 290 TPtr8 & CPjAudioInputEngine::GetFrame() 291 { 292 TInt l = parentStrm_->samples_per_frame * 293 parentStrm_->channel_count * 294 BYTES_PER_SAMPLE; 295 iStreamBuffer_->Des().FillZ(l); 296 iFramePtr_.Set((TUint8*)(iStreamBuffer_->Ptr()), l, l); 297 return iFramePtr_; 298 } 299 325 300 void CPjAudioInputEngine::MaiscOpenComplete(TInt aError) 326 301 { 327 302 lastError_ = aError; 303 if (aError != KErrNone) { 304 snd_perror("Error in MaiscOpenComplete()", aError); 305 return; 306 } 307 308 // set stream priority to normal and time sensitive 309 iInputStream_->SetPriority(EPriorityNormal, 310 EMdaPriorityPreferenceTime); 311 312 // Read the first frame. 313 TPtr8 & frm = GetFrame(); 314 TRAPD(err2, iInputStream_->ReadL(frm)); 315 if (err2) { 316 PJ_LOG(4,(THIS_FILE, "Exception in iInputStream_->ReadL()")); 317 } 328 318 } 329 319 … … 332 322 { 333 323 lastError_ = aError; 334 if (aError != KErrNone) 324 if (aError != KErrNone) { 325 snd_perror("Error in MaiscBufferCopied()", aError); 335 326 return; 327 } 336 328 337 329 // Call the callback. … … 342 334 343 335 // Record next frame 344 iFramePtr_ = iStreamBuffer_->Des(); 345 iInputStream_->ReadL(iFramePtr_); 336 TPtr8 & frm = GetFrame(); 337 TRAPD(err2, iInputStream_->ReadL(frm)); 338 if (err2) { 339 PJ_LOG(4,(THIS_FILE, "Exception in iInputStream_->ReadL()")); 340 } 346 341 } 347 342 … … 351 346 lastError_ = aError; 352 347 state_ = STATE_INACTIVE; 348 if (aError != KErrNone) { 349 snd_perror("Error in MaiscRecordComplete()", aError); 350 } 353 351 } 354 352 … … 362 360 */ 363 361 364 class CPjAudioOutputEngine : public MMdaAudioOutputStreamCallback362 class CPjAudioOutputEngine : public CBase, MMdaAudioOutputStreamCallback 365 363 { 366 364 public: … … 384 382 void Stop(); 385 383 386 p ublic:384 private: 387 385 State state_; 388 386 pjmedia_snd_stream *parentStrm_; … … 392 390 TUint8 *frameBuf_; 393 391 unsigned frameBufSize_; 392 TPtrC8 frame_; 394 393 TInt lastError_; 395 394 unsigned timestamp_; … … 480 479 parentStrm_->clock_rate, 481 480 parentStrm_->channel_count)); 482 481 483 482 // Open stream. 484 483 lastError_ = KRequestPending; 485 484 iOutputStream_->Open(&iStreamSettings); 486 487 // Wait until callback is called.488 while (lastError_ == KRequestPending)489 pj_thread_sleep(100);490 491 // Handle failure.492 if (lastError_ != KErrNone) {493 delete iOutputStream_;494 iOutputStream_ = NULL;495 return PJ_RETURN_OS_ERROR(lastError_);496 }497 485 498 486 // Success … … 561 549 // MMdaAudioOutputStreamCallback::MaoscBufferCopied() 562 550 // until whole data buffer is written. 563 TPtrC8 frame(frameBuf_, frameBufSize_); 564 iOutputStream_->WriteL(frame); 565 } 551 frame_.Set(frameBuf_, frameBufSize_); 552 iOutputStream_->WriteL(frame_); 553 } else { 554 snd_perror("Error in MaoscOpenComplete()", aError); 555 } 566 556 } 567 557 … … 587 577 588 578 // Write to playback stream. 589 TPtrC8 frame(frameBuf_, frameBufSize_);590 iOutputStream_->WriteL(frame );579 frame_.Set(frameBuf_, frameBufSize_); 580 iOutputStream_->WriteL(frame_); 591 581 592 582 } else if (aError==KErrAbort) { … … 597 587 lastError_ = aError; 598 588 state_ = STATE_INACTIVE; 589 snd_perror("Error in MaoscBufferCopied()", aError); 599 590 } 600 591 } … … 604 595 lastError_ = aError; 605 596 state_ = STATE_INACTIVE; 597 if (aError != KErrNone) { 598 snd_perror("Error in MaoscPlayComplete()", aError); 599 } 606 600 } 607 601 … … 656 650 pjmedia_snd_stream *strm; 657 651 652 if (index==-1) index = 0; 653 658 654 PJ_ASSERT_RETURN(index == 0, PJ_EINVAL); 659 655 PJ_ASSERT_RETURN(clock_rate && channel_count && samples_per_frame && … … 672 668 strm->samples_per_frame = samples_per_frame; 673 669 674 TMdaAudioDataSettings settings;675 TInt clockRateCap, channelCountCap;676 677 clockRateCap = get_clock_rate_cap(clock_rate);678 channelCountCap = get_channel_cap(channel_count);679 680 670 PJ_ASSERT_RETURN(bits_per_sample == 16, PJ_EINVAL); 681 PJ_ASSERT_RETURN( clockRateCap!= 0, PJ_EINVAL);682 PJ_ASSERT_RETURN( channelCountCap!= 0, PJ_EINVAL);671 PJ_ASSERT_RETURN(get_clock_rate_cap(clock_rate) != 0, PJ_EINVAL); 672 PJ_ASSERT_RETURN(get_channel_cap(channel_count) != 0, PJ_EINVAL); 683 673 684 674 // Create the input stream. … … 708 698 pjmedia_snd_stream *strm; 709 699 700 if (index == -1) index = 0; 701 710 702 PJ_ASSERT_RETURN(index == 0, PJ_EINVAL); 711 703 PJ_ASSERT_RETURN(clock_rate && channel_count && samples_per_frame && … … 724 716 strm->samples_per_frame = samples_per_frame; 725 717 726 TMdaAudioDataSettings settings;727 TInt clockRateCap, channelCountCap;728 729 clockRateCap = get_clock_rate_cap(clock_rate);730 channelCountCap = get_channel_cap(channel_count);731 732 718 PJ_ASSERT_RETURN(bits_per_sample == 16, PJ_EINVAL); 733 PJ_ASSERT_RETURN( clockRateCap!= 0, PJ_EINVAL);734 PJ_ASSERT_RETURN( channelCountCap!= 0, PJ_EINVAL);719 PJ_ASSERT_RETURN(get_clock_rate_cap(clock_rate) != 0, PJ_EINVAL); 720 PJ_ASSERT_RETURN(get_channel_cap(channel_count) != 0, PJ_EINVAL); 735 721 736 722 // Create the output stream. … … 761 747 pjmedia_snd_stream *strm; 762 748 749 if (rec_id == -1) rec_id = 0; 750 if (play_id == -1) play_id = 0; 751 763 752 PJ_ASSERT_RETURN(rec_id == 0 && play_id == 0, PJ_EINVAL); 764 753 PJ_ASSERT_RETURN(clock_rate && channel_count && samples_per_frame && … … 778 767 strm->samples_per_frame = samples_per_frame; 779 768 780 TMdaAudioDataSettings settings;781 TInt clockRateCap, channelCountCap;782 783 clockRateCap = get_clock_rate_cap(clock_rate);784 channelCountCap = get_channel_cap(channel_count);785 786 769 PJ_ASSERT_RETURN(bits_per_sample == 16, PJ_EINVAL); 787 PJ_ASSERT_RETURN( clockRateCap!= 0, PJ_EINVAL);788 PJ_ASSERT_RETURN( channelCountCap!= 0, PJ_EINVAL);770 PJ_ASSERT_RETURN(get_clock_rate_cap(clock_rate) != 0, PJ_EINVAL); 771 PJ_ASSERT_RETURN(get_channel_cap(channel_count) != 0, PJ_EINVAL); 789 772 790 773 // Create the output stream. … … 796 779 } 797 780 781 // Create the input stream. 782 TRAPD(err1, strm->inEngine = CPjAudioInputEngine::NewL(strm, rec_cb, 783 user_data)); 784 if (err1 != KErrNone) { 785 strm->inEngine = NULL; 786 delete strm->outEngine; 787 strm->outEngine = NULL; 788 pj_pool_release(pool); 789 return PJ_RETURN_OS_ERROR(err1); 790 } 791 798 792 // Done. 799 793 *p_snd_strm = strm; … … 807 801 808 802 PJ_ASSERT_RETURN(stream != NULL, PJ_EINVAL); 803 804 if (stream->outEngine) { 805 status = stream->outEngine->StartPlay(); 806 if (status != PJ_SUCCESS) 807 return status; 808 } 809 809 810 810 if (stream->inEngine) { … … 814 814 } 815 815 816 if (stream->outEngine) {817 status = stream->outEngine->StartPlay();818 if (status != PJ_SUCCESS)819 return status;820 }821 822 816 return PJ_SUCCESS; 823 817 }
Note: See TracChangeset
for help on using the changeset viewer.