Skip to content

Commit 8cd7999

Browse files
Sakoramtszumski
andauthored
Add: TX_FLAG_EXACT_USER_PACING for video session (#1264)
if TX_FLAG_EXACT_USER_PACING is enabled, the lib does not align the transmission time to the virtual receiver read schedule by adding TR_offset. The first packet of the frame will be sent exactly at the time specified by the user. Additionally: - Refactor tv_sync_pacing in st_tx_video_session.c - Remove TX_FLAG_RTP_TIMESTAMP_FIRST_PKT TX_FLAG_RTP_TIMESTAMP_FIRST_PKT did not changed behavior in any way. so its bit in mask was reused to TX_FLAG_EXACT_USER_PACING - Fix TX_FLAG_RTP_TIMESTAMP_EPOCH This flag should force the lib to set RTP timestamp exactly to N*frame_time. It did not happen before, it just caused a few packets worth of time difference. --------- Signed-off-by: Kasiewicz, Marek <[email protected]> Co-authored-by: Tomasz Szumski <[email protected]>
1 parent e070554 commit 8cd7999

File tree

14 files changed

+286
-206
lines changed

14 files changed

+286
-206
lines changed

config/tx_1v_user_pacing.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"interfaces": [
3+
{
4+
"name": "0000:af:01.0",
5+
"ip": "192.168.30.10"
6+
}
7+
],
8+
"tx_sessions": [
9+
{
10+
"dip": [
11+
"239.1.1.1"
12+
],
13+
"interface": [
14+
0
15+
],
16+
"st20p": [
17+
{
18+
"replicas": 1,
19+
"start_port": 20000,
20+
"payload_type": 112,
21+
"width": 1920,
22+
"height": 1080,
23+
"fps": "p59",
24+
"device": "AUTO",
25+
"input_format": "YUV422PLANAR10LE",
26+
"transport_format": "YUV_422_10bit",
27+
"st20p_url": "./yuv422p10le_1080p.yuv",
28+
"user_pacing": true
29+
}
30+
],
31+
"user_pacing_offset" : 20000000
32+
}
33+
]
34+
}

include/st20_api.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ extern "C" {
4545
#define ST20_TX_FLAG_EXT_FRAME (MTL_BIT32(2))
4646
/**
4747
* Flag bit in flags of struct st20_tx_ops.
48-
* User control the frame pacing by pass a timestamp in st20_tx_frame_meta,
49-
* lib will wait until timestamp is reached for each frame.
48+
* User control the frame transmission time by passing a timestamp in
49+
* st20_tx_frame_meta.timestamp, lib will wait until timestamp is reached for each frame.
50+
* The time of sending is aligned with virtual receiver read schedule.
5051
*/
5152
#define ST20_TX_FLAG_USER_PACING (MTL_BIT32(3))
5253
/**
5354
* Flag bit in flags of struct st20_tx_ops.
54-
* If enabled, lib will assign the rtp timestamp to the value in
55-
* st20_tx_frame_meta(ST10_TIMESTAMP_FMT_MEDIA_CLK is used)
55+
* If enabled, lib will assign the rtp timestamp to the value of
56+
* t20_tx_frame_meta.timestamp (if needed the value will be converted to
57+
* ST10_TIMESTAMP_FMT_MEDIA_CLK)
5658
*/
5759
#define ST20_TX_FLAG_USER_TIMESTAMP (MTL_BIT32(4))
5860
/**
@@ -74,13 +76,15 @@ extern "C" {
7476
#define ST20_TX_FLAG_ENABLE_RTCP (MTL_BIT32(7))
7577
/**
7678
* Flag bit in flags of struct st20_tx_ops.
77-
* Set this flag to set rtp timestamp at the time of the first packet egresses from the
78-
* sender.
79+
* It changes how ST20_TX_FLAG_USER_PACING works. if enabled, it does not align the
80+
* transmission time to the virtual receiver read schedule. The first
81+
* packet of the frame will be sent exactly at the time specified by the user.
7982
*/
80-
#define ST20_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT (MTL_BIT32(8))
83+
#define ST20_TX_FLAG_EXACT_USER_PACING (MTL_BIT32(8))
8184
/**
8285
* Flag bit in flags of struct st20_tx_ops.
83-
* Set this flag to set rtp timestamp at the time of the epoch.
86+
* If enabled the RTP timestamp will be set exactly to epoch + N *
87+
* frame_time, omitting TR_offset.
8488
*/
8589
#define ST20_TX_FLAG_RTP_TIMESTAMP_EPOCH (MTL_BIT32(9))
8690
/**

include/st_pipeline_api.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,15 @@ enum st20p_tx_flag {
432432
*/
433433
ST20P_TX_FLAG_EXT_FRAME = (MTL_BIT32(2)),
434434
/**
435-
* User control the frame pacing by pass a timestamp in st_frame,
436-
* lib will wait until timestamp is reached for each frame.
435+
* User control frame transmission time by pass a timestamp in st_frame.timestamp,
436+
* lib will wait until timestamp is reached for each frame. The time of sending is
437+
* aligned with virtual receiver read schedule.
437438
*/
438439
ST20P_TX_FLAG_USER_PACING = (MTL_BIT32(3)),
439440
/**
440-
* If enabled, lib will assign the rtp timestamp to the value in
441-
* tx_frame_meta(ST10_TIMESTAMP_FMT_MEDIA_CLK is used)
441+
* If enabled, lib will assign the rtp timestamp to the value of timestamp in
442+
* st_frame.timestamp (if needed the value will be converted to
443+
* ST10_TIMESTAMP_FMT_MEDIA_CLK)
442444
*/
443445
ST20P_TX_FLAG_USER_TIMESTAMP = (MTL_BIT32(4)),
444446
/**
@@ -456,12 +458,14 @@ enum st20p_tx_flag {
456458
*/
457459
ST20P_TX_FLAG_ENABLE_RTCP = (MTL_BIT32(7)),
458460
/**
459-
* Set this flag to set rtp timestamp at the time of the first packet egresses from the
460-
* sender.
461+
* It changes how ST20_TX_FLAG_USER_PACING works. if enabled, it does not align the
462+
* transmission time to the virtual receiver read schedule. The
463+
* first packet of the frame will be sent exactly at the time specified by the user.
461464
*/
462-
ST20P_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT = (MTL_BIT32(8)),
465+
ST20P_TX_FLAG_EXACT_USER_PACING = (MTL_BIT32(8)),
463466
/**
464-
* Set this flag to set rtp timestamp at the time of the epoch.
467+
* If enabled the RTP timestamp will be set exactly to epoch + N *
468+
* frame_time, omitting TR_offset.
465469
*/
466470
ST20P_TX_FLAG_RTP_TIMESTAMP_EPOCH = (MTL_BIT32(9)),
467471
/**

lib/src/st2110/pipeline/st20_pipeline_tx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ static int tx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_tx
305305
ops_tx.flags |= ST20_TX_FLAG_ENABLE_RTCP;
306306
ops_tx.rtcp = ops->rtcp;
307307
}
308-
if (ops->flags & ST20P_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT)
309-
ops_tx.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT;
308+
if (ops->flags & ST20P_TX_FLAG_EXACT_USER_PACING)
309+
ops_tx.flags |= ST20_TX_FLAG_EXACT_USER_PACING;
310310
if (ops->flags & ST20P_TX_FLAG_RTP_TIMESTAMP_EPOCH)
311311
ops_tx.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_EPOCH;
312312
if (ops->flags & ST20P_TX_FLAG_DISABLE_BULK) ops_tx.flags |= ST20_TX_FLAG_DISABLE_BULK;

lib/src/st2110/st_fmt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,14 +907,14 @@ bool st_frame_fmt_equal_transport(enum st_frame_fmt fmt, enum st20_fmt tfmt) {
907907
}
908908

909909
uint32_t st10_tai_to_media_clk(uint64_t tai_ns, uint32_t sampling_rate) {
910-
double ts = (double)tai_ns * sampling_rate / NS_PER_S;
910+
long double ts = (long double)tai_ns * sampling_rate / NS_PER_S;
911911
uint64_t tmstamp64 = ts;
912912
uint32_t tmstamp32 = tmstamp64;
913913
return tmstamp32;
914914
}
915915

916916
uint64_t st10_media_clk_to_ns(uint32_t media_ts, uint32_t sampling_rate) {
917-
double ts = (double)media_ts * NS_PER_S / sampling_rate;
917+
long double ts = (long double)media_ts * NS_PER_S / sampling_rate;
918918
return ts;
919919
}
920920

lib/src/st2110/st_header.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ struct st_tx_video_pacing {
188188
uint64_t cur_epochs; /* epoch of current frame */
189189
/* timestamp for rtp header */
190190
uint32_t rtp_time_stamp;
191-
uint64_t cur_epoch_time;
192-
double tsc_time_cursor; /* in ns, tsc time cursor for packet pacing */
193-
double ptp_time_cursor; /* in ns, ptp time cursor for packet pacing */
191+
uint64_t tsc_time_cursor; /* in ns, tsc time cursor for packet pacing */
192+
uint64_t ptp_time_cursor; /* in ns, ptp time cursor for packet pacing */
194193
/* ptp time may onward */
195194
uint32_t max_onward_epochs;
196195
uint64_t tsc_time_frame_start; /* start tsc time for frame start */

0 commit comments

Comments
 (0)