Skip to content

Commit 914cb55

Browse files
committed
alternative stream list api and unit tests for the api
Beside some small API rename the main difference is that the list implementation is not responsible for deallocating streams. Calling srtp_stream_list_dealloc() on a list that is not empty results in an error. This also changes the default implementation to be a double linked list making removing items faster.
1 parent 523c2a9 commit 914cb55

File tree

5 files changed

+404
-116
lines changed

5 files changed

+404
-116
lines changed

.github/workflows/cmake.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,11 @@ jobs:
7777
working-directory: ${{github.workspace}}/build
7878
shell: bash
7979
run: ctest
80+
81+
- name: Test Stream List Replacement
82+
working-directory: ${{github.workspace}}/build
83+
shell: bash
84+
run: |
85+
make clean
86+
make C_FLAGS="-DSRTP_NO_STREAM_LIST -DSRTP_USE_TEST_STREAM_LIST" srtp_driver
87+
./srtp_driver -v

include/srtp_priv.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,6 @@ srtp_err_status_t srtp_steam_init_all_master_keys(
9797
srtp_master_key_t **keys,
9898
const unsigned int max_master_keys);
9999

100-
/*
101-
* srtp_stream_init(s, p) initializes the srtp_stream_t s to
102-
* use the policy at the location p
103-
*/
104-
srtp_err_status_t srtp_stream_init(srtp_stream_t srtp, const srtp_policy_t *p);
105-
106-
srtp_err_status_t srtp_stream_dealloc(srtp_stream_ctx_t *stream,
107-
const srtp_stream_ctx_t *stream_template);
108-
109100
/*
110101
* libsrtp internal datatypes
111102
*/
@@ -154,6 +145,7 @@ typedef struct srtp_stream_ctx_t_ {
154145
int enc_xtn_hdr_count;
155146
uint32_t pending_roc;
156147
struct srtp_stream_ctx_t_ *next; /* linked list of streams */
148+
struct srtp_stream_ctx_t_ *prev; /* linked list of streams */
157149
} strp_stream_ctx_t_;
158150

159151
/*

include/stream_list_priv.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ extern "C" {
5858
* the API was extracted to allow downstreams to override its
5959
* implementation by defining the `SRTP_NO_STREAM_LIST` preprocessor
6060
* directive, which removes the default implementation of these
61-
* functions. if this is done, the `next` field is free for the
62-
* implementation to use.
61+
* functions. if this is done, the `next` & `prev` fields are free for
62+
* the implementation to use.
6363
*
6464
* this is still an internal interface; there is no stability
6565
* guarantee--downstreams should watch this file for changes in
@@ -69,7 +69,14 @@ extern "C" {
6969
/**
7070
* allocate and initialize a stream list instance
7171
*/
72-
srtp_err_status_t srtp_stream_list_create(srtp_stream_list_t *list);
72+
srtp_err_status_t srtp_stream_list_alloc(srtp_stream_list_t *list_ptr);
73+
74+
/**
75+
* deallocate a stream list instance
76+
*
77+
* the list must be empty or else an error is returned.
78+
*/
79+
srtp_err_status_t srtp_stream_list_dealloc(srtp_stream_list_t list);
7380

7481
/**
7582
* insert a stream into the list
@@ -82,38 +89,33 @@ srtp_err_status_t srtp_stream_list_create(srtp_stream_list_t *list);
8289
* behavior is undefined. if the SSRC field is mutated while the
8390
* stream is inserted, further operations have undefined behavior
8491
*/
85-
srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t *list,
92+
srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t list,
8693
srtp_stream_t stream);
8794

8895
/*
8996
* look up the stream corresponding to the specified SSRC and return it.
9097
* if no such SSRC is found, NULL is returned.
9198
*/
92-
srtp_stream_t srtp_stream_list_get(srtp_stream_list_t *list, uint32_t ssrc);
99+
srtp_stream_t srtp_stream_list_get(srtp_stream_list_t list, uint32_t ssrc);
93100

94101
/**
95-
* delete the stream associated to the specified SSRC.
102+
* remove the stream from the list.
96103
*
97-
* if a stream is found and removed, it's returned and ownership is
98-
* transferred to the caller. if not found, NULL is returned.
104+
* ownership is transferred to the caller.
105+
*
106+
* if the stream is not in the list the behavior is undefined.
99107
*/
100-
srtp_stream_t srtp_stream_list_delete(srtp_stream_list_t *list, uint32_t ssrc);
108+
void srtp_stream_list_remove(srtp_stream_list_t list, srtp_stream_t stream);
101109

102110
/**
103111
* iterate through all stored streams. while iterating, it is allowed to delete
104112
* the current element; any other mutation to the list is undefined behavior.
105113
* returning non-zero from callback aborts the iteration.
106114
*/
107-
void srtp_stream_list_for_each(srtp_stream_list_t *list,
115+
void srtp_stream_list_for_each(srtp_stream_list_t list,
108116
int (*callback)(srtp_stream_t, void *),
109117
void *data);
110118

111-
/**
112-
* deallocate a stream list instance and all streams inserted in it
113-
*/
114-
srtp_err_status_t srtp_stream_list_dealloc(srtp_stream_list_t *list,
115-
srtp_stream_t template_);
116-
117119
#ifdef __cplusplus
118120
}
119121
#endif

0 commit comments

Comments
 (0)