using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
#nullable enable
namespace BililiveRecorder.Core
{
public class RoomStats : INotifyPropertyChanged
{
#region IO Stats Fields
private string? ___StreamHost;
private DateTimeOffset ___StartTime;
private DateTimeOffset ___EndTime;
private TimeSpan ___Duration;
private int ___NetworkBytesDownloaded;
private double ___NetworkMbps;
private TimeSpan ___DiskWriteDuration;
private int ___DiskBytesWritten;
private double ___DiskMBps;
#endregion
#region Recording Stats Fields
private TimeSpan ___SessionDuration;
private long ___TotalInputBytes;
private long ___TotalOutputBytes;
private long ___CurrentFileSize;
private TimeSpan ___SessionMaxTimestamp;
private TimeSpan ___FileMaxTimestamp;
private double ___AddedDuration;
private double ___PassedTime;
private double ___DurationRatio;
private long ___InputVideoBytes;
private long ___InputAudioBytes;
private int ___OutputVideoFrames;
private int ___OutputAudioFrames;
private long ___OutputVideoBytes;
private long ___OutputAudioBytes;
private long ___TotalInputVideoBytes;
private long ___TotalInputAudioBytes;
private int ___TotalOutputVideoFrames;
private int ___TotalOutputAudioFrames;
private long ___TotalOutputVideoBytes;
private long ___TotalOutputAudioBytes;
#endregion
public RoomStats()
{
this.Reset();
}
#region IO Stats Properties
///
/// 直播服务器域名
///
public string? StreamHost { get => this.___StreamHost; set => this.SetField(ref this.___StreamHost, value); }
///
/// 当前统计区间的开始时间
///
public DateTimeOffset StartTime { get => this.___StartTime; set => this.SetField(ref this.___StartTime, value); }
///
/// 当前统计区间的结束时间
///
public DateTimeOffset EndTime { get => this.___EndTime; set => this.SetField(ref this.___EndTime, value); }
///
/// 当前统计区间的时长
///
public TimeSpan Duration { get => this.___Duration; set => this.SetField(ref this.___Duration, value); }
///
/// 下载了的数据量
///
public int NetworkBytesDownloaded { get => this.___NetworkBytesDownloaded; set => this.SetField(ref this.___NetworkBytesDownloaded, value); }
///
/// 平均下载速度,mibi-bits per second
///
public double NetworkMbps { get => this.___NetworkMbps; set => this.SetField(ref this.___NetworkMbps, value); }
///
/// 统计区间内的磁盘写入耗时
///
public TimeSpan DiskWriteDuration { get => this.___DiskWriteDuration; set => this.SetField(ref this.___DiskWriteDuration, value); }
///
/// 统计区间内写入磁盘的数据量
///
public int DiskBytesWritten { get => this.___DiskBytesWritten; set => this.SetField(ref this.___DiskBytesWritten, value); }
///
/// 平均写入速度,mibi-bytes per second
///
public double DiskMBps { get => this.___DiskMBps; set => this.SetField(ref this.___DiskMBps, value); }
#endregion
#region Recording Stats Properties
///
/// 从录制开始到现在一共经过的时间
///
public TimeSpan SessionDuration { get => this.___SessionDuration; set => this.SetField(ref this.___SessionDuration, 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 long CurrentFileSize { get => this.___CurrentFileSize; set => this.SetField(ref this.___CurrentFileSize, 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 AddedDuration { get => this.___AddedDuration; set => this.SetField(ref this.___AddedDuration, value); }
///
/// 当前这一个统计区间所经过的时间长度
///
public double PassedTime { get => this.___PassedTime; set => this.SetField(ref this.___PassedTime, value); }
///
/// 录制速度比例
///
public double DurationRatio { get => this.___DurationRatio; set => this.SetField(ref this.___DurationRatio, value); }
//----------------------------------------
///
/// 当前统计区间新收到的视频数据大小
///
public long InputVideoBytes { get => this.___InputVideoBytes; set => this.SetField(ref this.___InputVideoBytes, value); }
///
/// 当前统计区间新收到的音频数据大小
///
public long InputAudioBytes { get => this.___InputAudioBytes; set => this.SetField(ref this.___InputAudioBytes, value); }
///
/// 当前统计区间新写入的视频帧数量
///
public int OutputVideoFrames { get => this.___OutputVideoFrames; set => this.SetField(ref this.___OutputVideoFrames, value); }
///
/// 当前统计区间新写入的音频帧数量
///
public int OutputAudioFrames { get => this.___OutputAudioFrames; set => this.SetField(ref this.___OutputAudioFrames, value); }
///
/// 当前统计区间新写入的视频数据大小
///
public long OutputVideoBytes { get => this.___OutputVideoBytes; set => this.SetField(ref this.___OutputVideoBytes, value); }
///
/// 当前统计区间新写入的音频数据大小
///
public long OutputAudioBytes { get => this.___OutputAudioBytes; set => this.SetField(ref this.___OutputAudioBytes, value); }
///
/// 总共收到的视频数据大小
///
public long TotalInputVideoBytes { get => this.___TotalInputVideoBytes; set => this.SetField(ref this.___TotalInputVideoBytes, value); }
///
/// 总共收到的音频数据大小
///
public long TotalInputAudioBytes { get => this.___TotalInputAudioBytes; set => this.SetField(ref this.___TotalInputAudioBytes, value); }
///
/// 总共写入的视频帧数量
///
public int TotalOutputVideoFrames { get => this.___TotalOutputVideoFrames; set => this.SetField(ref this.___TotalOutputVideoFrames, value); }
///
/// 总共写入的音频帧数量
///
public int TotalOutputAudioFrames { get => this.___TotalOutputAudioFrames; set => this.SetField(ref this.___TotalOutputAudioFrames, value); }
///
/// 总共写入的视频数据大小
///
public long TotalOutputVideoBytes { get => this.___TotalOutputVideoBytes; set => this.SetField(ref this.___TotalOutputVideoBytes, value); }
///
/// 总共写入的音频数据大小
///
public long TotalOutputAudioBytes { get => this.___TotalOutputAudioBytes; set => this.SetField(ref this.___TotalOutputAudioBytes, value); }
#endregion
public void Reset()
{
this.SessionDuration = TimeSpan.Zero;
this.SessionMaxTimestamp = TimeSpan.Zero;
this.FileMaxTimestamp = TimeSpan.Zero;
//this.DurationRatio = double.NaN;
// ------------------------------
this.StreamHost = null;
this.StartTime = default;
this.EndTime = default;
this.Duration = default;
this.NetworkBytesDownloaded = default;
this.NetworkMbps = default;
this.DiskWriteDuration = default;
this.DiskBytesWritten = default;
this.DiskMBps = default;
// ------------------------------
this.SessionDuration = default;
this.TotalInputBytes = default;
this.TotalOutputBytes = default;
this.CurrentFileSize = default;
this.SessionMaxTimestamp = default;
this.FileMaxTimestamp = default;
this.AddedDuration = default;
this.PassedTime = default;
this.DurationRatio = double.NaN;
this.InputVideoBytes = default;
this.InputAudioBytes = default;
this.OutputVideoFrames = default;
this.OutputAudioFrames = default;
this.OutputVideoBytes = default;
this.OutputAudioBytes = default;
this.TotalInputVideoBytes = default;
this.TotalInputAudioBytes = default;
this.TotalOutputVideoFrames = default;
this.TotalOutputAudioFrames = default;
this.TotalOutputVideoBytes = default;
this.TotalOutputAudioBytes = default;
}
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
protected bool SetField(ref T location, T value, [CallerMemberName] string propertyName = "")
{
if (EqualityComparer.Default.Equals(location, value))
return false;
location = value;
this.OnPropertyChanged(propertyName);
return true;
}
}
}