diff options
Diffstat (limited to 'toxav/rtp.h')
-rw-r--r-- | toxav/rtp.h | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/toxav/rtp.h b/toxav/rtp.h new file mode 100644 index 00000000..4b0d681f --- /dev/null +++ b/toxav/rtp.h | |||
@@ -0,0 +1,216 @@ | |||
1 | /** toxrtp.h | ||
2 | * | ||
3 | * Copyright (C) 2013 Tox project All Rights Reserved. | ||
4 | * | ||
5 | * This file is part of Tox. | ||
6 | * | ||
7 | * Tox is free software: you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation, either version 3 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * Tox is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with Tox. If not, see <http://www.gnu.org/licenses/>. | ||
19 | * | ||
20 | * | ||
21 | * Report bugs/suggestions to me ( mannol ) at either #tox-dev @ freenode.net:6667 or | ||
22 | * my email: eniz_vukovic@hotmail.com | ||
23 | */ | ||
24 | |||
25 | #ifndef __TOXRTP | ||
26 | #define __TOXRTP | ||
27 | |||
28 | #define RTP_VERSION 2 | ||
29 | #include <inttypes.h> | ||
30 | #include <pthread.h> | ||
31 | #include "../toxcore/tox.h" | ||
32 | |||
33 | #define MAX_SEQU_NUM 65535 | ||
34 | #define MAX_RTP_SIZE 10400 | ||
35 | |||
36 | /** | ||
37 | * @brief Standard rtp header | ||
38 | * | ||
39 | */ | ||
40 | |||
41 | typedef struct _RTPHeader { | ||
42 | uint8_t flags; /* Version(2),Padding(1), Ext(1), Cc(4) */ | ||
43 | uint8_t marker_payloadt; /* Marker(1), PlayLoad Type(7) */ | ||
44 | uint16_t sequnum; /* Sequence Number */ | ||
45 | uint32_t timestamp; /* Timestamp */ | ||
46 | uint32_t ssrc; /* SSRC */ | ||
47 | uint32_t* csrc; /* CSRC's table */ | ||
48 | uint32_t length; /* Length of the header in payload string. */ | ||
49 | |||
50 | } RTPHeader; | ||
51 | |||
52 | |||
53 | /** | ||
54 | * @brief Standard rtp extension header. | ||
55 | * | ||
56 | */ | ||
57 | typedef struct _RTPExtHeader { | ||
58 | uint16_t type; /* Extension profile */ | ||
59 | uint16_t length; /* Number of extensions */ | ||
60 | uint32_t* table; /* Extension's table */ | ||
61 | |||
62 | } RTPExtHeader; | ||
63 | |||
64 | |||
65 | /** | ||
66 | * @brief Standard rtp message. | ||
67 | * | ||
68 | */ | ||
69 | typedef struct _RTPMessage { | ||
70 | RTPHeader* header; | ||
71 | RTPExtHeader* ext_header; | ||
72 | |||
73 | uint8_t data[MAX_RTP_SIZE]; | ||
74 | uint32_t length; | ||
75 | tox_IP_Port from; | ||
76 | |||
77 | struct _RTPMessage* next; | ||
78 | } RTPMessage; | ||
79 | |||
80 | |||
81 | /** | ||
82 | * @brief Our main session descriptor. | ||
83 | * It measures the session variables and controls | ||
84 | * the entire session. There are functions for manipulating | ||
85 | * the session so tend to use those instead of directly modifying | ||
86 | * session parameters. | ||
87 | * | ||
88 | */ | ||
89 | typedef struct _RTPSession { | ||
90 | uint8_t version; | ||
91 | uint8_t padding; | ||
92 | uint8_t extension; | ||
93 | uint8_t cc; | ||
94 | uint8_t marker; | ||
95 | uint8_t payload_type; | ||
96 | uint16_t sequnum; /* Set when sending */ | ||
97 | uint16_t rsequnum; /* Check when recving msg */ | ||
98 | uint32_t timestamp; | ||
99 | uint32_t ssrc; | ||
100 | uint32_t* csrc; | ||
101 | |||
102 | /* If some additional data must be sent via message | ||
103 | * apply it here. Only by allocating this member you will be | ||
104 | * automatically placing it within a message. | ||
105 | */ | ||
106 | RTPExtHeader* ext_header; | ||
107 | |||
108 | /* External header identifiers */ | ||
109 | int resolution; | ||
110 | int framerate; | ||
111 | |||
112 | |||
113 | /* Since these are only references of the | ||
114 | * call structure don't allocate or free | ||
115 | */ | ||
116 | |||
117 | const uint8_t* encrypt_key; | ||
118 | const uint8_t* decrypt_key; | ||
119 | uint8_t* encrypt_nonce; | ||
120 | uint8_t* decrypt_nonce; | ||
121 | |||
122 | uint8_t* nonce_cycle; | ||
123 | |||
124 | RTPMessage* oldest_msg; | ||
125 | RTPMessage* last_msg; /* tail */ | ||
126 | |||
127 | /* Msg prefix for core to know when recving */ | ||
128 | uint8_t prefix; | ||
129 | |||
130 | pthread_mutex_t mutex; | ||
131 | tox_IP_Port dest; | ||
132 | |||
133 | } RTPSession; | ||
134 | |||
135 | |||
136 | /** | ||
137 | * @brief Release all messages held by session. | ||
138 | * | ||
139 | * @param session The session. | ||
140 | * @return int | ||
141 | * @retval -1 Error occurred. | ||
142 | * @retval 0 Success. | ||
143 | */ | ||
144 | int rtp_release_session_recv ( RTPSession* session ); | ||
145 | |||
146 | |||
147 | /** | ||
148 | * @brief Get's oldest message in the list. | ||
149 | * | ||
150 | * @param session Where the list is. | ||
151 | * @return RTPMessage* The message. You need to call rtp_msg_free() to free it. | ||
152 | * @retval NULL No messages in the list, or no list. | ||
153 | */ | ||
154 | RTPMessage* rtp_recv_msg ( RTPSession* session ); | ||
155 | |||
156 | |||
157 | /** | ||
158 | * @brief Sends msg to _RTPSession::dest | ||
159 | * | ||
160 | * @param session The session. | ||
161 | * @param msg The message | ||
162 | * @param messenger Tox* object. | ||
163 | * @return int | ||
164 | * @retval -1 On error. | ||
165 | * @retval 0 On success. | ||
166 | */ | ||
167 | int rtp_send_msg ( RTPSession* session, Tox* messenger, const uint8_t* data, uint16_t length ); | ||
168 | |||
169 | |||
170 | /** | ||
171 | * @brief Speaks for it self. | ||
172 | * | ||
173 | * @param session The control session msg belongs to. It can be NULL. | ||
174 | * @param msg The message. | ||
175 | * @return void | ||
176 | */ | ||
177 | void rtp_free_msg ( RTPSession* session, RTPMessage* msg ); | ||
178 | |||
179 | |||
180 | /** | ||
181 | * @brief Must be called before calling any other rtp function. It's used | ||
182 | * to initialize RTP control session. | ||
183 | * | ||
184 | * @param payload_type Type of payload used to send. You can use values in toxmsi.h::MSICallType | ||
185 | * @param messenger Tox* object. | ||
186 | * @param friend_num Friend id. | ||
187 | * @param encrypt_key Speaks for it self. | ||
188 | * @param decrypt_key Speaks for it self. | ||
189 | * @param encrypt_nonce Speaks for it self. | ||
190 | * @param decrypt_nonce Speaks for it self. | ||
191 | * @return RTPSession* Created control session. | ||
192 | * @retval NULL Error occurred. | ||
193 | */ | ||
194 | RTPSession* rtp_init_session ( int payload_type, | ||
195 | Tox* messenger, | ||
196 | int friend_num, | ||
197 | const uint8_t* encrypt_key, | ||
198 | const uint8_t* decrypt_key, | ||
199 | const uint8_t* encrypt_nonce, | ||
200 | const uint8_t* decrypt_nonce ); | ||
201 | |||
202 | |||
203 | /** | ||
204 | * @brief Terminate the session. | ||
205 | * | ||
206 | * @param session The session. | ||
207 | * @param messenger The messenger who owns the session | ||
208 | * @return int | ||
209 | * @retval -1 Error occurred. | ||
210 | * @retval 0 Success. | ||
211 | */ | ||
212 | int rtp_terminate_session ( RTPSession* session, Tox* messenger ); | ||
213 | |||
214 | |||
215 | |||
216 | #endif /* __TOXRTP */ | ||