Several major bugfixes in FLV handling, multithreaded buffer now actually works (still crashes when multiple users connect, though... needs further "tweaking"), updated toolset.
This commit is contained in:
parent
4cd8641e50
commit
9b6e220b88
13 changed files with 564 additions and 328 deletions
23
tools/DTSC2FLV/Makefile
Normal file
23
tools/DTSC2FLV/Makefile
Normal file
|
@ -0,0 +1,23 @@
|
|||
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/
|
||||
|
64
tools/DTSC2FLV/main.cpp
Normal file
64
tools/DTSC2FLV/main.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/// \file DTSC2FLV/main.cpp
|
||||
/// Contains the code that will transform any valid DTSC input into valid FLVs.
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include "../../util/flv_tag.h" //FLV support
|
||||
#include "../../util/dtsc.h" //DTSC support
|
||||
#include "../../util/amf.h" //AMF support
|
||||
|
||||
/// Holds all code that converts filetypes to DTSC.
|
||||
namespace Converters{
|
||||
|
||||
/// Reads DTSC from STDIN, outputs FLV to STDOUT.
|
||||
int DTSC2FLV() {
|
||||
FLV::Tag FLV_out; // Temporary storage for outgoing FLV data.
|
||||
DTSC::Stream Strm;
|
||||
std::string inBuffer;
|
||||
char charBuffer[1024*10];
|
||||
unsigned int charCount;
|
||||
bool doneheader = false;
|
||||
|
||||
while (std::cin.good()){
|
||||
std::cin.read(charBuffer, 1024*10);
|
||||
charCount = std::cin.gcount();
|
||||
inBuffer.append(charBuffer, charCount);
|
||||
if (Strm.parsePacket(inBuffer)){
|
||||
if (!doneheader){
|
||||
doneheader = true;
|
||||
std::cout.write(FLV::Header, 13);
|
||||
FLV_out.DTSCMetaInit(Strm);
|
||||
std::cout.write(FLV_out.data, FLV_out.len);
|
||||
if (Strm.metadata.getContentP("video") && Strm.metadata.getContentP("video")->getContentP("init")){
|
||||
FLV_out.DTSCVideoInit(Strm);
|
||||
std::cout.write(FLV_out.data, FLV_out.len);
|
||||
}
|
||||
if (Strm.metadata.getContentP("audio") && Strm.metadata.getContentP("audio")->getContentP("init")){
|
||||
FLV_out.DTSCAudioInit(Strm);
|
||||
std::cout.write(FLV_out.data, FLV_out.len);
|
||||
}
|
||||
}
|
||||
if (FLV_out.DTSCLoader(Strm)){
|
||||
std::cout.write(FLV_out.data, FLV_out.len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "Done!" << std::endl;
|
||||
|
||||
return 0;
|
||||
}//FLV2DTSC
|
||||
|
||||
};//Converter namespace
|
||||
|
||||
/// Entry point for DTSC2FLV, simply calls Converters::DTSC2FLV().
|
||||
int main(){
|
||||
return Converters::DTSC2FLV();
|
||||
}//main
|
|
@ -217,6 +217,7 @@ namespace Converters{
|
|||
case 0x40: pack_out.addContent(DTSC::DTMI("keyframe", 1)); break;
|
||||
case 0x50: continue; break;//the video info byte we just throw away - useless to us...
|
||||
}
|
||||
pack_out.addContent(DTSC::DTMI("time", FLV_in.tagTime()));
|
||||
if ((videodata & 0x0F) == 7){
|
||||
switch (FLV_in.data[12]){
|
||||
case 1: pack_out.addContent(DTSC::DTMI("nalu", 1)); break;
|
||||
|
@ -225,9 +226,10 @@ namespace Converters{
|
|||
int offset = (FLV_in.data[13] << 16) + (FLV_in.data[14] << 8) + FLV_in.data[15];
|
||||
offset = (offset << 8) >> 8;
|
||||
pack_out.addContent(DTSC::DTMI("offset", offset));
|
||||
pack_out.addContent(DTSC::DTMI("data", std::string((char*)FLV_in.data+16, (size_t)FLV_in.len-20)));
|
||||
}else{
|
||||
pack_out.addContent(DTSC::DTMI("data", std::string((char*)FLV_in.data+12, (size_t)FLV_in.len-16)));
|
||||
}
|
||||
pack_out.addContent(DTSC::DTMI("time", FLV_in.tagTime()));
|
||||
pack_out.addContent(DTSC::DTMI("data", std::string((char*)FLV_in.data+12, (size_t)FLV_in.len-16)));
|
||||
if (sending){
|
||||
std::cout << pack_out.Pack(true);
|
||||
}else{
|
||||
|
|
23
tools/FLV_Analyser/Makefile
Normal file
23
tools/FLV_Analyser/Makefile
Normal file
|
@ -0,0 +1,23 @@
|
|||
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/
|
||||
|
52
tools/FLV_Analyser/main.cpp
Normal file
52
tools/FLV_Analyser/main.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/// \file DTSC_Analyser/main.cpp
|
||||
/// Contains the code for the DTSC Analysing tool.
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include "../../util/flv_tag.h" //FLV support
|
||||
|
||||
/// Reads DTSC from stdin and outputs human-readable information to stderr.
|
||||
int main() {
|
||||
|
||||
FLV::Tag FLV_in; // Temporary storage for incoming FLV data.
|
||||
|
||||
|
||||
while (!feof(stdin)){
|
||||
if (FLV_in.FileLoader(stdin)){
|
||||
std::cout << "Tag: " << FLV_in.tagType() << std::endl;
|
||||
printf("%hhX %hhX %hhX %hhX %hhX %hhX %hhX %hhX %hhX %hhX\n", FLV_in.data[11], FLV_in.data[12], FLV_in.data[13], FLV_in.data[14], FLV_in.data[15], FLV_in.data[16], FLV_in.data[17], FLV_in.data[18], FLV_in.data[19], FLV_in.data[20]);
|
||||
printf("%hhX %hhX %hhX %hhX %hhX %hhX %hhX %hhX %hhX %hhX\n", FLV_in.data[FLV_in.len-10], FLV_in.data[FLV_in.len-9], FLV_in.data[FLV_in.len-8], FLV_in.data[FLV_in.len-7], FLV_in.data[FLV_in.len-6], FLV_in.data[FLV_in.len-5], FLV_in.data[FLV_in.len-4], FLV_in.data[FLV_in.len-3], FLV_in.data[FLV_in.len-2], FLV_in.data[FLV_in.len-1]);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DTSC::Stream Strm;
|
||||
|
||||
std::string inBuffer;
|
||||
char charBuffer[1024*10];
|
||||
unsigned int charCount;
|
||||
bool doneheader = false;
|
||||
|
||||
while(std::cin.good()){
|
||||
//invalidate the current buffer
|
||||
std::cin.read(charBuffer, 1024*10);
|
||||
charCount = std::cin.gcount();
|
||||
inBuffer.append(charBuffer, charCount);
|
||||
if (Strm.parsePacket(inBuffer)){
|
||||
if (!doneheader){
|
||||
doneheader = true;
|
||||
Strm.metadata.Print();
|
||||
}
|
||||
Strm.getPacket().Print();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue