MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
Public Member Functions | Static Public Member Functions | Data Fields | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes
Mist::Output Class Reference

The output class is intended to be inherited by MistOut process classes. More...

#include <output.h>

Inheritance diagram for Mist::Output:
Mist::InOutBase Mist::HTTPOutput Mist::OutPush Mist::OutRaw Mist::OutRTMP Mist::OutRTSP Mist::OutDashMP4 Mist::OutHDS Mist::OutHSS Mist::OutHTTP Mist::OutHTTPMinimalServer Mist::OutJSON Mist::OutProgressiveFLV Mist::OutProgressiveMP3 Mist::OutProgressiveMP4 Mist::OutProgressiveOGG Mist::OutProgressiveSRT

Public Member Functions

 Output (Socket::Connection &conn)
 
virtual ~Output ()
 
void bufferFinalize (unsigned long tid)
 Wraps up the buffering of a shared memory data page. More...
 
void bufferLivePacket (JSON::Value &packet)
 Buffers a live packet to a page. More...
 
void bufferLivePacket (DTSC::Packet &packet)
 Buffers a live packet to a page. More...
 
void bufferNext (DTSC::Packet &pack)
 Buffers the next packet on the currently opened page. More...
 
void bufferNext (JSON::Value &pack)
 Buffers the next packet on the currently opened page. More...
 
void bufferRemove (unsigned long tid, unsigned long pageNumber)
 Removes a fully buffered page. More...
 
bool bufferStart (unsigned long tid, unsigned long pageNumber)
 
bool closeOutputFileForRecording ()
 
long unsigned int getMainSelectedTrack ()
 Returns the ID of the main selected track, or 0 if no tracks are selected. More...
 
virtual void initialize ()
 
void initiateMeta ()
 Opens a shared memory page for the stream metadata. More...
 
virtual void onFail ()
 Called when stream initialization has failed. More...
 
virtual bool onFinish ()
 
virtual void onRecord ()
 
virtual void onRequest ()
 
bool openOutputFileForRecording ()
 
virtual void prepareNext ()
 
void reconnect ()
 Connects or reconnects to the stream. More...
 
virtual void requestHandler ()
 
int run ()
 
void seek (unsigned long long pos)
 Prepares all tracks from selectedTracks for seeking to the specified ms position. More...
 
bool seek (unsigned int tid, unsigned long long pos, bool getNextKey=false)
 
void selectDefaultTracks ()
 
virtual void sendHeader ()
 
virtual void sendNext ()
 
void setBlocking (bool blocking)
 
void stats ()
 
void stop ()
 Clears the buffer, sets parseData to false, and generally makes not very much happen at all. More...
 
void updateMeta ()
 

Static Public Member Functions

static void init (Util::Config *cfg)
 
static bool listenMode ()
 

Data Fields

std::string reqUrl
 

Static Public Attributes

static JSON::Value capa = JSON::Value()
 

Protected Member Functions

void continueNegotiate (unsigned long tid)
 
virtual std::string getConnectedBinHost ()
 
virtual std::string getConnectedHost ()
 
unsigned int getKeyForTime (long unsigned int trackId, long long timeStamp)
 
bool recording ()
 

Protected Attributes

std::map< int, DTSCPageDatabookKeeping
 
bool completeKeysOnly
 Bool if we send whole keys only, so the metadata is complete and the output knows in advance what will be sent. More...
 
unsigned int crc
 Checksum, if any, for usage in the stats. More...
 
bool isBlocking
 If true, indicates that myConn is blocking. More...
 
bool isInitialized
 If false, triggers initialization if parseData is true. More...
 
unsigned int maxSkipAhead
 Maximum ms that we will go ahead of the intended timestamps. More...
 
unsigned int minSkipAhead
 Minimum ms that we will go ahead of the intended timestamps. More...
 
Socket::ConnectionmyConn
 Connection to the client. More...
 
DTSC::Meta myMeta
 Stores either the input or output metadata. More...
 
negotiationProxy nProxy
 
int outputFileDescriptor
 
bool parseData
 If true, triggers initalization if not already done, sending of header, sending of packets. More...
 
unsigned int realTime
 Playback speed in ms of data per second. eg: 0 is infinite, 1000 real-time, 5000 is 0.2X speed, 500 = 2X speed. More...
 
std::set< unsigned long > selectedTracks
 Stores the track id's that are either selected for playback or input. More...
 
bool sentHeader
 If false, triggers sendHeader if parseData is true. More...
 
bool standAlone
 
IPC::sharedClient statsPage
 Shared memory used for statistics reporting. More...
 
std::string streamName
 
DTSC::Packet thisPacket
 
bool wantRequest
 If true, waits for a request. More...
 

Static Protected Attributes

static Util::Configconfig = NULL
 

Private Member Functions

bool checkLimits ()
 
std::string getCountry (std::string ip)
 
std::string hostLookup (std::string ip)
 
bool isBlacklisted (std::string host, std::string streamName, int timeConnected)
 
void loadPageForKey (long unsigned int trackId, long long int keyNum)
 
void Log (std::string type, std::string message)
 
bool onList (std::string ip, std::string list)
 
int pageNumForKey (long unsigned int trackId, long long int keyNum)
 

Private Attributes

std::set< sortedPageInfobuffer
 A sorted list of next-to-be-loaded packets. More...
 
bool completeKeyReadyTimeOut
 
std::map< unsigned long, unsigned int > currKeyOpen
 
long long unsigned int firstTime
 Time of first packet after last seek. Used for real-time sending. More...
 
unsigned int lastStats
 Time of last sending of stats. More...
 
std::map< unsigned long, unsigned long > nxtKeyNum
 Contains the number of the next key, for page seeking purposes. More...
 
bool sought
 If a seek has been done, this is set to true. Used for seeking on prepareNext(). More...
 

Detailed Description

The output class is intended to be inherited by MistOut process classes.

It contains all generic code and logic, while the child classes implement anything specific to particular protocols or containers. It contains several virtual functions, that may be overridden to "hook" into the streaming process at those particular points, simplifying child class logic and implementation details.

Constructor & Destructor Documentation

Mist::Output::Output ( Socket::Connection conn)
Mist::Output::~Output ( )
virtual

Member Function Documentation

void Mist::InOutBase::bufferFinalize ( unsigned long  tid)
inherited

Wraps up the buffering of a shared memory data page.

Registers the data page on the track index page as well

Parameters
tidThe trackid of the page to finalize
void Mist::InOutBase::bufferLivePacket ( JSON::Value packet)
inherited

Buffers a live packet to a page.

Handles both buffering and creation of new pages

Initiates/continues negotiation with the buffer as well

Parameters
packetThe packet to buffer
void Mist::InOutBase::bufferLivePacket ( DTSC::Packet packet)
inherited

Buffers a live packet to a page.

Handles both buffering and creation of new pages

Initiates/continues negotiation with the buffer as well

Parameters
packetThe packet to buffer
void Mist::InOutBase::bufferNext ( DTSC::Packet pack)
inherited

Buffers the next packet on the currently opened page.

Parameters
packThe packet to buffer
void Mist::InOutBase::bufferNext ( JSON::Value pack)
inherited

Buffers the next packet on the currently opened page.

Parameters
packThe packet to buffer
Note
Internally calls bufferNext(DTSC::Packet & pack)
void Mist::InOutBase::bufferRemove ( unsigned long  tid,
unsigned long  pageNumber 
)
inherited

Removes a fully buffered page.

Does not do anything if the process is not standalone, in this case the master process will have an overloaded version of this function.

Parameters
tidThe trackid to remove the page from
pageNumberThe number of the page to remove
bool Mist::InOutBase::bufferStart ( unsigned long  tid,
unsigned long  pageNumber 
)
inherited
bool Mist::Output::checkLimits ( )
private
bool Mist::Output::closeOutputFileForRecording ( )
void Mist::InOutBase::continueNegotiate ( unsigned long  tid)
protectedinherited
std::string Mist::Output::getConnectedBinHost ( )
protectedvirtual

Reimplemented in Mist::HTTPOutput.

std::string Mist::Output::getConnectedHost ( )
protectedvirtual

Reimplemented in Mist::HTTPOutput.

std::string Mist::Output::getCountry ( std::string  ip)
private
unsigned int Mist::Output::getKeyForTime ( long unsigned int  trackId,
long long  timeStamp 
)
protected
long unsigned int Mist::Output::getMainSelectedTrack ( )

Returns the ID of the main selected track, or 0 if no tracks are selected.

The main track is the first video track, if any, and otherwise the first other track.

std::string Mist::Output::hostLookup ( std::string  ip)
private
void Mist::Output::init ( Util::Config cfg)
static
void Mist::Output::initialize ( )
virtual
Trigger:
The "CONN_PLAY" trigger is stream-specific, and is ran when an active connection first opens a stream.

Its payload is:

streamname
connected client host
output handler name
request URL (if any)

The "USER_NEW" trigger is stream-specific, and is ran when a new user first opens a stream. Segmented protcols are unduplicated over the duration of the statistics log (~10 minutes), true streaming protocols (RTMP, RTSP) are not deduplicated as no duplication ever takes place. Its payload is:

streamname
connected client host
User agent checksum (CRC32 of User-agent string)
output handler name
request URL (if any)

Reimplemented in Mist::OutDashMP4.

void Mist::InOutBase::initiateMeta ( )
inherited

Opens a shared memory page for the stream metadata.

Assumes myMeta contains the metadata to write.

bool Mist::Output::isBlacklisted ( std::string  host,
std::string  streamName,
int  timeConnected 
)
private
static bool Mist::Output::listenMode ( )
inlinestatic
void Mist::Output::loadPageForKey ( long unsigned int  trackId,
long long int  keyNum 
)
private
void Mist::Output::Log ( std::string  type,
std::string  message 
)
private
Todo:
These logs need to show up in the controller.
Todo:
Additionally, the triggering and untriggering of limits should be recorded in the controller as well.
void Mist::Output::onFail ( )
virtual

Called when stream initialization has failed.

The standard implementation will set isInitialized to false and close the client connection, thus causing the process to exit cleanly.

Reimplemented in Mist::HTTPOutput, and Mist::OutHTTP.

virtual bool Mist::Output::onFinish ( )
inlinevirtual

Reimplemented in Mist::OutProgressiveOGG, and Mist::OutJSON.

bool Mist::Output::onList ( std::string  ip,
std::string  list 
)
private
virtual void Mist::Output::onRecord ( )
inlinevirtual

Reimplemented in Mist::HTTPOutput.

void Mist::Output::onRequest ( )
virtual
bool Mist::Output::openOutputFileForRecording ( )
int Mist::Output::pageNumForKey ( long unsigned int  trackId,
long long int  keyNum 
)
private
void Mist::Output::prepareNext ( )
virtual
void Mist::Output::reconnect ( )

Connects or reconnects to the stream.

Assumes streamName class member has been set already. Will start input if not currently active, calls onFail() if this does not succeed. After assuring stream is online, clears nProxy.metaPages, then sets nProxy.metaPages[0], statsPage and nProxy.userClient to (hopefully) valid handles. Finally, calls updateMeta()

bool Mist::Output::recording ( )
protected
void Mist::Output::requestHandler ( )
virtual

Reimplemented in Mist::HTTPOutput, and Mist::OutPush.

int Mist::Output::run ( )
Trigger:
The "CONN_OPEN" trigger is stream-specific, and is ran when a connection is made or passed to a new handler.

Its payload is:

streamname
connected client host
output handler name
request URL (if any)

The "CONN_CLOSE" trigger is stream-specific, and is ran when a connection closes. Its payload is:

streamname
connected client host
output handler name
request URL (if any)
Todo:
generate payload
void Mist::Output::seek ( unsigned long long  pos)

Prepares all tracks from selectedTracks for seeking to the specified ms position.

bool Mist::Output::seek ( unsigned int  tid,
unsigned long long  pos,
bool  getNextKey = false 
)
void Mist::Output::selectDefaultTracks ( )
void Mist::Output::sendHeader ( )
virtual
virtual void Mist::Output::sendNext ( )
inlinevirtual
void Mist::Output::setBlocking ( bool  blocking)
void Mist::Output::stats ( )
void Mist::Output::stop ( )

Clears the buffer, sets parseData to false, and generally makes not very much happen at all.

void Mist::Output::updateMeta ( )

Field Documentation

std::map<int,DTSCPageData> Mist::Output::bookKeeping
protected
std::set<sortedPageInfo> Mist::Output::buffer
private

A sorted list of next-to-be-loaded packets.

JSON::Value Mist::Output::capa = JSON::Value()
static
bool Mist::Output::completeKeyReadyTimeOut
private
bool Mist::Output::completeKeysOnly
protected

Bool if we send whole keys only, so the metadata is complete and the output knows in advance what will be sent.

Util::Config * Mist::InOutBase::config = NULL
staticprotectedinherited
unsigned int Mist::Output::crc
protected

Checksum, if any, for usage in the stats.

std::map<unsigned long, unsigned int> Mist::Output::currKeyOpen
private
long long unsigned int Mist::Output::firstTime
private

Time of first packet after last seek. Used for real-time sending.

bool Mist::Output::isBlocking
protected

If true, indicates that myConn is blocking.

bool Mist::Output::isInitialized
protected

If false, triggers initialization if parseData is true.

unsigned int Mist::Output::lastStats
private

Time of last sending of stats.

unsigned int Mist::Output::maxSkipAhead
protected

Maximum ms that we will go ahead of the intended timestamps.

unsigned int Mist::Output::minSkipAhead
protected

Minimum ms that we will go ahead of the intended timestamps.

Socket::Connection& Mist::Output::myConn
protected

Connection to the client.

DTSC::Meta Mist::InOutBase::myMeta
protectedinherited

Stores either the input or output metadata.

negotiationProxy Mist::InOutBase::nProxy
protectedinherited
std::map<unsigned long, unsigned long> Mist::Output::nxtKeyNum
private

Contains the number of the next key, for page seeking purposes.

int Mist::Output::outputFileDescriptor
protected
bool Mist::Output::parseData
protected

If true, triggers initalization if not already done, sending of header, sending of packets.

unsigned int Mist::Output::realTime
protected

Playback speed in ms of data per second. eg: 0 is infinite, 1000 real-time, 5000 is 0.2X speed, 500 = 2X speed.

std::string Mist::Output::reqUrl
std::set<unsigned long> Mist::InOutBase::selectedTracks
protectedinherited

Stores the track id's that are either selected for playback or input.

bool Mist::Output::sentHeader
protected

If false, triggers sendHeader if parseData is true.

bool Mist::Output::sought
private

If a seek has been done, this is set to true. Used for seeking on prepareNext().

bool Mist::InOutBase::standAlone
protectedinherited
IPC::sharedClient Mist::Output::statsPage
protected

Shared memory used for statistics reporting.

std::string Mist::InOutBase::streamName
protectedinherited
DTSC::Packet Mist::InOutBase::thisPacket
protectedinherited
bool Mist::Output::wantRequest
protected

If true, waits for a request.


The documentation for this class was generated from the following files: