diff --git a/Buffer/playh264.sh b/Buffer/playh264.sh index 602d2f0a..4ec9510f 100755 --- a/Buffer/playh264.sh +++ b/Buffer/playh264.sh @@ -5,5 +5,5 @@ #ffmpeg -y -i "$1" -ar 44100 -vcodec libx264 -b 1000k -g 150 -r 20 -f flv - | ./Buffer 500 -ffmpeg -i "$1" -re -acodec aac -ar 11025 -vcodec libx264 -b 700k -vpre ultrafast -refs 1 -bf 0 -g 150 -f flv - 2> /dev/null | ./DDV_Buffer 500 $2 +ffmpeg -i "$1" -re -strict experimental -acodec aac -ar 11025 -vcodec libx264 -b 700k -vpre libx264-lossless_ultrafast -refs 1 -bf 0 -g 150 -f flv - 2> /dev/null | ./DDV_Buffer 500 $2 diff --git a/Connector_TS/Makefile b/Connector_TS/Makefile new file mode 100644 index 00000000..a248e725 --- /dev/null +++ b/Connector_TS/Makefile @@ -0,0 +1,26 @@ +SRC = main.cpp ../util/socket.cpp ../util/flv_tag.cpp +OBJ = $(SRC:.cpp=.o) +OUT = DDV_Conn_TS +INCLUDES = +DEBUG = 4 +OPTIMIZE = -g +CCFLAGS = -Wall -Wextra -funsigned-char $(OPTIMIZE) -DDEBUG=$(DEBUG) +CC = $(CROSS)g++ +LD = $(CROSS)ld +AR = $(CROSS)ar +LIBS= +.SUFFIXES: .cpp +.PHONY: clean default +default: $(OUT) +.cpp.o: + $(CC) $(INCLUDES) $(CCFLAGS) $(LIBS) -c $< -o $@ +$(OUT): $(OBJ) + $(CC) $(LIBS) -o $(OUT) $(OBJ) +clean: + rm -rf $(OBJ) $(OUT) Makefile.bak *~ +install: $(OUT) + -service HTTP_Conn stop + cp -f ./$(OUT) /usr/bin/ + cp -f ./HTTP_Conn /etc/init.d/ + service HTTP_Conn start + diff --git a/Connector_TS/Test.ts b/Connector_TS/Test.ts new file mode 100644 index 00000000..15a940de Binary files /dev/null and b/Connector_TS/Test.ts differ diff --git a/Connector_TS/Test2.ts b/Connector_TS/Test2.ts new file mode 100644 index 00000000..ddc7160a Binary files /dev/null and b/Connector_TS/Test2.ts differ diff --git a/Connector_TS/main.cpp b/Connector_TS/main.cpp new file mode 100644 index 00000000..b2e3e735 --- /dev/null +++ b/Connector_TS/main.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../util/socket.h" +#include "../util/flv_tag.h" + +class Transport_Packet { + public: + Transport_Packet( int PID = 0x100 ); + void SetPesHeader( ); + void Write( ); + private: + int PID; + char Buffer[188]; +};//Transport Packet + +Transport_Packet::Transport_Packet( int PID ) { + (*this).PID = PID; + Buffer[0] = (char)0x47; + Buffer[1] = (char)0x40 + (( PID & 0xFF00 ) >> 8 ); + Buffer[2] = ( PID & 0x00FF ); + Buffer[3] = (char)0x00; +} + +void Transport_Packet::SetPesHeader( ) { + Buffer[4] = (char)0x00; + Buffer[5] = (char)0x00; + Buffer[6] = (char)0x01; + Buffer[7] = (char)0xE0; + + Buffer[10] = (char)0x80; +} + +void Transport_Packet::Write( ) { + for( int i = 0; i < 188; i++ ) { std::cout << Buffer[i]; } +} + +std::string WrapNaluIntoTS( char * Buffer, int BufLen ) { + std::string result; + return result; +} + +int TS_Handler( Socket::Connection conn ) { + FLV::Tag tag;///< Temporary tag buffer for incoming video data. + bool ready4data = false;///< Set to true when streaming is to begin. + bool inited = false; + Socket::Connection ss(-1); + while(conn.connected() && !FLV::Parse_Error) { + if( !inited ) { + ss = Socket::Connection("/tmp/shared_socket_fifa"); + if (!ss.connected()){ + #if DEBUG >= 1 + fprintf(stderr, "Could not connect to server!\n"); + #endif + conn.close(); + break; + } + #if DEBUG >= 3 + fprintf(stderr, "Everything connected, starting to send video data...\n"); + #endif + inited = true; + } + switch (ss.ready()){ + case -1: + conn.close(); + #if DEBUG >= 1 + fprintf(stderr, "Source socket is disconnected.\n"); + #endif + break; + case 0: break;//not ready yet + default: + if (tag.SockLoader(ss)){//able to read a full packet? + if( tag.data[ 0 ] == 0x09 ) { + if( ( ( tag.data[ 11 ] & 0x0F ) == 7 ) && ( tag.data[ 12 ] == 1 ) ) { + fprintf(stderr, "Video contains NALU" ); + } + } + if( tag.data[ 0 ] == 0x08 ) { + fprintf(stderr, "Audio Tag Read\n"); + } + } + break; + } + } + Transport_Packet TS = Transport_Packet( ); + TS.SetPesHeader( ); + TS.Write( ); + return 0; +} + +#define DEFAULT_PORT 8888 +#define MAINHANDLER TS_Handler +#define CONFIGSECT TS +#include "../util/server_setup.cpp" diff --git a/Connector_TS/trim b/Connector_TS/trim new file mode 100755 index 00000000..4ed69cf1 Binary files /dev/null and b/Connector_TS/trim differ diff --git a/Connector_TS/trim.cpp b/Connector_TS/trim.cpp new file mode 100644 index 00000000..2149095b --- /dev/null +++ b/Connector_TS/trim.cpp @@ -0,0 +1,20 @@ + +#include +#include + +int main( ) { + std::string Temp; + while( std::cin.good() ) { + Temp += std::cin.get(); + } + while( Temp[0] == (char)0x00 ) { + Temp.erase( Temp.begin() ); + } + Temp.erase( Temp.end() - 1 ); + while( Temp[ Temp.size()-1 ] == (char)0x00 ) { + Temp.erase( Temp.end() - 1 ); + } + for( int i = 0; i < Temp.size(); i++ ) { + std::cout << Temp[i]; + } +} diff --git a/TS_Analyser/main.cpp b/TS_Analyser/main.cpp index ad1ea89e..4e451235 100644 --- a/TS_Analyser/main.cpp +++ b/TS_Analyser/main.cpp @@ -116,6 +116,7 @@ struct pes_packet { unsigned int DTS; std::vector Header_Stuffing; + std::vector First_Bytes; }; void fill_pes( pes_packet & PES, unsigned char * TempChar, int Offset = 4 ) { @@ -167,6 +168,10 @@ void fill_pes( pes_packet & PES, unsigned char * TempChar, int Offset = 4 ) { 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] ); + } } } @@ -203,6 +208,11 @@ void print_pes( pes_packet PES, std::string offset="\t" ) { 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" ); } } @@ -391,13 +401,11 @@ int main( ) { adaptation_field AF; pes_packet PES; int ProgramNum; - while( std::cin.good( ) ) { //&& BlockNo <= 1000 ) { + while( std::cin.good( ) && BlockNo <= 1000 ) { for( int i = 0; i < 188; i++ ) { if( std::cin.good( ) ){ TempChar[i] = std::cin.get(); } } - - if( ( ( TempChar[1] & 0x1F ) << 8 ) + ( TempChar[2] ) != 0x1FFF ) { printf( "Block %d:\n", BlockNo ); printf( "\tSync Byte:\t\t\t%X\n", TempChar[0] ); @@ -417,7 +425,6 @@ int main( ) { print_af( AF ); } - if( ( ( ( TempChar[1] & 0x1F ) << 8 ) + TempChar[2] ) == 0 ) { fill_pat( PAT, TempChar ); print_pat( PAT, true );