summaryrefslogtreecommitdiff
path: root/toxav/rtp.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxav/rtp.c')
-rw-r--r--toxav/rtp.c50
1 files changed, 35 insertions, 15 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