Commit Graph

294 Commits

Author SHA1 Message Date
Joshua Colp 6e907ae5d4 res_rtp_asterisk: Remove a log message that slipped in.
This was only supposed to be for testing, so now it can be
removed.

Change-Id: I3dfc2e776e70b3196aeed5688372ea80c0214b59
2019-10-17 05:50:49 -05:00
Joshua Colp e79a3b428a Merge "func_jitterbuffer: Add audio/video sync support." 2019-09-19 08:23:15 -05:00
Joshua Colp 7298a785ad 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
2019-09-18 20:22:50 +00:00
Ben Ford 723b695ce5 res_rtp_asterisk.c: Send RTCP as compound packets.
According to RFC3550, ALL RTCP packets must be sent in a compond packet
of at least two individual packets, including SR/RR and SDES. REMB,
FIR, and NACK were not following this format, and as a result, would
fail the packet check in ast_rtcp_interpret. This was found from writing
unit tests for RTCP. The browser would accept the way we were
constructing these RTCP packets, but when sending directly from one
Asterisk instance to another, the above mentioned problem would occur.

Change-Id: Ieb140e9c22568a251a564cd953dd22cd33244605
2019-09-13 09:48:31 -05:00
Ben Ford 0e56643d9f res_rtp: Add unit tests for RTCP stats.
Added unit tests for RTCP video stats. These tests include NACK, REMB,
FIR/FUR/PLI, SR/RR/SDES, and packet loss statistics. The REMB and FIR
tests are currently disabled due to a bug. We expect to receive a
compound packet, but the code sends this out as a single packet, which
the browser accepts, but makes Asterisk upset.

While writing these tests, I noticed an issue with NACK as well. Where
it is handling a received NACK request, it was reading in only the first
8 bits of following packets that were also lost. This has been changed
to the correct value of 16 bits.

Also made a minor fix to the data buffer unit test.

Change-Id: I56107c7411003a247589bbb6086d25c54719901b
2019-09-10 13:11:07 -05:00
Joshua Colp 2feac1d361 res_rtp_asterisk: Move where DTLS MTU variable is defined.
The DTLS MTU variable is not dependent on pjproject and should
not exist in its block.

Change-Id: I7e97d64dc192f2ac81bfe2b72b8229d321c7d026
2019-07-14 12:27:13 -06:00
Joshua Colp a8e5cf557d res_rtp_asterisk: Add support for DTLS packet fragmentation.
This change adds support for larger TLS certificates by allowing
OpenSSL to fragment the DTLS packets according to the configured
MTU. By default this is set to 1200.

This is accomplished by implementing our own BIO method that
supports MTU querying. The configured MTU is returned to OpenSSL
which fragments the packet accordingly. When a packet is to be
sent it is done directly out the RTP instance.

ASTERISK-28018

Change-Id: If2d5032019a28ffd48f43e9e93ed71dbdbf39c06
2019-06-13 07:51:57 -06:00
Friendly Automation 9b0a21c402 Merge "res_rtp_asterisk: timestamp should be unsigned instead of signed int" 2019-05-23 09:03:49 -05:00
Morten Tryfoss 3224ac07c9 res_rtp_asterisk: timestamp should be unsigned instead of signed int
Using timestamp with signed int will cause timestamps exceeding max value
to be negative.
This causes the jitterbuffer to do passthrough of the packet.

ASTERISK-28421

Change-Id: I9dabd0718180f2978856c50f43aac4e52dc3cde9
2019-05-21 18:32:57 +02:00
George Joseph be83591f99 res_rtp_asterisk: Add ability to propose local address in ICE
You can now add the "include_local_address" flag to an entry in
rtp.conf "[ice_host_candidates]" to include both the advertized
address and the local address in ICE negotiation:

[ice_host_candidates]
192.168.1.1 = 1.2.3.4,include_local_address

This causes both 192.168.1.1 and 1.2.3.4 to be advertized.

Change-Id: Ide492cd45ce84546175ca7d557de80d9770513db
2019-05-17 17:50:06 -06:00
Joshua Colp 7a6fd83aca res_rtp_asterisk: Fix sequence number cycling and packet loss count.
This change fixes two bugs which both resulted in the packet loss
count exceeding 65,000.

The first issue is that the sequence number check to determine if
cycling had occurred was using the wrong variable resulting in the
check never seeing that cycling has occurred, throwing off the
packet loss calculation. It now uses the correct variable.

The second issue is that the packet loss calculation assumed that
the received number of packets in an interval could never exceed
the expected number. In practice this isn't true due to delayed
or retransmitted packets. The expected will now be updated to
the received number if the received exceeds it.

ASTERISK-28379

Change-Id: If888ebc194ab69ac3194113a808c414b014ce0f6
2019-05-08 09:44:02 -06:00
Joshua Colp 6bb70c93f1 rtp: Add support for transport-cc in receiver direction.
The transport-cc draft is a mechanism by which additional information
about packet reception can be provided to the sender of packets so
they can do sender side bandwidth estimation. This is accomplished
by having a transport specific sequence number and an RTCP feedback
message. This change implements this in the receiver direction.

For each received RTP packet where transport-cc is negotiated we store
the time at which the RTP packet was received and its sequence number.
At a 1 second interval we go through all packets in that period of time
and use the stored time of each in comparison to its preceding packet to
calculate its delta. This delta information is placed in the RTCP
feedback message, along with indicators for any packets which were not
received.

The browser then uses this information to better estimate available
bandwidth and adjust accordingly. This may result in it lowering the
available send bandwidth or adjusting how "bursty" it can be.

ASTERISK-28400

Change-Id: I654a2cff5bd5554ab94457a14f70adb71f574afc
2019-05-01 05:13:14 -06:00
Matthew Fredrickson f78306470b res/res_rtp_asterisk: Enable rxjitter calculation for video
It looks like we're not properly calculating jitter values on received
video streams.  This patch enables the code that does jitter calculations
for those streams.

Change-Id: Iaac985808829c8f034db8c57318789c4c8c11392
2019-03-27 19:30:45 +00:00
sungtae kim 8641fd9700 res/res_rtp_asterisk.c: Fixing possible divide by zero
Currently, when the Asterisk calculates rtp statistics, it uses
sample_count as a unsigned integer parameter. This would be fine
for most of cases, but in case of large enough number of sample_count,
this might be causing the divide by zero error.

ASTERISK-28321

Change-Id: If7e0629abaceddd2166eb012456c53033ea26249
2019-03-11 09:09:09 -03:00
Torrey Searle 360f543677 res/res_rtp_asterisk: smoother can cause wrong timestamps if dtmf happen
Delivery timeval in the smoother object will fall behind while a DTMF is
being generated.  This can eventually lead to invalid rtp timestamps.
To prevent this from happening the smoother needs to be reset after every
DTMF to keep the timing up to date.

ASTERISK-28303 #close

Change-Id: Iaba3f7b428ebd72a4caa90e13b829ab4f088310f
2019-02-26 08:13:38 -06:00
Torrey Searle 8ea9608efb res/res_rtp_asterisk: clear smoother when local bridging
p2p_write updates txformat but doesn't require a smoother.  If a smoother
was created by another bridge type the smoother could fall out of date causing
one way audio issues.  To prevent this the smoother is now destroyed on the
start of native bridge.

ASTERISK-28284 #close

Change-Id: I84e67f144963787fff9b4d79ac500514fb40cdc6
2019-02-19 01:37:57 -06:00
Alexei Gradinari f662a26ea0 RTP: reset DTMF last seqno/timestamp on RTP renegotiation
The remote side may start a new stream when renegotiating RTP.
Need to reset the DTMF last sequence number and the timestamp
of the last END packet on RTP renegotiation.

If the new time stamp is lower then the timestamp of the last DTMF END packet
the asterisk drops all DTMF frames as out of order.

This bug was caught using Cisco ip-phone SPA5XX and codec g722.
On SIP session update the SPA50X resets stream and a new timestamp is twice
smaller then the previous.

ASTERISK-28162 #close

Change-Id: Ic72b4497e74d801b27a635559c1cf29c16c95254
2019-01-04 10:58:39 -05:00
Sean Bright 357219dfb3 res_rtp_asterisk: Remove some unused structure fields.
All of the fields that were removed were no longer referenced except for
'lastrxts' and 'rxseqno' which were only ever written to.

Change-Id: I5a5d31eb33e97663843698f58d0d97f22a76627c
2018-12-14 12:57:06 -05:00
Joshua C. Colp a28f0382e8 Merge "Use non-blocking socket() and pipe() wrappers" 2018-12-12 11:31:00 -06:00
George Joseph 5d4d723844 Merge "Revert "RTP: reset DTMF last seqno/timestamp on voice packet with marker bit"" 2018-12-11 14:18:25 -06:00
Sean Bright 42ff856216 Use non-blocking socket() and pipe() wrappers
Change-Id: I050ceffe5a133d5add2dab46687209813d58f597
2018-12-11 12:29:09 -05:00
George Joseph d1598dbc7d Revert "RTP: reset DTMF last seqno/timestamp on voice packet with marker bit"
This reverts commit 3f53041267.

Pending resolution of ASTERISK_28200

Change-Id: Iad4f3614cac95b00fdbb2b799aab8ae6285ec988
2018-12-11 09:28:48 -05:00
Joshua Colp b80c9071e3 Merge "RTP: need to reset DTMF last seqno/timestamp on voice packet with marker bit" 2018-11-26 13:47:32 -06:00
Alexei Gradinari 3f53041267 RTP: need to reset DTMF last seqno/timestamp on voice packet with marker bit
The marker bit set on the voice packet indicates the start
of a new stream and a new time stamp.
Need to reset the DTMF last sequence number and the timestamp
of the last END packet.

If the new time stamp is lower then the timestamp of the last DTMF END packet
the asterisk drops all DTMF frames as out of order.

This bug was caught using Cisco ip-phone SPA50X and codec g722.
On SIP session update the SPA50X resets stream indicating it with market bit
and a new timestamp is twice smaller then the previous.

ASTERISK-28162 #close

Change-Id: If9c5742158fa836ad549713a9814d46a5d2b1620
2018-11-23 10:41:52 -05:00
Corey Farrell 021ce938ca
astobj2: Remove legacy ao2_container_alloc routine.
Replace usage of ao2_container_alloc with ao2_container_alloc_hash or
ao2_container_alloc_list.  Remove ao2_container_alloc macro.

Change-Id: I0907d78bc66efc775672df37c8faad00f2f6c088
2018-11-21 09:56:16 -05:00
Richard Mudgett 7ab4befc2b res_rtp_asterisk.c: Add conditional module dependency to res_pjproject
* The dependency ensures that res_pjproject cannot be manually unloaded
before res_rtp_asterisk.
* The dependency allows startup loading errors to report that
res_rtp_asterisk depends upon res_pjproject.

Change-Id: Icf5e7581f4ddd6189929f6174c74dd951f887377
2018-10-17 16:13:51 -05:00
George Joseph 9914e3998e Merge "res_rtp_asterisk.c: Add "seqno" strictrtp option" 2018-09-28 07:27:24 -05:00
Ben Ford b11a6643cf res_rtp_asterisk.c: Add "seqno" strictrtp option
When networks experience disruptions, there can be large gaps of time
between receiving packets. When strictrtp is enabled, this created
issues where a flood of packets could come in and be seen as an attack.
Another option - seqno - has been added to the strictrtp option that
ignores the time interval and goes strictly by sequence number for
validity.

Change-Id: I8a42b8d193673899c8fc22fe7f98ea87df89be71
2018-09-26 13:27:03 -05:00
Joshua Colp 8bb264841a res_rtp_asterisk: Raise event when RTP port is allocated
This change raises a testsuite event to provide what port
Asterisk has actually allocated for RTP. This ensures that
testsuite tests can remove any assumption of ports and instead
use the actual port in use.

ASTERISK-28070

Change-Id: I91bd45782e84284e01c89acf4b2da352e14ae044
2018-09-25 05:35:26 -05:00
George Joseph ffcccd5e2f Merge "res_rtp_asterisk: Fix crash on ast_rtp_new failure." 2018-09-24 09:27:01 -05:00
Corey Farrell bdc8159799
res_rtp_asterisk: Fix crash on ast_rtp_new failure.
ast_rtp_new free'd rtp upon failure, but rtp_engine.c would also call
the destroy callback.  Remove call to ast_free from ast_rtp_new, leave
it to rtp_engine.c to initiate the full cleanup.  Add error detection
for the ssrc_mapping vector initialization.  In rtp_allocate_transport
set rtp->s = -1 in the failure path where we close that FD to ensure we
don't try closing it twice.

ASTERISK-27854 #close

Change-Id: Ie02aecbb46228ca804e24b19cec2bb6f7b94e451
2018-09-21 11:25:49 -04:00
Sean Bright ad4a6bc27a res_rtp_asterisk: Reset all settings on module reload
'rtpchecksums' and 'rtcpinterval' are not being reset to their defaults
if they are not present in the updated configuration file.

Change-Id: I1162e40199314d46cf3225d5e1271c4c81176670
2018-09-20 15:29:01 -05:00
neutrino88 289016239d res/res_rtp_asterisk: remove debug traces generated by an empty frame
The realtime text timer pops regularly and sends text frames even if
the buffer is empty. This causes a lot of unecessary debug logging.

* Made red_write() test if we need to send a frame before calling
ast_rtp_write()

ASTERISK-28002
Reported by: Emmanuel BUU
Tested by: Emmanuel BUU

Change-Id: Icf81310c3b8080b615a42060afc02ab41f9523dd
2018-08-27 12:03:03 -05:00
Richard Mudgett aee5f7c1b6 res_rtp_asterisk.c: Fix unused variable warnings
Compiling without SRTP support installed resulted in some unused variable
warnings.  These warnings also showed that the srtp variable was obtained
and passed around some functions but not really used even when a system
has SRTP installed.

Change-Id: I6daad34be3e89b19adef6e2fbe738018975155fc
2018-08-17 14:03:28 -05:00
Ben Ford c31a01bd75 res_pjsip/rtp: No joint capabilities between streams.
When a conference contained a mixture of audio/video and audio-only
users, a NOTICE message would pop up stating there are no joint
capabilities between streams. This happens because streams can never be
removed, but they can be in a REMOVED state. If we have the scenario
where user A joins with audio/video, user B joins with audio-only, and
user C joins with audio/video, then user A leaves, the message would
be triggered. That removed stream is still in the SDP, but Asterisk
would pass it through, causing it to be seen as a ulaw stream. A check
has been added for removed streams, setting their status to REMOVED when
handling negotiated SDPs.

Also addressed an issue where user A joins, then user B joins but does
not receive video until much later. Full frames were not being sent,
causing some PLI from the browser. Because the video was flowing in one
direction, the browser sets the SSRC to 1, but Asterisk was dropping the
PLI because of that. Added a check to see if the SSRC is 1 or not, which
sends full frames and allows video to flow between user A and user B.
This should only happen when dealing with PSFB or FUR, and in the case
of PSFB, only for PLI.

ASTERISK-27398

Change-Id: I26e7c6f101bc119549eeca406b5bcd25ad8ebc5e
2018-08-13 14:01:53 -05:00
Alexander Traud 870fe7f60c res_rtp_asterisk: In Developer Mode, do not require OpenSSL.
OpenSSL is an optional external library and should stay optional even when
Developer Mode is configured.

ASTERISK-27990

Change-Id: Ia68a4cd5474b26d45e0f43b04032ad598022853b
2018-07-27 08:40:32 -05:00
neutrino88 cb276b5085 res_rtp_asterisk: Avoid merging command and regular T.140 text packets
When realtime text packets are to be sent, the text is accumulated in a
buffer and sent regularly by a timer.  It can happen that commands such as
a backspace, CR, or LF get merged with regular text.  This breaks some
UAs.

The proposed change:
* We test if the current packet contains a command.  If so we send the
buffer immediately.
* We test if the buffer contained a command.  If so we send the buffer
immediately.
* We accumulate the text (or the command) in the buffer.

ASTERISK-27970

Change-Id: Ifbe993311410fa855cb8aa4a12084db75f413462
2018-07-26 13:58:22 -05:00
Ben Ford 5bacde37a2 res_rtp_asterisk: Add support for sending NACK requests.
Support has been added for receiving a NACK request and handling it.
Now, Asterisk can detect when a NACK request should be sent and knows
how to construct one based on the packets we've received from the remote
end. A buffer has been added that will store out of order packets until
we receive the packet we are expecting. Then, these packets are handled
like normal and frames are queued to the core like normal. Asterisk
knows which packets to request in the NACK request using a vector
which stores the sequence numbers of the packets we are currently missing.

If a missing packet is received, cycle through the buffer until we reach
another packet we have not received yet. If the buffer reaches a certain
size, send a NACK request. If the buffer reaches its max size, queue all
frames to the core and wipe the buffer and vector.

According to RFC3711, the NACK request must be sent out in a compound
packet. All compound packets must start with a sender or receiver
report, so some work was done to refactor the current sender / receiver
code to allow it to be used without having to also include sdes
information and automatically send the report.

Also added additional functionality to ast_data_buffer, along with some
testing.

For more information, refer to the wiki page:
https://wiki.asterisk.org/wiki/display/AST/WebRTC+User+Experience+Improvements

ASTERISK-27810 #close

Change-Id: Idab644b08a1593659c92cda64132ccc203fe991d
2018-07-18 13:37:03 -05:00
Alexander Traud b01fc2ef3d res_rtp_asterisk: Instead of ./configure use OPENSSL_NO_SRTP.
Previously, Asterisk used its script ./configure, to test whether OpenSSL was
built with no-srtp (or was simply too old). However, the header file
<openssl/opensslconf.h> is the preferred way to detect the local configuration
of OpenSSL.

As a positive side-effect the script ./configure does not interleave the
detection of the Open Settlement Protocol Toolkit (OSPTK) with the detection of
individual features of OpenSSL anymore.

Change-Id: I3c77c7b00b2ffa2e935632097fa057b9fdf480c0
2018-06-13 08:00:58 -06:00
Alexander Traud 0743ad6422 res_rtp_asterisk: Allow OpenSSL configured with no-deprecated.
Furthermore, allow OpenSSL configured with no-dh. Additionally, this change
allows auto-negotiation of the elliptic curve/group for servers, not only with
OpenSSL 1.0.2 but also with OpenSSL 1.1.0 and newer. This enables X25519
(since OpenSSL 1.1.0) and X448 (since OpenSSL 1.1.1) as a side-effect.

ASTERISK-27910

Change-Id: I5b0dd47c5194ee17f830f869d629d7ef212cf537
2018-06-08 22:02:38 +02:00
Joshua Colp 4ea98e49f1 Merge "rtp: Add support for RTP extension negotiation and abs-send-time." 2018-05-24 15:26:57 -05:00
Torrey Searle c5d2bf05f4 res/res_rtp_asterisk: ensure marker bit is correctly set on ssrc change
Certain race conditions between changing bridge types and DTMF can
cause the current FLAG_NEED_MARKER_BIT to send the marker bit before
the actual first packet of native bridging.

This logic keeps track of the ssrc the bridge is currently sending
and will correctly ensure the marker bit is set if SSRC as changed
from the previous sent packet.

ASTERISK-27845

Change-Id: I01858bd0235f1e5e629e20de71b422b16f55759b
2018-05-23 20:18:32 -06:00
Joshua Colp a507c73a78 rtp: Add support for RTP extension negotiation and abs-send-time.
When RTP was originally created it had the ability to place a single
extension in an RTP packet. In practice people wanted to potentially
put multiple extensions in one and so RFC 5285 (obsoleted by RFC
8285) came into existence. This allows RTP extensions to be negotiated
with a unique identifier to be used in the RTP packet, allowing
multiple extensions to be present in the packet.

This change extends the RTP engine API to add support for this. A
user of it can enable extensions and the API provides the ability to
retrieve the information (to construct SDP for example) and to provide
negotiated information (from SDP). The end result is that the RTP
engine can then query to see if the extension has been negotiated and
what unique identifier is to be used. It is then up to the RTP engine
implementation to construct the packet appropriately.

The first extension to use this support is abs-send-time which is
defined in the REMB draft[1] and is a second timestamp placed in an
RTP packet which is for when the packet has left the sending system.
It is used to more accurately determine the available bandwidth.

ASTERISK-27831

[1] https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03

Change-Id: I508deac557867b1e27fc7339be890c8018171588
2018-05-23 09:41:59 -06:00
Joshua Colp afdca5c68c res_rtp_asterisk: Always update SRTP on local SSRC change.
When the local SSRC changes we need to update the SRTP information
so that the proper key is used. This is commonly done as a result
of bridging two channels together. Previously we only updated
the SRTP information if media had already flowed, but in practice
the channel driver may have already performed SRTP negotiation and
set up the previous SSRC. We now always do it on a local SSRC
change.

ASTERISK-27795
ASTERISK-27800

Change-Id: Ia7c8e74c28841388b5244ac0b8fd6c1dc6ee4c10
2018-05-01 10:52:34 -06:00
Ben Ford f5d5083ea7 res_rtp_asterisk: Add support for receiving and handling NACK requests.
Adds the ability to receive and handle incoming NACK requests if
retransmissions are enabled. If retransmissions are enabled, a data
buffer is allocated that stores packets being sent. If a NACK request
is received, the packet requested for retransmission is sent if it is
still in the buffer. In the same request, if any of the following 16
packets are marked as not received, those will be sent as well if
available, as outlined in RFC4585.

Also changes RTCP RR and SR to use media source SSRC instead of packet
source SSRC when determining which instance to use for RTCP reports.

For more information, refer to the wiki page:
https://wiki.asterisk.org/wiki/display/AST/WebRTC+User+Experience+Improvements

ASTERISK-27806 #close

Change-Id: I7f7f124af3b9d5d2fd9cffc6ba8cb48a6fff06ec
2018-04-16 17:21:18 -06:00
Jenkins2 2a6072a9c4 Merge "pjsip / res_rtp_asterisk: Add support for sending REMB" 2018-04-09 11:14:16 -05:00
Joshua Colp 2e60196265 Merge "res_rtp_asterisk: Fix minimum block word length for REMB." 2018-04-09 10:58:00 -05:00
Joshua Colp c7bd554094 pjsip / res_rtp_asterisk: Add support for sending REMB
This change allows chan_pjsip to be given an AST_FRAME_RTCP
containing REMB feedback and pass it to res_rtp_asterisk.
Once res_rtp_asterisk receives the frame a REMB RTCP feedback
packet is constructed with the appropriate contents and sent
to the remote endpoint.

ASTERISK-27776

Change-Id: Ic53f821c1560d8924907ad82c4d9c0bc322b38cd
2018-04-06 08:36:54 -06:00
Joshua Colp 39016e3582 res_rtp_asterisk: Fix minimum block word length for REMB.
The minimum block word length is actually 4, not 5.

Change-Id: I878542218225aed72c72bdf1b856fc822cd2d649
2018-04-05 19:02:40 -06:00
Joshua Colp 8a602f18db res_rtp_asterisk: Queue video update on picture loss indication.
The previous payload specific feedback handling was very single
minded in that it just assumed everything should trigger a video
update. This was changed but the handling of picture loss indication
was not added. The result was that video may not flow. This change
adds it explicitly in.

Change-Id: I1894be02e39ee10a0af841b5a1dca5f0ec7d60b6
2018-04-05 17:49:29 -06:00