Changeset 1031:6b63434d94e0 in mediastreamer2
- Timestamp:
- Jun 29, 2010 2:53:10 PM (3 years ago)
- Branch:
- default
- Children:
- 1032:bcd6c2c5c9ff, 1037:436043572e47
- Location:
- src
- Files:
-
- 2 edited
-
msandroid.cpp (modified) (5 diffs)
-
speexec.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/msandroid.cpp
r1029 r1031 155 155 public: 156 156 msandroid_sound_read_data() : audio_record(0),audio_record_class(0),read_buff(0),read_chunk_size(0),ticker_count(0) { 157 qinit(&rq);157 ms_bufferizer_init(&rb); 158 158 ms_mutex_init(&mutex,NULL); 159 }; 160 ~msandroid_sound_read_data() { 161 ms_mutex_lock(&mutex); 162 flushq(&rq,0); 163 ms_mutex_unlock(&mutex); 164 ms_mutex_destroy(&mutex); 165 } 166 jobject audio_record; 167 jclass audio_record_class; 168 jbyteArray read_buff; 169 ms_mutex_t mutex; 170 queue_t rq; 171 int read_chunk_size; 172 unsigned long ticker_count; 173 174 175 159 } 160 ~msandroid_sound_read_data() { 161 ms_bufferizer_uninit (&rb); 162 ms_mutex_destroy(&mutex); 163 } 164 jobject audio_record; 165 jclass audio_record_class; 166 jbyteArray read_buff; 167 MSBufferizer rb; 168 int read_chunk_size; 169 } 176 170 }; 177 171 … … 210 204 m->b_wptr += nread; 211 205 ms_mutex_lock(&d->mutex); 212 putq(&d->rq,m);206 ms_bufferizer_put (&d->rb,m); 213 207 ms_mutex_unlock(&d->mutex); 214 208 }; … … 252 246 } 253 247 d->buff_size = jni_env->CallStaticIntMethod(d->audio_record_class,min_buff_size_id,d->rate,2/*CHANNEL_CONFIGURATION_MONO*/,2/* ENCODING_PCM_16BIT */); 254 d->read_chunk_size = (d->rate*(d->bits/8)*d->nchannels)*0.02;248 d->read_chunk_size = d->buff_size; 255 249 256 250 if (d->buff_size > 0) { … … 357 351 msandroid_sound_read_data *d=(msandroid_sound_read_data*)f->data; 358 352 mblk_t *m; 359 360 ms_mutex_lock(&d->mutex); 361 m=peekq(&d->rq); 362 363 if (d->ticker_count!=0 || m!=NULL){ 364 //start incrementing the first time we have a packet 365 d->ticker_count++; 366 } 367 // get buffer only every 2 ticks + alpha 368 if (m != NULL && ((d->ticker_count % 2)==1 || (d->ticker_count % 50)==0 ) ) { 369 m=getq(&d->rq); 370 ms_queue_put(f->outputs[0],m); 371 } 372 ms_mutex_unlock(&d->mutex); 373 353 int nbytes=0.02*(float)d->rate*2.0*(float)d->nchannels; 354 355 // output a buffer only every 2 ticks + alpha 356 if ((f->ticker->time % 20)==0 || (f->ticker->time % 510)==0){ 357 mblk_t *om=allocb(nbytes,0); 358 int err; 359 ms_mutex_lock(&d->mutex); 360 err=ms_bufferizer_read(&d->rb,om->b_wptr,nbytes); 361 if (err==nbytes){ 362 ms_mutex_unlock(&d->mutex); 363 om->b_wptr+=nbytes; 364 ms_queue_put(f->outputs[0],om); 365 }else freemsg(om); 366 } 374 367 } 375 368 … … 656 649 void msandroid_sound_write_process(MSFilter *f){ 657 650 msandroid_sound_write_data *d=(msandroid_sound_write_data*)f->data; 658 if (d->started == false) return;651 659 652 mblk_t *m; 660 653 while((m=ms_queue_get(f->inputs[0]))!=NULL){ 661 ms_mutex_lock(&d->mutex); 662 ms_bufferizer_put(d->bufferizer,m); 663 ms_cond_signal(&d->cond); 664 ms_mutex_unlock(&d->mutex); 654 if (d->started){ 655 ms_mutex_lock(&d->mutex); 656 ms_bufferizer_put(d->bufferizer,m); 657 ms_cond_signal(&d->cond); 658 ms_mutex_unlock(&d->mutex); 659 }else freemsg(m); 665 660 } 666 661 } -
src/speexec.c
r1029 r1031 59 59 int tail_length_ms; 60 60 bool_t using_silence; 61 bool_t echostarted; 61 62 }SpeexECState; 62 63 … … 74 75 s->den = NULL; 75 76 s->using_silence=FALSE; 77 s->echostarted=FALSE; 76 78 77 79 f->data=s; … … 91 93 mblk_t *m; 92 94 95 s->echostarted=FALSE; 93 96 s->filterlength=(s->tail_length_ms*s->samplerate)/1000; 94 97 delay_samples=s->delay_ms*s->samplerate/1000; … … 116 119 int size; 117 120 121 if (f->inputs[1]!=NULL){ 122 int maxsize; 123 ms_bufferizer_put_from_queue (&s->echo,f->inputs[1]); 124 maxsize=ms_bufferizer_get_avail(&s->echo); 125 if (s->echostarted==FALSE && maxsize>0){ 126 s->echostarted=TRUE; 127 } 128 if (maxsize>=s->ref_bytes_limit){ 129 ms_message("ref_bytes_limit adjusted from %i to %i",s->ref_bytes_limit,maxsize); 130 s->ref_bytes_limit=maxsize; 131 } 132 } 133 118 134 if (f->inputs[0]!=NULL){ 119 135 while((refm=ms_queue_get(f->inputs[0]))!=NULL){ … … 123 139 } 124 140 } 125 if (f->inputs[1]!=NULL){ 126 int maxsize; 127 ms_bufferizer_put_from_queue (&s->echo,f->inputs[1]); 128 if ((maxsize=ms_bufferizer_get_avail(&s->echo))>=s->ref_bytes_limit){ 129 ms_message("ref_bytes_limit adjusted from %i to %i",s->ref_bytes_limit,maxsize); 130 s->ref_bytes_limit=maxsize; 131 } 132 } 141 133 142 /* 134 143 ms_message("echo bytes=%i, ref bytes=%i",ms_bufferizer_get_avail(&s->echo), … … 162 171 ms_queue_put(f->outputs[1],oecho); 163 172 } 173 if (!s->echostarted){ 174 /*if we have not yet receive anything from the soundcard, bypass the reference signal*/ 175 while (ms_bufferizer_get_avail(&s->ref)>=nbytes){ 176 mblk_t *oref=allocb(nbytes,0); 177 ms_bufferizer_read(&s->ref,oref->b_wptr,nbytes); 178 oref->b_wptr+=nbytes; 179 ms_bufferizer_skip_bytes(&s->delayed_ref,nbytes); 180 ms_queue_put(f->outputs[0],oref); 181 } 182 } 183 164 184 /* do not accumulate too much reference signal */ 165 185 if ((size=ms_bufferizer_get_avail(&s->ref))> (s->ref_bytes_limit+nbytes)) {
Note: See TracChangeset
for help on using the changeset viewer.
