diff options
Diffstat (limited to 'toxav/rtp.h')
-rw-r--r-- | toxav/rtp.h | 122 |
1 files changed, 74 insertions, 48 deletions
diff --git a/toxav/rtp.h b/toxav/rtp.h index c98840ac..b18d6f8d 100644 --- a/toxav/rtp.h +++ b/toxav/rtp.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /** rtp.h | 1 | /** rtp.h |
2 | * | 2 | * |
3 | * Copyright (C) 2013 Tox project All Rights Reserved. | 3 | * Copyright (C) 2013-2015 Tox project All Rights Reserved. |
4 | * | 4 | * |
5 | * This file is part of Tox. | 5 | * This file is part of Tox. |
6 | * | 6 | * |
@@ -19,25 +19,45 @@ | |||
19 | * | 19 | * |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef __TOXRTP | 22 | #ifndef RTP_H |
23 | #define __TOXRTP | 23 | #define RTP_H |
24 | 24 | ||
25 | #define RTP_VERSION 2 | 25 | #define RTP_VERSION 2 |
26 | #include <inttypes.h> | ||
27 | // #include <pthread.h> | ||
28 | 26 | ||
29 | #include "../toxcore/Messenger.h" | 27 | #include "../toxcore/Messenger.h" |
30 | 28 | ||
31 | #define MAX_SEQU_NUM 65535 | 29 | #define LOGGED_LOCK(mutex) do { \ |
32 | #define MAX_RTP_SIZE 65535 | 30 | /*LOGGER_DEBUG("Locking mutex: %p", mutex);*/\ |
31 | pthread_mutex_lock(mutex);\ | ||
32 | /*LOGGER_DEBUG("Locked mutex: %p", mutex);*/\ | ||
33 | } while(0) | ||
34 | |||
35 | #define LOGGED_UNLOCK(mutex) do { \ | ||
36 | /*LOGGER_DEBUG("Unlocking mutex: %p", mutex);*/\ | ||
37 | pthread_mutex_unlock(mutex);\ | ||
38 | /*LOGGER_DEBUG("Unlocked mutex: %p", mutex);*/\ | ||
39 | } while(0) | ||
40 | |||
41 | #define MAX_RTP_SIZE 1500 | ||
33 | 42 | ||
34 | typedef enum { | ||
35 | rtp_ErrorSending = -40 | ||
36 | } RTPError; | ||
37 | /** | 43 | /** |
38 | * Standard rtp header | 44 | * Payload type identifier. Also used as rtp callback prefix. (Not dummies) |
45 | */ | ||
46 | enum { | ||
47 | rtp_TypeAudio = 192, | ||
48 | rtp_TypeVideo, | ||
49 | }; | ||
50 | |||
51 | enum { | ||
52 | rtp_StateBad = -1, | ||
53 | rtp_StateNormal, | ||
54 | rtp_StateGood, | ||
55 | }; | ||
56 | |||
57 | /** | ||
58 | * Standard rtp header. | ||
39 | */ | 59 | */ |
40 | typedef struct _RTPHeader { | 60 | typedef struct { |
41 | uint8_t flags; /* Version(2),Padding(1), Ext(1), Cc(4) */ | 61 | uint8_t flags; /* Version(2),Padding(1), Ext(1), Cc(4) */ |
42 | uint8_t marker_payloadt; /* Marker(1), PlayLoad Type(7) */ | 62 | uint8_t marker_payloadt; /* Marker(1), PlayLoad Type(7) */ |
43 | uint16_t sequnum; /* Sequence Number */ | 63 | uint16_t sequnum; /* Sequence Number */ |
@@ -45,83 +65,89 @@ typedef struct _RTPHeader { | |||
45 | uint32_t ssrc; /* SSRC */ | 65 | uint32_t ssrc; /* SSRC */ |
46 | uint32_t csrc[16]; /* CSRC's table */ | 66 | uint32_t csrc[16]; /* CSRC's table */ |
47 | uint32_t length; /* Length of the header in payload string. */ | 67 | uint32_t length; /* Length of the header in payload string. */ |
48 | |||
49 | } RTPHeader; | 68 | } RTPHeader; |
50 | 69 | /** | |
51 | /** | ||
52 | * Standard rtp extension header. | 70 | * Standard rtp extension header. |
53 | */ | 71 | */ |
54 | typedef struct _RTPExtHeader { | 72 | typedef struct { |
55 | uint16_t type; /* Extension profile */ | 73 | uint16_t type; /* Extension profile */ |
56 | uint16_t length; /* Number of extensions */ | 74 | uint16_t length; /* Number of extensions */ |
57 | uint32_t *table; /* Extension's table */ | 75 | uint32_t *table; /* Extension's table */ |
58 | |||
59 | } RTPExtHeader; | 76 | } RTPExtHeader; |
60 | 77 | ||
61 | /** | 78 | /** |
62 | * Standard rtp message. | 79 | * Standard rtp message. |
63 | */ | 80 | */ |
64 | typedef struct _RTPMessage { | 81 | typedef struct RTPMessage_s { |
65 | RTPHeader *header; | 82 | RTPHeader *header; |
66 | RTPExtHeader *ext_header; | 83 | RTPExtHeader *ext_header; |
67 | 84 | ||
68 | uint8_t data[MAX_RTP_SIZE]; | ||
69 | uint32_t length; | 85 | uint32_t length; |
70 | 86 | uint8_t data[]; | |
71 | struct _RTPMessage *next; | ||
72 | } RTPMessage; | 87 | } RTPMessage; |
73 | 88 | ||
74 | /** | 89 | /** |
75 | * RTP control session. | 90 | * RTP control session. |
76 | */ | 91 | */ |
77 | typedef struct _RTPSession { | 92 | typedef struct { |
78 | uint8_t version; | 93 | uint8_t version; |
79 | uint8_t padding; | 94 | uint8_t padding; |
80 | uint8_t extension; | 95 | uint8_t extension; |
81 | uint8_t cc; | 96 | uint8_t cc; |
82 | uint8_t marker; | 97 | uint8_t marker; |
83 | uint8_t payload_type; | 98 | uint8_t payload_type; |
84 | uint16_t sequnum; /* Set when sending */ | 99 | uint16_t sequnum; /* Sending sequence number */ |
85 | uint16_t rsequnum; /* Check when recving msg */ | 100 | uint16_t rsequnum; /* Receiving sequence number */ |
86 | uint32_t timestamp; | 101 | uint32_t rtimestamp; |
87 | uint32_t ssrc; | 102 | uint32_t ssrc; |
88 | uint32_t *csrc; | 103 | uint32_t *csrc; |
89 | 104 | ||
90 | /* If some additional data must be sent via message | 105 | /* If some additional data must be sent via message |
91 | * apply it here. Only by allocating this member you will be | 106 | * apply it here. Only by allocating this member you will be |
92 | * automatically placing it within a message. | 107 | * automatically placing it within a message. |
93 | */ | 108 | */ |
94 | RTPExtHeader *ext_header; | 109 | RTPExtHeader *ext_header; |
95 | 110 | ||
96 | /* Msg prefix for core to know when recving */ | 111 | /* Msg prefix for core to know when recving */ |
97 | uint8_t prefix; | 112 | uint8_t prefix; |
98 | |||
99 | int dest; | ||
100 | 113 | ||
101 | struct _CSSession *cs; | 114 | Messenger *m; |
115 | int friend_number; | ||
116 | struct RTCPSession_s *rtcp_session; | ||
102 | 117 | ||
118 | void *cs; | ||
119 | int (*mcb) (void*, RTPMessage* msg); | ||
120 | |||
103 | } RTPSession; | 121 | } RTPSession; |
104 | 122 | ||
105 | /** | 123 | /** |
106 | * Must be called before calling any other rtp function. | 124 | * Must be called before calling any other rtp function. |
107 | */ | 125 | */ |
108 | RTPSession *rtp_new ( int payload_type, Messenger *messenger, int friend_num ); | 126 | RTPSession *rtp_new ( int payload_type, Messenger *m, int friend_num, void* cs, int (*mcb) (void*, RTPMessage*) ); |
109 | |||
110 | /** | 127 | /** |
111 | * Terminate the session. | 128 | * Terminate the session. |
112 | */ | 129 | */ |
113 | void rtp_kill ( RTPSession *session, Messenger *messenger ); | 130 | void rtp_kill ( RTPSession* session ); |
114 | |||
115 | /** | 131 | /** |
116 | * Sends msg to _RTPSession::dest | 132 | * Do periodical rtp work. |
117 | */ | 133 | */ |
118 | int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *data, uint16_t length ); | 134 | int rtp_do(RTPSession *session); |
119 | 135 | /** | |
136 | * By default rtp is in receiving state | ||
137 | */ | ||
138 | int rtp_start_receiving (RTPSession *session); | ||
139 | /** | ||
140 | * Pause rtp receiving mode. | ||
141 | */ | ||
142 | int rtp_stop_receiving (RTPSession *session); | ||
143 | /** | ||
144 | * Sends msg to RTPSession::dest | ||
145 | */ | ||
146 | int rtp_send_data ( RTPSession* session, const uint8_t* data, uint16_t length, bool dummy ); | ||
120 | /** | 147 | /** |
121 | * Dealloc msg. | 148 | * Dealloc msg. |
122 | */ | 149 | */ |
123 | void rtp_free_msg ( RTPSession *session, RTPMessage *msg ); | 150 | void rtp_free_msg ( RTPMessage *msg ); |
124 | |||
125 | 151 | ||
126 | 152 | ||
127 | #endif /* __TOXRTP */ | 153 | #endif /* RTP_H */ |