Standardized coding style for TS-related code.

This commit is contained in:
Thulinma 2012-12-31 16:33:45 +01:00
parent 439d5bf98c
commit 05416da269
4 changed files with 246 additions and 245 deletions

View file

@ -15,99 +15,86 @@
/// Holds all TS processing related code.
namespace TS {
/// Class for reading and writing TS Streams
class Packet {
class Packet{
public:
Packet();
~Packet();
bool FromString( std::string & Data );
void PID( int NewPID );
bool FromString(std::string & Data);
void PID(int NewPID);
int PID();
void ContinuityCounter( int NewContinuity );
void ContinuityCounter(int NewContinuity);
int ContinuityCounter();
void Clear();
void PCR( int64_t NewVal );
void PCR(int64_t NewVal);
int64_t PCR();
void AdaptationField( int NewVal );
int AdaptationField( );
int AdaptationFieldLen( );
void AdaptationField(int NewVal);
int AdaptationField();
int AdaptationFieldLen();
void DefaultPAT();
void DefaultPMT();
int UnitStart( );
void UnitStart( int NewVal );
int RandomAccess( );
void RandomAccess( int NewVal );
int UnitStart();
void UnitStart(int NewVal);
int RandomAccess();
void RandomAccess(int NewVal);
int BytesFree();
void Print();
const char* ToString();
void PESVideoLeadIn( int NewLen, long long unsigned int PTS = 1 );
void PESAudioLeadIn( int NewLen, uint64_t PTS = 0 );
void FillFree( std::string & PackageData );
void AddStuffing( int NumBytes );
void PESVideoLeadIn(int NewLen, long long unsigned int PTS = 1);
void PESAudioLeadIn(int NewLen, uint64_t PTS = 0);
void FillFree(std::string & PackageData);
void AddStuffing(int NumBytes);
private:
//int Free;
std::string strBuf;
//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, std::string initData ) {
char StandardHeader[7] = {0xFF,0xF1,0x00,0x00,0x00,0x1F,0xFC};
static inline std::string GetAudioHeader(int FrameLen, std::string initData){
char StandardHeader[7] = {0xFF, 0xF1, 0x00, 0x00, 0x00, 0x1F, 0xFC};
FrameLen += 7;
StandardHeader[2] = ((((initData[0] >> 3) - 1) << 6 ) & 0xC0);//AAC Profile - 1 ( First two bits )
StandardHeader[2] |= (( ((initData[0] & 0x07) << 1) | ((initData[1] >> 7) & 0x01) ) << 2 );//AAC Frequency Index
StandardHeader[2] |= ((initData[1] & 0x20) >> 5);//AAC Channel Config
StandardHeader[3] = ((initData[1] & 0x18 ) << 3 );//AAC CHannel Config (cont.)
StandardHeader[3] |= ( ( FrameLen & 0x00001800 ) >> 11 );
StandardHeader[4] = ( ( FrameLen & 0x000007F8 ) >> 3 );
StandardHeader[5] |= ( ( FrameLen & 0x00000007 ) << 5 );
return std::string(StandardHeader,7);
StandardHeader[2] = ((((initData[0] >> 3) - 1) << 6) & 0xC0); //AAC Profile - 1 ( First two bits )
StandardHeader[2] |= ((((initData[0] & 0x07) << 1) | ((initData[1] >> 7) & 0x01)) << 2); //AAC Frequency Index
StandardHeader[2] |= ((initData[1] & 0x20) >> 5); //AAC Channel Config
StandardHeader[3] = ((initData[1] & 0x18) << 3); //AAC CHannel Config (cont.)
StandardHeader[3] |= ((FrameLen & 0x00001800) >> 11);
StandardHeader[4] = ((FrameLen & 0x000007F8) >> 3);
StandardHeader[5] |= ((FrameLen & 0x00000007) << 5);
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] = {
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,
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,
0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 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
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] = {
0x47,0x50,0x00,0x10, 0x00,0x02,0xB0,0x17, 0x00,0x01,0xC1,0x00, 0x00,0xE1,0x00,0xF0,
0x00,0x1B,0xE1,0x00, 0xF0,0x00,0x0F,0xE1, 0x01,0xF0,0x00,0x2F, 0x44,0xB9,0x9B,0xFF,
0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF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, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
/// The full Bytesteam Nal-Header.
static char NalHeader[4] = {
0x00,0x00,0x00,0x01
};
static char NalHeader[4] = {0x00, 0x00, 0x00, 0x01};
/// The shortened Bytesteam Nal-Header.
static char ShortNalHeader[3] = {
0x00,0x00,0x01
};
};//TS namespace
static char ShortNalHeader[3] = {0x00, 0x00, 0x01};
}
;
//TS namespace