Added duplicate checking for manual pushes
This commit is contained in:
parent
acbdede296
commit
6254c285d6
5 changed files with 58 additions and 77 deletions
|
@ -325,14 +325,10 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempt to start a push for streamname to target.
|
/// Attempt to start a push for streamname to target.
|
||||||
/// Both streamname and target may be changed by this function:
|
/// streamname MUST be pre-sanitized
|
||||||
/// - streamname is sanitized to a permissible streamname
|
/// target gets variables replaced and may be altered by the PUSH_OUT_START trigger response.
|
||||||
/// - target gets variables replaced and may be altered by the PUSH_OUT_START trigger response.
|
|
||||||
/// Attempts to match the altered target to an output that can push to it.
|
/// Attempts to match the altered target to an output that can push to it.
|
||||||
pid_t Util::startPush(std::string & streamname, std::string & target) {
|
pid_t Util::startPush(const std::string & streamname, std::string & target) {
|
||||||
|
|
||||||
sanitizeName(streamname);
|
|
||||||
|
|
||||||
if (Triggers::shouldTrigger("PUSH_OUT_START", streamname)) {
|
if (Triggers::shouldTrigger("PUSH_OUT_START", streamname)) {
|
||||||
std::string payload = streamname+"\n"+target;
|
std::string payload = streamname+"\n"+target;
|
||||||
std::string filepath_response;
|
std::string filepath_response;
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace Util {
|
||||||
void sanitizeName(std::string & streamname);
|
void sanitizeName(std::string & streamname);
|
||||||
bool streamAlive(std::string & streamname);
|
bool streamAlive(std::string & streamname);
|
||||||
bool startInput(std::string streamname, std::string filename = "", bool forkFirst = true);
|
bool startInput(std::string streamname, std::string filename = "", bool forkFirst = true);
|
||||||
int startPush(std::string & streamname, std::string & target);
|
int startPush(const std::string & streamname, std::string & target);
|
||||||
JSON::Value getStreamConfig(std::string streamname);
|
JSON::Value getStreamConfig(std::string streamname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <sys/stat.h> //for browse API call
|
#include <sys/stat.h> //for browse API call
|
||||||
#include <mist/http_parser.h>
|
#include <mist/http_parser.h>
|
||||||
#include <mist/auth.h>
|
#include <mist/auth.h>
|
||||||
|
#include <mist/stream.h>
|
||||||
#include <mist/config.h>
|
#include <mist/config.h>
|
||||||
#include <mist/defines.h>
|
#include <mist/defines.h>
|
||||||
#include <mist/timing.h>
|
#include <mist/timing.h>
|
||||||
|
@ -607,8 +608,9 @@ int Controller::handleAPIConnection(Socket::Connection & conn){
|
||||||
stream = Request["push_start"]["stream"].asStringRef();
|
stream = Request["push_start"]["stream"].asStringRef();
|
||||||
target = Request["push_start"]["target"].asStringRef();
|
target = Request["push_start"]["target"].asStringRef();
|
||||||
}
|
}
|
||||||
|
Util::sanitizeName(stream);
|
||||||
if (*stream.rbegin() != '+'){
|
if (*stream.rbegin() != '+'){
|
||||||
Controller::startPush(stream, target);
|
startPush(stream, target);
|
||||||
}else{
|
}else{
|
||||||
if (activeStreams.size()){
|
if (activeStreams.size()){
|
||||||
for (std::map<std::string, unsigned int>::iterator jt = activeStreams.begin(); jt != activeStreams.end(); ++jt){
|
for (std::map<std::string, unsigned int>::iterator jt = activeStreams.begin(); jt != activeStreams.end(); ++jt){
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#include <string>
|
#include "controller_push.h"
|
||||||
#include <mist/json.h>
|
#include "controller_statistics.h"
|
||||||
|
#include "controller_storage.h"
|
||||||
#include <mist/config.h>
|
#include <mist/config.h>
|
||||||
#include <mist/tinythread.h>
|
#include <mist/json.h>
|
||||||
#include <mist/procs.h>
|
#include <mist/procs.h>
|
||||||
#include <mist/stream.h>
|
#include <mist/stream.h>
|
||||||
#include "controller_storage.h"
|
#include <mist/tinythread.h>
|
||||||
#include "controller_statistics.h"
|
#include <string>
|
||||||
#include "controller_push.h"
|
|
||||||
|
|
||||||
namespace Controller{
|
namespace Controller{
|
||||||
|
|
||||||
|
@ -18,7 +18,9 @@ namespace Controller {
|
||||||
|
|
||||||
/// Immediately starts a push for the given stream to the given target.
|
/// Immediately starts a push for the given stream to the given target.
|
||||||
/// Simply calls Util::startPush and stores the resulting PID in the local activePushes map.
|
/// Simply calls Util::startPush and stores the resulting PID in the local activePushes map.
|
||||||
void startPush(std::string & stream, std::string & target){
|
void startPush(const std::string &stream, std::string &target){
|
||||||
|
//Cancel if already active
|
||||||
|
if (isPushActive(stream, target)){return;}
|
||||||
std::string originalTarget = target;
|
std::string originalTarget = target;
|
||||||
pid_t ret = Util::startPush(stream, target);
|
pid_t ret = Util::startPush(stream, target);
|
||||||
if (ret){
|
if (ret){
|
||||||
|
@ -32,13 +34,11 @@ namespace Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the push is currently active, false otherwise.
|
/// Returns true if the push is currently active, false otherwise.
|
||||||
bool isPushActive(std::string & streamname, std::string & target){
|
bool isPushActive(const std::string &streamname, const std::string &target){
|
||||||
std::set<pid_t> toWipe;
|
std::set<pid_t> toWipe;
|
||||||
for (std::map<pid_t, JSON::Value>::iterator it = activePushes.begin(); it != activePushes.end(); ++it){
|
for (std::map<pid_t, JSON::Value>::iterator it = activePushes.begin(); it != activePushes.end(); ++it){
|
||||||
if (Util::Procs::isActive(it->first)){
|
if (Util::Procs::isActive(it->first)){
|
||||||
if (it->second[1u].asStringRef() == streamname && it->second[2u].asStringRef() == target){
|
if (it->second[1u].asStringRef() == streamname && it->second[2u].asStringRef() == target){return true;}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
toWipe.insert(it->first);
|
toWipe.insert(it->first);
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,7 @@ namespace Controller {
|
||||||
|
|
||||||
/// Immediately stops a push with the given ID
|
/// Immediately stops a push with the given ID
|
||||||
void stopPush(unsigned int ID){
|
void stopPush(unsigned int ID){
|
||||||
if (ID > 1 && activePushes.count(ID)){
|
if (ID > 1 && activePushes.count(ID)){Util::Procs::Stop(ID);}
|
||||||
Util::Procs::Stop(ID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loops, checking every second if any pushes need restarting.
|
/// Loops, checking every second if any pushes need restarting.
|
||||||
|
@ -77,9 +75,7 @@ namespace Controller {
|
||||||
if (!isPushActive(streamname, target)){
|
if (!isPushActive(streamname, target)){
|
||||||
if (waitingPushes[streamname][target]++ >= waittime && (curCount < maxspeed || !maxspeed)){
|
if (waitingPushes[streamname][target]++ >= waittime && (curCount < maxspeed || !maxspeed)){
|
||||||
waitingPushes[streamname].erase(target);
|
waitingPushes[streamname].erase(target);
|
||||||
if (!waitingPushes[streamname].size()){
|
if (!waitingPushes[streamname].size()){waitingPushes.erase(streamname);}
|
||||||
waitingPushes.erase(streamname);
|
|
||||||
}
|
|
||||||
startPush(streamname, target);
|
startPush(streamname, target);
|
||||||
curCount++;
|
curCount++;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +86,7 @@ namespace Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Util::wait(1000);//wait at least 5 seconds
|
Util::wait(1000); // wait at least a second
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,13 +125,11 @@ namespace Controller {
|
||||||
std::string streamname = it->first;
|
std::string streamname = it->first;
|
||||||
if (pStr == streamname || (*pStr.rbegin() == '+' && streamname.substr(0, pStr.size()) == pStr)){
|
if (pStr == streamname || (*pStr.rbegin() == '+' && streamname.substr(0, pStr.size()) == pStr)){
|
||||||
|
|
||||||
if (!isPushActive(streamname, target)){
|
|
||||||
startPush(streamname, target);
|
startPush(streamname, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Removes a push from the list of auto-pushes.
|
/// Removes a push from the list of auto-pushes.
|
||||||
/// Does not stop currently active matching pushes.
|
/// Does not stop currently active matching pushes.
|
||||||
|
@ -153,9 +147,7 @@ namespace Controller {
|
||||||
}
|
}
|
||||||
JSON::Value newautopushes;
|
JSON::Value newautopushes;
|
||||||
jsonForEach(Controller::Storage["autopushes"], it){
|
jsonForEach(Controller::Storage["autopushes"], it){
|
||||||
if ((*it) != delPush){
|
if ((*it) != delPush){newautopushes.append(*it);}
|
||||||
newautopushes.append(*it);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Controller::Storage["autopushes"] = newautopushes;
|
Controller::Storage["autopushes"] = newautopushes;
|
||||||
}
|
}
|
||||||
|
@ -165,9 +157,7 @@ namespace Controller {
|
||||||
void removeAllPush(const std::string &streamname){
|
void removeAllPush(const std::string &streamname){
|
||||||
JSON::Value newautopushes;
|
JSON::Value newautopushes;
|
||||||
jsonForEach(Controller::Storage["autopushes"], it){
|
jsonForEach(Controller::Storage["autopushes"], it){
|
||||||
if ((*it)[0u] != streamname){
|
if ((*it)[0u] != streamname){newautopushes.append(*it);}
|
||||||
newautopushes.append(*it);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Controller::Storage["autopushes"] = newautopushes;
|
Controller::Storage["autopushes"] = newautopushes;
|
||||||
}
|
}
|
||||||
|
@ -178,26 +168,19 @@ namespace Controller {
|
||||||
const std::string &pStr = (*it)[0u].asStringRef();
|
const std::string &pStr = (*it)[0u].asStringRef();
|
||||||
if (pStr == streamname || (*pStr.rbegin() == '+' && streamname.substr(0, pStr.size()) == pStr)){
|
if (pStr == streamname || (*pStr.rbegin() == '+' && streamname.substr(0, pStr.size()) == pStr)){
|
||||||
std::string stream = streamname;
|
std::string stream = streamname;
|
||||||
|
Util::sanitizeName(stream);
|
||||||
std::string target = (*it)[1u];
|
std::string target = (*it)[1u];
|
||||||
if (!isPushActive(stream, target)){
|
|
||||||
startPush(stream, target);
|
startPush(stream, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void pushSettings(const JSON::Value &request, JSON::Value &response){
|
void pushSettings(const JSON::Value &request, JSON::Value &response){
|
||||||
if (request.isObject()){
|
if (request.isObject()){
|
||||||
if (request.isMember("wait")){
|
if (request.isMember("wait")){Controller::Storage["push_settings"]["wait"] = request["wait"].asInt();}
|
||||||
Controller::Storage["push_settings"]["wait"] = request["wait"].asInt();
|
if (request.isMember("maxspeed")){Controller::Storage["push_settings"]["maxspeed"] = request["maxspeed"].asInt();}
|
||||||
}
|
|
||||||
if (request.isMember("maxspeed")){
|
|
||||||
Controller::Storage["push_settings"]["maxspeed"] = request["maxspeed"].asInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
response = Controller::Storage["push_settings"];
|
response = Controller::Storage["push_settings"];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include <string>
|
|
||||||
#include <mist/json.h>
|
|
||||||
#include <mist/config.h>
|
#include <mist/config.h>
|
||||||
|
#include <mist/json.h>
|
||||||
#include <mist/tinythread.h>
|
#include <mist/tinythread.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace Controller{
|
namespace Controller{
|
||||||
// Functions for current pushes, start/stop/list
|
// Functions for current pushes, start/stop/list
|
||||||
void startPush(std::string & streamname, std::string & target);
|
void startPush(const std::string &streamname, std::string &target);
|
||||||
void stopPush(unsigned int ID);
|
void stopPush(unsigned int ID);
|
||||||
void listPush(JSON::Value &output);
|
void listPush(JSON::Value &output);
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ namespace Controller {
|
||||||
// internal use only
|
// internal use only
|
||||||
void doAutoPush(std::string &streamname);
|
void doAutoPush(std::string &streamname);
|
||||||
void pushCheckLoop(void *np);
|
void pushCheckLoop(void *np);
|
||||||
bool isPushActive(std::string & streamname, std::string & target);
|
bool isPushActive(const std::string &streamname, const std::string &target);
|
||||||
|
|
||||||
// for storing/retrieving settings
|
// for storing/retrieving settings
|
||||||
void pushSettings(const JSON::Value &request, JSON::Value &response);
|
void pushSettings(const JSON::Value &request, JSON::Value &response);
|
||||||
|
|
Loading…
Add table
Reference in a new issue