static void sound_read_preprocess(MSFilter *f){
	msandroid_sound_read_data *d=(msandroid_sound_read_data*)f->data;
	ms_debug("andsnd_read_preprocess");
	if (!d->started)
		sound_read_setup(f);
	ms_ticker_set_time_func(f->ticker,(uint64_t (*)(void*))ms_ticker_synchronizer_get_corrected_time, d->ticker_synchronizer);
}
static void sound_read_preprocess(MSFilter *f) {
    msandroid_sound_read_data *d=(msandroid_sound_read_data*)f->data;
    ms_debug("andsnd_read_preprocess");
    if (!d->started)
        sound_read_setup(f);
    ms_ticker_set_time_func(f->ticker,(uint64_t (*)(void*))ms_ticker_synchronizer_get_corrected_time, d->ticker_synchronizer);

    if (d->builtin_aec && d->audio_record) {
        //JNIEnv *env=ms_get_jni_env();

        JNIEnv *env = NULL;
        JavaVM *jvm = ms_get_jvm();
        if (jvm->AttachCurrentThread(&env, NULL)!=0) {
            ms_fatal("AttachCurrentThread() failed !");
            return;
        }
        jmethodID getsession_id=0;
        int sessionId=-1;
        getsession_id = env->GetMethodID(d->audio_record_class,"getAudioSessionId", "()I");
        if(getsession_id==0) {
            ms_error("cannot find AudioRecord.getAudioSessionId() method");
            jvm->DetachCurrentThread();
            return;
        }
        sessionId = env->CallIntMethod(d->audio_record,getsession_id);
        ms_message("AudioRecord.getAudioSessionId() returned %i", sessionId);
        if (sessionId==-1) {
            jvm->DetachCurrentThread();
            return;
        }
        d->aec = enable_hardware_echo_canceller(env, sessionId);
        jvm->DetachCurrentThread();
    }
}
示例#3
0
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);
	}
}
示例#4
0
void alsa_read_postprocess(MSFilter *obj){
	AlsaReadData *ad=(AlsaReadData*)obj->data;
#ifdef THREADED_VERSION
	alsa_stop_r(ad);
#endif
	ms_ticker_set_time_func(obj->ticker,NULL,NULL);
	if (ad->handle!=NULL) snd_pcm_close(ad->handle);
	ad->handle=NULL;
}
示例#5
0
static void winsnd_read_preprocess(MSFilter *f){
	WinSnd *d=(WinSnd*)f->data;
	MMRESULT mr;
	int i;
	int bsize;
	DWORD dwFlag;

	d->stat_input=0;
	d->stat_output=0;
	d->stat_notplayed=0;
	d->stat_minimumbuffer=WINSND_MINIMUMBUFFER;

	winsnd_apply_settings(d);
	/* Init Microphone device */
  dwFlag = CALLBACK_FUNCTION | WAVE_FORMAT_DIRECT;
  mr = waveInOpen (&d->indev, d->dev_id, &d->wfx,
              (DWORD) read_callback, (DWORD)f, dwFlag);
	if (mr != MMSYSERR_NOERROR)
	{
    ms_error("Failed to prepare windows sound device. (waveInOpen:0x%i)", mr);
    if (d->dev_id != WAVE_MAPPER)
		    dwFlag = WAVE_MAPPED | CALLBACK_FUNCTION;
    mr = waveInOpen (&d->indev, d->dev_id, &d->wfx,
              (DWORD) read_callback, (DWORD)f, dwFlag);
  }
	if (mr != MMSYSERR_NOERROR)
	{
    ms_error("Failed to prepare windows sound device. (waveInOpen:0x%i)", mr);
		mr = waveInOpen (&d->indev, WAVE_MAPPER, &d->wfx,
					(DWORD) read_callback, (DWORD)f, CALLBACK_FUNCTION);
		if (mr != MMSYSERR_NOERROR)
		{
			d->indev=NULL;
			ms_error("Failed to prepare windows sound device. (waveInOpen:0x%i)", mr);
		    return ;
		}
	}
	bsize=WINSND_NSAMPLES*d->wfx.nAvgBytesPerSec/8000;
	ms_debug("Using input buffers of %i bytes",bsize);
	for(i=0;i<WINSND_NBUFS;++i){
		WAVEHDR *hdr=&d->hdrs_read[i];
		add_input_buffer(d,hdr,bsize);
	}
	d->running=TRUE;
	mr=waveInStart(d->indev);
	if (mr != MMSYSERR_NOERROR){
		ms_error("waveInStart() error");
		return ;
	}
#ifndef _TRUE_TIME
	ms_ticker_set_time_func(f->ticker,winsnd_get_cur_time,d);
#endif
}
static void sound_read_postprocess(MSFilter *f) {
    msandroid_sound_read_data *d=(msandroid_sound_read_data*)f->data;
    jmethodID stop_id=0;
    jmethodID release_id=0;

    //JNIEnv *jni_env = ms_get_jni_env();
    JNIEnv *jni_env = NULL;
    JavaVM *jvm = ms_get_jvm();
    if (jvm->AttachCurrentThread(&jni_env, NULL)!=0) {
        ms_fatal("AttachCurrentThread() failed !");
        return;
    }
    ms_ticker_set_time_func(f->ticker,NULL,NULL);
    d->read_samples=0;

    //stop recording
    stop_id = jni_env->GetMethodID(d->audio_record_class,"stop", "()V");
    if(stop_id==0) {
        ms_error("cannot find AudioRecord.stop() method");
        goto end;
    }

    if (d->aec) {
        delete_hardware_echo_canceller(jni_env, d->aec);
        d->aec = NULL;
    }

    d->started = false;
    if (d->thread_id !=0) ms_thread_join(d->thread_id,0);

    if (d->audio_record) {
        jni_env->CallVoidMethod(d->audio_record,stop_id);

        //release recorder
        release_id = jni_env->GetMethodID(d->audio_record_class,"release", "()V");
        if(release_id==0) {
            ms_error("cannot find AudioRecord.release() method");
            goto end;
        }
        jni_env->CallVoidMethod(d->audio_record,release_id);
    }
    goto end;
end: {
        if (d->audio_record) jni_env->DeleteGlobalRef(d->audio_record);
        jni_env->DeleteGlobalRef(d->audio_record_class);
        if (d->read_buff) jni_env->DeleteGlobalRef(d->read_buff);
        jvm->DetachCurrentThread();
        return;
    }
}
static void sound_read_postprocess(MSFilter *f){
	msandroid_sound_read_data *d=(msandroid_sound_read_data*)f->data;
	jmethodID stop_id=0;
	jmethodID release_id=0;

	JNIEnv *jni_env = ms_get_jni_env();

	ms_ticker_set_time_func(f->ticker,NULL,NULL);
	d->read_samples=0;

	//stop recording
	stop_id = jni_env->GetMethodID(d->audio_record_class,"stop", "()V");
	if(stop_id==0) {
		ms_error("cannot find AudioRecord.stop() method");
		goto end;
	}

	d->started = false;
	if (d->thread_id !=0) ms_thread_join(d->thread_id,0);

	if (d->audio_record) {
		jni_env->CallVoidMethod(d->audio_record,stop_id);

		//release recorder
		release_id = jni_env->GetMethodID(d->audio_record_class,"release", "()V");
		if(release_id==0) {
			ms_error("cannot find AudioRecord.release() method");
			goto end;
		}
		jni_env->CallVoidMethod(d->audio_record,release_id);
	}
	goto end;
	end: {
		if (d->audio_record) jni_env->DeleteGlobalRef(d->audio_record);
		jni_env->DeleteGlobalRef(d->audio_record_class);
		if (d->read_buff) jni_env->DeleteGlobalRef(d->read_buff);
		return;
	}
}
示例#8
0
static void winsnd_read_postprocess(MSFilter *f){
	WinSnd *d=(WinSnd*)f->data;
	MMRESULT mr;
	int i;
#ifndef _TRUE_TIME
	ms_ticker_set_time_func(f->ticker,NULL,NULL);
#endif
	d->running=FALSE;
	mr=waveInStop(d->indev);
	if (mr != MMSYSERR_NOERROR){
		ms_error("waveInStop() error");
		return ;
	}
	mr=waveInReset(d->indev);
	if (mr != MMSYSERR_NOERROR){
		ms_error("waveInReset() error");
		return ;
	}
	for(i=0;i<WINSND_NBUFS;++i){
		WAVEHDR *hdr=&d->hdrs_read[i];
		if (hdr->dwFlags & WHDR_PREPARED)
		{
			mr = waveInUnprepareHeader(d->indev,hdr,sizeof (*hdr));
			if (mr != MMSYSERR_NOERROR){
				ms_error("waveInUnPrepareHeader() error");
			}
		}
	}
	mr = waveInClose(d->indev);
	if (mr != MMSYSERR_NOERROR){
		ms_error("waveInClose() error");
		return ;
	}

	ms_message("Shutting down sound device (playing: %i) (input-output: %i) (notplayed: %i)", d->nbufs_playing, d->stat_input - d->stat_output, d->stat_notplayed);
	flushq(&d->rq,0);
}
示例#9
0
static void winsnd_read_postprocess(MSFilter *f){
	MSSndCard *card=(MSSndCard*)f->data;
	ms_ticker_set_time_func(f->ticker,NULL,NULL);
	winsnd_stop_r(card);
}
示例#10
0
static void winsnd_read_preprocess(MSFilter *f){
	MSSndCard *card=(MSSndCard*)f->data;
	winsnd_start_r(card);
	ms_ticker_set_time_func(f->ticker,winsnd_get_cur_time,card->data);
}