-struct Client {
- enum State { READING_REQUEST, SENDING_HEADER, SENDING_DATA };
- State state;
-
- // The HTTP request, as sent by the client. If we are in READING_REQUEST,
- // this might not be finished.
- string client_request;
-
-#if 0
- // What stream we're connecting to; parsed from client_request.
- // Not relevant for READING_REQUEST.
- string stream_id;
-#endif
-
- // Number of bytes we've sent of the header. Only relevant for SENDING_HEADER.
- size_t header_bytes_sent;
-
- // Number of bytes we've sent of data. Only relevant for SENDING_DATA.
- size_t bytes_sent;
-};
-
-struct Stream {
- // The HTTP response header, plus the video stream header (if any).
- string header;
-
- // The stream data itself, stored in a circular buffer.
- char data[BACKLOG_SIZE];
-
- // How many bytes <data> contains. Can very well be larger than BACKLOG_SIZE,
- // since the buffer wraps.
- size_t data_size;
-};
-
-class Server {
-public:
- void add_socket(int server_sock);
- void add_stream(const string &stream_id);
- void set_header(const string &stream_id, const string &header);
- void add_data(const string &stream_id, const char *data, size_t bytes);
-
-private:
- map<string, Stream> streams;
-};
-
-class Input {
-public:
- Input();
- void curl_callback(char *ptr, size_t bytes);
-
-private:
- void process_block(const char *data, uint32_t size, uint32_t flags);
- void drop_pending_data(size_t num_bytes);
-
- // Data we have received but not fully processed yet.
- vector<char> pending_data;
-
- // If <pending_data> starts with a Metacube header,
- // this is true.
- bool has_metacube_header;
-};
-
-Input::Input()
- : has_metacube_header(false)