MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
output.h
Go to the documentation of this file.
1 #pragma once
2 #include <set>
3 #include <cstdlib>
4 #include <map>
5 #include <mist/config.h>
6 #include <mist/json.h>
7 #include <mist/flv_tag.h>
8 #include <mist/timing.h>
9 #include <mist/dtsc.h>
10 #include <mist/socket.h>
11 #include <mist/shared_memory.h>
12 /*LTS-START*/
13 #ifdef GEOIP
14 #include <GeoIP.h>
15 #endif
16 /*LTS-END*/
17 #include "../io.h"
18 
19 namespace Mist {
20 
23  struct sortedPageInfo {
24  bool operator < (const sortedPageInfo & rhs) const {
25  if (time < rhs.time) {
26  return true;
27  }
28  return (time == rhs.time && tid < rhs.tid);
29  }
30  unsigned int tid;
31  long long unsigned int time;
32  unsigned int offset;
33  };
34 
41  class Output : public InOutBase {
42  public:
43  //constructor and destructor
44  Output(Socket::Connection & conn);
45  virtual ~Output();
46  //static members for initialization and capabilities
47  static void init(Util::Config * cfg);
48  static JSON::Value capa;
49  /*LTS-START*/
50  #ifdef GEOIP
51  static GeoIP * geoIP4;
52  static GeoIP * geoIP6;
53  #endif
54  std::string reqUrl;
55  /*LTS-END*/
56  //non-virtual generic functions
57  int run();
58  void stats();
59  void seek(unsigned long long pos);
60  bool seek(unsigned int tid, unsigned long long pos, bool getNextKey = false);
61  void stop();
62  void setBlocking(bool blocking);
63  long unsigned int getMainSelectedTrack();
64  void updateMeta();
65  void selectDefaultTracks();
66  /*begin-roxlu*/
67  bool openOutputFileForRecording(); // Opens the output file and uses dup2() to make sure that all stdout is written into a file.
68  bool closeOutputFileForRecording(); // Closes the output file into which we're writing and resets the file descriptor.
69  /*end-roxlu*/
70  static bool listenMode(){return true;}
71  //virtuals. The optional virtuals have default implementations that do as little as possible.
72  virtual void sendNext() {}//REQUIRED! Others are optional.
73  virtual void prepareNext();
74  virtual void onRequest();
75  virtual bool onFinish() {
76  return false;
77  }
78  void reconnect();
79  virtual void initialize();
80  virtual void sendHeader();
81  virtual void onFail();
82  virtual void requestHandler();
83  virtual void onRecord(){
84  wantRequest = false;
85  parseData = true;
86  realTime = 1000;
87 
88  seek(0);
89  }
90  private://these *should* not be messed with in child classes.
91  /*LTS-START*/
92  void Log(std::string type, std::string message);
93  bool checkLimits();
94  bool isBlacklisted(std::string host, std::string streamName, int timeConnected);
95  std::string hostLookup(std::string ip);
96  bool onList(std::string ip, std::string list);
97  std::string getCountry(std::string ip);
98  /*LTS-END*/
99 
100 
101  std::map<unsigned long, unsigned int> currKeyOpen;
102  void loadPageForKey(long unsigned int trackId, long long int keyNum);
103  int pageNumForKey(long unsigned int trackId, long long int keyNum);
104  unsigned int lastStats;
105  long long unsigned int firstTime;
106  std::map<unsigned long, unsigned long> nxtKeyNum;
107  std::set<sortedPageInfo> buffer;
108  bool sought;
109  bool completeKeyReadyTimeOut;//a bool to see if there has been a keyframe TimeOut for complete keys in Live
110  protected://these are to be messed with by child classes
111 
112  virtual std::string getConnectedHost();
113  virtual std::string getConnectedBinHost();
114 
115 
118  unsigned int crc;
119  unsigned int getKeyForTime(long unsigned int trackId, long long timeStamp);
120 
121  //stream delaying variables
122  unsigned int maxSkipAhead;
123  unsigned int minSkipAhead;
124  unsigned int realTime;
126 
127  //Read/write status variables
129 
131  bool parseData;
134 
135  std::map<int,DTSCPageData> bookKeeping;
136  /*begin-roxlu*/
137  int outputFileDescriptor; // Write output into this file.
138  /*end-roxlu*/
139  bool recording();
140  };
141 
142 }
143 
unsigned int minSkipAhead
Minimum ms that we will go ahead of the intended timestamps.
Definition: output.h:123
bool wantRequest
If true, waits for a request.
Definition: output.h:130
std::string hostLookup(std::string ip)
Definition: controller_limits.cpp:190
unsigned int maxSkipAhead
Maximum ms that we will go ahead of the intended timestamps.
Definition: output.h:122
Class containing all basic input and output functions.
Definition: io.h:66
bool completeKeysOnly
Bool if we send whole keys only, so the metadata is complete and the output knows in advance what wil...
Definition: output.h:125
Socket::Connection & myConn
Connection to the client.
Definition: output.h:128
unsigned int tid
Definition: output.h:30
unsigned int crc
Checksum, if any, for usage in the stats.
Definition: output.h:118
A JSON::Value is either a string or an integer, but may also be an object, array or null...
Definition: json.h:21
static JSON::Value capa
Definition: output.h:48
unsigned int realTime
Playback speed in ms of data per second. eg: 0 is infinite, 1000 real-time, 5000 is 0...
Definition: output.h:124
std::set< sortedPageInfo > buffer
A sorted list of next-to-be-loaded packets.
Definition: output.h:107
Recording to file.
Definition: input.cpp:13
virtual bool onFinish()
Definition: output.h:75
unsigned int lastStats
Time of last sending of stats.
Definition: output.h:104
std::map< unsigned long, unsigned long > nxtKeyNum
Contains the number of the next key, for page seeking purposes.
Definition: output.h:106
The output class is intended to be inherited by MistOut process classes.
Definition: output.h:41
std::string reqUrl
Definition: output.h:54
std::map< unsigned long, unsigned int > currKeyOpen
Definition: output.h:101
The client part of a server/client model for shared memory.
Definition: shared_memory.h:212
Deals with parsing configuration from commandline options.
Definition: config.h:18
void Log(std::string kind, std::string message)
Store and print a log message.
Definition: controller_storage.cpp:22
std::string getCountry(std::string ip)
Definition: controller_limits.cpp:376
bool sentHeader
If false, triggers sendHeader if parseData is true.
Definition: output.h:133
IPC::sharedClient statsPage
Shared memory used for statistics reporting.
Definition: output.h:116
bool operator<(const sortedPageInfo &rhs) const
Definition: output.h:24
std::map< int, DTSCPageData > bookKeeping
Definition: output.h:135
static bool listenMode()
Definition: output.h:70
function init(plot)
Definition: jquery.flot.time.min.js:1
This struct keeps packet information sorted in playback order, so the Mist::Output class knows when t...
Definition: output.h:23
bool isBlocking
If true, indicates that myConn is blocking.
Definition: output.h:117
bool isInitialized
If false, triggers initialization if parseData is true.
Definition: output.h:132
bool sought
If a seek has been done, this is set to true. Used for seeking on prepareNext().
Definition: output.h:108
bool parseData
If true, triggers initalization if not already done, sending of header, sending of packets...
Definition: output.h:131
int outputFileDescriptor
Definition: output.h:137
long long unsigned int time
Definition: output.h:31
unsigned int offset
Definition: output.h:32
bool completeKeyReadyTimeOut
Definition: output.h:109
virtual void sendNext()
Definition: output.h:72
bool isBlacklisted(std::string host, std::string streamName, int timeConnected)
Definition: controller_limits.cpp:208
virtual void onRecord()
Definition: output.h:83
long long unsigned int firstTime
Time of first packet after last seek. Used for real-time sending.
Definition: output.h:105
This class is for easy communicating through sockets, either TCP or Unix.
Definition: socket.h:47
bool onList(std::string ip, std::string list)
Definition: controller_limits.cpp:145