]> git.sesse.net Git - cubemap/blob - input.h
Change from level-triggered to edge-triggered epoll mode. More than halves CPU usage.
[cubemap] / input.h
1 #ifndef _INPUT_H
2 #define _INPUT_H 1
3
4 #include <vector>
5 #include <string>
6
7 class Input {
8 public:
9         Input(const std::string &stream_id, const std::string &url);
10
11         // Connect to the given URL and start streaming.
12         void run();
13
14         // Stop streaming. NOTE: Does not currently work!
15         void stop();
16
17 private:
18         // Recovers the this pointer and calls do_work().
19         static void *do_work_thunk(void *arg);
20
21         // Actually does the download.
22         void do_work();
23
24         // Recovers the this pointer and calls curl_callback().
25         static size_t curl_callback_thunk(char *ptr, size_t size, size_t nmemb, void *userdata);
26
27         // Stores the given data, looks for Metacube blocks (skipping data if needed),
28         // and calls process_block() for each one.
29         void curl_callback(char *ptr, size_t bytes);
30         void process_block(const char *data, uint32_t size, uint32_t flags);
31
32         // Drops <num_bytes> bytes from the head of <pending_data>,
33         // and outputs a warning.
34         void drop_pending_data(size_t num_bytes);
35
36         std::string stream_id;
37         std::string url;
38
39         // Data we have received but not fully processed yet.
40         std::vector<char> pending_data;
41
42         // If <pending_data> starts with a Metacube header,
43         // this is true.
44         bool has_metacube_header;
45
46         pthread_t worker_thread;
47
48         // Whether we should stop or not.
49         volatile bool should_stop;
50 };
51
52 #endif  // !defined(_INPUT_H)