Osmo-CC: Add telephone-event selection to helper

pull/1/head
Andreas Eversberg 2 years ago
parent 91979b7ad4
commit e470138657
  1. 50
      src/libosmocc/helper.c

@ -56,10 +56,10 @@ const char *osmo_cc_helper_audio_accept(void *priv, struct osmo_cc_helper_audio_
{
char offer_sdp[65536];
const char *accept_sdp;
osmo_cc_session_media_t *media, *selected_media = NULL;
osmo_cc_session_codec_t *codec, *selected_codec = NULL;
osmo_cc_session_media_t *media, *selected_media;
osmo_cc_session_codec_t *codec, *selected_codec, *telephone_event;
int rc;
int i, selected_i;
int i, selected_codec_i, telephone_event_i;
if (*session_p) {
PDEBUG(DCC, DEBUG_ERROR, "Session already set, please fix!\n");
@ -83,33 +83,53 @@ const char *osmo_cc_helper_audio_accept(void *priv, struct osmo_cc_helper_audio_
return NULL;
}
selected_i = -1;
selected_media = NULL;
osmo_cc_session_for_each_media((*session_p)->media_list, media) {
/* only audio */
if (media->description.type != osmo_cc_session_media_type_audio)
continue;
selected_codec_i = -1;
selected_codec = NULL;
telephone_event_i = -1;
telephone_event = NULL;
osmo_cc_session_for_each_codec(media->codec_list, codec) {
for (i = 0; codecs[i].payload_name; i++) {
if (osmo_cc_session_if_codec(codec, codecs[i].payload_name, codecs[i].payload_rate, codecs[i].payload_channels)) {
/* select the first matchting codec or the one we prefer */
if (selected_i < 0 || i < selected_i) {
selected_codec = codec;
selected_media = media;
selected_i = i;
if (!!strcasecmp(codec->payload_name, "telephone-event")) {
for (i = 0; codecs[i].payload_name; i++) {
if (osmo_cc_session_if_codec(codec, codecs[i].payload_name, codecs[i].payload_rate, codecs[i].payload_channels)) {
/* select the first matchting codec or the one we prefer */
if (selected_codec_i < 0 || i < selected_codec_i) {
selected_codec = codec;
selected_codec_i = i;
selected_media = media;
}
/* if we don't force our preferred codec, use the preferred one from the remote */
if (!force_our_codec)
break;
}
/* if we don't force our preferred codec, use the preferred one from the remote */
if (!force_our_codec)
break;
}
} else {
/* special case: add telephone-event, if supported */
for (i = 0; codecs[i].payload_name; i++) {
if (!!strcasecmp(codecs[i].payload_name, "telephone-event"))
continue;
telephone_event = codec;
telephone_event_i = i;
break;
}
}
}
/* codec is selected within this media, we are done */
if (selected_codec)
break;
}
if (!selected_codec) {
PDEBUG(DCC, DEBUG_ERROR, "No codec found in setup message that we support.\n");
osmo_cc_free_session(*session_p);
return NULL;
}
osmo_cc_session_accept_codec(selected_codec, codecs[selected_i].encoder, codecs[selected_i].decoder);
osmo_cc_session_accept_codec(selected_codec, codecs[selected_codec_i].encoder, codecs[selected_codec_i].decoder);
if (telephone_event)
osmo_cc_session_accept_codec(telephone_event, codecs[telephone_event_i].encoder, codecs[telephone_event_i].decoder);
osmo_cc_session_accept_media(selected_media, 0, 0, NULL, 1, 1, receiver);
osmo_cc_rtp_open(selected_media);
osmo_cc_rtp_connect(selected_media);

Loading…
Cancel
Save