Refactor ATSC PLP Parser to use Span<byte> instead of byte[]
All checks were successful
🚀 Pack skyscraper8 / make-zip (push) Successful in 56s
All checks were successful
🚀 Pack skyscraper8 / make-zip (push) Successful in 56s
This commit is contained in:
parent
ef903cba96
commit
1843d914ed
@ -13,10 +13,9 @@ namespace skyscraper8.Atsc.A322
|
||||
{
|
||||
internal class AtscPlpBasebandParser
|
||||
{
|
||||
internal void PushBbframe(byte[] payload)
|
||||
internal void PushBbframe(Span<byte> payload)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(payload);
|
||||
byte a = ms.ReadUInt8();
|
||||
byte a = payload[0];
|
||||
bool mode = ((a >> 7) & 0x01) != 0;
|
||||
int pointer = (a & 0x7f);
|
||||
int addToPointer;
|
||||
@ -29,7 +28,7 @@ namespace skyscraper8.Atsc.A322
|
||||
else
|
||||
{
|
||||
addToPointer = 2;
|
||||
byte b = ms.ReadUInt8();
|
||||
byte b = payload[1];
|
||||
pointer |= (((b >> 2) & 0x3F) << 7);
|
||||
OfiDescription ofi = (OfiDescription)(b & 0x3);
|
||||
switch (ofi)
|
||||
@ -37,29 +36,45 @@ namespace skyscraper8.Atsc.A322
|
||||
case OfiDescription.NoExtensionMode:
|
||||
break;
|
||||
case OfiDescription.LongExtensionMode:
|
||||
byte lc = ms.ReadUInt8();
|
||||
byte lc = payload[2];
|
||||
addToPointer++;
|
||||
int extType = (lc >> 5) & 0x7;
|
||||
int extLen = (lc) & 0x1F;
|
||||
byte ld = ms.ReadUInt8();
|
||||
byte ld = payload[3];
|
||||
addToPointer++;
|
||||
extLen |= (((ld) & 0xFF) << 5);
|
||||
// see A322-2026-04-Physical-Layer-Protocol.pdf, Table 5.2
|
||||
//0 = counter
|
||||
//7 = padding
|
||||
byte[] extensionFiled = ms.ReadBytes(extLen);
|
||||
Span<byte> extensionField = payload.Slice(4, extLen);
|
||||
addToPointer += extLen;
|
||||
if (extType != 7)
|
||||
{
|
||||
throw new NotImplementedException(String.Format("ATSC 3.0 BBFRAME Padding Type {0} not yet implemented.", extType));
|
||||
}
|
||||
HandleExtension(true, extType, extensionField);
|
||||
break;
|
||||
case OfiDescription.ShortExtensionMode:
|
||||
byte lc2 = payload[2];
|
||||
addToPointer++;
|
||||
int extType2 = (lc2 >> 5) & 0x07;
|
||||
int extLen2 = (lc2) & 0x1f;
|
||||
|
||||
Span<byte> extensionField2 = payload.Slice(4, extLen2);
|
||||
addToPointer += extLen2;
|
||||
HandleExtension(false, extType2, extensionField2);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException(String.Format("{0} is not yet implemented in the ATSC 3.0 BBFrame Parser.", ofi));
|
||||
}
|
||||
}
|
||||
|
||||
while (ms.GetAvailableBytes() > 0)
|
||||
Span<byte> bbHeaderStripped = payload.Slice(addToPointer);
|
||||
if (pointer + 4 > bbHeaderStripped.Length)
|
||||
{
|
||||
Console.WriteLine("BBFRame, offset: {0}, less than four bytes left.", pointer);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("BBFRame, offset: {0}, first bytes: 0x{1:X2}{2:X2}{3:X2}{4:X2}", pointer, bbHeaderStripped[pointer], bbHeaderStripped[pointer + 1], bbHeaderStripped[pointer + 2], bbHeaderStripped[pointer + 3]);
|
||||
}
|
||||
/*while (ms.GetAvailableBytes() > 0)
|
||||
{
|
||||
switch(stateMachineState)
|
||||
{
|
||||
@ -169,7 +184,17 @@ namespace skyscraper8.Atsc.A322
|
||||
default:
|
||||
throw new NotImplementedException(String.Format("ATSC PLP Baseband Parser State machine state #{0}", stateMachineState));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private void HandleExtension(bool isLongExtension, int extType, Span<byte> extensionField)
|
||||
{
|
||||
if (extType == 7)
|
||||
{
|
||||
//Padding
|
||||
return;
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void DeliverPacket(AlpPacket? currentAlpPacket, byte[]? neededBuffer)
|
||||
|
||||
@ -94,7 +94,8 @@ namespace skyscraper8.Atsc.A324
|
||||
}
|
||||
else if (plp <= 63)
|
||||
{
|
||||
HandlePlp(plp, rtpPacket.RtpPayload);
|
||||
Span<byte> rtpPayloadSpan = new Span<byte>(rtpPacket.RtpPayload);
|
||||
HandlePlp(plp, rtpPayloadSpan);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -149,7 +150,7 @@ namespace skyscraper8.Atsc.A324
|
||||
}
|
||||
|
||||
private AtscPlpBasebandParser[] plps;
|
||||
private void HandlePlp(ushort plp, byte[] rtpPayload)
|
||||
private void HandlePlp(ushort plp, Span<byte> rtpPayload)
|
||||
{
|
||||
if (plps == null)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user