Commit 9695bacc authored by Simon Morlat's avatar Simon Morlat

do not check fps if late tick occurred recently

parent cefa09ed
......@@ -62,6 +62,13 @@ enum _MSTickerPrio{
typedef enum _MSTickerPrio MSTickerPrio;
struct _MSTickerLateEvent{
int lateMs; /**<number of milliseconds late*/
uint64_t time; /**<time of late event, in milliseconds*/
};
typedef struct _MSTickerLateEvent MSTickerLateEvent;
struct _MSTicker
{
ms_mutex_t lock;
......@@ -81,6 +88,7 @@ struct _MSTicker
MSTickerPrio prio;
MSTickerTickFunc wait_next_tick;
void *wait_next_tick_data;
MSTickerLateEvent late_event;
bool_t run; /* flag to indicate whether the ticker must be run or not */
};
......@@ -226,6 +234,13 @@ MS2_PUBLIC void ms_ticker_print_graphs(MSTicker *ticker);
**/
MS2_PUBLIC float ms_ticker_get_average_load(MSTicker *ticker);
/**
* Get last late tick event description.
* @param ticker the MSTicker
* @param ev a MSTickerLaterEvent structure that will be filled in return by the ticker.
**/
MS2_PUBLIC void ms_ticker_get_last_late_tick(MSTicker *ticker, MSTickerLateEvent *ev);
/**
* Create a ticker synchronizer.
*
......
......@@ -435,6 +435,8 @@ void * ms_ticker_run(void *arg)
ms_mutex_lock(&s->lock);
while(s->run){
uint64_t late_tick_time=0;
s->ticks++;
/*Step 1: run the graphs*/
{
......@@ -458,9 +460,14 @@ void * ms_ticker_run(void *arg)
late=s->wait_next_tick(s->wait_next_tick_data,s->time);
if (late>s->interval*5 && late>lastlate){
ms_warning("%s: We are late of %d miliseconds.",s->name,late);
late_tick_time=ms_get_cur_time_ms();
}
lastlate=late;
ms_mutex_lock(&s->lock);
if (late_tick_time){
s->late_event.lateMs=late;
s->late_event.time=late_tick_time;
}
}
ms_mutex_unlock(&s->lock);
unset_high_prio(precision);
......@@ -548,6 +555,11 @@ float ms_ticker_get_average_load(MSTicker *ticker){
return ticker->av_load;
}
void ms_ticker_get_last_late_tick(MSTicker *ticker, MSTickerLateEvent *ev){
ms_mutex_lock(&ticker->lock);
memcpy(ev,&ticker->late_event,sizeof(MSTickerLateEvent));
ms_mutex_unlock(&ticker->lock);
}
static uint64_t get_ms(const MSTimeSpec *ts){
return (ts->tv_sec*1000LL) + ((ts->tv_nsec+500000LL)/1000000LL);
......
......@@ -173,21 +173,26 @@ static void video_stream_track_fps_changes(VideoStream *stream){
stream->last_fps_check=curtime;
return;
}
if (curtime-stream->last_fps_check>=2000 && stream->configured_fps>0){
if (stream->source && stream->ms.encoder &&
ms_filter_has_method(stream->source,MS_FILTER_GET_FPS) &&
ms_filter_has_method(stream->ms.encoder,MS_FILTER_SET_FPS)){
float fps=0;
if (ms_filter_call_method(stream->source,MS_FILTER_GET_FPS,&fps)==0 && fps!=0){
if (fabsf(fps-stream->configured_fps)/stream->configured_fps>0.2){
ms_warning("Measured and target fps significantly different (%f<->%f), updating encoder.",
fps,stream->configured_fps);
stream->configured_fps=fps;
ms_filter_call_method(stream->ms.encoder,MS_FILTER_SET_FPS,&stream->configured_fps);
if (curtime-stream->last_fps_check>=2000 && stream->configured_fps>0 && stream->ms.sessions.ticker){
MSTickerLateEvent late_ev={0};
/*we must check that no late tick occured during the last 2 seconds, otherwise the fps measurement is severely biased.*/
ms_ticker_get_last_late_tick(stream->ms.sessions.ticker,&late_ev);
if (curtime > late_ev.time + 2000){
if (stream->source && stream->ms.encoder &&
ms_filter_has_method(stream->source,MS_FILTER_GET_FPS) &&
ms_filter_has_method(stream->ms.encoder,MS_FILTER_SET_FPS)){
float fps=0;
if (ms_filter_call_method(stream->source,MS_FILTER_GET_FPS,&fps)==0 && fps!=0){
if (fabsf(fps-stream->configured_fps)/stream->configured_fps>0.2){
ms_warning("Measured and target fps significantly different (%f<->%f), updating encoder.",
fps,stream->configured_fps);
stream->configured_fps=fps;
ms_filter_call_method(stream->ms.encoder,MS_FILTER_SET_FPS,&stream->configured_fps);
}
}
}
stream->last_fps_check=curtime;
}
stream->last_fps_check=curtime;
}
}
......
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