diff options
author | Eniz Vukovic <eniz_vukovic@hotmail.com> | 2015-10-10 23:54:23 +0200 |
---|---|---|
committer | Eniz Vukovic <eniz_vukovic@hotmail.com> | 2015-10-10 23:54:23 +0200 |
commit | d6fdf16520b6f242935ca95eeb739ec9a8eaa14c (patch) | |
tree | 069f3355835aa0497fe494c36554ea24d0b222f1 /toxav/rtp.h | |
parent | bf5e9b89d2a67c293aae503c03e193307ea7990b (diff) |
New Adaptive BR algorithm, cleanups and fixes
Diffstat (limited to 'toxav/rtp.h')
-rw-r--r-- | toxav/rtp.h | 139 |
1 files changed, 54 insertions, 85 deletions
diff --git a/toxav/rtp.h b/toxav/rtp.h index 9c5cf07d..fddbce3d 100644 --- a/toxav/rtp.h +++ b/toxav/rtp.h | |||
@@ -22,119 +22,88 @@ | |||
22 | #ifndef RTP_H | 22 | #ifndef RTP_H |
23 | #define RTP_H | 23 | #define RTP_H |
24 | 24 | ||
25 | #define RTP_VERSION 2 | 25 | #include "bwcontroler.h" |
26 | |||
27 | #include "../toxcore/Messenger.h" | 26 | #include "../toxcore/Messenger.h" |
28 | #include "stdbool.h" | 27 | #include "stdbool.h" |
29 | 28 | ||
30 | /** | 29 | /** |
31 | * Payload type identifier. Also used as rtp callback prefix. (Not dummies) | 30 | * Payload type identifier. Also used as rtp callback prefix. |
32 | */ | 31 | */ |
33 | enum { | 32 | enum { |
34 | rtp_TypeAudio = 192, | 33 | rtp_TypeAudio = 192, |
35 | rtp_TypeVideo, | 34 | rtp_TypeVideo, |
36 | }; | 35 | }; |
37 | 36 | ||
38 | enum { | 37 | struct RTPHeader { |
39 | rtp_StateBad = -1, | 38 | /* Standard RTP header */ |
40 | rtp_StateNormal, | 39 | #ifndef WORDS_BIGENDIAN |
41 | rtp_StateGood, | 40 | unsigned cc: 4; /* Contributing sources count */ |
42 | }; | 41 | unsigned xe: 1; /* Extra header */ |
42 | unsigned pe: 1; /* Padding */ | ||
43 | unsigned ve: 2; /* Version */ | ||
44 | |||
45 | unsigned pt: 7; /* Payload type */ | ||
46 | unsigned ma: 1; /* Marker */ | ||
47 | #else | ||
48 | unsigned ve: 2; /* Version */ | ||
49 | unsigned pe: 1; /* Padding */ | ||
50 | unsigned xe: 1; /* Extra header */ | ||
51 | unsigned cc: 4; /* Contributing sources count */ | ||
52 | |||
53 | unsigned ma: 1; /* Marker */ | ||
54 | unsigned pt: 7; /* Payload type */ | ||
55 | #endif | ||
56 | |||
57 | uint16_t sequnum; | ||
58 | uint32_t timestamp; | ||
59 | uint32_t ssrc; | ||
60 | uint32_t csrc[16]; | ||
43 | 61 | ||
44 | /** | 62 | /* Non-standard TOX-specific fields */ |
45 | * Standard rtp header. | 63 | uint16_t cpart;/* Data offset of the current part */ |
46 | */ | 64 | uint16_t tlen; /* Total message lenght */ |
47 | typedef struct { | 65 | } __attribute__ ((packed)); |
48 | uint8_t flags; /* Version(2),Padding(1), Ext(1), Cc(4) */ | ||
49 | uint8_t marker_payloadt; /* Marker(1), PlayLoad Type(7) */ | ||
50 | uint16_t sequnum; /* Sequence Number */ | ||
51 | uint32_t timestamp; /* Timestamp */ | ||
52 | uint32_t ssrc; /* SSRC */ | ||
53 | uint32_t csrc[16]; /* CSRC's table */ | ||
54 | uint32_t length; /* Length of the header in payload string. */ | ||
55 | } RTPHeader; | ||
56 | /** | ||
57 | * Standard rtp extension header. | ||
58 | */ | ||
59 | typedef struct { | ||
60 | uint16_t type; /* Extension profile */ | ||
61 | uint16_t length; /* Number of extensions */ | ||
62 | uint32_t *table; /* Extension's table */ | ||
63 | } RTPExtHeader; | ||
64 | 66 | ||
65 | /** | 67 | /* Check alignment */ |
66 | * Standard rtp message. | 68 | typedef char __fail_if_misaligned [ sizeof(struct RTPHeader) == 80 ? 1 : -1 ]; |
67 | */ | 69 | |
68 | typedef struct RTPMessage_s { | 70 | struct RTPMessage { |
69 | RTPHeader *header; | 71 | uint16_t len; |
70 | RTPExtHeader *ext_header; | 72 | |
73 | struct RTPHeader header; | ||
74 | uint8_t data[]; | ||
75 | } __attribute__ ((packed)); | ||
71 | 76 | ||
72 | uint32_t length; | 77 | /* Check alignment */ |
73 | uint8_t data[]; | 78 | typedef char __fail_if_misaligned [ sizeof(struct RTPMessage) == 82 ? 1 : -1 ]; |
74 | } RTPMessage; | ||
75 | 79 | ||
76 | /** | 80 | /** |
77 | * RTP control session. | 81 | * RTP control session. |
78 | */ | 82 | */ |
79 | typedef struct { | 83 | typedef struct { |
80 | uint8_t version; | ||
81 | uint8_t padding; | ||
82 | uint8_t extension; | ||
83 | uint8_t cc; | ||
84 | uint8_t marker; | ||
85 | uint8_t payload_type; | 84 | uint8_t payload_type; |
86 | uint16_t sequnum; /* Sending sequence number */ | 85 | uint16_t sequnum; /* Sending sequence number */ |
87 | uint16_t rsequnum; /* Receiving sequence number */ | 86 | uint16_t rsequnum; /* Receiving sequence number */ |
88 | uint32_t rtimestamp; | 87 | uint32_t rtimestamp; |
89 | uint32_t ssrc; | 88 | uint32_t ssrc; |
90 | uint32_t *csrc; | ||
91 | 89 | ||
92 | /* If some additional data must be sent via message | 90 | struct RTPMessage *mp; /* Expected parted message */ |
93 | * apply it here. Only by allocating this member you will be | ||
94 | * automatically placing it within a message. | ||
95 | */ | ||
96 | RTPExtHeader *ext_header; | ||
97 | |||
98 | /* Msg prefix for core to know when recving */ | ||
99 | uint8_t prefix; | ||
100 | 91 | ||
101 | Messenger *m; | 92 | Messenger *m; |
102 | int friend_number; | 93 | uint32_t friend_number; |
103 | struct RTCPSession_s *rtcp_session; | ||
104 | 94 | ||
95 | BWControler *bwc; | ||
105 | void *cs; | 96 | void *cs; |
106 | int (*mcb) (void*, RTPMessage* msg); | 97 | int (*mcb) (void *, struct RTPMessage *msg); |
107 | |||
108 | } RTPSession; | 98 | } RTPSession; |
109 | 99 | ||
110 | /** | ||
111 | * Must be called before calling any other rtp function. | ||
112 | */ | ||
113 | RTPSession *rtp_new ( int payload_type, Messenger *m, int friend_num, void* cs, int (*mcb) (void*, RTPMessage*) ); | ||
114 | /** | ||
115 | * Terminate the session. | ||
116 | */ | ||
117 | void rtp_kill ( RTPSession* session ); | ||
118 | /** | ||
119 | * Do periodical rtp work. | ||
120 | */ | ||
121 | int rtp_do(RTPSession *session); | ||
122 | /** | ||
123 | * By default rtp is in receiving state | ||
124 | */ | ||
125 | int rtp_start_receiving (RTPSession *session); | ||
126 | /** | ||
127 | * Pause rtp receiving mode. | ||
128 | */ | ||
129 | int rtp_stop_receiving (RTPSession *session); | ||
130 | /** | ||
131 | * Sends msg to RTPSession::dest | ||
132 | */ | ||
133 | int rtp_send_data ( RTPSession* session, const uint8_t* data, uint16_t length, bool dummy ); | ||
134 | /** | ||
135 | * Dealloc msg. | ||
136 | */ | ||
137 | void rtp_free_msg ( RTPMessage *msg ); | ||
138 | 100 | ||
101 | RTPSession *rtp_new (int payload_type, Messenger *m, uint32_t friend_num, | ||
102 | BWControler *bwc, void *cs, | ||
103 | int (*mcb) (void *, struct RTPMessage *)); | ||
104 | void rtp_kill (RTPSession *session); | ||
105 | int rtp_allow_receiving (RTPSession *session); | ||
106 | int rtp_stop_receiving (RTPSession *session); | ||
107 | int rtp_send_data (RTPSession *session, const uint8_t *data, uint16_t length); | ||
139 | 108 | ||
140 | #endif /* RTP_H */ | 109 | #endif /* RTP_H */ |