Skip to content

Commit b73061d

Browse files
committed
Fix: Race condition in pipelines
The status of frames was changed to TX_FRAME_FREE before the frame_done() finished modifing the frame, which made it possible that a frame obtained by the get_frame() function was modified after it had been retrieved. Signed-off-by: Kasiewicz, Marek <[email protected]>
1 parent 7c9b061 commit b73061d

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

lib/src/st2110/pipeline/st20_pipeline_tx.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ static int tx_st20p_frame_done(void* priv, uint16_t frame_idx,
111111
struct st20p_tx_ctx* ctx = priv;
112112
int ret;
113113
struct st20p_tx_frame* framebuff = &ctx->framebuffs[frame_idx];
114+
115+
struct st_frame* frame = tx_st20p_user_frame(ctx, framebuff);
116+
frame->tfmt = meta->tfmt;
117+
frame->timestamp = meta->timestamp;
118+
frame->epoch = meta->epoch;
119+
frame->rtp_timestamp = meta->rtp_timestamp;
114120

115121
mt_pthread_mutex_lock(&ctx->lock);
116122
if (ST20P_TX_FRAME_IN_TRANSMITTING == framebuff->stat) {
@@ -124,12 +130,6 @@ static int tx_st20p_frame_done(void* priv, uint16_t frame_idx,
124130
}
125131
mt_pthread_mutex_unlock(&ctx->lock);
126132

127-
struct st_frame* frame = tx_st20p_user_frame(ctx, framebuff);
128-
frame->tfmt = meta->tfmt;
129-
frame->timestamp = meta->timestamp;
130-
frame->epoch = meta->epoch;
131-
frame->rtp_timestamp = meta->rtp_timestamp;
132-
133133
if (ctx->ops.notify_frame_done &&
134134
!framebuff->frame_done_cb_called) { /* notify app which frame done */
135135
ctx->ops.notify_frame_done(ctx->ops.priv, frame);

lib/src/st2110/pipeline/st22_pipeline_tx.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ static int tx_st22p_frame_done(void* priv, uint16_t frame_idx,
133133
int ret;
134134
struct st22p_tx_frame* framebuff = &ctx->framebuffs[frame_idx];
135135

136+
framebuff->src.tfmt = meta->tfmt;
137+
framebuff->dst.tfmt = meta->tfmt;
138+
framebuff->src.timestamp = meta->timestamp;
139+
framebuff->dst.timestamp = meta->timestamp;
140+
framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = meta->rtp_timestamp;
141+
136142
mt_pthread_mutex_lock(&ctx->lock);
137143
if (ST22P_TX_FRAME_IN_TRANSMITTING == framebuff->stat) {
138144
ret = 0;
@@ -145,12 +151,6 @@ static int tx_st22p_frame_done(void* priv, uint16_t frame_idx,
145151
}
146152
mt_pthread_mutex_unlock(&ctx->lock);
147153

148-
framebuff->src.tfmt = meta->tfmt;
149-
framebuff->dst.tfmt = meta->tfmt;
150-
framebuff->src.timestamp = meta->timestamp;
151-
framebuff->dst.timestamp = meta->timestamp;
152-
framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = meta->rtp_timestamp;
153-
154154
if (ctx->ops.notify_frame_done) { /* notify app which frame done */
155155
struct st_frame* frame = tx_st22p_user_frame(ctx, framebuff);
156156
ctx->ops.notify_frame_done(ctx->ops.priv, frame);

lib/src/st2110/pipeline/st30_pipeline_tx.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ static int tx_st30p_frame_done(void* priv, uint16_t frame_idx,
108108
int ret;
109109
struct st30p_tx_frame* framebuff = &ctx->framebuffs[frame_idx];
110110

111+
struct st30_frame* frame = &framebuff->frame;
112+
frame->tfmt = meta->tfmt;
113+
frame->timestamp = meta->timestamp;
114+
frame->epoch = meta->epoch;
115+
frame->rtp_timestamp = meta->rtp_timestamp;
116+
111117
mt_pthread_mutex_lock(&ctx->lock);
112118
if (ST30P_TX_FRAME_IN_TRANSMITTING == framebuff->stat) {
113119
ret = 0;
@@ -120,11 +126,6 @@ static int tx_st30p_frame_done(void* priv, uint16_t frame_idx,
120126
}
121127
mt_pthread_mutex_unlock(&ctx->lock);
122128

123-
struct st30_frame* frame = &framebuff->frame;
124-
frame->tfmt = meta->tfmt;
125-
frame->timestamp = meta->timestamp;
126-
frame->epoch = meta->epoch;
127-
frame->rtp_timestamp = meta->rtp_timestamp;
128129

129130
if (ctx->ops.notify_frame_done) { /* notify app which frame done */
130131
ctx->ops.notify_frame_done(ctx->ops.priv, frame);

0 commit comments

Comments
 (0)