From 11ce47ace961c4eb04128d8e48a4824a43bda9cf Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 14 Sep 2016 19:46:27 +0200 Subject: [PATCH] Generalized DTSH header reading and writing of Inputs --- src/input/input_av.cpp | 13 +++---------- src/input/input_ismv.cpp | 10 ++-------- src/input/input_mp4.cpp | 13 ++++--------- src/input/input_ts.cpp | 15 ++++----------- 4 files changed, 13 insertions(+), 38 deletions(-) diff --git a/src/input/input_av.cpp b/src/input/input_av.cpp index 38577edc..399f1917 100644 --- a/src/input/input_av.cpp +++ b/src/input/input_av.cpp @@ -91,12 +91,8 @@ namespace Mist { bool inputAV::readHeader() { //See whether a separate header file exists. - DTSC::File tmp(config->getString("input") + ".dtsh"); - if (tmp){ - myMeta = tmp.getMeta(); - return true; - } - + if (readExistingHeader()){return true;} + myMeta.tracks.clear(); myMeta.live = false; myMeta.vod = true; @@ -204,10 +200,7 @@ namespace Mist { myMeta.live = false; myMeta.vod = true; - //store dtsc-style header file for faster processing, later - std::ofstream oFile(std::string(config->getString("input") + ".dtsh").c_str()); - oFile << myMeta.toJSON().toNetPacked(); - oFile.close(); + myMeta.toFile(config->getString("input") + ".dtsh"); seek(0); return true; diff --git a/src/input/input_ismv.cpp b/src/input/input_ismv.cpp index fb413ce3..390aa5b5 100644 --- a/src/input/input_ismv.cpp +++ b/src/input/input_ismv.cpp @@ -51,11 +51,7 @@ namespace Mist { return false; } //See whether a separate header file exists. - DTSC::File tmp(config->getString("input") + ".dtsh"); - if (tmp) { - myMeta = tmp.getMeta(); - return true; - } + if (readExistingHeader()){return true;} //parse ismv header fseek(inFile, 0, SEEK_SET); std::string ftyp; @@ -119,9 +115,7 @@ namespace Mist { } curBytePos = ftell(inFile); } - std::ofstream oFile(std::string(config->getString("input") + ".dtsh").c_str()); - oFile << myMeta.toJSON().toNetPacked(); - oFile.close(); + myMeta.toFile(config->getString("input") + ".dtsh"); return true; } diff --git a/src/input/input_mp4.cpp b/src/input/input_mp4.cpp index 955af8a3..8f640e93 100644 --- a/src/input/input_mp4.cpp +++ b/src/input/input_mp4.cpp @@ -273,13 +273,10 @@ namespace Mist { }//when at the end of the file //seek file to 0; fseeko(inFile,0,SEEK_SET); - + //See whether a separate header file exists. - DTSC::File tmpdtsh(config->getString("input") + ".dtsh"); - if (tmpdtsh){ - myMeta = tmpdtsh.getMeta(); - return true; - } + if (readExistingHeader()){return true;} + trackNo = 0; //Create header file from MP4 data while(!feof(inFile)){ @@ -560,9 +557,7 @@ namespace Mist { clearerr(inFile); //outputting dtsh file - std::ofstream oFile(std::string(config->getString("input") + ".dtsh").c_str()); - oFile << myMeta.toJSON().toNetPacked(); - oFile.close(); + myMeta.toFile(config->getString("input") + ".dtsh"); return true; } diff --git a/src/input/input_ts.cpp b/src/input/input_ts.cpp index dbb5b2ff..ea51c939 100755 --- a/src/input/input_ts.cpp +++ b/src/input/input_ts.cpp @@ -233,14 +233,9 @@ namespace Mist { ///it writes the remaining metadata. ///\todo Find errors, perhaps parts can be made more modular bool inputTS::readHeader() { - if (!inFile) { - return false; - } - DTSC::File tmp(config->getString("input") + ".dtsh"); - if (tmp) { - myMeta = tmp.getMeta(); - return true; - } + if (!inFile){return false;} + //See whether a separate header file exists. + if (readExistingHeader()){return true;} TS::Packet packet;//to analyse and extract data fseek(inFile, 0, SEEK_SET);//seek to beginning @@ -261,9 +256,7 @@ namespace Mist { } fseek(inFile, 0, SEEK_SET); - std::ofstream oFile(std::string(config->getString("input") + ".dtsh").c_str()); - oFile << myMeta.toJSON().toNetPacked(); - oFile.close(); + myMeta.toFile(config->getString("input") + ".dtsh"); return true; } #endif