Commit 20722eec authored by Ghislain MARY's avatar Ghislain MARY

Handle granularity in flow controlled bufferizer + set the same flow control...

Handle granularity in flow controlled bufferizer + set the same flow control interval and threshold in the soundcard filters.
parent 0652e1da
......@@ -163,6 +163,8 @@ struct _MSFlowControlledBufferizer {
uint64_t flow_control_time;
uint32_t flow_control_interval_ms;
uint32_t max_size_ms;
uint32_t granularity_ms;
uint32_t min_size_ms_during_interval;
int samplerate;
int nchannels;
};
......@@ -175,6 +177,8 @@ MS2_PUBLIC void ms_flow_controlled_bufferizer_init(MSFlowControlledBufferizer *o
MS2_PUBLIC void ms_flow_controlled_bufferizer_set_max_size_ms(MSFlowControlledBufferizer *obj, uint32_t ms);
MS2_PUBLIC void ms_flow_controlled_bufferizer_set_granularity_ms(MSFlowControlledBufferizer *obj, uint32_t ms);
MS2_PUBLIC void ms_flow_controlled_bufferizer_set_flow_control_interval_ms(MSFlowControlledBufferizer *obj, uint32_t ms);
MS2_PUBLIC void ms_flow_controlled_bufferizer_set_samplerate(MSFlowControlledBufferizer *obj, int samplerate);
......
......@@ -71,8 +71,8 @@ The BSD license below is for the original work.
MSFilter *ms_au_read_new(MSSndCard *card);
MSFilter *ms_au_write_new(MSSndCard *card);
static const int flow_control_interval = 1000; // ms
static const int flow_control_threshold = 50; // ms
static const int flow_control_interval = 5000; // ms
static const int flow_control_threshold = 40; // ms
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
......
......@@ -26,8 +26,8 @@
#include "mediastreamer2/msfilter.h"
#include "mediastreamer2/msticker.h"
static const int flowControlInterval = 1000; // ms
static const int flowControlThreshold = 50; // ms
static const int flowControlInterval = 5000; // ms
static const int flowControlThreshold = 40; // ms
/* -------------------------
| i o |
......
......@@ -44,8 +44,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
}
static const int flowControlInterval = 1000; // ms
static const int flowControlThreshold = 50; // ms
static const int flowControlInterval = 5000; // ms
static const int flowControlThreshold = 40; // ms
bool MSWASAPIWriter::smInstantiated = false;
......
......@@ -44,8 +44,8 @@ static int the_pa_ref = 0;
static pa_context *the_pa_context=NULL;
static pa_threaded_mainloop *the_pa_loop=NULL;
static const int targeted_latency = 20;/*ms*/
static const int flow_control_op_interval = 1000; // ms
static const int flow_control_threshold = 50; // ms
static const int flow_control_interval = 5000; // ms
static const int flow_control_threshold = 40; // ms
static void context_state_notify_cb(pa_context *ctx, void *userdata){
......@@ -340,7 +340,7 @@ static Stream *stream_new(StreamType type, MSFilter *f) {
s->state = PA_STREAM_UNCONNECTED;
ms_flow_controlled_bufferizer_init(&s->bufferizer, f, s->sampleSpec.rate, s->sampleSpec.channels);
ms_flow_controlled_bufferizer_set_max_size_ms(&s->bufferizer, flow_control_threshold);
ms_flow_controlled_bufferizer_set_flow_control_interval_ms(&s->bufferizer, flow_control_op_interval);
ms_flow_controlled_bufferizer_set_flow_control_interval_ms(&s->bufferizer, flow_control_interval);
s->dev = NULL;
s->init_volume = -1.0;
if (type == STREAM_TYPE_RECORD) {
......
......@@ -62,7 +62,6 @@ typedef struct SpeexECState{
int delay_ms;
int tail_length_ms;
int nominal_ref_samples;
int min_ref_samples;
char *state_str;
#ifdef EC_DUMP
FILE *echofile;
......@@ -184,7 +183,8 @@ static int adjust_framesize(int framesize, int samplerate){
static void configure_flow_controlled_bufferizer(SpeexECState *s) {
ms_flow_controlled_bufferizer_set_samplerate(&s->ref, s->samplerate);
ms_flow_controlled_bufferizer_set_max_size_ms(&s->ref, s->delay_ms + s->tail_length_ms - (s->tail_length_ms / 4));
ms_flow_controlled_bufferizer_set_max_size_ms(&s->ref, s->delay_ms);
ms_flow_controlled_bufferizer_set_granularity_ms(&s->ref, (s->framesize * 1000) / s->samplerate);
}
static void speex_ec_preprocess(MSFilter *f){
......@@ -207,7 +207,6 @@ static void speex_ec_preprocess(MSFilter *f){
m=allocb(delay_samples*2,0);
m->b_wptr+=delay_samples*2;
ms_bufferizer_put (&s->delayed_ref,m);
s->min_ref_samples=-1;
s->nominal_ref_samples=delay_samples;
#ifdef SPEEX_ECHO_GET_BLOB
apply_config(s);
......@@ -293,9 +292,6 @@ static void speex_ec_process(MSFilter *f){
avail-=nbytes;
avail_samples=avail/2;
/*ms_message("avail=%i",avail_samples);*/
if (avail_samples<s->min_ref_samples || s->min_ref_samples==-1){
s->min_ref_samples=avail_samples;
}
#ifdef EC_DUMP
if (s->reffile)
......
......@@ -139,7 +139,7 @@ void ms_bufferizer_destroy(MSBufferizer *obj){
static const uint32_t flow_control_interval_ms = 5000;
static const uint32_t max_size_ms = 1000;
static const uint32_t max_size_ms = 100;
MSFlowControlledBufferizer * ms_flow_controlled_bufferizer_new(MSFilter *f, int samplerate, int nchannels) {
MSFlowControlledBufferizer *obj = (MSFlowControlledBufferizer *)ms_new0(MSFlowControlledBufferizer, 1);
......@@ -152,7 +152,9 @@ void ms_flow_controlled_bufferizer_init(MSFlowControlledBufferizer *obj, MSFilte
obj->filter = f;
obj->flow_control_interval_ms = flow_control_interval_ms;
obj->max_size_ms = max_size_ms;
obj->granularity_ms = 0;
obj->flow_control_time = 0;
obj->min_size_ms_during_interval = UINT32_MAX;
obj->samplerate = samplerate;
obj->nchannels = nchannels;
}
......@@ -161,6 +163,10 @@ void ms_flow_controlled_bufferizer_set_max_size_ms(MSFlowControlledBufferizer *o
obj->max_size_ms = ms;
}
void ms_flow_controlled_bufferizer_set_granularity_ms(MSFlowControlledBufferizer *obj, uint32_t ms) {
obj->granularity_ms = ms;
}
void ms_flow_controlled_bufferizer_set_flow_control_interval_ms(MSFlowControlledBufferizer *obj, uint32_t ms) {
obj->flow_control_interval_ms = ms;
}
......@@ -179,16 +185,23 @@ static void control_flow(MSFlowControlledBufferizer *obj) {
if (obj->flow_control_time == 0) {
obj->flow_control_time = obj->filter->ticker->time;
}
if ((accumulated_ms < obj->min_size_ms_during_interval) || (obj->min_size_ms_during_interval == UINT32_MAX)) {
obj->min_size_ms_during_interval = accumulated_ms;
}
if ((accumulated_ms > obj->max_size_ms)
&& (((uint32_t)(obj->filter->ticker->time - obj->flow_control_time)) >= obj->flow_control_interval_ms)) {
MSAudioFlowControlDropEvent ev;
ev.flow_control_interval_ms = obj->flow_control_interval_ms;
ev.drop_ms = (uint32_t)ms_ticker_round((accumulated_ms - obj->max_size_ms) + (obj->max_size_ms / 4));
if (ev.drop_ms > 0) {
ms_warning("Flow controlled bufferizer of max %u ms buffered %u ms, asking to drop %u ms", obj->max_size_ms, accumulated_ms, ev.drop_ms);
ms_filter_notify(obj->filter, MS_AUDIO_FLOW_CONTROL_DROP_EVENT, &ev);
obj->flow_control_time = obj->filter->ticker->time;
if ((((uint32_t)(obj->filter->ticker->time - obj->flow_control_time)) >= obj->flow_control_interval_ms)
&& (obj->min_size_ms_during_interval != UINT32_MAX) && (obj->min_size_ms_during_interval > obj->max_size_ms)) {
uint32_t diff_ms = obj->min_size_ms_during_interval - obj->max_size_ms;
if (diff_ms > (obj->granularity_ms / 2)) {
MSAudioFlowControlDropEvent ev;
ev.flow_control_interval_ms = obj->flow_control_interval_ms;
ev.drop_ms = diff_ms - (obj->granularity_ms / 2);
if (ev.drop_ms > 0) {
ms_warning("Flow controlled bufferizer of max %u ms buffered at least %u ms in the last %u ms, asking to drop %u ms", obj->max_size_ms, obj->min_size_ms_during_interval, obj->flow_control_interval_ms, ev.drop_ms);
ms_filter_notify(obj->filter, MS_AUDIO_FLOW_CONTROL_DROP_EVENT, &ev);
obj->min_size_ms_during_interval = UINT32_MAX;
obj->flow_control_time = obj->filter->ticker->time;
}
}
}
}
......
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