Skip to content

Commit 1f0513a

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 93971b2 commit 1f0513a

25 files changed

+727
-299
lines changed

doc/usdt.md

Lines changed: 87 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,16 @@ sudo bpftrace -e 'usdt::st40:rx_mbuf_enqueue_fail { printf("%s m%d,s%d: mbuf %p
736736

737737
#### 2.5.6. st40p pipeline tracing
738738

739-
The ST40 pipeline helpers (used by `RxSt40PipelineSample`, `TxSt40PipelineSample`, or any app built on `st40_pipeline_api.h`) expose their own provider to focus on frame-level callbacks rather than mbuf activity. Today only the RX side wires USDT probes (TX helpers reuse the regular logging path):
739+
The ST40 pipeline helpers (used by `RxSt40PipelineSample`, `TxSt40PipelineSample`, or any app built on `st40_pipeline_api.h`) expose their own provider to focus on frame-level callbacks across both TX and RX paths:
740740

741741
```c
742742
provider st40p {
743+
/* tx */
744+
probe tx_frame_get(int idx, int f_idx, void* va);
745+
probe tx_frame_put(int idx, int f_idx, void* va);
746+
probe tx_frame_next(int idx, int f_idx);
747+
probe tx_frame_done(int idx, int f_idx, uint32_t tmstamp);
748+
probe tx_frame_drop(int idx, int f_idx, uint32_t tmstamp);
743749
/* rx */
744750
probe rx_frame_available(int idx, int f_idx, uint32_t meta_num);
745751
probe rx_frame_get(int idx, int f_idx, uint32_t meta_num);
@@ -749,6 +755,19 @@ provider st40p {
749755
}
750756
```
751757

758+
To watch for ancillary frames that arrive too late to flush, hook the TX drop probe (customize the process name for your setup):
759+
760+
```bash
761+
sudo bpftrace -e 'usdt::st40p:tx_frame_drop { printf("%s s%d: drop frame %d(timestamp:%u)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }' -p $(pidof TxSt40PipelineSample)
762+
```
763+
764+
Example output like below:
765+
766+
```text
767+
09:33:12 s0: drop frame 0(timestamp:241037184)
768+
09:33:12 s0: drop frame 1(timestamp:241037728)
769+
```
770+
752771
Typical RX-side traces (customize the process name/PID for your sample or RxTxApp process):
753772

754773
```bash
@@ -868,18 +887,34 @@ Example output like below:
868887
09:22:58 s0: done frame 1(timestamp:3639352297)
869888
```
870889

890+
#### 2.6.5. tx_frame_drop USDT
891+
892+
usage: customize the application process name as your setup
893+
894+
```bash
895+
sudo bpftrace -e 'usdt::st20p:tx_frame_drop { printf("%s s%d: drop frame %d(timestamp:%u)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }' -p $(pidof RxTxApp)
896+
```
897+
898+
Example output like below:
899+
900+
```text
901+
09:25:04 s0: drop frame 0(timestamp:3639471120)
902+
09:25:04 s0: drop frame 1(timestamp:3639472621)
903+
```
904+
871905
And if you want to trace all st20p tx events, use below bpftrace script.
872906

873907
```bash
874908
sudo bpftrace -e '
875909
usdt::st20p:tx_frame_get { printf("%s s%d: get frame %d(addr:%p)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }
876910
usdt::st20p:tx_frame_put { printf("%s s%d: put frame %d(addr:%p,stat:%d)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2, arg3); }
877911
usdt::st20p:tx_frame_done { printf("%s s%d: done frame %d(timestamp:%u)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }
912+
usdt::st20p:tx_frame_drop { printf("%s s%d: drop frame %d(timestamp:%u)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }
878913
usdt::st20p:tx_frame_next { printf("%s s%d: next frame %d\n", strftime("%H:%M:%S", nsecs), arg0, arg1); }
879914
' -p $(pidof RxTxApp)
880915
```
881916

882-
#### 2.6.5. rx_frame_get USDT
917+
#### 2.6.6. rx_frame_get USDT
883918

884919
usage: customize the application process name as your setup
885920

@@ -895,7 +930,7 @@ Example output like below:
895930
10:37:16 s0: get frame 2(addr:0x3209a17000)
896931
```
897932

898-
#### 2.6.6. rx_frame_put USDT
933+
#### 2.6.7. rx_frame_put USDT
899934

900935
usage: customize the application process name as your setup
901936

@@ -911,7 +946,7 @@ Example output like below:
911946
10:37:33 s0: put frame 2(addr:0x3209a17000)
912947
```
913948

914-
#### 2.6.7. rx_frame_available USDT
949+
#### 2.6.8. rx_frame_available USDT
915950

916951
usage: customize the application process name as your setup
917952

@@ -937,7 +972,7 @@ usdt::st20p:rx_frame_available { printf("%s s%d: available frame %d(addr:%p, tms
937972
' -p $(pidof RxTxApp)
938973
```
939974

940-
#### 2.6.8. tx_frame_dump USDT
975+
#### 2.6.9. tx_frame_dump USDT
941976

942977
Usage: Attaching to this hook initiates the process, which continues to dump frames to a local file every 5 seconds until detachment occurs.
943978

@@ -952,7 +987,7 @@ Example output like below:
952987
13:26:46 s0: dump frame 0x3206217000 size 8294400 to imtl_usdt_st20ptx_s0_1920_1080_CzYDQe.yuv
953988
```
954989

955-
#### 2.6.9. rx_frame_dump USDT
990+
#### 2.6.10. rx_frame_dump USDT
956991

957992
Usage: Attaching to this hook initiates the process, which continues to dump frames to a local file every 5 seconds until detachment occurs.
958993

@@ -1207,18 +1242,34 @@ Example output like below:
12071242
15:05:38 s0: done frame 1(timestamp:380834179)
12081243
```
12091244

1245+
#### 2.8.5. tx_frame_drop USDT
1246+
1247+
usage: customize the application process name as your setup
1248+
1249+
```bash
1250+
sudo bpftrace -e 'usdt::st22p:tx_frame_drop { printf("%s s%d: drop frame %d(timestamp:%u)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }' -p $(pidof RxTxApp)
1251+
```
1252+
1253+
Example output like below:
1254+
1255+
```text
1256+
15:06:42 s0: drop frame 0(timestamp:380846682)
1257+
15:06:42 s0: drop frame 1(timestamp:380848184)
1258+
```
1259+
12101260
And if you want to trace all st22p tx events, use below bpftrace script.
12111261

12121262
```bash
12131263
sudo bpftrace -e '
12141264
usdt::st22p:tx_frame_get { printf("%s s%d: get frame %d(addr:%p)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }
12151265
usdt::st22p:tx_frame_put { printf("%s s%d: put frame %d(addr:%p)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }
1266+
usdt::st22p:tx_frame_drop { printf("%s s%d: drop frame %d(timestamp:%u)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }
12161267
usdt::st22p:tx_frame_done { printf("%s s%d: done frame %d(timestamp:%u)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }
12171268
usdt::st22p:tx_frame_next { printf("%s s%d: next frame %d\n", strftime("%H:%M:%S", nsecs), arg0, arg1); }
12181269
' -p $(pidof RxTxApp)
12191270
```
12201271

1221-
#### 2.8.5. rx_frame_get USDT
1272+
#### 2.8.6. rx_frame_get USDT
12221273

12231274
usage: customize the application process name as your setup
12241275

@@ -1234,7 +1285,7 @@ Example output like below:
12341285
15:10:54 s0: get frame 2(addr:0x320830e600)
12351286
```
12361287

1237-
#### 2.8.6. rx_frame_put USDT
1288+
#### 2.8.7. rx_frame_put USDT
12381289

12391290
usage: customize the application process name as your setup
12401291

@@ -1250,7 +1301,7 @@ Example output like below:
12501301
15:11:08 s0: put frame 2(addr:0x320830e600)
12511302
```
12521303

1253-
#### 2.8.7. rx_frame_available USDT
1304+
#### 2.8.8. rx_frame_available USDT
12541305

12551306
usage: customize the application process name as your setup
12561307

@@ -1276,7 +1327,7 @@ usdt::st22p:rx_frame_available { printf("%s s%d: available frame %d(addr:%p, tms
12761327
' -p $(pidof RxTxApp)
12771328
```
12781329

1279-
#### 2.8.8. tx_frame_dump USDT
1330+
#### 2.8.9. tx_frame_dump USDT
12801331

12811332
Usage: Attaching to this hook initiates the process, which continues to dump frames to a local file every 5 seconds until detachment occurs.
12821333

@@ -1291,7 +1342,7 @@ Example output like below:
12911342
15:22:04 s0: dump frame 0x3205b0e600 size 5184000 to imtl_usdt_st22ptx_s0_1920_1080_oOJwjO.yuv
12921343
```
12931344

1294-
#### 2.8.9. rx_frame_dump USDT
1345+
#### 2.8.10. rx_frame_dump USDT
12951346

12961347
Usage: Attaching to this hook initiates the process, which continues to dump frames to a local file every 5 seconds until detachment occurs.
12971348

@@ -1306,7 +1357,7 @@ Example output like below:
13061357
15:23:04 s0: dump frame 0x3207d0e600 size 5184000 to imtl_usdt_st22prx_s0_1920_1080_N72BCd.yuv
13071358
```
13081359

1309-
#### 2.8.10. tx_encode_get USDT
1360+
#### 2.8.11. tx_encode_get USDT
13101361

13111362
usage: customize the application process name as your setup
13121363

@@ -1321,7 +1372,7 @@ Example output like below:
13211372
16:20:25 s0: get encode 1(src:0x320610e600,dst:0x32032400fc)
13221373
```
13231374

1324-
#### 2.8.11. tx_encode_put USDT
1375+
#### 2.8.12. tx_encode_put USDT
13251376

13261377
usage: customize the application process name as your setup
13271378

@@ -1345,7 +1396,7 @@ usdt::st22p:tx_encode_put { printf("%s s%d: put encode %d(src:%p,dst:%p), result
13451396
' -p $(pidof RxTxApp)
13461397
```
13471398

1348-
#### 2.8.12. rx_decode_get USDT
1399+
#### 2.8.13. rx_decode_get USDT
13491400

13501401
usage: customize the application process name as your setup
13511402

@@ -1361,7 +1412,7 @@ Example output like below:
13611412
16:18:43 s0: get decode 2(src:0x3208f0e600,dst:0x320830e600), codestream size: 777600
13621413
```
13631414

1364-
#### 2.8.13. rx_decode_put USDT
1415+
#### 2.8.14. rx_decode_put USDT
13651416

13661417
usage: customize the application process name as your setup
13671418

@@ -1471,18 +1522,34 @@ Example output like below:
14711522
15:51:58 s0: done frame 2(timestamp:447476096)
14721523
```
14731524

1525+
#### 2.9.5. tx_frame_drop USDT
1526+
1527+
usage: customize the application process name as your setup
1528+
1529+
```bash
1530+
sudo bpftrace -e 'usdt::st30p:tx_frame_drop { printf("%s s%d: drop frame %d(timestamp:%u)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }' -p $(pidof RxTxApp)
1531+
```
1532+
1533+
Example output like below:
1534+
1535+
```text
1536+
15:52:11 s0: drop frame 0(timestamp:447476608)
1537+
15:52:11 s0: drop frame 1(timestamp:447477088)
1538+
```
1539+
14741540
And if you want to trace all st30p tx events, use below bpftrace script.
14751541

14761542
```bash
14771543
sudo bpftrace -e '
14781544
usdt::st30p:tx_frame_get { printf("%s s%d: get frame %d(addr:%p)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }
14791545
usdt::st30p:tx_frame_put { printf("%s s%d: put frame %d(addr:%p)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }
1546+
usdt::st30p:tx_frame_drop { printf("%s s%d: drop frame %d(timestamp:%u)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }
14801547
usdt::st30p:tx_frame_done { printf("%s s%d: done frame %d(timestamp:%u)\n", strftime("%H:%M:%S", nsecs), arg0, arg1, arg2); }
14811548
usdt::st30p:tx_frame_next { printf("%s s%d: next frame %d\n", strftime("%H:%M:%S", nsecs), arg0, arg1); }
14821549
' -p $(pidof RxTxApp)
14831550
```
14841551

1485-
#### 2.9.5. rx_frame_get USDT
1552+
#### 2.9.6. rx_frame_get USDT
14861553

14871554
usage: customize the application process name as your setup
14881555

@@ -1498,7 +1565,7 @@ Example output like below:
14981565
15:57:50 s0: get frame 2(addr:0x32034009c0)
14991566
```
15001567

1501-
#### 2.9.6. rx_frame_put USDT
1568+
#### 2.9.7. rx_frame_put USDT
15021569

15031570
usage: customize the application process name as your setup
15041571

@@ -1514,7 +1581,7 @@ Example output like below:
15141581
15:58:14 s0: put frame 2(addr:0x32034009c0)
15151582
```
15161583

1517-
#### 2.9.7. rx_frame_available USDT
1584+
#### 2.9.8. rx_frame_available USDT
15181585

15191586
usage: customize the application process name as your setup
15201587

@@ -1540,7 +1607,7 @@ usdt::st30p:rx_frame_available { printf("%s s%d: available frame %d(addr:%p, tms
15401607
' -p $(pidof RxTxApp)
15411608
```
15421609

1543-
#### 2.9.8. tx_frame_dump USDT
1610+
#### 2.9.9. tx_frame_dump USDT
15441611

15451612
Usage: This utility is designed to capture and store audio frames transmitted over the network. Attaching to this hook initiates the process, which continues to dump frames to a local file until detachment occurs.
15461613

@@ -1568,7 +1635,7 @@ Then use ffmpeg tools to convert ram PCM file to a wav, customize the format as
15681635
ffmpeg -f s24be -ar 48000 -ac 2 -i imtl_usdt_st30ptx_s0_48000_24_c2_LgAKKR.pcm dump.wav
15691636
```
15701637

1571-
#### 2.9.9. rx_frame_dump USDT
1638+
#### 2.9.10. rx_frame_dump USDT
15721639

15731640
Usage: Similar to tx_frame_dump hook, this utility is designed to capture and store audio frames received over the network. Attaching to this hook initiates the process, which continues to dump frames to a local file until detachment occurs.
15741641

include/st20_api.h

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

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

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

include/st30_api.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,14 @@ struct st30_tx_ops {
385385
int (*notify_frame_done)(void* priv, uint16_t frame_idx,
386386
struct st30_tx_frame_meta* meta);
387387

388+
/**
389+
* Optional. Callback triggered when a frame epoch is omitted/skipped in the lib.
390+
* This occurs when the transmission timing falls behind schedule and an epoch
391+
* must be skipped to maintain synchronization. (or in the user pacing mode
392+
* when the user time is behind the lib sending time).
393+
*/
394+
int (*notify_frame_late)(void* priv, uint64_t epoch_skipped);
395+
388396
/*
389397
* Optional. The size of fifo ring which used between the packet builder and pacing.
390398
* Leave to zero to use default value: the packet number within

include/st30_pipeline_api.h

Lines changed: 17 additions & 2 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. */
@@ -130,10 +137,18 @@ struct st30p_tx_ops {
130137
int (*notify_frame_available)(void* priv);
131138
/**
132139
* Optional. Callback when frame done.
133-
* And only non-block method can be used within this callback as it run from lcore
134-
* tasklet routine.
140+
* If TX_FLAG_DROP_WHEN_LATE is enabled AND notify_frame_late is set,
141+
* then this will be called only when notify_frame_late is NOT called.
135142
*/
136143
int (*notify_frame_done)(void* priv, struct st30_frame* frame);
144+
/**
145+
* Optional. Callback when frame timing issues occur.
146+
* If ST30P_TX_FLAG_DROP_WHEN_LATE is enabled: triggered when a frame is dropped
147+
* from the pipeline due to late transmission.
148+
* If ST30P_TX_FLAG_DROP_WHEN_LATE is disabled: triggered when the transport
149+
* layer reports late frame delivery.
150+
*/
151+
int (*notify_frame_late)(void* priv, uint64_t epoch_skipped);
137152

138153
/**
139154
* 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
/**

0 commit comments

Comments
 (0)