Class TsFormatParser
Provides MPEG-2 Transport Stream format parsing and encoding capabilities, including program association table (PAT) and program map table (PMT) processing, PES packet demultiplexing, and stream descriptor management.
public class TsFormatParser : IDisposable
- Inheritance
-
TsFormatParser
- Implements
- Inherited Members
Constructors
TsFormatParser()
Initializes a new instance of the TsFormatParser class.
public TsFormatParser()
Properties
CombineOutputPackets
Gets or sets a value indicating whether output packets should be combined. When set, the value is propagated to all known PES streams.
public bool CombineOutputPackets { get; set; }
Property Value
IgnoreScrambledFlag
Gets or sets a value indicating whether the scrambled flag should be ignored during parsing.
public bool IgnoreScrambledFlag { get; set; }
Property Value
IgnoreTimestampJump
Gets or sets a value indicating whether timestamp jumps should be ignored. When set, the value is propagated to all known PES streams. Non-audio and non-video streams always ignore timestamp jumps regardless of this setting.
public bool IgnoreTimestampJump { get; set; }
Property Value
IsLive
Gets or sets a value indicating whether the stream is live. Defaults to true.
public bool IsLive { get; set; }
Property Value
LoosePesAssembling
Gets or sets a value indicating whether loose PES assembling mode is enabled. When set, the value is propagated to all known PID streams.
public bool LoosePesAssembling { get; set; }
Property Value
MediaTypeConfirmationCount
Gets or sets the number of confirmations required before a media type is considered stable. When set, the value is propagated to all known PES streams.
public int MediaTypeConfirmationCount { get; set; }
Property Value
Mtu
Gets or sets the maximum transmission unit (MTU) size for output packets. When set, the value is propagated to all known PES streams.
public int Mtu { get; set; }
Property Value
PesFilter
Gets or sets the PES PID filter. When set, only elementary streams matching the specified PES PIDs are monitored, and all other elementary streams are removed.
public Dictionary<ushort, ushort> PesFilter { get; set; }
Property Value
PmtFilter
Gets or sets the PMT PID filter. When set, only programs matching the specified PMT PIDs are monitored, and all other programs are discarded.
public HashSet<ushort> PmtFilter { get; set; }
Property Value
ProgramCount
Gets the number of discovered programs.
public int ProgramCount { get; }
Property Value
ProgramDescriptorDirty
Gets or sets a value indicating whether the program descriptor has been modified and needs to be re-read.
public bool ProgramDescriptorDirty { get; set; }
Property Value
ProgramDescriptorReady
Gets or sets a value indicating whether the program descriptor is ready.
public bool ProgramDescriptorReady { get; set; }
Property Value
StreamDetectionTimeout
Gets or sets the stream detection timeout in 100-nanosecond intervals. Defaults to 30 seconds.
public long StreamDetectionTimeout { get; set; }
Property Value
StreamDetectionTimeoutBytes
Gets or sets the stream detection timeout in bytes. Defaults to 1048576 (1 MB).
public long StreamDetectionTimeoutBytes { get; set; }
Property Value
StripDownMedia
Gets or sets a value indicating whether media data should be stripped down. When set, the value is propagated to all known PES streams.
public bool StripDownMedia { get; set; }
Property Value
Methods
Decode(VersatileBuffer)
Decodes transport stream data from the specified data packet.
public List<VersatileBuffer> Decode(VersatileBuffer dataPacket)
Parameters
dataPacketVersatileBufferThe data packet to decode, or
nullto process buffered data.
Returns
- List<VersatileBuffer>
A list of decoded media sample buffers.
Decode(VersatileBuffer, int, int)
Decodes transport stream data from the specified data packet starting at the given position.
public List<VersatileBuffer> Decode(VersatileBuffer dataPacket, int position, int bytesToRead)
Parameters
dataPacketVersatileBufferThe data packet to decode, or
nullto process buffered data.positionintThe byte offset within the data packet to start reading from.
bytesToReadintThe number of bytes to read from the data packet.
Returns
- List<VersatileBuffer>
A list of decoded media sample buffers.
Decode(VersatileBufferStream)
Decodes transport stream data from the specified buffer stream.
public List<VersatileBuffer> Decode(VersatileBufferStream stream)
Parameters
streamVersatileBufferStreamThe buffer stream to decode, or
nullto process buffered data.
Returns
- List<VersatileBuffer>
A list of decoded media sample buffers.
DiscardStream(int, int, bool)
Discards or un-discards a specific stream or an entire program at the specified indices.
When streamIndex is negative, the entire program is discarded or un-discarded.
public void DiscardStream(int programIndex, int streamIndex, bool discardValue)
Parameters
programIndexintThe zero-based index of the program.
streamIndexintThe zero-based index of the stream within the program, or a negative value to target the entire program.
discardValueboolA value of
trueto discard the stream or program;falseto un-discard it.
Discontinuity()
Signals a discontinuity to all known PID streams, resetting their internal state.
public void Discontinuity()
Dispose()
Releases all resources used by the TsFormatParser class.
public void Dispose()
Encode()
Encodes control information (PAT, PMT, and PCR packets) for all programs. This overload does not force encoding and respects the minimum interval between encodings.
public void Encode()
Encode(bool)
Encodes control information (PAT, PMT, and PCR packets) for all programs.
public void Encode(bool force)
Parameters
forceboolIf
true, forces encoding regardless of the minimum interval; otherwise, encoding is throttled to once every 50 milliseconds.
Encode(VersatileBuffer, int, int, long, long)
Encodes a media sample into PES packets and enqueues them for output.
public void Encode(VersatileBuffer sample, int programIndex, int streamIndex, long dts, long pts)
Parameters
sampleVersatileBufferThe media sample buffer to encode.
programIndexintThe zero-based index of the program.
streamIndexintThe zero-based index of the stream within the program.
dtslongThe decode timestamp in 100-nanosecond intervals.
ptslongThe presentation timestamp in 100-nanosecond intervals.
Flush()
Flushes all known PID streams, clears the output queue, trims the internal data stream, and releases any pre-decoded buffers.
public void Flush()
GetProgramPid(int)
Gets the PMT PID for the program at the specified index.
public int GetProgramPid(int programIndex)
Parameters
programIndexintThe zero-based index of the program.
Returns
- int
The PMT PID of the program, or
-1if the index is out of range.
GetSendPacket()
Dequeues and returns the next packet from the send queue.
public VersatileBuffer GetSendPacket()
Returns
- VersatileBuffer
The next VersatileBuffer packet, or
nullif the queue is empty.
GetSendPackets()
Dequeues and returns all packets from the send queue.
public List<VersatileBuffer> GetSendPackets()
Returns
- List<VersatileBuffer>
A list of all VersatileBuffer packets from the output queue.
GetSendQueueCount()
Gets the number of packets currently in the send queue.
public int GetSendQueueCount()
Returns
- int
The number of packets in the output queue.
GetStreamDescriptor(int)
Gets the stream descriptor containing media types for all streams in the specified program.
public List<MediaType> GetStreamDescriptor(int programIndex)
Parameters
programIndexintThe zero-based index of the program.
Returns
SetStreamDescriptor(int, List<MediaType>)
Sets the stream descriptor for the specified program, creating or updating elementary streams and their corresponding PES stream handlers.
public void SetStreamDescriptor(int programIndex, List<MediaType> streamDescriptor)