MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
Public Member Functions | Static Public Member Functions | Protected Attributes
TS::Packet Class Reference

Class for reading and writing TS Streams. More...

#include <ts_packet.h>

Inheritance diagram for TS::Packet:
TS::ProgramAssociationTable TS::ProgramAssociationTable TS::ProgramMappingTable TS::ProgramMappingTable

Public Member Functions

 Packet ()
 This constructor creates an empty Packet, ready for use for either reading or writing. More...
 
 Packet ()
 
 Packet (const Packet &rhs)
 
 Packet (const Packet &rhs)
 
 ~Packet ()
 
 ~Packet ()
 The deconstructor deletes all space that may be occupied by a Packet. More...
 
void addStuffing ()
 Adds stuffing to the Packet depending on how much content you want to send. More...
 
void addStuffing ()
 
const char * checkAndGetBuffer () const
 
const char * checkAndGetBuffer () const
 Checks the size of the internal packet buffer (prints error if size !=188), then returns a pointer to the data. More...
 
void clear ()
 
void clear ()
 Sets the packet pos to 4, and resets the first 4 fields to defaults (including sync byte on pos 0) More...
 
int fillFree (const char *PackageData, int maxLen)
 Fills the free bytes of the Packet. More...
 
int fillFree (const char *PackageData, int maxLen)
 
bool FromFile (FILE *data)
 This function fills a Packet from a file. More...
 
bool FromFile (FILE *data)
 
bool FromPointer (const char *data)
 This funtion fills a Packet from a char array. More...
 
bool FromPointer (const char *data)
 
int getAdaptationField () const
 
int getAdaptationField () const
 Gets whether a Packet contains an adaptationfield. More...
 
int getAdaptationFieldLen () const
 
int getAdaptationFieldLen () const
 Gets the current length of the adaptationfield. More...
 
unsigned int getBytesFree () const
 Gets the amount of bytes that are not written yet in a Packet. More...
 
unsigned int getBytesFree () const
 
int getContinuityCounter () const
 Gets the Continuity Counter of a single Packet. More...
 
int getContinuityCounter () const
 
unsigned int getDataSize () const
 
unsigned int getDataSize () const
 
int64_t getOPCR () const
 Gets the OPCR (Original Program Clock Reference) of a Packet. More...
 
int64_t getOPCR () const
 
const char * getPayload () const
 returns the character buffer with a std::string wrapper More...
 
const char * getPayload () const
 
int getPayloadLength () const
 Gets the length of the payload for this apcket. More...
 
int getPayloadLength () const
 
int64_t getPCR () const
 Gets the PCR (Program Clock Reference) of a Packet. More...
 
int64_t getPCR () const
 
unsigned int getPID () const
 
unsigned int getPID () const
 Gets the PID of a single Packet. More...
 
bool getRandomAccess () const
 Gets whether this Packet can be accessed at random (indicates keyframe). More...
 
bool getRandomAccess () const
 
unsigned int getTransportScramblingControl () const
 Gets the transport scrambling control of a Packet. More...
 
unsigned int getTransportScramblingControl () const
 
bool getUnitStart () const
 Gets the payload unit start inficator of a Packet. More...
 
bool getUnitStart () const
 
bool hasDiscontinuity () const
 
bool hasDiscontinuity () const
 
bool hasESpriority () const
 
bool hasESpriority () const
 Gets the elementary stream priority indicator of a Packet. More...
 
bool hasOPCR () const
 
bool hasOPCR () const
 Gets the value of the OPCR flag. More...
 
bool hasPCR () const
 
bool hasPCR () const
 Gets the value of the PCR flag. More...
 
bool hasPriority () const
 
bool hasPriority () const
 Gets the transport priority of a Packet. More...
 
bool hasSplicingPoint () const
 
bool hasSplicingPoint () const
 Gets the value of the splicing point flag. More...
 
bool hasTransportError () const
 
bool hasTransportError () const
 Gets the transport error inficator of a Packet. More...
 
bool isPMT () const
 
bool isPMT () const
 Returns true if this PID contains a PMT. More...
 
 operator bool () const
 
 operator bool () const
 
void setAdaptationField (int NewVal)
 
void setAdaptationField (int NewVal)
 Sets the selection value for an adaptationfield of a Packet. More...
 
void setContinuityCounter (int NewContinuity)
 Sets the Continuity Counter of a single Packet. More...
 
void setContinuityCounter (int NewContinuity)
 
void setDefaultPAT ()
 Transforms the Packet into a standard Program Association Table. More...
 
void setDefaultPAT ()
 
void setDiscontinuity (bool newVal)
 
void setDiscontinuity (bool newVal)
 
void setPCR (int64_t NewVal)
 Sets the PCR (Program Clock Reference) of a Packet. More...
 
void setPCR (int64_t NewVal)
 
void setPID (int NewPID)
 Sets the PID of a single Packet. More...
 
void setPID (int NewPID)
 
void setRandomAccess (bool newVal)
 
void setRandomAccess (bool newVal)
 Gets the value of the transport private data point flag. More...
 
void setUnitStart (bool newVal)
 Sets the start of a new unit in this Packet. More...
 
void setUnitStart (bool newVal)
 
std::string toPrettyString (size_t indent=0, int detailLevel=3) const
 Prints a packet to stdout, for analyser purposes. More...
 
std::string toPrettyString (size_t indent=0, int detailLevel=3) const
 
void updPos (unsigned int newPos)
 
void updPos (unsigned int newPos)
 update position in character array (pos), More...
 

Static Public Member Functions

static std::string & getPESAudioLeadIn (unsigned int len, unsigned long long PTS)
 Generates a PES Lead-in for an audio frame. More...
 
static std::string & getPESAudioLeadIn (unsigned int len, unsigned long long PTS)
 
static std::string & getPESVideoLeadIn (unsigned int len, unsigned long long PTS, unsigned long long offset, bool isAligned)
 
static std::string & getPESVideoLeadIn (unsigned int len, unsigned long long PTS, unsigned long long offset, bool isAligned)
 Generates a PES Lead-in for a video frame. More...
 

Protected Attributes

unsigned int pos
 
char strBuf [189]
 

Detailed Description

Class for reading and writing TS Streams.

The class is capable of analyzing a packet of 188 bytes and calculating key values

Constructor & Destructor Documentation

TS::Packet::Packet ( )

This constructor creates an empty Packet, ready for use for either reading or writing.

All this constructor does is call Packet::clear().

TS::Packet::Packet ( const Packet rhs)
TS::Packet::~Packet ( )

The deconstructor deletes all space that may be occupied by a Packet.

TS::Packet::Packet ( )
TS::Packet::Packet ( const Packet rhs)
TS::Packet::~Packet ( )

Member Function Documentation

void TS::Packet::addStuffing ( )

Adds stuffing to the Packet depending on how much content you want to send.

Parameters
NumBytesthe amount of non-stuffing content bytes you want to send.
Returns
The amount of content bytes that can be send.
Todo:
more stuffing required
void TS::Packet::addStuffing ( )
const char * TS::Packet::checkAndGetBuffer ( ) const

Checks the size of the internal packet buffer (prints error if size !=188), then returns a pointer to the data.

Returns
A character pointer to the internal packet buffer data
const char* TS::Packet::checkAndGetBuffer ( ) const
void TS::Packet::clear ( )
void TS::Packet::clear ( )

Sets the packet pos to 4, and resets the first 4 fields to defaults (including sync byte on pos 0)

int TS::Packet::fillFree ( const char *  NewVal,
int  maxLen 
)

Fills the free bytes of the Packet.

Stores as many bytes from NewVal as possible in the packet. The minimum of Packet::BytesFree and maxLen is used.

Parameters
NewValThe data to store in the packet.
maxLenThe maximum amount of bytes to store.
int TS::Packet::fillFree ( const char *  PackageData,
int  maxLen 
)
bool TS::Packet::FromFile ( FILE *  data)
bool TS::Packet::FromFile ( FILE *  data)

This function fills a Packet from a file.

It fills the content with the next 188 bytes int he file.

Parameters
DataThe data to be read into the packet.
Returns
true if it was possible to read in a full packet, false otherwise.
bool TS::Packet::FromPointer ( const char *  data)

This funtion fills a Packet from a char array.

It fills the content with the first 188 characters of a char array

Parameters
DataThe char array that contains the data to be read into the packet
Returns
true if successful (which always happens, or else a segmentation fault should occur)
bool TS::Packet::FromPointer ( const char *  data)
int TS::Packet::getAdaptationField ( ) const

Gets whether a Packet contains an adaptationfield.

Returns
The existence of an adaptationfield.
  • 0: No adaptationfield present.
  • 1: Adaptationfield is present.
int TS::Packet::getAdaptationField ( ) const
int TS::Packet::getAdaptationFieldLen ( ) const
int TS::Packet::getAdaptationFieldLen ( ) const

Gets the current length of the adaptationfield.

Returns
The length of the adaptationfield.
unsigned int TS::Packet::getBytesFree ( ) const
unsigned int TS::Packet::getBytesFree ( ) const

Gets the amount of bytes that are not written yet in a Packet.

Returns
The amount of bytes that can still be written to this packet.
int TS::Packet::getContinuityCounter ( ) const
int TS::Packet::getContinuityCounter ( ) const

Gets the Continuity Counter of a single Packet.

Returns
The value of the Continuity Counter.
unsigned int TS::Packet::getDataSize ( ) const
unsigned int TS::Packet::getDataSize ( ) const
int64_t TS::Packet::getOPCR ( ) const

Gets the OPCR (Original Program Clock Reference) of a Packet.

Returns
The value of the OPCR.
int64_t TS::Packet::getOPCR ( ) const
const char * TS::Packet::getPayload ( ) const

returns the character buffer with a std::string wrapper

Returns
The raw TS data as a string Gets the payload of this packet, as a raw char array
The payload of this ts packet as a char pointer
const char* TS::Packet::getPayload ( ) const
int TS::Packet::getPayloadLength ( ) const

Gets the length of the payload for this apcket.

Returns
The amount of bytes payload in this packet
int TS::Packet::getPayloadLength ( ) const
int64_t TS::Packet::getPCR ( ) const

Gets the PCR (Program Clock Reference) of a Packet.

Returns
The value of the PCR.
int64_t TS::Packet::getPCR ( ) const
std::string & TS::Packet::getPESAudioLeadIn ( unsigned int  len,
unsigned long long  PTS 
)
static

Generates a PES Lead-in for an audio frame.

Prepends the lead-in to variable toSend, assumes toSend's length is all other data.

Parameters
lenThe length of this frame.
PTSThe timestamp of the frame.
static std::string& TS::Packet::getPESAudioLeadIn ( unsigned int  len,
unsigned long long  PTS 
)
static
std::string & TS::Packet::getPESVideoLeadIn ( unsigned int  len,
unsigned long long  PTS,
unsigned long long  offset,
bool  isAligned 
)
static

Generates a PES Lead-in for a video frame.

Prepends the lead-in to variable toSend, assumes toSend's length is all other data.

Parameters
lenThe length of this frame.
PTSThe timestamp of the frame.
static std::string& TS::Packet::getPESVideoLeadIn ( unsigned int  len,
unsigned long long  PTS,
unsigned long long  offset,
bool  isAligned 
)
static
unsigned int TS::Packet::getPID ( ) const

Gets the PID of a single Packet.

Returns
The value of the PID.
unsigned int TS::Packet::getPID ( ) const
bool TS::Packet::getRandomAccess ( ) const

Gets whether this Packet can be accessed at random (indicates keyframe).

Returns
Whether or not this Packet contains a keyframe.
bool TS::Packet::getRandomAccess ( ) const
unsigned int TS::Packet::getTransportScramblingControl ( ) const

Gets the transport scrambling control of a Packet.

Returns
The transport scrambling control of a Packet
unsigned int TS::Packet::getTransportScramblingControl ( ) const
bool TS::Packet::getUnitStart ( ) const
bool TS::Packet::getUnitStart ( ) const

Gets the payload unit start inficator of a Packet.

Returns
The payload unit start inficator of a Packet
bool TS::Packet::hasDiscontinuity ( ) const
bool TS::Packet::hasDiscontinuity ( ) const
bool TS::Packet::hasESpriority ( ) const
bool TS::Packet::hasESpriority ( ) const

Gets the elementary stream priority indicator of a Packet.

Returns
The elementary stream priority indicator of a Packet
bool TS::Packet::hasOPCR ( ) const

Gets the value of the OPCR flag.

Returns
true if there is an OPCR, false otherwise
bool TS::Packet::hasOPCR ( ) const
bool TS::Packet::hasPCR ( ) const

Gets the value of the PCR flag.

Returns
true if there is a PCR, false otherwise
bool TS::Packet::hasPCR ( ) const
bool TS::Packet::hasPriority ( ) const
bool TS::Packet::hasPriority ( ) const

Gets the transport priority of a Packet.

Returns
The transport priority of a Packet
bool TS::Packet::hasSplicingPoint ( ) const

Gets the value of the splicing point flag.

Returns
the value of the splicing point flag
bool TS::Packet::hasSplicingPoint ( ) const
bool TS::Packet::hasTransportError ( ) const
bool TS::Packet::hasTransportError ( ) const

Gets the transport error inficator of a Packet.

Returns
The transport error inficator of a Packet
bool TS::Packet::isPMT ( ) const
bool TS::Packet::isPMT ( ) const

Returns true if this PID contains a PMT.

Important caveat: only works if the corresponding PAT has been pretty-printed earlier!

TS::Packet::operator bool ( ) const
TS::Packet::operator bool ( ) const
void TS::Packet::setAdaptationField ( int  NewVal)
void TS::Packet::setAdaptationField ( int  NewSelector)

Sets the selection value for an adaptationfield of a Packet.

Parameters
NewSelectorThe new value of the selection bits.
  • 1: No AdaptationField.
  • 2: AdaptationField Only.
  • 3: AdaptationField followed by Data.
void TS::Packet::setContinuityCounter ( int  NewContinuity)
void TS::Packet::setContinuityCounter ( int  NewContinuity)

Sets the Continuity Counter of a single Packet.

Parameters
NewContinuityThe new Continuity Counter of the packet.
void TS::Packet::setDefaultPAT ( )

Transforms the Packet into a standard Program Association Table.

void TS::Packet::setDefaultPAT ( )
void TS::Packet::setDiscontinuity ( bool  newVal)
void TS::Packet::setDiscontinuity ( bool  newVal)
void TS::Packet::setPCR ( int64_t  NewVal)

Sets the PCR (Program Clock Reference) of a Packet.

Parameters
NewValThe new PCR Value.
void TS::Packet::setPCR ( int64_t  NewVal)
void TS::Packet::setPID ( int  NewPID)

Sets the PID of a single Packet.

Parameters
NewPIDThe new PID of the packet.
void TS::Packet::setPID ( int  NewPID)
void TS::Packet::setRandomAccess ( bool  NewVal)

Gets the value of the transport private data point flag.

Returns
the value of the transport private data point flag
void TS::Packet::setRandomAccess ( bool  newVal)
void TS::Packet::setUnitStart ( bool  newVal)
void TS::Packet::setUnitStart ( bool  NewVal)

Sets the start of a new unit in this Packet.

Parameters
NewValThe new value for the start of a unit.
std::string TS::Packet::toPrettyString ( size_t  indent = 0,
int  detailLevel = 3 
) const

Prints a packet to stdout, for analyser purposes.

std::string TS::Packet::toPrettyString ( size_t  indent = 0,
int  detailLevel = 3 
) const
void TS::Packet::updPos ( unsigned int  newPos)

update position in character array (pos),

void TS::Packet::updPos ( unsigned int  newPos)

Field Documentation

unsigned int TS::Packet::pos
protected
char TS::Packet::strBuf
protected

The documentation for this class was generated from the following files: