Analyser unification finished

This commit is contained in:
Thulinma 2017-04-16 16:20:12 +02:00
parent 051a8c826b
commit 945e6f2d1a
44 changed files with 1264 additions and 2903 deletions

View file

@ -1,71 +1,45 @@
#include <cstdio>
#include <cstdlib>
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <signal.h>
#include <string.h>
#include <string>
#include <unistd.h>
#include <vector>
#include <mist/config.h>
#include <mist/defines.h>
#include <mist/mp4.h>
#include <mist/timing.h>
#include <sys/sysinfo.h>
#include "analyser_mp4.h"
mp4Analyser::mp4Analyser(Util::Config config) : analysers(config) {
curPos = 0;
dataSize = 0;
void AnalyserMP4::init(Util::Config &conf){
Analyser::init(conf);
}
int mp4Analyser::doAnalyse() {
DEBUG_MSG(DLVL_DEVEL, "Read a box at position %d", curPos);
std::cerr << mp4Data.toPrettyString(0) << std::endl;
return dataSize; // endtime?
AnalyserMP4::AnalyserMP4(Util::Config &conf) : Analyser(conf){
curPos = prePos = 0;
}
bool mp4Analyser::hasInput() {
if (!std::cin.good()) { return false; }
mp4Buffer += std::cin.get();
dataSize++;
if (!std::cin.good()) {
mp4Buffer.erase(mp4Buffer.size() - 1, 1);
dataSize--;
bool AnalyserMP4::parsePacket(){
prePos = curPos;
// Read in smart bursts until we have enough data
while (isOpen() && mp4Buffer.size() < neededBytes()){
uint64_t needed = neededBytes();
mp4Buffer.reserve(needed);
for (uint64_t i = mp4Buffer.size(); i < needed; ++i){
mp4Buffer += std::cin.get();
++curPos;
if (!std::cin.good()){mp4Buffer.erase(mp4Buffer.size() - 1, 1);}
}
}
return true;
if (mp4Data.read(mp4Buffer)){
INFO_MSG("Read a box at position %d", prePos);
if (detail >= 2){std::cout << mp4Data.toPrettyString(0) << std::endl;}
///\TODO update mediaTime with the current timestamp
return true;
}
FAIL_MSG("Could not read box at position %llu", prePos);
return false;
}
bool mp4Analyser::packetReady() {
return mp4Data.read(mp4Buffer);
/// Calculates how many bytes we need to read a whole box.
uint64_t AnalyserMP4::neededBytes(){
if (mp4Buffer.size() < 4){return 4;}
uint64_t size = ntohl(((int *)mp4Buffer.data())[0]);
if (size != 1){return size;}
if (mp4Buffer.size() < 16){return 16;}
size = 0 + ntohl(((int *)mp4Buffer.data())[2]);
size <<= 32;
size += ntohl(((int *)mp4Buffer.data())[3]);
return size;
}
mp4Analyser::~mp4Analyser() {
INFO_MSG("Stopped parsing at position %d", curPos);
}
int main(int argc, char **argv) {
Util::Config conf = Util::Config(argv[0]);
conf.addOption("filter", JSON::fromString("{\"arg\":\"num\", \"short\":\"f\", \"long\":\"filter\", \"default\":0, \"help\":\"Only print info "
"about this tag type (8 = audio, 9 = video, 0 = all)\"}"));
conf.addOption("mode", JSON::fromString("{\"long\":\"mode\", \"arg\":\"string\", \"short\":\"m\", \"default\":\"analyse\", \"help\":\"What to "
"do with the stream. Valid modes are 'analyse', 'validate', 'output'.\"}"));
conf.addOption("filename",
JSON::fromString("{\"arg_num\":1, \"arg\":\"string\", \"default\":\"\", \"help\":\"Filename of the FLV file to analyse.\"}"));
conf.parseArgs(argc, argv);
mp4Analyser A(conf);
// FlvAnalyser A(conf);
A.Run();
return 0;
}