]> git.sesse.net Git - cubemap/blob - metacube2.h
Fix a crash when a HTTP input connected to an UDP output goes unavailable.
[cubemap] / metacube2.h
1 #ifndef _METACUBE2_H
2 #define _METACUBE2_H
3
4 /*
5  * Definitions for the Metacube2 protocol, used to communicate with Cubemap.
6  *
7  * Note: This file is meant to compile as both C and C++, for easier inclusion
8  * in other projects.
9  */
10
11 #include <stdint.h>
12
13 #define METACUBE2_SYNC "cube!map"  /* 8 bytes long. */
14 #define METACUBE_FLAGS_HEADER 0x1
15 #define METACUBE_FLAGS_NOT_SUITABLE_FOR_STREAM_START 0x2
16
17 /*
18  * Metadata packets; should not be counted as data, but rather
19  * parsed (or ignored if you don't understand them).
20  *
21  * Metadata packets start with a uint64_t (network byte order)
22  * that describe the type; the rest is defined by the type.
23  */
24 #define METACUBE_FLAGS_METADATA 0x4
25
26 struct metacube2_block_header {
27         char sync[8];    /* METACUBE2_SYNC */
28         uint32_t size;   /* Network byte order. Does not include header. */
29         uint16_t flags;  /* Network byte order. METACUBE_FLAGS_*. */
30         uint16_t csum;   /* Network byte order. CRC16 of size and flags.
31                             If METACUBE_FLAGS_METADATA is set, inverted
32                             so that older clients will ignore it as broken. */
33 };
34
35 uint16_t metacube2_compute_crc(const struct metacube2_block_header *hdr);
36
37 /*
38  * Set by the encoder, and can be measured for latency purposes (e.g., if the
39  * network can't keep up, the latency will tend to increase.
40  */
41 #define METACUBE_METADATA_TYPE_ENCODER_TIMESTAMP 0x1
42
43 struct metacube2_timestamp_packet {
44         uint64_t type;  /* METACUBE_METADATA_TYPE_ENCODER_TIMESTAMP, in network byte order. */
45
46         /*
47          * Time since the UTC epoch. Basically a struct timespec.
48          * Both are in network byte order.
49          */
50         uint64_t tv_sec;
51         uint64_t tv_nsec;
52 };
53
54 /*
55  * Sent before a block to mark its presentation timestamp (ie., counts
56  * only for the next Metacube block). Used so that the reflector can know
57  * the length (in seconds) of fragments.
58  */
59 #define METACUBE_METADATA_TYPE_NEXT_BLOCK_PTS 0x2
60
61 struct metacube2_pts_packet {
62         uint64_t type;  /* METACUBE_METADATA_TYPE_NEXT_BLOCK_PTS, in network byte order. */
63
64         /* The timestamp of the first packet in the next block, in network byte order. */
65         int64_t pts;
66
67         /* Timebase "pts" is expressed in, as a fraction. Network byte order. */
68         uint64_t timebase_num, timebase_den;
69 };
70
71 #endif  /* !defined(_METACUBE_H) */