-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstream_handler.h
48 lines (42 loc) · 1.16 KB
/
stream_handler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef STREAM_HANDLER_H_INC
#define STREAM_HANDLER_H_INC
#include <vector>
#include <string>
#include <functional>
#include "ui/image_transport.h"
//#include "memory_buffer.h"
class stream_handler {
private:
image_transport& trans;
sigc::signal<void, size_t> received_data;
size_t obj_write(void*, size_t);
protected:
image_transport& transport() { return trans; }
public:
virtual size_t add_data(const char*, size_t) = 0; //need to copy buffer
static size_t write(void*, size_t, size_t, void*);
stream_handler(image_transport& t) : trans(t) {}
void reset();
sigc::signal<void, size_t>& signal_received_data();
};
class mjpeg_stream_handler : public stream_handler {
public:
mjpeg_stream_handler(image_transport&, const std::string&);
size_t add_data(const char*, size_t); //const as we need to copy the buffer
void process_data();
void reset();
void reset(const std::string&);
private:
std::string delim;
std::vector<char> buf;
std::string content_type;
size_t content_length;
enum state_t {
SEARCH,
CONTENT_TYPE,
CONTENT_LENGTH,
READ_DATA
};
state_t state;
};
#endif