Commit 3062cc77 authored by Ghislain MARY's avatar Ghislain MARY

Improve call stats.

parent c35111c8
......@@ -46,7 +46,7 @@ Linphone::Core::LinphoneCallLog^ Linphone::Core::LinphoneCall::GetCallLog()
Linphone::Core::LinphoneCallStats^ Linphone::Core::LinphoneCall::GetAudioStats()
{
gApiLock.Lock();
Linphone::Core::LinphoneCallStats^ stats = (Linphone::Core::LinphoneCallStats^) Linphone::Core::Utils::CreateLinphoneCallStats((void*) linphone_call_get_audio_stats(this->call), this->call);
Linphone::Core::LinphoneCallStats^ stats = (Linphone::Core::LinphoneCallStats^) Linphone::Core::Utils::CreateLinphoneCallStats(this->call, (int)Linphone::Core::MediaType::Audio);
gApiLock.Unlock();
return stats;
}
......
#include "ApiLock.h"
#include "LinphoneCallStats.h"
#include "LinphoneCall.h"
#include "Server.h"
......@@ -5,25 +6,103 @@
Linphone::Core::MediaType Linphone::Core::LinphoneCallStats::GetMediaType()
{
return (Linphone::Core::MediaType) this->stats->type;
return this->mediaType;
}
Linphone::Core::IceState Linphone::Core::LinphoneCallStats::GetIceState()
{
return (Linphone::Core::IceState) this->stats->ice_state;
return this->iceState;
}
float Linphone::Core::LinphoneCallStats::GetDownloadBandwidth()
{
return this->stats->download_bandwidth;
return this->downloadBandwidth;
}
float Linphone::Core::LinphoneCallStats::GetUploadBandwidth()
{
return this->stats->upload_bandwidth;
return this->uploadBandwidth;
}
float Linphone::Core::LinphoneCallStats::GetSenderLossRate()
{
return this->senderLossRate;
}
float Linphone::Core::LinphoneCallStats::GetReceiverLossRate()
{
return this->receiverLossRate;
}
float Linphone::Core::LinphoneCallStats::GetSenderInterarrivalJitter()
{
return this->senderInterarrivalJitter;
}
float Linphone::Core::LinphoneCallStats::GetReceiverInterarrivalJitter()
{
return this->receiverInterarrivalJitter;
}
float Linphone::Core::LinphoneCallStats::GetRoundTripDelay()
{
return this->roundTripDelay;
}
int64 Linphone::Core::LinphoneCallStats::GetLatePacketsCumulativeNumber()
{
return this->cumulativeLatePackets;
}
float Linphone::Core::LinphoneCallStats::GetJitterBufferSize()
{
return this->jitterBufferSize;
}
float Linphone::Core::LinphoneCallStats::GetLocalLossRate()
{
return this->localLossRate;
}
float Linphone::Core::LinphoneCallStats::GetLocalLateRate()
{
return this->localLateRate;
}
Linphone::Core::LinphoneCallStats::LinphoneCallStats(::LinphoneCall *call, Linphone::Core::MediaType mediaType) :
call(call)
{
gApiLock.Lock();
const ::LinphoneCallStats *stats = nullptr;
if (mediaType == MediaType::Audio) {
stats = linphone_call_get_audio_stats(this->call);
} else {
stats = linphone_call_get_video_stats(this->call);
}
this->mediaType = (Linphone::Core::MediaType) stats->type;
this->iceState = (Linphone::Core::IceState) stats->ice_state;
this->downloadBandwidth = stats->download_bandwidth;
this->uploadBandwidth = stats->upload_bandwidth;
this->senderLossRate = UpdateSenderLossRate(stats);
this->receiverLossRate = UpdateReceiverLossRate(stats);
this->senderInterarrivalJitter = UpdateSenderInterarrivalJitter(stats);
this->receiverInterarrivalJitter = UpdateReceiverInterarrivalJitter(stats);
this->roundTripDelay = stats->round_trip_delay;
this->cumulativeLatePackets = UpdateLatePacketsCumulativeNumber(stats);
this->jitterBufferSize = stats->jitter_stats.jitter_buffer_size_ms;
this->localLossRate = stats->local_loss_rate;
this->localLateRate = stats->local_late_rate;
gApiLock.Unlock();
}
Linphone::Core::LinphoneCallStats::~LinphoneCallStats()
{
}
float Linphone::Core::LinphoneCallStats::UpdateSenderLossRate(const ::LinphoneCallStats *stats)
{
const report_block_t *srb = NULL;
......@@ -42,10 +121,10 @@ float Linphone::Core::LinphoneCallStats::GetSenderLossRate()
if (!srb)
return 0.0;
return (100.0 * report_block_get_fraction_lost(srb) / 256.0);
return (100.0f * report_block_get_fraction_lost(srb) / 256.0f);
}
float Linphone::Core::LinphoneCallStats::GetReceiverLossRate()
float Linphone::Core::LinphoneCallStats::UpdateReceiverLossRate(const ::LinphoneCallStats *stats)
{
const report_block_t* rrb = NULL;
......@@ -64,10 +143,10 @@ float Linphone::Core::LinphoneCallStats::GetReceiverLossRate()
if (!rrb)
return 0.0;
return (100.0 * report_block_get_fraction_lost(rrb) / 256.0);
return (100.0f * report_block_get_fraction_lost(rrb) / 256.0f);
}
float Linphone::Core::LinphoneCallStats::GetSenderInterarrivalJitter()
float Linphone::Core::LinphoneCallStats::UpdateSenderInterarrivalJitter(const ::LinphoneCallStats *stats)
{
const ::LinphoneCallParams* params;
const ::PayloadType* pt;
......@@ -103,7 +182,7 @@ float Linphone::Core::LinphoneCallStats::GetSenderInterarrivalJitter()
return ((float)report_block_get_interarrival_jitter(srb) / (float)pt->clock_rate);
}
float Linphone::Core::LinphoneCallStats::GetReceiverInterarrivalJitter()
float Linphone::Core::LinphoneCallStats::UpdateReceiverInterarrivalJitter(const ::LinphoneCallStats *stats)
{
const ::LinphoneCallParams* params;
const ::PayloadType* pt;
......@@ -139,12 +218,7 @@ float Linphone::Core::LinphoneCallStats::GetReceiverInterarrivalJitter()
return ((float)report_block_get_interarrival_jitter(rrb) / (float)pt->clock_rate);
}
float Linphone::Core::LinphoneCallStats::GetRoundTripDelay()
{
return this->stats->round_trip_delay;
}
int64 Linphone::Core::LinphoneCallStats::GetLatePacketsCumulativeNumber()
int64 Linphone::Core::LinphoneCallStats::UpdateLatePacketsCumulativeNumber(const ::LinphoneCallStats *stats)
{
rtp_stats_t rtp_stats;
......@@ -161,31 +235,3 @@ int64 Linphone::Core::LinphoneCallStats::GetLatePacketsCumulativeNumber()
return rtp_stats.outoftime;
}
float Linphone::Core::LinphoneCallStats::GetJitterBufferSize()
{
return this->stats->jitter_stats.jitter_buffer_size_ms;
}
float Linphone::Core::LinphoneCallStats::GetLocalLossRate()
{
return this->stats->local_loss_rate;
}
float Linphone::Core::LinphoneCallStats::GetLocalLateRate()
{
return this->stats->local_late_rate;
}
Linphone::Core::LinphoneCallStats::LinphoneCallStats(::LinphoneCallStats *call_stats, ::LinphoneCall *call) :
stats(call_stats),
call(call)
{
}
Linphone::Core::LinphoneCallStats::~LinphoneCallStats()
{
}
......@@ -6,12 +6,18 @@ namespace Linphone
{
namespace Core
{
/// <summary>
/// Media type of the statistics (audio or video).
/// </summary>
public enum class MediaType : int
{
Audio = 0,
Video = 1
};
/// <summary>
/// State of the ICE processing.
/// </summary>
public enum class IceState : int
{
NotActivated = 0,
......@@ -22,10 +28,22 @@ namespace Linphone
RelayConnection = 5
};
/// <summary>
/// Object representing the statistics of a call.
/// To get the statistics of a call use the LinphoneCall::GetAudioStats() method. It gives the call statistics at the specific time it is asked for.
/// So to have updated statistics you need to get the statistics from the call again.
/// </summary>
public ref class LinphoneCallStats sealed
{
public:
/// <summary>
/// Gets the media type (audio or video).
/// </summary>
MediaType GetMediaType();
/// <summary>
/// Gets the state of the ICE process.
/// </summary>
IceState GetIceState();
/// <summary>
......@@ -37,9 +55,25 @@ namespace Linphone
/// Gets the upload bandwidth in kbits/s.
/// </summary>
float GetUploadBandwidth();
/// <summary>
/// Gets the local loss rate since last emitted RTCP report.
/// </summary>
float GetSenderLossRate();
/// <summary>
/// Gets the remote loss rate from the last received RTCP report.
/// </summary>
float GetReceiverLossRate();
/// <summary>
/// Gets the local interarrival jitter.
/// </summary>
float GetSenderInterarrivalJitter();
/// <summary>
/// Gets the remote reported interarrival jitter.
/// </summary>
float GetReceiverInterarrivalJitter();
/// <summary>
......@@ -49,6 +83,10 @@ namespace Linphone
/// -1 if the information is not available.
/// </returns>
float GetRoundTripDelay();
/// <summary>
/// Gets the cumulative number of late packets.
/// </summary>
int64 GetLatePacketsCumulativeNumber();
/// <summary>
......@@ -56,18 +94,43 @@ namespace Linphone
/// </summary>
float GetJitterBufferSize();
/// <summary>
/// Get the local loss rate. Unlike GetSenderLossRate() that returns this loss rate "since last emitted RTCP report", the value returned here is updated every second.
/// </summary>
float GetLocalLossRate();
/// <summary>
/// Get the local late packets rate. The value returned here is updated every second.
/// </summary>
float GetLocalLateRate();
private:
friend class Linphone::Core::Utils;
friend ref class Linphone::Core::LinphoneCore;
LinphoneCallStats(::LinphoneCallStats* stats, ::LinphoneCall *call);
LinphoneCallStats(::LinphoneCall *call, Linphone::Core::MediaType mediaType);
~LinphoneCallStats();
::LinphoneCallStats *stats;
float Linphone::Core::LinphoneCallStats::UpdateSenderLossRate(const ::LinphoneCallStats *stats);
float Linphone::Core::LinphoneCallStats::UpdateReceiverLossRate(const ::LinphoneCallStats *stats);
float Linphone::Core::LinphoneCallStats::UpdateSenderInterarrivalJitter(const ::LinphoneCallStats *stats);
float Linphone::Core::LinphoneCallStats::UpdateReceiverInterarrivalJitter(const ::LinphoneCallStats *stats);
int64 Linphone::Core::LinphoneCallStats::UpdateLatePacketsCumulativeNumber(const ::LinphoneCallStats *stats);
::LinphoneCall *call;
MediaType mediaType;
IceState iceState;
float downloadBandwidth;
float uploadBandwidth;
float senderLossRate;
float receiverLossRate;
float senderInterarrivalJitter;
float receiverInterarrivalJitter;
float roundTripDelay;
int64 cumulativeLatePackets;
float jitterBufferSize;
float localLossRate;
float localLateRate;
};
}
}
\ No newline at end of file
......@@ -113,9 +113,9 @@ Platform::Object^ Linphone::Core::Utils::CreateLinphoneCallParams(void* callPara
return ref new Linphone::Core::LinphoneCallParams((::LinphoneCallParams *)callParams);
}
Platform::Object^ Linphone::Core::Utils::CreateLinphoneCallStats(void* callStats, void* call)
Platform::Object^ Linphone::Core::Utils::CreateLinphoneCallStats(void* call, int mediaType)
{
return ref new Linphone::Core::LinphoneCallStats((::LinphoneCallStats *)callStats, (::LinphoneCall *)call);
return ref new Linphone::Core::LinphoneCallStats((::LinphoneCall *)call, (Linphone::Core::MediaType)mediaType);
}
void Linphone::Core::Utils::EchoCalibrationCallback(void *lc, int status, int delay_ms, void *data)
......
......@@ -94,7 +94,7 @@ namespace Linphone
/// <summary>
/// Creates a C++/CX LinphoneCallStats object using pointer to C structure.
/// </summary>
static Platform::Object^ CreateLinphoneCallStats(void* callStats, void* call);
static Platform::Object^ CreateLinphoneCallStats(void* call, int mediaType);
static void EchoCalibrationCallback(void *lc, int status, int delay_ms, void *data);
......
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