Added Output::disconnect() call

This commit is contained in:
Thulinma 2018-03-20 14:22:04 +01:00
parent bea8678df9
commit 74baf8d4a4
2 changed files with 36 additions and 15 deletions

View file

@ -123,6 +123,7 @@ namespace Mist{
/// The standard implementation will set isInitialized to false and close the client connection, /// The standard implementation will set isInitialized to false and close the client connection,
/// thus causing the process to exit cleanly. /// thus causing the process to exit cleanly.
void Output::onFail(){ void Output::onFail(){
MEDIUM_MSG("onFail");
isInitialized = false; isInitialized = false;
wantRequest = true; wantRequest = true;
parseData= false; parseData= false;
@ -131,6 +132,7 @@ namespace Mist{
} }
void Output::initialize(){ void Output::initialize(){
MEDIUM_MSG("initialize");
if (isInitialized){ if (isInitialized){
return; return;
} }
@ -140,7 +142,6 @@ 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(); reconnect();
//if the connection failed, fail //if the connection failed, fail
if (streamName.size() < 1){ if (streamName.size() < 1){
@ -176,6 +177,21 @@ namespace Mist{
return false; return false;
} }
/// Disconnects from all stat/user-related shared structures.
void Output::disconnect(){
MEDIUM_MSG("disconnect");
if (statsPage.getData()){
statsPage.finish();
myConn.resetCounter();
}
if (nProxy.userClient.getData()){
nProxy.userClient.finish();
}
isInitialized = false;
myMeta.reset();
nProxy.metaPages.clear();
}
/// Connects or reconnects to the stream. /// Connects or reconnects to the stream.
/// Assumes streamName class member has been set already. /// Assumes streamName class member has been set already.
/// Will start input if not currently active, calls onFail() if this does not succeed. /// Will start input if not currently active, calls onFail() if this does not succeed.
@ -197,12 +213,7 @@ namespace Mist{
return; return;
} }
} }
if (statsPage.getData()){ disconnect();
statsPage.finish();
}
if (nProxy.userClient.getData()){
nProxy.userClient.finish();
}
nProxy.streamName = streamName; nProxy.streamName = streamName;
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());
@ -217,13 +228,13 @@ namespace Mist{
} }
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());
nProxy.metaPages.clear();
nProxy.metaPages[0].init(pageId, DEFAULT_STRM_PAGE_SIZE); nProxy.metaPages[0].init(pageId, DEFAULT_STRM_PAGE_SIZE);
if (!nProxy.metaPages[0].mapped){ if (!nProxy.metaPages[0].mapped){
FAIL_MSG("Could not connect to data for %s", streamName.c_str()); FAIL_MSG("Could not connect to data for %s", streamName.c_str());
onFail(); onFail();
return; return;
} }
isInitialized = true;
statsPage = IPC::sharedClient(SHM_STATISTICS, STAT_EX_SIZE, true); statsPage = IPC::sharedClient(SHM_STATISTICS, STAT_EX_SIZE, true);
stats(true); stats(true);
updateMeta(); updateMeta();
@ -245,7 +256,7 @@ namespace Mist{
void Output::selectDefaultTracks(){ void Output::selectDefaultTracks(){
if (!isInitialized){ if (!isInitialized){
initialize(); initialize();
return; if (!isInitialized){return;}
} }
//check which tracks don't actually exist //check which tracks don't actually exist
std::set<unsigned long> toRemove; std::set<unsigned long> toRemove;
@ -1058,8 +1069,11 @@ namespace Mist{
nProxy.userClient = IPC::sharedClient(userPageName, PLAY_EX_SIZE, true); nProxy.userClient = IPC::sharedClient(userPageName, PLAY_EX_SIZE, true);
if (!nProxy.userClient.getData()){ if (!nProxy.userClient.getData()){
WARN_MSG("Player connection failure - aborting output"); WARN_MSG("Player connection failure - aborting output");
onFinish(); if (!onFinish()){
myConn.close(); myConn.close();
}else{
disconnect();
}
return; return;
} }
} }
@ -1068,14 +1082,20 @@ namespace Mist{
waitForStreamPushReady(); waitForStreamPushReady();
if (!nProxy.userClient.isAlive()){ if (!nProxy.userClient.isAlive()){
WARN_MSG("Failed to wait for buffer, aborting incoming push"); WARN_MSG("Failed to wait for buffer, aborting incoming push");
onFinish(); if (!onFinish()){
myConn.close(); myConn.close();
}else{
disconnect();
}
return; return;
} }
}else{ }else{
INFO_MSG("Received disconnect request from input"); INFO_MSG("Received disconnect request from input");
onFinish(); if (!onFinish()){
myConn.close(); myConn.close();
}else{
disconnect();
}
return; return;
} }
} }

View file

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