Move extremum.c from mediastreamer2: object to compute min/max value on a sliding period of time

parent a2c61186
......@@ -27,33 +27,34 @@ LOCAL_MODULE := libortp
LOCAL_SRC_FILES := \
src/str_utils.c \
src/port.c \
src/avprofile.c \
src/b64.c \
src/event.c \
src/extremum.c \
src/jitterctl.c \
src/logging.c \
src/netsim.c \
src/ortp.c \
src/payloadtype.c \
src/port.c \
src/posixtimer.c \
src/rtcp.c \
src/rtcp_fb.c \
src/rtcp_xr.c \
src/rtcpparse.c \
src/rtpparse.c \
src/rtpprofile.c \
src/rtpsession.c \
src/rtpsession_inet.c \
src/jitterctl.c \
src/rtpsignaltable.c \
src/rtptimer.c \
src/posixtimer.c \
src/ortp.c \
src/scheduler.c \
src/avprofile.c \
src/sessionset.c \
src/telephonyevents.c \
src/payloadtype.c \
src/rtpprofile.c \
src/rtcp.c \
src/rtcp_fb.c \
src/rtcp_xr.c \
src/utils.c \
src/rtcpparse.c \
src/event.c \
src/str_utils.c \
src/stun.c \
src/stun_udp.c \
src/b64.c \
src/netsim.c
src/telephonyevents.c \
src/utils.c
LOCAL_CFLAGS += \
-DORTP_INET6 \
......
......@@ -79,6 +79,7 @@ typedef struct _JitterControl
int clock_rate;
bool_t adaptive;
bool_t enabled;
ortp_extremum *buffer_extremum;
} JitterControl;
typedef struct _WaitPoint
......
......@@ -157,6 +157,23 @@ ORTP_PUBLIC void msgb_allocator_init(msgb_allocator_t *pa);
ORTP_PUBLIC mblk_t *msgb_allocator_alloc(msgb_allocator_t *pa, size_t size);
ORTP_PUBLIC void msgb_allocator_uninit(msgb_allocator_t *pa);
/**
* Utility object to determine a maximum or minimum (but not both at the same
* time), of a signal during a sliding period of time.
*/
typedef struct _ortp_extremum{
float current_extremum;
uint64_t extremum_time;
float last_stable;
int period;
}ortp_extremum;
ORTP_PUBLIC void ortp_extremum_reset(ortp_extremum *obj);
ORTP_PUBLIC void ortp_extremum_init(ortp_extremum *obj, int period);
ORTP_PUBLIC void ortp_extremum_record_min(ortp_extremum *obj, uint64_t curtime, float value);
ORTP_PUBLIC void ortp_extremum_record_max(ortp_extremum *obj, uint64_t curtime, float value);
ORTP_PUBLIC float ortp_extremum_get_current(ortp_extremum *obj);
#ifdef __cplusplus
}
#endif
......
......@@ -29,6 +29,7 @@ set(SOURCE_FILES
avprofile.c
b64.c
event.c
extremum.c
jitterctl.c
logging.c
netsim.c
......
......@@ -17,32 +17,34 @@ AM_LDFLAGS=$(PTHREAD_LDFLAGS)
lib_LTLIBRARIES = libortp.la
libortp_la_SOURCES= str_utils.c \
port.c \
libortp_la_SOURCES= \
avprofile.c \
b64.c \
event.c \
extremum.c \
jitterctl.c jitterctl.h \
logging.c \
netsim.c \
ortp.c \
payloadtype.c \
port.c \
posixtimer.c \
rtcp.c \
rtcp_fb.c \
rtcp_xr.c \
rtcpparse.c \
rtpparse.c \
rtpprofile.c \
rtpsession.c \
rtpsession_inet.c \
rtpsession_priv.h \
jitterctl.c jitterctl.h \
rtpsignaltable.c \
rtptimer.c rtptimer.h \
posixtimer.c \
ortp.c \
scheduler.c scheduler.h \
avprofile.c \
sessionset.c \
str_utils.c \
telephonyevents.c \
payloadtype.c \
rtpprofile.c \
rtcp.c \
rtcp_fb.c \
rtcp_xr.c \
utils.c utils.h \
rtcpparse.c \
event.c \
b64.c \
netsim.c
utils.c utils.h
libortp_la_LIBADD= $(PTHREAD_LIBS) $(RT_LIBS) -lm $(SSL_LIBS)
......
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2014 Belledonne Communications SARL
Author: Simon MORLAT (simon.morlat@linphone.org)
This program is free software; you can redistribute it and/or
modify it under the terortp of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "ortp/str_utils.h"
void ortp_extremum_reset(ortp_extremum *obj){
obj->current_extremum=0;
obj->extremum_time=(uint64_t)-1;
obj->last_stable=0;
}
void ortp_extremum_init(ortp_extremum *obj, int period){
ortp_extremum_reset(obj);
obj->period=period;
}
static void extremum_set_new(ortp_extremum *obj, const char* kind){
obj->last_stable=obj->current_extremum;
/*ortp_message("New %s value : %f",kind,obj->last_stable);*/
}
static void extremum_check_init(ortp_extremum *obj, uint64_t curtime, float value, const char *kind){
if (obj->extremum_time!=(uint64_t)-1){
if (curtime-obj->extremum_time>obj->period){
/*last extremum is too old, drop it*/
extremum_set_new(obj,kind);
obj->extremum_time=(uint64_t)-1;
}
}
if (obj->extremum_time==(uint64_t)-1){
obj->current_extremum=value;
obj->extremum_time=curtime;
}
}
void ortp_extremum_record_min(ortp_extremum *obj, uint64_t curtime, float value){
extremum_check_init(obj,curtime,value,"min");
if (value<obj->current_extremum){
obj->current_extremum=value;
obj->extremum_time=curtime;
if (value<obj->last_stable){
extremum_set_new(obj,"min");
}
}
}
void ortp_extremum_record_max(ortp_extremum *obj, uint64_t curtime, float value){
extremum_check_init(obj,curtime,value,"max");
if (value>obj->current_extremum){
obj->current_extremum=value;
obj->extremum_time=curtime;
if (value>obj->last_stable){
extremum_set_new(obj,"max");
}
}
}
float ortp_extremum_get_current(ortp_extremum *obj){
return obj->last_stable;
}
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