Connector_TS Added

This commit is contained in:
Erik Zandvliet 2011-07-30 12:13:51 +02:00
parent ca59fdefbd
commit 6b719ea726
8 changed files with 161 additions and 5 deletions

26
Connector_TS/Makefile Normal file
View 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

Binary file not shown.

BIN
Connector_TS/Test2.ts Normal file

Binary file not shown.

103
Connector_TS/main.cpp Normal file
View 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

Binary file not shown.

20
Connector_TS/trim.cpp Normal file
View 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];
}
}