Finish splitting controller into multiple files, universalised coding style across all files.
This commit is contained in:
parent
0db5f60b95
commit
0920b3259b
30 changed files with 1616 additions and 1246 deletions
|
@ -16,20 +16,20 @@
|
|||
#include <mist/config.h>
|
||||
|
||||
/// Holds all code that converts filetypes to/from DTSC.
|
||||
namespace Converters{
|
||||
|
||||
namespace Converters {
|
||||
|
||||
/// Reads DTSC from STDIN, outputs FLV to STDOUT.
|
||||
int DTSC2FLV() {
|
||||
int DTSC2FLV(){
|
||||
FLV::Tag FLV_out; // Temporary storage for outgoing FLV data.
|
||||
DTSC::Stream Strm;
|
||||
std::string inBuffer;
|
||||
char charBuffer[1024*10];
|
||||
char charBuffer[1024 * 10];
|
||||
unsigned int charCount;
|
||||
bool doneheader = false;
|
||||
|
||||
while (std::cin.good()){
|
||||
if (Strm.parsePacket(inBuffer)){
|
||||
if (!doneheader){
|
||||
if ( !doneheader){
|
||||
doneheader = true;
|
||||
std::cout.write(FLV::Header, 13);
|
||||
FLV_out.DTSCMetaInit(Strm);
|
||||
|
@ -47,22 +47,22 @@ namespace Converters{
|
|||
std::cout.write(FLV_out.data, FLV_out.len);
|
||||
}
|
||||
}else{
|
||||
std::cin.read(charBuffer, 1024*10);
|
||||
std::cin.read(charBuffer, 1024 * 10);
|
||||
charCount = std::cin.gcount();
|
||||
inBuffer.append(charBuffer, charCount);
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "Done!" << std::endl;
|
||||
|
||||
return 0;
|
||||
}//FLV2DTSC
|
||||
|
||||
};//Converter namespace
|
||||
return 0;
|
||||
} //FLV2DTSC
|
||||
|
||||
} //Converter namespace
|
||||
|
||||
/// Entry point for DTSC2FLV, simply calls Converters::DTSC2FLV().
|
||||
int main(int argc, char ** argv){
|
||||
Util::Config conf = Util::Config(argv[0], PACKAGE_VERSION);
|
||||
conf.parseArgs(argc, argv);
|
||||
return Converters::DTSC2FLV();
|
||||
}//main
|
||||
} //main
|
||||
|
|
|
@ -7,16 +7,16 @@
|
|||
#include <mist/config.h>
|
||||
|
||||
/// Holds all code that converts filetypes to/from to DTSC.
|
||||
namespace Converters{
|
||||
namespace Converters {
|
||||
|
||||
/// Reads an DTSC file and attempts to fix the metadata in it.
|
||||
int DTSCFix(Util::Config & conf) {
|
||||
int DTSCFix(Util::Config & conf){
|
||||
DTSC::File F(conf.getString("filename"));
|
||||
JSON::Value oriheader = F.getMeta();
|
||||
JSON::Value meta = oriheader;
|
||||
JSON::Value pack;
|
||||
|
||||
if (!oriheader.isMember("moreheader")){
|
||||
if ( !oriheader.isMember("moreheader")){
|
||||
std::cerr << "This file is not DTSCFix'able. Please re-convert and try again." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
@ -46,14 +46,20 @@ namespace Converters{
|
|||
long long unsigned int bps = 0;
|
||||
|
||||
F.seekNext();
|
||||
while (!F.getJSON().isNull()){
|
||||
while ( !F.getJSON().isNull()){
|
||||
nowpack = F.getJSON()["time"].asInt();
|
||||
if (firstpack == 0){firstpack = nowpack;}
|
||||
if (firstpack == 0){
|
||||
firstpack = nowpack;
|
||||
}
|
||||
if (F.getJSON()["datatype"].asString() == "audio"){
|
||||
if (lastaudio != 0 && (nowpack - lastaudio) != 0){
|
||||
bps = F.getJSON()["data"].asString().size() / (nowpack - lastaudio);
|
||||
if (bps < aud_min){aud_min = bps;}
|
||||
if (bps > aud_max){aud_max = bps;}
|
||||
if (bps < aud_min){
|
||||
aud_min = bps;
|
||||
}
|
||||
if (bps > aud_max){
|
||||
aud_max = bps;
|
||||
}
|
||||
}
|
||||
totalaudio += F.getJSON()["data"].asString().size();
|
||||
lastaudio = nowpack;
|
||||
|
@ -61,24 +67,36 @@ namespace Converters{
|
|||
if (F.getJSON()["datatype"].asString() == "video"){
|
||||
if (lastvideo != 0 && (nowpack - lastvideo) != 0){
|
||||
bps = F.getJSON()["data"].asString().size() / (nowpack - lastvideo);
|
||||
if (bps < vid_min){vid_min = bps;}
|
||||
if (bps > vid_max){vid_max = bps;}
|
||||
if (bps < vid_min){
|
||||
vid_min = bps;
|
||||
}
|
||||
if (bps > vid_max){
|
||||
vid_max = bps;
|
||||
}
|
||||
}
|
||||
if (F.getJSON()["keyframe"].asInt() != 0){
|
||||
meta["keytime"].append(F.getJSON()["time"]);
|
||||
meta["keybpos"].append(F.getLastReadPos());
|
||||
if (lastkey != 0){
|
||||
bps = nowpack - lastkey;
|
||||
if (bps < key_min){key_min = bps;}
|
||||
if (bps > key_max){key_max = bps;}
|
||||
if (bps < key_min){
|
||||
key_min = bps;
|
||||
}
|
||||
if (bps > key_max){
|
||||
key_max = bps;
|
||||
}
|
||||
}
|
||||
keyframes++;
|
||||
lastkey = nowpack;
|
||||
}
|
||||
if (F.getJSON()["offset"].asInt() != 0){
|
||||
bps = F.getJSON()["offset"].asInt();
|
||||
if (bps < bfrm_min){bfrm_min = bps;}
|
||||
if (bps > bfrm_max){bfrm_max = bps;}
|
||||
if (bps < bfrm_min){
|
||||
bfrm_min = bps;
|
||||
}
|
||||
if (bps > bfrm_max){
|
||||
bfrm_max = bps;
|
||||
}
|
||||
}
|
||||
totalvideo += F.getJSON()["data"].asString().size();
|
||||
lastvideo = nowpack;
|
||||
|
@ -86,7 +104,7 @@ namespace Converters{
|
|||
F.seekNext();
|
||||
}
|
||||
|
||||
meta["length"] = (long long int)((nowpack - firstpack)/1000);
|
||||
meta["length"] = (long long int)((nowpack - firstpack) / 1000);
|
||||
meta["lastms"] = (long long int)nowpack;
|
||||
if (meta.isMember("audio")){
|
||||
meta["audio"]["bps"] = (long long int)(totalaudio / ((lastaudio - firstpack) / 1000));
|
||||
|
@ -104,7 +122,7 @@ namespace Converters{
|
|||
std::cerr << "Appending new header..." << std::endl;
|
||||
std::string loader = meta.toPacked();
|
||||
long long int newHPos = F.addHeader(loader);
|
||||
if (!newHPos){
|
||||
if ( !newHPos){
|
||||
std::cerr << "Failure appending new header. Cancelling." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
@ -117,9 +135,9 @@ namespace Converters{
|
|||
}else{
|
||||
return -1;
|
||||
}
|
||||
}//DTSCFix
|
||||
} //DTSCFix
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/// Entry point for FLV2DTSC, simply calls Converters::FLV2DTSC().
|
||||
int main(int argc, char ** argv){
|
||||
|
@ -127,4 +145,4 @@ int main(int argc, char ** argv){
|
|||
conf.addOption("filename", JSON::fromString("{\"arg_num\":1, \"arg\":\"string\", \"help\":\"Filename of the file to attempt to fix.\"}"));
|
||||
conf.parseArgs(argc, argv);
|
||||
return Converters::DTSCFix(conf);
|
||||
}//main
|
||||
} //main
|
||||
|
|
|
@ -17,65 +17,67 @@
|
|||
#include <mist/config.h>
|
||||
|
||||
/// Holds all code that converts filetypes to/from to DTSC.
|
||||
namespace Converters{
|
||||
namespace Converters {
|
||||
|
||||
/// Reads FLV from STDIN, outputs DTSC to STDOUT.
|
||||
int FLV2DTSC() {
|
||||
int FLV2DTSC(){
|
||||
FLV::Tag FLV_in; // Temporary storage for incoming FLV data.
|
||||
JSON::Value meta_out; // Storage for outgoing header data.
|
||||
JSON::Value pack_out; // Storage for outgoing data.
|
||||
std::stringstream prebuffer; // Temporary buffer before sending real data
|
||||
bool sending = false;
|
||||
unsigned int counter = 0;
|
||||
|
||||
while (!feof(stdin)){
|
||||
|
||||
while ( !feof(stdin)){
|
||||
if (FLV_in.FileLoader(stdin)){
|
||||
pack_out = FLV_in.toJSON(meta_out);
|
||||
if (pack_out.isNull()){continue;}
|
||||
if (!sending){
|
||||
if (pack_out.isNull()){
|
||||
continue;
|
||||
}
|
||||
if ( !sending){
|
||||
counter++;
|
||||
if (counter > 8){
|
||||
sending = true;
|
||||
meta_out["moreheader"] = 0LL;
|
||||
std::string packed_header = meta_out.toPacked();
|
||||
unsigned int size = htonl(packed_header.size());
|
||||
std::cout << std::string(DTSC::Magic_Header, 4) << std::string((char*)&size, 4) << packed_header;
|
||||
std::cout << std::string(DTSC::Magic_Header, 4) << std::string((char*) &size, 4) << packed_header;
|
||||
std::cout << prebuffer.rdbuf();
|
||||
prebuffer.str("");
|
||||
std::cerr << "Buffer done, starting real-time output..." << std::endl;
|
||||
}else{
|
||||
std::string packed_out = pack_out.toPacked();
|
||||
unsigned int size = htonl(packed_out.size());
|
||||
prebuffer << std::string(DTSC::Magic_Packet, 4) << std::string((char*)&size, 4) << packed_out;
|
||||
continue;//don't also write
|
||||
prebuffer << std::string(DTSC::Magic_Packet, 4) << std::string((char*) &size, 4) << packed_out;
|
||||
continue; //don't also write
|
||||
}
|
||||
}
|
||||
//simply write
|
||||
std::string packed_out = pack_out.toPacked();
|
||||
unsigned int size = htonl(packed_out.size());
|
||||
std::cout << std::string(DTSC::Magic_Packet, 4) << std::string((char*)&size, 4) << packed_out;
|
||||
std::cout << std::string(DTSC::Magic_Packet, 4) << std::string((char*) &size, 4) << packed_out;
|
||||
}
|
||||
}
|
||||
|
||||
// if the FLV input is very short, do output it correctly...
|
||||
if (!sending){
|
||||
if ( !sending){
|
||||
std::cerr << "EOF - outputting buffer..." << std::endl;
|
||||
meta_out["moreheader"] = 0LL;
|
||||
std::string packed_header = meta_out.toPacked();
|
||||
unsigned int size = htonl(packed_header.size());
|
||||
std::cout << std::string(DTSC::Magic_Header, 4) << std::string((char*)&size, 4) << packed_header;
|
||||
std::cout << std::string(DTSC::Magic_Header, 4) << std::string((char*) &size, 4) << packed_header;
|
||||
std::cout << prebuffer.rdbuf();
|
||||
}
|
||||
std::cerr << "Done! If you output this data to a file, don't forget to run MistDTSCFix next." << std::endl;
|
||||
|
||||
return 0;
|
||||
}//FLV2DTSC
|
||||
|
||||
};//Buffer namespace
|
||||
return 0;
|
||||
} //FLV2DTSC
|
||||
|
||||
}
|
||||
|
||||
/// Entry point for FLV2DTSC, simply calls Converters::FLV2DTSC().
|
||||
int main(int argc, char ** argv){
|
||||
Util::Config conf = Util::Config(argv[0], PACKAGE_VERSION);
|
||||
conf.parseArgs(argc, argv);
|
||||
return Converters::FLV2DTSC();
|
||||
}//main
|
||||
} //main
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue