Skip to content

Commit c11dcf3

Browse files
committed
Changed stream list to arrays and optimized stream lookup with SSE2.
The stream list in the SRTP context is now implemented with two arrays: an array of SSRCs and an array of pointers to the streams corresponding to the SSRCs. The streams no longer form a single linked list. Stream lookup by SSRC is now performed over the array of SSRCs, which is considerably faster because it is more cache-friendly. Additionally, the lookup is optimized for SSE2, which provides an additional massive speedup with many streams in the list. Although the lookup still has linear complexity, its absolute times are reduced and with tens to hundreds elements are lower or comparable with a typical rb-tree equivalent. Expected speedup of SSE2 version over the previous implementation: SSRCs speedup (scalar) speedup (SSE2) 1 0.39x 0.22x 3 0.57x 0.23x 5 0.69x 0.62x 10 0.77x 1.43x 20 0.86x 2.38x 30 0.87x 3.44x 50 1.13x 6.21x 100 1.25x 8.51x 200 1.30x 9.83x At small numbers of SSRCs the new algorithm is somewhat slower, but given that the absolute and relative times of the lookup are very small, that slowdown is not very significant.
1 parent 19e6a05 commit c11dcf3

File tree

3 files changed

+366
-132
lines changed

3 files changed

+366
-132
lines changed

include/srtp_priv.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,27 @@ typedef struct srtp_stream_ctx_t_ {
149149
int *enc_xtn_hdr;
150150
int enc_xtn_hdr_count;
151151
uint32_t pending_roc;
152-
struct srtp_stream_ctx_t_ *next; /* linked list of streams */
153152
} strp_stream_ctx_t_;
154153

154+
/*
155+
* An srtp_stream_list_t is a list of streams searchable by SSRC.
156+
*
157+
* Pointers to streams and their respective SSRCs are stored in two arrays,
158+
* where the stream pointer and the SSRC at the same index correspond to each
159+
* other.
160+
*/
161+
typedef struct srtp_stream_list_t {
162+
srtp_stream_ctx_t **streams;
163+
uint32_t *ssrcs;
164+
uint32_t size;
165+
uint32_t capacity;
166+
} srtp_stream_list_t;
167+
155168
/*
156169
* an srtp_ctx_t holds a stream list and a service description
157170
*/
158171
typedef struct srtp_ctx_t_ {
159-
struct srtp_stream_ctx_t_ *stream_list; /* linked list of streams */
172+
srtp_stream_list_t stream_list; /* list of streams */
160173
struct srtp_stream_ctx_t_ *stream_template; /* act as template for other */
161174
/* streams */
162175
void *user_data; /* user custom data */

0 commit comments

Comments
 (0)