MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
Data Structures | Functions
Util Namespace Reference

Contains utility code, not directly related to streaming media. More...

Data Structures

class  Config
 Deals with parsing configuration from commandline options. More...
 
class  Procs
 Deals with spawning, monitoring and stopping child processes. More...
 

Functions

long long int bootSecs ()
 Gets the current system uptime in seconds. More...
 
void Daemonize (bool notClose=false)
 Will turn the current process into a daemon. More...
 
long long int epoch ()
 Gets the amount of seconds since 01/01/1970. More...
 
long long unsigned int getMicros ()
 Gets the current time in microseconds. More...
 
long long unsigned int getMicros (long long unsigned int previous)
 Gets the time difference in microseconds. More...
 
long long int getMS ()
 Gets the current time in milliseconds. More...
 
void getMyExec (std::deque< std::string > &execs)
 Gets all executables in getMyPath that start with "Mist". More...
 
std::string getMyPath ()
 Gets directory the current executable is stored in. More...
 
long long int getNTP ()
 
JSON::Value getStreamConfig (std::string streamname)
 
std::string getTmpFolder ()
 
std::string getUTCString (long long int epoch=0)
 
void sanitizeName (std::string &streamname)
 Filters the streamname, removing invalid characters and converting all letters to lowercase. More...
 
void setUser (std::string user)
 Will set the active user to the named username. More...
 
void sleep (int ms)
 Sleeps for roughly the indicated amount of milliseconds. More...
 
bool startInput (std::string streamname, std::string filename="", bool forkFirst=true)
 Assures the input for the given stream name is active. More...
 
int startRecording (std::string streamname)
 
bool streamAlive (std::string &streamname)
 Checks if the given streamname has an active input serving it. More...
 
bool stringToBool (std::string &str)
 Parses a string reference to a boolean. More...
 
void wait (int ms)
 Sleeps for the indicated amount of milliseconds or longer. More...
 

Detailed Description

Contains utility code, not directly related to streaming media.

Function Documentation

long long int Util::bootSecs ( )

Gets the current system uptime in seconds.

void Util::Daemonize ( bool  notClose = false)

Will turn the current process into a daemon.

Works by calling daemon(1,0): Does not change directory to root. Does redirect output to /dev/null

long long int Util::epoch ( )

Gets the amount of seconds since 01/01/1970.

long long unsigned int Util::getMicros ( )

Gets the current time in microseconds.

long long unsigned int Util::getMicros ( long long unsigned int  previous)

Gets the time difference in microseconds.

long long int Util::getMS ( )

Gets the current time in milliseconds.

void Util::getMyExec ( std::deque< std::string > &  execs)

Gets all executables in getMyPath that start with "Mist".

std::string Util::getMyPath ( )

Gets directory the current executable is stored in.

long long int Util::getNTP ( )
JSON::Value Util::getStreamConfig ( std::string  streamname)
std::string Util::getTmpFolder ( )
std::string Util::getUTCString ( long long int  epoch = 0)
void Util::sanitizeName ( std::string &  streamname)

Filters the streamname, removing invalid characters and converting all letters to lowercase.

If a '?' character is found, everything following that character is deleted. The original string is modified. If a '+' or space exists, then only the part before that is sanitized.

void Util::setUser ( std::string  user)

Will set the active user to the named username.

Sets the current process' running user.

void Util::sleep ( int  ms)

Sleeps for roughly the indicated amount of milliseconds.

Will not sleep if ms is negative. Will not sleep for longer than 100 seconds (100000ms). Can be interrupted early by a signal, no guarantee of minimum sleep time. Can be slightly off depending on OS accuracy.

bool Util::startInput ( std::string  streamname,
std::string  filename = "",
bool  forkFirst = true 
)

Assures the input for the given stream name is active.

Does stream name sanitizion first, followed by a stream name length check (<= 100 chars). Then, checks if an input is already active by running streamAlive(). If yes, aborts. If no, loads up the server configuration and attempts to start the given stream according to current config. At this point, fails and aborts if MistController isn't running.

Trigger:
The "STREAM_LOAD" trigger is stream-specific, and is ran right before launching an input for an inactive stream. If cancelled, the input is not launched. Its payload is:
streamname
The "STREAM_SOURCE" trigger is stream-specific, and is ran right before launching an input for an inactive stream. It cannot be cancelled, but an invalid source can be returned; which is effectively equivalent to cancelling. This trigger is special: the response is used as source override for this stream, and not handled as normal. If used, the handler for this trigger MUST return a valid source to allow the stream input to load up at all. If used multiple times, the last defined handler overrides any and all previous handlers. Its payload is:
streamname
int Util::startRecording ( std::string  streamname)
bool Util::streamAlive ( std::string &  streamname)

Checks if the given streamname has an active input serving it.

Returns true if this is the case. Assumes the streamname has already been through sanitizeName()!

bool Util::stringToBool ( std::string &  str)

Parses a string reference to a boolean.

Returns true if the string, with whitespace removed and converted to lowercase, prefix-matches any of: "1", "yes", "true", "cont". Returns false otherwise.

void Util::wait ( int  ms)

Sleeps for the indicated amount of milliseconds or longer.

Will not sleep if ms is negative. Will not sleep for longer than 10 minutes (600000ms). If interrupted by signal, resumes sleep until at least ms milliseconds have passed. Can be slightly off (in positive direction only) depending on OS accuracy.