Documentation Fix

This commit is contained in:
Erik Zandvliet 2012-06-11 21:32:19 +02:00 committed by Thulinma
parent 45df1b72df
commit 0d6ff18723
3 changed files with 66 additions and 18 deletions

View file

@ -5,9 +5,7 @@
/// This constructor creates an empty TS::Packet, ready for use for either reading or writing. /// This constructor creates an empty TS::Packet, ready for use for either reading or writing.
/// All this constructor does is call TS::Packet::Clear(). /// All this constructor does is call TS::Packet::Clear().
TS::Packet::Packet() { TS::Packet::Packet() { Clear( ); }
Clear( );
}
/// This constructor creates a filled TS::Packet, or creates an empty /// This constructor creates a filled TS::Packet, or creates an empty
/// packet if not enough Data provided. /// packet if not enough Data provided.
@ -17,9 +15,7 @@ TS::Packet::Packet( std::string & Data ) {
if( Data.size() < 188 ) { if( Data.size() < 188 ) {
Clear( ); Clear( );
} else { } else {
for( int i = 0; i < 188; i++ ) { for( int i = 0; i < 188; i++ ) { Buffer[i] = Data[i]; }
Buffer[i] = Data[i];
}
Data.erase(0,188); Data.erase(0,188);
Free = 0; Free = 0;
} }
@ -42,7 +38,7 @@ int TS::Packet::PID() {
return (( Buffer[1] & 0x1F ) << 8 ) + Buffer[2]; return (( Buffer[1] & 0x1F ) << 8 ) + Buffer[2];
} }
/// Sets the Continuity Counter of a single TS::Packet /// Sets the Continuity Counter of a single TS::Packet.
/// \param NewContinuity The new Continuity Counter of the packet. /// \param NewContinuity The new Continuity Counter of the packet.
void TS::Packet::ContinuityCounter( int NewContinuity ) { void TS::Packet::ContinuityCounter( int NewContinuity ) {
Buffer[3] = ( Buffer[3] & 0xF0 ) + ( NewContinuity & 0x0F ); Buffer[3] = ( Buffer[3] & 0xF0 ) + ( NewContinuity & 0x0F );
@ -55,37 +51,41 @@ int TS::Packet::ContinuityCounter() {
return ( Buffer[3] & 0x0F ); return ( Buffer[3] & 0x0F );
} }
/// Gets the amount of bytes that are not written yet in a TS::Packet /// Gets the amount of bytes that are not written yet in a TS::Packet.
/// \return The amount of bytes that can still be written to this packet. /// \return The amount of bytes that can still be written to this packet.
int TS::Packet::BytesFree( ) { int TS::Packet::BytesFree( ) {
return Free; return Free;
} }
/// Clears a TS::Packet /// Clears a TS::Packet.
void TS::Packet::Clear( ) { void TS::Packet::Clear( ) {
Free = 184; Free = 184;
Buffer[0] = 0x47; Buffer[0] = 0x47;
for( int i = 1; i < 188; i++ ) { for( int i = 1; i < 188; i++ ) { Buffer[i] = 0x00; }
Buffer[i] = 0x00;
}
AdaptationField( 1 ); AdaptationField( 1 );
} }
/// Sets the selection value for an adaptationfield of a TS::Packet /// Sets the selection value for an adaptationfield of a TS::Packet.
/// \param NewSelector The new value of the selection bits. /// \param NewSelector The new value of the selection bits.
/// - 1: No AdaptationField /// - 1: No AdaptationField.
/// - 2: AdaptationField Only /// - 2: AdaptationField Only.
/// - 3: AdaptationField followed by Data /// - 3: AdaptationField followed by Data.
void TS::Packet::AdaptationField( int NewSelector ) { void TS::Packet::AdaptationField( int NewSelector ) {
Buffer[3] = ( Buffer[3] & 0xCF ) + ((NewSelector & 0x03) << 4); Buffer[3] = ( Buffer[3] & 0xCF ) + ((NewSelector & 0x03) << 4);
Buffer[4] = 0; Buffer[4] = 0;
Free = std::min( Free, 184 ); Free = std::min( Free, 184 );
} }
/// Gets whether a TS::Packet contains an adaptationfield.
/// \return The existence of an adaptationfield.
/// - 0: No adaptationfield present.
/// - 1: Adaptationfield is present.
int TS::Packet::AdaptationField( ) { int TS::Packet::AdaptationField( ) {
return ((Buffer[3] & 0x30) >> 4 ); return ((Buffer[3] & 0x30) >> 4 );
} }
/// Sets the PCR (Program Clock Reference) of a TS::Packet.
/// \param NewVal The new PCR Value.
void TS::Packet::PCR( int64_t NewVal ) { void TS::Packet::PCR( int64_t NewVal ) {
NewVal += (0xF618 * 300); NewVal += (0xF618 * 300);
AdaptationField( 3 ); AdaptationField( 3 );
@ -102,6 +102,8 @@ void TS::Packet::PCR( int64_t NewVal ) {
Free = std::min( Free, 176 ); Free = std::min( Free, 176 );
}; };
/// Gets the PCR (Program Clock Reference) of a TS::Packet.
/// \return The value of the PCR.
int64_t TS::Packet::PCR( ) { int64_t TS::Packet::PCR( ) {
if( !AdaptationField() ) { if( !AdaptationField() ) {
return -1; return -1;
@ -116,6 +118,8 @@ int64_t TS::Packet::PCR( ) {
return Result; return Result;
} }
/// Gets the current length of the adaptationfield.
/// \return The length of the adaptationfield.
int TS::Packet::AdaptationFieldLen( ) { int TS::Packet::AdaptationFieldLen( ) {
if( !AdaptationField() ) { if( !AdaptationField() ) {
return -1; return -1;
@ -123,6 +127,7 @@ int TS::Packet::AdaptationFieldLen( ) {
return (int)Buffer[4]; return (int)Buffer[4];
} }
/// Prints a packet to stdout, for analyser purposes.
void TS::Packet::Print( ) { void TS::Packet::Print( ) {
std::cout << "TS Packet: " << (Buffer[0] == 0x47) std::cout << "TS Packet: " << (Buffer[0] == 0x47)
<< "\n\tNewUnit: " << UnitStart() << "\n\tNewUnit: " << UnitStart()
@ -140,10 +145,14 @@ void TS::Packet::Print( ) {
} }
} }
/// Gets whether a new unit starts in this TS::Packet.
/// \return The start of a new unit.
int TS::Packet::UnitStart( ) { int TS::Packet::UnitStart( ) {
return ( Buffer[1] & 0x40) >> 6; return ( Buffer[1] & 0x40) >> 6;
} }
/// Sets the start of a new unit in this TS::Packet.
/// \param NewVal The new value for the start of a unit.
void TS::Packet::UnitStart( int NewVal ) { void TS::Packet::UnitStart( int NewVal ) {
if( NewVal ) { if( NewVal ) {
Buffer[1] = (Buffer[1] | 0x40); Buffer[1] = (Buffer[1] | 0x40);
@ -152,6 +161,8 @@ void TS::Packet::UnitStart( int NewVal ) {
} }
} }
/// Gets whether this TS::Packet can be accessed at random (indicates keyframe).
/// \return Whether or not this TS::Packet contains a keyframe.
int TS::Packet::RandomAccess( ) { int TS::Packet::RandomAccess( ) {
if( !AdaptationField() ) { if( !AdaptationField() ) {
return -1; return -1;
@ -159,6 +170,8 @@ int TS::Packet::RandomAccess( ) {
return ( Buffer[5] & 0x40) >> 6; return ( Buffer[5] & 0x40) >> 6;
} }
/// Sets whether this TS::Packet contains a keyframe
/// \param NewVal Whether or not this TS::Packet contains a keyframe.
void TS::Packet::RandomAccess( int NewVal ) { void TS::Packet::RandomAccess( int NewVal ) {
if( AdaptationField() ) { if( AdaptationField() ) {
if( Buffer[4] == 0 ) { if( Buffer[4] == 0 ) {
@ -182,6 +195,7 @@ void TS::Packet::RandomAccess( int NewVal ) {
Free = std::min( Free, 182 ); Free = std::min( Free, 182 );
} }
/// Transforms the TS::Packet into a standard Program Association Table
void TS::Packet::DefaultPAT( ) { void TS::Packet::DefaultPAT( ) {
static int MyCntr = 0; static int MyCntr = 0;
std::copy( TS::PAT, TS::PAT + 188, Buffer ); std::copy( TS::PAT, TS::PAT + 188, Buffer );
@ -190,6 +204,7 @@ void TS::Packet::DefaultPAT( ) {
MyCntr = ( (MyCntr + 1) % 0x10); MyCntr = ( (MyCntr + 1) % 0x10);
} }
/// Transforms the TS::Packet into a standard Program Mapping Table
void TS::Packet::DefaultPMT( ) { void TS::Packet::DefaultPMT( ) {
static int MyCntr = 0; static int MyCntr = 0;
std::copy( TS::PMT, TS::PMT + 188, Buffer ); std::copy( TS::PMT, TS::PMT + 188, Buffer );
@ -198,12 +213,18 @@ void TS::Packet::DefaultPMT( ) {
MyCntr = ( (MyCntr + 1) % 0x10); MyCntr = ( (MyCntr + 1) % 0x10);
} }
/// Generates a string from the contents of the TS::Packet
/// \return A string representation of the packet.
std::string TS::Packet::ToString( ) { std::string TS::Packet::ToString( ) {
std::string Result( Buffer, 188 ); std::string Result( Buffer, 188 );
std::cout.write( Buffer,188 ); std::cout.write( Buffer,188 );
return Result; return Result;
} }
/// Generates a PES Lead-in for a video frame.
/// Starts at the first Free byte.
/// \param NewLen The length of this video frame.
void TS::Packet::PESVideoLeadIn( int NewLen ) { void TS::Packet::PESVideoLeadIn( int NewLen ) {
static int PTS = 27000000; static int PTS = 27000000;
NewLen += 14; NewLen += 14;
@ -235,6 +256,10 @@ void TS::Packet::PESVideoLeadIn( int NewLen ) {
PTS += 3003; PTS += 3003;
} }
/// Generates a PES Lead-in for an audio frame.
/// Starts at the first Free byte.
/// \param NewLen The length of this audio frame.
/// \param PTS The timestamp of the audio frame.
void TS::Packet::PESAudioLeadIn( int NewLen, uint64_t PTS ) { void TS::Packet::PESAudioLeadIn( int NewLen, uint64_t PTS ) {
PTS = PTS * 90; PTS = PTS * 90;
NewLen += 8; NewLen += 8;
@ -257,6 +282,9 @@ void TS::Packet::PESAudioLeadIn( int NewLen, uint64_t PTS ) {
Free = Free - 12; Free = Free - 12;
} }
/// Fills the free bytes of the TS::Packet.
/// Stores as many bytes from NewVal as possible in the packet.
/// \param NewVal The data to store in the packet.
void TS::Packet::FillFree( std::string & NewVal ) { void TS::Packet::FillFree( std::string & NewVal ) {
int Offset = 188 - Free; int Offset = 188 - Free;
std::copy( NewVal.begin(), NewVal.begin() + Free, Buffer + Offset ); std::copy( NewVal.begin(), NewVal.begin() + Free, Buffer + Offset );
@ -264,6 +292,8 @@ void TS::Packet::FillFree( std::string & NewVal ) {
Free = 0; Free = 0;
} }
/// Adds NumBytes of stuffing to the TS::Packet.
/// \param NumBytes the amount of stuffing bytes.
void TS::Packet::AddStuffing( int NumBytes ) { void TS::Packet::AddStuffing( int NumBytes ) {
if( NumBytes <= 0 ) { return; } if( NumBytes <= 0 ) { return; }
if( AdaptationField( ) == 3 ) { if( AdaptationField( ) == 3 ) {
@ -284,6 +314,8 @@ void TS::Packet::AddStuffing( int NumBytes ) {
} }
} }
/// Transforms this TS::Packet into a standard Service Description Table
void TS::Packet::FFMpegHeader( ) { void TS::Packet::FFMpegHeader( ) {
static int MyCntr = 0; static int MyCntr = 0;
std::copy( TS::SDT, TS::SDT + 188, Buffer ); std::copy( TS::SDT, TS::SDT + 188, Buffer );

View file

@ -12,7 +12,7 @@
/// Holds all TS processing related code. /// Holds all TS processing related code.
namespace TS { namespace TS {
/// Simple class for reading and writing TS Streams /// Class for reading and writing TS Streams
class Packet { class Packet {
public: public:
Packet(); Packet();
@ -48,6 +48,10 @@ namespace TS {
char Buffer[188];///< The actual data char Buffer[188];///< The actual data
};//TS::Packet class };//TS::Packet class
/// Constructs an audio header to be used on each audio frame.
/// The length of this header will ALWAYS be 7 bytes, and has to be
/// prepended on each audio frame.
/// \param FrameLen the length of the current audio frame.
static inline std::string GetAudioHeader( int FrameLen ) { static inline std::string GetAudioHeader( int FrameLen ) {
char StandardHeader[7] = {0xFF,0xF1,0x4C,0x80,0x00,0x1F,0xFC}; char StandardHeader[7] = {0xFF,0xF1,0x4C,0x80,0x00,0x1F,0xFC};
FrameLen += 7; FrameLen += 7;
@ -57,6 +61,8 @@ namespace TS {
return std::string(StandardHeader,7); return std::string(StandardHeader,7);
} }
/// A standard Program Association Table, as generated by FFMPEG.
/// Seems to be independent of the stream.
static char PAT[188] = { static char PAT[188] = {
0x47,0x40,0x00,0x10, 0x00,0x00,0xB0,0x0D, 0x00,0x01,0xC1,0x00, 0x00,0x00,0x01,0xF0, 0x47,0x40,0x00,0x10, 0x00,0x00,0xB0,0x0D, 0x00,0x01,0xC1,0x00, 0x00,0x00,0x01,0xF0,
0x00,0x2A,0xB1,0x04, 0xB2,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0x00,0x2A,0xB1,0x04, 0xB2,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
@ -72,6 +78,8 @@ namespace TS {
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF
}; };
/// A standard Program Mapping Table, as generated by FFMPEG.
/// Contains both Audio and Video mappings, works also on video- or audio-only streams.
static char PMT[188] = { static char PMT[188] = {
0x47,0x50,0x00,0x10, 0x00,0x02,0xB0,0x1D, 0x00,0x01,0xC1,0x00, 0x00,0xE1,0x00,0xF0, 0x47,0x50,0x00,0x10, 0x00,0x02,0xB0,0x1D, 0x00,0x01,0xC1,0x00, 0x00,0xE1,0x00,0xF0,
0x00,0x1B,0xE1,0x00, 0xF0,0x00,0x0F,0xE1, 0x01,0xF0,0x06,0x0A, 0x04,0x65,0x6E,0x67, 0x00,0x1B,0xE1,0x00, 0xF0,0x00,0x0F,0xE1, 0x01,0xF0,0x06,0x0A, 0x04,0x65,0x6E,0x67,
@ -87,6 +95,8 @@ namespace TS {
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF
}; };
/// A standard Sevice Description Table, as generated by FFMPEG.
/// Not used in our connector, provided for compatibility means
static char SDT[188] = { static char SDT[188] = {
0x47,0x40,0x11,0x10, 0x00,0x42,0xF0,0x25, 0x00,0x01,0xC1,0x00, 0x00,0x00,0x01,0xFF, 0x47,0x40,0x11,0x10, 0x00,0x42,0xF0,0x25, 0x00,0x01,0xC1,0x00, 0x00,0x00,0x01,0xFF,
0x00,0x01,0xFC,0x80, 0x14,0x48,0x12,0x01, 0x06,0x46,0x46,0x6D, 0x70,0x65,0x67,0x09, 0x00,0x01,0xFC,0x80, 0x14,0x48,0x12,0x01, 0x06,0x46,0x46,0x6D, 0x70,0x65,0x67,0x09,
@ -102,6 +112,8 @@ namespace TS {
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF
}; };
/// A standard Picture Parameter Set, as generated by FFMPEG.
/// Seems to be stream-independent.
static char PPS[24] = { static char PPS[24] = {
0x00,0x00,0x00,0x01, 0x00,0x00,0x00,0x01,
0x27,0x4D,0x40,0x1F, 0x27,0x4D,0x40,0x1F,
@ -111,15 +123,19 @@ namespace TS {
0x5E,0xF7,0xC0,0x40 0x5E,0xF7,0xC0,0x40
}; };
/// A standard Sequence Parameter Set, as generated by FFMPEG.
/// Seems to be stream-independent.
static char SPS[8] = { static char SPS[8] = {
0x00,0x00,0x00,0x01, 0x00,0x00,0x00,0x01,
0x28,0xCE,0x09,0xC8 0x28,0xCE,0x09,0xC8
}; };
/// The full Bytesteam Nal-Header.
static char NalHeader[4] = { static char NalHeader[4] = {
0x00,0x00,0x00,0x01 0x00,0x00,0x00,0x01
}; };
/// The shortened Bytesteam Nal-Header.
static char ShortNalHeader[3] = { static char ShortNalHeader[3] = {
0x00,0x00,0x01 0x00,0x00,0x01
}; };

View file

@ -1,4 +1,4 @@
/// \file Connector_TS/main.cpp /// \file conn_ts.cpp
/// Contains the main code for the TS Connector /// Contains the main code for the TS Connector
/// \todo Check data to be sent for video /// \todo Check data to be sent for video
/// \todo Handle audio packets /// \todo Handle audio packets