Added a entropy-calculating filter.
All checks were successful
🚀 Pack skyscraper8 / make-zip (push) Successful in 3m54s
All checks were successful
🚀 Pack skyscraper8 / make-zip (push) Successful in 3m54s
This commit is contained in:
parent
d1ba3976cb
commit
8aa9ac82d4
@ -57,15 +57,18 @@ namespace skyscraper8.Skyscraper.Math
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Raise events if we feel like it
|
//Raise events if we feel like it
|
||||||
if (newEntropy != Entropy)
|
if (EntropyRising != null || EntropyFalling != null)
|
||||||
{
|
{
|
||||||
double oldEntropy = Entropy;
|
if (newEntropy != Entropy)
|
||||||
double oldPercentage = Percentage;
|
{
|
||||||
double newPercentage = (newEntropy / 8.0) * 100.0;
|
double oldEntropy = Entropy;
|
||||||
if (newEntropy > Entropy)
|
double oldPercentage = Percentage;
|
||||||
EntropyRising?.Invoke(oldEntropy, newEntropy, oldPercentage, newPercentage);
|
double newPercentage = (newEntropy / 8.0) * 100.0;
|
||||||
else if (newEntropy < Entropy)
|
if (newEntropy > Entropy)
|
||||||
EntropyFalling?.Invoke(oldEntropy, newEntropy, oldPercentage, newPercentage);
|
EntropyRising?.Invoke(oldEntropy, newEntropy, oldPercentage, newPercentage);
|
||||||
|
else if (newEntropy < Entropy)
|
||||||
|
EntropyFalling?.Invoke(oldEntropy, newEntropy, oldPercentage, newPercentage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_entropy = newEntropy;
|
_entropy = newEntropy;
|
||||||
|
|||||||
45
skyscraper8/Skyscraper/Math/PidEntryCalculatorFilter.cs
Normal file
45
skyscraper8/Skyscraper/Math/PidEntryCalculatorFilter.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user