func_jitterbuffer: Add audio/video sync support.

This change adds support to the JITTERBUFFER dialplan function
for audio and video synchronization. When enabled the RTCP SR
report is used to produce an NTP timestamp for both the audio and
video streams. Using this information the video frames are queued
until their NTP timestamp is equal to or behind the NTP timestamp
of the audio. The audio jitterbuffer acts as the leader deciding
when to shrink/grow the jitterbuffer when adaptive is in use. For
both adaptive and fixed the video buffer follows the size of the
audio jitterbuffer.

ASTERISK-28533

Change-Id: I3fd75160426465e6d46bb2e198c07b9d314a4492
This commit is contained in:
Joshua Colp
2019-09-06 13:18:55 +00:00
parent ac8db871ec
commit 7298a785ad
7 changed files with 237 additions and 24 deletions

View File

@@ -62,8 +62,9 @@
</syntax>
<description>
<para>Jitterbuffers are constructed in two different ways.
The first always take three arguments: <replaceable>max_size</replaceable>,
<replaceable>resync_threshold</replaceable>, and <replaceable>target_extra</replaceable>.
The first always take four arguments: <replaceable>max_size</replaceable>,
<replaceable>resync_threshold</replaceable>, <replaceable>target_extra</replaceable>,
and <replaceable>sync_video</replaceable>.
Alternatively, a single argument of <literal>default</literal> can be provided,
which will construct the default jitterbuffer for the given
<replaceable>jitterbuffer type</replaceable>.</para>
@@ -76,12 +77,17 @@
<para>target_extra: This option only affects the adaptive jitterbuffer. It represents
the amount time in milliseconds by which the new jitter buffer will pad its size.
Defaults to 40ms.</para>
<para>sync_video: This option enables video synchronization with the audio stream. It can be
turned on and off. Defaults to off.</para>
<example title="Fixed with defaults" language="text">
exten => 1,1,Set(JITTERBUFFER(fixed)=default)
</example>
<example title="Fixed with 200ms max size" language="text">
exten => 1,1,Set(JITTERBUFFER(fixed)=200)
</example>
<example title="Fixed with 200ms max size and video sync support" language="text">
exten => 1,1,Set(JITTERBUFFER(fixed)=200,,,yes)
</example>
<example title="Fixed with 200ms max size, resync threshold 1500" language="text">
exten => 1,1,Set(JITTERBUFFER(fixed)=200,1500)
</example>
@@ -91,6 +97,9 @@
<example title="Adaptive with 200ms max size, 60ms target extra" language="text">
exten => 1,1,Set(JITTERBUFFER(adaptive)=200,,60)
</example>
<example title="Adaptive with 200ms max size and video sync support" language="text">
exten => 1,1,Set(JITTERBUFFER(adaptive)=200,,,yes)
</example>
<example title="Set a fixed jitterbuffer with defaults; then remove it" language="text">
exten => 1,1,Set(JITTERBUFFER(fixed)=default)
exten => 1,n,Set(JITTERBUFFER(disabled)=)
@@ -133,6 +142,7 @@ static int jb_helper(struct ast_channel *chan, const char *cmd, char *data, cons
AST_APP_ARG(max_size);
AST_APP_ARG(resync_threshold);
AST_APP_ARG(target_extra);
AST_APP_ARG(sync_video);
);
AST_STANDARD_APP_ARGS(args, parse);
@@ -151,6 +161,11 @@ static int jb_helper(struct ast_channel *chan, const char *cmd, char *data, cons
"jbtargetextra",
args.target_extra);
}
if (!ast_strlen_zero(args.sync_video)) {
res |= ast_jb_read_conf(&jb_conf,
"jbsyncvideo",
args.sync_video);
}
if (res) {
ast_log(LOG_WARNING, "Invalid jitterbuffer parameters %s\n", value);
}