From ebf176094740248f999a0b78fca00395c746adad Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Tue, 7 Feb 2017 13:57:53 +0100 Subject: [PATCH] add new function to get stream stats --- coreapi/linphonecall.c | 43 +++++++++++++++++++++++++++-------------- include/linphone/call.h | 2 ++ include/linphone/core.h | 8 ++++++++ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 24a8ea09f..96ca7b541 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -4099,28 +4099,41 @@ static void update_local_stats(LinphoneCallStats *stats, MediaStream *stream) { stats->clockrate = pt ? pt->clock_rate : 8000; } -const LinphoneCallStats *linphone_call_get_audio_stats(LinphoneCall *call) { - LinphoneCallStats *stats = &call->stats[LINPHONE_CALL_STATS_AUDIO]; - if (call->audiostream){ - update_local_stats(stats,(MediaStream*)call->audiostream); +static MediaStream *linphone_call_get_stream(LinphoneCall *call, LinphoneStreamType type){ + switch(type){ + case LinphoneStreamTypeAudio: + return &call->audiostream->ms; + case LinphoneStreamTypeVideo: + return &call->videostream->ms; + case LinphoneStreamTypeText: + return &call->textstream->ms; + case LinphoneStreamTypeUnknown: + break; } - return stats; + return NULL; +} + +const LinphoneCallStats *linphone_call_get_stats(LinphoneCall *call, LinphoneStreamType type){ + if (type>=0 && type<=LinphoneStreamTypeText){ + LinphoneCallStats *stats = &call->stats[type]; + MediaStream *ms = linphone_call_get_stream(call, type); + if (ms) update_local_stats(stats, ms); + return stats; + } + ms_error("Invalid stream type %i", (int)type); + return NULL; +} + +const LinphoneCallStats *linphone_call_get_audio_stats(LinphoneCall *call) { + return linphone_call_get_stats(call, LinphoneStreamTypeAudio); } const LinphoneCallStats *linphone_call_get_video_stats(LinphoneCall *call) { - LinphoneCallStats *stats = &call->stats[LINPHONE_CALL_STATS_VIDEO]; - if (call->videostream){ - update_local_stats(stats,(MediaStream*)call->videostream); - } - return stats; + return linphone_call_get_stats(call, LinphoneStreamTypeVideo); } const LinphoneCallStats *linphone_call_get_text_stats(LinphoneCall *call) { - LinphoneCallStats *stats = &call->stats[LINPHONE_CALL_STATS_TEXT]; - if (call->textstream){ - update_local_stats(stats,(MediaStream*)call->textstream); - } - return stats; + return linphone_call_get_stats(call, LinphoneStreamTypeText); } static bool_t ice_in_progress(LinphoneCallStats *stats){ diff --git a/include/linphone/call.h b/include/linphone/call.h index 178af25c8..4be10ce39 100644 --- a/include/linphone/call.h +++ b/include/linphone/call.h @@ -571,6 +571,8 @@ LINPHONE_PUBLIC bool_t linphone_call_media_in_progress(LinphoneCall *call); */ LINPHONE_PUBLIC void linphone_call_ogl_render(LinphoneCall *call, bool_t is_preview); + + /** * @} */ diff --git a/include/linphone/core.h b/include/linphone/core.h index dcc7e3db0..3fbccd07b 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -546,6 +546,14 @@ typedef enum _LinphoneAddressFamily LinphoneAddressFamily; #include "linphone/call_stats.h" + +/** + * Return call statistics for a particular stream type. + * @param call the call + * @param type the stream type +**/ +LINPHONE_PUBLIC const LinphoneCallStats *linphone_call_get_stats(LinphoneCall *call, LinphoneStreamType type); + LINPHONE_PUBLIC const LinphoneCallStats *linphone_call_get_audio_stats(LinphoneCall *call); LINPHONE_PUBLIC const LinphoneCallStats *linphone_call_get_video_stats(LinphoneCall *call); LINPHONE_PUBLIC const LinphoneCallStats *linphone_call_get_text_stats(LinphoneCall *call);