Gave MistOut processes the ability to restart MistIn processes and/or reconnect to them as/if needed.

This commit is contained in:
Thulinma 2015-07-21 23:36:32 +02:00
parent fce83c903b
commit dc6b4ca0b9
2 changed files with 23 additions and 8 deletions

View file

@ -96,14 +96,26 @@ namespace Mist {
if (streamName.size() < 1){ if (streamName.size() < 1){
return; //abort - no stream to initialize... return; //abort - no stream to initialize...
} }
isInitialized = true;
reconnect();
selectDefaultTracks();
sought = false;
}
/// Connects or reconnects to the stream.
/// Assumes streamName class member has been set already.
/// Will start input if not currently active, calls onFail() if this does not succeed.
/// After assuring stream is online, clears metaPages, then sets metaPages[0], statsPage and userClient to (hopefully) valid handles.
/// Finally, calls updateMeta()
void Output::reconnect(){
if (!Util::startInput(streamName)){ if (!Util::startInput(streamName)){
DEBUG_MSG(DLVL_FAIL, "Opening stream failed - aborting initalization"); DEBUG_MSG(DLVL_FAIL, "Opening stream failed - aborting initalization");
onFail(); onFail();
return; return;
} }
isInitialized = true;
char pageId[NAME_BUFFER_SIZE]; char pageId[NAME_BUFFER_SIZE];
snprintf(pageId, NAME_BUFFER_SIZE, SHM_STREAM_INDEX, streamName.c_str()); snprintf(pageId, NAME_BUFFER_SIZE, SHM_STREAM_INDEX, streamName.c_str());
metaPages.clear();
metaPages[0].init(pageId, DEFAULT_META_PAGE_SIZE); metaPages[0].init(pageId, DEFAULT_META_PAGE_SIZE);
if (!metaPages[0].mapped){ if (!metaPages[0].mapped){
DEBUG_MSG(DLVL_FAIL, "Could not connect to server for %s\n", streamName.c_str()); DEBUG_MSG(DLVL_FAIL, "Could not connect to server for %s\n", streamName.c_str());
@ -113,14 +125,10 @@ namespace Mist {
statsPage = IPC::sharedClient(SHM_STATISTICS, STAT_EX_SIZE, true); statsPage = IPC::sharedClient(SHM_STATISTICS, STAT_EX_SIZE, true);
char userPageName[NAME_BUFFER_SIZE]; char userPageName[NAME_BUFFER_SIZE];
snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str()); snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str());
if (!userClient.getData()){ userClient = IPC::sharedClient(userPageName, PLAY_EX_SIZE, true);
userClient = IPC::sharedClient(userPageName, PLAY_EX_SIZE, true);
}
updateMeta(); updateMeta();
selectDefaultTracks();
sought = false;
} }
void Output::selectDefaultTracks(){ void Output::selectDefaultTracks(){
if (!isInitialized){ if (!isInitialized){
initialize(); initialize();
@ -282,7 +290,13 @@ namespace Mist {
if (!timeout){ if (!timeout){
DEBUG_MSG(DLVL_HIGH, "Requesting page with key %lu:%lld", trackId, keyNum); DEBUG_MSG(DLVL_HIGH, "Requesting page with key %lu:%lld", trackId, keyNum);
} }
if (timeout++ > 100){ ++timeout;
//if we've been waiting for this page for 3 seconds, reconnect to the stream - something might be going wrong...
if (timeout == 30){
DEVEL_MSG("Loading is taking longer than usual, reconnecting to stream %s...", streamName.c_str());
reconnect();
}
if (timeout > 100){
DEBUG_MSG(DLVL_FAIL, "Timeout while waiting for requested page %lld for track %lu. Aborting.", keyNum, trackId); DEBUG_MSG(DLVL_FAIL, "Timeout while waiting for requested page %lld for track %lu. Aborting.", keyNum, trackId);
curPage.erase(trackId); curPage.erase(trackId);
currKeyOpen.erase(trackId); currKeyOpen.erase(trackId);

View file

@ -59,6 +59,7 @@ namespace Mist {
virtual bool onFinish() { virtual bool onFinish() {
return false; return false;
} }
void reconnect();
virtual void initialize(); virtual void initialize();
virtual void sendHeader(); virtual void sendHeader();
virtual void onFail(); virtual void onFail();