Convert to autotools build system for cleanness (part1).

This commit is contained in:
Thulinma 2012-05-08 19:19:42 +02:00
parent 3ebfe1b693
commit 36e086e0e2
125 changed files with 125 additions and 4475 deletions

View file

@ -1,23 +0,0 @@
SRC = main.cpp ../util/json.cpp ../util/socket.cpp ../util/dtsc.cpp ../util/tinythread.cpp user.cpp stats.cpp stream.cpp
OBJ = $(SRC:.cpp=.o)
OUT = MistBuffer
INCLUDES =
DEBUG = 4
OPTIMIZE = -g
CCFLAGS = -Wall -Wextra -funsigned-char $(OPTIMIZE) -DDEBUG=$(DEBUG)
CC = $(CROSS)g++
LD = $(CROSS)ld
AR = $(CROSS)ar
LIBS = -lpthread
.SUFFIXES: .cpp
.PHONY: clean default
default: $(OUT)
.cpp.o:
$(CC) $(INCLUDES) $(CCFLAGS) $(LIBS) -c $< -o $@
$(OUT): $(OBJ)
$(CC) $(LIBS) -o ../bin/$(OUT) $(OBJ)
clean:
rm -rf $(OBJ) ../bin/$(OUT) Makefile.bak *~
install: $(OUT)
cp -f ../bin/$(OUT) /usr/bin/

View file

@ -1,5 +0,0 @@
#!/bin/bash
ffmpeg -re -i "$1" -b 1024000 -ar 11025 -f flv - 2> /dev/null | ./Buffer 500 $2

View file

@ -1,9 +0,0 @@
#!/bin/bash
#ffmpeg -y -i "$1" -acodec libfaac -ar 44100 -vcodec libx264 -b 1000k -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -g 150 -r 20 -f flv - 2> /dev/null | ./Server_PLS 500
#ffmpeg -y -i "$1" -ar 44100 -vcodec libx264 -b 1000k -g 150 -r 20 -f flv - | ./Buffer 500
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

View file

@ -1,26 +0,0 @@
SRC = main.cpp ../util/socket.cpp ../util/http_parser.cpp ../util/flv_tag.cpp ../util/amf.cpp ../util/dtsc.cpp ../util/config.cpp ../util/base64.cpp ../util/json.cpp
OBJ = $(SRC:.cpp=.o)
OUT = MistConnHTTP
INCLUDES =
DEBUG = 4
OPTIMIZE = -g
CCFLAGS = -Wall -Wextra -funsigned-char $(OPTIMIZE) -DDEBUG=$(DEBUG) -DVERSION=$(VERSION)
VERSION = `git describe --tags`
CC = $(CROSS)g++
LD = $(CROSS)ld
AR = $(CROSS)ar
LIBS=
.SUFFIXES: .cpp
.PHONY: clean default
default: cversion $(OUT)
.cpp.o:
$(CC) $(INCLUDES) $(CCFLAGS) $(LIBS) -c $< -o $@
$(OUT): $(OBJ)
$(CC) $(LIBS) -o ../bin/$(OUT) $(OBJ)
clean:
rm -rf $(OBJ) ../bin/$(OUT) Makefile.bak *~
install: $(OUT)
cp -f ../bin/$(OUT) /usr/bin/
cversion:
rm -rf ../util/config.o

View file

@ -1,23 +0,0 @@
SRC = main.cpp ../util/socket.cpp
OBJ = $(SRC:.cpp=.o)
OUT = MistConnRAW
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 ../bin/$(OUT) $(OBJ)
clean:
rm -rf $(OBJ) ../bin/$(OUT) Makefile.bak *~
install: $(OUT)
cp -f ../bin/$(OUT) /usr/bin/

View file

@ -1,27 +0,0 @@
SRC = main.cpp ../util/socket.cpp ../util/flv_tag.cpp ../util/amf.cpp ../util/rtmpchunks.cpp ../util/crypto.cpp ../util/config.cpp ../util/dtsc.cpp
OBJ = $(SRC:.cpp=.o)
OUT = MistConnRTMP
INCLUDES =
STATIC =
DEBUG = 4
OPTIMIZE = -g
CCFLAGS = -Wall -Wextra -funsigned-char $(OPTIMIZE) -DDEBUG=$(DEBUG) -DVERSION=$(VERSION)
CC = $(CROSS)g++
LD = $(CROSS)ld
AR = $(CROSS)ar
VERSION = `git describe --tags`
LIBS = -lssl -lcrypto
.SUFFIXES: .cpp
.PHONY: clean default
default: cversion $(OUT)
.cpp.o:
$(CC) $(INCLUDES) $(CCFLAGS) -c $< -o $@
$(OUT): $(OBJ)
$(CC) -o ../bin/$(OUT) $(OBJ) $(STATIC) $(LIBS)
clean:
rm -rf $(OBJ) ../bin/$(OUT) Makefile.bak *~
install: $(OUT)
cp -f ../bin/$(OUT) /usr/bin/
cversion:
rm -rf ../util/config.o

View file

@ -1,25 +0,0 @@
SRC = main.cpp ../util/socket.cpp ../util/http_parser.cpp ../util/flv_tag.cpp ../util/amf.cpp ../util/util.cpp ../util/dtsc.cpp
OBJ = $(SRC:.cpp=.o)
OUT = Connector_RTSP
INCLUDES = $(shell pkg-config --cflags jrtplib)
DEBUG = 4
OPTIMIZE = -g
CCFLAGS = -Wall -Wextra -funsigned-char $(OPTIMIZE) -DDEBUG=$(DEBUG)
CC = $(CROSS)g++
LD = $(CROSS)ld
AR = $(CROSS)ar
LIBS = $(shell pkg-config --libs jrtplib)
.SUFFIXES: .cpp
.PHONY: clean default
default: $(OUT)
.cpp.o:
$(CC) $(INCLUDES) $(CCFLAGS) $(LIBS) -c $< -o $@
$(OUT): $(OBJ)
$(CC) -o $(OUT) $(OBJ) $(LIBS)
clean:
rm -rf $(OBJ) $(OUT) Makefile.bak *~
run-test: $(OUT)
rm -rf ./meh
mkfifo ./meh
cat ./meh &
nc -l -p 554 -e './$(OUT) 2>./meh'

View file

@ -1,25 +0,0 @@
example for installing to ../usr (use DESTDIR=/tmp, /usr/local or whatever you want)
$ DESTDIR="${PWD%/*}/usr"
building jthread (as local user, no root required):
$ cd $somedir
$ wget http://research.edm.uhasselt.be/jori/jthread/jthread-1.3.1.tar.gz
$ tar xvf jthread-1.3.1.tar.gz && cd jthread-1.3.1
$ cmake -DCMAKE_INSTALL_PREFIX:PATH="$DESTDIR"
$ make && make install
AFTER building jthread
$ cd $somedir
$ wget http://research.edm.uhasselt.be/jori/jrtplib/jrtplib-3.9.1.tar.bz2
$ tar xf jrtplib-3.9.1.tar.bz2 && cd jrtplib-3.9.1
$ cmake -DCMAKE_INSTALL_PREFIX:PATH="$DESTDIRr" -DADDITIONAL_INCLUDE_DIRS:STRING="$DESTDIR/include"
$ make -j8
Modify $DESTDIR/usr/lib/pkgconfig/jrtplib.pc such that it looks like (subst $DESTDIR accordingly):
Libs: -L$DESTDIR/lib/ -ljrtp -ljthread -lpthread
$ make install
building Connector_RTSP:
$ PKG_CONFIG_PATH=$DESTDIR/lib/pkgconfig make
Running Connector_RTSP:
$ LD_LIBRARY_PATH="$DESTDIR/lib:$LD_LIBRARY_PATH" ./Connector_RTSP

View file

@ -1,299 +0,0 @@
/// \file Connector_RTSP/main.cpp
/// Contains the main code for the RTSP Connector
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <string>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <getopt.h>
#include <iostream>
#include <sstream>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/epoll.h>
#include "../util/socket.h"
#include "../util/flv_tag.h"
#include "../util/http_parser.h"
//JRTPLIB
#include "rtp.h"
/// Reads a single NALU from std::cin. Expected is H.264 Bytestream format.
/// Function was used as a way of debugging data. FLV does not contain all the metadata we need, so we had to try different approaches.
/// \return The Nalu data.
/// \todo Throw this function away when everything works, it is not needed.
std::string ReadNALU( ) {
static char Separator[3] = { (char)0x00, (char)0x00, (char)0x01 };
std::string Buffer;
std::string Result;
do {
Buffer += std::cin.get();
} while ( std::cin.good() && ( Buffer.find( Separator,0,3 ) == std::string::npos ) );
if( !std::cin.good() ) { return ""; }
Result = Buffer.substr(0, Buffer.find( Separator,0,3 ) );
while( *(Result.end() - 1) == (char)0x00 ) { Result.erase( Result.end() - 1 ); }
if( Result.size() == 0 ) { Result = ReadNALU( ); }
return Result;
}
/// The main function of the connector.
/// Used by server_setup.cpp in the bottom of the file, to start up the Connector.
/// This function contains the while loop the accepts connections, and sends them data.
/// \param conn A connection with the client.
int RTSP_Handler( Socket::Connection conn ) {
/// \todo Convert this to DTSC::DTMI, with an additional DTSC::Stream/
FLV::Tag tag;// Temporary tag buffer for incoming video data.
bool PlayVideo = false;
bool PlayAudio = true;
//JRTPlib Objects to handle the RTP connection, which runs "parallel" to RTSP.
jrtplib::RTPSession VideoSession;
jrtplib::RTPSessionParams VideoParams;
jrtplib::RTPUDPv6TransmissionParams VideoTransParams;
std::string PreviousRequest = "";
std::string streamname;
Socket::Connection ss(-1);
HTTP::Parser HTTP_R, HTTP_S;
//Some clients appear to expect a single request per connection. Don't know which ones.
bool PerRequest = false;
//The main loop of the function
while(conn.connected() && !FLV::Parse_Error) {
if( HTTP_R.Read(conn ) ) {
//send Debug info to stderr.
//send the appropriate responses on RTSP Commands.
fprintf( stderr, "REQUEST:\n%s\n", HTTP_R.BuildRequest().c_str() );
HTTP_S.protocol = "RTSP/1.0";
if( HTTP_R.method == "OPTIONS" ) {
//Always return the requested CSeq value.
HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() );
//The minimal set of options required for RTSP, add new options here as well if we want to support these.
HTTP_S.SetHeader( "Public", "OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY" );
//End the HTTP body, IMPORTANT!! Connection hangs otherwise!!
HTTP_S.SetBody( "\r\n\r\n" );
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() );
conn.write( HTTP_S.BuildResponse( "200", "OK" ) );
} else if ( HTTP_R.method == "DESCRIBE" ) {
///\todo Implement DESCRIBE option.
//Don't know if a 501 response is seen as valid. If it is, don't bother changing it.
if( HTTP_R.GetHeader( "Accept" ).find( "application/sdp" ) == std::string::npos ) {
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "501", "Not Implemented" ).c_str() );
conn.write( HTTP_S.BuildResponse( "501", "Not Implemented" ) );
} else {
HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() );
HTTP_S.SetHeader( "Content-Type", "application/sdp" );
/// \todo Retrieve presence of video and audio data, and process into response. Can now easily be done through DTSC::DTMI
/// \todo Retrieve Packetization mode ( is 0 for now ). I suppose this is the H264 packetization mode. Can maybe be retrieved from the docs on H64.
/// \todo Send a valid SDP file.
/// \todo Add audio to SDP file.
//This is just a dummy with data that was supposedly right for our teststream.
//SDP Docs: http://tools.ietf.org/html/rfc4566
HTTP_S.SetBody( "v=0\r\n" //protocol version
"o=- 0 0 IN IP4 ddvtech.com\r\n" //originator and session identifier (5.2):
//username sess-id sess-version nettype addrtype unicast-addr
//"-": no concept of User IDs, nettype IN(ternet)
//IP4: following address is a FQDN for IPv4
"s=Fifa Test\r\n" //session name (5.3)
//"c" - destination is specified in SETUP per rfc2326 C.1.7, set null as recommended
"c=IN IP4 0.0.0.0\r\n" //connection information -- not required if included in all media
//nettype addrtype connection-address
"t=0 0\r\n" //time the session is active: start-time stop-time; "0 0"=permanent session
"a=recvonly\r\n"//zero or more session attribute lines
"m=video 0 RTP/AVP 98\r\n"//media name and transport address: media port proto fmt ...
"a=control:" + HTTP_R.url + "\r\n"//rfc2326 C.1.1, URL for aggregate control on session level
"a=rtpmap:98 H264/90000\r\n"//rfc2326 C.1.3, dynamic payload type; see also http://tools.ietf.org/html/rfc1890#section-5
"a=fmtp:98 packetization-mode=0"//codec-specific parameters
"\r\n\r\n");//m=audio 0 RTP/AAP 96\r\na=control:rtsp://localhost/fifa/audio\r\na=rtpmap:96 mpeg4-generic/16000/2\r\n\r\n");
//important information when supporting multiple streams http://tools.ietf.org/html/rfc2326#appendix-C.3
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() );
conn.write( HTTP_S.BuildResponse( "200", "OK" ) );
}
} else if ( HTTP_R.method == "SETUP" ) {
bool setup_session = false;//whether a session should be setup or not
std::string temp = HTTP_R.GetHeader("Transport");
//Extract the random UTP pair for video data ( RTP/RTCP)
int ClientRTPLoc = temp.find( "client_port=" ) + 12;
int PortSpacer = temp.find( "-", ClientRTPLoc );
int RTPClientPort = atoi( temp.substr( ClientRTPLoc, ( PortSpacer - ClientRTPLoc ) ).c_str() );
if( HTTP_S.GetHeader( "Session" ) != "" ) {
//Return an error if a second client tries to connect with an already running stream.
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "459", "Aggregate Operation Not Allowed" ).c_str() );
conn.write( HTTP_S.BuildResponse( "459", "Aggregate Operation Not Allowed" ) );
} else {
do{
if (!ss.connected()){
/// \todo Put stream name-to-file mapping in a separate util file or even class
streamname = std::string(HTTP_R.url.c_str());
unsigned int slash_pos = streamname.rfind('/');
if (slash_pos != std::string::npos) streamname.erase(0, slash_pos);
for (std::string::iterator i=streamname.begin(); i != streamname.end(); ++i){
if (*i == '?'){
streamname.erase(i, streamname.end());
break;
}
if (!isalpha(*i) && !isdigit(*i) && *i != '_'){
streamname.erase(i);
--i;
}else{
*i = tolower(*i);
}
}
streamname = "/tmp/shared_socket_" + streamname;
ss = Socket::Connection(streamname);
if (!ss.connected()){
streamname = "";
HTTP_R.BuildResponse("404", "Not Found");
break; //skip the session below
}
}
setup_session = true;
}while(0);
}
if (setup_session) {
HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() );
HTTP_S.SetHeader( "Session", time(NULL) );
/// \todo Add support for audio
// if( HTTP_R.url.find( "audio" ) != std::string::npos ) {
// HTTP_S.SetHeader( "Transport", HTTP_R.GetHeader( "Transport" ) + ";server_port=50002-50003" );
// } else {
//Stub data for testing purposes. This should now be extracted somehow from DTSC::DTMI
VideoParams.SetOwnTimestampUnit( ( 1.0 / 29.917 ) * 90000.0 );
VideoParams.SetMaximumPacketSize( 10000 );
//create a JRTPlib session
int VideoStatus;
uint16_t pbase;
//after 20 retries, just give up, most ports are likely in use
int retries = 20;
do {
//pick the right port here in the range 5000 to 5000 + 2 * 500 = 6000
pbase = 5000 + 2 * (rand() % 500);
VideoTransParams.SetPortbase( pbase );
VideoStatus = VideoSession.Create( VideoParams, &VideoTransParams, jrtplib::RTPTransmitter::IPv6UDPProto );
} while(VideoStatus < 0 && --retries > 0);
if( VideoStatus < 0 ) {
std::cerr << "Video session could not be created: " << jrtplib::RTPGetErrorString( VideoStatus ) << std::endl;
exit( -1 );
} else {
std::cerr << "Created video session using ports " << pbase << " and " << (pbase+1) << "\n";
}
//send video data
std::stringstream transport;
transport << HTTP_R.GetHeader( "Transport" ) << ";server_port=" << pbase << "-" << (pbase+1);
HTTP_S.SetHeader( "Transport", transport.str() );
/// \todo Connect with clients other than localhost
uint8_t localip[32];
int status = inet_pton( AF_INET6, conn.getHost().c_str(), localip ) ;
//Debug info
std::cerr << "Status: " << status << "\n";
jrtplib::RTPIPv6Address addr(localip,RTPClientPort);
//add the destination address to the VideoSession
VideoStatus = VideoSession.AddDestination(addr);
if (VideoStatus < 0) {
std::cerr << "Destination could not be set: " << jrtplib::RTPGetErrorString(VideoStatus) << std::endl;
exit(-1);
} else {
std::cerr << "Destination Set\n";
}
//Stub data for testing purposes.
//Payload type should confirm with the SDP File. 98 == H264 / AVC
VideoSession.SetDefaultPayloadType(98);
VideoSession.SetDefaultMark(false);
//We have no idea if this timestamp has to correspond with the OwnTimeStampUnit() above.
VideoSession.SetDefaultTimestampIncrement( ( 1.0 / 29.917 ) * 90000 );
// }
HTTP_S.SetBody( "\r\n\r\n" );
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() );
conn.write( HTTP_S.BuildResponse( "200", "OK" ) );
}
} else if( HTTP_R.method == "PLAY" ) {
if( HTTP_R.GetHeader( "Range" ).substr(0,4) != "npt=" ) {
//We do not support this, whatever it is. Not needed for minimal compliance.
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "501", "Not Implemented" ).c_str() );
conn.write( HTTP_S.BuildResponse( "501", "Not Implemented" ) );
} else {
//Initializes for actual streaming over the SETUP connection.
HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() );
HTTP_S.SetHeader( "Session", HTTP_R.GetHeader( "Session" ) );
HTTP_S.SetHeader( "Range", HTTP_R.GetHeader( "Range" ) );
HTTP_S.SetHeader( "RTP-Info", "url=" + HTTP_R.url + ";seq=0;rtptime=0" );
HTTP_S.SetBody( "\r\n\r\n" );
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() );
conn.write( HTTP_S.BuildResponse( "200", "OK" ) );
//Used further down, to start streaming video.
//PlayAudio = true;
PlayVideo = true;
}
} else if( HTTP_R.method == "TEARDOWN" ) {
//If we were sending any stream data at this point, stop it, but keep the setup.
HTTP_S.SetHeader( "CSeq", HTTP_R.GetHeader( "CSeq" ).c_str() );
HTTP_S.SetBody( "\r\n\r\n" );
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "200", "OK" ).c_str() );
conn.write( HTTP_S.BuildResponse( "200", "OK" ) );
//PlayAudio = false;
PlayVideo = false;
} else {
//We do not implement other commands ( yet )
fprintf( stderr, "RESPONSE:\n%s\n", HTTP_S.BuildResponse( "501", "Not Implemented" ).c_str() );
conn.write( HTTP_S.BuildResponse( "501", "Not Implemented" ) );
}
HTTP_R.Clean();
HTTP_S.Clean();
if( PerRequest ) {
conn.close();
}
}
if( PlayVideo ) {
bool no_data_ignore = false;
std::string VideoBuf;
ss.canRead();
switch (ss.ready()) {
case -1:
std::cerr << "Buffer socket is disconnected\n";
break;
case 0://not ready
no_data_ignore = true;
break;
default:
///\todo Make it work!
DTSC::Stream ds;
ss.spool();
if (ds.parsePacket(ss.Received())){
VideoBuf = ds.lastData();
}else{
std::cerr << "Failed to parse packet" << std::endl;
no_data_ignore = true;//perhaps corrupt?
}
break;
}
if(no_data_ignore){}else if( VideoBuf == "" ) {
//videobuffer is empty, no more data.
jrtplib::RTPTime delay = jrtplib::RTPTime(10.0);
VideoSession.BYEDestroy(delay,"Out of data",11);
conn.close();
std::cerr << "Buffer empty - closing connection" << std::endl;
} else {
//Send a single NALU (H264 block) here.
VideoSession.SendPacket( VideoBuf.c_str(), VideoBuf.size(), 98, false, ( 1.0 / 29.917 ) * 90000 );
//we can add delays here as follows:
//don't know if these are nescecary or not, but good for testing nonetheless
// jrtplib::RTPTime delay( ( 1.0 / 29.917 ) * 90000 );
// jrtplib::RTPTime::Wait( delay );
}
}
}
return 0;
}
//Set Default Port
#define DEFAULT_PORT 554
//Set the function that should be forked for each client
#define MAINHANDLER RTSP_Handler
//Set the section in the Config file, though we will not use this yet
#define CONFIGSECT RTSP
//Include the main functionality, as well as fork support and everything.
#include "../util/server_setup.cpp"

View file

@ -1,9 +0,0 @@
#include <jrtplib3/rtpsession.h>
#include <jrtplib3/rtppacket.h>
#include <jrtplib3/rtpudpv4transmitter.h>
#include <jrtplib3/rtpudpv6transmitter.h>
#include <jrtplib3/rtpipv4address.h>
#include <jrtplib3/rtpipv6address.h>
#include <jrtplib3/rtpsessionparams.h>
#include <jrtplib3/rtperrors.h>

View file

@ -1,79 +0,0 @@
Port 554 TCP
RTSP/1.0 xxx reason
100 Continue
200 OK
300 Multiple Choices
301 Moved Permanently
303 See Other
400 Bad Request
500 Internal Server Error
501 Not Implemented
Need to support:
Connection: keep-alive
Content-Length: 0 (default)
Content-Type: ran/dom
Content-Language: en
Content-Encoding: leave out!
Transport: RTP/AVP;unicast;client_port=4588-4589;server_port=6256-6257
Public: SETUP, TEARDOWN, OPTIONS, DESCRIBE, PLAY
RTP-Info: url=rtmp://localhost/blaat
Unsupported: random (reply with same as require header!)
Session: ignore!
Transport: RTP/AVP;unicast;client_port=4588-4589
Require: random
SETUP:
SETUP rtsp://localhost/blaat RTSP/1.0
Transport: RTP/AVP;unicast;client_port=4588-4589
RTSP/1.0 200 OK
Transport: RTP/AVP;unicast;client_port=4588-4589;server_port=6256-6257
TEARDOWN:
TEARDOWN rtsp://localhost/blaat RTSP/1.0
RTSP/1.0 200 OK
OPTIONS:
OPTIONS * RTSP/1.0
Require: koekjes
RTSP/1.0 200 OK
Unsupported: koekjes
Public: SETUP, TEARDOWN, OPTIONS, DESCRIBE, PLAY
DESCRIBE:
DESCRIBE rtsp://server.example.com/fizzle/foo RTSP/1.0
Accept: application/sdp, application/rtsl, application/mheg
RTSP/1.0 200 OK
Content-Type: application/sdp
Content-Length: xxx
v=0
o=- 0 0 IN IP4 ddvtech.com
s=PLSServer
c=IN IP4 0.0.0.0
a=recvonly
t=0 0
m=video 0 RTP/AVP 98
a=rtpmap:98 H264/90000
m=audio 0 RTP/AVP 99
a=rtpmap:99 MPEG4-GENERIC/11025/1
PLAY:
PLAY rtsp://audio.example.com/meeting.en RTSP/1.0
Range: clock=19961108T142300Z-19961108T143520Z
RTSP/1.0 200 OK
jRTPlib docs: http://research.edm.uhasselt.be/jori/jrtplib/documentation/index.html

View file

@ -1,26 +0,0 @@
SRC = main.cpp ../util/socket.cpp ../util/http_parser.cpp ../util/flv_tag.cpp ../util/amf.cpp ../util/dtsc.cpp ../util/config.cpp ../util/base64.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

View file

@ -1,364 +0,0 @@
/// \file Connector_TS/main.cpp
/// Contains the main code for the TS Connector
/// \todo Check data to be sent for video
/// \todo Handle audio packets
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <getopt.h>
#include <iostream>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/epoll.h>
#include "../util/socket.h"
#include "../util/dtsc.h"
/// A simple class to create a single Transport Packet
class Transport_Packet {
public:
Transport_Packet( bool PacketStart = false, int PID = 0x100 );
void SetPayload( char * Payload, int PayloadLen, int Offset = 13 );
void SetPesHeader( int Offset = 4, int MsgLen = 0xFFFF, int Current = 0, int Previous = 0 );
void Write( );
void Write( Socket::Connection conn );
void SetContinuityCounter( int Counter );
void SetMessageLength( int MsgLen );
void SetAdaptationField( double TimeStamp = 0 );
void CreatePAT( int ContinuityCounter );
void CreatePMT( int ContinuityCounter );
private:
int PID;///< PID of this packet
char Buffer[188];///< The actual data
};//Transport Packet
/// Get the current time in milliseconds
/// \return Current time in milliseconds
unsigned int getNowMS() {
timeval t;
gettimeofday(&t, 0);
return t.tv_sec + t.tv_usec/1000;
}
/// The constructor
/// \param PacketStart Start of a new sequence
/// \param PID The PID for this packet
Transport_Packet::Transport_Packet( bool PacketStart, int PID ) {
(*this).PID = PID;
Buffer[0] = (char)0x47;
Buffer[1] = ( PacketStart ? (char)0x40 : 0 ) + (( PID & 0xFF00 ) >> 8 );
Buffer[2] = ( PID & 0x00FF );
Buffer[3] = (char)0x10;
}
/// Sets the length of the message
/// \param MsgLen the new length of the message
void Transport_Packet::SetMessageLength( int MsgLen ) {
Buffer[8] = ( MsgLen & 0xFF00 ) >> 8;
Buffer[9] = ( MsgLen & 0xFF );
}
/// Sets the Continuity Counter of a packet
/// \param Counter The new Continuity Counter
void Transport_Packet::SetContinuityCounter( int Counter ) {
Buffer[3] = ( Buffer[3] & 0xF0 ) + ( Counter & 0x0F );
}
/// Writes a PES header with length and PTS/DTS
/// \param Offset Offset of the PES header in the packet
/// \param MsgLen Length of the PES data
/// \param Current The PTS of this PES packet
/// \param Previous The DTS of this PES packet
void Transport_Packet::SetPesHeader( int Offset, int MsgLen, int Current, int Previous ) {
Current = Current * 27000;
Previous = Previous * 27000;
Buffer[Offset] = (char)0x00;
Buffer[Offset+1] = (char)0x00;
Buffer[Offset+2] = (char)0x01;
Buffer[Offset+3] = (char)0xE0;
Buffer[Offset+4] = ( MsgLen & 0xFF00 ) >> 8;
Buffer[Offset+5] = ( MsgLen & 0x00FF );
Buffer[Offset+6] = (char)0x80;
Buffer[Offset+7] = (char)0xC0;
Buffer[Offset+8] = (char)0x0A;
Buffer[Offset+9] = (char)0x30 + ( (Current & 0xC0000000 ) >> 29 ) + (char)0x01;
Buffer[Offset+10] = ( ( ( Current & 0x3FFF8000 ) >> 14 ) & 0xFF00 ) >> 8;
Buffer[Offset+11] = ( ( ( Current & 0x3FFF8000 ) >> 14 ) & 0x00FF ) + (char)0x01;
Buffer[Offset+12] = ( ( ( Current & 0x00007FFF ) << 1 ) & 0xFF00 ) >> 8;
Buffer[Offset+13] = ( ( ( Current & 0x00007FFF ) << 1 ) & 0x00FF ) + (char)0x01;
Buffer[Offset+14] = (char)0x10 + ( (Previous & 0xC0000000 ) >> 29 ) + (char)0x01;
Buffer[Offset+15] = ( ( ( Previous & 0x3FFF8000 ) >> 14 ) & 0xFF00 ) >> 8;
Buffer[Offset+16] = ( ( ( Previous & 0x3FFF8000 ) >> 14 ) & 0x00FF ) + (char)0x01;
Buffer[Offset+17] = ( ( ( Previous & 0x00007FFF ) << 1 ) & 0xFF00 ) >> 8;
Buffer[Offset+18] = ( ( ( Previous & 0x00007FFF ) << 1 ) & 0x00FF ) + (char)0x01;
}
/// Creates an adapatation field
/// \param TimeStamp the current PCR
void Transport_Packet::SetAdaptationField( double TimeStamp ) {
TimeStamp = TimeStamp * 27000;
int Extension = (int)TimeStamp % 300;
int Base = (int)TimeStamp / 300;
Buffer[3] = ( Buffer[3] & 0x0F ) + 0x30;
Buffer[4] = (char)0x07;
Buffer[5] = (char)0x10;
Buffer[6] = ( ( Base >> 1 ) & 0xFF000000 ) >> 24;
Buffer[7] = ( ( Base >> 1 ) & 0x00FF0000 ) >> 16;
Buffer[8] = ( ( Base >> 1 ) & 0x0000FF00 ) >> 8;
Buffer[9] = ( ( Base >> 1 ) & 0x000000FF );
Buffer[10] = ( ( Extension & 0x0100) >> 8 ) + ( ( Base & 0x00000001 ) << 7 ) + (char)0x7E;
Buffer[11] = ( Extension & 0x00FF);
}
/// Writes data into the payload of our packet
/// The data to be written is of lenght min( PayLoadLen, 188 - Offset )
/// \param Payload The data to write
/// \param PayLoadLen The length of the data
/// \param Offset The offset in the packet payload
void Transport_Packet::SetPayload( char * Payload, int PayloadLen, int Offset ) {
memcpy( &Buffer[Offset], Payload, std::min( PayloadLen, 188-Offset ) );
}
/// Creates a default PAT packet
/// Sets up the complete packet
/// \param ContinuityCounter The Continuity Counter for this packet
void Transport_Packet::CreatePAT( int ContinuityCounter ) {
Buffer[3] = (char)0x10 + ContinuityCounter;
Buffer[4] = (char)0x00;
Buffer[5] = (char)0x00;
Buffer[6] = (char)0xB0;
Buffer[7] = (char)0x0D;
Buffer[8] = (char)0x00;
Buffer[9] = (char)0x01;
Buffer[10] = (char)0xC1;
Buffer[11] = (char)0x00;
Buffer[12] = (char)0x00;
Buffer[13] = (char)0x00;
Buffer[14] = (char)0x01;
Buffer[15] = (char)0xF0;
Buffer[16] = (char)0x00;
Buffer[17] = (char)0x2A;
Buffer[18] = (char)0xB1;
Buffer[19] = (char)0x04;
Buffer[20] = (char)0xB2;
for(int i = 21; i < 188; i++ ) {
Buffer[i] = (char)0xFF;
}
}
/// Creates a default PMT packet
/// Sets up the complete packet
/// \param ContinuityCounter The Continuity Counter for this packet
void Transport_Packet::CreatePMT( int ContinuityCounter ) {
Buffer[3] = (char)0x10 + ContinuityCounter;
Buffer[4] = (char)0x00;
Buffer[5] = (char)0x02;
Buffer[6] = (char)0xB0;
Buffer[7] = (char)0x17;
Buffer[8] = (char)0x00;
Buffer[9] = (char)0x01;
Buffer[10] = (char)0xC1;
Buffer[11] = (char)0x00;
Buffer[12] = (char)0x00;
Buffer[13] = (char)0xE1;
Buffer[14] = (char)0x00;
Buffer[15] = (char)0xF0;
Buffer[16] = (char)0x00;
Buffer[17] = (char)0x1B;
Buffer[18] = (char)0xE1;
Buffer[19] = (char)0x00;
Buffer[20] = (char)0xF0;
Buffer[21] = (char)0x00;
Buffer[22] = (char)0x03;
Buffer[23] = (char)0xE1;
Buffer[24] = (char)0x01;
Buffer[25] = (char)0xF0;
Buffer[26] = (char)0x00;
Buffer[27] = (char)0x4E;
Buffer[28] = (char)0x59;
Buffer[29] = (char)0x3D;
Buffer[30] = (char)0x1E;
for(int i = 31; i < 188; i++ ) {
Buffer[i] = (char)0xFF;
}
}
/// Sends a default PAT
/// \param conn The connection with the client
void SendPAT( Socket::Connection conn ) {
static int ContinuityCounter = 0;
Transport_Packet TS;
TS = Transport_Packet( true, 0 );
TS.CreatePAT( ContinuityCounter );
TS.Write( conn );
ContinuityCounter = ( ContinuityCounter + 1 ) & 0x0F;
}
/// Sends a default PMT
/// \param conn The connection with the client
void SendPMT( Socket::Connection conn ) {
static int ContinuityCounter = 0;
Transport_Packet TS;
TS = Transport_Packet( true, 0x1000 );
TS.CreatePMT( ContinuityCounter );
TS.Write( conn );
ContinuityCounter = ( ContinuityCounter + 1 ) & 0x0F;
}
/// Wraps one or more NALU packets into transport packets
/// \param tag The FLV Tag
std::vector<Transport_Packet> WrapNalus( DTSC::DTMI Tag ) {
static int ContinuityCounter = 0;
static int Previous_Tag = 0;
static int First_PCR = getNowMS();
static int Previous_PCR = 0;
static char LeadIn[4] = { (char)0x00, (char)0x00, (char)0x00, (char)0x001 };
int Current_PCR;
int Current_Tag;
std::string Data = Tag.getContentP("data")->StrValue();
int Offset = 0;
Transport_Packet TS;
int Sent = 0;
int PacketAmount = ceil( ( ( Data.size() - (188 - 35 ) ) / 184 ) + 1 );//Minus first packet, + round up and first packet.
std::vector<Transport_Packet> Result;
TS = Transport_Packet( true, 0x100 );
TS.SetContinuityCounter( ContinuityCounter );
ContinuityCounter = ( ( ContinuityCounter + 1 ) & 0x0F );
Current_PCR = getNowMS();
Current_Tag = Tag.getContentP("time")->NumValue();
if( true ) { //Current_PCR - Previous_PCR >= 1 ) {
TS.SetAdaptationField( Current_PCR - First_PCR );
Offset = 8;
Previous_PCR = Current_PCR;
}
TS.SetPesHeader( 4 + Offset, Data.size() , Current_Tag, Previous_Tag );
Previous_Tag = Current_Tag;
TS.SetPayload( LeadIn, 4, 23 + Offset );
TS.SetPayload( &Data[16], 157 - Offset, 27 + Offset );
Sent = 157 - Offset;
Result.push_back( TS );
while( Sent + 176 < Data.size() ) {
// for( int i = 0; i < (PacketAmount - 1); i++ ) {
TS = Transport_Packet( false, 0x100 );
TS.SetContinuityCounter( ContinuityCounter );
ContinuityCounter = ( ( ContinuityCounter + 1 ) & 0x0F );
Current_PCR = getNowMS();
Offset = 0;
if( true ) { //Current_PCR - Previous_PCR >= 1 ) {
TS.SetAdaptationField( Current_PCR - First_PCR );
Offset = 8;
Previous_PCR = Current_PCR;
}
TS.SetPayload( &Data[16 + Sent], 184 - Offset, 4 + Offset );
Sent += 184 - Offset;
Result.push_back( TS );
}
if( Sent < ( Data.size() ) ) {
Current_PCR = getNowMS();
Offset = 0;
if( true ) { //now - Previous_PCR >= 5 ) {
TS.SetAdaptationField( Current_PCR - First_PCR );
Offset = 8;
Previous_PCR = Current_PCR;
}
std::cerr << "Wrapping packet: last packet length\n";
std::cerr << "\tTotal:\t\t" << Data.size() << "\n";
std::cerr << "\tSent:\t\t" << Sent << "\n";
int To_Send = ( Data.size() ) - Sent;
std::cerr << "\tTo Send:\t" << To_Send << "\n";
std::cerr << "\tStuffing:\t" << 176 - To_Send << "\n";
char Stuffing = (char)0xFF;
for( int i = 0; i < ( 176 - To_Send ); i++ ) {
TS.SetPayload( &Stuffing, 1, 4 + Offset + i );
}
TS.SetPayload( &Data[16 + Sent], 176 - To_Send , 4 + Offset + ( 176 - To_Send ) );
Result.push_back( TS );
}
return Result;
}
/// Writes a packet to STDOUT
void Transport_Packet::Write( ) {
for( int i = 0; i < 188; i++ ) { std::cout << Buffer[i]; }
}
/// Writes a packet onto a connection
/// \param conn The connection with the client
void Transport_Packet::Write( Socket::Connection conn ) {
// conn.write( Buffer, 188 );
for( int i = 0; i < 188; i++ ) { std::cout << Buffer[i]; }
}
/// The main function of the connector
/// \param conn A connection with the client
int TS_Handler( Socket::Connection conn ) {
DTSC::Stream stream;
// FLV::Tag tag;///< Temporary tag buffer for incoming video data.
bool inited = false;
bool firstvideo = true;
Socket::Connection ss(-1);
int zet = 0;
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:
ss.spool();
if ( stream.parsePacket( ss.Received() ) ) {
if( stream.lastType() == DTSC::VIDEO ) {
fprintf(stderr, "Video contains NALU\n" );
SendPAT( conn );
SendPMT( conn );
std::vector<Transport_Packet> AllNalus = WrapNalus( stream.getPacket(0) );
for( int i = 0; i < AllNalus.size( ); i++ ) {
AllNalus[i].Write( conn );
}
std::cerr << "Item: " << ++zet << "\n";
}
if( stream.lastType() == DTSC::AUDIO ) {
// if( ( tag.data[ 11 ] == 0xAF ) && ( tag.data[ 12 ] == 0x01 ) ) {
fprintf(stderr, "Audio Contains Raw AAC\n");
// }
}
}
break;
}
}
return 0;
}
#define DEFAULT_PORT 8888
#define MAINHANDLER TS_Handler
#define CONFIGSECT TS
#include "../util/server_setup.cpp"

View file

@ -1,30 +0,0 @@
SRC = main.cpp ../util/json.cpp ../util/socket.cpp ../util/http_parser.cpp ../util/md5.cpp ../util/config.cpp ../util/procs.cpp ../util/base64.cpp ../util/auth.cpp
OBJ = $(SRC:.cpp=.o)
OUT = MistController
INCLUDES =
DEBUG = 4
OPTIMIZE = -g
VERSION = `git describe --tags`
COMPILED_USERNAME = testuser
COMPILED_PASSWORD = 179ad45c6ce2cb97cf1029e212046e81
#COMPILED_PASSWORD = testpass
CCFLAGS = -Wall -Wextra -funsigned-char $(OPTIMIZE) -DDEBUG=$(DEBUG) -DCOMPILED_USERNAME=$(COMPILED_USERNAME) -DCOMPILED_PASSWORD=$(COMPILED_PASSWORD) -DVERSION=$(VERSION)
INSTALL = install
CC = $(CROSS)g++
LD = $(CROSS)ld
AR = $(CROSS)ar
LIBS = -lssl -lcrypto
.SUFFIXES: .cpp
.PHONY: clean default
default: cversion $(OUT)
.cpp.o:
$(CC) $(INCLUDES) $(CCFLAGS) -c $< -o $@
$(OUT): $(OBJ)
$(CC) -o ../bin/$(OUT) $(OBJ) $(LIBS)
clean:
rm -rf $(OBJ) ../bin/$(OUT) Makefile.bak *~
cversion:
rm -rf ../util/config.o
install: $(OUT)
$(INSTALL) -D ./$(OUT) $(DESTDIR)/usr/bin/$(OUT)

View file

@ -1,38 +0,0 @@
default: client
.PHONY: client client-debug client-clean clean release-install debug-install install docs
prepare:
mkdir -p ./bin
cp -f *.html ./bin/
client-debug: prepare
cd Connector_HTTP; $(MAKE)
cd Connector_RTMP; $(MAKE)
cd Connector_RAW; $(MAKE)
cd Buffer; $(MAKE)
cd Controller; $(MAKE)
cd tools/FLV2DTSC; $(MAKE)
client: client-debug
client-clean:
cd Connector_HTTP; $(MAKE) clean
cd Connector_RTMP; $(MAKE) clean
cd Connector_RAW; $(MAKE) clean
cd Buffer; $(MAKE) clean
cd Controller; $(MAKE) clean
cd tools/FLV2DTSC; $(MAKE) clean
clean: client-clean
rm -rf ./bin
client-release: prepare
cd Connector_HTTP; $(MAKE) DEBUG=0 OPTIMIZE=-O2
cd Connector_RTMP; $(MAKE) DEBUG=0 OPTIMIZE=-O2
cd Connector_RAW; $(MAKE) DEBUG=0 OPTIMIZE=-O2
cd Buffer; $(MAKE) DEBUG=0 OPTIMIZE=-O2
cd Controller; $(MAKE) DEBUG=0 OPTIMIZE=-O2
cd tools/FLV2DTSC; $(MAKE) DEBUG=0 OPTIMIZE=-O2
release: client-release
release-install: client-clean client-release
cp ./bin/Mist* /usr/bin/
debug-install: client-clean client-debug
cp ./bin/Mist* /usr/bin/
install: debug-install
docs:
doxygen ./Doxyfile > /dev/null

2
Makefile.am Normal file
View file

@ -0,0 +1,2 @@
SUBDIRS=lib src
EXTRA_DIST=server.html

39
configure.ac Normal file
View file

@ -0,0 +1,39 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.60])
m4_include([version.m4])
AC_INIT(MistServer, VERSION_NUMBER, contact@ddvtech.com)
AC_CONFIG_SRCDIR([src/buffer.cpp])
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
# Checks for libraries.
AC_PROG_RANLIB
# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_INT32_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([dup2 gettimeofday memset mkdir socket strerror])
AC_CONFIG_FILES([Makefile
lib/Makefile
src/Makefile])
AC_OUTPUT

15
lib/Makefile.am Normal file
View file

@ -0,0 +1,15 @@
noinst_LIBRARIES=libamf.a libauth.a libbase64.a libconfig.a libcrypto.a libdtsc.a libflv_tag.a libhttp_parser.a libjson.a libmd5.a libprocs.a librtmpchunks.a libsocket.a libtinythread.a
libamf_a_SOURCES=amf.h amf.cpp
libauth_a_SOURCES=auth.h auth.cpp
libbase64_a_SOURCES=base64.h base64.cpp
libconfig_a_SOURCES=config.h config.cpp
libcrypto_a_SOURCES=crypto.h crypto.cpp
libdtsc_a_SOURCES=dtsc.h dtsc.cpp
libflv_tag_a_SOURCES=flv_tag.h flv_tag.cpp
libhttp_parser_a_SOURCES=http_parser.h http_parser.cpp
libjson_a_SOURCES=json.h json.cpp
libmd5_a_SOURCES=md5.h md5.cpp
libprocs_a_SOURCES=procs.h procs.cpp
librtmpchunks_a_SOURCES=rtmpchunks.h rtmpchunks.cpp
libsocket_a_SOURCES=socket.h socket.cpp
libtinythread_a_SOURCES=tinythread.h tinythread.cpp

View file

@ -53,7 +53,7 @@ void Util::Config::parseArgs(int argc, char ** argv){
case 'd': daemon_mode = true; break; case 'd': daemon_mode = true; break;
case 'u': username = optarg; break; case 'u': username = optarg; break;
case 'v': case 'v':
printf("%s\n", TOSTRING(VERSION)); printf("%s\n", TOSTRING(PACKAGE_VERSION));
exit(1); exit(1);
break; break;
case 'h': case 'h':
@ -63,7 +63,7 @@ void Util::Config::parseArgs(int argc, char ** argv){
printf("Options: -h[elp], -?, -v[ersion], -n[odaemon], -d[aemon], -p[ort] VAL, -i[nterface] VAL, -u[sername] VAL\n"); printf("Options: -h[elp], -?, -v[ersion], -n[odaemon], -d[aemon], -p[ort] VAL, -i[nterface] VAL, -u[sername] VAL\n");
printf("Defaults:\n interface: %s\n port: %i\n daemon mode: %s\n username: %s\n", interface.c_str(), listen_port, doingdaemon.c_str(), username.c_str()); printf("Defaults:\n interface: %s\n port: %i\n daemon mode: %s\n username: %s\n", interface.c_str(), listen_port, doingdaemon.c_str(), username.c_str());
printf("Username root means no change to UID, no matter what the UID is.\n"); printf("Username root means no change to UID, no matter what the UID is.\n");
printf("This is %s version %s\n", argv[0], TOSTRING(VERSION)); printf("This is %s version %s\n", argv[0], TOSTRING(PACKAGE_VERSION));
exit(1); exit(1);
break; break;
} }

13
src/Makefile.am Normal file
View file

@ -0,0 +1,13 @@
outdir=../bin
out_PROGRAMS=MistBuffer MistController MistConnRAW MistConnRTMP MistConnHTTP
AM_LDFLAGS=-L../lib
MistBuffer_SOURCES=buffer.cpp buffer_stats.cpp buffer_user.cpp buffer_stream.cpp
MistBuffer_LDADD=-ljson -lsocket -ldtsc -ltinythread -lpthread
MistController_SOURCES=controller.cpp
MistController_LDADD=-ljson -lsocket -lprocs -lmd5 -lconfig -lhttp_parser -lauth -lbase64 -lssl -lcrypto
MistConnRAW_SOURCES=conn_raw.cpp
MistConnRAW_LDADD=-lsocket
MistConnRTMP_SOURCES=conn_rtmp.cpp
MistConnRTMP_LDADD=-lsocket -ldtsc -lrtmpchunks -lflv_tag -lconfig -lamf -lssl -lcrypto
MistConnHTTP_SOURCES=conn_http.cpp
MistConnHTTP_LDADD=-lsocket

View file

@ -12,7 +12,7 @@
#include <signal.h> #include <signal.h>
#include <sstream> #include <sstream>
#include <sys/time.h> #include <sys/time.h>
#include "stream.h" #include "buffer_stream.h"
/// Holds all code unique to the Buffer. /// Holds all code unique to the Buffer.
namespace Buffer{ namespace Buffer{

View file

@ -1,4 +1,4 @@
#include "stats.h" #include "buffer_stats.h"
#include <stdlib.h> //for atoi() #include <stdlib.h> //for atoi()
Buffer::Stats::Stats(){ Buffer::Stats::Stats(){

View file

@ -1,4 +1,4 @@
#include "stream.h" #include "buffer_stream.h"
/// Stores the globally equal reference. /// Stores the globally equal reference.
Buffer::Stream * Buffer::Stream::ref = 0; Buffer::Stream * Buffer::Stream::ref = 0;

View file

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <string> #include <string>
#include "../util/tinythread.h" #include "../lib/tinythread.h"
#include "../util/json.h" #include "../lib/json.h"
#include "user.h" #include "buffer_user.h"
namespace Buffer{ namespace Buffer{
class Stream{ class Stream{

View file

@ -1,5 +1,5 @@
#include "user.h" #include "buffer_user.h"
#include "stream.h" #include "buffer_stream.h"
#include <sstream> #include <sstream>
int Buffer::user::UserCount = 0; int Buffer::user::UserCount = 0;

View file

@ -1,9 +1,9 @@
#pragma once #pragma once
#include <string> #include <string>
#include "stats.h" #include "buffer_stats.h"
#include "../util/dtsc.h" #include "../lib/dtsc.h"
#include "../util/socket.h" #include "../lib/socket.h"
#include "../util/tinythread.h" #include "../lib/tinythread.h"
namespace Buffer{ namespace Buffer{
/// Holds connected users. /// Holds connected users.

View file

@ -11,14 +11,13 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <getopt.h> #include <getopt.h>
#include <ctime> #include <ctime>
#include "../util/socket.h" #include "../lib/socket.h"
#include "../util/http_parser.h" #include "../lib/http_parser.h"
#include "../util/json.h" #include "../lib/json.h"
#include "../util/dtsc.h" #include "../lib/dtsc.h"
#include "../util/flv_tag.h" #include "../lib/flv_tag.h"
#include "../util/MP4/interface.cpp" #include "../lib/base64.h"
#include "../util/base64.h" #include "../lib/amf.h"
#include "../util/amf.h"
/// Holds everything unique to HTTP Connector. /// Holds everything unique to HTTP Connector.
namespace Connector_HTTP{ namespace Connector_HTTP{
@ -29,7 +28,18 @@ namespace Connector_HTTP{
std::queue<std::string> Flash_FragBuffer;///<Fragment buffer for F4V std::queue<std::string> Flash_FragBuffer;///<Fragment buffer for F4V
DTSC::Stream Strm;///< Incoming stream buffer. DTSC::Stream Strm;///< Incoming stream buffer.
HTTP::Parser HTTP_R, HTTP_S;///<HTTP Receiver en HTTP Sender. HTTP::Parser HTTP_R, HTTP_S;///<HTTP Receiver en HTTP Sender.
/// Folds data into a mdat container and returns it.
std::string mdatFold(std::string data){
std::string Result;
unsigned int t_int;
t_int = htonl(data.size()+8);
Result.append((char*)&t_int, 4);
t_int = htonl(0x6D646174);
Result.append((char*)&t_int, 4);
Result.append(data);
return Result;
}
/// Returns AMF-format metadata for Adobe HTTP Dynamic Streaming. /// Returns AMF-format metadata for Adobe HTTP Dynamic Streaming.
std::string GetMetaData( ) { std::string GetMetaData( ) {
@ -269,7 +279,7 @@ namespace Connector_HTTP{
if ((Flash_RequestPending > 0) && !Flash_FragBuffer.empty()){ if ((Flash_RequestPending > 0) && !Flash_FragBuffer.empty()){
HTTP_S.Clean(); HTTP_S.Clean();
HTTP_S.SetHeader("Content-Type","video/mp4"); HTTP_S.SetHeader("Content-Type","video/mp4");
HTTP_S.SetBody(Interface::mdatFold(Flash_FragBuffer.front())); HTTP_S.SetBody(mdatFold(Flash_FragBuffer.front()));
Flash_FragBuffer.pop(); Flash_FragBuffer.pop();
HTTP_S.SendResponse(conn, "200", "OK");//schrijf de HTTP response header HTTP_S.SendResponse(conn, "200", "OK");//schrijf de HTTP response header
Flash_RequestPending--; Flash_RequestPending--;
@ -323,4 +333,4 @@ namespace Connector_HTTP{
#define DEFAULT_PORT 8080 #define DEFAULT_PORT 8080
#define MAINHANDLER Connector_HTTP::Connector_HTTP #define MAINHANDLER Connector_HTTP::Connector_HTTP
#define CONFIGSECT HTTP #define CONFIGSECT HTTP
#include "../util/server_setup.cpp" #include "server_setup.cpp"

View file

@ -2,7 +2,7 @@
/// Contains the main code for the RAW connector. /// Contains the main code for the RAW connector.
#include <iostream> #include <iostream>
#include "../util/socket.h" #include "../lib/socket.h"
/// Contains the main code for the RAW connector. /// Contains the main code for the RAW connector.
/// Expects a single commandline argument telling it which stream to connect to, /// Expects a single commandline argument telling it which stream to connect to,

View file

@ -11,10 +11,10 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <getopt.h> #include <getopt.h>
#include <sstream> #include <sstream>
#include "../util/socket.h" #include "../lib/socket.h"
#include "../util/flv_tag.h" #include "../lib/flv_tag.h"
#include "../util/amf.h" #include "../lib/amf.h"
#include "../util/rtmpchunks.h" #include "../lib/rtmpchunks.h"
/// Holds all functions and data unique to the RTMP Connector /// Holds all functions and data unique to the RTMP Connector
namespace Connector_RTMP{ namespace Connector_RTMP{
@ -505,4 +505,4 @@ void Connector_RTMP::parseAMFCommand(AMF::Object & amfdata, int messagetype, int
#define DEFAULT_PORT 1935 #define DEFAULT_PORT 1935
#define MAINHANDLER Connector_RTMP::Connector_RTMP #define MAINHANDLER Connector_RTMP::Connector_RTMP
#define CONFIGSECT RTMP #define CONFIGSECT RTMP
#include "../util/server_setup.cpp" #include "server_setup.cpp"

View file

@ -21,13 +21,13 @@
#include <sys/types.h> #include <sys/types.h>
#include <signal.h> #include <signal.h>
#include <sstream> #include <sstream>
#include "../util/socket.h" #include "../lib/socket.h"
#include "../util/http_parser.h" #include "../lib/http_parser.h"
#include "../util/md5.h" #include "../lib/md5.h"
#include "../util/json.h" #include "../lib/json.h"
#include "../util/procs.h" #include "../lib/procs.h"
#include "../util/config.h" #include "../lib/config.h"
#include "../util/auth.h" #include "../lib/auth.h"
#define UPLINK_INTERVAL 30 #define UPLINK_INTERVAL 30
@ -209,7 +209,7 @@ void CheckConfig(JSON::Value & in, JSON::Value & out){
} }
} }
out = in; out = in;
out["version"] = TOSTRING(VERSION); out["version"] = TOSTRING(PACKAGE_VERSION);
} }
bool streamsEqual(JSON::Value & one, JSON::Value & two){ bool streamsEqual(JSON::Value & one, JSON::Value & two){

View file

@ -15,8 +15,8 @@
#endif #endif
#include "socket.h" //Socket library #include "../lib/socket.h" //Socket library
#include "config.h" //utilities for config management #include "../lib/config.h" //utilities for config management
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#include <pwd.h> #include <pwd.h>

View file

@ -1,19 +0,0 @@
SRC = main.cpp
OBJ = $(SRC:.cpp=.o)
OUT = Box_Parser
INCLUDES =
CCFLAGS = -Wall -Wextra -funsigned-char -g
CC = $(CROSS)g++
LD = $(CROSS)ld
AR = $(CROSS)ar
LIBS = -lssl -lcrypto
.SUFFIXES: .cpp
.PHONY: clean default
default: $(OUT)
.cpp.o:
$(CC) $(INCLUDES) $(CCFLAGS) -c $< -o $@
$(OUT): $(OBJ)
$(CC) $(LIBS) -o $(OUT) $(OBJ)
clean:
rm -rf $(OBJ) $(OUT) Makefile.bak *~

View file

@ -1,19 +0,0 @@
SRC = main.cpp ../../util/amf.cpp
OBJ = $(SRC:.cpp=.o)
OUT = AMFtest
INCLUDES =
CCFLAGS = -Wall -Wextra -funsigned-char -g
CC = $(CROSS)g++
LD = $(CROSS)ld
AR = $(CROSS)ar
LIBS = -lssl -lcrypto
.SUFFIXES: .cpp
.PHONY: clean default
default: $(OUT)
.cpp.o:
$(CC) $(INCLUDES) $(CCFLAGS) -c $< -o $@
$(OUT): $(OBJ)
$(CC) $(LIBS) -o $(OUT) $(OBJ)
clean:
rm -rf $(OBJ) $(OUT) Makefile.bak *~

View file

@ -1,23 +0,0 @@
SRC = main.cpp ../../util/flv_tag.cpp ../../util/dtsc.cpp ../../util/amf.cpp ../../util/socket.cpp
OBJ = $(SRC:.cpp=.o)
OUT = DDV_DTSC2FLV
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)
cp -f ./$(OUT) /usr/bin/

View file

@ -1,23 +0,0 @@
SRC = main.cpp ../../util/dtsc.cpp
OBJ = $(SRC:.cpp=.o)
OUT = DTSC_Info
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)
cp -f ./$(OUT) /usr/bin/

View file

@ -1,20 +0,0 @@
SRC = main.cpp ../../util/flv_tag.cpp ../../util/dtsc.cpp ../../util/amf.cpp ../../util/socket.cpp
OBJ = $(SRC:.cpp=.o)
OUT = MistFLV2DTSC
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 ../../bin/$(OUT) $(OBJ)
clean:
rm -rf $(OBJ) ../../bin/$(OUT) Makefile.bak *~

View file

@ -1,23 +0,0 @@
SRC = main.cpp ../../util/flv_tag.cpp ../../util/dtsc.cpp ../../util/amf.cpp ../../util/socket.cpp
OBJ = $(SRC:.cpp=.o)
OUT = FLV_Info
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)
cp -f ./$(OUT) /usr/bin/

View file

@ -1,19 +0,0 @@
SRC = main.cpp ../../util/flv_tag.cpp ../../util/http_parser.cpp ../../util/socket.cpp
OBJ = $(SRC:.cpp=.o)
OUT = Box_Parser
INCLUDES =
CCFLAGS = -Wall -Wextra -funsigned-char -g
CC = $(CROSS)g++
LD = $(CROSS)ld
AR = $(CROSS)ar
LIBS = -lssl -lcrypto
.SUFFIXES: .cpp
.PHONY: clean default
default: $(OUT)
.cpp.o:
$(CC) $(INCLUDES) $(CCFLAGS) -c $< -o $@
$(OUT): $(OBJ)
$(CC) $(LIBS) -o $(OUT) $(OBJ)
clean:
rm -rf $(OBJ) $(OUT) Makefile.bak *~

View file

@ -1,20 +0,0 @@
SRC = main.cpp ../../util/amf.cpp ../../util/rtmpchunks.cpp ../../util/crypto.cpp ../../util/flv_tag.cpp ../../util/socket.cpp ../../util/dtsc.cpp
OBJ = $(SRC:.cpp=.o)
OUT = RTMP_Parser
INCLUDES =
STATIC =
CCFLAGS = -Wall -Wextra -funsigned-char -g
CC = $(CROSS)g++
LD = $(CROSS)ld
AR = $(CROSS)ar
LIBS = -lssl -lcrypto
.SUFFIXES: .cpp
.PHONY: clean default
default: $(OUT)
.cpp.o:
$(CC) $(INCLUDES) $(CCFLAGS) -c $< -o $@
$(OUT): $(OBJ)
$(CC) -o $(OUT) $(OBJ) $(STATIC) $(LIBS)
clean:
rm -rf $(OBJ) $(OUT) Makefile.bak *~

View file

@ -1,20 +0,0 @@
SRC = main.cpp ../../util/util.cpp
OBJ = $(SRC:.cpp=.o)
OUT = spawntest
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 *~

View file

@ -1,26 +0,0 @@
/// \file spawntest/main.cpp
/// Contains a testing program for the Util::Proc utility class.
#include <iostream>
#include <string>
#include "../../util/util.h" //Process utility
/// Sleeps a maximum of five seconds, each second being interruptable by a signal.
void sleepFive(){
sleep(1); sleep(1); sleep(1); sleep(1); sleep(1);
}
/// Testing program for Util::Proc utility class.
int main(){
Util::Procs::Start("number1", "./test.sh Koekjes");
sleepFive();
Util::Procs::Start("number2", "./testpipein.sh", "./testpipeout.sh");
sleepFive();
Util::Procs::Start("number3", "./infitest.sh");
sleepFive();
Util::Procs::Stop("number3");
Util::Procs::Start("number4", "./infitest.sh", "./testpipeout.sh");
sleepFive();
Util::Procs::Stop("number4");
return 0;
}//main

View file

@ -1,6 +0,0 @@
#!/bin/sh
echo "I am a test!"
echo "I was called as $0"
echo "My first param is $1"
echo "Exiting now..."

View file

@ -1,5 +0,0 @@
#!/bin/sh
echo "Sending something through the pipe..." 1>&2
echo "something"
echo "Exiting pipewriter" 1>&2

View file

@ -1,6 +0,0 @@
#!/bin/sh
echo "Reading stdin..."
read meh
echo "I read $meh"
echo "Exiting pipereader now..."

View file

@ -1,18 +0,0 @@
SRC = box_abst.cpp box_afra.cpp box_afrt.cpp box_amhp.cpp box_asrt.cpp box_avcC.cpp box.cpp box_dinf.cpp box_dref.cpp box_esds.cpp box_ftyp.cpp box_hdlr.cpp box_hmhd.cpp box_mdat.cpp box_mdhd.cpp box_mdia.cpp box_mfhd.cpp box_minf.cpp box_moof.cpp box_moov.cpp box_mvex.cpp box_mvhd.cpp box_nmhd.cpp box_rtmp.cpp box_smhd.cpp box_stbl.cpp box_stco.cpp box_stsc.cpp box_stsd.cpp box_stts.cpp box_tfhd.cpp box_tkhd.cpp box_traf.cpp box_trak.cpp box_trex.cpp box_trun.cpp box_url.cpp box_vmhd.cpp interface.cpp main.cpp
OBJ = $(SRC:.cpp=.o)
OUT = Boxtest
INCLUDES =
CCFLAGS = -Wall -Wextra -funsigned-char -g
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 *~

View file

@ -1,123 +0,0 @@
#pragma once
#include <arpa/inet.h>
#include <stdint.h>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
class Box {
public:
Box();
Box(uint32_t BoxType);
Box(uint8_t * Content, uint32_t length);
~Box();
void SetBoxType(uint32_t BoxType);
uint32_t GetBoxType();
void SetPayload(uint32_t Size, uint8_t * Data, uint32_t Index = 0);
uint32_t GetPayloadSize();
uint8_t * GetPayload();
uint8_t * GetPayload(uint32_t Index, uint32_t & Size);
uint32_t GetBoxedDataSize();
uint8_t * GetBoxedData( );
static uint8_t * uint32_to_uint8( uint32_t data );
static uint8_t * uint16_to_uint8( uint16_t data );
static uint8_t * uint8_to_uint8( uint8_t data );
void ResetPayload( );
private:
uint8_t * Payload;
uint32_t PayloadSize;
};//Box Class
Box::Box() {
Payload = (uint8_t *)malloc(8);
PayloadSize = 0;
}
Box::Box(uint32_t BoxType) {
Payload = (uint8_t *)malloc(8);
SetBoxType(BoxType);
PayloadSize = 0;
}
Box::Box(uint8_t * Content, uint32_t length) {
PayloadSize = length-8;
Payload = (uint8_t *)malloc(length);
memcpy(Payload, Content, length);
}
Box::~Box() {
if (Payload) free(Payload);
}
void Box::SetBoxType(uint32_t BoxType) {
((unsigned int*)Payload)[1] = htonl(BoxType);
}
uint32_t Box::GetBoxType() {
return ntohl(((unsigned int*)Payload)[1]);
}
void Box::SetPayload(uint32_t Size, uint8_t * Data, uint32_t Index) {
if ( Index + Size > PayloadSize ) {
PayloadSize = Index + Size;
((unsigned int*)Payload)[0] = htonl(PayloadSize+8);
Payload = (uint8_t *)realloc(Payload, PayloadSize + 8);
}
memcpy(Payload + 8 + Index, Data, Size);
}
uint32_t Box::GetPayloadSize() {
return PayloadSize;
}
uint8_t * Box::GetPayload() {
return Payload+8;
}
uint8_t * Box::GetPayload(uint32_t Index, uint32_t & Size) {
if(Index > PayloadSize) {Size = 0;}
if(Index + Size > PayloadSize) { Size = PayloadSize - Index; }
return Payload + 8 + Index;
}
uint32_t Box::GetBoxedDataSize() {
return ntohl(((unsigned int*)Payload)[0]);
}
uint8_t * Box::GetBoxedData( ) {
return Payload;
}
uint8_t * Box::uint32_to_uint8( uint32_t data ) {
uint8_t * temp = new uint8_t[4];
temp[0] = (data >> 24) & 0x000000FF;
temp[1] = (data >> 16 ) & 0x000000FF;
temp[2] = (data >> 8 ) & 0x000000FF;
temp[3] = (data ) & 0x000000FF;
return temp;
}
uint8_t * Box::uint16_to_uint8( uint16_t data ) {
uint8_t * temp = new uint8_t[2];
temp[0] = (data >> 8) & 0x00FF;
temp[1] = (data ) & 0x00FF;
return temp;
}
uint8_t * Box::uint8_to_uint8( uint8_t data ) {
uint8_t * temp = new uint8_t[1];
temp[0] = data;
return temp;
}
void Box::ResetPayload( ) {
PayloadSize = 0;
Payload = (uint8_t *)realloc(Payload, PayloadSize + 8);
((unsigned int*)Payload)[0] = htonl(0);
}

View file

@ -1,227 +0,0 @@
#pragma once
#include "box.cpp"
#include <string>
#include <vector>
struct abst_serverentry {
std::string ServerBaseUrl;
};//abst_serverentry
struct abst_qualityentry {
std::string QualityModifier;
};//abst_qualityentry
class Box_abst {
public:
Box_abst( );
~Box_abst();
Box * GetBox();
void SetBootstrapVersion( uint32_t Version = 1 );
void SetProfile( uint8_t Profile = 0 );
void SetLive( bool Live = true );
void SetUpdate( bool Update = false );
void SetTimeScale( uint32_t Scale = 1000 );
void SetMediaTime( uint32_t Time = 0 );
void SetSMPTE( uint32_t Smpte = 0 );
void SetMovieIdentifier( std::string Identifier = "" );
void SetDRM( std::string Drm = "" );
void SetMetaData( std::string MetaData = "" );
void AddServerEntry( std::string Url = "", uint32_t Offset = 0 );
void AddQualityEntry( std::string Quality = "", uint32_t Offset = 0 );
void AddSegmentRunTable( Box * newSegment, uint32_t Offset = 0 );
void AddFragmentRunTable( Box * newFragment, uint32_t Offset = 0 );
void SetVersion( bool NewVersion = 0 );
void WriteContent( );
private:
void SetDefaults( );
void SetReserved( );
uint32_t curBootstrapInfoVersion;
uint8_t curProfile;
bool isLive;
bool isUpdate;
bool Version;
uint32_t curTimeScale;
uint32_t curMediatime;//write as uint64_t
uint32_t curSMPTE;//write as uint64_t
std::string curMovieIdentifier;
std::string curDRM;
std::string curMetaData;
std::vector<abst_serverentry> Servers;
std::vector<abst_qualityentry> Qualities;
std::vector<Box *> SegmentRunTables;
std::vector<Box *> FragmentRunTables;
Box * Container;
};//Box_ftyp Class
Box_abst::Box_abst( ) {
Container = new Box( 0x61627374 );
SetDefaults( );
}
Box_abst::~Box_abst() {
delete Container;
}
Box * Box_abst::GetBox() {
return Container;
}
void Box_abst::SetBootstrapVersion( uint32_t Version ) {
curBootstrapInfoVersion = Version;
}
void Box_abst::SetProfile( uint8_t Profile ) {
curProfile = Profile;
}
void Box_abst::SetLive( bool Live ) {
isLive = Live;
}
void Box_abst::SetUpdate( bool Update ) {
isUpdate = Update;
}
void Box_abst::SetTimeScale( uint32_t Scale ) {
curTimeScale = Scale;
}
void Box_abst::SetMediaTime( uint32_t Time ) {
curMediatime = Time;
}
void Box_abst::SetSMPTE( uint32_t Smpte ) {
curSMPTE = Smpte;
}
void Box_abst::SetMovieIdentifier( std::string Identifier ) {
curMovieIdentifier = Identifier;
}
void Box_abst::SetDRM( std::string Drm ) {
curDRM = Drm;
}
void Box_abst::SetMetaData( std::string MetaData ) {
curMetaData = MetaData;
}
void Box_abst::AddServerEntry( std::string Url, uint32_t Offset ) {
if(Offset >= Servers.size()) {
Servers.resize(Offset+1);
}
Servers[Offset].ServerBaseUrl = Url;
}
void Box_abst::AddQualityEntry( std::string Quality, uint32_t Offset ) {
if(Offset >= Qualities.size()) {
Qualities.resize(Offset+1);
}
Qualities[Offset].QualityModifier = Quality;
}
void Box_abst::AddSegmentRunTable( Box * newSegment, uint32_t Offset ) {
if( Offset >= SegmentRunTables.size() ) {
SegmentRunTables.resize(Offset+1);
}
if( SegmentRunTables[Offset] ) {
delete SegmentRunTables[Offset];
}
SegmentRunTables[Offset] = newSegment;
}
void Box_abst::AddFragmentRunTable( Box * newFragment, uint32_t Offset ) {
if( Offset >= FragmentRunTables.size() ) {
FragmentRunTables.resize(Offset+1);
}
if( FragmentRunTables[Offset] ) {
delete FragmentRunTables[Offset];
}
FragmentRunTables[Offset] = newFragment;
}
void Box_abst::SetDefaults( ) {
SetProfile( );
SetLive( );
SetUpdate( );
SetTimeScale( );
SetMediaTime( );
SetSMPTE( );
SetMovieIdentifier( );
SetDRM( );
SetMetaData( );
SetVersion( );
}
void Box_abst::SetVersion( bool NewVersion) {
Version = NewVersion;
}
void Box_abst::SetReserved( ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0));
}
void Box_abst::WriteContent( ) {
Box * current;
std::string serializedServers = "";
std::string serializedQualities = "";
std::string serializedSegments = "";
std::string serializedFragments = "";
int SegmentAmount = 0;
int FragmentAmount = 0;
uint8_t * temp = new uint8_t[1];
Container->ResetPayload( );
SetReserved( );
for( uint32_t i = 0; i < Servers.size(); i++ ) {
serializedServers.append(Servers[i].ServerBaseUrl.c_str());
serializedServers += '\0';
}
for( uint32_t i = 0; i < Qualities.size(); i++ ) {
serializedQualities.append(Qualities[i].QualityModifier.c_str());
serializedQualities += '\0';
}
for( uint32_t i = 0; i < SegmentRunTables.size(); i++ ) {
current=SegmentRunTables[i];
if( current ) {
SegmentAmount ++;
serializedSegments.append((char*)current->GetBoxedData(),current->GetBoxedDataSize());
}
}
for( uint32_t i = 0; i < FragmentRunTables.size(); i++ ) {
current=FragmentRunTables[i];
if( current ) {
FragmentAmount ++;
serializedFragments.append((char*)current->GetBoxedData(),current->GetBoxedDataSize());
}
}
uint32_t OffsetServerEntryCount = 29 + curMovieIdentifier.size() + 1;
uint32_t OffsetQualityEntryCount = OffsetServerEntryCount + 1 + serializedServers.size();
uint32_t OffsetDrmData = OffsetQualityEntryCount + 1 + serializedQualities.size();
uint32_t OffsetMetaData = OffsetDrmData + curDRM.size() + 1;
uint32_t OffsetSegmentRuntableCount = OffsetMetaData + curMetaData.size() + 1;
uint32_t OffsetFragmentRuntableCount = OffsetSegmentRuntableCount + 1 + serializedSegments.size();
temp[0] = 0 + ( curProfile << 6 ) + ( (uint8_t)isLive << 7 ) + ( (uint8_t)isUpdate << 7 );
Container->SetPayload((uint32_t)serializedFragments.size(),(uint8_t*)serializedFragments.c_str(),OffsetFragmentRuntableCount+1);
Container->SetPayload((uint32_t)1,Box::uint8_to_uint8(FragmentAmount),OffsetFragmentRuntableCount);
Container->SetPayload((uint32_t)serializedSegments.size(),(uint8_t*)serializedSegments.c_str(),OffsetSegmentRuntableCount+1);
Container->SetPayload((uint32_t)1,Box::uint8_to_uint8(SegmentAmount),OffsetSegmentRuntableCount);
Container->SetPayload((uint32_t)curMetaData.size()+1,(uint8_t*)curMetaData.c_str(),OffsetMetaData);
Container->SetPayload((uint32_t)curDRM.size()+1,(uint8_t*)curDRM.c_str(),OffsetDrmData);
Container->SetPayload((uint32_t)serializedQualities.size(),(uint8_t*)serializedQualities.c_str(),OffsetQualityEntryCount+1);
Container->SetPayload((uint32_t)1,Box::uint8_to_uint8(Qualities.size()),OffsetQualityEntryCount);
Container->SetPayload((uint32_t)serializedServers.size(),(uint8_t*)serializedServers.c_str(),OffsetServerEntryCount+1);
Container->SetPayload((uint32_t)1,Box::uint8_to_uint8(Servers.size()),OffsetServerEntryCount);
Container->SetPayload((uint32_t)curMovieIdentifier.size()+1,(uint8_t*)curMovieIdentifier.c_str(),29);//+1 for \0-terminated string...
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(curSMPTE),25);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),21);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(curMediatime),17);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),13);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(curTimeScale),9);
Container->SetPayload((uint32_t)1,temp,8);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(curBootstrapInfoVersion),4);
}

View file

@ -1,75 +0,0 @@
#include "box.cpp"
#include <vector>
struct afra_record {
uint32_t Time;
uint32_t Offset;
};//afra_record
class Box_afra {
public:
Box_afra( );
~Box_afra();
Box * GetBox();
void SetTimeScale( uint32_t Scale = 1 );
void AddEntry( uint32_t Time = 0, uint32_t SampleOffset = 0, uint32_t Offset = 0 );
void WriteContent( );
private:
void SetReserved( );
void SetDefaults( );
Box * Container;
uint32_t CurrentTimeScale;
std::vector<afra_record> Entries;
};//Box_ftyp Class
Box_afra::Box_afra( ) {
Container = new Box( 0x61667261 );
SetReserved( );
SetDefaults( );
}
Box_afra::~Box_afra() {
delete Container;
}
Box * Box_afra::GetBox() {
return Container;
}
void Box_afra::SetDefaults( ) {
SetTimeScale( );
}
void Box_afra::SetReserved( ) {
uint8_t * temp = new uint8_t[1];
temp[0] = 0;
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),1);
Container->SetPayload((uint32_t)1,temp);
}
void Box_afra::SetTimeScale( uint32_t Scale ) {
CurrentTimeScale = Scale;
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Scale),5);
}
void Box_afra::AddEntry( uint32_t Time, uint32_t SampleOffset, uint32_t Offset ) {
if(Offset >= Entries.size()) {
Entries.resize(Offset+1);
}
Entries[Offset].Time = Time;
Entries[Offset].Offset = SampleOffset;
}
void Box_afra::WriteContent( ) {
Container->ResetPayload();
SetReserved( );
if(!Entries.empty()) {
for(int32_t i = Entries.size() -1; i >= 0; i--) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries[i].Offset),(i*12)+21);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries[i].Time),(i*12)+17);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),(i*12)+13);
}
}
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries.size()),9);
}

View file

@ -1,104 +0,0 @@
#include "box.cpp"
#include <string>
#include <vector>
struct afrt_fragmentrunentry {
uint32_t FirstFragment;
uint32_t FirstFragmentTimestamp; //write as uint64_t
uint32_t FragmentDuration;
uint8_t DiscontinuityIndicator;//if FragmentDuration == 0
};//afrt_fragmentrunentry
class Box_afrt {
public:
Box_afrt( );
~Box_afrt();
Box * GetBox();
void SetUpdate( bool Update = false );
void SetTimeScale( uint32_t Scale = 1000 );
void AddQualityEntry( std::string Quality = "", uint32_t Offset = 0 );
void AddFragmentRunEntry( uint32_t FirstFragment = 0, uint32_t FirstFragmentTimestamp = 0, uint32_t FragmentsDuration = 1, uint8_t Discontinuity = 0, uint32_t Offset = 0 );
void WriteContent( );
private:
void SetDefaults( );
bool isUpdate;
uint32_t curTimeScale;
std::vector<std::string> QualitySegmentUrlModifiers;
std::vector<afrt_fragmentrunentry> FragmentRunEntryTable;
Box * Container;
};//Box_ftyp Class
Box_afrt::Box_afrt( ) {
Container = new Box( 0x61667274 );
}
Box_afrt::~Box_afrt() {
delete Container;
}
Box * Box_afrt::GetBox() {
return Container;
}
void Box_afrt::SetUpdate( bool Update ) {
isUpdate = Update;
}
void Box_afrt::AddQualityEntry( std::string Quality, uint32_t Offset ) {
if(Offset >= QualitySegmentUrlModifiers.size()) {
QualitySegmentUrlModifiers.resize(Offset+1);
}
QualitySegmentUrlModifiers[Offset] = Quality;
}
void Box_afrt::AddFragmentRunEntry( uint32_t FirstFragment, uint32_t FirstFragmentTimestamp, uint32_t FragmentsDuration, uint8_t Discontinuity, uint32_t Offset ) {
if( Offset >= FragmentRunEntryTable.size() ) {
FragmentRunEntryTable.resize(Offset+1);
}
FragmentRunEntryTable[Offset].FirstFragment = FirstFragment;
FragmentRunEntryTable[Offset].FirstFragmentTimestamp = FirstFragmentTimestamp;
FragmentRunEntryTable[Offset].FragmentDuration = FragmentsDuration;
if( FragmentsDuration == 0) {
FragmentRunEntryTable[Offset].DiscontinuityIndicator = Discontinuity;
}
}
void Box_afrt::SetDefaults( ) {
SetUpdate( );
SetTimeScale( );
}
void Box_afrt::SetTimeScale( uint32_t Scale ) {
curTimeScale = Scale;
}
void Box_afrt::WriteContent( ) {
std::string serializedQualities = "";
std::string serializedFragmentEntries = "";
Container->ResetPayload( );
for( uint32_t i = 0; i < QualitySegmentUrlModifiers.size(); i++ ) {
serializedQualities.append(QualitySegmentUrlModifiers[i].c_str());
serializedQualities += '\0';
}
for( uint32_t i = 0; i < FragmentRunEntryTable.size(); i ++ ) {
serializedFragmentEntries.append((char*)Box::uint32_to_uint8(FragmentRunEntryTable[i].FirstFragment),4);
serializedFragmentEntries.append((char*)Box::uint32_to_uint8(0),4);
serializedFragmentEntries.append((char*)Box::uint32_to_uint8(FragmentRunEntryTable[i].FirstFragmentTimestamp),4);
serializedFragmentEntries.append((char*)Box::uint32_to_uint8(FragmentRunEntryTable[i].FragmentDuration),4);
if(FragmentRunEntryTable[i].FragmentDuration == 0) {
serializedFragmentEntries.append((char*)Box::uint8_to_uint8(FragmentRunEntryTable[i].DiscontinuityIndicator),1);
}
}
uint32_t OffsetFragmentRunEntryCount = 9 + serializedQualities.size();
Container->SetPayload((uint32_t)serializedFragmentEntries.size(),(uint8_t*)serializedFragmentEntries.c_str(),OffsetFragmentRunEntryCount+4);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(FragmentRunEntryTable.size()),OffsetFragmentRunEntryCount);
Container->SetPayload((uint32_t)serializedQualities.size(),(uint8_t*)serializedQualities.c_str(),9);
Container->SetPayload((uint32_t)1,Box::uint8_to_uint8(QualitySegmentUrlModifiers.size()),8);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(curTimeScale),4);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8((isUpdate ? 1 : 0)));
}

View file

@ -1,63 +0,0 @@
#include "box.cpp"
#include <string>
#include <vector>
struct amhp_record {
uint8_t HintTrackMode;
uint8_t Settings;
uint8_t TrailerDefaultSize;
};//stsc_record
class Box_amhp {
public:
Box_amhp( );
~Box_amhp();
Box * GetBox();
void SetReserved( );
void AddEntry( uint8_t HintTrackMode, uint8_t Settings, uint8_t TrailerDefaultSize, uint32_t Offset = 0 );
void WriteContent( );
private:
Box * Container;
std::vector<amhp_record> Entries;
};//Box_ftyp Class
Box_amhp::Box_amhp( ) {
Container = new Box( 0x616D6870 );
SetReserved();
}
Box_amhp::~Box_amhp() {
delete Container;
}
Box * Box_amhp::GetBox() {
return Container;
}
void Box_amhp::SetReserved( ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0));
}
void Box_amhp::AddEntry( uint8_t HintTrackMode, uint8_t Settings, uint8_t TrailerDefaultSize, uint32_t Offset ) {
if(Offset >= Entries.size()) {
Entries.resize(Offset+1);
}
Entries[Offset].HintTrackMode = HintTrackMode;
Entries[Offset].Settings = Settings;
Entries[Offset].TrailerDefaultSize = TrailerDefaultSize;
}
void Box_amhp::WriteContent( ) {
Container->ResetPayload();
SetReserved( );
if(!Entries.empty()) {
for(int32_t i = Entries.size() -1; i >= 0; i--) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries[i].TrailerDefaultSize),(i*12)+16);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries[i].Settings),(i*12)+12);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries[i].HintTrackMode),(i*12)+8);
}
}
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries.size()),4);
}

View file

@ -1,87 +0,0 @@
#include "box.cpp"
#include <string>
#include <vector>
struct asrt_segmentrunentry {
uint32_t FirstSegment;
uint32_t FragmentsPerSegment;
};//abst_qualityentry
class Box_asrt {
public:
Box_asrt( );
~Box_asrt();
Box * GetBox();
void SetUpdate( bool Update = false );
void AddQualityEntry( std::string Quality = "", uint32_t Offset = 0 );
void AddSegmentRunEntry( uint32_t FirstSegment = 0, uint32_t FragmentsPerSegment = 100, uint32_t Offset = 0 );
void WriteContent( );
void SetVersion( bool NewVersion = 0 );
private:
void SetDefaults( );
bool isUpdate;
bool Version;
std::vector<std::string> QualitySegmentUrlModifiers;
std::vector<asrt_segmentrunentry> SegmentRunEntryTable;
Box * Container;
};//Box_ftyp Class
Box_asrt::Box_asrt( ) {
Container = new Box( 0x61737274 );
}
Box_asrt::~Box_asrt() {
delete Container;
}
Box * Box_asrt::GetBox() {
return Container;
}
void Box_asrt::SetUpdate( bool Update ) {
isUpdate = Update;
}
void Box_asrt::AddQualityEntry( std::string Quality, uint32_t Offset ) {
if(Offset >= QualitySegmentUrlModifiers.size()) {
QualitySegmentUrlModifiers.resize(Offset+1);
}
QualitySegmentUrlModifiers[Offset] = Quality;
}
void Box_asrt::AddSegmentRunEntry( uint32_t FirstSegment, uint32_t FragmentsPerSegment, uint32_t Offset ) {
if( Offset >= SegmentRunEntryTable.size() ) {
SegmentRunEntryTable.resize(Offset+1);
}
SegmentRunEntryTable[Offset].FirstSegment = FirstSegment;
SegmentRunEntryTable[Offset].FragmentsPerSegment = FragmentsPerSegment;
}
void Box_asrt::SetVersion( bool NewVersion ) {
Version = NewVersion;
}
void Box_asrt::SetDefaults( ) {
SetUpdate( );
}
void Box_asrt::WriteContent( ) {
std::string serializedQualities = "";
Container->ResetPayload( );
for( uint32_t i = 0; i < QualitySegmentUrlModifiers.size(); i++ ) {
serializedQualities.append(QualitySegmentUrlModifiers[i].c_str());
serializedQualities += '\0';
}
uint32_t OffsetSegmentRunEntryCount = 5 + serializedQualities.size();
for( uint32_t i = 0; i < SegmentRunEntryTable.size(); i ++ ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(SegmentRunEntryTable[i].FragmentsPerSegment),(8*i)+OffsetSegmentRunEntryCount+8);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(SegmentRunEntryTable[i].FirstSegment),(8*i)+OffsetSegmentRunEntryCount+4);
}
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(SegmentRunEntryTable.size()),OffsetSegmentRunEntryCount);
Container->SetPayload((uint32_t)serializedQualities.size(),(uint8_t*)serializedQualities.c_str(),5);
Container->SetPayload((uint32_t)1,Box::uint8_to_uint8(QualitySegmentUrlModifiers.size()),4);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8((isUpdate ? 1 : 0)));
}

View file

@ -1,87 +0,0 @@
#include "box.cpp"
#include <string>
#include <algorithm>
class Box_avcC {
public:
Box_avcC( );
~Box_avcC();
Box * GetBox();
void SetDataReferenceIndex( uint16_t DataReferenceIndex = 1 );
void SetWidth( uint16_t Width = 0 );
void SetHeight( uint16_t Height = 0 );
void SetResolution ( uint32_t Horizontal = 0x00480000, uint32_t Vertical = 0x00480000 );
void SetFrameCount ( uint16_t FrameCount = 1 );
void SetCompressorName ( std::string CompressorName = "");
void SetDepth ( uint16_t Depth = 0x0018 );
private:
Box * Container;
void SetReserved( );
void SetDefaults( );
};//Box_ftyp Class
Box_avcC::Box_avcC( ) {
Container = new Box( 0x61766343 );
SetReserved();
SetDefaults();
}
Box_avcC::~Box_avcC() {
delete Container;
}
Box * Box_avcC::GetBox() {
return Container;
}
void Box_avcC::SetDataReferenceIndex( uint16_t DataReferenceIndex ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( DataReferenceIndex ),6);
}
void Box_avcC::SetWidth( uint16_t Width ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( Width ),24);
}
void Box_avcC::SetHeight( uint16_t Height ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( Height ),26);
}
void Box_avcC::SetResolution ( uint32_t Horizontal, uint32_t Vertical ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8( Vertical ),32);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8( Horizontal ),28);
}
void Box_avcC::SetFrameCount ( uint16_t FrameCount ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( FrameCount ),40);
}
void Box_avcC::SetCompressorName ( std::string CompressorName ) {
uint8_t * Printable = new uint8_t[1];
Printable[0] = std::min( (unsigned int)31, (unsigned int)CompressorName.size() );
Container->SetPayload((uint32_t)Printable[0],(uint8_t*)CompressorName.c_str(),43);
Container->SetPayload((uint32_t)1, Printable ,42);
}
void Box_avcC::SetDepth ( uint16_t Depth ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( Depth ),74);
}
void Box_avcC::SetReserved( ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( (uint16_t)-1 ),76);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),36);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),20);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),16);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),12);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),8);
Container->SetPayload((uint32_t)4,Box::uint16_to_uint8(0),4);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0));
}
void Box_avcC::SetDefaults( ) {
SetWidth( );
SetHeight( );
SetDepth ( );
SetFrameCount ( );
SetResolution ( );
}

View file

@ -1,43 +0,0 @@
#include "box.cpp"
#include <vector>
#include <string>
class Box_dinf {
public:
Box_dinf();
~Box_dinf();
Box * GetBox();
void AddContent( Box * newcontent );
void WriteContent( );
private:
Box * Container;
Box * Content;
};//Box_ftyp Class
Box_dinf::Box_dinf( ) {
Container = new Box( 0x64696E66 );
}
Box_dinf::~Box_dinf() {
delete Container;
}
Box * Box_dinf::GetBox() {
return Container;
}
void Box_dinf::AddContent( Box * newcontent ) {
if(Content) {
delete Content;
Content = NULL;
}
Content = newcontent;
}
void Box_dinf::WriteContent( ) {
Container->ResetPayload( );
std::string serializedbox = "";
serializedbox.append((char*)Content->GetBoxedData(),Content->GetBoxedDataSize());
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str());
}

View file

@ -1,58 +0,0 @@
#include "box.cpp"
#include <vector>
#include <string>
class Box_dref {
public:
Box_dref();
~Box_dref();
Box * GetBox();
void AddContent( Box * newcontent, uint32_t offset = 0 );
void WriteContent( );
private:
Box * Container;
void SetReserved( );
std::vector<Box *> Content;
};//Box_ftyp Class
Box_dref::Box_dref( ) {
Container = new Box( 0x64726566 );
SetReserved( );
}
Box_dref::~Box_dref() {
delete Container;
}
Box * Box_dref::GetBox() {
return Container;
}
void Box_dref::AddContent( Box * newcontent, uint32_t offset ) {
if( offset >= Content.size() ) {
Content.resize(offset+1);
}
if( Content[offset] ) {
delete Content[offset];
}
Content[offset] = newcontent;
}
void Box_dref::WriteContent( ) {
Container->ResetPayload( );
Box * current;
std::string serializedbox = "";
for( uint32_t i = 0; i < Content.size(); i++ ) {
current=Content[i];
if( current ) {
serializedbox.append((char*)current->GetBoxedData(),current->GetBoxedDataSize());
}
}
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str(),4);
SetReserved( );
}
void Box_dref::SetReserved( ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0));
}

View file

@ -1,55 +0,0 @@
#include "box.cpp"
#include <string>
class Box_esds {
public:
Box_esds( );
~Box_esds();
Box * GetBox();
void SetDataReferenceIndex( uint16_t DataReferenceIndex = 1);
void SetChannelCount( uint16_t Count = 2 );
void SetSampleSize( uint16_t Size = 16 );
private:
Box * Container;
void SetReserved( );
void SetDefaults( );
};//Box_ftyp Class
Box_esds::Box_esds( ) {
Container = new Box( 0x65736473 );
SetReserved();
SetDefaults();
}
Box_esds::~Box_esds() {
delete Container;
}
Box * Box_esds::GetBox() {
return Container;
}
void Box_esds::SetDataReferenceIndex( uint16_t DataReferenceIndex ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( DataReferenceIndex ),6);
}
void Box_esds::SetChannelCount( uint16_t Count ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( Count ),16);
}
void Box_esds::SetSampleSize( uint16_t Size ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( Size ),18);
}
void Box_esds::SetReserved( ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8( 0 ),20);
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( 0 ),4);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8( 0 ));
}
void Box_esds::SetDefaults( ) {
SetSampleSize( );
SetChannelCount( );
SetDataReferenceIndex( );
}

View file

@ -1,39 +0,0 @@
#include "box.cpp"
class Box_ftyp {
public:
Box_ftyp( );
~Box_ftyp();
Box * GetBox();
void SetMajorBrand( uint32_t MajorBrand = 0x66347620 );
void SetMinorBrand( uint32_t MinorBrand = 0x1 );
private:
void SetDefaults( );
Box * Container;
};//Box_ftyp Class
Box_ftyp::Box_ftyp( ) {
Container = new Box( 0x66747970 );
SetDefaults( );
}
Box_ftyp::~Box_ftyp() {
delete Container;
}
Box * Box_ftyp::GetBox() {
return Container;
}
void Box_ftyp::SetMajorBrand( uint32_t MajorBrand ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(MajorBrand));
}
void Box_ftyp::SetMinorBrand( uint32_t MinorBrand ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(MinorBrand),4);
}
void Box_ftyp::SetDefaults( ) {
SetMinorBrand( );
SetMajorBrand( );
}

View file

@ -1,59 +0,0 @@
#include "box.cpp"
#include <string>
class Box_hdlr {
public:
Box_hdlr( );
~Box_hdlr();
Box * GetBox();
void SetHandlerType( uint32_t HandlerType = 0 );
void SetName ( std::string Name = "" );
private:
Box * Container;
void SetReserved( );
void SetDefaults( );
uint32_t CurrentHandlerType;
};//Box_ftyp Class
Box_hdlr::Box_hdlr( ) {
Container = new Box( 0x68646C72 );
CurrentHandlerType = 0;
SetReserved();
}
Box_hdlr::~Box_hdlr() {
delete Container;
}
Box * Box_hdlr::GetBox() {
return Container;
}
void Box_hdlr::SetReserved( ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),20);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),16);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),12);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),4);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0));
}
void Box_hdlr::SetHandlerType( uint32_t HandlerType ) {
if( HandlerType != 0 ) {
CurrentHandlerType = HandlerType;
}
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(CurrentHandlerType),8);
}
void Box_hdlr::SetName ( std::string Name ) {
char * tmp = new char[Name.size()+1];
strcpy(tmp,Name.c_str());
Container->ResetPayload();
SetReserved();
SetHandlerType(0);
Container->SetPayload((uint32_t)strlen(tmp)+1,(uint8_t*)tmp,24);
}
void Box_hdlr::SetDefaults( ) {
SetName( );
SetHandlerType( );
}

View file

@ -1,57 +0,0 @@
#include "box.cpp"
class Box_hmhd {
public:
Box_hmhd( );
~Box_hmhd();
Box * GetBox();
void SetMaxPDUSize( uint16_t Size = 0 );
void SetAvgPDUSize( uint16_t Size = 0 );
void SetMaxBitRate( uint32_t Rate = 0 );
void SetAvgBitRate( uint32_t Rate = 0 );
private:
Box * Container;
void SetReserved( );
void SetDefaults( );
};//Box_ftyp Class
Box_hmhd::Box_hmhd( ) {
Container = new Box( 0x686D6864 );
SetDefaults();
SetReserved();
}
Box_hmhd::~Box_hmhd() {
delete Container;
}
Box * Box_hmhd::GetBox() {
return Container;
}
void Box_hmhd::SetMaxPDUSize( uint16_t Size ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(Size),4);
}
void Box_hmhd::SetAvgPDUSize( uint16_t Size ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(Size),6);
}
void Box_hmhd::SetMaxBitRate( uint32_t Rate ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Rate),8);
}
void Box_hmhd::SetAvgBitRate( uint32_t Rate ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Rate),12);
}
void Box_hmhd::SetReserved( ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),16);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0));
}
void Box_hmhd::SetDefaults( ) {
SetAvgBitRate( );
SetMaxBitRate( );
SetAvgPDUSize( );
SetMaxPDUSize( );
}

View file

@ -1,37 +0,0 @@
#include "box_abst.cpp"
#include "box_afra.cpp"
#include "box_afrt.cpp"
#include "box_amhp.cpp"
#include "box_asrt.cpp"
#include "box_avcC.cpp"
#include "box_dinf.cpp"
#include "box_dref.cpp"
#include "box_esds.cpp"
#include "box_ftyp.cpp"
#include "box_hdlr.cpp"
#include "box_hmhd.cpp"
#include "box_mdat.cpp"
#include "box_mdhd.cpp"
#include "box_mdia.cpp"
#include "box_mfhd.cpp"
#include "box_minf.cpp"
#include "box_moof.cpp"
#include "box_moov.cpp"
#include "box_mvex.cpp"
#include "box_mvhd.cpp"
#include "box_nmhd.cpp"
#include "box_rtmp.cpp"
#include "box_smhd.cpp"
#include "box_stbl.cpp"
#include "box_stco.cpp"
#include "box_stsc.cpp"
#include "box_stsd.cpp"
#include "box_stts.cpp"
#include "box_tfhd.cpp"
#include "box_tkhd.cpp"
#include "box_traf.cpp"
#include "box_trak.cpp"
#include "box_trex.cpp"
#include "box_trun.cpp"
#include "box_url.cpp"
#include "box_vmhd.cpp"

View file

@ -1,29 +0,0 @@
#include "box.cpp"
#include <vector>
#include <string>
class Box_mdat {
public:
Box_mdat();
~Box_mdat();
Box * GetBox();
void SetContent( uint8_t * NewData, uint32_t DataLength , uint32_t offset = 0 );
private:
Box * Container;
};//Box_ftyp Class
Box_mdat::Box_mdat( ) {
Container = new Box( 0x6D646174 );
}
Box_mdat::~Box_mdat() {
delete Container;
}
Box * Box_mdat::GetBox() {
return Container;
}
void Box_mdat::SetContent( uint8_t * NewData, uint32_t DataLength , uint32_t Offset ) {
Container->SetPayload(DataLength,NewData,Offset);
}

View file

@ -1,88 +0,0 @@
#include "box.cpp"
#include <ctime>
#define SECONDS_DIFFERENCE 2082844800
class Box_mdhd {
public:
Box_mdhd( );
~Box_mdhd();
Box * GetBox();
void SetCreationTime( uint32_t TimeStamp = 0 );
void SetModificationTime( uint32_t TimeStamp = 0 );
void SetTimeScale( uint32_t TimeUnits = 0 );
void SetDurationTime( uint32_t TimeUnits = 0 );
void SetLanguage( uint8_t Firstchar = 'n', uint8_t Secondchar = 'l', uint8_t Thirdchar = 'd' );
private:
void SetReserved();
void SetDefaults();
Box * Container;
};//Box_ftyp Class
Box_mdhd::Box_mdhd( ) {
Container = new Box( 0x6D646864 );
}
Box_mdhd::~Box_mdhd() {
delete Container;
}
Box * Box_mdhd::GetBox() {
return Container;
}
void Box_mdhd::SetCreationTime( uint32_t TimeStamp ) {
uint32_t CreationTime;
if(!TimeStamp) {
CreationTime = time(NULL) + SECONDS_DIFFERENCE;
} else {
CreationTime = TimeStamp;
}
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(CreationTime),4);
}
void Box_mdhd::SetModificationTime( uint32_t TimeStamp ) {
uint32_t ModificationTime;
if(!TimeStamp) {
ModificationTime = time(NULL) + SECONDS_DIFFERENCE;
} else {
ModificationTime = TimeStamp;
}
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(ModificationTime),8);
}
void Box_mdhd::SetTimeScale( uint32_t TimeUnits ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(TimeUnits),12);
}
void Box_mdhd::SetDurationTime( uint32_t TimeUnits ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(TimeUnits),16);
}
void Box_mdhd::SetLanguage( uint8_t Firstchar, uint8_t Secondchar, uint8_t Thirdchar ) {
uint8_t FirstByte = 0;
uint8_t SecondByte = 0;
Firstchar -= 0x60;
Secondchar -= 0x60;
Thirdchar -= 0x60;
FirstByte += (Firstchar << 2);
FirstByte += (Secondchar >> 3);
SecondByte += (Secondchar << 5);
SecondByte += Thirdchar;
Container->SetPayload((uint32_t)1,&SecondByte,21);
Container->SetPayload((uint32_t)1,&FirstByte,20);
}
void Box_mdhd::SetReserved() {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(0),22);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0));
}
void Box_mdhd::SetDefaults() {
SetLanguage();
SetDurationTime();
SetTimeScale();
SetModificationTime();
SetCreationTime();
}

View file

@ -1,51 +0,0 @@
#include "box.cpp"
#include <vector>
#include <string>
class Box_mdia {
public:
Box_mdia();
~Box_mdia();
Box * GetBox();
void AddContent( Box * newcontent, uint32_t offset = 0 );
void WriteContent( );
private:
Box * Container;
std::vector<Box *> Content;
};//Box_ftyp Class
Box_mdia::Box_mdia( ) {
Container = new Box( 0x6D646961 );
}
Box_mdia::~Box_mdia() {
delete Container;
}
Box * Box_mdia::GetBox() {
return Container;
}
void Box_mdia::AddContent( Box * newcontent, uint32_t offset ) {
if( offset >= Content.size() ) {
Content.resize(offset+1);
}
if( Content[offset] ) {
delete Content[offset];
}
Content[offset] = newcontent;
}
void Box_mdia::WriteContent( ) {
Container->ResetPayload( );
Box * current;
std::string serializedbox = "";
for( uint32_t i = 0; i < Content.size(); i++ ) {
current=Content[i];
if( current ) {
serializedbox.append((char*)current->GetBoxedData(),current->GetBoxedDataSize());
}
}
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str());
}

Some files were not shown because too many files have changed in this diff Show more