char *codec_order[SWITCH_MAX_CODECS];
int codec_order_last;
const switch_codec_implementation_t *codecs[SWITCH_MAX_CODECS];
-
+ char fmtp[SWITCH_MAX_CODECS][MAX_FMTP_LEN];
int payload_space;
char *origin;
switch_media_type_t type,
const char *iananame,
uint32_t rate,
+ const char *fmtp_in,
switch_payload_t *ptP,
switch_payload_t *recv_ptP,
char **fmtpP)
switch_mutex_lock(smh->sdp_mutex);
for (pmap = engine->payload_map; pmap ; pmap = pmap->next) {
+ char *fmtp_a = pmap->rm_fmtp;
if (!pmap->allocated) continue;
- if (!strcasecmp(pmap->iananame, iananame) && (!rate || (rate == pmap->rate))) {
+ if (!fmtp_a) fmtp_a = "";
+ if (!fmtp_in) fmtp_in = "";
+
+
+ if (!strcasecmp(pmap->iananame, iananame) && !strcasecmp(fmtp_a, fmtp_in) && (!rate || (rate == pmap->rate))) {
pt = pmap->pt;
recv_pt = pmap->recv_pt;
fmtp = pmap->rm_fmtp;
tmp_codec_string = switch_core_session_strdup(smh->session, codec_string);
switch_channel_set_variable(session->channel, "rtp_use_codec_string", codec_string);
smh->codec_order_last = switch_separate_string(tmp_codec_string, ',', smh->codec_order, SWITCH_MAX_CODECS);
- smh->mparams->num_codecs = switch_loadable_module_get_codecs_sorted(smh->codecs, SWITCH_MAX_CODECS, smh->codec_order, smh->codec_order_last);
+ smh->mparams->num_codecs = switch_loadable_module_get_codecs_sorted(smh->codecs, smh->fmtp, SWITCH_MAX_CODECS, smh->codec_order, smh->codec_order_last);
}
const char *tmp;
int m_idx = 0;
int nm_idx = 0;
+ int vmatch_pt = 0;
switch_assert(session);
const switch_codec_implementation_t *search[1];
char *prefs[1];
char tmp[80];
+ char fmtp[SWITCH_MAX_CODECS][MAX_FMTP_LEN];
int num;
const switch_codec_implementation_t *timp = NULL;
codec_ms, near_match->number_of_channels);
prefs[0] = tmp;
- num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1);
+ num = switch_loadable_module_get_codecs_sorted(search, fmtp, 1, prefs, 1);
if (num) {
timp = search[0];
}
}
+ if (switch_true(switch_channel_get_variable_dup(session->channel, "inherit_codec", SWITCH_FALSE, -1))) {
+ vmatch_pt = 1;
+ }
+
+ compare:
for (map = m->m_rtpmaps; map; map = map->rm_next) {
}
}
-
+
if (!(rm_encoding = map->rm_encoding)) {
rm_encoding = "";
}
-
+
for (i = 0; i < total_codecs; i++) {
const switch_codec_implementation_t *imp = codec_array[i];
- if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
+ if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
continue;
}
switch_channel_test_flag(session->channel, CF_NOVIDEO)) {
continue;
}
-
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Video Codec Compare [%s:%d]/[%s:%d]\n",
+
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CONSOLE, "Video Codec Compare [%s:%d]/[%s:%d]\n",
rm_encoding, map->rm_pt, imp->iananame, imp->ianacode);
if ((zstr(map->rm_encoding) || (smh->mparams->ndlb & SM_NDLB_ALLOW_BAD_IANANAME)) && map->rm_pt < 96) {
vmatch = (map->rm_pt == imp->ianacode) ? 1 : 0;
vmatch = strcasecmp(rm_encoding, imp->iananame) ? 0 : 1;
}
- if (vmatch && (map->rm_rate == imp->samples_per_second)) {
+ if (vmatch && vmatch_pt) {
+ const char *other_pt = switch_channel_get_variable_partner(channel, "rtp_video_pt");
+ const char *other_fmtp = switch_channel_get_variable_partner(channel, "rtp_video_fmtp");
+
+ const char *foo = switch_channel_get_partner_uuid(channel);
+
+ if (other_pt) {
+ int opt = atoi(other_pt);
+
+ if (map->rm_pt != opt) {
+ vmatch = 0;
+ }
+ }
+ }
+
+ if (vmatch) {
matches[m_idx].imp = imp;
matches[m_idx].map = map;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Video Codec Compare [%s:%d] +++ is saved as a match\n",
- imp->iananame, imp->ianacode);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CONSOLE, "Video Codec Compare [%s:%d] +++ is saved as a match\n",
+ imp->iananame, map->rm_pt);
m_idx++;
}
}
}
+ if (vmatch_pt && !m_idx) {
+ vmatch_pt = 0;
+ goto compare;
+ }
+
if (smh->crypto_mode == CRYPTO_MODE_MANDATORY && got_video_crypto < 1) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Crypto not negotiated but required.\n");
vmatch = 0;
#endif
}
-
-
switch_snprintf(tmp, sizeof(tmp), "%d", v_engine->cur_payload_map->remote_sdp_port);
switch_channel_set_variable(session->channel, SWITCH_REMOTE_VIDEO_IP_VARIABLE, v_engine->cur_payload_map->remote_sdp_ip);
switch_channel_set_variable(session->channel, SWITCH_REMOTE_VIDEO_PORT_VARIABLE, tmp);
fmtp = smh->fmtps[i];
}
+
if (smh->ianacodes[i] > 95 || switch_channel_test_flag(session->channel, CF_VERBOSE_SDP)) {
int channels = get_channels(imp->iananame, imp->number_of_channels);
switch_payload_t orig_pt = 0;
char *orig_fmtp = NULL;
- //smh->ianacodes[i] = imp->ianacode;
-
if (smh->ianacodes[i] > 64) {
if (smh->mparams->dtmf_type == DTMF_2833 && smh->mparams->te > 95 && smh->mparams->te == smh->payload_space) {
smh->payload_space++;
if (orig_session &&
switch_core_session_get_payload_code(orig_session,
imp->codec_type == SWITCH_CODEC_TYPE_AUDIO ? SWITCH_MEDIA_TYPE_AUDIO : SWITCH_MEDIA_TYPE_VIDEO,
- imp->iananame, imp->samples_per_second, &orig_pt, NULL, &orig_fmtp) == SWITCH_STATUS_SUCCESS) {
+ imp->iananame, imp->samples_per_second, smh->fmtp[i], &orig_pt, NULL, &orig_fmtp) == SWITCH_STATUS_SUCCESS) {
+
if (orig_pt == smh->mparams->te) {
smh->mparams->te = (switch_payload_t)smh->payload_space++;
}
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "\r\n");
-
if (v_engine->codec_negotiated) {
const char *of;
payload_map_t *pmap;
v_engine->cur_payload_map->pt, v_engine->cur_payload_map->rm_encoding,
v_engine->cur_payload_map->rm_rate);
-
if (switch_channel_test_flag(session->channel, CF_RECOVERING)) {
pass_fmtp = v_engine->cur_payload_map->rm_fmtp;
} else {
if (ov_fmtp) {
pass_fmtp = ov_fmtp;
- } else if (switch_true(switch_channel_get_variable_dup(session->channel, "rtp_mirror_fmtp", SWITCH_FALSE, -1))) {
- pass_fmtp = switch_channel_get_variable(session->channel, "rtp_video_fmtp");
+ } else {
+
+ pass_fmtp = v_engine->cur_payload_map->fmtp_out;
+
+ if (!pass_fmtp || switch_true(switch_channel_get_variable_dup(session->channel, "rtp_mirror_fmtp", SWITCH_FALSE, -1))) {
+ pass_fmtp = switch_channel_get_variable(session->channel, "rtp_video_fmtp");
+ }
}
}
-
+
if (pass_fmtp) {
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=fmtp:%d %s\r\n", v_engine->cur_payload_map->pt, pass_fmtp);
}
if (pmap->pt != v_engine->cur_payload_map->pt && pmap->negotiated) {
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d %s/%ld\r\n",
pmap->pt, pmap->iananame, pmap->rate);
-
}
}
switch_mutex_unlock(smh->sdp_mutex);
if (append_video) {
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "%s%s", append_video, end_of(append_video) == '\n' ? "" : "\r\n");
}
-
+
if (v_engine->smode == SWITCH_MEDIA_FLOW_SENDONLY) {
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "%s", "a=sendonly\r\n");
} else if (v_engine->smode == SWITCH_MEDIA_FLOW_RECVONLY) {
imp->samples_per_second);
}
+
+
if (!zstr(ov_fmtp)) {
fmtp = (char *) ov_fmtp;
} else {
fmtp = switch_event_get_header(map, imp->iananame);
}
- if (smh->fmtps[i]) {
+ if (!zstr(smh->fmtp[i])) {
+ fmtp = smh->fmtp[i];
+ } else if (smh->fmtps[i]) {
fmtp = smh->fmtps[i];
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Setting NULL SDP is invalid\n");
return;
}
-
if ((parser = sdp_parse(NULL, r_sdp, (int) strlen(r_sdp), 0))) {
if ((sdp = sdp_session(parser))) {
int num_codecs = 0;
char *codec_order[SWITCH_MAX_CODECS];
const switch_codec_implementation_t *codecs[SWITCH_MAX_CODECS] = { 0 };
+ char fmtp[SWITCH_MAX_CODECS][MAX_FMTP_LEN];
+
switch_channel_t *channel = switch_core_session_get_channel(session);
int prefer_sdp = 0;
const char *var;
char *tmp_codec_string;
if ((tmp_codec_string = strdup(codec_string))) {
num_codecs = switch_separate_string(tmp_codec_string, ',', codec_order, SWITCH_MAX_CODECS);
- num_codecs = switch_loadable_module_get_codecs_sorted(codecs, SWITCH_MAX_CODECS, codec_order, num_codecs);
+ num_codecs = switch_loadable_module_get_codecs_sorted(codecs, fmtp, SWITCH_MAX_CODECS, codec_order, num_codecs);
switch_safe_free(tmp_codec_string);
}
} else {
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND || prefer_sdp) {
for (map = m->m_rtpmaps; map; map = map->rm_next) {
+ match = 0;
+
if (map->rm_pt > 127 || already_did[map->rm_pt]) {
continue;
}
if (match) {
add_audio_codec(map, imp, ptime, buf, sizeof(buf));
- break;
}
}
continue;
}
for (map = m->m_rtpmaps; map; map = map->rm_next) {
+ match = 0;
+
if (map->rm_pt > 127 || already_did[map->rm_pt]) {
continue;
}
if (match) {
add_audio_codec(map, imp, ptime, buf, sizeof(buf));
- break;
}
}
}
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_ERROR, "Cannot find a c= line in the sdp at media or session level!\n");
break;
}
- for (i = 0; i < num_codecs; i++) {
- const switch_codec_implementation_t *imp = codecs[i];
- if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO || imp->ianacode > 127 || already_did[imp->ianacode]) {
- continue;
- }
-
- if (switch_channel_direction(session->channel) == SWITCH_CALL_DIRECTION_INBOUND &&
- switch_channel_test_flag(session->channel, CF_NOVIDEO)) {
- continue;
- }
+ if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND || prefer_sdp) {
for (map = m->m_rtpmaps; map; map = map->rm_next) {
+ match = 0;
+
if (map->rm_pt > 127 || already_did[map->rm_pt]) {
continue;
}
- if ((zstr(map->rm_encoding) || (smh->mparams->ndlb & SM_NDLB_ALLOW_BAD_IANANAME)) && map->rm_pt < 96) {
- match = (map->rm_pt == imp->ianacode) ? 1 : 0;
- } else {
- if (map->rm_encoding) {
- match = !strcasecmp(map->rm_encoding, imp->iananame) &&
- ((map->rm_pt < 96 && imp->ianacode < 96) || (map->rm_pt > 95 && imp->ianacode > 95));
+ for (i = 0; i < num_codecs; i++) {
+ const switch_codec_implementation_t *imp = codecs[i];
+
+ if ((zstr(map->rm_encoding) || (smh->mparams->ndlb & SM_NDLB_ALLOW_BAD_IANANAME)) && map->rm_pt < 96) {
+ match = (map->rm_pt == imp->ianacode) ? 1 : 0;
} else {
- match = 0;
+ if (map->rm_encoding) {
+ match = !strcasecmp(map->rm_encoding, imp->iananame) &&
+ ((map->rm_pt < 96 && imp->ianacode < 96) || (map->rm_pt > 95 && imp->ianacode > 95));
+ } else {
+ match = 0;
+ }
+ }
+
+ if (match) {
+ if (map->rm_fmtp) {
+ switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s.%s~%s", imp->modname, imp->iananame, map->rm_fmtp);
+ } else {
+ switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s.%s", imp->modname, imp->iananame);
+ }
+ already_did[imp->ianacode] = 1;
}
}
+ }
- if (match) {
- switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s.%s", imp->modname, imp->iananame);
- already_did[imp->ianacode] = 1;
- break;
+ } else {
+ for (i = 0; i < num_codecs; i++) {
+ const switch_codec_implementation_t *imp = codecs[i];
+
+ if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO || imp->ianacode > 127 || already_did[imp->ianacode]) {
+ continue;
+ }
+
+ if (switch_channel_direction(session->channel) == SWITCH_CALL_DIRECTION_INBOUND &&
+ switch_channel_test_flag(session->channel, CF_NOVIDEO)) {
+ continue;
+ }
+
+ for (map = m->m_rtpmaps; map; map = map->rm_next) {
+ match = 0;
+
+ if (map->rm_pt > 127 || already_did[map->rm_pt]) {
+ continue;
+ }
+
+ if ((zstr(map->rm_encoding) || (smh->mparams->ndlb & SM_NDLB_ALLOW_BAD_IANANAME)) && map->rm_pt < 96) {
+ match = (map->rm_pt == imp->ianacode) ? 1 : 0;
+ } else {
+ if (map->rm_encoding) {
+ match = !strcasecmp(map->rm_encoding, imp->iananame) &&
+ ((map->rm_pt < 96 && imp->ianacode < 96) || (map->rm_pt > 95 && imp->ianacode > 95));
+ } else {
+ match = 0;
+ }
+ }
+
+ if (match) {
+ if (map->rm_fmtp) {
+ switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s.%s~%s", imp->modname, imp->iananame, map->rm_fmtp);
+ } else {
+ switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s.%s", imp->modname, imp->iananame);
+ }
+ already_did[imp->ianacode] = 1;
+ }
}
}
}
}
}
+
if (buf[0] == ',') {
switch_channel_set_variable(channel, "ep_codec_string", buf + 1);
}
if ((tmp = switch_channel_get_variable(session->channel, "rtp_use_codec_string"))) {
char *tmp_codec_string = switch_core_session_strdup(smh->session, tmp);
smh->codec_order_last = switch_separate_string(tmp_codec_string, ',', smh->codec_order, SWITCH_MAX_CODECS);
- smh->mparams->num_codecs = switch_loadable_module_get_codecs_sorted(smh->codecs, SWITCH_MAX_CODECS, smh->codec_order, smh->codec_order_last);
+ smh->mparams->num_codecs = switch_loadable_module_get_codecs_sorted(smh->codecs, smh->fmtp, SWITCH_MAX_CODECS, smh->codec_order, smh->codec_order_last);
}
if ((tmp = switch_channel_get_variable(session->channel, "rtp_2833_send_payload"))) {
}
-SWITCH_DECLARE(char *) switch_parse_codec_buf(char *buf, uint32_t *interval, uint32_t *rate, uint32_t *bit, uint32_t *channels, char **modname)
+SWITCH_DECLARE(char *) switch_parse_codec_buf(char *buf, uint32_t *interval, uint32_t *rate, uint32_t *bit, uint32_t *channels, char **modname, char **fmtp)
{
char *cur, *next = NULL, *name, *p;
name = p;
}
+ if ((p = strchr(name, '~'))) {
+ *p++ = '\0';
+ if (fmtp) {
+ *fmtp = p;
+ }
+ }
+
return name;
}
-SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_implementation_t **array, int arraylen, char **prefs, int preflen)
+SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_implementation_t **array, char fmtp_array[SWITCH_MAX_CODECS][MAX_FMTP_LEN], int arraylen, char **prefs, int preflen)
{
int x, i = 0, j = 0;
switch_codec_interface_t *codec_interface;
switch_mutex_lock(loadable_modules.mutex);
for (x = 0; x < preflen; x++) {
- char *name, buf[256], jbuf[256], *modname = NULL;
+ char *name, buf[256], jbuf[256], *modname = NULL, *fmtp = NULL;
uint32_t interval = 0, rate = 0, bit = 0, channels = 1;
switch_copy_string(buf, prefs[x], sizeof(buf));
- name = switch_parse_codec_buf(buf, &interval, &rate, &bit, &channels, &modname);
+ name = switch_parse_codec_buf(buf, &interval, &rate, &bit, &channels, &modname, &fmtp);
for(j = 0; j < x; j++) {
- char *jname, *jmodname = NULL;
+ char *jname, *jmodname = NULL, *jfmtp = NULL;
uint32_t jinterval = 0, jrate = 0, jbit = 0, jchannels = 1;
uint32_t ointerval = interval, orate = rate, ochannels = channels;
}
switch_copy_string(jbuf, prefs[j], sizeof(jbuf));
- jname = switch_parse_codec_buf(jbuf, &jinterval, &jrate, &jbit, &jchannels, &jmodname);
+ jname = switch_parse_codec_buf(jbuf, &jinterval, &jrate, &jbit, &jchannels, &jmodname, &jfmtp);
if (jinterval == 0) {
jinterval = switch_default_ptime(jname, 0);
jchannels = 1;
}
- if (!strcasecmp(name, jname) && ointerval == jinterval && orate == jrate && ochannels == jchannels) {
+ if (!strcasecmp(name, jname) && ointerval == jinterval && orate == jrate && ochannels == jchannels &&
+ !strcasecmp(switch_str_nil(fmtp), switch_str_nil(jfmtp))) {
goto next_x;
}
}
}
}
-
+ if (!zstr(fmtp)) {
+ switch_set_string(fmtp_array[i], fmtp);
+ }
array[i++] = imp;
goto found;