Added a entropy-calculating filter.
All checks were successful
🚀 Pack skyscraper8 / make-zip (push) Successful in 3m54s

This commit is contained in:
Fey 2026-01-28 18:04:51 +01:00
parent d1ba3976cb
commit 8aa9ac82d4
2 changed files with 60 additions and 12 deletions

View File

@ -57,6 +57,8 @@ namespace skyscraper8.Skyscraper.Math
}
//Raise events if we feel like it
if (EntropyRising != null || EntropyFalling != null)
{
if (newEntropy != Entropy)
{
double oldEntropy = Entropy;
@ -67,6 +69,7 @@ namespace skyscraper8.Skyscraper.Math
else if (newEntropy < Entropy)
EntropyFalling?.Invoke(oldEntropy, newEntropy, oldPercentage, newPercentage);
}
}
_entropy = newEntropy;
}

View File

@ -0,0 +1,45 @@
using skyscraper5.Mpeg2;
using skyscraper5.src.Mpeg2.PacketFilter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace skyscraper8.Skyscraper.Math
{
public class PidEntryCalculatorFilter : IPacketFilter
{
public bool PassPacket(TsPacket packet)
{
if (entropyCalculatorStreams == null)
entropyCalculatorStreams = new EntropyCalculatorStream[0x1fff];
if (packet.PayloadFlagSet)
{
uint pid = packet.PID;
if (entropyCalculatorStreams[pid] == null)
entropyCalculatorStreams[pid] = new EntropyCalculatorStream();
entropyCalculatorStreams[pid].Write(packet.Payload);
}
return true;
}
private EntropyCalculatorStream[] entropyCalculatorStreams;
public double GetEntropy(int pid)
{
if (pid < 0)
throw new ArgumentOutOfRangeException(nameof(pid));
if (pid > entropyCalculatorStreams.Length)
throw new ArgumentOutOfRangeException(nameof(pid));
EntropyCalculatorStream stream = entropyCalculatorStreams[pid];
if (stream == null)
return double.NaN;
return stream.Entropy;
}
}
}