From 87c567e37c9f0c33aea42ffb51fad15d6582300c Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 8 May 2012 22:43:37 +0200 Subject: [PATCH] Final edits to bring all analysers and converters into autotools build system. Done! --- .gitignore | 2 + configure.ac | 2 + src/Makefile.am | 3 +- src/analysers/Makefile.am | 12 + src/analysers/abst_analyser.cpp | 244 -------------- src/analysers/amf_analyser.cpp | 2 +- src/analysers/dtsc_analyser.cpp | 2 +- src/analysers/flv_analyser.cpp | 2 +- src/analysers/httpbox_analyser.cpp | 45 --- src/analysers/rtmp_analyser.cpp | 8 +- src/analysers/rtp_analyser.cpp | 63 ---- src/analysers/ts_analyser.cpp | 501 ----------------------------- src/converters/Makefile.am | 7 + src/converters/dtsc2flv.cpp | 6 +- src/converters/flv2dtsc.cpp | 6 +- 15 files changed, 38 insertions(+), 867 deletions(-) create mode 100644 src/analysers/Makefile.am delete mode 100644 src/analysers/abst_analyser.cpp delete mode 100644 src/analysers/httpbox_analyser.cpp delete mode 100644 src/analysers/rtp_analyser.cpp delete mode 100644 src/analysers/ts_analyser.cpp create mode 100644 src/converters/Makefile.am diff --git a/.gitignore b/.gitignore index 552a25cd..b19cf75e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ docs nbproject autom4te.cache src/Mist* +src/analysers/Mist* +src/converters/Mist* configure config.log config.status diff --git a/configure.ac b/configure.ac index 1bce87ef..6bc6a611 100644 --- a/configure.ac +++ b/configure.ac @@ -35,5 +35,7 @@ AC_CHECK_FUNCS([dup2 gettimeofday memset mkdir socket strerror]) AC_CONFIG_FILES([Makefile lib/Makefile + src/converters/Makefile + src/analysers/Makefile src/Makefile]) AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am index a8ad7a82..640aaf08 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,5 @@ -outdir=../bin +SUBDIRS=converters analysers +outdir=.. out_PROGRAMS=MistBuffer MistController MistConnRAW MistConnRTMP MistConnHTTP AM_LDFLAGS=-L../lib MistBuffer_SOURCES=buffer.cpp buffer_stats.cpp buffer_user.cpp buffer_stream.cpp diff --git a/src/analysers/Makefile.am b/src/analysers/Makefile.am new file mode 100644 index 00000000..1b918b87 --- /dev/null +++ b/src/analysers/Makefile.am @@ -0,0 +1,12 @@ +outdir=../.. +out_PROGRAMS=MistAnalyserRTMP MistAnalyserFLV MistAnalyserDTSC MistAnalyserAMF +AM_LDFLAGS=-L../../lib +MistAnalyserRTMP_SOURCES=rtmp_analyser.cpp +MistAnalyserRTMP_LDADD=-lrtmpchunks -lamf -lflv_tag -ldtsc -lsocket -lssl -lcrypto +MistAnalyserFLV_SOURCES=flv_analyser.cpp +MistAnalyserFLV_LDADD=-lflv_tag -lamf -ldtsc -lsocket +MistAnalyserDTSC_SOURCES=dtsc_analyser.cpp +MistAnalyserDTSC_LDADD=-ldtsc +MistAnalyserAMF_SOURCES=amf_analyser.cpp +MistAnalyserAMF_LDADD=-lamf + diff --git a/src/analysers/abst_analyser.cpp b/src/analysers/abst_analyser.cpp deleted file mode 100644 index 49d1d9dc..00000000 --- a/src/analysers/abst_analyser.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/// \file ABST_Parser/main.cpp -/// Debugging tool for ABST boxes. -/// Expects ABST data through stdin, outputs human-readable information to stderr. -/// \todo Erik, update, delete or properly document this file. - -#include -#include -#include -#include "../../util/MP4/box_includes.h" - -void Parse( Box * source ,std::string PrintOffset ) { - if( source->header.BoxType == 0x61627374 ) { - uint8_t Version = source->Payload[0]; - uint32_t Flags = (source->Payload[1] << 16) + (source->Payload[2] << 8) + (source->Payload[3]); //uint24_t - uint32_t BootstrapInfoVersion = (source->Payload[4] << 24) + (source->Payload[5] << 16) +(source->Payload[6] << 8) + (source->Payload[7]); - uint8_t Profile = (source->Payload[8] >> 6); //uint2_t - uint8_t Live = ((source->Payload[8] >> 5 ) & 0x1); //uint1_t - uint8_t Update = ((source->Payload[8] >> 4 ) & 0x1); //uint1_t - uint8_t Reserved = (source->Payload[8] & 0x4); //uint4_t - uint32_t Timescale = (source->Payload[9] << 24) + (source->Payload[10] << 16) +(source->Payload[11] << 8) + (source->Payload[12]); - uint32_t CurrentMediaTime_Upperhalf = (source->Payload[13] << 24) + (source->Payload[14] << 16) +(source->Payload[15] << 8) + (source->Payload[16]); - uint32_t CurrentMediaTime_Lowerhalf = (source->Payload[17] << 24) + (source->Payload[18] << 16) +(source->Payload[19] << 8) + (source->Payload[20]); - uint32_t SmpteTimeCodeOffset_Upperhalf = (source->Payload[21] << 24) + (source->Payload[22] << 16) +(source->Payload[23] << 8) + (source->Payload[24]); - uint32_t SmpteTimeCodeOffset_Lowerhalf = (source->Payload[25] << 24) + (source->Payload[26] << 16) +(source->Payload[27] << 8) + (source->Payload[28]); - - std::string MovieIdentifier; - uint8_t ServerEntryCount = -1; - std::vector ServerEntryTable; - uint8_t QualityEntryCount = -1; - std::vector QualityEntryTable; - std::string DrmData; - std::string MetaData; - uint8_t SegmentRunTableCount = -1; - std::vector SegmentRunTableEntries; - uint8_t FragmentRunTableCount = -1; - std::vector FragmentRunTableEntries; - - uint32_t CurrentOffset = 29; - uint32_t TempSize; - Box* TempBox; - std::string temp; - while( source->Payload[CurrentOffset] != '\0' ) { MovieIdentifier += source->Payload[CurrentOffset]; CurrentOffset ++; } - CurrentOffset ++; - ServerEntryCount = source->Payload[CurrentOffset]; - CurrentOffset ++; - for( uint8_t i = 0; i < ServerEntryCount; i++ ) { - temp = ""; - while( source->Payload[CurrentOffset] != '\0' ) { temp += source->Payload[CurrentOffset]; CurrentOffset ++; } - ServerEntryTable.push_back(temp); - CurrentOffset++; - } - QualityEntryCount = source->Payload[CurrentOffset]; - CurrentOffset ++; - for( uint8_t i = 0; i < QualityEntryCount; i++ ) { - temp = ""; - while( source->Payload[CurrentOffset] != '\0' ) { temp += source->Payload[CurrentOffset]; CurrentOffset ++; } - QualityEntryTable.push_back(temp); - CurrentOffset++; - } - while( source->Payload[CurrentOffset] != '\0' ) { DrmData += source->Payload[CurrentOffset]; CurrentOffset ++; } - CurrentOffset ++; - while( source->Payload[CurrentOffset] != '\0' ) { MetaData += source->Payload[CurrentOffset]; CurrentOffset ++; } - CurrentOffset ++; - SegmentRunTableCount = source->Payload[CurrentOffset]; - CurrentOffset ++; - for( uint8_t i = 0; i < SegmentRunTableCount; i++ ) { - TempSize = (source->Payload[CurrentOffset] << 24) + (source->Payload[CurrentOffset+1]<< 16) + (source->Payload[CurrentOffset+2]<< 8) + (source->Payload[CurrentOffset+3]); - TempBox = new Box( &source->Payload[CurrentOffset], TempSize ); - SegmentRunTableEntries.push_back(TempBox); - CurrentOffset += TempSize; - } - FragmentRunTableCount = source->Payload[CurrentOffset]; - CurrentOffset ++; - for( uint8_t i = 0; i < FragmentRunTableCount; i++ ) { - TempSize = (source->Payload[CurrentOffset] << 24) + (source->Payload[CurrentOffset+1]<< 16) + (source->Payload[CurrentOffset+2]<< 8) + (source->Payload[CurrentOffset+3]); - TempBox = new Box( &source->Payload[CurrentOffset], TempSize ); - FragmentRunTableEntries.push_back(TempBox); - CurrentOffset += TempSize; - } - - std::cerr << "Box_ABST:\n"; - std::cerr << PrintOffset << " Version: " << (int)Version << "\n"; - std::cerr << PrintOffset << " Flags: " << (int)Flags << "\n"; - std::cerr << PrintOffset << " BootstrapInfoVersion: " << (int)BootstrapInfoVersion << "\n"; - std::cerr << PrintOffset << " Profile: " << (int)Profile << "\n"; - std::cerr << PrintOffset << " Live: " << (int)Live << "\n"; - std::cerr << PrintOffset << " Update: " << (int)Update << "\n"; - std::cerr << PrintOffset << " Reserved: " << (int)Reserved << "\n"; - std::cerr << PrintOffset << " Timescale: " << (int)Timescale << "\n"; - std::cerr << PrintOffset << " CurrentMediaTime: " << (int)CurrentMediaTime_Upperhalf << " " << CurrentMediaTime_Lowerhalf << "\n"; - std::cerr << PrintOffset << " SmpteTimeCodeOffset: " << (int)SmpteTimeCodeOffset_Upperhalf << " " << SmpteTimeCodeOffset_Lowerhalf << "\n"; - std::cerr << PrintOffset << " MovieIdentifier: " << MovieIdentifier << "\n"; - std::cerr << PrintOffset << " ServerEntryCount: " << (int)ServerEntryCount << "\n"; - std::cerr << PrintOffset << " ServerEntryTable:\n"; - for( uint32_t i = 0; i < ServerEntryTable.size( ); i++ ) { - std::cerr << PrintOffset << " " << i+1 << ": " << ServerEntryTable[i] << "\n"; - } - std::cerr << PrintOffset << " QualityEntryCount: " << (int)QualityEntryCount << "\n"; - std::cerr << PrintOffset << " QualityEntryTable:\n"; - for( uint32_t i = 0; i < QualityEntryTable.size( ); i++ ) { - std::cerr << PrintOffset << " " << i+1 << ": " << QualityEntryTable[i] << "\n"; - } - std::cerr << PrintOffset << " DrmData: " << DrmData << "\n"; - std::cerr << PrintOffset << " MetaData: " << MetaData << "\n"; - std::cerr << PrintOffset << " SegmentRunTableCount: " << (int)SegmentRunTableCount << "\n"; - std::cerr << PrintOffset << " SegmentRunTableEntries:\n"; - for( uint32_t i = 0; i < SegmentRunTableEntries.size( ); i++ ) { - std::cerr << PrintOffset << " " << i+1 << ": "; - Parse( SegmentRunTableEntries[i], PrintOffset+" " ); - } - std::cerr << PrintOffset << " FragmentRunTableCount: " << (int)FragmentRunTableCount << "\n"; - std::cerr << PrintOffset << " FragmentRunTableEntries:\n"; - for( uint32_t i = 0; i < FragmentRunTableEntries.size( ); i++ ) { - std::cerr << PrintOffset << " " << i+1 << ": "; - Parse( FragmentRunTableEntries[i], PrintOffset+" " ); - } - - } else if ( source->header.BoxType == 0x61737274 ) { - uint8_t Version = source->Payload[0]; - uint32_t Flags = (source->Payload[1] << 16) + (source->Payload[2] << 8) + (source->Payload[3]); //uint24_t - uint8_t QualityEntryCount; - std::vector QualitySegmentUrlModifiers; - uint32_t SegmentRunEntryCount; - std::vector< std::pair > SegmentRunEntryTable; - - uint32_t CurrentOffset = 4; - std::string temp; - std::pair TempPair; - QualityEntryCount = source->Payload[CurrentOffset]; - CurrentOffset ++; - for( uint8_t i = 0; i < QualityEntryCount; i++ ) { - temp = ""; - while( source->Payload[CurrentOffset] != '\0' ) { temp += source->Payload[CurrentOffset]; CurrentOffset ++; } - QualitySegmentUrlModifiers.push_back(temp); - CurrentOffset++; - } - SegmentRunEntryCount = (source->Payload[CurrentOffset] << 24) + (source->Payload[CurrentOffset+1] << 16) + (source->Payload[CurrentOffset+2] << 8) + (source->Payload[CurrentOffset+3]); - CurrentOffset +=4; - for( uint8_t i = 0; i < SegmentRunEntryCount; i++ ) { - TempPair.first = (source->Payload[CurrentOffset] << 24) + (source->Payload[CurrentOffset+1] << 16) + (source->Payload[CurrentOffset+2] << 8) + (source->Payload[CurrentOffset+3]); - CurrentOffset+=4; - TempPair.second = (source->Payload[CurrentOffset] << 24) + (source->Payload[CurrentOffset+1] << 16) + (source->Payload[CurrentOffset+2] << 8) + (source->Payload[CurrentOffset+3]); - CurrentOffset+=4; - SegmentRunEntryTable.push_back(TempPair); - } - - std::cerr << "Box_ASRT:\n"; - std::cerr << PrintOffset << " Version: " << (int)Version << "\n"; - std::cerr << PrintOffset << " Flags: " << (int)Flags << "\n"; - std::cerr << PrintOffset << " QualityEntryCount: " << (int)QualityEntryCount << "\n"; - std::cerr << PrintOffset << " QualitySegmentUrlModifiers:\n"; - for( uint32_t i = 0; i < QualitySegmentUrlModifiers.size( ); i++ ) { - std::cerr << PrintOffset << " " << i+1 << ": " << QualitySegmentUrlModifiers[i] << "\n"; - } - std::cerr << PrintOffset << " SegmentRunEntryCount: " << (int)SegmentRunEntryCount << "\n"; - std::cerr << PrintOffset << " SegmentRunEntryTable:\n"; - for( uint32_t i = 0; i < SegmentRunEntryTable.size( ); i++ ) { - std::cerr << PrintOffset << " " << i+1 << ":\n"; - std::cerr << PrintOffset << " FirstSegment: " << SegmentRunEntryTable[i].first << "\n"; - std::cerr << PrintOffset << " FragmentsPerSegment: " << SegmentRunEntryTable[i].second << "\n"; - } - } else if ( source->header.BoxType == 0x61667274 ) { - uint8_t Version = source->Payload[0]; - uint32_t Flags = (source->Payload[1] << 16) + (source->Payload[2] << 8) + (source->Payload[3]); //uint24_t - uint32_t TimeScale = (source->Payload[4] << 24) + (source->Payload[5] << 16) + (source->Payload[6] << 8) + (source->Payload[7]); - uint8_t QualityEntryCount; - std::vector QualitySegmentUrlModifiers; - uint32_t FragmentRunEntryCount; - std::vector FragmentRunEntryTable; - - uint32_t CurrentOffset = 8; - std::string temp; - afrt_fragmentrunentry TempEntry; - QualityEntryCount = source->Payload[CurrentOffset]; - CurrentOffset ++; - for( uint8_t i = 0; i < QualityEntryCount; i++ ) { - temp = ""; - while( source->Payload[CurrentOffset] != '\0' ) { temp += source->Payload[CurrentOffset]; CurrentOffset ++; } - QualitySegmentUrlModifiers.push_back(temp); - CurrentOffset++; - } - FragmentRunEntryCount = (source->Payload[CurrentOffset] << 24) + (source->Payload[CurrentOffset+1] << 16) + (source->Payload[CurrentOffset+2] << 8) + (source->Payload[CurrentOffset+3]); - CurrentOffset +=4; - for( uint8_t i = 0; i < FragmentRunEntryCount; i ++ ) { - TempEntry.FirstFragment = (source->Payload[CurrentOffset] << 24) + (source->Payload[CurrentOffset+1] << 16) + (source->Payload[CurrentOffset+2] << 8) + (source->Payload[CurrentOffset+3]); - CurrentOffset +=4; - CurrentOffset +=4; - TempEntry.FirstFragmentTimestamp = (source->Payload[CurrentOffset] << 24) + (source->Payload[CurrentOffset+1] << 16) + (source->Payload[CurrentOffset+2] << 8) + (source->Payload[CurrentOffset+3]); - CurrentOffset +=4; - TempEntry.FragmentDuration = (source->Payload[CurrentOffset] << 24) + (source->Payload[CurrentOffset+1] << 16) + (source->Payload[CurrentOffset+2] << 8) + (source->Payload[CurrentOffset+3]); - CurrentOffset +=4; - if( TempEntry.FragmentDuration == 0 ) { - TempEntry.DiscontinuityIndicator = source->Payload[CurrentOffset]; - CurrentOffset++; - } - FragmentRunEntryTable.push_back(TempEntry); - } - - std::cerr << "Box_AFRT:\n"; - std::cerr << PrintOffset << " Version: " << (int)Version << "\n"; - std::cerr << PrintOffset << " Flags: " << (int)Flags << "\n"; - std::cerr << PrintOffset << " Timescale: " << (int)TimeScale << "\n"; - std::cerr << PrintOffset << " QualityEntryCount: " << (int)QualityEntryCount << "\n"; - std::cerr << PrintOffset << " QualitySegmentUrlModifiers:\n"; - for( uint32_t i = 0; i < QualitySegmentUrlModifiers.size( ); i++ ) { - std::cerr << PrintOffset << " " << i+1 << ": " << QualitySegmentUrlModifiers[i] << "\n"; - } - std::cerr << PrintOffset << " FragmentRunEntryCount: " << (int)FragmentRunEntryCount << "\n"; - std::cerr << PrintOffset << " FragmentRunEntryTable:\n"; - for( uint32_t i = 0; i < FragmentRunEntryTable.size( ); i++ ) { - std::cerr << PrintOffset << " " << i+1 << ":\n"; - std::cerr << PrintOffset << " FirstFragment: " << FragmentRunEntryTable[i].FirstFragment << "\n"; - std::cerr << PrintOffset << " FirstFragmentTimestamp: " << FragmentRunEntryTable[i].FirstFragmentTimestamp << "\n"; - std::cerr << PrintOffset << " FragmentDuration: " << FragmentRunEntryTable[i].FragmentDuration << "\n"; - if( FragmentRunEntryTable[i].FragmentDuration == 0 ) { - std::cerr << PrintOffset << " DiscontinuityIndicator: " << (int)FragmentRunEntryTable[i].DiscontinuityIndicator << "\n"; - } - } - } else { - std::cerr << "BoxType '" - << (char)(source->header.BoxType >> 24) - << (char)((source->header.BoxType << 8) >> 24) - << (char)((source->header.BoxType << 16) >> 24) - << (char)((source->header.BoxType << 24) >> 24) - << "' not yet implemented!\n"; - } -} - -int main( ) { - std::string temp; - bool validinp = true; - char thischar; - while(validinp) { - thischar = std::cin.get( ); - if(std::cin.good( ) ) { - temp += thischar; - } else { - validinp = false; - } - } - Box * TestBox = new Box((uint8_t*)temp.c_str( ), temp.size( )); - Parse( TestBox, "" ); - delete TestBox; -} diff --git a/src/analysers/amf_analyser.cpp b/src/analysers/amf_analyser.cpp index e58d7def..a03519d6 100644 --- a/src/analysers/amf_analyser.cpp +++ b/src/analysers/amf_analyser.cpp @@ -7,7 +7,7 @@ #include #include #include -#include "../../util/amf.h" +#include "../../lib/amf.h" /// Debugging tool for AMF data. /// Expects AMF data through stdin, outputs human-readable information to stderr. diff --git a/src/analysers/dtsc_analyser.cpp b/src/analysers/dtsc_analyser.cpp index e9c5463d..9be443cb 100644 --- a/src/analysers/dtsc_analyser.cpp +++ b/src/analysers/dtsc_analyser.cpp @@ -10,7 +10,7 @@ #include #include #include -#include "../../util/dtsc.h" //DTSC support +#include "../../lib/dtsc.h" //DTSC support /// Reads DTSC from stdin and outputs human-readable information to stderr. int main() { diff --git a/src/analysers/flv_analyser.cpp b/src/analysers/flv_analyser.cpp index 1d4aef0e..8af413d5 100644 --- a/src/analysers/flv_analyser.cpp +++ b/src/analysers/flv_analyser.cpp @@ -10,7 +10,7 @@ #include #include #include -#include "../../util/flv_tag.h" //FLV support +#include "../../lib/flv_tag.h" //FLV support /// Reads DTSC from stdin and outputs human-readable information to stderr. int main() { diff --git a/src/analysers/httpbox_analyser.cpp b/src/analysers/httpbox_analyser.cpp deleted file mode 100644 index c78c694d..00000000 --- a/src/analysers/httpbox_analyser.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/// \file HTTP_Box_Parser/main.cpp -/// Debugging tool for F4M HTTP streaming data. -/// Expects raw TCP data through stdin, outputs human-readable information to stderr. -/// This will attempt to read either HTTP requests or responses from stdin, and if the body is more than -/// 10,000 bytes long will attempt to parse the data as a MP4 box. (Other cases show a message about the fragment being too small) -/// Then it will take the payload of this box, print the first four bytes, and attempt to parse the whole payload as FLV data. -/// The parsed FLV data is then pretty-printed, containing information about the codec parameters and types of tags it encounters. - -#include -#include -#include -#include -#include "../../util/http_parser.h" -#include "../../util/MP4/box_includes.h" -#include "../../util/flv_tag.h" - -/// Debugging tool for F4M HTTP streaming data. -/// Expects raw TCP data through stdin, outputs human-readable information to stderr. -/// This will attempt to read either HTTP requests or responses from stdin, and if the body is more than -/// 10,000 bytes long will attempt to parse the data as a MP4 box. (Other cases show a message about the fragment being too small) -/// Then it will take the payload of this box, print the first four bytes, and attempt to parse the whole payload as FLV data. -/// The parsed FLV data is then pretty-printed, containing information about the codec parameters and types of tags it encounters. -int main(){ - HTTP::Parser H; - FLV::Tag F; - unsigned int P = 0; - char * Payload = 0; - - while (H.Read(stdin) || H.CleanForNext()){ - if (H.body.size() > 10000){ - Box * TestBox = new Box((uint8_t*)H.body.c_str(), H.body.size()); - Payload = (char*)TestBox->GetPayload(); - printf("First bytes: %2hhu %2hhu %2hhu %2hhu\n", Payload[0], Payload[1], Payload[2], Payload[3]); - P = 0; - while (TestBox->GetPayloadSize() > P){ - if (F.MemLoader(Payload, TestBox->GetPayloadSize(), P)){ - std::cout << "Got a " << F.len << " bytes " << F.tagType() << " FLV tag of time " << F.tagTime() << "." << std::endl; - } - } - delete TestBox; - }else{ - std::cout << "Skipped too small fragment of size " << H.body.size() << std::endl; - } - } -}//main diff --git a/src/analysers/rtmp_analyser.cpp b/src/analysers/rtmp_analyser.cpp index 40e2c6e2..72d34970 100644 --- a/src/analysers/rtmp_analyser.cpp +++ b/src/analysers/rtmp_analyser.cpp @@ -15,9 +15,9 @@ #include #include #include -#include "../../util/flv_tag.h" -#include "../../util/amf.h" -#include "../../util/rtmpchunks.h" +#include "../../lib/flv_tag.h" +#include "../../lib/amf.h" +#include "../../lib/rtmpchunks.h" int Detail = 0; #define DETAIL_RECONSTRUCT 1 @@ -153,7 +153,7 @@ int main(int argc, char ** argv){ std::cerr << amfdata.Print() << std::endl; }else{ amf3data = AMF::parse3(next.data); - std::cerr << amf3data.Print() << std::endl; + amf3data.Print(); } } break; case 18:{ diff --git a/src/analysers/rtp_analyser.cpp b/src/analysers/rtp_analyser.cpp deleted file mode 100644 index 30ad3842..00000000 --- a/src/analysers/rtp_analyser.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include - -///A struct that will contain all data stored in a RTP Header -struct RTP_Header { - char Version; - bool Padding; - bool Extension; - char CSRC_Count; - bool Marker; - char Payload_Type; - int Sequence_Number; - int Timestamp; - int SSRC; -};//RTP_Header - - -///Fills a RTP Header -///\param hdr A RTP Header structure -///\param Header A characterpointer to an RTP packet -///\param HeaderSize the expected length of the header -void Read_Header( RTP_Header & hdr, char * Header, int HeaderSize ) { - hdr.Version = ( Header[0] & 0xC0 ) >> 6; - hdr.Padding = ( Header[0] & 0x20 ) >> 5; - hdr.Extension = ( Header[0] & 0x10 ) >> 4; - hdr.CSRC_Count = ( Header[0] & 0x0F ); - hdr.Marker = ( Header[1] & 0x80 ) >> 7; - hdr.Payload_Type = ( Header[1] & 0x7F ); - hdr.Sequence_Number = ( ( ( Header[2] ) << 8 ) + ( Header[3] ) ) & 0x0000FFFF; - hdr.Timestamp = ( ( Header[4] ) << 24 ) + ( ( Header[5] ) << 16 ) + ( ( Header[6] ) << 8 ) + ( Header[7] ); - hdr.SSRC = ( ( Header[8] ) << 24 ) + ( ( Header[9] ) << 16 ) + ( ( Header[10] ) << 8 ) + ( Header[11] ); -} - -///Prints a RTP header -///\param hdr The RTP Header -void Print_Header( RTP_Header hdr ) { - printf( "RTP Header:\n" ); - printf( "\tVersion:\t\t%d\n", hdr.Version ); - printf( "\tPadding:\t\t%d\n", hdr.Padding ); - printf( "\tExtension:\t\t%d\n", hdr.Extension ); - printf( "\tCSRC Count:\t\t%d\n", hdr.CSRC_Count ); - printf( "\tMarker:\t\t\t%d\n", hdr.Marker ); - printf( "\tPayload Type:\t\t%d\n", hdr.Payload_Type ); - printf( "\tSequence Number:\t%d\n", hdr.Sequence_Number ); - printf( "\tTimestamp:\t\t%u\n", hdr.Timestamp ); - printf( "\tSSRC:\t\t\t%u\n", hdr.SSRC ); -} - -int main( ) { - int HeaderSize = 12; - char Header[ HeaderSize ]; - - for( int i = 0; i < HeaderSize; i++ ) { - if( !std::cin.good() ) { break; } - Header[ i ] = std::cin.get(); - } - - RTP_Header hdr; - - Read_Header( hdr, Header, HeaderSize ); - Print_Header( hdr ); - return 0; -} diff --git a/src/analysers/ts_analyser.cpp b/src/analysers/ts_analyser.cpp deleted file mode 100644 index a635ca53..00000000 --- a/src/analysers/ts_analyser.cpp +++ /dev/null @@ -1,501 +0,0 @@ -/// \file TS_Analyser/main.cpp -/// Contains the code for the TS Analyser - -#include -#include -#include -#include -#include -#include - -/// Contains all data unique to a single entry in the PAT -struct program_association_table_entry { - unsigned int Program_Number;///< Number of the program adressed - unsigned char Reserved; - unsigned int Program_Map_PID;///< PID of the map associated with this program -}; - -/// The program association table ( PAT ) -struct program_association_table { - unsigned char Pointer_Field;///< A single padding character - unsigned char Table_ID;///< ID of this table - bool Section_Syntax_Indicator;///< Indicates whether the payload confirms to specification, or is private - bool Zero; - unsigned char Reserved_1; - unsigned int Section_Length;///< Length of this section of the PAT - unsigned int Transport_Stream_ID;///< ID of the stream - unsigned char Reserved_2; - unsigned char Version_Number;///< Version of this section - bool Current_Next_Indicator;///< Currently applicable - unsigned char Section_Number;///< Number of this section - unsigned char Last_Section_Number;///< Amount of sections in the complete table - std::vector Entries; - unsigned int CRC_32; -}; - -/// An entry of the PMT -struct program_mapping_table_entry { - unsigned char Stream_Type;///< Type of stream we encounter - unsigned char Reserved_1; - unsigned int Elementary_PID;///< PID of the packages carying the elementary stream for this entry - unsigned char Reserved_2; - unsigned int ES_Info_Length;///< Length of extra info. Not needed for understanding the file -}; - -/// The program mapping table ( PMT ) -struct program_mapping_table { - unsigned char Pointer_Field;///< A single padding character - unsigned char Table_ID;///< ID of this table - bool Section_Syntax_Indicator;///< Indicates whether the payload confirms to specification, or is private - bool Zero; - unsigned char Reserved_1; - unsigned int Section_Length;///< Length of this section - unsigned int Program_Number;///< Program number in stream - unsigned char Reserved_2; - unsigned char Version_Number;///< Version of this section - bool Current_Next_Indicator;///< Currently applicable - unsigned char Section_Number;///< Number of this section - unsigned char Last_Section_Number;///< Amount of sections in PMT - unsigned char Reserved_3; - unsigned int PCR_PID;///< PID of the packets that contain Program Counter References - unsigned char Reserved_4; - unsigned int Program_Info_Length;///< Length of the program descriptors. Skip for analysis - //vector Descriptors - std::vector Entries; - unsigned int CRC_32; -}; - -/// The adaptation field -struct adaptation_field { - unsigned char Adaptation_Field_Length;///Lenght of the complete field, greater or equal to 0 - bool Discontinuity_Indicator; - bool Random_Access_Indicator; - bool Elementary_Stream_Priority_Indicator; - bool PCR_Flag;///< PCR Field existent - bool OPCR_Flag;///< OPCR Field existent - bool Splicing_Point_Flag; - bool Transport_Private_Data_Flag; - bool Adaptation_Field_Extension_Flag; - - unsigned char Program_Clock_Reference_Base_MSB;///< Most significant bit for the Base value of the PCR - unsigned int Program_Clock_Reference_Base;///< Least significant 32 bits for the Base value of the PCR - unsigned char PCR_Reserved; - unsigned int Program_Clock_Reference_Extension;///< Extension of the PCR - - unsigned char Original_Program_Clock_Reference_Base_MSB;///< Most significant bit for the Base value of the OPCR - unsigned int Original_Program_Clock_Reference_Base;///< Least significant 32 bits for the Base value of the OPCR - unsigned char OPCR_Reserved; - unsigned int Original_Program_Clock_Reference_Extension;///< Extension of the OPCR -}; - -/// The general structure of a PES packet -struct pes_packet { - unsigned int Packet_Start_Code_Prefix;///< Prefix, should be 0x000001 - unsigned char Stream_ID;///< ID of the current stream - unsigned int PES_Packet_Length;///< Length of the PES packet - - unsigned char Two; - unsigned char PES_Scrambling_Control; - bool PES_Priority; - bool Data_Alignment_Indicator; - bool Copyright; - bool Original_Or_Copy; - unsigned char PTS_DTS_Flags;///Presentation Time Stamp and/or Display Time Stamp available - bool ESCR_Flag; - bool ES_Rate_Flag; - bool DSM_Trick_Mode_Flag; - bool Additional_Copy_Info_Flag; - bool PES_CRC_Flag; - bool PES_Extension_Flag; - unsigned char PES_Header_Data_Length;///< Length of the header - - unsigned char PTS_Spacer;///< Spacer, value depends on the flag - unsigned char PTS_MSB;///< Most significant bit of the PTS - unsigned int PTS;///< Least significant 32 bits of the PTS - - unsigned char DTS_Spacer;///< Spacer, value depends on the flag - unsigned char DTS_MSB;///< Most significant bit of the DTS - unsigned int DTS;///< Least significant 32 bits of the DTS - - std::vector Header_Stuffing;///< Header stuffing, if present - std::vector First_Bytes;///< Storage capacity for the first few bytes -}; - -/// Fills a PES Packet -/// \param PES The packet in which the data should be stored -/// \param TempChar The current TS packet data -/// \param Offset Offset of the PES data, changed if adaptation field exists -void fill_pes( pes_packet & PES, unsigned char * TempChar, int Offset = 4 ) { - PES.Packet_Start_Code_Prefix = ( TempChar[Offset] << 16 ) + ( TempChar[Offset+1] << 8 ) + TempChar[Offset+2]; - PES.Stream_ID = TempChar[Offset+3]; - PES.PES_Packet_Length = ( TempChar[Offset+4] << 8 ) + TempChar[Offset+5]; - Offset += 6; - if( true ) { //Always for streams yet encountered - PES.Two = ( TempChar[Offset] & 0xC0 ) >> 6; - PES.PES_Scrambling_Control = ( TempChar[Offset] & 0x30 ) >> 4; - PES.PES_Priority = ( TempChar[Offset] & 0x08 ) >> 3; - PES.Data_Alignment_Indicator = ( TempChar[Offset] & 0x04 ) >> 2; - PES.Copyright = ( TempChar[Offset] & 0x02 ) >> 1; - PES.Original_Or_Copy = ( TempChar[Offset] & 0x01 ); - Offset ++; - PES.PTS_DTS_Flags = ( TempChar[Offset] & 0xC0 ) >> 6; - PES.ESCR_Flag = ( TempChar[Offset] & 0x20 ) >> 5; - PES.ES_Rate_Flag = ( TempChar[Offset] & 0x10 ) >> 4; - PES.DSM_Trick_Mode_Flag = ( TempChar[Offset] & 0x08 ) >> 3; - PES.Additional_Copy_Info_Flag = ( TempChar[Offset] & 0x04 ) >> 2; - PES.PES_CRC_Flag = ( TempChar[Offset] & 0x02 ) >> 1; - PES.PES_Extension_Flag = ( TempChar[Offset] & 0x01 ); - Offset ++; - PES.PES_Header_Data_Length = TempChar[Offset]; - Offset ++; - int HeaderStart = Offset; - if( PES.PTS_DTS_Flags >= 2 ) { - PES.PTS_Spacer = ( TempChar[Offset] & 0xF0 ) >> 4; - PES.PTS_MSB = ( TempChar[Offset] & 0x08 ) >> 3; - PES.PTS = ( ( TempChar[Offset] & 0x06 ) << 29 ); - PES.PTS += ( TempChar[Offset+1] ) << 22; - PES.PTS += ( ( TempChar[Offset+2] ) & 0xFE ) << 14; - PES.PTS += ( TempChar[Offset+3] ) << 7; - PES.PTS += ( ( TempChar[Offset+4] & 0xFE ) >> 1 ); - Offset += 5; - } - if( PES.PTS_DTS_Flags == 3 ) { - PES.DTS_Spacer = ( TempChar[Offset] & 0xF0 ) >> 4; - PES.DTS_MSB = ( TempChar[Offset] & 0x08 ) >> 3; - PES.DTS = ( ( TempChar[Offset] & 0x06 ) << 29 ); - PES.DTS += ( TempChar[Offset+1] ) << 22; - PES.DTS += ( ( TempChar[Offset+2] ) & 0xFE ) << 14; - PES.DTS += ( TempChar[Offset+3] ) << 7; - PES.DTS += ( ( TempChar[Offset+4] & 0xFE ) >> 1 ); - Offset += 5; - } - PES.Header_Stuffing.clear(); - while( Offset < HeaderStart + PES.PES_Header_Data_Length ) { - PES.Header_Stuffing.push_back( TempChar[Offset] ); - Offset ++; - } - PES.First_Bytes.clear(); - for( int i = 0; i < 30; i ++ ) { - PES.First_Bytes.push_back( TempChar[Offset+i] ); - } - } -} - -/// Prints a PES packet to STDOUT -/// \param PES The packet to be print -/// \param offset A string indicating the indentation of the outputed data -void print_pes( pes_packet PES, std::string offset="\t" ) { - printf( "%sPES Header\n", offset.c_str() ); - printf( "%s\tPacket Start Code Prefix\t%.6X\n", offset.c_str(), PES.Packet_Start_Code_Prefix ); - printf( "%s\tStream ID\t\t\t%X\n", offset.c_str(), PES.Stream_ID ); - printf( "%s\tPES Packet Length\t\t%X\n", offset.c_str(), PES.PES_Packet_Length ); - if( true ) { //Always for streams yet encountered - printf( "%s\tTwo:\t\t\t\t%d\n", offset.c_str(), PES.Two ); - printf( "%s\tPES Scrambling Control:\t\t%d\n", offset.c_str(), PES.PES_Scrambling_Control ); - printf( "%s\tPES Priority:\t\t\t%d\n", offset.c_str(), PES.PES_Priority ); - printf( "%s\tData Alignment Indicator:\t%d\n", offset.c_str(), PES.Data_Alignment_Indicator ); - printf( "%s\tCopyright:\t\t\t%d\n", offset.c_str(), PES.Copyright ); - printf( "%s\tOriginal Or Copy:\t\t%d\n", offset.c_str(), PES.Original_Or_Copy ); - printf( "%s\tPTS DTS Flags:\t\t\t%d\n", offset.c_str(), PES.PTS_DTS_Flags ); - printf( "%s\tESCR Flag:\t\t\t%d\n", offset.c_str(), PES.ESCR_Flag ); - printf( "%s\tES Rate Flag:\t\t\t%d\n", offset.c_str(), PES.ES_Rate_Flag ); - printf( "%s\tDSM Trick Mode Flag:\t\t%d\n", offset.c_str(), PES.DSM_Trick_Mode_Flag ); - printf( "%s\tAdditional Copy Info Flag:\t%d\n", offset.c_str(), PES.Additional_Copy_Info_Flag ); - printf( "%s\tPES CRC Flag:\t\t\t%d\n", offset.c_str(), PES.PES_CRC_Flag ); - printf( "%s\tPES Extension Flag:\t\t%d\n", offset.c_str(), PES.PES_Extension_Flag ); - printf( "%s\tPES Header Data Length:\t\t%d\n", offset.c_str(), PES.PES_Header_Data_Length ); - if( PES.PTS_DTS_Flags >= 2 ) { - printf( "%s\tPTS Spacer\t\t\t%d\n", offset.c_str(), PES.PTS_Spacer ); - printf( "%s\tPTS\t\t\t\t%X%.8X\n", offset.c_str(), PES.PTS_MSB, PES.PTS ); - } - if( PES.PTS_DTS_Flags == 3 ) { - printf( "%s\tDTS Spacer\t\t\t%d\n", offset.c_str(), PES.DTS_Spacer ); - printf( "%s\tDTS\t\t\t\t%X%.8X\n", offset.c_str(), PES.DTS_MSB, PES.DTS ); - } - printf( "%s\tHeader Stuffing\t\t\t", offset.c_str() ); - for( int i = 0; i < PES.Header_Stuffing.size(); i++ ) { - printf( "%.2X ", PES.Header_Stuffing[i] ); - } - printf( "\n" ); - printf( "%s\tFirst_Bytes\t\t\t", offset.c_str() ); - for( int i = 0; i < PES.First_Bytes.size(); i++ ) { - printf( "%.2X ", PES.First_Bytes[i] ); - } - printf( "\n" ); - } -} - -/// Fills a PAT structure with the right data -/// \param PAT the structure to be filled -/// \param TempChar The TS packet data -void fill_pat( program_association_table & PAT, unsigned char * TempChar ) { - PAT.Pointer_Field = TempChar[4]; - PAT.Table_ID = TempChar[5]; - PAT.Section_Syntax_Indicator = ((TempChar[6] & 0x80 ) != 0 ); - PAT.Zero = (( TempChar[6] & 0x40 ) != 0 ); - PAT.Reserved_1 = (( TempChar[6] & 0x30 ) >> 4 ); - PAT.Section_Length = (( TempChar[6] & 0x0F ) << 8 ) + TempChar[7]; - PAT.Transport_Stream_ID = (( TempChar[8] << 8 ) + TempChar[9] ); - PAT.Reserved_2 = (( TempChar[10] & 0xC0 ) >> 6 ); - PAT.Version_Number = (( TempChar[10] & 0x01 ) >> 1 ); - PAT.Current_Next_Indicator = (( TempChar[10] & 0x01 ) != 0 ); - PAT.Section_Number = TempChar[11]; - PAT.Last_Section_Number = TempChar[12]; - PAT.Entries.clear( ); - for( int i = 0; i < PAT.Section_Length - 9; i += 4 ) { - program_association_table_entry PAT_Entry; - PAT_Entry.Program_Number = ( TempChar[13+i] << 8 ) + TempChar[14+i]; - PAT_Entry.Reserved = ( TempChar[15+i] & 0xE0 ) >> 5; - PAT_Entry.Program_Map_PID = (( TempChar[15+i] & 0x1F ) << 8 ) + TempChar[16+i]; - PAT.Entries.push_back( PAT_Entry ); - } - PAT.CRC_32 = ( TempChar[8+PAT.Section_Length-4] << 24 ) + ( TempChar[8+PAT.Section_Length-3] << 16 ) + ( TempChar[8+PAT.Section_Length-2] << 8 ) + ( TempChar[8+PAT.Section_Length-1] ); -} - -/// Prints a PAT to STDOUT -/// \param PAT The table to be print -/// \param offset A string indicating the indentation of the outputed data -void print_pat( program_association_table PAT, bool Pointer_Field = false, std::string offset="\t" ) { - printf( "%sProgram Association Table\n", offset.c_str() ); - if( Pointer_Field ) { - printf( "%s\tPointer Field:\t\t\t%X\n", offset.c_str(), PAT.Pointer_Field ); - } - printf( "%s\tTable ID:\t\t\t%X\n", offset.c_str(), PAT.Table_ID ); - printf( "%s\tSection Syntax Indicator:\t%d\n", offset.c_str(), PAT.Section_Syntax_Indicator ); - printf( "%s\t0:\t\t\t\t%d\n", offset.c_str(), PAT.Zero ); - printf( "%s\tReserved:\t\t\t%d\n", offset.c_str(), PAT.Reserved_1 ); - printf( "%s\tSection Length:\t\t\t%X\n", offset.c_str(), PAT.Section_Length ); - printf( "%s\tTransport Stream ID\t\t%X\n", offset.c_str(), PAT.Transport_Stream_ID ); - printf( "%s\tReserved:\t\t\t%d\n", offset.c_str(), PAT.Reserved_2 ); - printf( "%s\tVersion Number:\t\t\t%X\n", offset.c_str(), PAT.Version_Number ); - printf( "%s\tCurrent Next Indicator:\t\t%d\n", offset.c_str(), PAT.Current_Next_Indicator ); - printf( "%s\tSection Number:\t\t\t%X\n", offset.c_str(), PAT.Section_Number ); - printf( "%s\tLast Section Number:\t\t%d\n\n", offset.c_str(), PAT.Last_Section_Number ); - for( int i = 0; i < PAT.Entries.size(); i++ ) { - printf( "%s\tEntry %d\n", offset.c_str(), i ); - printf( "%s\t\tProgram Number:\t\t%X\n", offset.c_str(), PAT.Entries[i].Program_Number ); - printf( "%s\t\tReserved:\t\t%X\n", offset.c_str(), PAT.Entries[i].Reserved ); - printf( "%s\t\tProgram Map PID:\t%X\n", offset.c_str(), PAT.Entries[i].Program_Map_PID ); - } - printf( "\n%s\tCRC_32:\t\t\t\t%X\n", offset.c_str(), PAT.CRC_32 ); -} - -/// Fills a PMT structure with the right data -/// \param PMT the structure to be filled -/// \param TempChar The TS packet data -void fill_pmt( program_mapping_table & PMT, unsigned char * TempChar ) { - int CurrentOffset; - PMT.Pointer_Field = TempChar[4]; - PMT.Table_ID = TempChar[5]; - PMT.Section_Syntax_Indicator = (( TempChar[6] & 0x80 ) != 0 ); - PMT.Zero = (( TempChar[6] & 0x40 ) != 0 ); - PMT.Reserved_1 = (( TempChar[6] & 0x30 ) >> 4 ); - PMT.Section_Length = (( TempChar[6] & 0x0F ) << 8 ) + TempChar[7]; - PMT.Program_Number = (TempChar[8] << 8) + TempChar[9]; - PMT.Reserved_2 = (( TempChar[10] & 0xC0 ) >> 6 ); - PMT.Version_Number = (( TempChar[10] & 0x1E ) >> 1 ); - PMT.Current_Next_Indicator = ( TempChar[10] & 0x01 ); - PMT.Section_Number = TempChar[11]; - PMT.Last_Section_Number = TempChar[12]; - PMT.Reserved_3 = (( TempChar[13] & 0xE0 ) >> 5 ); - PMT.PCR_PID = (( TempChar[13] & 0x1F ) << 8 ) + TempChar[14]; - PMT.Reserved_4 = (( TempChar[15] & 0xF0 ) >> 4 ); - PMT.Program_Info_Length = ((TempChar[15] & 0x0F ) << 8 ) + TempChar[16]; - CurrentOffset = 17 + PMT.Program_Info_Length; - PMT.Entries.clear( ); - while( CurrentOffset < PMT.Section_Length - 8 ) { - program_mapping_table_entry PMT_Entry; - PMT_Entry.Stream_Type = TempChar[CurrentOffset]; - PMT_Entry.Reserved_1 = (( TempChar[CurrentOffset+1] & 0xE0 ) >> 5 ); - PMT_Entry.Elementary_PID = (( TempChar[CurrentOffset+1] & 0x1F ) << 8 ) + TempChar[CurrentOffset+2]; - PMT_Entry.Reserved_2 = (( TempChar[CurrentOffset+3] & 0xF0 ) >> 4 ); - PMT_Entry.ES_Info_Length = (( TempChar[CurrentOffset+3] & 0x0F ) << 8 ) + TempChar[CurrentOffset+4]; - PMT.Entries.push_back( PMT_Entry ); - CurrentOffset += 4 + PMT_Entry.ES_Info_Length; - } - PMT.CRC_32 = ( TempChar[CurrentOffset] << 24 ) + ( TempChar[CurrentOffset+1] << 16 ) + ( TempChar[CurrentOffset+2] << 8 ) + ( TempChar[CurrentOffset+3] ); -} - -/// Prints a PMT to STDOUT -/// \param PMT The table to be print -/// \param offset A string indicating the indentation of the outputed data -void print_pmt( program_mapping_table PMT, bool Pointer_Field = false, std::string offset="\t" ) { - if( Pointer_Field ) { - printf( "%s\tPointer Field:\t\t\t%X\n", offset.c_str(), PMT.Pointer_Field ); - } - printf( "%s\tTable ID:\t\t\t%X\n", offset.c_str(), PMT.Table_ID ); - printf( "%s\tSection Syntax Indicator:\t%d\n", offset.c_str(), PMT.Section_Syntax_Indicator); - printf( "%s\t0:\t\t\t\t%d\n", offset.c_str(), PMT.Zero ); - printf( "%s\tReserved:\t\t\t%d\n", offset.c_str(), PMT.Reserved_1 ); - printf( "%s\tSection Length:\t\t\t%X\n", offset.c_str(), PMT.Section_Length ); - printf( "%s\tProgram Number:\t\t\t%X\n", offset.c_str(), PMT.Program_Number ); - printf( "%s\tReserved:\t\t\t%d\n", offset.c_str(), PMT.Reserved_2 ); - printf( "%s\tVersion Number:\t\t\t%d\n", offset.c_str(), PMT.Version_Number ); - printf( "%s\tCurrent_Next_Indicator:\t\t%d\n", offset.c_str(), PMT.Current_Next_Indicator ); - printf( "%s\tSection Number:\t\t\t%d\n", offset.c_str(), PMT.Section_Number ); - printf( "%s\tLast Section Number:\t\t%d\n", offset.c_str(), PMT.Last_Section_Number ); - printf( "%s\tReserved:\t\t\t%d\n", offset.c_str(), PMT.Reserved_3 ); - printf( "%s\tPCR PID:\t\t\t%X\n", offset.c_str(), PMT.PCR_PID ); - printf( "%s\tReserved:\t\t\t%d\n", offset.c_str(), PMT.Reserved_4 ); - printf( "%s\tProgram Info Length:\t\t%d\n", offset.c_str(), PMT.Program_Info_Length ); - printf( "%s\tProgram Descriptors Go Here\n\n" ); - for( int i = 0; i < PMT.Entries.size(); i++ ) { - printf( "%s\tEntry %d:\n", offset.c_str(), i ); - printf( "%s\t\tStream Type\t\t%d\n", offset.c_str(), PMT.Entries[i].Stream_Type ); - printf( "%s\t\tReserved\t\t%d\n", offset.c_str(), PMT.Entries[i].Reserved_1 ); - printf( "%s\t\tElementary PID\t\t%X\n", offset.c_str(), PMT.Entries[i].Elementary_PID ); - printf( "%s\t\tReserved\t\t%d\n", offset.c_str(), PMT.Entries[i].Reserved_2 ); - printf( "%s\t\tES Info Length\t\t%d\n", offset.c_str(), PMT.Entries[i].ES_Info_Length ); - } - printf( "%s\tCRC 32\t\t%8X\n", offset.c_str(), PMT.CRC_32 ); -} - -/// Fills an AF structure with the right data -/// \param AF the structure to be filled -/// \param TempChar The TS packet data -void fill_af( adaptation_field & AF, unsigned char * TempChar ) { - AF.Adaptation_Field_Length = TempChar[4]; - AF.Discontinuity_Indicator = (( TempChar[5] & 0x80 ) >> 7 ); - AF.Random_Access_Indicator = (( TempChar[5] & 0x40 ) >> 6 ); - AF.Elementary_Stream_Priority_Indicator = (( TempChar[5] & 0x20 ) >> 5 ); - AF.PCR_Flag = (( TempChar[5] & 0x10 ) >> 4 ); - AF.OPCR_Flag = (( TempChar[5] & 0x08 ) >> 3 ); - AF.Splicing_Point_Flag = (( TempChar[5] & 0x04 ) >> 2 ); - AF.Transport_Private_Data_Flag = (( TempChar[5] & 0x02 ) >> 1 ); - AF.Adaptation_Field_Extension_Flag = (( TempChar[5] & 0x01 ) ); - int CurrentOffset = 6; - if( AF.PCR_Flag ) { - AF.Program_Clock_Reference_Base_MSB = ( ( ( TempChar[CurrentOffset] ) & 0x80 ) >> 7 ); - AF.Program_Clock_Reference_Base = ( ( ( TempChar[CurrentOffset] ) & 0x7F ) << 25 ); - AF.Program_Clock_Reference_Base += ( ( TempChar[CurrentOffset+1] ) << 17 ); - AF.Program_Clock_Reference_Base += ( ( TempChar[CurrentOffset+2] ) << 9 ); - AF.Program_Clock_Reference_Base += ( ( TempChar[CurrentOffset+3] ) << 1 ); - AF.Program_Clock_Reference_Base += ( ( ( TempChar[CurrentOffset+4] ) & 0x80 ) >> 7 ); - AF.PCR_Reserved = ( ( TempChar[CurrentOffset+4] ) & 0x7E ) >> 1; - AF.Program_Clock_Reference_Extension = ( ( TempChar[CurrentOffset+4] ) & 0x01 ) << 8 + TempChar[CurrentOffset+5]; - CurrentOffset += 6; - } -} - -/// Prints an AF to STDOUT -/// \param AF The Adaptation Field to be print -/// \param offset A string indicating the indentation of the outputed data -void print_af( adaptation_field AF, std::string offset="\t" ) { - printf( "%sAdaptation Field\n", offset.c_str() ); - printf( "%s\tAdaptation Field Length\t\t\t%X\n", offset.c_str(), AF.Adaptation_Field_Length ); - printf( "%s\tDiscontinuity Indicator\t\t\t%X\n", offset.c_str(), AF.Discontinuity_Indicator ); - printf( "%s\tRandom Access Indicator\t\t\t%X\n", offset.c_str(), AF.Random_Access_Indicator ); - printf( "%s\tElementary Stream Priority Indicator\t%X\n", offset.c_str(), AF.Elementary_Stream_Priority_Indicator ); - printf( "%s\tPCR Flag\t\t\t\t%X\n", offset.c_str(), AF.PCR_Flag ); - printf( "%s\tOPCR Flag\t\t\t\t%X\n", offset.c_str(), AF.OPCR_Flag ); - printf( "%s\tSplicing Point Flag\t\t\t%X\n", offset.c_str(), AF.Splicing_Point_Flag ); - printf( "%s\tTransport Private Data Flag\t\t%X\n", offset.c_str(), AF.Transport_Private_Data_Flag ); - printf( "%s\tAdaptation Field Extension Flag\t\t%X\n", offset.c_str(), AF.Adaptation_Field_Extension_Flag ); - if( AF.PCR_Flag ) { - printf( "\n%s\tProgram Clock Reference Base\t\t%X%.8X\n", offset.c_str(), AF.Program_Clock_Reference_Base_MSB, AF.Program_Clock_Reference_Base ); - printf( "%s\tReserved\t\t\t\t%d\n", offset.c_str(), AF.PCR_Reserved ); - printf( "%s\tProgram Clock Reference Extension\t%X\n", offset.c_str(), AF.Program_Clock_Reference_Extension ); - } -} - -/// Locates a Packet ID in the PAT -/// \param PAT The PAT to look in -/// \param PID The PID to check for existense -/// \return The program number of the PAT, or -1 if not found -int find_pid_in_pat( program_association_table PAT, unsigned int PID ) { - for( int i = 0; i < PAT.Entries.size(); i++ ) { - if( PAT.Entries[i].Program_Map_PID == PID ) { - return PAT.Entries[i].Program_Number; - } - } - return -1; -} - -/// Checks whether a packet is part of an elementary stream -/// \param PMT The program mapping table -/// \param PID The PID of the packet -/// \return PID is found in the elementary streams of PMT -bool is_elementary_pid( program_mapping_table PMT, unsigned int PID ) { - for( int i = 0; i < PMT.Entries.size(); i++ ) { - if( PMT.Entries[i].Elementary_PID == PID ) { - return true; - } - } - return false; -} - - -/// The main function of the analyser -int main( ) { - std::string File; - unsigned int BlockNo = 1; - unsigned int EmptyBlocks = 0; - unsigned char TempChar[188]; - unsigned char Skip; - unsigned int SkippedBytes = 0; - unsigned int Adaptation; - program_association_table PAT; - program_mapping_table PMT; - adaptation_field AF; - pes_packet PES; - int ProgramNum; - std::ofstream outfile; - outfile.open( "out.ts" ); - while( std::cin.good( ) && BlockNo <= 10000 ) { - for( int i = 0; i < 188; i++ ) { - if( std::cin.good( ) ){ TempChar[i] = std::cin.get(); } - } - - int PID = ( ( TempChar[1] & 0x1F ) << 8 ) + ( TempChar[2] ); - if( true ) { - printf( "Block %d:\n", BlockNo ); - printf( "\tSync Byte:\t\t\t%X\n", TempChar[0] ); - printf( "\tTransport Error Indicator:\t%d\n", ( ( TempChar[1] & 0x80 ) != 0 ) ); - printf( "\tPayload Unit Start Indicator:\t%d\n", ( ( TempChar[1] & 0x40 ) != 0 ) ); - printf( "\tTransport Priority:\t\t%d\n", ( ( TempChar[1] & 0x20 ) != 0 ) ); - printf( "\tPID:\t\t\t\t%X\n", ( ( TempChar[1] & 0x1F ) << 8 ) + ( TempChar[2] ) ); - printf( "\tScrambling control:\t\t%d\n", ( ( TempChar[3] & 0xC0 ) >> 6 ) ); - printf( "\tAdaptation Field Exists:\t%d\n", ( ( TempChar[3] & 0x30 ) >> 4 ) ); - printf( "\tContinuity Counter:\t\t%X\n", ( TempChar[3] & 0x0F ) ); - - Adaptation = ( ( TempChar[3] & 0x30 ) >> 4 ); - - //Adaptation Field Exists - if( Adaptation == 2 || Adaptation == 3 ) { - fprintf( stderr, "Block: %d -> Adaptation == %d\n", BlockNo, Adaptation ); - fill_af( AF, TempChar ); - print_af( AF ); - } - - if( ( ( ( TempChar[1] & 0x1F ) << 8 ) + TempChar[2] ) == 0 ) { - fill_pat( PAT, TempChar ); - print_pat( PAT, true ); - } - - ProgramNum = find_pid_in_pat( PAT, ( ( TempChar[1] & 0x1F ) << 8 ) + ( TempChar[2] ) ); - if( ProgramNum != -1 ) { - printf( "\tProgram Mapping Table for program %X\n", ProgramNum ); - fill_pmt( PMT, TempChar ); - print_pmt( PMT, true ); - } - - if( ( ( TempChar[1] & 0x40 ) ) && ( ( TempChar[1] & 0x1F ) << 8 ) + ( TempChar[2] ) ) { - fill_pes( PES, TempChar, ( Adaptation == 3 ? 5 + TempChar[4] : 4 ) ); - print_pes( PES ); - } - - BlockNo ++; - } else { - EmptyBlocks ++; - } - - //Find Next Sync Byte - SkippedBytes = 0; - while( (int)std::cin.peek( ) != 0x47 ) { - std::cin >> Skip; - SkippedBytes ++; - } - } - return 0; -} - diff --git a/src/converters/Makefile.am b/src/converters/Makefile.am new file mode 100644 index 00000000..35ed7ec2 --- /dev/null +++ b/src/converters/Makefile.am @@ -0,0 +1,7 @@ +outdir=../.. +out_PROGRAMS=MistDTSC2FLV MistFLV2DTSC +AM_LDFLAGS=-L../../lib +MistDTSC2FLV_SOURCES=dtsc2flv.cpp +MistDTSC2FLV_LDADD=-ldtsc -lflv_tag -lamf -lsocket +MistFLV2DTSC_SOURCES=dtsc2flv.cpp +MistFLV2DTSC_LDADD=-ldtsc -lflv_tag -lamf -lsocket diff --git a/src/converters/dtsc2flv.cpp b/src/converters/dtsc2flv.cpp index e2572abb..2aaeaced 100644 --- a/src/converters/dtsc2flv.cpp +++ b/src/converters/dtsc2flv.cpp @@ -10,9 +10,9 @@ #include #include #include -#include "../../util/flv_tag.h" //FLV support -#include "../../util/dtsc.h" //DTSC support -#include "../../util/amf.h" //AMF support +#include "../../lib/flv_tag.h" //FLV support +#include "../../lib/dtsc.h" //DTSC support +#include "../../lib/amf.h" //AMF support /// Holds all code that converts filetypes to DTSC. namespace Converters{ diff --git a/src/converters/flv2dtsc.cpp b/src/converters/flv2dtsc.cpp index e1ad8b55..403e29e6 100644 --- a/src/converters/flv2dtsc.cpp +++ b/src/converters/flv2dtsc.cpp @@ -10,9 +10,9 @@ #include #include #include -#include "../../util/flv_tag.h" //FLV support -#include "../../util/dtsc.h" //DTSC support -#include "../../util/amf.h" //AMF support +#include "../../lib/flv_tag.h" //FLV support +#include "../../lib/dtsc.h" //DTSC support +#include "../../lib/amf.h" //AMF support /// Holds all code that converts filetypes to DTSC. namespace Converters{