From c62b4bf381c6a158c84cad7fb63f4f9c0fb440fd Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 8 Sep 2015 18:32:12 +0200 Subject: [PATCH] Split input handling into separate convert and serve functions. --- src/input/input.cpp | 116 +++++++++++++++++++++++--------------------- src/input/input.h | 3 ++ 2 files changed, 65 insertions(+), 54 deletions(-) diff --git a/src/input/input.cpp b/src/input/input.cpp index 01f99fc4..9ba9d7ad 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -116,65 +116,73 @@ namespace Mist { parseHeader(); if (!config->getString("streamname").size()){ - //check filename for no - - if (config->getString("output") != "-"){ - std::string filename = config->getString("output"); - if (filename.size() < 5 || filename.substr(filename.size() - 5) != ".dtsc"){ - filename += ".dtsc"; - } - //output to dtsc - DTSC::Meta newMeta = myMeta; - newMeta.reset(); - std::ofstream file(filename.c_str()); - long long int bpos = 0; - seek(0); - getNext(); - while (thisPacket){ - newMeta.updatePosOverride(thisPacket, bpos); - file.write(thisPacket.getData(), thisPacket.getDataLen()); - bpos += thisPacket.getDataLen(); - getNext(); - } - //close file - file.close(); - //create header - file.open((filename+".dtsh").c_str()); - file << newMeta.toJSON().toNetPacked(); - file.close(); - }else{ - DEBUG_MSG(DLVL_FAIL,"No filename specified, exiting"); - } + convert(); }else{ - char userPageName[NAME_BUFFER_SIZE]; - snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str()); - userPage.init(userPageName, PLAY_EX_SIZE, true); - if (!isBuffer){ - for (std::map::iterator it = myMeta.tracks.begin(); it != myMeta.tracks.end(); it++){ - bufferFrame(it->first, 1); - } - } - - DEBUG_MSG(DLVL_DEVEL,"Input for stream %s started", streamName.c_str()); - - long long int activityCounter = Util::bootSecs(); - while ((Util::bootSecs() - activityCounter) < 10 && config->is_active){//10 second timeout - Util::wait(1000); - removeUnused(); - userPage.parseEach(callbackWrapper); - if (userPage.amount){ - activityCounter = Util::bootSecs(); - DEBUG_MSG(DLVL_INSANE, "Connected users: %d", userPage.amount); - }else{ - DEBUG_MSG(DLVL_INSANE, "Timer running"); - } - } - finish(); - DEBUG_MSG(DLVL_DEVEL,"Input for stream %s closing clean", streamName.c_str()); - //end player functionality + serve(); } return 0; } + void Input::convert(){ + //check filename for no - + if (config->getString("output") != "-"){ + std::string filename = config->getString("output"); + if (filename.size() < 5 || filename.substr(filename.size() - 5) != ".dtsc"){ + filename += ".dtsc"; + } + //output to dtsc + DTSC::Meta newMeta = myMeta; + newMeta.reset(); + std::ofstream file(filename.c_str()); + long long int bpos = 0; + seek(0); + getNext(); + while (thisPacket){ + newMeta.updatePosOverride(thisPacket, bpos); + file.write(thisPacket.getData(), thisPacket.getDataLen()); + bpos += thisPacket.getDataLen(); + getNext(); + } + //close file + file.close(); + //create header + file.open((filename+".dtsh").c_str()); + file << newMeta.toJSON().toNetPacked(); + file.close(); + }else{ + DEBUG_MSG(DLVL_FAIL,"No filename specified, exiting"); + } + } + + void Input::serve(){ + char userPageName[NAME_BUFFER_SIZE]; + snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str()); + userPage.init(userPageName, PLAY_EX_SIZE, true); + if (!isBuffer){ + for (std::map::iterator it = myMeta.tracks.begin(); it != myMeta.tracks.end(); it++){ + bufferFrame(it->first, 1); + } + } + + DEBUG_MSG(DLVL_DEVEL,"Input for stream %s started", streamName.c_str()); + + long long int activityCounter = Util::bootSecs(); + while ((Util::bootSecs() - activityCounter) < 10 && config->is_active){//10 second timeout + Util::wait(1000); + removeUnused(); + userPage.parseEach(callbackWrapper); + if (userPage.amount){ + activityCounter = Util::bootSecs(); + DEBUG_MSG(DLVL_INSANE, "Connected users: %d", userPage.amount); + }else{ + DEBUG_MSG(DLVL_INSANE, "Timer running"); + } + } + finish(); + DEBUG_MSG(DLVL_DEVEL,"Input for stream %s closing clean", streamName.c_str()); + //end player functionality + } + void Input::finish(){ for( std::map >::iterator it = pageCounter.begin(); it != pageCounter.end(); it++){ for (std::map::iterator it2 = it->second.begin(); it2 != it->second.end(); it2++){ diff --git a/src/input/input.h b/src/input/input.h index 29ffe302..725051fe 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -36,6 +36,9 @@ namespace Mist { virtual void removeUnused(); virtual void trackSelect(std::string trackSpec){}; virtual void userCallback(char * data, size_t len, unsigned int id); + + void serve(); + void convert(); void parseHeader(); bool bufferFrame(unsigned int track, unsigned int keyNum);