summaryrefslogtreecommitdiff
path: root/toxav/rtp.h
diff options
context:
space:
mode:
authorEniz Vukovic <eniz_vukovic@hotmail.com>2015-10-10 23:54:23 +0200
committerEniz Vukovic <eniz_vukovic@hotmail.com>2015-10-10 23:54:23 +0200
commitd6fdf16520b6f242935ca95eeb739ec9a8eaa14c (patch)
tree069f3355835aa0497fe494c36554ea24d0b222f1 /toxav/rtp.h
parentbf5e9b89d2a67c293aae503c03e193307ea7990b (diff)
New Adaptive BR algorithm, cleanups and fixes
Diffstat (limited to 'toxav/rtp.h')
-rw-r--r--toxav/rtp.h139
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 */
33enum { 32enum {
34 rtp_TypeAudio = 192, 33 rtp_TypeAudio = 192,
35 rtp_TypeVideo, 34 rtp_TypeVideo,
36}; 35};
37 36
38enum { 37struct 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 */
47typedef 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 */
59typedef 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. 68typedef char __fail_if_misaligned [ sizeof(struct RTPHeader) == 80 ? 1 : -1 ];
67 */ 69
68typedef struct RTPMessage_s { 70struct 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[]; 78typedef 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 */
79typedef struct { 83typedef 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 */
113RTPSession *rtp_new ( int payload_type, Messenger *m, int friend_num, void* cs, int (*mcb) (void*, RTPMessage*) );
114/**
115 * Terminate the session.
116 */
117void rtp_kill ( RTPSession* session );
118/**
119 * Do periodical rtp work.
120 */
121int rtp_do(RTPSession *session);
122/**
123 * By default rtp is in receiving state
124 */
125int rtp_start_receiving (RTPSession *session);
126/**
127 * Pause rtp receiving mode.
128 */
129int rtp_stop_receiving (RTPSession *session);
130/**
131 * Sends msg to RTPSession::dest
132 */
133int rtp_send_data ( RTPSession* session, const uint8_t* data, uint16_t length, bool dummy );
134/**
135 * Dealloc msg.
136 */
137void rtp_free_msg ( RTPMessage *msg );
138 100
101RTPSession *rtp_new (int payload_type, Messenger *m, uint32_t friend_num,
102 BWControler *bwc, void *cs,
103 int (*mcb) (void *, struct RTPMessage *));
104void rtp_kill (RTPSession *session);
105int rtp_allow_receiving (RTPSession *session);
106int rtp_stop_receiving (RTPSession *session);
107int rtp_send_data (RTPSession *session, const uint8_t *data, uint16_t length);
139 108
140#endif /* RTP_H */ 109#endif /* RTP_H */