module-rtp: use sess.latency.msec also for sender

Use the sess.latency.msec also for the sender and use it to control the
NODE_LATENCY. Make it a float to be in line with the other time values.
Set is to a default of ptime, which was what it used to be.

This makes it possible to set the ptime to a smaller value than the
sess.latency.msec so that we send out multiple packets per quantum.
This will result in some bursty output for now but with a timer that can
be improved later.

Update the docs a little, mention the new rtp.ptime and rtp.frametime.
This commit is contained in:
Wim Taymans 2024-01-25 15:42:16 +01:00
parent ec825086f1
commit c37f9f9cf0
4 changed files with 24 additions and 12 deletions

View file

@ -52,9 +52,14 @@
* - `net.mtu = <int>`: MTU to use, default 1280 * - `net.mtu = <int>`: MTU to use, default 1280
* - `net.ttl = <int>`: TTL to use, default 1 * - `net.ttl = <int>`: TTL to use, default 1
* - `net.loop = <bool>`: loopback multicast, default false * - `net.loop = <bool>`: loopback multicast, default false
* - `sess.min-ptime = <int>`: minimum packet time in milliseconds, default 2 * - `sess.min-ptime = <float>`: minimum packet time in milliseconds, default 2
* - `sess.max-ptime = <int>`: maximum packet time in milliseconds, default 20 * - `sess.max-ptime = <float>`: maximum packet time in milliseconds, default 20
* - `sess.name = <str>`: a session name * - `sess.name = <str>`: a session name
* - `rtp.ptime = <float>`: size of the packets in milliseconds, default up to MTU but
* between sess.min-ptime and sess.max-ptime
* - `rtp.framecount = <int>`: number of samples per packet, default up to MTU but
* between sess.min-ptime and sess.max-ptime
* - `sess.latency.msec = <float>`: target node latency in milliseconds, default as rtp.ptime
* - `sess.ts-offset = <int>`: an offset to apply to the timestamp, default -1 = random offset * - `sess.ts-offset = <int>`: an offset to apply to the timestamp, default -1 = random offset
* - `sess.ts-refclk = <string>`: the name of a reference clock * - `sess.ts-refclk = <string>`: the name of a reference clock
* - `sess.media = <string>`: the media type audio|midi|opus, default audio * - `sess.media = <string>`: the media type audio|midi|opus, default audio

View file

@ -56,7 +56,7 @@
* you want to receive packets from or 0.0.0.0 to receive from any source address. * you want to receive packets from or 0.0.0.0 to receive from any source address.
* - `source.port = <int>`: the source port * - `source.port = <int>`: the source port
* - `node.always-process = <bool>`: true to receive even when not running * - `node.always-process = <bool>`: true to receive even when not running
* - `sess.latency.msec = <str>`: target network latency in milliseconds, default 100 * - `sess.latency.msec = <float>`: target network latency in milliseconds, default 100
* - `sess.ignore-ssrc = <bool>`: ignore SSRC, default false * - `sess.ignore-ssrc = <bool>`: ignore SSRC, default false
* - `sess.media = <string>`: the media type audio|midi|opus, default audio * - `sess.media = <string>`: the media type audio|midi|opus, default audio
* - `stream.props = {}`: properties to be passed to the stream * - `stream.props = {}`: properties to be passed to the stream

View file

@ -284,7 +284,7 @@ struct rtp_stream *rtp_stream_new(struct pw_core *core,
float min_ptime, max_ptime; float min_ptime, max_ptime;
const struct spa_pod *params[1]; const struct spa_pod *params[1];
enum pw_stream_flags flags; enum pw_stream_flags flags;
int latency_msec; float latency_msec;
int res; int res;
impl = calloc(1, sizeof(*impl)); impl = calloc(1, sizeof(*impl));
@ -450,16 +450,23 @@ struct rtp_stream *rtp_stream_new(struct pw_core *core,
pw_properties_setf(props, "rtp.framecount", "%u", impl->psamples); pw_properties_setf(props, "rtp.framecount", "%u", impl->psamples);
} }
} }
latency_msec = pw_properties_get_uint32(props, /* For senders, the default latency is ptime and for a receiver it is
"sess.latency.msec", DEFAULT_SESS_LATENCY); * DEFAULT_SESS_LATENCY. Setting the sess.latency.msec for a sender to
* something smaller/bigger will influence the quantum and the amount
* of packets we send in one cycle */
str = pw_properties_get(props, "sess.latency.msec");
if (!spa_atof(str, &latency_msec)) {
latency_msec = direction == PW_DIRECTION_INPUT ?
samples_to_msec(impl, impl->psamples) :
DEFAULT_SESS_LATENCY;
}
impl->target_buffer = msec_to_samples(impl, latency_msec); impl->target_buffer = msec_to_samples(impl, latency_msec);
impl->max_error = msec_to_samples(impl, ERROR_MSEC); impl->max_error = msec_to_samples(impl, ERROR_MSEC);
pw_properties_setf(props, PW_KEY_NODE_RATE, "1/%d", impl->rate); pw_properties_setf(props, PW_KEY_NODE_RATE, "1/%d", impl->rate);
if (direction == PW_DIRECTION_INPUT) { if (direction == PW_DIRECTION_INPUT) {
// TODO: make sess.latency.msec work for sender streams
pw_properties_setf(props, PW_KEY_NODE_LATENCY, "%d/%d", pw_properties_setf(props, PW_KEY_NODE_LATENCY, "%d/%d",
impl->psamples, impl->rate); impl->target_buffer, impl->rate);
} else { } else {
pw_properties_setf(props, PW_KEY_NODE_LATENCY, "%d/%d", pw_properties_setf(props, PW_KEY_NODE_LATENCY, "%d/%d",
impl->target_buffer / 2, impl->rate); impl->target_buffer / 2, impl->rate);

View file

@ -16,12 +16,12 @@ struct rtp_stream;
#define DEFAULT_CHANNELS 2 #define DEFAULT_CHANNELS 2
#define DEFAULT_POSITION "[ FL FR ]" #define DEFAULT_POSITION "[ FL FR ]"
#define ERROR_MSEC 2 #define ERROR_MSEC 2.0f
#define DEFAULT_SESS_LATENCY 100 #define DEFAULT_SESS_LATENCY 100.0f
#define DEFAULT_MTU 1280 #define DEFAULT_MTU 1280
#define DEFAULT_MIN_PTIME 2 #define DEFAULT_MIN_PTIME 2.0f
#define DEFAULT_MAX_PTIME 20 #define DEFAULT_MAX_PTIME 20.0f
struct rtp_stream_events { struct rtp_stream_events {
#define RTP_VERSION_STREAM_EVENTS 0 #define RTP_VERSION_STREAM_EVENTS 0