From fedd18146ee7d89fec763bd2cf9e5fb794a0e6e4 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 15 Sep 2016 15:56:17 +0200 Subject: [PATCH] Generalized DTSH header reading and writing of Inputs --- src/input/input.cpp | 14 ++++++++++++++ src/input/input.h | 1 + src/input/input_flv.cpp | 20 ++++---------------- src/input/input_mp3.cpp | 16 +++------------- src/input/input_ogg.cpp | 6 +----- 5 files changed, 23 insertions(+), 34 deletions(-) diff --git a/src/input/input.cpp b/src/input/input.cpp index c7230888..e31e8fc7 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -533,5 +533,19 @@ namespace Mist { void Input::quitPlay(){ playing = 0; } + + bool Input::readExistingHeader(){ + DTSC::File tmpdtsh(config->getString("input") + ".dtsh"); + if (!tmpdtsh){ + return false; + } + if (tmpdtsh.getMeta().version != DTSH_VERSION){ + INFO_MSG("Updating wrong version header file from version %llu to %llu", tmpdtsh.getMeta().version, DTSH_VERSION); + return false; + } + myMeta = tmpdtsh.getMeta(); + return true; + } + } diff --git a/src/input/input.h b/src/input/input.h index 25589429..996f4261 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -29,6 +29,7 @@ namespace Mist { static void callbackWrapper(char * data, size_t len, unsigned int id); virtual bool setup() = 0; virtual bool readHeader() = 0; + virtual bool readExistingHeader(); virtual bool atKeyFrame(); virtual void getNext(bool smart = true) {}; virtual void seek(int seekTime){}; diff --git a/src/input/input_flv.cpp b/src/input/input_flv.cpp index 66aa218b..53412c9c 100644 --- a/src/input/input_flv.cpp +++ b/src/input/input_flv.cpp @@ -49,23 +49,13 @@ namespace Mist { } bool inputFLV::readHeader() { - JSON::Value lastPack; - if (!inFile) { - return false; - } + if (!inFile){return false;} //See whether a separate header file exists. - DTSC::File tmp(config->getString("input") + ".dtsh"); - if (tmp){ - myMeta = tmp.getMeta(); - if (myMeta){ - return true; - }else{ - myMeta = DTSC::Meta(); - } - } + if (readExistingHeader()){return true;} //Create header file from FLV data fseek(inFile, 13, SEEK_SET); AMF::Object amf_storage; + JSON::Value lastPack; long long int lastBytePos = 13; while (!feof(inFile) && !FLV::Parse_Error){ if (tmpTag.FileLoader(inFile)){ @@ -80,9 +70,7 @@ namespace Mist { std::cerr << FLV::Error_Str << std::endl; return false; } - 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_mp3.cpp b/src/input/input_mp3.cpp index 7cf0b21d..3307923c 100644 --- a/src/input/input_mp3.cpp +++ b/src/input/input_mp3.cpp @@ -47,17 +47,9 @@ namespace Mist { } bool inputMP3::readHeader() { - if (!inFile) { - return false; - } + if (!inFile){return false;} //See whether a separate header file exists. - DTSC::File tmp(config->getString("input") + ".dtsh"); - if (tmp){ - myMeta = tmp.getMeta(); - if (myMeta){ - return true; - } - } + if (readExistingHeader()){return true;} myMeta = DTSC::Meta(); myMeta.tracks[1].trackID = 1; myMeta.tracks[1].type = "audio"; @@ -93,9 +85,7 @@ namespace Mist { fseek(inFile, 0, SEEK_SET); timestamp = 0; - 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_ogg.cpp b/src/input/input_ogg.cpp index 06e20f6a..c5a95237 100644 --- a/src/input/input_ogg.cpp +++ b/src/input/input_ogg.cpp @@ -222,11 +222,7 @@ namespace Mist { getNext(); } - std::ofstream oFile(std::string(config->getString("input") + ".dtsh").c_str()); - oFile << myMeta.toJSON().toNetPacked(); - oFile.close(); - - //myMeta.toPrettyString(std::cout); + myMeta.toFile(config->getString("input") + ".dtsh"); return true; }