BililiveRecorder/BililiveRecorder.Core/RecordingStats.cs

58 lines
2.3 KiB
C#
Raw Normal View History

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;
private double duraionRatio;
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); }
public double DuraionRatio { get => this.duraionRatio; set => this.SetField(ref this.duraionRatio, value); }
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-04-21 19:48:28 +08:00
this.DuraionRatio = 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;
}
}
}