Merge branch 'development' into LTS_development

# Conflicts:
#	src/input/input.cpp
This commit is contained in:
Thulinma 2017-07-26 17:01:52 +02:00
commit 6b1db9d0ec
11 changed files with 71 additions and 66 deletions

View file

@ -142,5 +142,5 @@ static inline void show_stackframe(){}
#define SHM_STREAM_ENCRYPT "MstCRYP%s" //%s stream name #define SHM_STREAM_ENCRYPT "MstCRYP%s" //%s stream name
#define SIMUL_TRACKS 10 #define SIMUL_TRACKS 20

View file

@ -35,6 +35,47 @@ namespace HTTP{
/// Clears all extra/override headers for outgoing requests. /// Clears all extra/override headers for outgoing requests.
void Downloader::clearHeaders(){extraHeaders.clear();} void Downloader::clearHeaders(){extraHeaders.clear();}
/// Returns a reference to the internal HTTP class instance.
Parser &Downloader::getHTTP(){return H;}
/// Returns a reference to the internal Socket::Connection class instance.
Socket::Connection &Downloader::getSocket(){return S;}
/// Sends a request for the given URL, does no waiting.
void Downloader::doRequest(const HTTP::URL &link){
if (link.protocol != "http"){
FAIL_MSG("Protocol not supported: %s", link.protocol.c_str());
return;
}
INFO_MSG("Retrieving %s", link.getUrl().c_str());
H.Clean();
// Reconnect if needed
if (!S || link.host != connectedHost || link.getPort() != connectedPort){
S.close();
connectedHost = link.host;
connectedPort = link.getPort();
S = Socket::Connection(connectedHost, connectedPort, true);
}
H.url = "/" + link.path;
if (link.args.size()){H.url += "?" + link.args;}
if (link.port.size()){
H.SetHeader("Host", link.host + ":" + link.port);
}else{
H.SetHeader("Host", link.host);
}
H.SetHeader("User-Agent", "MistServer " PACKAGE_VERSION);
H.SetHeader("X-Version", PACKAGE_VERSION);
H.SetHeader("Accept", "*/*");
if (extraHeaders.size()){
for (std::map<std::string, std::string>::iterator it = extraHeaders.begin();
it != extraHeaders.end(); ++it){
H.SetHeader(it->first, it->second);
}
}
H.SendRequest(S);
H.Clean();
}
/// Downloads the given URL into 'H', returns true on success. /// Downloads the given URL into 'H', returns true on success.
/// Makes at most 5 attempts, and will wait no longer than 5 seconds without receiving data. /// Makes at most 5 attempts, and will wait no longer than 5 seconds without receiving data.
bool Downloader::get(const HTTP::URL &link, uint8_t maxRecursiveDepth){ bool Downloader::get(const HTTP::URL &link, uint8_t maxRecursiveDepth){
@ -43,36 +84,9 @@ namespace HTTP{
FAIL_MSG("Protocol not supported: %s", link.protocol.c_str()); FAIL_MSG("Protocol not supported: %s", link.protocol.c_str());
return false; return false;
} }
INFO_MSG("Retrieving %s", link.getUrl().c_str());
unsigned int loop = 6; // max 5 attempts unsigned int loop = 6; // max 5 attempts
while (--loop){// loop while we are unsuccessful while (--loop){// loop while we are unsuccessful
H.Clean(); doRequest(link);
// Reconnect if needed
if (!S || link.host != connectedHost || link.getPort() != connectedPort){
S.close();
connectedHost = link.host;
connectedPort = link.getPort();
S = Socket::Connection(connectedHost, connectedPort, true);
}
H.url = "/" + link.path;
if (link.args.size()){H.url += "?" + link.args;}
if (link.port.size()){
H.SetHeader("Host", link.host + ":" + link.port);
}else{
H.SetHeader("Host", link.host);
}
H.SetHeader("User-Agent", "MistServer " PACKAGE_VERSION);
H.SetHeader("X-Version", PACKAGE_VERSION);
H.SetHeader("Accept", "*/*");
if (extraHeaders.size()){
for (std::map<std::string, std::string>::iterator it = extraHeaders.begin();
it != extraHeaders.end(); ++it){
H.SetHeader(it->first, it->second);
}
}
H.SendRequest(S);
H.Clean();
uint64_t reqTime = Util::bootSecs(); uint64_t reqTime = Util::bootSecs();
while (S && Util::bootSecs() < reqTime + 5){ while (S && Util::bootSecs() < reqTime + 5){
// No data? Wait for a second or so. // No data? Wait for a second or so.

View file

@ -6,6 +6,7 @@ namespace HTTP{
public: public:
Downloader(){progressCallback = 0;} Downloader(){progressCallback = 0;}
std::string &data(); std::string &data();
void doRequest(const HTTP::URL &link);
bool get(const std::string &link); bool get(const std::string &link);
bool get(const HTTP::URL &link, uint8_t maxRecursiveDepth = 6); bool get(const HTTP::URL &link, uint8_t maxRecursiveDepth = 6);
std::string getHeader(const std::string &headerName); std::string getHeader(const std::string &headerName);
@ -15,6 +16,8 @@ namespace HTTP{
bool (*progressCallback)(); ///< Called every time the socket stalls, up to 4X per second. bool (*progressCallback)(); ///< Called every time the socket stalls, up to 4X per second.
void setHeader(const std::string &name, const std::string &val); void setHeader(const std::string &name, const std::string &val);
void clearHeaders(); void clearHeaders();
Parser &getHTTP();
Socket::Connection &getSocket();
private: private:
std::map<std::string, std::string> extraHeaders; ///< Holds extra headers to sent with request std::map<std::string, std::string> extraHeaders; ///< Holds extra headers to sent with request

View file

@ -184,13 +184,20 @@ namespace Mist {
} }
int Input::run() { int Input::run() {
myMeta.sourceURI = config->getString("input");
if (streamStatus){streamStatus.mapped[0] = STRMSTAT_BOOT;} if (streamStatus){streamStatus.mapped[0] = STRMSTAT_BOOT;}
checkHeaderTimes(config->getString("input")); checkHeaderTimes(config->getString("input"));
if (!readHeader()) { if (needHeader()){
std::cerr << "Reading header for " << config->getString("input") << " failed." << std::endl; uint64_t timer = Util::bootMS();
return 0; bool headerSuccess = readHeader();
if (!headerSuccess) {
std::cerr << "Reading header for " << config->getString("input") << " failed." << std::endl;
return 0;
}else{
timer = Util::bootMS() - timer;
DEBUG_MSG(DLVL_DEVEL, "Read header for '%s' in %llums", streamName.c_str(), timer);
}
} }
myMeta.sourceURI = config->getString("input");
if (myMeta.vod){ if (myMeta.vod){
parseHeader(); parseHeader();
MEDIUM_MSG("Header parsed, %lu tracks", myMeta.tracks.size()); MEDIUM_MSG("Header parsed, %lu tracks", myMeta.tracks.size());
@ -629,7 +636,7 @@ namespace Mist {
return false; return false;
} }
//Update keynum to point to the corresponding page //Update keynum to point to the corresponding page
uint64_t bufferTimer = Util::getMS(); uint64_t bufferTimer = Util::bootMS();
INFO_MSG("Loading key %u from page %lu", keyNum, (--(nProxy.pagesByTrack[track].upper_bound(keyNum)))->first); INFO_MSG("Loading key %u from page %lu", keyNum, (--(nProxy.pagesByTrack[track].upper_bound(keyNum)))->first);
keyNum = (--(nProxy.pagesByTrack[track].upper_bound(keyNum)))->first; keyNum = (--(nProxy.pagesByTrack[track].upper_bound(keyNum)))->first;
if (!bufferStart(track, keyNum)) { if (!bufferStart(track, keyNum)) {
@ -664,7 +671,7 @@ namespace Mist {
getNext(); getNext();
} }
bufferFinalize(track); bufferFinalize(track);
bufferTimer = Util::getMS() - bufferTimer; bufferTimer = Util::bootMS() - bufferTimer;
DEBUG_MSG(DLVL_DEVEL, "Done buffering page %d (%llu packets, %llu bytes) for track %d in %llums", keyNum, packCounter, byteCounter, track, bufferTimer); DEBUG_MSG(DLVL_DEVEL, "Done buffering page %d (%llu packets, %llu bytes) for track %d in %llums", keyNum, packCounter, byteCounter, track, bufferTimer);
pageCounter[track][keyNum] = 15; pageCounter[track][keyNum] = 15;
return true; return true;
@ -690,7 +697,6 @@ namespace Mist {
playing = -1; playing = -1;
playUntil = until; playUntil = until;
initialTime = 0; initialTime = 0;
benchMark = Util::getMS();
} }
void Input::playOnce() { void Input::playOnce() {
@ -698,7 +704,6 @@ namespace Mist {
playing = 1; playing = 1;
} }
++playing; ++playing;
benchMark = Util::getMS();
} }
void Input::quitPlay() { void Input::quitPlay() {

View file

@ -29,6 +29,7 @@ namespace Mist {
static void callbackWrapper(char * data, size_t len, unsigned int id); static void callbackWrapper(char * data, size_t len, unsigned int id);
virtual bool checkArguments() = 0; virtual bool checkArguments() = 0;
virtual bool readHeader() = 0; virtual bool readHeader() = 0;
virtual bool needHeader(){return !readExistingHeader();}
virtual bool preRun(){return true;} virtual bool preRun(){return true;}
virtual bool readExistingHeader(); virtual bool readExistingHeader();
virtual bool atKeyFrame(); virtual bool atKeyFrame();
@ -59,7 +60,6 @@ namespace Mist {
int initialTime; int initialTime;
int playing; int playing;
unsigned int playUntil; unsigned int playUntil;
unsigned int benchMark;
bool isBuffer; bool isBuffer;
uint64_t activityCounter; uint64_t activityCounter;

View file

@ -1030,16 +1030,5 @@ namespace Mist {
return true; return true;
} }
bool inputBuffer::readHeader() {
return true;
}
void inputBuffer::getNext(bool smart) {}
void inputBuffer::seek(int seekTime) {}
void inputBuffer::trackSelect(std::string trackSpec) {}
} }

View file

@ -24,12 +24,13 @@ namespace Mist {
bool preRun(); bool preRun();
bool checkArguments(){return true;} bool checkArguments(){return true;}
void updateMeta(); void updateMeta();
bool readHeader(); bool readHeader(){return false;}
void getNext(bool smart = true); bool needHeader(){return false;}
void getNext(bool smart = true){}
void updateTrackMeta(unsigned long tNum); void updateTrackMeta(unsigned long tNum);
void updateMetaFromPage(unsigned long tNum, unsigned long pageNum); void updateMetaFromPage(unsigned long tNum, unsigned long pageNum);
void seek(int seekTime); void seek(int seekTime){}
void trackSelect(std::string trackSpec); void trackSelect(std::string trackSpec){}
bool removeKey(unsigned int tid); bool removeKey(unsigned int tid);
void removeUnused(); void removeUnused();
void eraseTrackDataPages(unsigned long tid); void eraseTrackDataPages(unsigned long tid);

View file

@ -223,19 +223,15 @@ namespace Mist {
return true; return true;
} }
bool inputDTSC::needHeader(){
if (!needsLock()){return false;}
return Input::needHeader();
}
bool inputDTSC::readHeader() { bool inputDTSC::readHeader() {
if (!needsLock()) {
return true;
}
if (!inFile) { if (!inFile) {
return false; return false;
} }
DTSC::File tmp(config->getString("input") + ".dtsh");
if (tmp) {
myMeta = tmp.getMeta();
DEBUG_MSG(DLVL_HIGH, "Meta read in with %lu tracks", myMeta.tracks.size());
return true;
}
if (inFile.getMeta().moreheader < 0 || inFile.getMeta().tracks.size() == 0) { if (inFile.getMeta().moreheader < 0 || inFile.getMeta().tracks.size() == 0) {
DEBUG_MSG(DLVL_FAIL, "Missing external header file"); DEBUG_MSG(DLVL_FAIL, "Missing external header file");
return false; return false;

View file

@ -13,6 +13,7 @@ namespace Mist {
void parseStreamHeader(); void parseStreamHeader();
bool checkArguments(); bool checkArguments();
bool readHeader(); bool readHeader();
bool needHeader();
void getNext(bool smart = true); void getNext(bool smart = true);
void seek(int seekTime); void seek(int seekTime);
void trackSelect(std::string trackSpec); void trackSelect(std::string trackSpec);

View file

@ -78,8 +78,6 @@ namespace Mist {
bool inputFLV::readHeader() { bool inputFLV::readHeader() {
if (!inFile){return false;} if (!inFile){return false;}
//See whether a separate header file exists.
if (readExistingHeader()){return true;}
//Create header file from FLV data //Create header file from FLV data
Util::fseek(inFile, 13, SEEK_SET); Util::fseek(inFile, 13, SEEK_SET);
AMF::Object amf_storage; AMF::Object amf_storage;

View file

@ -51,8 +51,6 @@ namespace Mist {
bool inputMP3::readHeader() { bool inputMP3::readHeader() {
if (!inFile){return false;} if (!inFile){return false;}
//See whether a separate header file exists.
if (readExistingHeader()){return true;}
myMeta = DTSC::Meta(); myMeta = DTSC::Meta();
myMeta.tracks[1].trackID = 1; myMeta.tracks[1].trackID = 1;
myMeta.tracks[1].type = "audio"; myMeta.tracks[1].type = "audio";