Skip to content

Commit 6599840

Browse files
committed
TWCC: fix repair stats for FEC
1 parent 0bb2c14 commit 6599840

File tree

1 file changed

+36
-19
lines changed
  • subprojects/gst-plugins-good/gst/rtpmanager

1 file changed

+36
-19
lines changed

subprojects/gst-plugins-good/gst/rtpmanager/rtptwcc.c

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,6 @@ _redblock_new(GArray* seq, guint16 fec_seq,
299299
g_array_set_size (block->fec_seqs, num_redundant_packets);
300300
block->fec_states = g_array_new (FALSE, FALSE, sizeof (TWCCPktState));
301301
g_array_set_size (block->fec_states, num_redundant_packets);
302-
g_array_index (block->fec_states, TWCCPktState, idx_redundant_packets)
303-
= RTP_TWCC_FECBLOCK_PKT_UNKNOWN;
304302
for (guint16 i = 0; i < num_redundant_packets; i++)
305303
{
306304
g_array_index (block->fec_states, TWCCPktState, i)
@@ -379,6 +377,9 @@ _redblock_reconsider (RTPTWCCManager * twcc, RedBlock * block)
379377
gsize nrecovered = 0;
380378
gsize lost = 0;
381379

380+
gchar states_media[48];
381+
gchar states_fec[16];
382+
382383
/* Special case for RTX: lost RTX introduces extra complexity which
383384
is easier to handle separately
384385
*/
@@ -409,45 +410,59 @@ _redblock_reconsider (RTPTWCCManager * twcc, RedBlock * block)
409410
g_array_index (block->seqs, guint16, i));
410411
if (!pkt || pkt->state == RTP_TWCC_FECBLOCK_PKT_UNKNOWN) {
411412
unknowns = TRUE;
413+
if (i < G_N_ELEMENTS(states_media)) states_media[i] = 'U';
412414
} else if (pkt->state == RTP_TWCC_FECBLOCK_PKT_RECEIVED) {
413415
nreceived++;
416+
if (i < G_N_ELEMENTS(states_media)) states_media[i] = '+';
414417
} else if (pkt->state == RTP_TWCC_FECBLOCK_PKT_RECOVERED) {
415418
recovered = TRUE;
419+
if (i < G_N_ELEMENTS(states_media)) states_media[i] = 'R';
416420
} else if (pkt->state == RTP_TWCC_FECBLOCK_PKT_LOST) {
417421
lost++;
422+
if (i < G_N_ELEMENTS(states_media)) states_media[i] = '-';
418423
}
419424

420425
if (pkt) {
421426
pkt->update_stats = FALSE;
422427
}
423428
}
429+
states_media[block->seqs->len] = '\0';
424430

425431
/* Walk through all fec packets */
426432
for (gsize i = 0; i < block->fec_seqs->len; ++i) {
427433
if (g_array_index (block->fec_states, TWCCPktState, i)
428434
== RTP_TWCC_FECBLOCK_PKT_UNKNOWN) {
429435
unknowns = TRUE;
436+
if (i < G_N_ELEMENTS(states_fec)) states_fec[i] = 'U';
430437
continue;
431438
}
432439
SentPacket *pkt = _find_stats_sentpacket (twcc,
433440
g_array_index (block->fec_seqs, guint16, i));
434441
if (!pkt || pkt->state == RTP_TWCC_FECBLOCK_PKT_UNKNOWN) {
435442
unknowns = TRUE;
443+
if (i < G_N_ELEMENTS(states_fec)) states_fec[i] = 'U';
436444
} else if (pkt->state == RTP_TWCC_FECBLOCK_PKT_RECEIVED) {
437445
nreceived++;
446+
if (i < G_N_ELEMENTS(states_fec)) states_fec[i] = '+';
438447
} else if (pkt->state == RTP_TWCC_FECBLOCK_PKT_RECOVERED) {
439448
recovered = TRUE;
449+
if (i < G_N_ELEMENTS(states_fec)) states_fec[i] = 'R';
440450
} else if (pkt->state == RTP_TWCC_FECBLOCK_PKT_LOST) {
441451
lost++;
452+
if (i < G_N_ELEMENTS(states_fec)) states_fec[i] = '-';
442453
}
443454

444455
if (pkt) {
445456
pkt->update_stats = FALSE;
446457
}
447458
}
459+
states_fec[block->fec_seqs->len] = '\0';
460+
448461

449462
/* We have packet[s] that was not reported about in feedbacks yet */
450463
if (unknowns) {
464+
GST_INFO ("Media: %s; FEC: %s", states_media, states_fec);
465+
GST_INFO ("The FEC block has unknown packets");
451466
return 0;
452467
}
453468

@@ -479,6 +494,8 @@ _redblock_reconsider (RTPTWCCManager * twcc, RedBlock * block)
479494
}
480495
}
481496

497+
GST_INFO ("Media: %s; FEC: %s; recovered: %lu", states_media, states_fec,
498+
nrecovered);
482499
return nrecovered;
483500
}
484501

@@ -715,7 +732,7 @@ twcc_stats_ctx_calculate_windowed_stats (RTPTWCCManager * twcc, TWCCStatsCtx * c
715732
last_local_pkt = pkt;
716733
}
717734

718-
if (GST_CLOCK_TIME_IS_VALID (pkt->remote_ts)) {
735+
if (pkt->state == RTP_TWCC_FECBLOCK_PKT_RECEIVED) {
719736
/* don't count the bits for the first packet in the window */
720737
if (first_remote_pkt == NULL) {
721738
first_remote_pkt = pkt;
@@ -724,13 +741,13 @@ twcc_stats_ctx_calculate_windowed_stats (RTPTWCCManager * twcc, TWCCStatsCtx * c
724741
}
725742
last_remote_pkt = pkt;
726743
packets_recv++;
727-
} else {
728-
GST_LOG ("Packet #%u is lost, recovered=%u", pkt->seqnum,
729-
pkt->state == RTP_TWCC_FECBLOCK_PKT_RECOVERED);
744+
} else if (pkt->state == RTP_TWCC_FECBLOCK_PKT_RECOVERED) {
745+
GST_LOG ("Packet #%u is lost and recovered");
746+
packets_lost++;
747+
packets_recovered++;
748+
} else if(pkt->state == RTP_TWCC_FECBLOCK_PKT_LOST) {
749+
GST_LOG ("Packet #%u is lost");
730750
packets_lost++;
731-
if (pkt->state == RTP_TWCC_FECBLOCK_PKT_RECOVERED) {
732-
packets_recovered++;
733-
}
734751
}
735752

736753
if (!prev) {
@@ -2404,8 +2421,8 @@ rtp_twcc_manager_get_windowed_stats (RTPTWCCManager * twcc,
24042421
change them to twcc seqnums. */
24052422

24062423
GRealArray *protect_seqnums_array_real = (GRealArray*)pkt->protects_seqnums;
2407-
GST_WARNING_OBJECT (twcc, "protect_seqnums refcount: %d",
2408-
protect_seqnums_array_real->ref_count);
2424+
GST_WARNING_OBJECT (twcc, "protect_seqnums protects ssrc: %u, refcount: %d",
2425+
pkt->protects_ssrc, protect_seqnums_array_real->ref_count);
24092426

24102427
if (pkt->redundant_idx < 0 || pkt->redundant_num <= 0
24112428
|| pkt->redundant_idx >= pkt->redundant_num) {
@@ -2459,6 +2476,10 @@ rtp_twcc_manager_get_windowed_stats (RTPTWCCManager * twcc,
24592476
/* Add every data packet into seqnum_2_redblocks */
24602477
block = _redblock_new (pkt->protects_seqnums, pkt->seqnum,
24612478
pkt->redundant_idx, pkt->redundant_num);
2479+
g_array_index (block->fec_seqs, guint16, (gsize)pkt->redundant_idx)
2480+
= pkt->seqnum;
2481+
g_array_index (block->fec_states, TWCCPktState,
2482+
(gsize)pkt->redundant_idx) = pkt->state;
24622483
g_hash_table_insert (twcc->redund_2_redblocks, key, block);
24632484
/* Link this seqnum to the block in order to be able to
24642485
release the block once this packet leave its lifetime */
@@ -2483,10 +2504,8 @@ rtp_twcc_manager_get_windowed_stats (RTPTWCCManager * twcc,
24832504
}
24842505
}
24852506
const gsize packets_recovered = _redblock_reconsider (twcc, block);
2486-
if (packets_recovered > 0) {
2487-
GST_LOG ("Reconsider block because of packet #%u, recovered %lu pckt",
2488-
pkt->seqnum, packets_recovered);
2489-
}
2507+
GST_LOG ("Reconsider block because of packet #%u, recovered %lu pckt",
2508+
pkt->seqnum, packets_recovered);
24902509
/* RTX of FEC */
24912510
} else {
24922511
RedBlock * block;
@@ -2500,10 +2519,8 @@ rtp_twcc_manager_get_windowed_stats (RTPTWCCManager * twcc,
25002519
}
25012520
}
25022521
const gsize packets_recovered = _redblock_reconsider (twcc, block);
2503-
if (packets_recovered > 0) {
2504-
GST_LOG ("Reconsider block because of packet #%u, "
2505-
"recovered %lu pckt", pkt->seqnum, packets_recovered);
2506-
}
2522+
GST_LOG ("Reconsider block because of packet #%u, "
2523+
"recovered %lu pckt", pkt->seqnum, packets_recovered);
25072524
}
25082525
}
25092526
} /* for array */

0 commit comments

Comments
 (0)