2021-02-23 18:03:37 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
#nullable enable
|
|
|
|
namespace BililiveRecorder.Core
|
|
|
|
{
|
|
|
|
public class RecordingStats : INotifyPropertyChanged
|
|
|
|
{
|
|
|
|
private TimeSpan sessionMaxTimestamp;
|
|
|
|
private TimeSpan fileMaxTimestamp;
|
|
|
|
private TimeSpan sessionDuration;
|
|
|
|
private double networkMbps;
|
|
|
|
private long totalInputBytes;
|
|
|
|
private long totalOutputBytes;
|
2021-08-04 21:58:35 +08:00
|
|
|
private double durationRatio;
|
2021-02-23 18:03:37 +08:00
|
|
|
|
2021-04-21 19:48:28 +08:00
|
|
|
public RecordingStats()
|
|
|
|
{
|
|
|
|
this.Reset();
|
|
|
|
}
|
|
|
|
|
2021-02-23 18:03:37 +08:00
|
|
|
public TimeSpan SessionDuration { get => this.sessionDuration; set => this.SetField(ref this.sessionDuration, value); }
|
|
|
|
public TimeSpan SessionMaxTimestamp { get => this.sessionMaxTimestamp; set => this.SetField(ref this.sessionMaxTimestamp, value); }
|
|
|
|
public TimeSpan FileMaxTimestamp { get => this.fileMaxTimestamp; set => this.SetField(ref this.fileMaxTimestamp, value); }
|
|
|
|
|
2021-08-04 21:58:35 +08:00
|
|
|
public double DurationRatio { get => this.durationRatio; set => this.SetField(ref this.durationRatio, value); }
|
2021-02-23 18:03:37 +08:00
|
|
|
|
|
|
|
public long TotalInputBytes { get => this.totalInputBytes; set => this.SetField(ref this.totalInputBytes, value); }
|
|
|
|
public long TotalOutputBytes { get => this.totalOutputBytes; set => this.SetField(ref this.totalOutputBytes, value); }
|
|
|
|
|
|
|
|
public double NetworkMbps { get => this.networkMbps; set => this.SetField(ref this.networkMbps, value); }
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
{
|
|
|
|
this.SessionDuration = TimeSpan.Zero;
|
|
|
|
this.SessionMaxTimestamp = TimeSpan.Zero;
|
|
|
|
this.FileMaxTimestamp = TimeSpan.Zero;
|
2021-08-04 21:58:35 +08:00
|
|
|
this.DurationRatio = double.NaN;
|
2021-02-23 18:03:37 +08:00
|
|
|
this.TotalInputBytes = 0;
|
|
|
|
this.TotalOutputBytes = 0;
|
|
|
|
this.NetworkMbps = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
protected virtual void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
protected bool SetField<T>(ref T location, T value, [CallerMemberName] string propertyName = "")
|
|
|
|
{
|
|
|
|
if (EqualityComparer<T>.Default.Equals(location, value))
|
|
|
|
return false;
|
|
|
|
location = value;
|
|
|
|
this.OnPropertyChanged(propertyName);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|