JSON-based input selection.

This commit is contained in:
Thulinma 2014-10-02 15:41:50 +02:00
parent d85fe140ca
commit 8542281ac2
13 changed files with 279 additions and 215 deletions

View file

@ -40,6 +40,14 @@ namespace Controller {
capabilities["connectors"].removeMember((*it).substr(7));
}
}
if ((*it).substr(0, 6) == "MistIn" && (*it) != "MistInfo"){
arg_one = Util::getMyPath() + (*it);
conn_args[0] = arg_one.c_str();
capabilities["inputs"][(*it).substr(6)] = JSON::fromString(Util::Procs::getOutputOf((char**)conn_args));
if (capabilities["inputs"][(*it).substr(6)].size() < 1){
capabilities["inputs"].removeMember((*it).substr(6));
}
}
}
}

View file

@ -1,7 +1,11 @@
#include <sys/stat.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <mist/timing.h>
#include <mist/shared_memory.h>
#include "controller_storage.h"
#include "controller_capabilities.h"
///\brief Holds everything unique to the controller.
namespace Controller {
@ -68,5 +72,23 @@ namespace Controller {
fclose(output);
close((long long int)err);
}
/// Writes the current config to shared memory to be used in other processes
void writeConfig(){
JSON::Value writeConf;
writeConf["config"] = Storage["config"];
writeConf["streams"] = Storage["streams"];
writeConf["capabilities"] = capabilities;
static IPC::sharedPage mistConfOut("!mistConfig", 4*1024*1024, true);
IPC::semaphore configLock("!mistConfLock", O_CREAT | O_RDWR, ACCESSPERMS, 1);
//lock semaphore
configLock.wait();
//write config
std::string temp = writeConf.toPacked();
memcpy(mistConfOut.mapped, temp.data(), std::min(temp.size(), (unsigned long)mistConfOut.len));
//unlock semaphore
configLock.post();
}
}

View file

@ -17,4 +17,6 @@ namespace Controller {
void handleMsg(void * err);
void writeConfig();
}

View file

@ -6,6 +6,7 @@
#include <mist/defines.h>
#include <mist/shared_memory.h>
#include "controller_streams.h"
#include "controller_capabilities.h"
#include "controller_storage.h"
#include "controller_statistics.h"
#include <sys/stat.h>
@ -22,13 +23,15 @@ namespace Controller {
if (one.isMember("source") != two.isMember("source") || one["source"] != two["source"]){
return false;
}
if (one.isMember("DVR") != two.isMember("DVR") || (one.isMember("DVR") && one["DVR"] != two["DVR"])){
return false;
}
if (one.isMember("cut") != two.isMember("cut") || (one.isMember("cut") && one["cut"] != two["cut"])){
return false;
}
return true;
/// \todo Change this to use capabilities["inputs"] and only compare required/optional parameters.
/// \todo Maybe change this to check for correct source and/or required parameters.
//temporary: compare the two JSON::Value objects.
return one==two;
//nothing different? return true by default
//return true;
}
///\brief Checks the validity of a stream, updates internal stream status.
@ -116,7 +119,7 @@ namespace Controller {
DEBUG_MSG(DLVL_INSANE, "(re)loading metadata for stream %s", name.c_str());
if ((URL.substr(URL.size() - 5) != ".dtsc") && (stat((URL+".dtsh").c_str(), &fileinfo) != 0)){
DEBUG_MSG(DLVL_INSANE, "Stream %s is non-DTSC file without DTSH. Opening stream to generate DTSH...", name.c_str());
Util::Stream::getVod(URL, name);
Util::startInput(name);
DEBUG_MSG(DLVL_INSANE, "Waiting for stream %s to open...", name.c_str());
//wait for the stream
{
@ -241,7 +244,7 @@ namespace Controller {
changed = true;
}
if (changed){
WriteFile(Util::getTmpFolder() + "streamlist", strlist.toString());
writeConfig();
}
}
@ -250,16 +253,8 @@ namespace Controller {
for (JSON::ObjIter jit = in.ObjBegin(); jit != in.ObjEnd(); jit++){
if (out.isMember(jit->first)){
if ( !streamsEqual(jit->second, out[jit->first])){
out[jit->first].null();
out[jit->first] = jit->second;
out[jit->first]["name"] = jit->first;
out[jit->first]["source"] = jit->second["source"];
if (jit->second.isMember("DVR")){
out[jit->first]["DVR"] = jit->second["DVR"].asInt();
}
if (jit->second.isMember("cut")){
out[jit->first]["cut"] = jit->second["cut"].asInt();
}
out[jit->first]["updated"] = 1ll;
Log("STRM", std::string("Updated stream ") + jit->first);
checkStream(jit->first, out[jit->first]);
}