]> git.sesse.net Git - cubemap/blob - udpinput.h
Allow prebuffer to happen by playing data from the backlog.
[cubemap] / udpinput.h
1 #ifndef _UDPINPUT_H
2 #define _UDPINPUT_H 1
3
4 #include <pthread.h>
5 #include <string>
6 #include <vector>
7
8 #include "input.h"
9
10 class InputProto;
11
12 class UDPInput : public Input {
13 public:
14         UDPInput(const std::string &url);
15
16         // Serialization/deserialization.
17         UDPInput(const InputProto &serialized);
18         virtual InputProto serialize() const;
19
20         virtual std::string get_url() const { return url; }
21         virtual void close_socket();
22
23         virtual void add_destination(int stream_index);
24
25         virtual InputStats get_stats() const;
26
27 private:
28         // Actually gets the packets.
29         virtual void do_work();
30
31         // Create the HTTP header.
32         void construct_header();
33
34         std::vector<int> stream_indices;
35
36         // The URL and its parsed components.
37         std::string url;
38         std::string user, host, port, path;
39
40         // The HTTP header we're sending to clients.
41         std::string http_header;
42
43         // The socket we are receiving on (or -1).
44         int sock;
45
46         // Temporary buffer, sized for the maximum size of an UDP packet.
47         char packet_buf[65536];
48
49         // Mutex protecting <stats>.
50         mutable pthread_mutex_t stats_mutex;
51
52         // The current statistics for this connection. Protected by <stats_mutex>.
53         InputStats stats;
54 };
55
56 #endif  // !defined(_UDPINPUT_H)