Fix bug in buffer, new stuff for TS #16 5.5h

This commit is contained in:
Erik Zandvliet 2012-03-12 15:47:29 +01:00
parent 05364aad2e
commit c63e018105
3 changed files with 38 additions and 38 deletions

View file

@ -211,7 +211,9 @@ namespace Buffer{
Storage["totals"]["up"] = tot_up; Storage["totals"]["up"] = tot_up;
Storage["totals"]["count"] = tot_count; Storage["totals"]["count"] = tot_count;
Storage["totals"]["now"] = now; Storage["totals"]["now"] = now;
if( argc >= 4 ) {
Storage["totals"]["buffer"] = argv[2]; Storage["totals"]["buffer"] = argv[2];
}
if (!StatsSocket.connected()){ if (!StatsSocket.connected()){
StatsSocket = Socket::Connection("/tmp/ddv_statistics", true); StatsSocket = Socket::Connection("/tmp/ddv_statistics", true);
} }

View file

@ -1,4 +1,4 @@
SRC = main.cpp ../util/socket.cpp ../util/flv_tag.cpp SRC = main.cpp ../util/socket.cpp ../util/dtsc.cpp ../util/util.cpp
OBJ = $(SRC:.cpp=.o) OBJ = $(SRC:.cpp=.o)
OUT = DDV_Conn_TS OUT = DDV_Conn_TS
INCLUDES = INCLUDES =

View file

@ -18,7 +18,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/epoll.h> #include <sys/epoll.h>
#include "../util/socket.h" #include "../util/socket.h"
#include "../util/flv_tag.h" #include "../util/dtsc.h"
/// A simple class to create a single Transport Packet /// A simple class to create a single Transport Packet
class Transport_Packet { class Transport_Packet {
@ -216,37 +216,39 @@ void SendPMT( Socket::Connection conn ) {
/// Wraps one or more NALU packets into transport packets /// Wraps one or more NALU packets into transport packets
/// \param tag The FLV Tag /// \param tag The FLV Tag
std::vector<Transport_Packet> WrapNalus( FLV::Tag tag ) { std::vector<Transport_Packet> WrapNalus( DTSC::DTMI Tag ) {
static int ContinuityCounter = 0; static int ContinuityCounter = 0;
static int Previous_Tag = 0; static int Previous_Tag = 0;
static int First_PCR = getNowMS(); static int First_PCR = getNowMS();
static int Previous_PCR = 0; static int Previous_PCR = 0;
static char LeadIn[4] = { (char)0x00, (char)0x00, (char)0x00, (char)0x001 };
int Current_PCR; int Current_PCR;
int Current_Tag; int Current_Tag;
std::string Data = Tag.getContentP("data")->StrValue();
int Offset = 0; int Offset = 0;
Transport_Packet TS; Transport_Packet TS;
int Sent = 0; int Sent = 0;
int PacketAmount = ( ( tag.len - (188 - 35 ) ) / 184 ) + 2;
int PacketAmount = ceil( ( ( Data.size() - (188 - 35 ) ) / 184 ) + 1 );//Minus first packet, + round up and first packet.
std::vector<Transport_Packet> Result; std::vector<Transport_Packet> Result;
char LeadIn[4] = { (char)0x00, (char)0x00, (char)0x00, (char)0x01 };
TS = Transport_Packet( true, 0x100 ); TS = Transport_Packet( true, 0x100 );
TS.SetContinuityCounter( ContinuityCounter ); TS.SetContinuityCounter( ContinuityCounter );
ContinuityCounter = ( ( ContinuityCounter + 1 ) & 0x0F ); ContinuityCounter = ( ( ContinuityCounter + 1 ) & 0x0F );
Current_PCR = getNowMS(); Current_PCR = getNowMS();
Current_Tag = ( tag.data[7] << 24 ) + ( tag.data[4] << 16 ) + ( tag.data[5] << 8 ) + ( tag.data[6] ); Current_Tag = Tag.getContentP("time")->NumValue();
if( true ) { //Current_PCR - Previous_PCR >= 1 ) { if( true ) { //Current_PCR - Previous_PCR >= 1 ) {
TS.SetAdaptationField( Current_PCR - First_PCR ); TS.SetAdaptationField( Current_PCR - First_PCR );
Offset = 8; Offset = 8;
Previous_PCR = Current_PCR; Previous_PCR = Current_PCR;
} }
TS.SetPesHeader( 4 + Offset, tag.len - 16 , Current_Tag, Previous_Tag ); TS.SetPesHeader( 4 + Offset, Data.size() , Current_Tag, Previous_Tag );
Previous_Tag = Current_Tag; Previous_Tag = Current_Tag;
TS.SetPayload( LeadIn, 31, 23 + Offset ); TS.SetPayload( LeadIn, 4, 23 + Offset );
TS.SetPayload( &tag.data[16], 157 - Offset, 27 + Offset ); TS.SetPayload( &Data[16], 157 - Offset, 27 + Offset );
Sent = 157 - Offset; Sent = 157 - Offset;
Result.push_back( TS ); Result.push_back( TS );
while( Sent + 176 < tag.len - 16 ) { while( Sent + 176 < Data.size() ) {
// for( int i = 0; i < (PacketAmount - 1); i++ ) { // for( int i = 0; i < (PacketAmount - 1); i++ ) {
TS = Transport_Packet( false, 0x100 ); TS = Transport_Packet( false, 0x100 );
TS.SetContinuityCounter( ContinuityCounter ); TS.SetContinuityCounter( ContinuityCounter );
@ -258,11 +260,11 @@ std::vector<Transport_Packet> WrapNalus( FLV::Tag tag ) {
Offset = 8; Offset = 8;
Previous_PCR = Current_PCR; Previous_PCR = Current_PCR;
} }
TS.SetPayload( &tag.data[16 + Sent], 184 - Offset, 4 + Offset ); TS.SetPayload( &Data[16 + Sent], 184 - Offset, 4 + Offset );
Sent += 184 - Offset; Sent += 184 - Offset;
Result.push_back( TS ); Result.push_back( TS );
} }
if( Sent < ( tag.len - 16 ) ) { if( Sent < ( Data.size() ) ) {
Current_PCR = getNowMS(); Current_PCR = getNowMS();
Offset = 0; Offset = 0;
if( true ) { //now - Previous_PCR >= 5 ) { if( true ) { //now - Previous_PCR >= 5 ) {
@ -271,16 +273,16 @@ std::vector<Transport_Packet> WrapNalus( FLV::Tag tag ) {
Previous_PCR = Current_PCR; Previous_PCR = Current_PCR;
} }
std::cerr << "Wrapping packet: last packet length\n"; std::cerr << "Wrapping packet: last packet length\n";
std::cerr << "\tTotal:\t\t" << tag.len - 16 << "\n"; std::cerr << "\tTotal:\t\t" << Data.size() << "\n";
std::cerr << "\tSent:\t\t" << Sent << "\n"; std::cerr << "\tSent:\t\t" << Sent << "\n";
int To_Send = ( tag.len - 16 ) - Sent; int To_Send = ( Data.size() ) - Sent;
std::cerr << "\tTo Send:\t" << To_Send << "\n"; std::cerr << "\tTo Send:\t" << To_Send << "\n";
std::cerr << "\tStuffing:\t" << 176 - To_Send << "\n"; std::cerr << "\tStuffing:\t" << 176 - To_Send << "\n";
char Stuffing = (char)0xFF; char Stuffing = (char)0xFF;
for( int i = 0; i < ( 176 - To_Send ); i++ ) { for( int i = 0; i < ( 176 - To_Send ); i++ ) {
TS.SetPayload( &Stuffing, 1, 4 + Offset + i ); TS.SetPayload( &Stuffing, 1, 4 + Offset + i );
} }
TS.SetPayload( &tag.data[16 + Sent], 176 - To_Send , 4 + Offset + ( 176 - To_Send ) ); TS.SetPayload( &Data[16 + Sent], 176 - To_Send , 4 + Offset + ( 176 - To_Send ) );
Result.push_back( TS ); Result.push_back( TS );
} }
return Result; return Result;
@ -301,12 +303,13 @@ void Transport_Packet::Write( Socket::Connection conn ) {
/// The main function of the connector /// The main function of the connector
/// \param conn A connection with the client /// \param conn A connection with the client
int TS_Handler( Socket::Connection conn ) { int TS_Handler( Socket::Connection conn ) {
FLV::Tag tag;///< Temporary tag buffer for incoming video data. DTSC::Stream stream;
// FLV::Tag tag;///< Temporary tag buffer for incoming video data.
bool inited = false; bool inited = false;
bool firstvideo = true; bool firstvideo = true;
Socket::Connection ss(-1); Socket::Connection ss(-1);
int zet = 0; int zet = 0;
while(conn.connected() && !FLV::Parse_Error) { while(conn.connected()) {// && !FLV::Parse_Error) {
if( !inited ) { if( !inited ) {
ss = Socket::Connection("/tmp/shared_socket_fifa"); ss = Socket::Connection("/tmp/shared_socket_fifa");
if (!ss.connected()){ if (!ss.connected()){
@ -331,27 +334,22 @@ int TS_Handler( Socket::Connection conn ) {
break; break;
case 0: break;//not ready yet case 0: break;//not ready yet
default: default:
if (tag.SockLoader(ss)){//able to read a full packet? ss.spool();
if( tag.data[ 0 ] == 0x09 ) { if ( stream.parsePacket( conn.Received() ) ) {
if( ( ( tag.data[ 11 ] & 0x0F ) == 7 ) ) { //&& ( tag.data[ 12 ] == 1 ) ) { if( stream.lastType() == DTSC::VIDEO ) {
fprintf(stderr, "Video contains NALU\n" ); fprintf(stderr, "Video contains NALU\n" );
// if( firstvideo ) {
// firstvideo = false;
// } else {
SendPAT( conn ); SendPAT( conn );
SendPMT( conn ); SendPMT( conn );
std::vector<Transport_Packet> Meh = WrapNalus( tag ); std::vector<Transport_Packet> AllNalus = WrapNalus( stream.getPacket(0) );
for( int i = 0; i < Meh.size( ); i++ ) { for( int i = 0; i < AllNalus.size( ); i++ ) {
Meh[i].Write( conn ); AllNalus[i].Write( conn );
} }
std::cerr << "Item: " << ++zet << "\n"; std::cerr << "Item: " << ++zet << "\n";
// }
} }
} if( stream.lastType() == DTSC::AUDIO ) {
if( tag.data[ 0 ] == 0x08 ) { // if( ( tag.data[ 11 ] == 0xAF ) && ( tag.data[ 12 ] == 0x01 ) ) {
if( ( tag.data[ 11 ] == 0xAF ) && ( tag.data[ 12 ] == 0x01 ) ) {
fprintf(stderr, "Audio Contains Raw AAC\n"); fprintf(stderr, "Audio Contains Raw AAC\n");
} // }
} }
} }
break; break;