From 56f8c11f0b476b0a9e2a26b2cac941e47b3f2a5d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 1 Oct 2010 12:22:06 -0500 Subject: [PATCH] refactor fmtp parser as a core func --- src/include/switch_core.h | 1 + src/mod/endpoints/mod_sofia/sofia_glue.c | 14 ++++++++++++-- src/switch_core_codec.c | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 8b08db7d9d..466dc51186 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -1351,6 +1351,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_init_with_bitrate(switch_codec uint32_t flags, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool); SWITCH_DECLARE(switch_status_t) switch_core_codec_copy(switch_codec_t *codec, switch_codec_t *new_codec, switch_memory_pool_t *pool); +SWITCH_DECLARE(switch_status_t) switch_core_codec_parse_fmtp(const char *codec_name, const char *fmtp, uint32_t rate, switch_codec_fmtp_t *codec_fmtp); SWITCH_DECLARE(switch_status_t) switch_core_codec_reset(switch_codec_t *codec); /*! diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index e4933c63c1..42b8b5e80b 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -4152,6 +4152,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s const char *rm_encoding; uint32_t map_bit_rate = 0; int codec_ms = 0; + switch_codec_fmtp_t codec_fmtp = { 0 }; if (x++ < skip) { continue; @@ -4197,9 +4198,18 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s map_bit_rate = switch_known_bitrate(map->rm_pt); - if (!codec_ms) { - codec_ms = ptime; + if (!zstr(map->rm_fmtp)) { + if ((switch_core_codec_parse_fmtp(map->rm_encoding, map->rm_fmtp, map->rm_rate, &codec_fmtp)) == SWITCH_STATUS_SUCCESS) { + if (codec_fmtp.bits_per_second) { + map_bit_rate = codec_fmtp.bits_per_second; + } + if (codec_fmtp.microseconds_per_packet) { + ptime = (codec_fmtp.microseconds_per_packet / 1000); + } + } } + + codec_ms = ptime; for (i = first; i < last && i < tech_pvt->num_codecs; i++) { const switch_codec_implementation_t *imp = tech_pvt->codecs[i]; diff --git a/src/switch_core_codec.c b/src/switch_core_codec.c index edaf8b87e9..d45d73ed76 100644 --- a/src/switch_core_codec.c +++ b/src/switch_core_codec.c @@ -450,6 +450,28 @@ SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_video_write_codec(switc } +SWITCH_DECLARE(switch_status_t) switch_core_codec_parse_fmtp(const char *codec_name, const char *fmtp, uint32_t rate, switch_codec_fmtp_t *codec_fmtp) +{ + switch_codec_interface_t *codec_interface; + switch_status_t status = SWITCH_STATUS_FALSE; + + if (zstr(codec_name) || zstr(fmtp) || !codec_fmtp) { + return SWITCH_STATUS_FALSE; + } + + memset(codec_fmtp, 0, sizeof(*codec_fmtp)); + + if ((codec_interface = switch_loadable_module_get_codec_interface(codec_name))) { + if (codec_interface->parse_fmtp) { + codec_fmtp->actual_samples_per_second = rate; + status = codec_interface->parse_fmtp(fmtp, codec_fmtp); + } + + UNPROTECT_INTERFACE(codec_interface); + } + + return status; +} SWITCH_DECLARE(switch_status_t) switch_core_codec_reset(switch_codec_t *codec) {