summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-09-30 13:25:43 -0400
committerirungentoo <irungentoo@gmail.com>2014-09-30 13:25:43 -0400
commit45090ab2e51928ee1f1d96cc2a82dfc3d25c5cf0 (patch)
tree6d82f2cde52106e370c4bb5dcc80fcd67d9022d5
parent627e4d3aa629038b0e195f2189e9826b32c9531a (diff)
parenta46810a1976096ec6af2b809d85e6eeaa51b51ad (diff)
Merge branch 'rework_av'
-rw-r--r--toxav/rtp.c50
-rw-r--r--toxcore/util.c58
-rw-r--r--toxcore/util.h13
3 files changed, 35 insertions, 86 deletions
diff --git a/toxav/rtp.c b/toxav/rtp.c
index de6c9c41..a4e1b12e 100644
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -88,7 +88,8 @@ RTPHeader *extract_header ( const uint8_t *payload, int length )
88 return NULL; 88 return NULL;
89 } 89 }
90 90
91 bytes_to_U16(&_retu->sequnum, payload); 91 memcpy(&_retu->sequnum, payload, sizeof(_retu->sequnum));
92 _retu->sequnum = ntohs(_retu->sequnum);
92 93
93 const uint8_t *_it = payload + 2; 94 const uint8_t *_it = payload + 2;
94 95
@@ -128,15 +129,18 @@ RTPHeader *extract_header ( const uint8_t *payload, int length )
128 _retu->length = _length; 129 _retu->length = _length;
129 130
130 131
131 bytes_to_U32(&_retu->timestamp, _it); 132 memcpy(&_retu->timestamp, _it, sizeof(_retu->timestamp));
133 _retu->timestamp = ntohl(_retu->timestamp);
132 _it += 4; 134 _it += 4;
133 bytes_to_U32(&_retu->ssrc, _it); 135 memcpy(&_retu->ssrc, _it, sizeof(_retu->ssrc));
136 _retu->ssrc = ntohl(_retu->ssrc);
134 137
135 uint8_t _x; 138 uint8_t _x;
136 139
137 for ( _x = 0; _x < _cc; _x++ ) { 140 for ( _x = 0; _x < _cc; _x++ ) {
138 _it += 4; 141 _it += 4;
139 bytes_to_U32(&(_retu->csrc[_x]), _it); 142 memcpy(&_retu->csrc[_x], _it, sizeof(_retu->csrc[_x]));
143 _retu->csrc[_x] = ntohl(_retu->csrc[_x]);
140 } 144 }
141 145
142 return _retu; 146 return _retu;
@@ -162,7 +166,8 @@ RTPExtHeader *extract_ext_header ( const uint8_t *payload, uint16_t length )
162 } 166 }
163 167
164 uint16_t _ext_length; 168 uint16_t _ext_length;
165 bytes_to_U16(&_ext_length, _it); 169 memcpy(&_ext_length, _it, sizeof(_ext_length));
170 _ext_length = ntohs(_ext_length);
166 _it += 2; 171 _it += 2;
167 172
168 173
@@ -173,7 +178,8 @@ RTPExtHeader *extract_ext_header ( const uint8_t *payload, uint16_t length )
173 } 178 }
174 179
175 _retu->length = _ext_length; 180 _retu->length = _ext_length;
176 bytes_to_U16(&_retu->type, _it); 181 memcpy(&_retu->type, _it, sizeof(_retu->type));
182 _retu->type = ntohs(_retu->type);
177 _it += 2; 183 _it += 2;
178 184
179 if ( !(_retu->table = calloc(_ext_length, sizeof (uint32_t))) ) { 185 if ( !(_retu->table = calloc(_ext_length, sizeof (uint32_t))) ) {
@@ -186,7 +192,8 @@ RTPExtHeader *extract_ext_header ( const uint8_t *payload, uint16_t length )
186 192
187 for ( _x = 0; _x < _ext_length; _x++ ) { 193 for ( _x = 0; _x < _ext_length; _x++ ) {
188 _it += 4; 194 _it += 4;
189 bytes_to_U32(&(_retu->table[_x]), _it); 195 memcpy(&(_retu->table[_x]), _it, sizeof(_retu->table[_x]));
196 _retu->table[_x] = ntohl(_retu->table[_x]);
190 } 197 }
191 198
192 return _retu; 199 return _retu;
@@ -202,12 +209,16 @@ RTPExtHeader *extract_ext_header ( const uint8_t *payload, uint16_t length )
202uint8_t *add_header ( RTPHeader *header, uint8_t *payload ) 209uint8_t *add_header ( RTPHeader *header, uint8_t *payload )
203{ 210{
204 uint8_t _cc = GET_FLAG_CSRCC ( header ); 211 uint8_t _cc = GET_FLAG_CSRCC ( header );
205
206 uint8_t *_it = payload; 212 uint8_t *_it = payload;
213 uint16_t sequnum;
214 uint32_t timestamp;
215 uint32_t ssrc;
216 uint32_t csrc;
207 217
208 218
209 /* Add sequence number first */ 219 /* Add sequence number first */
210 U16_to_bytes(_it, header->sequnum); 220 sequnum = htons(header->sequnum);
221 memcpy(_it, &sequnum, sizeof(sequnum));
211 _it += 2; 222 _it += 2;
212 223
213 *_it = header->flags; 224 *_it = header->flags;
@@ -216,15 +227,18 @@ uint8_t *add_header ( RTPHeader *header, uint8_t *payload )
216 ++_it; 227 ++_it;
217 228
218 229
219 U32_to_bytes( _it, header->timestamp); 230 timestamp = htonl(header->timestamp);
231 memcpy(_it, &timestamp, sizeof(timestamp));
220 _it += 4; 232 _it += 4;
221 U32_to_bytes( _it, header->ssrc); 233 ssrc = htonl(header->ssrc);
234 memcpy(_it, &ssrc, sizeof(ssrc));
222 235
223 uint8_t _x; 236 uint8_t _x;
224 237
225 for ( _x = 0; _x < _cc; _x++ ) { 238 for ( _x = 0; _x < _cc; _x++ ) {
226 _it += 4; 239 _it += 4;
227 U32_to_bytes( _it, header->csrc[_x]); 240 csrc = htonl(header->csrc[_x]);
241 memcpy(_it, &csrc, sizeof(csrc));
228 } 242 }
229 243
230 return _it + 4; 244 return _it + 4;
@@ -240,10 +254,15 @@ uint8_t *add_header ( RTPHeader *header, uint8_t *payload )
240uint8_t *add_ext_header ( RTPExtHeader *header, uint8_t *payload ) 254uint8_t *add_ext_header ( RTPExtHeader *header, uint8_t *payload )
241{ 255{
242 uint8_t *_it = payload; 256 uint8_t *_it = payload;
257 uint16_t length;
258 uint16_t type;
259 uint32_t entry;
243 260
244 U16_to_bytes(_it, header->length); 261 length = htons(header->length);
262 memcpy(_it, &length, sizeof(length));
245 _it += 2; 263 _it += 2;
246 U16_to_bytes(_it, header->type); 264 type = htons(header->type);
265 memcpy(_it, &type, sizeof(type));
247 _it -= 2; /* Return to 0 position */ 266 _it -= 2; /* Return to 0 position */
248 267
249 if ( header->table ) { 268 if ( header->table ) {
@@ -251,7 +270,8 @@ uint8_t *add_ext_header ( RTPExtHeader *header, uint8_t *payload )
251 270
252 for ( _x = 0; _x < header->length; _x++ ) { 271 for ( _x = 0; _x < header->length; _x++ ) {
253 _it += 4; 272 _it += 4;
254 U32_to_bytes(_it, header->table[_x]); 273 entry = htonl(header->table[_x]);
274 memcpy(_it, &entry, sizeof(entry));
255 } 275 }
256 } 276 }
257 277
diff --git a/toxcore/util.c b/toxcore/util.c
index 969ee704..ee4fa3b2 100644
--- a/toxcore/util.c
+++ b/toxcore/util.c
@@ -133,61 +133,3 @@ int load_state(load_state_callback_func load_state_callback, void *outer,
133 133
134 return length == 0 ? 0 : -1; 134 return length == 0 ? 0 : -1;
135}; 135};
136
137/* Converts 4 bytes to uint32_t */
138inline__ void bytes_to_U32(uint32_t *dest, const uint8_t *bytes)
139{
140 *dest =
141#ifdef WORDS_BIGENDIAN
142 ( ( uint32_t ) * bytes ) |
143 ( ( uint32_t ) * ( bytes + 1 ) << 8 ) |
144 ( ( uint32_t ) * ( bytes + 2 ) << 16 ) |
145 ( ( uint32_t ) * ( bytes + 3 ) << 24 ) ;
146#else
147 ( ( uint32_t ) * bytes << 24 ) |
148 ( ( uint32_t ) * ( bytes + 1 ) << 16 ) |
149 ( ( uint32_t ) * ( bytes + 2 ) << 8 ) |
150 ( ( uint32_t ) * ( bytes + 3 ) ) ;
151#endif
152}
153
154/* Converts 2 bytes to uint16_t */
155inline__ void bytes_to_U16(uint16_t *dest, const uint8_t *bytes)
156{
157 *dest =
158#ifdef WORDS_BIGENDIAN
159 ( ( uint16_t ) * bytes ) |
160 ( ( uint16_t ) * ( bytes + 1 ) << 8 );
161#else
162 ( ( uint16_t ) * bytes << 8 ) |
163 ( ( uint16_t ) * ( bytes + 1 ) );
164#endif
165}
166
167/* Convert uint32_t to byte string of size 4 */
168inline__ void U32_to_bytes(uint8_t *dest, uint32_t value)
169{
170#ifdef WORDS_BIGENDIAN
171 *(dest) = ( value );
172 *(dest + 1) = ( value >> 8 );
173 *(dest + 2) = ( value >> 16 );
174 *(dest + 3) = ( value >> 24 );
175#else
176 *(dest) = ( value >> 24 );
177 *(dest + 1) = ( value >> 16 );
178 *(dest + 2) = ( value >> 8 );
179 *(dest + 3) = ( value );
180#endif
181}
182
183/* Convert uint16_t to byte string of size 2 */
184inline__ void U16_to_bytes(uint8_t *dest, uint16_t value)
185{
186#ifdef WORDS_BIGENDIAN
187 *(dest) = ( value );
188 *(dest + 1) = ( value >> 8 );
189#else
190 *(dest) = ( value >> 8 );
191 *(dest + 1) = ( value );
192#endif
193} \ No newline at end of file
diff --git a/toxcore/util.h b/toxcore/util.h
index 955ce8c4..7992a985 100644
--- a/toxcore/util.h
+++ b/toxcore/util.h
@@ -47,17 +47,4 @@ typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32
47int load_state(load_state_callback_func load_state_callback, void *outer, 47int load_state(load_state_callback_func load_state_callback, void *outer,
48 const uint8_t *data, uint32_t length, uint16_t cookie_inner); 48 const uint8_t *data, uint32_t length, uint16_t cookie_inner);
49 49
50/* Converts 4 bytes to uint32_t */
51void bytes_to_U32(uint32_t *dest, const uint8_t *bytes);
52
53/* Converts 2 bytes to uint16_t */
54void bytes_to_U16(uint16_t *dest, const uint8_t *bytes);
55
56/* Convert uint32_t to byte string of size 4 */
57void U32_to_bytes(uint8_t *dest, uint32_t value);
58
59/* Convert uint16_t to byte string of size 2 */
60void U16_to_bytes(uint8_t *dest, uint16_t value);
61
62
63#endif /* __UTIL_H__ */ 50#endif /* __UTIL_H__ */