Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
mediastreamer2
Commits
9695bacc
Commit
9695bacc
authored
Nov 05, 2014
by
Simon Morlat
Browse files
do not check fps if late tick occurred recently
parent
cefa09ed
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
12 deletions
+44
-12
include/mediastreamer2/msticker.h
include/mediastreamer2/msticker.h
+15
-0
src/base/msticker.c
src/base/msticker.c
+12
-0
src/voip/videostream.c
src/voip/videostream.c
+17
-12
No files found.
include/mediastreamer2/msticker.h
View file @
9695bacc
...
...
@@ -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.
*
...
...
src/base/msticker.c
View file @
9695bacc
...
...
@@ -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
);
...
...
src/voip/videostream.c
View file @
9695bacc
...
...
@@ -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
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment