module-rtp: handle framecount attribute

This commit is contained in:
Dmitry Sharshakov 2023-12-16 19:21:33 +03:00 committed by Wim Taymans
parent 2525a99b97
commit 873e6119b8
2 changed files with 20 additions and 3 deletions

View file

@ -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);

View file

@ -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);