Updated buffer and controller for upcoming features.

This commit is contained in:
Thulinma 2013-11-18 16:48:59 +01:00
parent 1986b1517b
commit 0a3b34e9b6
7 changed files with 306 additions and 451 deletions

View file

@ -11,18 +11,12 @@
namespace Buffer {
/// Keeps track of a single streams inputs and outputs, taking care of thread safety and all other related issues.
class Stream{
class Stream : public DTSC::Stream{
public:
/// Get a reference to this Stream object.
static Stream * get();
/// Get the current statistics in JSON format.
std::string & getStats();
/// Get a new DTSC::Ring object for a user.
DTSC::Ring * getRing();
/// Drop a DTSC::Ring object.
void dropRing(DTSC::Ring * ring);
/// Get the (constant) header data of this stream.
std::string & getHeader();
/// Set the IP address to accept push data from.
void setWaitingIP(std::string ip);
/// Check if this is the IP address to accept push data from.
@ -35,29 +29,25 @@ namespace Buffer {
void saveStats(std::string username, Stats & stats);
/// Stores final statistics.
void clearStats(std::string username, Stats & stats, std::string reason);
/// Blocks until writing is safe.
void getWriteLock();
/// Drops a previously gotten write lock.
void dropWriteLock(bool newpackets_available);
/// Blocks until reading is safe.
void getReadLock();
/// Drops a previously gotten read lock.
void dropReadLock();
/// Retrieves a reference to the DTSC::Stream
DTSC::Stream * getStream();
/// Sets the buffer name.
void setName(std::string n);
/// Add a user to the userlist.
void addUser(user * newUser);
/// Delete a user from the userlist.
void removeUser(user * oldUser);
/// Disconnects all users.
void disconnectUsers();
/// Blocks the thread until new data is available.
void waitForData();
/// Sends the metadata to a specific socket
void sendMeta(Socket::Connection & s);
/// Cleanup function
~Stream();
private:
/// TODO: WRITEME
bool parsePacket(std::string & buffer);
bool parsePacket(Socket::Buffer & buffer);
DTSC::livePos getNext(DTSC::livePos & pos, std::set<int> & allowedTracks);
void cutBefore(int whereToCut);
private:
void deletionCallback(DTSC::livePos deleting);
volatile int readers; ///< Current count of active readers;
volatile int writers; ///< Current count of waiting/active writers.
tthread::mutex rw_mutex; ///< Mutex for read/write locking.
@ -65,7 +55,6 @@ namespace Buffer {
static Stream * ref;
Stream();
JSON::Value Storage; ///< Global storage of data.
DTSC::Stream * Strm;
std::string waiting_ip; ///< IP address for media push.
Socket::Connection ip_input; ///< Connection used for media push.
tthread::recursive_mutex stats_mutex; ///< Mutex for stats/users modifications.