Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

srtp_stream_hash_t #659

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/srtp_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ extern "C" {
typedef struct srtp_stream_ctx_t_ srtp_stream_ctx_t;
typedef srtp_stream_ctx_t *srtp_stream_t;
typedef struct srtp_stream_list_ctx_t_ *srtp_stream_list_t;
typedef struct srtp_stream_hash_t_ *srtp_stream_hash_t;

/*
* the following declarations are libSRTP internal functions
Expand Down Expand Up @@ -158,7 +159,7 @@ typedef struct srtp_stream_ctx_t_ {
* an srtp_ctx_t holds a stream list and a service description
*/
typedef struct srtp_ctx_t_ {
srtp_stream_list_t stream_list; /* linked list of streams */
srtp_stream_hash_t stream_hash; /* hash of stream lists */
struct srtp_stream_ctx_t_ *stream_template; /* act as template for other */
/* streams */
void *user_data; /* user custom data */
Expand Down
49 changes: 49 additions & 0 deletions include/stream_list_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,55 @@ void srtp_stream_list_for_each(srtp_stream_list_t list,
int (*callback)(srtp_stream_t, void *),
void *data);

/**
* allocate and initialize a stream hash instance
*/
srtp_err_status_t srtp_stream_hash_alloc(srtp_stream_hash_t *hash_ptr);

/**
* deallocate a stream hash instance
*
* the underlying lists must be empty or else an error is returned.
*/
srtp_err_status_t srtp_stream_hash_dealloc(srtp_stream_hash_t hash);

/**
* insert a stream into the hash
*
* returns srtp_err_status_alloc_fail if insertion failed due to unavailable
* capacity in the hash. if operation succeeds, srtp_err_status_ok is returned
*
* if another stream with the same SSRC already exists in the hash,
* behavior is undefined. if the SSRC field is mutated while the
* stream is inserted, further operations have undefined behavior
*/
srtp_err_status_t srtp_stream_hash_insert(srtp_stream_hash_t hash,
srtp_stream_t stream);

/*
* look up the stream corresponding to the specified SSRC and return it.
* if no such SSRC is found, NULL is returned.
*/
srtp_stream_t srtp_stream_hash_get(srtp_stream_hash_t hash, uint32_t ssrc);

/**
* remove the stream from the hash.
*
* The stream to be removed is referenced "by value", i.e., by the pointer to be
* removed from the hash. This pointer is obtained using `srtp_stream_hash_get`
* or as callback parameter in `srtp_stream_hash_for_each`.
*/
void srtp_stream_hash_remove(srtp_stream_hash_t hash, srtp_stream_t stream);

/**
* iterate through all stored streams. while iterating, it is allowed to delete
* the current element; any other mutation to the hash is undefined behavior.
* returning non-zero from callback aborts the iteration.
*/
void srtp_stream_hash_for_each(srtp_stream_hash_t hash,
int (*callback)(srtp_stream_t, void *),
void *data);

#ifdef __cplusplus
}
#endif
Expand Down
Loading
Loading