Commit 44d29b3d authored by Simon Morlat's avatar Simon Morlat

automatic configuration of echo cancellation upon latency of android sound reader

parent 95285b1b
......@@ -469,6 +469,8 @@ the method index (_cnt_) and the argument size */
#define MS_FILTER_ADD_ATTR MS_FILTER_BASE_METHOD(8,const char)
#define MS_FILTER_SET_MTU MS_FILTER_BASE_METHOD(9,int)
#define MS_FILTER_GET_MTU MS_FILTER_BASE_METHOD(10,int)
/**Filters can return their latency in milliseconds (if known) using this method:*/
#define MS_FILTER_GET_LATENCY MS_FILTER_BASE_METHOD(11,int)
enum _MSFilterInterfaceId{
......@@ -483,7 +485,6 @@ typedef enum _MSFilterInterfaceId MSFilterInterfaceId;
/* more specific methods: to be moved into implementation specific header files*/
#define MS_FILTER_SET_FRAMESIZE MS_FILTER_BASE_METHOD(11,int)
#define MS_FILTER_SET_FILTERLENGTH MS_FILTER_BASE_METHOD(12,int)
#define MS_FILTER_SET_OUTPUT_SAMPLE_RATE MS_FILTER_BASE_METHOD(13,int)
#define MS_FILTER_ENABLE_DIRECTMODE MS_FILTER_BASE_METHOD(14,int)
......
......@@ -245,17 +245,6 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
return -1;
}
if (use_ec) {
stream->ec=ms_filter_new(MS_SPEEX_EC_ID);
ms_filter_call_method(stream->ec,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate);
if (stream->ec_tail_len!=0)
ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_TAIL_LENGTH,&stream->ec_tail_len);
if (stream->ec_delay!=0)
ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_DELAY,&stream->ec_delay);
if (stream->ec_framesize!=0)
ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_FRAMESIZE,&stream->ec_framesize);
}
if (stream->el_type!=ELInactive || stream->use_gc || stream->use_ng){
stream->volsend=ms_filter_new(MS_VOLUME_ID);
stream->volrecv=ms_filter_new(MS_VOLUME_ID);
......@@ -291,10 +280,29 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
if (stream->write_resampler == NULL) stream->write_resampler=ms_filter_new(MS_RESAMPLE_ID);
}
tmp=1;
ms_filter_call_method(stream->soundwrite,MS_FILTER_SET_NCHANNELS, &tmp);
/*configure the echo canceller if required */
if (use_ec) {
stream->ec=ms_filter_new(MS_SPEEX_EC_ID);
ms_filter_call_method(stream->ec,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate);
if (stream->ec_tail_len!=0)
ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_TAIL_LENGTH,&stream->ec_tail_len);
if (stream->ec_delay!=0){
ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_DELAY,&stream->ec_delay);
}else{
/*configure from latency of sound card in case it is availlable */
int latency=0;
ms_filter_call_method(stream->soundread,MS_FILTER_GET_LATENCY,&latency);
latency-=30; /*keep 30 milliseconds security margin*/
if (latency<0) latency=0;
ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_DELAY,&latency);
}
if (stream->ec_framesize!=0)
ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_FRAMESIZE,&stream->ec_framesize);
}
/* give the encoder/decoder some parameters*/
ms_filter_call_method(stream->encoder,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate);
ms_message("Payload's bitrate is %i",pt->normal_bitrate);
......
......@@ -26,7 +26,7 @@
static JavaVM *ms_andsnd_jvm;
static void sound_read_setup(MSFilter *f);
/*
mediastreamer2 sound card functions
......@@ -135,18 +135,23 @@ static int set_read_rate(MSFilter *f, void *arg){
msandroid_sound_data *d=(msandroid_sound_data*)f->data;
d->rate=proposed_rate;
return 0;
/*d->rate=44100; //to improve latency on msn 7k
if (proposed_rate == d->rate) {
}
static int get_latency(MSFilter *f, void *arg){
msandroid_sound_data *d=(msandroid_sound_data*)f->data;
if (!d->started){
sound_read_setup(f);
((int*)arg)=(1000*d->buff_size)/(d->nchannels*2*d->rate);
}
return 0;
} else {
return d->rate;
}*/
}
MSFilterMethod msandroid_sound_read_methods[]={
{ MS_FILTER_SET_SAMPLE_RATE , set_read_rate },
{ MS_FILTER_GET_SAMPLE_RATE , get_rate },
{ MS_FILTER_SET_NCHANNELS , set_nchannels },
{ MS_FILTER_GET_LATENCY , get_latency},
{ 0 , NULL }
};
......@@ -210,7 +215,7 @@ static void* msandroid_read_cb(msandroid_sound_read_data* d) {
}
}
void msandroid_sound_read_preprocess(MSFilter *f){
static void sound_read_setup(MSFilter *f){
ms_debug("andsnd_read_preprocess");
msandroid_sound_read_data *d=(msandroid_sound_read_data*)f->data;
JNIEnv *jni_env = 0;
......@@ -300,7 +305,13 @@ void msandroid_sound_read_preprocess(MSFilter *f){
}
}
void msandroid_sound_read_postprocess(MSFilter *f){
static void sound_read_preprocess(MSFilter *f){
ms_debug("andsnd_read_preprocess");
if (!d->started)
sound_read_setup(f);
}
static void sound_read_postprocess(MSFilter *f){
msandroid_sound_read_data *d=(msandroid_sound_read_data*)f->data;
JNIEnv *jni_env = 0;
jmethodID flush_id=0;
......@@ -344,7 +355,7 @@ void msandroid_sound_read_postprocess(MSFilter *f){
}
}
void msandroid_sound_read_process(MSFilter *f){
static void sound_read_process(MSFilter *f){
msandroid_sound_read_data *d=(msandroid_sound_read_data*)f->data;
mblk_t *m;
int nbytes=0.02*(float)d->rate*2.0*(float)d->nchannels;
......@@ -373,9 +384,9 @@ static MSFilterDesc msandroid_sound_read_desc={
/*.ninputs=*/0,
/*.noutputs=*/1,
/*.init*/NULL,
/*.preprocess=*/msandroid_sound_read_preprocess,
/*.process=*/msandroid_sound_read_process,
/*.postprocess=*/msandroid_sound_read_postprocess,
/*.preprocess=*/sound_read_preprocess,
/*.process=*/sound_read_process,
/*.postprocess=*/sound_read_postprocess,
/*.uninit*/NULL,
/*.methods=*/msandroid_sound_read_methods
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment