Skip to content

Commit

Permalink
pbuf stats: print media type instead of SSRC
Browse files Browse the repository at this point in the history
refers to GH-417
  • Loading branch information
MartinPulec committed Oct 16, 2024
1 parent 30bceeb commit 5306ea4
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ int audio_init(struct state_audio **ret,

assert(opt->host != nullptr);
tmp = strdup(opt->host);
s->audio_participants = pdb_init(&audio_offset);
s->audio_participants = pdb_init("audio", &audio_offset);
addr = strtok_r(tmp, ",", &unused);
assert(addr != nullptr);

Expand Down
13 changes: 9 additions & 4 deletions src/pdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "debug.h"
#include "tfrc.h"
#include "pdb.h"
#include "utils/macros.h" // for IF_NOT_NULL_ELSE, STR_LEN

#define PDB_MAGIC 0x10101010
#define PDB_NODE_MAGIC 0x01010101
Expand All @@ -87,6 +88,7 @@ struct pdb {
uint32_t magic;
int count;
volatile int *delay_ms;
char stream_identifier[STR_LEN];
};

/*****************************************************************************/
Expand Down Expand Up @@ -242,14 +244,16 @@ static pdb_node_t *pdb_delete_node(struct pdb *tree, pdb_node_t * z)

/*****************************************************************************/

struct pdb *pdb_init(volatile int *delay_ms)
struct pdb *pdb_init(const char *stream_id, volatile int *delay_ms)
{
struct pdb *db = malloc(sizeof(struct pdb));
if (db != NULL) {
db->magic = PDB_MAGIC;
db->count = 0;
db->root = NULL;
db->delay_ms = delay_ms;
snprintf_ch(db->stream_identifier, "%s",
IF_NOT_NULL_ELSE(stream_id, "unknown"));
}
return db;
}
Expand All @@ -275,7 +279,8 @@ void pdb_destroy(struct pdb **db_p)
*db_p = NULL;
}

static struct pdb_e *pdb_create_item(uint32_t ssrc, volatile int *delay_ms)
static struct pdb_e *
pdb_create_item(uint32_t ssrc, const char *stream_id, volatile int *delay_ms)
{
struct pdb_e *p = malloc(sizeof(struct pdb_e));
if (p != NULL) {
Expand All @@ -291,7 +296,7 @@ static struct pdb_e *pdb_create_item(uint32_t ssrc, volatile int *delay_ms)
p->decoder_state = NULL;
p->decoder_state_deleter = NULL;
p->pt = 255;
p->playout_buffer = pbuf_init(delay_ms);
p->playout_buffer = pbuf_init(stream_id ,delay_ms);
p->tfrc_state = tfrc_init(p->creation_time);
}
return p;
Expand All @@ -312,7 +317,7 @@ int pdb_add(struct pdb *db, uint32_t ssrc)
return 1;
}

i = pdb_create_item(ssrc, db->delay_ms);
i = pdb_create_item(ssrc, db->stream_identifier, db->delay_ms);
if (i == NULL) {
debug_msg("Unable to create database entry - ssrc %x\n", ssrc);
return 2;
Expand Down
4 changes: 2 additions & 2 deletions src/pdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Ian Wesley-Smith <[email protected]>
*
* Copyright (c) 2002 University of Southern California
* Copyright (c) 2005-2010 CESNET z.s.p.o.
* Copyright (c) 2005-2024 CESNET
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted provided that the following conditions
Expand Down Expand Up @@ -98,7 +98,7 @@ struct pdb; /* The participant database */
* @param delay_ms delay to be added to playback. Main reason is to give user a possibility to
* sync audio and video.
*/
struct pdb *pdb_init(volatile int *delay_ms);
struct pdb *pdb_init(const char *stream_id, volatile int *delay_ms);
void pdb_destroy(struct pdb **db);
int pdb_add(struct pdb *db, uint32_t ssrc);
struct pdb_e *pdb_get(struct pdb *db, uint32_t ssrc);
Expand Down
23 changes: 19 additions & 4 deletions src/rtp/pbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ struct pbuf {
int out_of_order_pkts;
int max_out_of_order_dist;
int dups; // duplicite packets
char stream_identifier[STR_LEN];
};

static void free_cdata(struct coded_data *head);
Expand Down Expand Up @@ -174,7 +175,8 @@ static void pbuf_validate(struct pbuf *playout_buf)
#endif
}

struct pbuf *pbuf_init(volatile int *delay_ms)
struct pbuf *
pbuf_init(const char *stream_id, volatile int *delay_ms)
{
struct pbuf *playout_buf = NULL;

Expand All @@ -189,6 +191,7 @@ struct pbuf *pbuf_init(volatile int *delay_ms)
playout_buf->playout_delay_us = 0.032 * 1000 * 1000;
playout_buf->last_report_seq = -1;
playout_buf->stats_interval = DEFAULT_STATS_INTERVAL;
snprintf_ch(playout_buf->stream_identifier, "%s", stream_id);
} else {
debug_msg("Failed to allocate memory for playout buffer\n");
}
Expand Down Expand Up @@ -400,9 +403,21 @@ static inline void pbuf_process_stats(struct pbuf *playout_buf, rtp_packet * pkt
if (playout_buf->dups > 0) {
snprintf(oo_dups_str + strlen(oo_dups_str), sizeof oo_dups_str - strlen(oo_dups_str), ", %d dups", playout_buf->dups);
}
log_msg(LOG_LEVEL_INFO, "SSRC 0x%08" PRIx32 ": %d/%d packets received (%s%.4f%%" TERM_FG_RESET "), %d lost, max loss %d%s\n",
pkt->ssrc, playout_buf->received_pkts, playout_buf->expected_pkts, (recv_pct < 100.0 ? TERM_FG_RED : ""), recv_pct,
playout_buf->expected_pkts - playout_buf->received_pkts, playout_buf->longest_gap, oo_dups_str);

char ssrc_str[STR_LEN];
if (log_level >= LOG_LEVEL_VERBOSE) {
snprintf_ch(ssrc_str, " SSRC 0x%08" PRIx32, pkt->ssrc);
} else {
ssrc_str[0] = '\0';
}
MSG(INFO,
"[%s]%s %d/%d packets received (%s%.4f%%" TERM_FG_RESET
"), %d lost, max loss %d%s\n",
playout_buf->stream_identifier, ssrc_str, playout_buf->received_pkts,
playout_buf->expected_pkts,
(recv_pct < 100.0 ? TERM_FG_RED : ""), recv_pct,
playout_buf->expected_pkts - playout_buf->received_pkts,
playout_buf->longest_gap, oo_dups_str);

if (playout_buf->max_out_of_order_dist >= playout_buf->stats_interval) {
size_t new_val = (playout_buf->max_out_of_order_dist + STAT_INT_MIN_DIVISOR - 1) / STAT_INT_MIN_DIVISOR * STAT_INT_MIN_DIVISOR;
Expand Down
4 changes: 2 additions & 2 deletions src/rtp/pbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Ian Wesley-Smith <[email protected]>
*
* Copyright (c) 2003-2004 University of Southern California
* Copyright (c) 2005-2021 CESNET z.s.p.o.
* Copyright (c) 2005-2024 CESNET
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted provided that the following conditions
Expand Down Expand Up @@ -120,7 +120,7 @@ typedef int decode_frame_t(struct coded_data *cdata, void *decode_data, struct p
/*
* External interface:
*/
struct pbuf *pbuf_init(volatile int *delay_ms);
struct pbuf *pbuf_init(const char *stream_id, volatile int *delay_ms);
void pbuf_destroy(struct pbuf *);
void pbuf_insert(struct pbuf *playout_buf, rtp_packet *r);
int pbuf_is_empty(struct pbuf *playout_buf);
Expand Down
2 changes: 1 addition & 1 deletion src/video_capture/rtsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ vidcap_rtsp_init(struct vidcap_params *params, void **state) {
s->vrtsp_state.mcast_if = NULL;
s->vrtsp_state.required_connections = 1;

s->vrtsp_state.participants = pdb_init(0);
s->vrtsp_state.participants = pdb_init("rtsp", 0);

s->vrtsp_state.decode_data.offset_len = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/video_rxtx/rtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ rtp_video_rxtx::process_sender_message(struct msg_sender *msg)
rtp_video_rxtx::rtp_video_rxtx(map<string, param_u> const &params) :
video_rxtx(params), m_fec_state(NULL), m_video_desc{}
{
m_participants = pdb_init(&video_offset);
m_participants = pdb_init("video", &video_offset);
m_requested_receiver = params.at("receiver").str;
m_recv_port_number = params.at("rx_port").i;
m_send_port_number = params.at("tx_port").i;
Expand Down

0 comments on commit 5306ea4

Please sign in to comment.