Finish splitting controller into multiple files, universalised coding style across all files.

This commit is contained in:
Thulinma 2012-12-12 20:16:53 +01:00
parent 0db5f60b95
commit 0920b3259b
30 changed files with 1616 additions and 1246 deletions

View file

@ -11,14 +11,16 @@
/// Debugging tool for AMF data.
/// Expects AMF data through stdin, outputs human-readable information to stderr.
int main(int argc, char ** argv) {
int main(int argc, char ** argv){
Util::Config conf = Util::Config(argv[0], PACKAGE_VERSION);
conf.parseArgs(argc, argv);
std::string temp;
while (std::cin.good()){temp += std::cin.get();}//read all of std::cin to temp
temp.erase(temp.size()-1, 1);//strip the invalid last character
AMF::Object amfdata = AMF::parse(temp);//parse temp into an AMF::Object
amfdata.Print();//pretty-print the object
while (std::cin.good()){
temp += std::cin.get();
} //read all of std::cin to temp
temp.erase(temp.size() - 1, 1); //strip the invalid last character
AMF::Object amfdata = AMF::parse(temp); //parse temp into an AMF::Object
amfdata.Print(); //pretty-print the object
return 0;
}

View file

@ -36,15 +36,21 @@ int main(int argc, char ** argv){
long long unsigned int bps = 0;
F.seekNext();
while (!F.getJSON().isNull()){
while ( !F.getJSON().isNull()){
std::cout << F.getJSON().toPrettyString() << std::endl;
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;
@ -52,22 +58,34 @@ int main(int argc, char ** argv){
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){
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;
@ -76,7 +94,7 @@ int main(int argc, char ** argv){
}
std::cout << std::endl << "Summary:" << std::endl;
meta["length"] = (long long int)((nowpack - firstpack)/1000);
meta["length"] = (long long int)((nowpack - firstpack) / 1000);
if (meta.isMember("audio")){
meta["audio"]["bps"] = (long long int)(totalaudio / ((lastaudio - firstpack) / 1000));
std::cout << " Audio: " << meta["audio"]["codec"].asString() << std::endl;
@ -96,4 +114,4 @@ int main(int argc, char ** argv){
std::cout << " B-frames: " << bfrm_min << " - " << bfrm_max << std::endl;
}
return 0;
}//main
} //main

View file

@ -15,20 +15,20 @@
#include <mist/config.h>
/// Reads FLV from stdin and outputs human-readable information to stderr.
int main(int argc, char ** argv) {
int main(int argc, char ** argv){
Util::Config conf = Util::Config(argv[0], PACKAGE_VERSION);
conf.parseArgs(argc, argv);
FLV::Tag FLV_in; // Temporary storage for incoming FLV data.
std::ofstream vData( "vData" );
std::ofstream aData( "aData" );
while (!feof(stdin)){
std::ofstream vData("vData");
std::ofstream aData("aData");
while ( !feof(stdin)){
if (FLV_in.FileLoader(stdin)){
std::cout << "Tag: " << FLV_in.tagType() << "\n\tTime: " << FLV_in.tagTime() << std::endl;
if( FLV_in.data[0] == 0x08 ) {//Audio
aData.write( FLV_in.data + 13, FLV_in.len - 17 );
if (FLV_in.data[0] == 0x08){ //Audio
aData.write(FLV_in.data + 13, FLV_in.len - 17);
}
if( FLV_in.data[0] == 0x09 ) {//Video
vData.write( FLV_in.data + 16, FLV_in.len - 20 );
if (FLV_in.data[0] == 0x09){ //Video
vData.write(FLV_in.data + 16, FLV_in.len - 20);
}
}
}

View file

@ -12,21 +12,23 @@
/// Debugging tool for MP4 data.
/// Expects MP4 data through stdin, outputs human-readable information to stderr.
int main(int argc, char ** argv) {
int main(int argc, char ** argv){
Util::Config conf = Util::Config(argv[0], PACKAGE_VERSION);
conf.parseArgs(argc, argv);
std::string temp;
while (std::cin.good()){temp += std::cin.get();}//read all of std::cin to temp
temp.erase(temp.size()-1, 1);//strip the invalid last character
while (std::cin.good()){
temp += std::cin.get();
} //read all of std::cin to temp
temp.erase(temp.size() - 1, 1); //strip the invalid last character
MP4::Box mp4data;
while (mp4data.read(temp)){
std::cerr << mp4data.toPrettyString(0) << std::endl;
if( mp4data.isType( "mdat" ) ) {
if (mp4data.isType("mdat")){
std::ofstream oFile;
oFile.open( "mdat" );
oFile << std::string( mp4data.payload(), mp4data.payloadSize() );
oFile.open("mdat");
oFile << std::string(mp4data.payload(), mp4data.payloadSize());
oFile.close();
}
}

View file

@ -30,9 +30,11 @@ int Detail = 0;
/// Automatically skips 3073 bytes of handshake data.
int main(int argc, char ** argv){
Util::Config conf = Util::Config(argv[0], PACKAGE_VERSION);
conf.addOption("detail", JSON::fromString("{\"arg_num\":1, \"arg\":\"integer\", \"default\":0, \"help\":\"Bitmask, 1 = Reconstruct, 2 = Explicit media info, 4 = Verbose chunks\"}"));
conf.addOption("detail",
JSON::fromString(
"{\"arg_num\":1, \"arg\":\"integer\", \"default\":0, \"help\":\"Bitmask, 1 = Reconstruct, 2 = Explicit media info, 4 = Verbose chunks\"}"));
conf.parseArgs(argc, argv);
Detail = conf.getInteger("detail");
if (Detail > 0){
fprintf(stderr, "Detail level set:\n");
@ -49,36 +51,38 @@ int main(int argc, char ** argv){
}
std::string inbuffer;
while (std::cin.good()){inbuffer += std::cin.get();}//read all of std::cin to temp
inbuffer.erase(0, 3073);//strip the handshake part
while (std::cin.good()){
inbuffer += std::cin.get();
} //read all of std::cin to temp
inbuffer.erase(0, 3073); //strip the handshake part
RTMPStream::Chunk next;
FLV::Tag F;//FLV holder
FLV::Tag F; //FLV holder
AMF::Object amfdata("empty", AMF::AMF0_DDV_CONTAINER);
AMF::Object3 amf3data("empty", AMF::AMF3_DDV_CONTAINER);
while (next.Parse(inbuffer)){
if ((Detail & DETAIL_VERBOSE) == DETAIL_VERBOSE){
fprintf(stderr, "Chunk info: [%#2X] CS ID %u, timestamp %u, len %u, type ID %u, Stream ID %u\n", next.headertype, next.cs_id, next.timestamp, next.len, next.msg_type_id, next.msg_stream_id);
fprintf(stderr, "Chunk info: [%#2X] CS ID %u, timestamp %u, len %u, type ID %u, Stream ID %u\n", next.headertype, next.cs_id, next.timestamp,
next.len, next.msg_type_id, next.msg_stream_id);
}
switch (next.msg_type_id){
case 0://does not exist
case 0: //does not exist
fprintf(stderr, "Error chunk - %i, %i, %i, %i, %i\n", next.cs_id, next.timestamp, next.real_len, next.len_left, next.msg_stream_id);
//return 0;
break;//happens when connection breaks unexpectedly
case 1://set chunk size
break; //happens when connection breaks unexpectedly
case 1: //set chunk size
RTMPStream::chunk_rec_max = ntohl(*(int*)next.data.c_str());
fprintf(stderr, "CTRL: Set chunk size: %i\n", RTMPStream::chunk_rec_max);
break;
case 2://abort message - we ignore this one
case 2: //abort message - we ignore this one
fprintf(stderr, "CTRL: Abort message: %i\n", ntohl(*(int*)next.data.c_str()));
//4 bytes of stream id to drop
break;
case 3://ack
case 3: //ack
RTMPStream::snd_window_at = ntohl(*(int*)next.data.c_str());
fprintf(stderr, "CTRL: Acknowledgement: %i\n", RTMPStream::snd_window_at);
break;
case 4:{
case 4: {
short int ucmtype = ntohs(*(short int*)next.data.c_str());
switch (ucmtype){
case 0:
@ -106,8 +110,9 @@ int main(int argc, char ** argv){
fprintf(stderr, "CTRL: User control message: UNKNOWN %hu - %u\n", ucmtype, ntohl(*(unsigned int*)(next.data.c_str()+2)));
break;
}
} break;
case 5://window size of other end
}
break;
case 5: //window size of other end
RTMPStream::rec_window_size = ntohl(*(int*)next.data.c_str());
RTMPStream::rec_window_at = RTMPStream::rec_cnt;
fprintf(stderr, "CTRL: Window size: %i\n", RTMPStream::rec_window_size);
@ -147,19 +152,20 @@ int main(int argc, char ** argv){
case 16:
fprintf(stderr, "Received AFM3 shared object\n");
break;
case 17:{
case 17: {
fprintf(stderr, "Received AFM3 command message:\n");
char soort = next.data[0];
next.data = next.data.substr(1);
if (soort == 0){
amfdata = AMF::parse(next.data);
std::cerr << amfdata.Print() << std::endl;
}else{
amf3data = AMF::parse3(next.data);
amf3data.Print();
}
} break;
case 18:{
char soort = next.data[0];
next.data = next.data.substr(1);
if (soort == 0){
amfdata = AMF::parse(next.data);
std::cerr << amfdata.Print() << std::endl;
}else{
amf3data = AMF::parse3(next.data);
amf3data.Print();
}
}
break;
case 18: {
fprintf(stderr, "Received AFM0 data message (metadata):\n");
amfdata = AMF::parse(next.data);
amfdata.Print();
@ -167,15 +173,17 @@ int main(int argc, char ** argv){
F.ChunkLoader(next);
std::cout.write(F.data, F.len);
}
} break;
}
break;
case 19:
fprintf(stderr, "Received AFM0 shared object\n");
break;
case 20:{//AMF0 command message
case 20: { //AMF0 command message
fprintf(stderr, "Received AFM0 command message:\n");
amfdata = AMF::parse(next.data);
std::cerr << amfdata.Print() << std::endl;
} break;
}
break;
case 22:
fprintf(stderr, "Received aggregate message\n");
break;
@ -183,8 +191,8 @@ int main(int argc, char ** argv){
fprintf(stderr, "Unknown chunk received! Probably protocol corruption, stopping parsing of incoming data.\n");
return 1;
break;
}//switch for type of chunk
}//while chunk parsed
} //switch for type of chunk
} //while chunk parsed
fprintf(stderr, "No more readable data\n");
return 0;
}//main
} //main