void alsa_read_process(MSFilter *obj){ AlsaReadData *ad=(AlsaReadData*)obj->data; #ifdef AMD_HACK int samples=(160*ad->rate)/8000; #else int samples=(128*ad->rate)/8000; #endif int err; mblk_t *om=NULL; if (ad->handle==NULL && ad->pcmdev!=NULL){ ad->handle=alsa_open_r(ad->pcmdev,16,ad->nchannels==2,ad->rate); } if (ad->handle==NULL) return; while (alsa_can_read(ad->handle,samples)){ int size=samples*2; om=allocb(size,0); if ((err=alsa_read(ad->handle,om->b_wptr,samples))<=0) { ms_warning("Fail to read samples"); freemsg(om); return; } size=err*2; om->b_wptr+=size; /*ms_message("alsa_read_process: Outputing %i bytes",size);*/ ms_queue_put(obj->outputs[0],om); #ifdef AMD_HACK break; #endif } }
void alsa_read_process(MSFilter *obj){ AlsaReadData *ad=(AlsaReadData*)obj->data; int samples=(128*ad->rate)/8000; int err; mblk_t *om=NULL; if (ad->handle==NULL && ad->pcmdev!=NULL && !ad->read_started){ ad->read_started=TRUE; ad->handle=alsa_open_r(ad->pcmdev,16,ad->nchannels==2,ad->rate); if (ad->handle){ ad->read_samples=0; ms_ticker_set_time_func(obj->ticker,(uint64_t (*)(void*))ms_ticker_synchronizer_get_corrected_time, ad->ticker_synchronizer); } } if (ad->handle==NULL) return; while (alsa_can_read(ad->handle)>=samples){ int size=samples*2*ad->nchannels; om=allocb(size,0); if ((err=alsa_read(ad->handle,om->b_wptr,samples))<=0) { ms_warning("Fail to read samples"); freemsg(om); return; } ad->read_samples+=err; size=err*2*ad->nchannels; om->b_wptr+=size; compute_timespec(ad); /*ms_message("alsa_read_process: Outputing %i bytes",size);*/ ms_queue_put(obj->outputs[0],om); } }
static void * alsa_write_thread(void *p){ AlsaReadData *ad=(AlsaReadData*)p; int samples=(160*ad->rate)/8000; int err; int count=0; mblk_t *om=NULL; struct timeval timeout; if (ad->handle==NULL && ad->pcmdev!=NULL){ ad->handle=alsa_open_r(ad->pcmdev,16,ad->nchannels==2,ad->rate); } if (ad->handle==NULL) return NULL; while (ad->read_started) { count = alsa_can_read(ad->handle,samples); if (count==24) { /* keep this value for this driver */ } else if (count<=0) { count = samples; } else if (count>0) { //ms_warning("%i count", count); //count = samples; } int size=count*2; om=allocb(size,0); if ((err=alsa_read(ad->handle,om->b_wptr,count))<=0) { ms_warning("nothing to read"); //ms_warning("Fail to read samples %i", count); continue; } //ms_warning(" read %i", err); size=err*2; om->b_wptr+=size; ms_mutex_lock(&ad->mutex); ms_bufferizer_put(ad->bufferizer,om); ms_mutex_unlock(&ad->mutex); if (count==24) { timeout.tv_sec = 0; timeout.tv_usec = 2000; select(0, 0, NULL, NULL, &timeout ); } else { /* select will be less active than locking on "read" */ timeout.tv_sec = 0; timeout.tv_usec = 5000; select(0, 0, NULL, NULL, &timeout ); } } if (ad->handle!=NULL) snd_pcm_close(ad->handle); ad->handle=NULL; return NULL; }