From 7e82673a13b10667f090b0b4f8aab9439ee10cdc Mon Sep 17 00:00:00 2001
From: Thulinma <jaron@vietors.com>
Date: Thu, 5 May 2016 11:41:33 +0200
Subject: [PATCH] Minor fixes.

---
 lib/stream.h          |  2 --
 src/output/output.cpp | 24 ++++++++++++++----------
 src/output/output.h   |  2 --
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/lib/stream.h b/lib/stream.h
index 021d94f3..8f75abdd 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -11,8 +11,6 @@ namespace Util {
   void sanitizeName(std::string & streamname);
   bool streamAlive(std::string & streamname);
   bool startInput(std::string streamname, std::string filename = "", bool forkFirst = true);
-  /* roxlu-begin */
   int startRecording(std::string streamname);
-  /* roxlu-end */
   JSON::Value getStreamConfig(std::string streamname);
 }
diff --git a/src/output/output.cpp b/src/output/output.cpp
index ac81a026..88a23693 100644
--- a/src/output/output.cpp
+++ b/src/output/output.cpp
@@ -278,16 +278,6 @@ namespace Mist {
       onFail();
       return;
     }
-    if (!source.size()){
-      std::string strName = streamName;
-      Util::sanitizeName(strName);
-      IPC::sharedPage serverCfg("!mistConfig", DEFAULT_CONF_PAGE_SIZE, false, false); ///< Contains server configuration and capabilities
-      IPC::semaphore configLock("!mistConfLock", O_CREAT | O_RDWR, ACCESSPERMS, 1);
-      configLock.wait();
-      DTSC::Scan streamCfg = DTSC::Scan(serverCfg.mapped, serverCfg.len).getMember("streams").getMember(strName);
-      source = streamCfg.getMember("source").asString();
-      configLock.post();
-    }
     char pageId[NAME_BUFFER_SIZE];
     snprintf(pageId, NAME_BUFFER_SIZE, SHM_STREAM_INDEX, streamName.c_str());
     nProxy.metaPages.clear();
@@ -430,6 +420,20 @@ namespace Mist {
       for (std::map<unsigned int,DTSC::Track>::iterator trit = myMeta.tracks.begin(); trit != myMeta.tracks.end(); trit++){
         INSANE_MSG("Found track/codec: %s", trit->second.codec.c_str());
       }
+      static std::string source;
+      if (!source.size()){
+        IPC::sharedPage serverCfg(SHM_CONF, DEFAULT_CONF_PAGE_SIZE, false, false); ///< Contains server configuration and capabilities
+        IPC::semaphore configLock(SEM_CONF, O_CREAT | O_RDWR, ACCESSPERMS, 1);
+        configLock.wait();
+        std::string smp = streamName.substr(0, streamName.find_first_of("+ "));
+        //check if smp (everything before + or space) exists
+        DTSC::Scan streamCfg = DTSC::Scan(serverCfg.mapped, serverCfg.len).getMember("streams").getMember(smp);
+        if (streamCfg){
+          source = streamCfg.getMember("source").asString();
+        }
+        configLock.post();
+        configLock.close();
+      }
       if (!myMeta.tracks.size() && (source.find("dtsc://") == 0)){
         //Wait 5 seconds and try again. Keep a counter, try at most 3 times
         static int counter = 0;
diff --git a/src/output/output.h b/src/output/output.h
index f9443091..31af830b 100644
--- a/src/output/output.h
+++ b/src/output/output.h
@@ -108,8 +108,6 @@ namespace Mist {
       bool sought;///<If a seek has been done, this is set to true. Used for seeking on prepareNext().
       bool completeKeyReadyTimeOut;//a bool to see if there has been a keyframe TimeOut for complete keys in Live
     protected://these are to be messed with by child classes
-      std::string source;
-      
       virtual std::string getConnectedHost();
       virtual std::string getConnectedBinHost();