#pragma once #include #include #include #include #include #include #include #include #include #include #include "../io.h" namespace Mist { /// This struct keeps packet information sorted in playback order, so the /// Mist::Output class knows when to buffer which packet. struct sortedPageInfo{ bool operator < (const sortedPageInfo & rhs) const { if (time < rhs.time){ return true; } return (time == rhs.time && tid < rhs.tid); } unsigned int tid; long long unsigned int time; unsigned int offset; }; /// 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. class Output : public InOutBase { public: //constructor and destructor Output(Socket::Connection & conn); //static members for initialization and capabilities static void init(Util::Config * cfg); static JSON::Value capa; //non-virtual generic functions virtual int run(); virtual void stats(bool force = false); void seek(unsigned long long pos, bool toKey = false); bool seek(unsigned int tid, unsigned long long pos, bool getNextKey = false); void stop(); uint64_t currentTime(); uint64_t startTime(); uint64_t endTime(); uint64_t liveTime(); void setBlocking(bool blocking); void updateMeta(); bool selectDefaultTracks(); bool connectToFile(std::string file); static bool listenMode(){return true;} uint32_t currTrackCount() const; virtual bool isReadyForPlay(); //virtuals. The optional virtuals have default implementations that do as little as possible. /// This function is called whenever a packet is ready for sending. /// Inside it, thisPacket is guaranteed to contain a valid packet. virtual void sendNext() {}//REQUIRED! Others are optional. bool prepareNext(); virtual void dropTrack(uint32_t trackId, std::string reason, bool probablyBad = true); virtual void onRequest(); static void listener(Util::Config & conf, int (*callback)(Socket::Connection & S)); virtual void initialSeek(); virtual bool onFinish() { return false; } void reconnect(); void disconnect(); virtual void initialize(); virtual void sendHeader(); virtual void onFail(const std::string & msg, bool critical = false); virtual void requestHandler(); static Util::Config * config; void playbackSleep(uint64_t millis); private://these *should* not be messed with in child classes. std::map currKeyOpen; void loadPageForKey(long unsigned int trackId, long long int keyNum); int pageNumForKey(long unsigned int trackId, long long int keyNum); int pageNumMax(long unsigned int trackId); unsigned int lastStats;///