Skip to content

Commit

Permalink
Reed-Solomon: add defaults for audio
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MartinPulec committed Sep 11, 2024
1 parent 5bae31f commit 215b823
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") !=
Expand Down
4 changes: 2 additions & 2 deletions src/rtp/fec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/rtp/fec.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct fec {
const std::map<int, int> &) = 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();
Expand Down
13 changes: 8 additions & 5 deletions src/rtp/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -424,7 +427,7 @@ static void usage() {
"\t" TBOLD("<n>") " - length of block + parity "
"(default " TBOLD("%d") ", max %d),\n"
"\t\t\tmust be > <k>\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. "
Expand Down
2 changes: 1 addition & 1 deletion src/rtp/rs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<video_frame> encode(std::shared_ptr<video_frame> frame) override;
virtual audio_frame2 encode(audio_frame2 const &) override;
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 @@ -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) {
Expand Down

0 comments on commit 215b823

Please sign in to comment.