Changed getStream/getLive/getVod functions to return a bool instead of a socket.

This commit is contained in:
Thulinma 2014-04-18 14:23:02 +02:00
parent 4e0fe2e6e5
commit efa5d67231
2 changed files with 18 additions and 9 deletions

View file

@ -5,6 +5,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <semaphore.h>
#include "json.h" #include "json.h"
#include "stream.h" #include "stream.h"
#include "procs.h" #include "procs.h"
@ -59,7 +60,7 @@ void Util::Stream::sanitizeName(std::string & streamname){
} }
} }
Socket::Connection Util::Stream::getLive(std::string streamname){ bool Util::Stream::getLive(std::string streamname){
JSON::Value ServConf = JSON::fromFile(getTmpFolder() + "streamlist"); JSON::Value ServConf = JSON::fromFile(getTmpFolder() + "streamlist");
static unsigned long long counter = 0; static unsigned long long counter = 0;
std::stringstream name; std::stringstream name;
@ -82,11 +83,11 @@ Socket::Connection Util::Stream::getLive(std::string streamname){
}else if(pid == -1){ }else if(pid == -1){
perror("Could not start vod"); perror("Could not start vod");
} }
return Socket::Connection(); return true;
} }
/// Starts a process for a VoD stream. /// Starts a process for a VoD stream.
Socket::Connection Util::Stream::getVod(std::string filename, std::string streamname){ bool Util::Stream::getVod(std::string filename, std::string streamname){
static unsigned long long counter = 0; static unsigned long long counter = 0;
std::stringstream name; std::stringstream name;
name << "MistInDTSC " << (counter++); name << "MistInDTSC " << (counter++);
@ -109,14 +110,22 @@ Socket::Connection Util::Stream::getVod(std::string filename, std::string stream
}else if(pid == -1){ }else if(pid == -1){
perror("Could not start vod"); perror("Could not start vod");
} }
return Socket::Connection(); return true;
} }
/// Probe for available streams. Currently first VoD, then Live. /// Probe for available streams. Currently first VoD, then Live.
Socket::Connection Util::Stream::getStream(std::string streamname){ bool Util::Stream::getStream(std::string streamname){
sanitizeName(streamname); sanitizeName(streamname);
JSON::Value ServConf = JSON::fromFile(getTmpFolder() + "streamlist"); JSON::Value ServConf = JSON::fromFile(getTmpFolder() + "streamlist");
if (ServConf["streams"].isMember(streamname)){ if (ServConf["streams"].isMember(streamname)){
//check if the stream is already active, if yes, don't re-activate
sem_t * playerLock = sem_open(std::string("/lock_" + streamname).c_str(), O_CREAT | O_RDWR, ACCESSPERMS, 1);
if (sem_trywait(playerLock) == -1){
sem_close(playerLock);
return true;
}
sem_post(playerLock);
sem_close(playerLock);
if (ServConf["streams"][streamname]["source"].asString()[0] == '/'){ if (ServConf["streams"][streamname]["source"].asString()[0] == '/'){
return getVod(ServConf["streams"][streamname]["source"].asString(), streamname); return getVod(ServConf["streams"][streamname]["source"].asString(), streamname);
}else{ }else{
@ -124,7 +133,7 @@ Socket::Connection Util::Stream::getStream(std::string streamname){
} }
} }
DEBUG_MSG(DLVL_ERROR, "Stream not found: %s", streamname.c_str()); DEBUG_MSG(DLVL_ERROR, "Stream not found: %s", streamname.c_str());
return Socket::Connection(); return false;
} }
/// Create a stream on the system. /// Create a stream on the system.

View file

@ -10,9 +10,9 @@ namespace Util {
class Stream{ class Stream{
public: public:
static void sanitizeName(std::string & streamname); static void sanitizeName(std::string & streamname);
static Socket::Connection getLive(std::string streamname); static bool getLive(std::string streamname);
static Socket::Connection getVod(std::string filename, std::string streamname); static bool getVod(std::string filename, std::string streamname);
static Socket::Connection getStream(std::string streamname); static bool getStream(std::string streamname);
static Socket::Server makeLive(std::string streamname); static Socket::Server makeLive(std::string streamname);
}; };
} }