Utils::Stream::getStream now actually works in all cases where it should, the way it should. ^_^

This commit is contained in:
Thulinma 2012-08-31 16:55:28 +02:00
parent 2afb88c8de
commit ed2021d01c
2 changed files with 34 additions and 24 deletions

View file

@ -1,8 +1,13 @@
/// \file stream.cpp /// \file stream.cpp
/// Utilities for handling streams. /// Utilities for handling streams.
#if DEBUG >= 4
#include <iostream>
#endif
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include "json.h"
#include "stream.h" #include "stream.h"
#include "procs.h" #include "procs.h"
#include "socket.h" #include "socket.h"
@ -23,31 +28,42 @@ void Util::Stream::sanitizeName(std::string & streamname){
} }
Socket::Connection Util::Stream::getLive(std::string streamname){ Socket::Connection Util::Stream::getLive(std::string streamname){
sanitizeName(streamname);
return Socket::Connection("/tmp/mist/stream_"+streamname); return Socket::Connection("/tmp/mist/stream_"+streamname);
} }
/// Starts a process for the VoD stream. /// Starts a process for a VoD stream.
Socket::Connection Util::Stream::getVod(std::string streamname){ Socket::Connection Util::Stream::getVod(std::string filename){
sanitizeName(streamname);
std::string filename = "/tmp/mist/vod_" + streamname;
/// \todo Is the name unique enough?
std::string name = "MistPlayer " + filename; std::string name = "MistPlayer " + filename;
const char *argv[] = { "MistPlayer", filename.c_str(), NULL }; const char *argv[] = { "MistPlayer", filename.c_str(), NULL };
int fdin = -1, fdout = -1; int fdin = -1, fdout = -1, fderr = fileno(stderr);
Util::Procs::StartPiped(name, (char **)argv, &fdin, &fdout, 0); Util::Procs::StartPiped(name, (char **)argv, &fdin, &fdout, &fderr);
// if StartPiped fails then fdin and fdout will be unmodified (-1) // if StartPiped fails then fdin and fdout will be unmodified (-1)
return Socket::Connection(fdin, fdout); return Socket::Connection(fdin, fdout);
} }
/// 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){ Socket::Connection Util::Stream::getStream(std::string streamname){
Socket::Connection vod = getVod(streamname); sanitizeName(streamname);
if (vod.connected()){ JSON::Value ServConf = JSON::fromFile("/tmp/mist/streamlist");
return vod; if (ServConf["streams"].isMember(streamname)){
if (ServConf["streams"][streamname]["channel"]["URL"].asString()[0] == '/'){
#if DEBUG >= 4
std::cerr << "Opening VoD stream from file " << ServConf["streams"][streamname]["channel"]["URL"].asString() << std::endl;
#endif
return getVod(ServConf["streams"][streamname]["channel"]["URL"].asString());
}else{
#if DEBUG >= 4
std::cerr << "Opening live stream " << streamname << std::endl;
#endif
return Socket::Connection("/tmp/mist/stream_"+streamname);
}
} }
return getLive(streamname); #if DEBUG >= 4
std::cerr << "Could not open stream " << streamname << " - stream not found" << std::endl;
#endif
return Socket::Connection();
} }
/// Create a stream on the system. /// Create a stream on the system.
/// Filters the streamname, removing invalid characters and /// Filters the streamname, removing invalid characters and
/// converting all letters to lowercase. /// converting all letters to lowercase.

View file

@ -7,17 +7,11 @@
namespace Util{ namespace Util{
class Stream{ class Stream{
/// Sanitize a streamname. public:
static void sanitizeName(std::string & streamname); static void sanitizeName(std::string & streamname);
public: static Socket::Connection getLive(std::string streamname);
/// Get a connection to a Live stream. static Socket::Connection getVod(std::string streamname);
static Socket::Connection getLive(std::string streamname); static Socket::Connection getStream(std::string streamname);
/// Get a connection to a VoD stream. static Socket::Server makeLive(std::string streamname);
static Socket::Connection getVod(std::string streamname);
/// Probe for available streams. Currently first VoD, then Live.
static Socket::Connection getStream(std::string streamname);
/// Create a Live stream on the system.
static Socket::Server makeLive(std::string streamname);
}; };
} }