diff options
author | irungentoo <irungentoo@gmail.com> | 2014-02-16 19:13:34 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-02-16 19:13:34 -0500 |
commit | 9d1eb27717472f5655242fac7b8123a44f1ff33c (patch) | |
tree | fd205f1ea53749717d9930d93ddb153fc8a16929 /toxav/rtp.h | |
parent | fd3dc22ef3bd77beb78faf24cd43e9d2b9706f5d (diff) | |
parent | f79b327fd639b2dcca9d4d2c137f93c1dce622fc (diff) |
Merge branch 'av-fix' into av-good
Diffstat (limited to 'toxav/rtp.h')
-rw-r--r-- | toxav/rtp.h | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/toxav/rtp.h b/toxav/rtp.h new file mode 100644 index 00000000..acec8b0a --- /dev/null +++ b/toxav/rtp.h | |||
@@ -0,0 +1,219 @@ | |||
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 at #tox-dev @ freenode.net:6667 | ||
22 | */ | ||
23 | |||
24 | #ifndef __TOXRTP | ||
25 | #define __TOXRTP | ||
26 | |||
27 | #define RTP_VERSION 2 | ||
28 | #include <inttypes.h> | ||
29 | #include <pthread.h> | ||
30 | |||
31 | #include "../toxcore/util.h" | ||
32 | #include "../toxcore/network.h" | ||
33 | #include "../toxcore/net_crypto.h" | ||
34 | #include "../toxcore/Messenger.h" | ||
35 | |||
36 | #define MAX_SEQU_NUM 65535 | ||
37 | #define MAX_RTP_SIZE 65535 | ||
38 | |||
39 | /** | ||
40 | * @brief Standard rtp header | ||
41 | * | ||
42 | */ | ||
43 | |||
44 | typedef struct _RTPHeader { | ||
45 | uint8_t flags; /* Version(2),Padding(1), Ext(1), Cc(4) */ | ||
46 | uint8_t marker_payloadt; /* Marker(1), PlayLoad Type(7) */ | ||
47 | uint16_t sequnum; /* Sequence Number */ | ||
48 | uint32_t timestamp; /* Timestamp */ | ||
49 | uint32_t ssrc; /* SSRC */ | ||
50 | uint32_t* csrc; /* CSRC's table */ | ||
51 | uint32_t length; /* Length of the header in payload string. */ | ||
52 | |||
53 | } RTPHeader; | ||
54 | |||
55 | |||
56 | /** | ||
57 | * @brief Standard rtp extension header. | ||
58 | * | ||
59 | */ | ||
60 | typedef struct _RTPExtHeader { | ||
61 | uint16_t type; /* Extension profile */ | ||
62 | uint16_t length; /* Number of extensions */ | ||
63 | uint32_t* table; /* Extension's table */ | ||
64 | |||
65 | } RTPExtHeader; | ||
66 | |||
67 | |||
68 | /** | ||
69 | * @brief Standard rtp message. | ||
70 | * | ||
71 | */ | ||
72 | typedef struct _RTPMessage { | ||
73 | RTPHeader* header; | ||
74 | RTPExtHeader* ext_header; | ||
75 | |||
76 | uint8_t data[MAX_RTP_SIZE]; | ||
77 | uint32_t length; | ||
78 | IP_Port from; | ||
79 | |||
80 | struct _RTPMessage* next; | ||
81 | } RTPMessage; | ||
82 | |||
83 | |||
84 | /** | ||
85 | * @brief Our main session descriptor. | ||
86 | * It measures the session variables and controls | ||
87 | * the entire session. There are functions for manipulating | ||
88 | * the session so tend to use those instead of directly modifying | ||
89 | * session parameters. | ||
90 | * | ||
91 | */ | ||
92 | typedef struct _RTPSession { | ||
93 | uint8_t version; | ||
94 | uint8_t padding; | ||
95 | uint8_t extension; | ||
96 | uint8_t cc; | ||
97 | uint8_t marker; | ||
98 | uint8_t payload_type; | ||
99 | uint16_t sequnum; /* Set when sending */ | ||
100 | uint16_t rsequnum; /* Check when recving msg */ | ||
101 | uint32_t timestamp; | ||
102 | uint32_t ssrc; | ||
103 | uint32_t* csrc; | ||
104 | |||
105 | /* If some additional data must be sent via message | ||
106 | * apply it here. Only by allocating this member you will be | ||
107 | * automatically placing it within a message. | ||
108 | */ | ||
109 | RTPExtHeader* ext_header; | ||
110 | |||
111 | /* External header identifiers */ | ||
112 | int resolution; | ||
113 | int framerate; | ||
114 | |||
115 | |||
116 | /* Since these are only references of the | ||
117 | * call structure don't allocate or free | ||
118 | */ | ||
119 | |||
120 | const uint8_t* encrypt_key; | ||
121 | const uint8_t* decrypt_key; | ||
122 | uint8_t* encrypt_nonce; | ||
123 | uint8_t* decrypt_nonce; | ||
124 | |||
125 | uint8_t* nonce_cycle; | ||
126 | |||
127 | RTPMessage* oldest_msg; | ||
128 | RTPMessage* last_msg; /* tail */ | ||
129 | |||
130 | /* Msg prefix for core to know when recving */ | ||
131 | uint8_t prefix; | ||
132 | |||
133 | pthread_mutex_t mutex; | ||
134 | int dest; | ||
135 | |||
136 | } RTPSession; | ||
137 | |||
138 | |||
139 | /** | ||
140 | * @brief Release all messages held by session. | ||
141 | * | ||
142 | * @param session The session. | ||
143 | * @return int | ||
144 | * @retval -1 Error occurred. | ||
145 | * @retval 0 Success. | ||
146 | */ | ||
147 | int rtp_release_session_recv ( RTPSession* session ); | ||
148 | |||
149 | |||
150 | /** | ||
151 | * @brief Get's oldest message in the list. | ||
152 | * | ||
153 | * @param session Where the list is. | ||
154 | * @return RTPMessage* The message. You need to call rtp_msg_free() to free it. | ||
155 | * @retval NULL No messages in the list, or no list. | ||
156 | */ | ||
157 | RTPMessage* rtp_recv_msg ( RTPSession* session ); | ||
158 | |||
159 | |||
160 | /** | ||
161 | * @brief Sends msg to _RTPSession::dest | ||
162 | * | ||
163 | * @param session The session. | ||
164 | * @param msg The message | ||
165 | * @param messenger Tox* object. | ||
166 | * @return int | ||
167 | * @retval -1 On error. | ||
168 | * @retval 0 On success. | ||
169 | */ | ||
170 | int rtp_send_msg ( RTPSession* session, Messenger* messenger, const uint8_t* data, uint16_t length ); | ||
171 | |||
172 | |||
173 | /** | ||
174 | * @brief Speaks for it self. | ||
175 | * | ||
176 | * @param session The control session msg belongs to. It can be NULL. | ||
177 | * @param msg The message. | ||
178 | * @return void | ||
179 | */ | ||
180 | void rtp_free_msg ( RTPSession* session, RTPMessage* msg ); | ||
181 | |||
182 | |||
183 | /** | ||
184 | * @brief Must be called before calling any other rtp function. It's used | ||
185 | * to initialize RTP control session. | ||
186 | * | ||
187 | * @param payload_type Type of payload used to send. You can use values in toxmsi.h::MSICallType | ||
188 | * @param messenger Tox* object. | ||
189 | * @param friend_num Friend id. | ||
190 | * @param encrypt_key Speaks for it self. | ||
191 | * @param decrypt_key Speaks for it self. | ||
192 | * @param encrypt_nonce Speaks for it self. | ||
193 | * @param decrypt_nonce Speaks for it self. | ||
194 | * @return RTPSession* Created control session. | ||
195 | * @retval NULL Error occurred. | ||
196 | */ | ||
197 | RTPSession* rtp_init_session ( int payload_type, | ||
198 | Messenger* messenger, | ||
199 | int friend_num, | ||
200 | const uint8_t* encrypt_key, | ||
201 | const uint8_t* decrypt_key, | ||
202 | const uint8_t* encrypt_nonce, | ||
203 | const uint8_t* decrypt_nonce ); | ||
204 | |||
205 | |||
206 | /** | ||
207 | * @brief Terminate the session. | ||
208 | * | ||
209 | * @param session The session. | ||
210 | * @param messenger The messenger who owns the session | ||
211 | * @return int | ||
212 | * @retval -1 Error occurred. | ||
213 | * @retval 0 Success. | ||
214 | */ | ||
215 | int rtp_terminate_session ( RTPSession* session, Messenger* messenger ); | ||
216 | |||
217 | |||
218 | |||
219 | #endif /* __TOXRTP */ | ||