Skip to content

Commit 7ef3711

Browse files
committed
Fix: User pacing test
Signed-off-by: Kasiewicz, Marek <[email protected]>
1 parent b4c1020 commit 7ef3711

File tree

14 files changed

+665
-184
lines changed

14 files changed

+665
-184
lines changed

include/st20_api.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ struct st20_rx_tp_meta {
480480
enum st_rx_tp_compliant compliant;
481481
/** the failed cause if compliant is not ST_RX_TP_COMPLIANT_NARROW */
482482
char failed_cause[64];
483+
/** TAI timestamp measured right after first packet of the frame was received */
484+
uint64_t receive_timestamp;
483485

484486
/* packets count in current report meta */
485487
uint32_t pkts_cnt;
@@ -1876,6 +1878,24 @@ int st20_tx_put_mbuf(st20_tx_handle handle, void* mbuf, uint16_t len);
18761878
*/
18771879
int st20_tx_get_sch_idx(st20_tx_handle handle);
18781880

1881+
/**
1882+
* Retrieve pacing parameters for a tx st2110-20 session.
1883+
*
1884+
* @param handle
1885+
* The handle to the tx st2110-20(video) session.
1886+
* @param tr_offset_ns
1887+
* Optional output for the tr offset value in nanoseconds.
1888+
* @param trs_ns
1889+
* Optional output for the packet spacing (TRS) value in nanoseconds.
1890+
* @param vrx_pkts
1891+
* Optional output for the VRX packet count.
1892+
*
1893+
* @return
1894+
* 0 on success, negative value otherwise.
1895+
*/
1896+
int st20_tx_get_pacing_params(st20_tx_handle handle, double* tr_offset_ns, double* trs_ns,
1897+
uint32_t* vrx_pkts);
1898+
18791899
/**
18801900
* Retrieve the general statistics(I/O) for one tx st2110-20(video) session.
18811901
*

include/st_pipeline_api.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ struct st_frame {
319319
/** timing parser meta for st20p_rx_get_frame, only active if
320320
* ST20P_RX_FLAG_TIMING_PARSER_META */
321321
struct st20_rx_tp_meta* tp[MTL_SESSION_PORT_MAX];
322+
/** TAI timestamp measured right after first packet of the frame was received */
323+
uint64_t receive_timestamp;
322324
};
323325

324326
/** Device type of st plugin */
@@ -1761,6 +1763,23 @@ size_t st20p_tx_frame_size(st20p_tx_handle handle);
17611763
*/
17621764
int st20p_tx_get_sch_idx(st20p_tx_handle handle);
17631765

1766+
/**
1767+
* Retrieve pacing parameters for a tx st2110-20(pipeline) session.
1768+
*
1769+
* @param handle
1770+
* The handle to the tx st2110-20(video) session.
1771+
* @param tr_offset_ns
1772+
* Optional output for the tr offset value in nanoseconds.
1773+
* @param trs_ns
1774+
* Optional output for the packet spacing (TRS) value in nanoseconds.
1775+
* @param vrx_pkts
1776+
* Optional output for the VRX packet count.
1777+
*
1778+
* @return
1779+
* 0 on success, negative value otherwise.
1780+
*/
1781+
int st20p_tx_get_pacing_params(st20p_tx_handle handle, double* tr_offset_ns,
1782+
double* trs_ns, uint32_t* vrx_pkts);
17641783
/**
17651784
* Retrieve the general statistics(I/O) for one tx st2110-20(pipeline) session.
17661785
*

lib/src/st2110/pipeline/st20_pipeline_rx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ static int rx_st20p_frame_ready(void* priv, void* frame,
217217
framebuff->src.timestamp = framebuff->dst.timestamp = meta->timestamp;
218218
framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = meta->rtp_timestamp;
219219
framebuff->src.status = framebuff->dst.status = meta->status;
220+
framebuff->src.receive_timestamp = framebuff->dst.receive_timestamp =
221+
meta->timestamp_first_pkt;
220222

221223
framebuff->src.pkts_total = framebuff->dst.pkts_total = meta->pkts_total;
222224
for (enum mtl_session_port s_port = 0; s_port < MTL_SESSION_PORT_MAX; s_port++) {

lib/src/st2110/pipeline/st20_pipeline_tx.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,26 @@ int st20p_tx_get_sch_idx(st20p_tx_handle handle) {
984984
return st20_tx_get_sch_idx(ctx->transport);
985985
}
986986

987+
int st20p_tx_get_pacing_params(st20p_tx_handle handle, double* tr_offset_ns,
988+
double* trs_ns, uint32_t* vrx_pkts) {
989+
struct st20p_tx_ctx* ctx = handle;
990+
int cidx;
991+
992+
if (!handle) {
993+
err("%s, invalid handle %p\n", __func__, handle);
994+
return -EINVAL;
995+
}
996+
ctx = handle;
997+
cidx = ctx->idx;
998+
999+
if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) {
1000+
err("%s(%d), invalid type %d\n", __func__, cidx, ctx->type);
1001+
return -EINVAL;
1002+
}
1003+
1004+
return st20_tx_get_pacing_params(ctx->transport, tr_offset_ns, trs_ns, vrx_pkts);
1005+
}
1006+
9871007
int st20p_tx_get_session_stats(st20p_tx_handle handle, struct st20_tx_user_stats* stats) {
9881008
struct st20p_tx_ctx* ctx = handle;
9891009
int cidx;

lib/src/st2110/st_tx_video_session.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4343,6 +4343,27 @@ int st20_tx_get_sch_idx(st20_tx_handle handle) {
43434343
return s_impl->sch->idx;
43444344
}
43454345

4346+
int st20_tx_get_pacing_params(st20_tx_handle handle, double* tr_offset_ns, double* trs_ns,
4347+
uint32_t* vrx_pkts) {
4348+
struct st_tx_video_session_handle_impl* s_impl = handle;
4349+
4350+
if (!handle) {
4351+
err("%s, invalid handle %p\n", __func__, handle);
4352+
return -EINVAL;
4353+
}
4354+
4355+
if (s_impl->type != MT_HANDLE_TX_VIDEO) {
4356+
err("%s, invalid type %d\n", __func__, s_impl->type);
4357+
return -EINVAL;
4358+
}
4359+
4360+
struct st_tx_video_session_impl* s = s_impl->impl;
4361+
if (tr_offset_ns) *tr_offset_ns = s->pacing.tr_offset;
4362+
if (trs_ns) *trs_ns = s->pacing.trs;
4363+
if (vrx_pkts) *vrx_pkts = s->pacing.vrx;
4364+
return 0;
4365+
}
4366+
43464367
int st20_tx_get_session_stats(st20_tx_handle handle, struct st20_tx_user_stats* stats) {
43474368
struct st_tx_video_session_handle_impl* s_impl = handle;
43484369

lib/src/st2110/st_video_transmitter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* This adds a superficial difference between the RTP timestamp and the transmission
1818
* time, which makes it look as if the packets have a slight latency immediately after
1919
* entering the wire. This prevents negative latency values. */
20-
#define LATENCY_COMPENSATION 1
20+
#define LATENCY_COMPENSATION 2
2121

2222
static int video_trs_tasklet_start(void* priv) {
2323
struct st_video_transmitter_impl* trs = priv;

tests/integration_tests/noctx/St20pHandler.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#include "noctx.hpp"
66

7-
St20pHandler::St20pHandler(st_tests_context* ctx, FrameTestStrategy* sessionUserData,
7+
St20pHandler::St20pHandler(st_tests_context* ctx, FrameTestStrategy* frameTestStrategy,
88
st20p_tx_ops ops_tx, st20p_rx_ops ops_rx, bool create,
99
bool start)
10-
: Handlers(ctx, sessionUserData) {
10+
: Handlers(ctx, frameTestStrategy) {
1111
if (ops_tx.name == nullptr && ops_rx.name == nullptr) {
1212
fillSt20Ops();
1313
ops_tx = sessionsOpsTx;
@@ -17,11 +17,11 @@ St20pHandler::St20pHandler(st_tests_context* ctx, FrameTestStrategy* sessionUser
1717
sessionsOpsRx = ops_rx;
1818
}
1919

20-
EXPECT_TRUE(sessionUserData != nullptr);
21-
if (!sessionUserData) return;
20+
EXPECT_TRUE(frameTestStrategy != nullptr);
21+
if (!frameTestStrategy) return;
2222

23-
this->sessionUserData = sessionUserData;
24-
sessionUserData->parent = this;
23+
this->frameTestStrategy = frameTestStrategy;
24+
frameTestStrategy->parent = this;
2525

2626
if (create) {
2727
createSession(ops_tx, ops_rx, start);
@@ -111,17 +111,17 @@ void St20pHandler::createSession(st20p_tx_ops ops_tx, st20p_rx_ops ops_rx, bool
111111
sessionsOpsTx = ops_tx;
112112
sessionsOpsRx = ops_rx;
113113

114-
createSessionTx();
115114
createSessionRx();
115+
createSessionTx();
116116

117117
if (start) {
118118
startSession();
119119
}
120120
}
121121

122122
void St20pHandler::createSession(bool start) {
123-
createSessionTx();
124123
createSessionRx();
124+
createSessionTx();
125125

126126
if (start) {
127127
startSession();
@@ -168,8 +168,8 @@ void St20pHandler::st20TxDefaultFunction(std::atomic<bool>& stopFlag) {
168168
ASSERT_EQ(frame->width, width);
169169
ASSERT_EQ(frame->height, height);
170170

171-
if (sessionUserData->enable_tx_modifier) {
172-
sessionUserData->txTestFrameModifier(frame->addr, frameSize);
171+
if (frameTestStrategy->enable_tx_modifier) {
172+
frameTestStrategy->txTestFrameModifier(frame->addr, frameSize);
173173
}
174174

175175
frame->data_size = frameSize;
@@ -201,28 +201,29 @@ void St20pHandler::st20RxDefaultFunction(std::atomic<bool>& stopFlag) {
201201
ASSERT_EQ(frame->height, height);
202202
ASSERT_GE(frame->data_size, frameSize);
203203

204-
if (sessionUserData->enable_rx_modifier) {
205-
sessionUserData->rxTestFrameModifier(frame->addr, frame->data_size);
204+
if (frameTestStrategy->enable_rx_modifier) {
205+
frameTestStrategy->rxTestFrameModifier(frame->addr, frame->data_size);
206206
}
207207

208208
st20p_rx_put_frame(handle, frame);
209209
}
210210
}
211211

212-
void St20pHandler::startSession() {
213-
Handlers::startSession(
214-
{[this](std::atomic<bool>& stopFlag) { this->st20TxDefaultFunction(stopFlag); },
215-
[this](std::atomic<bool>& stopFlag) { this->st20RxDefaultFunction(stopFlag); }});
216-
}
217212

218213
void St20pHandler::startSessionTx() {
219214
Handlers::startSession(
220-
{[this](std::atomic<bool>& stopFlag) { this->st20TxDefaultFunction(stopFlag); }});
221-
}
222-
215+
{[this](std::atomic<bool>& stopFlag) { this->st20TxDefaultFunction(stopFlag); }});
216+
}
217+
223218
void St20pHandler::startSessionRx() {
224219
Handlers::startSession(
225-
{[this](std::atomic<bool>& stopFlag) { this->st20RxDefaultFunction(stopFlag); }});
220+
{[this](std::atomic<bool>& stopFlag) { this->st20RxDefaultFunction(stopFlag); }});
221+
}
222+
223+
void St20pHandler::startSession() {
224+
startSessionRx();
225+
sleep(1);
226+
startSessionTx();
226227
}
227228

228229
void St20pHandler::startSession(

tests/integration_tests/noctx/St30pHandler.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#include "noctx.hpp"
66

7-
St30pHandler::St30pHandler(st_tests_context* ctx, FrameTestStrategy* sessionUserData,
7+
St30pHandler::St30pHandler(st_tests_context* ctx, FrameTestStrategy* frameTestStrategy,
88
st30p_tx_ops ops_tx, st30p_rx_ops ops_rx,
99
uint msPerFramebuffer, bool create, bool start)
10-
: Handlers(ctx, sessionUserData), msPerFramebuffer(msPerFramebuffer) {
10+
: Handlers(ctx, frameTestStrategy), msPerFramebuffer(msPerFramebuffer) {
1111
if (ops_tx.name == nullptr && ops_rx.name == nullptr) {
1212
fillSt30pOps();
1313
ops_tx = sessionsOpsTx;
@@ -17,10 +17,10 @@ St30pHandler::St30pHandler(st_tests_context* ctx, FrameTestStrategy* sessionUser
1717
sessionsOpsRx = ops_rx;
1818
}
1919

20-
if (!sessionUserData) throw std::runtime_error("St30pHandler no sessionUserData");
20+
if (!frameTestStrategy) throw std::runtime_error("St30pHandler no frameTestStrategy");
2121

22-
this->sessionUserData = sessionUserData;
23-
sessionUserData->parent = this;
22+
this->frameTestStrategy = frameTestStrategy;
23+
frameTestStrategy->parent = this;
2424

2525
if (create) {
2626
createSession(ops_tx, ops_rx, start);
@@ -177,8 +177,8 @@ void St30pHandler::st30pTxDefaultFunction(std::atomic<bool>& stopFlag) {
177177
ASSERT_EQ(frame->ptime, sessionsOpsTx.ptime);
178178
ASSERT_EQ(frame->sampling, sessionsOpsTx.sampling);
179179

180-
if (sessionUserData->enable_tx_modifier) {
181-
sessionUserData->txTestFrameModifier(frame, frame->data_size);
180+
if (frameTestStrategy->enable_tx_modifier) {
181+
frameTestStrategy->txTestFrameModifier(frame, frame->data_size);
182182
}
183183

184184
st30p_tx_put_frame((st30p_tx_handle)handle, frame);
@@ -203,8 +203,8 @@ void St30pHandler::st30pRxDefaultFunction(std::atomic<bool>& stopFlag) {
203203
ASSERT_EQ(frame->ptime, sessionsOpsRx.ptime);
204204
ASSERT_EQ(frame->sampling, sessionsOpsRx.sampling);
205205

206-
if (sessionUserData->enable_rx_modifier) {
207-
sessionUserData->rxTestFrameModifier(frame, frame->data_size);
206+
if (frameTestStrategy->enable_rx_modifier) {
207+
frameTestStrategy->rxTestFrameModifier(frame, frame->data_size);
208208
}
209209

210210
st30p_rx_put_frame((st30p_rx_handle)handle, frame);

tests/integration_tests/noctx/noctx.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ void NoCtxTest::TearDown() {
5353
}
5454
st20pHandlers.clear();
5555

56-
for (auto data : sessionUserDatas) {
56+
for (auto data : frameTestStrategys) {
5757
if (data) {
5858
delete data;
5959
data = nullptr;
6060
}
6161
}
62-
sessionUserDatas.clear();
62+
frameTestStrategys.clear();
6363

6464
if (ctx) {
6565
if (ctx->handle) {
@@ -110,6 +110,46 @@ void NoCtxTest::sleepUntilFailure(int sleep_duration) {
110110
}
111111
}
112112

113+
NoCtxTest::St20pHandlerBundle NoCtxTest::createSt20pHandlerBundle(
114+
bool createTx, bool createRx,
115+
std::function<FrameTestStrategy*(St20pHandler*)> strategyFactory,
116+
std::function<void(St20pHandler*)> configure) {
117+
if (!ctx) {
118+
throw std::runtime_error("createSt20pHandlerBundle expects initialized ctx");
119+
}
120+
121+
auto handler = new St20pHandler(ctx);
122+
if (configure) {
123+
configure(handler);
124+
}
125+
126+
FrameTestStrategy* strategy = nullptr;
127+
if (strategyFactory) {
128+
strategy = strategyFactory(handler);
129+
handler->setFrameTestStrategy(strategy);
130+
}
131+
132+
if (createRx) {
133+
handler->createSessionRx();
134+
}
135+
if (createTx) {
136+
handler->createSessionTx();
137+
}
138+
139+
registerSt20pResources(handler, strategy);
140+
return {handler, strategy};
141+
}
142+
143+
void NoCtxTest::registerSt20pResources(St20pHandler* handler,
144+
FrameTestStrategy* strategy) {
145+
if (handler) {
146+
st20pHandlers.emplace_back(handler);
147+
}
148+
if (strategy) {
149+
frameTestStrategys.emplace_back(strategy);
150+
}
151+
}
152+
113153
/**
114154
* @brief Set the TX session port names, including redundant port if specified.
115155
*

0 commit comments

Comments
 (0)