Skip to content

Commit db0f98d

Browse files
Add: Ability to drop old frames
Change the way pipeline TX handles the order of framebuffers. Track per-frame sequence numbers so transport can dequeue the newest converted frame instead of always taking the next one, needed as otherwise we cannot drop frames, as they will not be in order. (This also makes it easier for multi threaded applications to use the api should improve performance with multiple threads from the api only). Add a new flag to the TX pipeline to enable droping frames when we jump over epoch. Mostly will aid with user control pacing. Implemented in a way that only drops one frame in a scenario where late is detected. This creates limitation for extreamly high drops The stream will still not adjust immidiately instead doing send frame | drop frame | send frame | drop frame ... until we catch up. (Done mostly as big jumps over more than 2 frames could be undesirable and if you have that big of a drop ... well this is the least of your troubles). Due to lack of consumer and producer print stats of the queue via reporting the framebuffers statuses (removed the ACCURATE_FRAMEBUFF) as it became redundant. Reverts: 772621d All above done in pipeline as the purpose of the api pipeline is to smoothe the library tight timing requirements from the user applications. Fix the st20p wrong user timestamp reporting in frames snapped to the next frame. if times given by the application looks as follows ----|--frame-1--|--frame-2--|--frame-3--|--frame-4--|-... epoch-1--|--epoch-2--|--epoch-3--|--epoch-4--|... This causes frames to snap to the next epoch, resulting in incorrect timestamp reporting where every frame appears to have a "wrong user timestamp" due to the forward snapping behavior. Fixes: 88c3566 Fix the usdt for st40p tx (only to add the spurn event). Fixes: 921fa0d
1 parent 1440fe1 commit db0f98d

18 files changed

+507
-125
lines changed

include/st20_api.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,13 @@ struct st20_tx_ops {
11691169
int (*notify_frame_done)(void* priv, uint16_t frame_idx,
11701170
struct st20_tx_frame_meta* meta);
11711171

1172+
/**
1173+
* Optional. Callback triggered when a frame epoch is omitted/skipped in the lib.
1174+
* This occurs when the transmission timing falls behind schedule and an epoch
1175+
* must be skipped to maintain synchronization. (or in the user pacing mode
1176+
* when the user time is behind the lib sending time).
1177+
*/
1178+
int (*notify_frame_late)(void* priv, uint64_t epoch_skipped);
11721179
/**
11731180
* Optional. The event callback when there is some event(vsync or others) happened for
11741181
* this session. Only non-block method can be used in this callback as it run from lcore
@@ -1319,6 +1326,14 @@ struct st22_tx_ops {
13191326
int (*notify_frame_done)(void* priv, uint16_t frame_idx,
13201327
struct st22_tx_frame_meta* meta);
13211328

1329+
/**
1330+
* Optional. Callback triggered when a frame epoch is omitted/skipped in the lib.
1331+
* This occurs when the transmission timing falls behind schedule and an epoch
1332+
* must be skipped to maintain synchronization. (or in the user pacing mode
1333+
* when the user time is behind the lib sending time).
1334+
*/
1335+
int (*notify_frame_late)(void* priv, uint64_t epoch_skipped);
1336+
13221337
/**
13231338
* Optional. The event callback when there is some event(vsync or others) happened for
13241339
* this session. Only non-block method can be used in this callback as it run from lcore

include/st30_api.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ struct st30_tx_ops {
383383
int (*notify_frame_done)(void* priv, uint16_t frame_idx,
384384
struct st30_tx_frame_meta* meta);
385385

386+
/**
387+
* Optional. Callback when frame done in the lib.
388+
* And only non-block method can be used within this callback as it run from lcore
389+
* tasklet routine.
390+
*/
391+
int (*notify_frame_late)(void* priv, uint64_t epoch_skipped);
392+
386393
/*
387394
* Optional. The size of fifo ring which used between the packet builder and pacing.
388395
* Leave to zero to use default value: the packet number within

include/st30_pipeline_api.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ enum st30p_tx_flag {
5252
/** Enable the st30p_tx_get_frame block behavior to wait until a frame becomes
5353
available or timeout(default: 1s, use st30p_tx_set_block_timeout to customize)*/
5454
ST30P_TX_FLAG_BLOCK_GET = (MTL_BIT32(15)),
55+
56+
/**
57+
* Drop frames when the mtl reports late frames (transport can't keep up).
58+
* When late frame is detected, next frame from pipeline is ommited.
59+
* Untill we resume normal frame sending.
60+
*/
61+
ST30P_TX_FLAG_DROP_WHEN_LATE = (MTL_BIT32(16)),
5562
};
5663

5764
/** The structure info for st30 frame meta. */
@@ -131,6 +138,14 @@ struct st30p_tx_ops {
131138
* tasklet routine.
132139
*/
133140
int (*notify_frame_done)(void* priv, struct st30_frame* frame);
141+
/**
142+
* Optional. Callback when frame timing issues occur.
143+
* If ST30P_TX_FLAG_DROP_WHEN_LATE is enabled: triggered when a frame is dropped
144+
* from the pipeline due to late transmission.
145+
* If ST30P_TX_FLAG_DROP_WHEN_LATE is disabled: triggered when the transport
146+
* layer reports late frame delivery.
147+
*/
148+
int (*notify_frame_late)(void* priv, uint64_t epoch_skipped);
134149

135150
/**
136151
* Optional. The rtp timestamp delta(us) to the start time of frame.

include/st40_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ struct st40_tx_ops {
337337
int (*notify_frame_done)(void* priv, uint16_t frame_idx,
338338
struct st40_tx_frame_meta* meta);
339339

340+
int (*notify_frame_late)(void* priv, uint64_t epoch_skipped);
341+
340342
/** Optional. UDP source port number, leave as 0 to use same port as dst */
341343
uint16_t udp_src_port[MTL_SESSION_PORT_MAX];
342344
/**

include/st40_pipeline_api.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ enum st40p_tx_flag {
6767
* lib will wait until timestamp is reached for each frame.
6868
*/
6969
ST40P_TX_FLAG_USER_PACING = (MTL_BIT32(3)),
70+
/**
71+
* Drop frames when the mtl reports late frames (transport can't keep up).
72+
* When late frame is detected, next frame from pipeline is ommited.
73+
* Untill we resume normal frame sending.
74+
*/
75+
ST40P_TX_FLAG_DROP_WHEN_LATE = (MTL_BIT32(7)),
7076
/**
7177
* Flag bit in flags of struct st40_tx_ops.
7278
* If enabled, lib will assign the rtp timestamp to the value in
@@ -91,10 +97,6 @@ enum st40p_tx_flag {
9197
/** Enable the st40p_tx_get_frame block behavior to wait until a frame becomes
9298
available or timeout(default: 1s, use st40p_tx_set_block_timeout to customize)*/
9399
ST40P_TX_FLAG_BLOCK_GET = (MTL_BIT32(15)),
94-
/**
95-
** Enable verbose reporting of framebuffer statuses in statistics output
96-
*/
97-
ST40P_TX_FLAG_ACCURATE_FRAMEBUFF_STATISTICS = (MTL_BIT32(25)),
98100
};
99101

100102
/**
@@ -131,6 +133,15 @@ struct st40p_tx_ops {
131133
*/
132134
int (*notify_frame_done)(void* priv, struct st40_frame_info* frame_info);
133135

136+
/**
137+
* Optional. Callback when frame timing issues occur.
138+
* If ST30P_TX_FLAG_DROP_WHEN_LATE is enabled: triggered when a frame is dropped
139+
* from the pipeline due to late transmission.
140+
* If ST30P_TX_FLAG_DROP_WHEN_LATE is disabled: triggered when the transport
141+
* layer reports late frame delivery.
142+
*/
143+
int (*notify_frame_late)(void* priv, uint64_t epoch_skipped);
144+
134145
/**
135146
* Optional. tx destination mac address.
136147
* Valid if ST40P_TX_FLAG_USER_P(R)_MAC is enabled

include/st41_api.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ typedef struct st_rx_fastmetadata_session_handle_impl* st41_rx_handle;
4343
* lib will wait until timestamp is reached for each frame.
4444
*/
4545
#define ST41_TX_FLAG_USER_PACING (MTL_BIT32(3))
46+
/**
47+
* Flag bit in flags of struct st41_tx_ops.
48+
* Drop all packets that are old to recover from overflow situations and user
49+
* mismanagement. This flag works in conjunction with ST41_TX_FLAG_USER_PACING to handle
50+
* overflow scenarios.
51+
*/
52+
#define ST41_TX_FLAG_DROP_OLD (MTL_BIT32(7))
4653
/**
4754
* Flag bit in flags of struct st41_tx_ops.
4855
* If enabled, lib will assign the rtp timestamp to the value in

include/st_pipeline_api.h

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,12 @@ enum st22p_tx_flag {
384384
* lib will wait until timestamp is reached for each frame.
385385
*/
386386
ST22P_TX_FLAG_USER_PACING = (MTL_BIT32(3)),
387+
/**
388+
* Drop frames when the mtl reports late frames (transport can't keep up).
389+
* When late frame is detected, next frame from pipeline is ommited.
390+
* Untill we resume normal frame sending.
391+
*/
392+
ST22P_TX_FLAG_DROP_WHEN_LATE = (MTL_BIT32(12)),
387393
/**
388394
* If enabled, lib will assign the rtp timestamp to the value in
389395
* tx_frame_meta(ST10_TIMESTAMP_FMT_MEDIA_CLK is used)
@@ -413,6 +419,8 @@ enum st22p_tx_flag {
413419
/** Enable the st22p_tx_get_frame block behavior to wait until a frame becomes
414420
available or timeout(default: 1s, use st22p_tx_set_block_timeout to customize) */
415421
ST22P_TX_FLAG_BLOCK_GET = (MTL_BIT32(15)),
422+
/** If enabled, drop old frames when user pacing is used */
423+
ST22P_TX_FLAG_USER_TIMESTAMP_DROP_OLD = (MTL_BIT32(16)),
416424
};
417425

418426
/** Bit define for flags of struct st20p_tx_ops. */
@@ -437,6 +445,12 @@ enum st20p_tx_flag {
437445
* aligned with virtual receiver read schedule.
438446
*/
439447
ST20P_TX_FLAG_USER_PACING = (MTL_BIT32(3)),
448+
/**
449+
* Drop frames when the mtl reports late frames (transport can't keep up).
450+
* When late frame is detected, next frame from pipeline is ommited.
451+
* Untill we resume normal frame sending.
452+
*/
453+
ST20P_TX_FLAG_DROP_WHEN_LATE = (MTL_BIT32(12)),
440454
/**
441455
* If enabled, lib will assign the rtp timestamp to the value of timestamp in
442456
* st_frame.timestamp (if needed the value will be converted to
@@ -875,12 +889,22 @@ struct st20p_tx_ops {
875889
*/
876890
int (*notify_frame_available)(void* priv);
877891
/**
878-
* Optional. Callback when frame done in the lib.
879-
* And only non-block method can be used within this callback as it run from lcore
880-
* tasklet routine.
892+
* Optional. Callback when frame timing issues occur.
893+
* If ST20P_TX_FLAG_DROP_WHEN_LATE is enabled: triggered when a frame is dropped
894+
* from the pipeline due to late transmission.
895+
* If ST20P_TX_FLAG_DROP_WHEN_LATE is disabled: triggered when the transport
896+
* layer reports late frame delivery.
881897
*/
882898
int (*notify_frame_done)(void* priv, struct st_frame* frame);
883899

900+
/**
901+
* Optional. Callback when frame is late in the lib, if ST20P_TX_FLAG_DROP_WHEN_LATE is
902+
* enabled then it is triggered when a frame is omitted in pipeline tx.
903+
* If hte ST20P_TX_FLAG_DROP_WHEN_LATE is not enabled, then it is triggered when the
904+
* transport layer reports a late frame.
905+
*/
906+
int (*notify_frame_late)(void* priv, uint64_t epoch_skipped);
907+
884908
/** Optional. Linesize for transport frame, only for non-convert mode */
885909
size_t transport_linesize;
886910

@@ -1046,12 +1070,22 @@ struct st22p_tx_ops {
10461070
*/
10471071
int (*notify_frame_available)(void* priv);
10481072
/**
1049-
* Optional. Callback when frame done in the lib.
1050-
* And only non-block method can be used within this callback as it run from lcore
1051-
* tasklet routine.
1073+
* Optional. Callback when frame timing issues occur.
1074+
* If ST22P_TX_FLAG_DROP_WHEN_LATE is enabled: triggered when a frame is dropped
1075+
* from the pipeline due to late transmission.
1076+
* If ST22P_TX_FLAG_DROP_WHEN_LATE is disabled: triggered when the transport
1077+
* layer reports late frame delivery.
10521078
*/
10531079
int (*notify_frame_done)(void* priv, struct st_frame* frame);
10541080

1081+
/**
1082+
* Optional. Callback when frame is late in the lib, if ST22P_TX_FLAG_DROP_WHEN_LATE is
1083+
* enabled then it is triggered when a frame is omitted in pipeline tx.
1084+
* If hte ST22P_TX_FLAG_DROP_WHEN_LATE is not enabled, then it is triggered when the
1085+
* transport layer reports a late frame.
1086+
*/
1087+
int (*notify_frame_late)(void* priv, uint64_t epoch_skipped);
1088+
10551089
/** Optional for ST22P_TX_FLAG_ENABLE_RTCP. RTCP info */
10561090
struct st_tx_rtcp_ops rtcp;
10571091
/**

lib/src/mt_usdt.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
MT_DTRACE_PROBE4(st20p, tx_frame_put, idx, f_idx, va, stat)
107107
#define MT_USDT_ST20P_TX_FRAME_DONE(idx, f_idx, tmstamp) \
108108
MT_DTRACE_PROBE3(st20p, tx_frame_done, idx, f_idx, tmstamp)
109+
#define MT_USDT_ST20P_TX_FRAME_SPURN(idx, f_idx, tmstamp) \
110+
MT_DTRACE_PROBE3(st20p, tx_frame_done, idx, f_idx, tmstamp)
109111
#define MT_USDT_ST20P_TX_FRAME_NEXT(idx, f_idx) \
110112
MT_DTRACE_PROBE2(st20p, tx_frame_next, idx, f_idx)
111113
#define MT_USDT_ST20P_TX_FRAME_DUMP(idx, file, va, sz) \
@@ -128,6 +130,8 @@
128130
MT_DTRACE_PROBE3(st30p, tx_frame_put, idx, f_idx, va)
129131
#define MT_USDT_ST30P_TX_FRAME_DONE(idx, f_idx, tmstamp) \
130132
MT_DTRACE_PROBE3(st30p, tx_frame_done, idx, f_idx, tmstamp)
133+
#define MT_USDT_ST30P_TX_FRAME_SPURN(idx, f_idx, tmstamp) \
134+
MT_DTRACE_PROBE3(st30p, tx_frame_done, idx, f_idx, tmstamp)
131135
#define MT_USDT_ST30P_TX_FRAME_NEXT(idx, f_idx) \
132136
MT_DTRACE_PROBE2(st30p, tx_frame_next, idx, f_idx)
133137
#define MT_USDT_ST30P_TX_FRAME_DUMP(idx, file, frames) \
@@ -144,6 +148,17 @@
144148
MT_DTRACE_PROBE3(st30p, rx_frame_dump, idx, file, frames)
145149
#define MT_USDT_ST30P_RX_FRAME_DUMP_ENABLED() ST30P_RX_FRAME_DUMP_ENABLED()
146150

151+
#define MT_USDT_ST40P_TX_FRAME_GET(idx, f_idx, va) \
152+
MT_DTRACE_PROBE3(st40p, tx_frame_get, idx, f_idx, va)
153+
#define MT_USDT_ST40P_TX_FRAME_PUT(idx, f_idx, va) \
154+
MT_DTRACE_PROBE3(st40p, tx_frame_put, idx, f_idx, va)
155+
#define MT_USDT_ST40P_TX_FRAME_DONE(idx, f_idx, tmstamp) \
156+
MT_DTRACE_PROBE3(st40p, tx_frame_done, idx, f_idx, tmstamp)
157+
#define MT_USDT_ST40P_TX_FRAME_SPURN(idx, f_idx, tmstamp) \
158+
MT_DTRACE_PROBE3(st30p, tx_frame_done, idx, f_idx, tmstamp)
159+
#define MT_USDT_ST40P_TX_FRAME_NEXT(idx, f_idx) \
160+
MT_DTRACE_PROBE2(st40p, tx_frame_next, idx, f_idx)
161+
147162
#define MT_USDT_ST20_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, tmstamp) \
148163
MT_DTRACE_PROBE5(st20, tx_frame_next, m_idx, s_idx, f_idx, va, tmstamp)
149164
#define MT_USDT_ST20_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \

lib/src/mt_usdt_provider.d

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ provider st20p {
8080
probe tx_frame_put(int idx, int f_idx, void* va, int stat);
8181
probe tx_frame_next(int idx, int f_idx);
8282
probe tx_frame_done(int idx, int f_idx, uint32_t tmstamp);
83+
probe tx_frame_spurn(int idx, int f_idx, uint32_t tmstamp);
8384
/* attach to enable the frame dump at runtime */
8485
probe tx_frame_dump(int idx, char* dump_file, void* va, uint32_t data_size);
8586
/* rx */
@@ -94,6 +95,7 @@ provider st22 {
9495
/* tx */
9596
probe tx_frame_next(int m_idx, int s_idx, int f_idx, void* va, uint32_t tmstamp, uint32_t codestream_size);
9697
probe tx_frame_done(int m_idx, int s_idx, int f_idx, uint32_t tmstamp);
98+
probe tx_frame_spurn(int m_idx, int s_idx, int f_idx, uint32_t tmstamp);
9799
/* attach to enable the frame dump at runtime */
98100
probe tx_frame_dump(int m_idx, int s_idx, char* dump_file, void* va, uint32_t data_size);
99101
/* rx */
@@ -110,6 +112,7 @@ provider st22p {
110112
probe tx_frame_put(int idx, int f_idx, void* va, int stat, uint32_t data_size);
111113
probe tx_frame_next(int idx, int f_idx);
112114
probe tx_frame_done(int idx, int f_idx, uint32_t tmstamp);
115+
probe tx_frame_spurn(int idx, int f_idx, uint32_t tmstamp);
113116
/* attach to enable the frame dump at runtime */
114117
probe tx_frame_dump(int idx, char* dump_file, void* va, uint32_t data_size);
115118
/* rx */
@@ -132,6 +135,7 @@ provider st30p {
132135
probe tx_frame_put(int idx, int f_idx, void* va);
133136
probe tx_frame_next(int idx, int f_idx);
134137
probe tx_frame_done(int idx, int f_idx, uint32_t tmstamp);
138+
probe tx_frame_spurn(int idx, int f_idx, uint32_t tmstamp);
135139
/* attach to enable the frame dump at runtime */
136140
probe tx_frame_dump(int idx, char* dump_file, int frames);
137141
/* rx */
@@ -143,6 +147,12 @@ provider st30p {
143147
}
144148

145149
provider st40p {
150+
/* tx */
151+
probe tx_frame_get(int idx, int f_idx, void* va);
152+
probe tx_frame_put(int idx, int f_idx, void* va);
153+
probe tx_frame_next(int idx, int f_idx);
154+
probe tx_frame_done(int idx, int f_idx, uint32_t tmstamp);
155+
probe tx_frame_spurn(int idx, int f_idx, uint32_t tmstamp)
146156
/* rx */
147157
probe rx_frame_get(int idx, int f_idx, uint32_t meta_num);
148158
probe rx_frame_put(int idx, int f_idx, uint32_t meta_num);

0 commit comments

Comments
 (0)