Changeset 1641 for pjproject/trunk/pjmedia/src/pjmedia/symbian_sound.cpp
- Timestamp:
- Dec 28, 2007 6:55:02 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/symbian_sound.cpp
r1428 r1641 65 65 66 66 // Common settings. 67 pjmedia_dir dir; 67 68 unsigned clock_rate; 68 69 unsigned channel_count; … … 163 164 pj_uint32_t timeStamp_; 164 165 166 // cache variable 167 // to avoid calculating frame length repeatedly 168 TInt frameLen_; 169 170 // in some SymbianOS (e.g: OSv9.1), sometimes recorded size != requested framesize 171 // so let's provide a buffer to make sure the rec callback returns framesize as requested. 172 TUint8 *frameRecBuf_; 173 TInt frameRecBufLen_; 174 165 175 CPjAudioInputEngine(pjmedia_snd_stream *parent_strm, 166 176 pjmedia_snd_rec_cb rec_cb, … … 180 190 pjmedia_snd_rec_cb rec_cb, 181 191 void *user_data) 182 : state_(STATE_INACTIVE), parentStrm_(parent_strm), recCb_(rec_cb), 192 : state_(STATE_INACTIVE), parentStrm_(parent_strm), 193 recCb_(rec_cb), userData_(user_data), 183 194 iInputStream_(NULL), iStreamBuffer_(NULL), iFramePtr_(0, 0), 184 userData_(user_data), lastError_(KErrNone), timeStamp_(0) 195 lastError_(KErrNone), timeStamp_(0), 196 frameLen_(parent_strm->samples_per_frame * parent_strm->channel_count * BYTES_PER_SAMPLE), 197 frameRecBuf_(NULL), frameRecBufLen_(0) 185 198 { 186 199 } … … 189 202 { 190 203 Stop(); 204 191 205 delete iStreamBuffer_; 192 206 iStreamBuffer_ = NULL; 207 208 delete [] frameRecBuf_; 209 frameRecBuf_ = NULL; 210 frameRecBufLen_ = 0; 193 211 } 194 212 195 213 void CPjAudioInputEngine::ConstructL() 196 214 { 197 iStreamBuffer_ = HBufC8::NewL(parentStrm_->samples_per_frame * 198 parentStrm_->channel_count * 199 BYTES_PER_SAMPLE); 215 iStreamBuffer_ = HBufC8::NewL(frameLen_); 216 CleanupStack::PushL(iStreamBuffer_); 217 218 frameRecBuf_ = new TUint8[frameLen_*2]; 219 CleanupStack::PushL(frameRecBuf_); 200 220 } 201 221 … … 217 237 { 218 238 CPjAudioInputEngine *self = NewLC(parent, rec_cb, user_data); 239 CleanupStack::Pop(self->frameRecBuf_); 240 CleanupStack::Pop(self->iStreamBuffer_); 219 241 CleanupStack::Pop(self); 220 242 return self; … … 290 312 TPtr8 & CPjAudioInputEngine::GetFrame() 291 313 { 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); 314 //iStreamBuffer_->Des().FillZ(frameLen_); 315 iFramePtr_.Set((TUint8*)(iStreamBuffer_->Ptr()), frameLen_, frameLen_); 297 316 return iFramePtr_; 298 317 } … … 327 346 } 328 347 329 // Call the callback. 330 recCb_(userData_, timeStamp_, (void*)aBuffer.Ptr(), aBuffer.Size()); 331 332 // Increment timestamp. 333 timeStamp_ += (aBuffer.Size() * BYTES_PER_SAMPLE); 348 if (frameRecBufLen_ || aBuffer.Size() < frameLen_) { 349 pj_memcpy(frameRecBuf_ + frameRecBufLen_, (void*) aBuffer.Ptr(), aBuffer.Size()); 350 frameRecBufLen_ += aBuffer.Size(); 351 } 352 353 if (frameRecBufLen_) { 354 while (frameRecBufLen_ >= frameLen_) { 355 // Call the callback. 356 recCb_(userData_, timeStamp_, frameRecBuf_, frameLen_); 357 // Increment timestamp. 358 timeStamp_ += parentStrm_->samples_per_frame; 359 360 frameRecBufLen_ -= frameLen_; 361 pj_memmove(frameRecBuf_, frameRecBuf_+frameLen_, frameRecBufLen_); 362 } 363 } else { 364 // Call the callback. 365 recCb_(userData_, timeStamp_, (void*) aBuffer.Ptr(), aBuffer.Size()); 366 // Increment timestamp. 367 timeStamp_ += parentStrm_->samples_per_frame; 368 } 334 369 335 370 // Record next frame … … 526 561 iSettings.iChannels); 527 562 528 // set volume to 1/ 4th of stream max volume529 iOutputStream_->SetVolume(iOutputStream_->MaxVolume()/ 4);563 // set volume to 1/2th of stream max volume 564 iOutputStream_->SetVolume(iOutputStream_->MaxVolume()/2); 530 565 531 566 // set stream priority to normal and time sensitive … … 629 664 { 630 665 /* Always return the default sound device */ 666 if (index == (unsigned)-1) 667 index = 0; 668 631 669 PJ_ASSERT_RETURN(index==0, NULL); 632 670 return &symbian_snd_dev_info; … … 663 701 strm = (pjmedia_snd_stream*) pj_pool_zalloc(pool, 664 702 sizeof(pjmedia_snd_stream)); 703 strm->dir = PJMEDIA_DIR_CAPTURE; 665 704 strm->pool = pool; 666 705 strm->clock_rate = clock_rate; … … 677 716 if (err != KErrNone) { 678 717 pj_pool_release(pool); 679 return PJ_RETURN_OS_ERROR(err); 680 } 681 718 return PJ_RETURN_OS_ERROR(err); 719 } 682 720 683 721 // Done. … … 711 749 strm = (pjmedia_snd_stream*) pj_pool_zalloc(pool, 712 750 sizeof(pjmedia_snd_stream)); 751 strm->dir = PJMEDIA_DIR_PLAYBACK; 713 752 strm->pool = pool; 714 753 strm->clock_rate = clock_rate; … … 762 801 strm = (pjmedia_snd_stream*) pj_pool_zalloc(pool, 763 802 sizeof(pjmedia_snd_stream)); 803 strm->dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; 764 804 strm->pool = pool; 765 805 strm->clock_rate = clock_rate; … … 795 835 } 796 836 837 /* 838 * Get stream info. 839 */ 840 PJ_DEF(pj_status_t) pjmedia_snd_stream_get_info(pjmedia_snd_stream *strm, 841 pjmedia_snd_stream_info *pi) 842 { 843 PJ_ASSERT_RETURN(strm && pi, PJ_EINVAL); 844 845 pj_bzero(pi, sizeof(*pi)); 846 pi->dir = strm->dir; 847 pi->play_id = 0; 848 pi->rec_id = 0; 849 pi->clock_rate = strm->clock_rate; 850 pi->channel_count = strm->channel_count; 851 pi->samples_per_frame = strm->samples_per_frame; 852 pi->bits_per_sample = BYTES_PER_SAMPLE * 8; 853 pi->rec_latency = 0; 854 pi->play_latency = 0; 855 856 return PJ_SUCCESS; 857 } 858 797 859 798 860 PJ_DEF(pj_status_t) pjmedia_snd_stream_start(pjmedia_snd_stream *stream)
Note: See TracChangeset
for help on using the changeset viewer.