Added an optional feature to procecss MPE Packets multi-threaded.
All checks were successful
🚀 Pack skyscraper8 / make-zip (push) Successful in 1m0s
All checks were successful
🚀 Pack skyscraper8 / make-zip (push) Successful in 1m0s
This commit is contained in:
parent
e86a89846d
commit
0cddb3b085
@ -17,15 +17,43 @@ namespace skyscraper5.Dvb.DataBroadcasting
|
||||
class MultiprotocolEncapsulationDecoder : IPsiProcessor
|
||||
{
|
||||
private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
|
||||
private const bool ENABLE_MULTITHREADING = false;
|
||||
|
||||
public IMultiprotocolEncapsulationEventHandler EventHandler { get; }
|
||||
|
||||
public MultiprotocolEncapsulationDecoder(IMultiprotocolEncapsulationEventHandler eventHandler)
|
||||
{
|
||||
EventHandler = eventHandler;
|
||||
restartRequired = true;
|
||||
}
|
||||
|
||||
public void GatherPsi(PsiSection section, int sourcePid)
|
||||
{
|
||||
if (!ENABLE_MULTITHREADING)
|
||||
{
|
||||
GatherPsiEx(section, sourcePid);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_actionQueue == null)
|
||||
_actionQueue = new Queue<Action>();
|
||||
|
||||
lock (_actionQueue)
|
||||
{
|
||||
_actionQueue.Enqueue(() => { GatherPsiEx(section, sourcePid); });
|
||||
}
|
||||
|
||||
if (restartRequired)
|
||||
{
|
||||
restartRequired = false;
|
||||
_actionQueueThread = new Thread(SeperatedThreadFunction);
|
||||
_actionQueueThread.Name = String.Format("MPE Decoder Thread for PID 0x{0:X4}", sourcePid);
|
||||
_actionQueueThread.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GatherPsiEx(PsiSection section, int sourcePid)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(section.GetDataCopy(), false);
|
||||
if (ms.Length < 12)
|
||||
@ -70,11 +98,36 @@ namespace skyscraper5.Dvb.DataBroadcasting
|
||||
}
|
||||
else
|
||||
{
|
||||
HandleIpDatagram(sourcePid,payload);
|
||||
HandleIpDatagram(sourcePid, payload);
|
||||
}
|
||||
}
|
||||
|
||||
private Thread _actionQueueThread;
|
||||
private Queue<Action> _actionQueue;
|
||||
private bool restartRequired;
|
||||
private void SeperatedThreadFunction()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
int remainingElements = 0;
|
||||
lock (_actionQueue)
|
||||
{
|
||||
remainingElements = _actionQueue.Count;
|
||||
}
|
||||
if (remainingElements == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Action action = null;
|
||||
lock (_actionQueue)
|
||||
{
|
||||
action = _actionQueue.Dequeue();
|
||||
}
|
||||
action();
|
||||
}
|
||||
restartRequired = true;
|
||||
}
|
||||
|
||||
private bool announcedLlcTraffic;
|
||||
private void HandleLlcSnap(int sourcePid, byte[] macAddress, byte[] payload)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user