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

@ -19,10 +19,17 @@ bool NAL_Unit::ReadData( std::string & InputData ) {
ShortAnnexB += (char)0x00; ShortAnnexB += (char)0x00;
ShortAnnexB += (char)0x01; ShortAnnexB += (char)0x01;
// fprintf( stderr, "NAL_Unit::ReadData --- DataSize: %d\n", InputData.size() ); // fprintf( stderr, "NAL_Unit::ReadData --- DataSize: %d\n", InputData.size() );
if( InputData.size() < 3 ) { return false; } if (InputData.size() < 3){
return false;
}
bool AnnexB = false; bool AnnexB = false;
if( InputData.substr(0,3) == ShortAnnexB ) { AnnexB = true; } if (InputData.substr(0, 3) == ShortAnnexB){
if( InputData.substr(0,4) == FullAnnexB ) { InputData.erase(0,1); AnnexB = true; } AnnexB = true;
}
if (InputData.substr(0, 4) == FullAnnexB){
InputData.erase(0, 1);
AnnexB = true;
}
if (AnnexB){ if (AnnexB){
MyData = ""; MyData = "";
InputData.erase(0, 3); //Intro Bytes InputData.erase(0, 3); //Intro Bytes
@ -31,9 +38,13 @@ bool NAL_Unit::ReadData( std::string & InputData ) {
MyData = InputData.substr(0, Location); MyData = InputData.substr(0, Location);
InputData.erase(0, Location); InputData.erase(0, Location);
}else{ }else{
if( InputData.size() < 4 ) { return false; } if (InputData.size() < 4){
return false;
}
int UnitLen = (InputData[0] << 24) + (InputData[1] << 16) + (InputData[2] << 8) + InputData[3]; int UnitLen = (InputData[0] << 24) + (InputData[1] << 16) + (InputData[2] << 8) + InputData[3];
if( InputData.size() < 4+UnitLen ) { return false; } if (InputData.size() < 4 + UnitLen){
return false;
}
InputData.erase(0, 4); //Remove Length InputData.erase(0, 4); //Remove Length
MyData = InputData.substr(0, UnitLen); MyData = InputData.substr(0, UnitLen);
InputData.erase(0, UnitLen); //Remove this unit from the string InputData.erase(0, UnitLen); //Remove this unit from the string
@ -44,7 +55,9 @@ bool NAL_Unit::ReadData( std::string & InputData ) {
std::string NAL_Unit::AnnexB(bool LongIntro){ std::string NAL_Unit::AnnexB(bool LongIntro){
std::string Result; std::string Result;
if (MyData.size()){ if (MyData.size()){
if( LongIntro ) { Result += (char)0x00; } if (LongIntro){
Result += (char)0x00;
}
Result += (char)0x00; Result += (char)0x00;
Result += (char)0x00; Result += (char)0x00;
Result += (char)0x01; //Annex B Lead-In Result += (char)0x01; //Annex B Lead-In

View file

@ -11,4 +11,5 @@ class NAL_Unit {
int Type(); int Type();
private: private:
std::string MyData; std::string MyData;
};//NAL_Unit class };
//NAL_Unit class

View file

@ -25,7 +25,8 @@ bool TS::Packet::FromString( std::string & Data ) {
} }
/// The deconstructor deletes all space that may be occupied by a TS::Packet. /// The deconstructor deletes all space that may be occupied by a TS::Packet.
TS::Packet::~Packet() { } TS::Packet::~Packet(){
}
/// Sets the PID of a single TS::Packet. /// Sets the PID of a single TS::Packet.
/// \param NewPID The new PID of the packet. /// \param NewPID The new PID of the packet.
@ -135,11 +136,8 @@ int TS::Packet::AdaptationFieldLen( ) {
/// Prints a packet to stdout, for analyser purposes. /// Prints a packet to stdout, for analyser purposes.
void TS::Packet::Print(){ void TS::Packet::Print(){
std::cout << "TS Packet: " << (strBuf[0] == 0x47) std::cout << "TS Packet: " << (strBuf[0] == 0x47) << "\n\tNewUnit: " << UnitStart() << "\n\tPID: " << PID() << "\n\tContinuity Counter: "
<< "\n\tNewUnit: " << UnitStart() << ContinuityCounter() << "\n\tAdaption Field: " << AdaptationField() << "\n";
<< "\n\tPID: " << PID()
<< "\n\tContinuity Counter: " << ContinuityCounter()
<< "\n\tAdaption Field: " << AdaptationField() << "\n";
if (AdaptationField()){ if (AdaptationField()){
std::cout << "\t\tAdaption Field Length: " << AdaptationFieldLen() << "\n"; std::cout << "\t\tAdaption Field Length: " << AdaptationFieldLen() << "\n";
if (AdaptationFieldLen()){ if (AdaptationFieldLen()){
@ -299,7 +297,9 @@ void TS::Packet::FillFree( std::string & NewVal ) {
/// Adds NumBytes of stuffing to the TS::Packet. /// Adds NumBytes of stuffing to the TS::Packet.
/// \param NumBytes the amount of stuffing bytes. /// \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){
int Offset = strBuf[4]; int Offset = strBuf[4];
strBuf[4] = Offset + NumBytes - 1; strBuf[4] = Offset + NumBytes - 1;

View file

@ -48,7 +48,8 @@ namespace TS {
//int Free; //int Free;
std::string strBuf; std::string strBuf;
//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. /// 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 /// The length of this header will ALWAYS be 7 bytes, and has to be
@ -69,45 +70,31 @@ namespace TS {
/// A standard Program Association Table, as generated by FFMPEG. /// A standard Program Association Table, as generated by FFMPEG.
/// Seems to be independent of the stream. /// 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, 0x00, 0x2A, 0xB1, 0x04,
0x47,0x40,0x00,0x10, 0x00,0x00,0xB0,0x0D, 0x00,0x01,0xC1,0x00, 0x00,0x00,0x01,0xF0, 0xB2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 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, 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
};
/// A standard Program Mapping Table, as generated by FFMPEG. /// A standard Program Mapping Table, as generated by FFMPEG.
/// Contains both Audio and Video mappings, works also on video- or audio-only streams. /// 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, 0x17, 0x00, 0x01, 0xC1, 0x00, 0x00, 0xE1, 0x00, 0xF0, 0x00, 0x1B, 0xE1, 0x00,
0x47,0x50,0x00,0x10, 0x00,0x02,0xB0,0x17, 0x00,0x01,0xC1,0x00, 0x00,0xE1,0x00,0xF0, 0xF0, 0x00, 0x0F, 0xE1, 0x01, 0xF0, 0x00, 0x2F, 0x44, 0xB9, 0x9B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 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FF,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. /// 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. /// The shortened Bytesteam Nal-Header.
static char ShortNalHeader[3] = { static char ShortNalHeader[3] = {0x00, 0x00, 0x01};
0x00,0x00,0x01 }
}; ;
};//TS namespace //TS namespace