From 873e6119b816ceb71732b0ccfdd33d600f98063a Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Sat, 16 Dec 2023 19:21:33 +0300 Subject: [PATCH] module-rtp: handle framecount attribute --- src/modules/module-rtp-sap.c | 3 ++- src/modules/module-rtp/stream.c | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/modules/module-rtp-sap.c b/src/modules/module-rtp-sap.c index bf17e106d..4dce3b471 100644 --- a/src/modules/module-rtp-sap.c +++ b/src/modules/module-rtp-sap.c @@ -704,7 +704,7 @@ static struct session *session_new_announce(struct impl *impl, struct node *node sdp->ptime = 0.0; if ((str = pw_properties_get(props, "rtp.framecount")) != NULL) - if (!spa_atou32(str, &sdp->framecount)) + if (!spa_atou32(str, &sdp->framecount, 0)) sdp->framecount = 0; if ((str = pw_properties_get(props, "rtp.media")) != NULL) @@ -925,6 +925,7 @@ static struct session *session_new(struct impl *impl, struct sdp_info *info) pw_properties_setf(props, "rtp.destination.port", "%u", info->dst_port); pw_properties_setf(props, "rtp.payload", "%u", info->payload); pw_properties_set(props, "rtp.ptime", spa_dtoa(tmp, sizeof(tmp), info->ptime)); + pw_properties_setf(props, "rtp.framecount", "%u", info->framecount); pw_properties_setf(props, "rtp.media", "%s", info->media_type); pw_properties_setf(props, "rtp.mime", "%s", info->mime_type); pw_properties_setf(props, "rtp.rate", "%u", info->rate); diff --git a/src/modules/module-rtp/stream.c b/src/modules/module-rtp/stream.c index dfe52ffa9..e767c8ecc 100644 --- a/src/modules/module-rtp/stream.c +++ b/src/modules/module-rtp/stream.c @@ -416,8 +416,24 @@ struct rtp_stream *rtp_stream_new(struct pw_core *core, if (!spa_atof(str, &ptime)) ptime = 0.0; - if (ptime) { - impl->psamples = ptime * impl->rate / 1000; + uint32_t framecount = 0; + if ((str = pw_properties_get(props, "rtp.framecount")) != NULL) + if (!spa_atou32(str, &framecount, 0)) + framecount = 0; + + if (ptime > 0 || framecount > 0) { + if (!framecount) { + impl->psamples = ptime * impl->rate / 1000; + pw_properties_setf(props, "rtp.framecount", "%u", impl->psamples); + } else if (!ptime) { + impl->psamples = framecount; + pw_properties_set(props, "rtp.ptime", + spa_dtoa(tmp, sizeof(tmp), + impl->psamples * 1000.0 / impl->rate)); + } else if (fabs((impl->psamples * 1000.0 / impl->rate) - ptime) > 0.1) { + impl->psamples = ptime * impl->rate / 1000; + pw_log_warn("rtp.ptime doesn't match rtp.framecount. Choosing rtp.ptime"); + } } else { impl->psamples = impl->mtu / impl->stride; impl->psamples = SPA_CLAMP(impl->psamples, min_samples, max_samples);