Skip to content

Commit d5c3091

Browse files
author
lewis
committed
-added PushData method to TsPacketFactory
-added TsPacketReady event to TsPacketFactory
1 parent e497e3a commit d5c3091

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

Cinegy.TsDecoder.userprefs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Properties>
2+
<MonoDevelop.Ide.Workbench ActiveDocument="Cinegy.TsDecoder/TransportStream/TsPacketFactory.cs">
3+
<Files>
4+
<File FileName="Cinegy.TsDecoder/project.json" Line="4" Column="19" />
5+
<File FileName="Cinegy.TsDecoder/TransportStream/TsPacketFactory.cs" Line="1" Column="1" />
6+
</Files>
7+
</MonoDevelop.Ide.Workbench>
8+
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
9+
<MonoDevelop.Ide.DebuggingService.Breakpoints>
10+
<BreakpointStore />
11+
</MonoDevelop.Ide.DebuggingService.Breakpoints>
12+
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
13+
<MultiItemStartupConfigurations />
14+
</Properties>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"version": 1,
3+
"dgSpecHash": "emMfyldg5EuVLztC264ADohfhSxLFaVexkmU1vwU16tOlrYppJJ1GoN7iQiGDbIAwvPEpqkoDR+aqhNKa+hYmg==",
4+
"success": true
5+
}

Cinegy.TsDecoder/TransportStream/TsPacketFactory.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,33 @@ public TsPacketFactory(byte TsPacketSize)
3939
TsPacketFixedSize = TsPacketSize;
4040
}
4141

42+
/// <summary>
43+
/// Accepts a data array, and loads this data into the factory. When data is pushed, it will raise a TsPacketReady event for each TS packet that is generated.
44+
/// </summary>
45+
/// <param name="data">Byte array containing TS stream data</param>
46+
/// <param name="dataSize">Optional length parameter to limit amount of data read from referenced array.</param>
47+
public void PushData(byte[] data, int dataSize = 0, bool retainPayload = true, bool preserveSourceData = false)
48+
{
49+
if (dataSize == 0)
50+
{
51+
dataSize = data.Length;
52+
}
53+
54+
var packets = GetTsPacketsFromData(data, dataSize,retainPayload,preserveSourceData);
55+
56+
foreach (var tsPacket in packets)
57+
{
58+
OnTsPacketReadyDetected(tsPacket);
59+
}
60+
61+
}
62+
4263
/// <summary>
4364
/// Returns TsPackets for any input data. If data ends with incomplete packet, this is stored and prepended to next call.
4465
/// If data stream is restarted, prior buffer will be skipped as sync will not be acknowledged - but any restarts should being with first byte as sync to avoid possible merging with prior data if lengths coincide.
4566
/// </summary>
4667
/// <param name="data">Aligned or unaligned data buffer containing TS packets. Aligned is more efficient if possible.</param>
68+
/// <param name="dataSize">Optional length parameter to limit amount of data read from referenced array.</param>
4769
/// <param name="retainPayload">Optional parameter to trigger any resulting TS payload to be copied into the returned structure</param>
4870
/// <param name="preserveSourceData">Optional parameter to trigger complete copy of source data for TS packet to be held in array for quick access</param>
4971
/// <returns>Complete TS packets from this data and any prior partial data rolled over.</returns>
@@ -301,5 +323,22 @@ public static int FindSync(IList<byte> tsData, int offset, int TsPacketSize)
301323
throw;
302324
}
303325
}
326+
327+
// a complete TS packet is ready for callbacks...
328+
public event TsPacketReadyEventHandler TsPacketReady;
329+
public delegate void TsPacketReadyEventHandler(object sender, TsPacketReadyEventArgs args);
330+
331+
protected virtual void OnTsPacketReadyDetected(TsPacket tsPacket)
332+
{
333+
var handler = TsPacketReady;
334+
if (handler == null) return;
335+
var args = new TsPacketReadyEventArgs { TsPacket = tsPacket };
336+
handler(this, args);
337+
}
338+
}
339+
340+
public class TsPacketReadyEventArgs : EventArgs
341+
{
342+
public TsPacket TsPacket { get; set; }
304343
}
305344
}

0 commit comments

Comments
 (0)