From 215b823861ff61306cd17d58b1f5f7772104dd28 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 11 Sep 2024 13:11:09 +0200 Subject: [PATCH] Reed-Solomon: add defaults for audio For unsompreesed audio, where it has only the advantage, set default R-S values to k=160 n=240 (50 % redundancy). For uncompressed audio, the number of packets per frmae start at 3 (for 16-bit 30p), for which the value is appropriate. Not for the audio captured at 60 Hz, however. Here it, is 1600 B with 16-bit samples, with the R-S FEC this yields 2 packets only. --- src/audio/audio.cpp | 2 +- src/rtp/fec.cpp | 4 ++-- src/rtp/fec.h | 2 +- src/rtp/rs.cpp | 13 ++++++++----- src/rtp/rs.h | 2 +- src/video_rxtx/rtp.cpp | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index 9451f25dbf..860821f8ca 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -873,7 +873,7 @@ static struct response *audio_sender_process_message(struct state_audio *s, stru delete old_fec_state; break; } - s->fec_state = fec::create_from_config(msg->fec_cfg); + s->fec_state = fec::create_from_config(msg->fec_cfg, true); if (s->fec_state == nullptr) { s->fec_state = old_fec_state; if (strstr(msg->fec_cfg, "help") != diff --git a/src/rtp/fec.cpp b/src/rtp/fec.cpp index 0324382b82..df5878029f 100644 --- a/src/rtp/fec.cpp +++ b/src/rtp/fec.cpp @@ -59,7 +59,7 @@ using std::stof; using std::stoi; using std::string; -fec *fec::create_from_config(const char *c_str) noexcept +fec *fec::create_from_config(const char *c_str, bool is_audio) noexcept { try { if (strncmp(c_str, "LDGM percents ", strlen("LDGM percents ")) == 0) { @@ -87,7 +87,7 @@ fec *fec::create_from_config(const char *c_str) noexcept return new ldgm(c_str + strlen("LDGM cfg ")); } if (strncmp(c_str, "RS cfg ", strlen("RS cfg ")) == 0) { - return new rs(c_str + strlen("rs cfg ")); + return new rs(c_str + strlen("rs cfg "), is_audio); } throw ug_runtime_error("Unrecognized FEC configuration!"); } catch (string const &s) { diff --git a/src/rtp/fec.h b/src/rtp/fec.h index f8b813ab49..97780f49ca 100644 --- a/src/rtp/fec.h +++ b/src/rtp/fec.h @@ -64,7 +64,7 @@ struct fec { const std::map &) = 0; virtual ~fec() {} - static fec *create_from_config(const char *str) noexcept; + static fec *create_from_config(const char *str, bool is_audio) noexcept; static fec *create_from_desc(struct fec_desc) noexcept; static int pt_from_fec_type(enum tx_media_type media_type, enum fec_type fec_type, bool encrypted) throw(); static enum fec_type fec_type_from_pt(int pt) throw(); diff --git a/src/rtp/rs.cpp b/src/rtp/rs.cpp index c01984aaa4..0c7a9b94d5 100644 --- a/src/rtp/rs.cpp +++ b/src/rtp/rs.cpp @@ -51,8 +51,11 @@ #include "utils/text.h" #include "video.h" -#define DEFAULT_K 200 -#define DEFAULT_N 240 +enum { + DEFAULT_K_AUDIO = 160, + DEFAULT_K_VIDEO = 200, + DEFAULT_N = 240, +}; #define MAX_K 255 #define MAX_N 255 @@ -90,7 +93,7 @@ rs::rs(unsigned int k, unsigned int n) #endif } -rs::rs(const char *c_cfg) +rs::rs(const char *c_cfg, bool is_audio) { if (strcmp(c_cfg, "help") == 0) { usage(); @@ -105,7 +108,7 @@ rs::rs(const char *c_cfg) assert(item != NULL); m_n = atoi(item); } else { - m_k = DEFAULT_K; + m_k = is_audio ? DEFAULT_K_AUDIO : DEFAULT_K_VIDEO; m_n = DEFAULT_N; } free(cfg); @@ -424,7 +427,7 @@ static void usage() { "\t" TBOLD("") " - length of block + parity " "(default " TBOLD("%d") ", max %d),\n" "\t\t\tmust be > \n\n", - DEFAULT_K, MAX_K, DEFAULT_N, MAX_N); + DEFAULT_K_VIDEO, MAX_K, DEFAULT_N, MAX_N); char desc[] = "The n/k ratio determines the redundancy that the FEC provides. " diff --git a/src/rtp/rs.h b/src/rtp/rs.h index ac9c369228..3f93eba033 100644 --- a/src/rtp/rs.h +++ b/src/rtp/rs.h @@ -48,7 +48,7 @@ struct video_frame; struct rs : public fec { rs(unsigned int k, unsigned int n); - rs(const char *cfg); + rs(const char *cfg, bool is_audio); virtual ~rs(); std::shared_ptr encode(std::shared_ptr frame) override; virtual audio_frame2 encode(audio_frame2 const &) override; diff --git a/src/video_rxtx/rtp.cpp b/src/video_rxtx/rtp.cpp index 52d0a00694..98d99aa45e 100644 --- a/src/video_rxtx/rtp.cpp +++ b/src/video_rxtx/rtp.cpp @@ -129,7 +129,7 @@ rtp_video_rxtx::process_sender_message(struct msg_sender *msg) delete old_fec_state; break; } - m_fec_state = fec::create_from_config(msg->fec_cfg); + m_fec_state = fec::create_from_config(msg->fec_cfg, false); if (m_fec_state == nullptr) { int rc = 0; if (strstr(msg->fec_cfg, "help") == nullptr) {