Skip to content

Commit f8ad243

Browse files
authored
Merge pull request #612 from mildsunrise/stream-list-api
Allow overriding stream list implementation
2 parents b1f3b8b + d1eb03a commit f8ad243

File tree

5 files changed

+846
-256
lines changed

5 files changed

+846
-256
lines changed

.github/workflows/stream_list.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Stream List CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
os: [ubuntu-latest, macos-latest, windows-latest]
15+
16+
runs-on: ${{ matrix.os }}
17+
18+
env:
19+
CTEST_OUTPUT_ON_FAILURE: 1
20+
21+
steps:
22+
23+
- uses: actions/checkout@v2
24+
25+
- name: Create Build Environment
26+
run: cmake -E make_directory ${{github.workspace}}/build
27+
28+
- name: Configure CMake
29+
working-directory: ${{github.workspace}}/build
30+
shell: bash
31+
run: cmake $GITHUB_WORKSPACE -DBUILD_WITH_SANITIZERS=TRUE -DCMAKE_C_FLAGS:STRING="-DSRTP_NO_STREAM_LIST -DSRTP_USE_TEST_STREAM_LIST"
32+
33+
- name: Build
34+
working-directory: ${{github.workspace}}/build
35+
shell: bash
36+
run: cmake --build . -t srtp_driver
37+
38+
- name: Test
39+
working-directory: ${{github.workspace}}/build
40+
shell: bash
41+
run: ctest -R srtp_driver

include/srtp_priv.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ extern "C" {
6666

6767
typedef struct srtp_stream_ctx_t_ srtp_stream_ctx_t;
6868
typedef srtp_stream_ctx_t *srtp_stream_t;
69+
typedef struct srtp_stream_list_ctx_t_ *srtp_stream_list_t;
6970

7071
/*
7172
* the following declarations are libSRTP internal functions
@@ -96,12 +97,6 @@ srtp_err_status_t srtp_steam_init_all_master_keys(
9697
srtp_master_key_t **keys,
9798
const unsigned int max_master_keys);
9899

99-
/*
100-
* srtp_stream_init(s, p) initializes the srtp_stream_t s to
101-
* use the policy at the location p
102-
*/
103-
srtp_err_status_t srtp_stream_init(srtp_stream_t srtp, const srtp_policy_t *p);
104-
105100
/*
106101
* libsrtp internal datatypes
107102
*/
@@ -149,14 +144,21 @@ typedef struct srtp_stream_ctx_t_ {
149144
int *enc_xtn_hdr;
150145
int enc_xtn_hdr_count;
151146
uint32_t pending_roc;
152-
struct srtp_stream_ctx_t_ *next; /* linked list of streams */
147+
/*
148+
The next and prev pointers are here to allow for a stream list to be
149+
implemented as an intrusive doubly-linked list (the former being the
150+
default). Other stream list implementations can ignore these fields or use
151+
them for some other purpose specific to the stream list implementation.
152+
*/
153+
struct srtp_stream_ctx_t_ *next;
154+
struct srtp_stream_ctx_t_ *prev;
153155
} strp_stream_ctx_t_;
154156

155157
/*
156158
* an srtp_ctx_t holds a stream list and a service description
157159
*/
158160
typedef struct srtp_ctx_t_ {
159-
struct srtp_stream_ctx_t_ *stream_list; /* linked list of streams */
161+
srtp_stream_list_t stream_list; /* linked list of streams */
160162
struct srtp_stream_ctx_t_ *stream_template; /* act as template for other */
161163
/* streams */
162164
void *user_data; /* user custom data */

include/stream_list_priv.h

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* stream_list_priv.h
3+
*
4+
* list of SRTP streams, keyed by SSRC
5+
*
6+
* Alba Mendez
7+
*/
8+
/*
9+
*
10+
* Copyright (c) 2001-2017, Cisco Systems, Inc.
11+
* Copyright (c) 2022, Dolby Laboratories, Inc.
12+
* All rights reserved.
13+
*
14+
* Redistribution and use in source and binary forms, with or without
15+
* modification, are permitted provided that the following conditions
16+
* are met:
17+
*
18+
* Redistributions of source code must retain the above copyright
19+
* notice, this list of conditions and the following disclaimer.
20+
*
21+
* Redistributions in binary form must reproduce the above
22+
* copyright notice, this list of conditions and the following
23+
* disclaimer in the documentation and/or other materials provided
24+
* with the distribution.
25+
*
26+
* Neither the name of the Cisco Systems, Inc. nor the names of its
27+
* contributors may be used to endorse or promote products derived
28+
* from this software without specific prior written permission.
29+
*
30+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
34+
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
41+
* OF THE POSSIBILITY OF SUCH DAMAGE.
42+
*
43+
*/
44+
45+
#ifndef SRTP_STREAM_LIST_PRIV_H
46+
#define SRTP_STREAM_LIST_PRIV_H
47+
48+
#include <srtp_priv.h>
49+
50+
#ifdef __cplusplus
51+
extern "C" {
52+
#endif
53+
54+
/**
55+
* srtp_stream_list_t holds a list of srtp_stream_t, each identified
56+
* by their SSRC.
57+
*
58+
* the API was extracted to allow downstreams to override its
59+
* implementation by defining the `SRTP_NO_STREAM_LIST` preprocessor
60+
* directive, which removes the default implementation of these
61+
* functions. if this is done, the `next` & `prev` fields are free for
62+
* the implementation to use.
63+
*
64+
* this is still an internal interface; there is no stability
65+
* guarantee--downstreams should watch this file for changes in
66+
* signatures or semantics.
67+
*/
68+
69+
/**
70+
* allocate and initialize a stream list instance
71+
*/
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);
80+
81+
/**
82+
* insert a stream into the list
83+
*
84+
* returns srtp_err_status_alloc_fail if insertion failed due to unavailable
85+
* capacity in the list. if operation succeeds, srtp_err_status_ok is returned
86+
*
87+
* if another stream with the same SSRC already exists in the list,
88+
* behavior is undefined. if the SSRC field is mutated while the
89+
* stream is inserted, further operations have undefined behavior
90+
*/
91+
srtp_err_status_t srtp_stream_list_insert(srtp_stream_list_t list,
92+
srtp_stream_t stream);
93+
94+
/*
95+
* look up the stream corresponding to the specified SSRC and return it.
96+
* if no such SSRC is found, NULL is returned.
97+
*/
98+
srtp_stream_t srtp_stream_list_get(srtp_stream_list_t list, uint32_t ssrc);
99+
100+
/**
101+
* remove the stream from the list.
102+
*
103+
* The stream to be removed is referenced "by value", i.e., by the pointer to be
104+
* removed from the list. This pointer is obtained using `srtp_stream_list_get`
105+
* or as callback parameter in `srtp_stream_list_for_each`.
106+
*/
107+
void srtp_stream_list_remove(srtp_stream_list_t list, srtp_stream_t stream);
108+
109+
/**
110+
* iterate through all stored streams. while iterating, it is allowed to delete
111+
* the current element; any other mutation to the list is undefined behavior.
112+
* returning non-zero from callback aborts the iteration.
113+
*/
114+
void srtp_stream_list_for_each(srtp_stream_list_t list,
115+
int (*callback)(srtp_stream_t, void *),
116+
void *data);
117+
118+
#ifdef __cplusplus
119+
}
120+
#endif
121+
122+
#endif /* SRTP_STREAM_LIST_PRIV_H */

0 commit comments

Comments
 (0)