Updates on the TS Connector -- should work now with video-only, but has bugs in getting the data from the buffer
This commit is contained in:
parent
ec180b2857
commit
8364b187e9
1 changed files with 55 additions and 19 deletions
|
@ -1,32 +1,35 @@
|
||||||
#include <iostream>
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <cstdlib>
|
#include <cmath>
|
||||||
|
#include <ctime>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cmath>
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <sys/epoll.h>
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <ctime>
|
#include <iostream>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/epoll.h>
|
||||||
#include "../util/socket.h"
|
#include "../util/socket.h"
|
||||||
#include "../util/flv_tag.h"
|
#include "../util/flv_tag.h"
|
||||||
|
|
||||||
class Transport_Packet {
|
class Transport_Packet {
|
||||||
public:
|
public:
|
||||||
Transport_Packet( int PID = 0x100 );
|
Transport_Packet( bool NALUStart = false, int PID = 0x100 );
|
||||||
|
void SetPayload( char * Payload, int PayloadLen, int Offset = 13 );
|
||||||
void SetPesHeader( );
|
void SetPesHeader( );
|
||||||
void Write( );
|
void Write( );
|
||||||
|
void Write( Socket::Connection conn );
|
||||||
private:
|
private:
|
||||||
int PID;
|
int PID;
|
||||||
char Buffer[188];
|
char Buffer[188];
|
||||||
};//Transport Packet
|
};//Transport Packet
|
||||||
|
|
||||||
Transport_Packet::Transport_Packet( int PID ) {
|
Transport_Packet::Transport_Packet( bool NALUStart, int PID ) {
|
||||||
(*this).PID = PID;
|
(*this).PID = PID;
|
||||||
Buffer[0] = (char)0x47;
|
Buffer[0] = (char)0x47;
|
||||||
Buffer[1] = (char)0x40 + (( PID & 0xFF00 ) >> 8 );
|
Buffer[1] = ( NALUStart ? (char)0x40 : 0 ) + (( PID & 0xFF00 ) >> 8 );
|
||||||
Buffer[2] = ( PID & 0x00FF );
|
Buffer[2] = ( PID & 0x00FF );
|
||||||
Buffer[3] = (char)0x00;
|
Buffer[3] = (char)0x00;
|
||||||
}
|
}
|
||||||
|
@ -36,23 +39,50 @@ void Transport_Packet::SetPesHeader( ) {
|
||||||
Buffer[5] = (char)0x00;
|
Buffer[5] = (char)0x00;
|
||||||
Buffer[6] = (char)0x01;
|
Buffer[6] = (char)0x01;
|
||||||
Buffer[7] = (char)0xE0;
|
Buffer[7] = (char)0xE0;
|
||||||
|
Buffer[8] = (char)0xFF;
|
||||||
|
Buffer[9] = (char)0xFF;
|
||||||
Buffer[10] = (char)0x80;
|
Buffer[10] = (char)0x80;
|
||||||
|
Buffer[11] = (char)0x00;
|
||||||
|
Buffer[12] = (char)0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Transport_Packet::SetPayload( char * Payload, int PayloadLen, int Offset ) {
|
||||||
|
// std::cerr << "\tSetPayload::Writing " << std::min( PayloadLen, 188-Offset ) << " bytes\n";
|
||||||
|
memcpy( &Buffer[Offset], Payload, std::min( PayloadLen, 188-Offset ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Transport_Packet> WrapNalus( FLV::Tag tag ) {
|
||||||
|
Transport_Packet TS;
|
||||||
|
int PacketAmount = ( ( tag.len - (188 - 17 ) ) / 184 ) + 2;
|
||||||
|
std::cerr << "Wrapping a tag of length " << tag.len << " into " << PacketAmount << " TS Packet(s)\n";
|
||||||
|
std::vector<Transport_Packet> Result;
|
||||||
|
char LeadIn[4] = { (char)0x00, (char)0x00, (char)0x00, (char)0x01 };
|
||||||
|
TS = Transport_Packet( true );
|
||||||
|
TS.SetPesHeader( );
|
||||||
|
TS.SetPayload( LeadIn, 4, 13 );
|
||||||
|
TS.SetPayload( &tag.data[16], 171, 17 );
|
||||||
|
Result.push_back( TS );
|
||||||
|
for( int i = 0; i < (PacketAmount - 1); i++ ) {
|
||||||
|
// std::cerr << i << "<" << (PacketAmount - 1) << "? " << ( i < ( PacketAmount - 1 ) ) << "\n";
|
||||||
|
TS = Transport_Packet( false );
|
||||||
|
TS.SetPayload( &tag.data[187+(184*i)], 184, 4 );
|
||||||
|
Result.push_back( TS );
|
||||||
|
}
|
||||||
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transport_Packet::Write( ) {
|
void Transport_Packet::Write( ) {
|
||||||
for( int i = 0; i < 188; i++ ) { std::cout << Buffer[i]; }
|
for( int i = 0; i < 188; i++ ) { std::cout << Buffer[i]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string WrapNaluIntoTS( char * Buffer, int BufLen ) {
|
void Transport_Packet::Write( Socket::Connection conn ) {
|
||||||
std::string result;
|
conn.write( Buffer, 188 );
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int TS_Handler( Socket::Connection conn ) {
|
int TS_Handler( Socket::Connection conn ) {
|
||||||
FLV::Tag tag;///< Temporary tag buffer for incoming video data.
|
FLV::Tag tag;///< Temporary tag buffer for incoming video data.
|
||||||
bool ready4data = false;///< Set to true when streaming is to begin.
|
|
||||||
bool inited = false;
|
bool inited = false;
|
||||||
|
bool firstvideo = true;
|
||||||
Socket::Connection ss(-1);
|
Socket::Connection ss(-1);
|
||||||
while(conn.connected() && !FLV::Parse_Error) {
|
while(conn.connected() && !FLV::Parse_Error) {
|
||||||
if( !inited ) {
|
if( !inited ) {
|
||||||
|
@ -81,7 +111,16 @@ int TS_Handler( Socket::Connection conn ) {
|
||||||
if (tag.SockLoader(ss)){//able to read a full packet?
|
if (tag.SockLoader(ss)){//able to read a full packet?
|
||||||
if( tag.data[ 0 ] == 0x09 ) {
|
if( tag.data[ 0 ] == 0x09 ) {
|
||||||
if( ( ( tag.data[ 11 ] & 0x0F ) == 7 ) && ( tag.data[ 12 ] == 1 ) ) {
|
if( ( ( tag.data[ 11 ] & 0x0F ) == 7 ) && ( tag.data[ 12 ] == 1 ) ) {
|
||||||
fprintf(stderr, "Video contains NALU" );
|
fprintf(stderr, "Video contains NALU\n" );
|
||||||
|
if( firstvideo ) {
|
||||||
|
firstvideo = false;
|
||||||
|
} else {
|
||||||
|
std::vector<Transport_Packet> Meh = WrapNalus( tag );
|
||||||
|
std::cerr << "Received " << Meh.size( ) << " Transport Packet(s)\n";
|
||||||
|
for( int i = 0; i < Meh.size( ); i++ ) {
|
||||||
|
Meh[i].Write( conn );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( tag.data[ 0 ] == 0x08 ) {
|
if( tag.data[ 0 ] == 0x08 ) {
|
||||||
|
@ -91,9 +130,6 @@ int TS_Handler( Socket::Connection conn ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Transport_Packet TS = Transport_Packet( );
|
|
||||||
TS.SetPesHeader( );
|
|
||||||
TS.Write( );
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue