Merge pull request #2113 from dragos-oancea/more_opus

[Core, mod_opus] Fixes.
This commit is contained in:
Andrey Volk 2023-06-15 20:48:11 +03:00 committed by GitHub
commit 7f62d6168d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 6 deletions

View File

@ -676,8 +676,14 @@ struct switch_codec_fmtp {
int bits_per_second; int bits_per_second;
/*! number of microseconds of media in one packet (ptime * 1000) */ /*! number of microseconds of media in one packet (ptime * 1000) */
int microseconds_per_packet; int microseconds_per_packet;
/*! stereo */ /*! maximum ptime in ms */
int stereo; int max_ptime;
/*! minimum ptime in ms */
int min_ptime;
/*! stereo, typically bidirectional */
int stereo;
/* sender properties (stereo) */
int sprop_stereo;
/*! private data for the codec module to store handle specific info */ /*! private data for the codec module to store handle specific info */
void *private_info; void *private_info;

View File

@ -273,10 +273,12 @@ static switch_status_t switch_opus_fmtp_parse(const char *fmtp, switch_codec_fmt
if (!strcasecmp(data, "maxptime")) { if (!strcasecmp(data, "maxptime")) {
codec_settings->maxptime = atoi(arg); codec_settings->maxptime = atoi(arg);
codec_fmtp->max_ptime = codec_settings->maxptime;
} }
if (!strcasecmp(data, "minptime")) { if (!strcasecmp(data, "minptime")) {
codec_settings->minptime = atoi(arg); codec_settings->minptime = atoi(arg);
codec_fmtp->min_ptime = codec_settings->minptime;
} }
if (!strcasecmp(data, "ptime")) { if (!strcasecmp(data, "ptime")) {
@ -291,6 +293,7 @@ static switch_status_t switch_opus_fmtp_parse(const char *fmtp, switch_codec_fmt
if (!strcasecmp(data, "sprop-stereo")) { if (!strcasecmp(data, "sprop-stereo")) {
codec_settings->sprop_stereo = atoi(arg); codec_settings->sprop_stereo = atoi(arg);
codec_fmtp->sprop_stereo = codec_settings->sprop_stereo;
} }
if (!strcasecmp(data, "maxaveragebitrate")) { if (!strcasecmp(data, "maxaveragebitrate")) {
@ -311,6 +314,10 @@ static switch_status_t switch_opus_fmtp_parse(const char *fmtp, switch_codec_fmt
if (!switch_opus_acceptable_rate(codec_settings->sprop_maxcapturerate)) { if (!switch_opus_acceptable_rate(codec_settings->sprop_maxcapturerate)) {
codec_settings->sprop_maxcapturerate = 0; /* value not supported */ codec_settings->sprop_maxcapturerate = 0; /* value not supported */
} }
if (codec_settings->sprop_maxcapturerate) {
codec_fmtp->actual_samples_per_second = codec_settings->sprop_maxcapturerate;
}
} }
} }
} }
@ -1342,7 +1349,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opus_load)
{ {
switch_codec_interface_t *codec_interface; switch_codec_interface_t *codec_interface;
switch_api_interface_t *commands_api_interface; switch_api_interface_t *commands_api_interface;
int samples = 480; int samples = 480; /* start with 10 ms ptime */
int bytes = 960; int bytes = 960;
int mss = 10000; int mss = 10000;
int x = 0; int x = 0;
@ -1443,7 +1450,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opus_load)
} }
/* 16 khz */ /* 16 khz */
samples = 480; samples = 160;
bytes = 320; bytes = 320;
mss = 10000; mss = 10000;
rate = 16000; rate = 16000;
@ -1540,7 +1547,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opus_load)
} }
/* 8 khz */ /* 8 khz */
samples = 480; samples = 80;
bytes = 160; bytes = 160;
mss = 10000; mss = 10000;
rate = 8000; rate = 8000;

View File

@ -5497,6 +5497,10 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s
} else if (!strcasecmp(map->rm_encoding, "opus")) { } else if (!strcasecmp(map->rm_encoding, "opus")) {
map_channels = 1; map_channels = 1;
} }
if (codec_fmtp.max_ptime) {
maxptime = codec_fmtp.max_ptime;
}
} }
} }
@ -8724,7 +8728,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi
a_engine->cur_payload_map->remote_sdp_ip, a_engine->cur_payload_map->remote_sdp_ip,
a_engine->cur_payload_map->remote_sdp_port, a_engine->cur_payload_map->remote_sdp_port,
a_engine->cur_payload_map->pt, a_engine->cur_payload_map->pt,
a_engine->read_impl.samples_per_packet, strcasecmp("opus", a_engine->read_impl.iananame) ? a_engine->read_impl.samples_per_packet :
a_engine->read_impl.samples_per_second * (a_engine->read_impl.microseconds_per_packet / 1000) / 1000,
a_engine->cur_payload_map->codec_ms * 1000, a_engine->cur_payload_map->codec_ms * 1000,
flags, timer_name, &err, switch_core_session_get_pool(session), flags, timer_name, &err, switch_core_session_get_pool(session),
0, 0); 0, 0);