Connector_TS Added
This commit is contained in:
parent
ca59fdefbd
commit
6b719ea726
8 changed files with 161 additions and 5 deletions
|
@ -5,5 +5,5 @@
|
||||||
|
|
||||||
#ffmpeg -y -i "$1" -ar 44100 -vcodec libx264 -b 1000k -g 150 -r 20 -f flv - | ./Buffer 500
|
#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
|
||||||
|
|
||||||
|
|
26
Connector_TS/Makefile
Normal file
26
Connector_TS/Makefile
Normal file
|
@ -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
|
||||||
|
|
BIN
Connector_TS/Test.ts
Normal file
BIN
Connector_TS/Test.ts
Normal file
Binary file not shown.
BIN
Connector_TS/Test2.ts
Normal file
BIN
Connector_TS/Test2.ts
Normal file
Binary file not shown.
103
Connector_TS/main.cpp
Normal file
103
Connector_TS/main.cpp
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <queue>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
#include <cmath>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <sys/epoll.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <ctime>
|
||||||
|
#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"
|
BIN
Connector_TS/trim
Executable file
BIN
Connector_TS/trim
Executable file
Binary file not shown.
20
Connector_TS/trim.cpp
Normal file
20
Connector_TS/trim.cpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
#include<iostream>
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
}
|
|
@ -116,6 +116,7 @@ struct pes_packet {
|
||||||
unsigned int DTS;
|
unsigned int DTS;
|
||||||
|
|
||||||
std::vector<unsigned char> Header_Stuffing;
|
std::vector<unsigned char> Header_Stuffing;
|
||||||
|
std::vector<unsigned char> First_Bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
void fill_pes( pes_packet & PES, unsigned char * TempChar, int Offset = 4 ) {
|
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] );
|
PES.Header_Stuffing.push_back( TempChar[Offset] );
|
||||||
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( "%.2X ", PES.Header_Stuffing[i] );
|
||||||
}
|
}
|
||||||
printf( "\n" );
|
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;
|
adaptation_field AF;
|
||||||
pes_packet PES;
|
pes_packet PES;
|
||||||
int ProgramNum;
|
int ProgramNum;
|
||||||
while( std::cin.good( ) ) { //&& BlockNo <= 1000 ) {
|
while( std::cin.good( ) && BlockNo <= 1000 ) {
|
||||||
for( int i = 0; i < 188; i++ ) {
|
for( int i = 0; i < 188; i++ ) {
|
||||||
if( std::cin.good( ) ){ TempChar[i] = std::cin.get(); }
|
if( std::cin.good( ) ){ TempChar[i] = std::cin.get(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if( ( ( TempChar[1] & 0x1F ) << 8 ) + ( TempChar[2] ) != 0x1FFF ) {
|
if( ( ( TempChar[1] & 0x1F ) << 8 ) + ( TempChar[2] ) != 0x1FFF ) {
|
||||||
printf( "Block %d:\n", BlockNo );
|
printf( "Block %d:\n", BlockNo );
|
||||||
printf( "\tSync Byte:\t\t\t%X\n", TempChar[0] );
|
printf( "\tSync Byte:\t\t\t%X\n", TempChar[0] );
|
||||||
|
@ -417,7 +425,6 @@ int main( ) {
|
||||||
print_af( AF );
|
print_af( AF );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( ( ( ( TempChar[1] & 0x1F ) << 8 ) + TempChar[2] ) == 0 ) {
|
if( ( ( ( TempChar[1] & 0x1F ) << 8 ) + TempChar[2] ) == 0 ) {
|
||||||
fill_pat( PAT, TempChar );
|
fill_pat( PAT, TempChar );
|
||||||
print_pat( PAT, true );
|
print_pat( PAT, true );
|
||||||
|
|
Loading…
Add table
Reference in a new issue