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

@ -1,14 +1,14 @@
#include "nal.h"
NAL_Unit::NAL_Unit( ) {
NAL_Unit::NAL_Unit(){
}
NAL_Unit::NAL_Unit( std::string & InputData ) {
ReadData( InputData );
NAL_Unit::NAL_Unit(std::string & InputData){
ReadData(InputData);
}
bool NAL_Unit::ReadData( std::string & InputData ) {
bool NAL_Unit::ReadData(std::string & InputData){
std::string FullAnnexB;
FullAnnexB += (char)0x00;
FullAnnexB += (char)0x00;
@ -19,53 +19,66 @@ bool NAL_Unit::ReadData( std::string & InputData ) {
ShortAnnexB += (char)0x00;
ShortAnnexB += (char)0x01;
// 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;
if( InputData.substr(0,3) == ShortAnnexB ) { AnnexB = true; }
if( InputData.substr(0,4) == FullAnnexB ) { InputData.erase(0,1); AnnexB = true; }
if( AnnexB ) {
if (InputData.substr(0, 3) == ShortAnnexB){
AnnexB = true;
}
if (InputData.substr(0, 4) == FullAnnexB){
InputData.erase(0, 1);
AnnexB = true;
}
if (AnnexB){
MyData = "";
InputData.erase(0,3);//Intro Bytes
InputData.erase(0, 3); //Intro Bytes
bool FinalByteRead = false;
int Location = std::min( InputData.find( ShortAnnexB ), InputData.find( FullAnnexB ) );
MyData = InputData.substr(0,Location);
InputData.erase(0,Location);
} else {
if( InputData.size() < 4 ) { return false; }
int Location = std::min(InputData.find(ShortAnnexB), InputData.find(FullAnnexB));
MyData = InputData.substr(0, Location);
InputData.erase(0, Location);
}else{
if (InputData.size() < 4){
return false;
}
int UnitLen = (InputData[0] << 24) + (InputData[1] << 16) + (InputData[2] << 8) + InputData[3];
if( InputData.size() < 4+UnitLen ) { return false; }
InputData.erase(0,4);//Remove Length
MyData = InputData.substr(0,UnitLen);
InputData.erase(0,UnitLen);//Remove this unit from the string
if (InputData.size() < 4 + UnitLen){
return false;
}
InputData.erase(0, 4); //Remove Length
MyData = InputData.substr(0, UnitLen);
InputData.erase(0, UnitLen); //Remove this unit from the string
}
return true;
}
std::string NAL_Unit::AnnexB( bool LongIntro ) {
std::string NAL_Unit::AnnexB(bool LongIntro){
std::string Result;
if( MyData.size() ) {
if( LongIntro ) { Result += (char)0x00; }
if (MyData.size()){
if (LongIntro){
Result += (char)0x00;
}
Result += (char)0x00;
Result += (char)0x00;
Result += (char)0x01;//Annex B Lead-In
Result += (char)0x01; //Annex B Lead-In
Result += MyData;
}
return Result;
}
std::string NAL_Unit::SizePrepended( ) {
std::string NAL_Unit::SizePrepended(){
std::string Result;
if( MyData.size() ) {
if (MyData.size()){
int DataSize = MyData.size();
Result += (char)( ( DataSize & 0xFF000000 ) >> 24 );
Result += (char)( ( DataSize & 0x00FF0000 ) >> 16 );
Result += (char)( ( DataSize & 0x0000FF00 ) >> 8 );
Result += (char)( DataSize & 0x000000FF );//Size Lead-In
Result += (char)((DataSize & 0xFF000000) >> 24);
Result += (char)((DataSize & 0x00FF0000) >> 16);
Result += (char)((DataSize & 0x0000FF00) >> 8);
Result += (char)(DataSize & 0x000000FF); //Size Lead-In
Result += MyData;
}
return Result;
}
int NAL_Unit::Type( ) {
return ( MyData[0] & 0x1F );
int NAL_Unit::Type(){
return (MyData[0] & 0x1F);
}