From 3ef44546a878eb02f4855a46812319fa1da47714 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 31 Aug 2012 16:55:28 +0200 Subject: [PATCH] Utils::Stream::getStream now actually works in all cases where it should, the way it should. ^_^ --- lib/stream.cpp | 40 ++++++++++++++++++++++++++++------------ lib/stream.h | 18 ++++++------------ 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/lib/stream.cpp b/lib/stream.cpp index cd2d563e..a091325c 100644 --- a/lib/stream.cpp +++ b/lib/stream.cpp @@ -1,8 +1,13 @@ /// \file stream.cpp /// Utilities for handling streams. +#if DEBUG >= 4 +#include +#endif + #include #include +#include "json.h" #include "stream.h" #include "procs.h" #include "socket.h" @@ -23,31 +28,42 @@ void Util::Stream::sanitizeName(std::string & streamname){ } Socket::Connection Util::Stream::getLive(std::string streamname){ - sanitizeName(streamname); return Socket::Connection("/tmp/mist/stream_"+streamname); } -/// Starts a process for the VoD stream. -Socket::Connection Util::Stream::getVod(std::string streamname){ - sanitizeName(streamname); - std::string filename = "/tmp/mist/vod_" + streamname; - /// \todo Is the name unique enough? +/// Starts a process for a VoD stream. +Socket::Connection Util::Stream::getVod(std::string filename){ std::string name = "MistPlayer " + filename; const char *argv[] = { "MistPlayer", filename.c_str(), NULL }; - int fdin = -1, fdout = -1; - Util::Procs::StartPiped(name, (char **)argv, &fdin, &fdout, 0); + int fdin = -1, fdout = -1, fderr = fileno(stderr); + Util::Procs::StartPiped(name, (char **)argv, &fdin, &fdout, &fderr); // if StartPiped fails then fdin and fdout will be unmodified (-1) return Socket::Connection(fdin, fdout); } /// Probe for available streams. Currently first VoD, then Live. Socket::Connection Util::Stream::getStream(std::string streamname){ - Socket::Connection vod = getVod(streamname); - if (vod.connected()){ - return vod; + sanitizeName(streamname); + JSON::Value ServConf = JSON::fromFile("/tmp/mist/streamlist"); + 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. /// Filters the streamname, removing invalid characters and /// converting all letters to lowercase. diff --git a/lib/stream.h b/lib/stream.h index 56650c3b..f08433d9 100644 --- a/lib/stream.h +++ b/lib/stream.h @@ -7,17 +7,11 @@ namespace Util{ class Stream{ - /// Sanitize a streamname. - static void sanitizeName(std::string & streamname); - public: - /// Get a connection to a Live stream. - static Socket::Connection getLive(std::string streamname); - /// Get a connection to a VoD stream. - 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); + public: + static void sanitizeName(std::string & streamname); + static Socket::Connection getLive(std::string streamname); + static Socket::Connection getVod(std::string streamname); + static Socket::Connection getStream(std::string streamname); + static Socket::Server makeLive(std::string streamname); }; }