Skip to content

Commit df8218d

Browse files
Fix: late frame notification in audio session
Move the late frame notification callback to avoid returning zeroed epoch time to the caller.
1 parent 6bf6514 commit df8218d

File tree

4 files changed

+6
-123
lines changed

4 files changed

+6
-123
lines changed

lib/src/st2110/pipeline/st22_pipeline_tx.c

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static bool tx_st22p_if_frame_late(struct st22p_tx_ctx* ctx,
135135

136136
mt_pthread_mutex_unlock(&ctx->lock);
137137

138-
dbg("%s(%d), frame %u drop late by %" PRIu64 "ns (> period %" PRIu64 "ns), cur %" PRIu64
138+
notice("%s(%d), frame %u drop late by %" PRIu64 "ns (> period %" PRIu64 "ns), cur %" PRIu64
139139
" frame %" PRIu64 "\n",
140140
__func__, ctx->idx, framebuff->seq_number, cur_tai - frame_tai, frame_period_ns,
141141
cur_tai, frame_tai);
@@ -197,42 +197,6 @@ static int tx_st22p_next_frame(void* priv, uint16_t* next_frame_idx,
197197
return 0;
198198
}
199199

200-
int st22p_tx_late_frame_drop(void* handle, uint64_t epoch_skipped) {
201-
struct st22p_tx_ctx* ctx = handle;
202-
int cidx = ctx->idx;
203-
struct st22p_tx_frame* framebuff;
204-
205-
if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) {
206-
err("%s(%d), invalid type %d\n", __func__, cidx, ctx->type);
207-
return 0;
208-
}
209-
210-
if (!ctx->ready) return -EBUSY; /* not ready */
211-
mt_pthread_mutex_lock(&ctx->lock);
212-
framebuff = tx_st22p_newest_available(ctx, ST22P_TX_FRAME_ENCODED);
213-
/* not any converted frame */
214-
if (!framebuff) {
215-
mt_pthread_mutex_unlock(&ctx->lock);
216-
return -EBUSY;
217-
}
218-
219-
framebuff->stat = ST22P_TX_FRAME_FREE;
220-
ctx->stat_drop_frame++;
221-
dbg("%s(%d), drop frame %u succ\n", __func__, cidx, framebuff->idx);
222-
mt_pthread_mutex_unlock(&ctx->lock);
223-
224-
if (ctx->ops.notify_frame_late) {
225-
ctx->ops.notify_frame_late(ctx->ops.priv, epoch_skipped);
226-
} else if (ctx->ops.notify_frame_done) {
227-
ctx->ops.notify_frame_done(ctx->ops.priv, tx_st22p_user_frame(ctx, framebuff));
228-
}
229-
230-
/* notify app can get frame */
231-
tx_st22p_notify_frame_available(ctx);
232-
MT_USDT_ST22P_TX_FRAME_DONE(ctx->idx, framebuff->idx, framebuff->dst.rtp_timestamp);
233-
return 0;
234-
}
235-
236200
static int tx_st22p_frame_done(void* priv, uint16_t frame_idx,
237201
struct st22_tx_frame_meta* meta) {
238202
struct st22p_tx_ctx* ctx = priv;

lib/src/st2110/pipeline/st30_pipeline_tx.c

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -171,41 +171,6 @@ static int tx_st30p_next_frame(void* priv, uint16_t* next_frame_idx,
171171
return 0;
172172
}
173173

174-
static int st30p_tx_late_frame_drop(void* handle, uint64_t epoch_skipped) {
175-
struct st30p_tx_ctx* ctx = handle;
176-
struct st30p_tx_frame* framebuff;
177-
178-
if (ctx->type != MT_ST30_HANDLE_PIPELINE_TX) {
179-
err("%s(%d), invalid type %d\n", __func__, ctx->idx, ctx->type);
180-
return 0;
181-
}
182-
183-
if (!ctx->ready) return -EBUSY;
184-
185-
mt_pthread_mutex_lock(&ctx->lock);
186-
framebuff = tx_st30p_newest_available(ctx, ST30P_TX_FRAME_READY);
187-
if (!framebuff) {
188-
mt_pthread_mutex_unlock(&ctx->lock);
189-
return -EBUSY;
190-
}
191-
192-
framebuff->stat = ST30P_TX_FRAME_FREE;
193-
ctx->stat_drop_frame++;
194-
dbg("%s(%d), drop frame %u succ\n", __func__, ctx->idx, framebuff->idx);
195-
mt_pthread_mutex_unlock(&ctx->lock);
196-
197-
if (ctx->ops.notify_frame_late) {
198-
ctx->ops.notify_frame_late(ctx->ops.priv, epoch_skipped);
199-
} else if (ctx->ops.notify_frame_done) {
200-
ctx->ops.notify_frame_done(ctx->ops.priv, &framebuff->frame);
201-
}
202-
203-
tx_st30p_notify_frame_available(ctx);
204-
MT_USDT_ST30P_TX_FRAME_DROP(ctx->idx, framebuff->idx, framebuff->frame.rtp_timestamp);
205-
206-
return 0;
207-
}
208-
209174
static int tx_st30p_frame_done(void* priv, uint16_t frame_idx,
210175
struct st30_tx_frame_meta* meta) {
211176
struct st30p_tx_ctx* ctx = priv;
@@ -279,11 +244,7 @@ static int tx_st30p_create_transport(struct mtl_main_impl* impl, struct st30p_tx
279244
ops_tx.flags |= ST30_TX_FLAG_FORCE_NUMA;
280245
}
281246
if (ops->flags & ST30P_TX_FLAG_USER_PACING) ops_tx.flags |= ST30_TX_FLAG_USER_PACING;
282-
if (ops->flags & ST30P_TX_FLAG_DROP_WHEN_LATE) {
283-
ops_tx.notify_frame_late = st30p_tx_late_frame_drop;
284-
} else if (ops->notify_frame_late) {
285-
ops_tx.notify_frame_late = ops->notify_frame_late;
286-
}
247+
if (ops->notify_frame_late) ops_tx.notify_frame_late = ops->notify_frame_late;
287248
ops_tx.pacing_way = ops->pacing_way;
288249
ops_tx.rtp_timestamp_delta_us = ops->rtp_timestamp_delta_us;
289250

lib/src/st2110/pipeline/st40_pipeline_tx.c

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -166,43 +166,6 @@ static int tx_st40p_next_frame(void* priv, uint16_t* next_frame_idx,
166166
return 0;
167167
}
168168

169-
int st40p_tx_late_frame_drop(void* handle, uint64_t epoch_skipped) {
170-
struct st40p_tx_ctx* ctx = handle;
171-
int cidx = ctx->idx;
172-
struct st40p_tx_frame* framebuff;
173-
174-
if (ctx->type != MT_ST40_HANDLE_PIPELINE_TX) {
175-
err("%s(%d), invalid type %d\n", __func__, cidx, ctx->type);
176-
return 0;
177-
}
178-
179-
if (!ctx->ready) return -EBUSY;
180-
181-
mt_pthread_mutex_lock(&ctx->lock);
182-
framebuff = tx_st40p_newest_available(ctx, ST40P_TX_FRAME_READY);
183-
if (!framebuff) {
184-
mt_pthread_mutex_unlock(&ctx->lock);
185-
return -EBUSY;
186-
}
187-
188-
framebuff->stat = ST40P_TX_FRAME_FREE;
189-
ctx->stat_drop_frame++;
190-
dbg("%s(%d), drop frame %u succ\n", __func__, ctx->idx, framebuff->idx);
191-
mt_pthread_mutex_unlock(&ctx->lock);
192-
193-
if (ctx->ops.notify_frame_late) {
194-
ctx->ops.notify_frame_late(ctx->ops.priv, epoch_skipped);
195-
} else if (ctx->ops.notify_frame_done) {
196-
ctx->ops.notify_frame_done(ctx->ops.priv, &framebuff->frame_info);
197-
}
198-
199-
tx_st40p_notify_frame_available(ctx);
200-
MT_USDT_ST40P_TX_FRAME_DROP(ctx->idx, framebuff->idx,
201-
framebuff->frame_info.rtp_timestamp);
202-
203-
return 0;
204-
}
205-
206169
static int tx_st40p_frame_done(void* priv, uint16_t frame_idx,
207170
struct st40_tx_frame_meta* meta) {
208171
struct st40p_tx_ctx* ctx = priv;
@@ -308,11 +271,7 @@ static int tx_st40p_create_transport(struct mtl_main_impl* impl, struct st40p_tx
308271
ops_tx.flags |= ST40_TX_FLAG_EXACT_USER_PACING;
309272
if (ops->flags & ST40P_TX_FLAG_SPLIT_ANC_BY_PKT)
310273
ops_tx.flags |= ST40_TX_FLAG_SPLIT_ANC_BY_PKT;
311-
if (ops->flags & ST40P_TX_FLAG_DROP_WHEN_LATE) {
312-
ops_tx.notify_frame_late = st40p_tx_late_frame_drop;
313-
} else if (ops->notify_frame_late) {
314-
ops_tx.notify_frame_late = ops->notify_frame_late;
315-
}
274+
if (ops->notify_frame_late) ops_tx.notify_frame_late = ops->notify_frame_late;
316275
if (ops->flags & ST40P_TX_FLAG_ENABLE_RTCP) ops_tx.flags |= ST40_TX_FLAG_ENABLE_RTCP;
317276

318277
/* test-only mutation config */

lib/src/st2110/st_tx_audio_session.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,14 @@ static int tx_audio_session_sync_pacing(struct mtl_main_impl* impl,
318318
if (to_epoch < 0) {
319319
/* time bigger than the assigned epoch time */
320320
ST_SESSION_STAT_INC(s, port_user_stats, stat_epoch_mismatch);
321+
if (s->ops.notify_frame_late) {
322+
s->ops.notify_frame_late(s->ops.priv, -to_epoch / pkt_time);
323+
}
321324
to_epoch = 0; /* send asap */
322325
}
323326

324327
if (epochs > next_epochs) {
325328
ST_SESSION_STAT_ADD(s, port_user_stats.common, stat_epoch_drop, -to_epoch / pkt_time);
326-
327-
if (s->ops.notify_frame_late) {
328-
s->ops.notify_frame_late(s->ops.priv, -to_epoch / pkt_time);
329-
}
330329
}
331330

332331
if (epochs < next_epochs) {

0 commit comments

Comments
 (0)