Commit Graph

432 Commits

Author SHA1 Message Date
Joni Räsänen cfb7c5e665 rtcp: Separate sender and receiver statistics
Only functional change was in function that saved maximum seq for sent
packets. This function or value were not used anywhere.
2021-07-30 14:54:51 +03:00
Joni Räsänen 57b091292b rtcp: Don't report without RTP packets
Send receiver reports instead of sender reports if we haven't sent any
RTP packets. Also don't include report blocks if we haven't received
any RTP packets.
2021-07-30 14:54:49 +03:00
Joni Räsänen 7b0e1bc94a rtcp: Fix invalid size of receiver reports 2021-07-30 14:54:45 +03:00
Joni Räsänen 27dc0db42e api: Rename addr to remote_address for clarity 2021-07-28 15:32:59 +03:00
Joni Räsänen 7f5d60eacb rtcp: Improve timing of reports and remove dependency from runner 2021-07-28 14:26:54 +03:00
Joni Räsänen 1db0404b61 api: Add check for Crypto inclusion to context class 2021-07-26 16:01:02 +03:00
Joni Räsänen 3b5acb7f88 build: Move includes to include/uvgrtp folder 2021-07-09 12:11:05 +03:00
Joni Räsänen 4cc94e9abe srtp: Remove zrtp dependency from srtp_base
The architecture is more easily modified with less dependencies. The
dependency concerned only getting the keys from zrtp and now that is
handled by media_stream.

Also added checks that we are not double freeing resources, since
previous version seemed very risky.
2021-06-17 12:55:26 +03:00
Joni Räsänen 67e54644c4 rtcp: Add std function interface options for getting rtcp frames 2021-06-15 13:09:54 +03:00
Joni Räsänen d29479ced5 rtcp: Use function for reading rtcp report blocks
Removes duplicate code for reading reports.
2021-06-14 16:43:34 +03:00
Joni Räsänen d8b461aa0a rtcp: Move header reading to the common handle function
Also add few checks that we have received enough data.
2021-06-14 15:40:53 +03:00
Joni Räsänen 55dad012a1 rtcp: Combine generation of sender and receiver reports
This reduces the amount of duplicate code in rtcp.
2021-06-14 14:46:40 +03:00
Joni Räsänen 4b97303271 rtcp: Rename sender report and receiver report variables
The r_frame and s_frame are not as clear as rr_frame and sr_frame.
2021-06-11 12:19:11 +03:00
Joni Räsänen ded95e9c41 rtcp: Helper function for sending rtcp packets to participants
Also free the frame if encryption failed.
2021-06-09 11:02:40 +03:00
Joni Räsänen c337b803d5 rtcp: Helper function for reading rtcp header 2021-06-09 11:02:38 +03:00
Joni Räsänen 6449f9d614 rtcp: Use a common function for rtcp packet header construction
This commit removes little bit of duplicate code, making future bug
fixes easier. The length of the packet is not set correctly, but that
will bi fixed in future.
2021-06-09 11:02:33 +03:00
Joni Räsänen decde85859 build: Move private headers out from include folder 2021-06-04 14:43:51 +03:00
Joni Räsänen 44590422ee common: Eliminate causes of compiler warnings for type conversions
Tried to check the values that they don't exceed the maximum size.
Skipped checks in places where I think refactoring will happen soon.
2021-06-04 13:06:41 +03:00
Joni Räsänen e739648923 common: Default initializers for struct member variables
Since compiler was complaining about them and its little bit more
secure, I set all integers to 0 and pointers to nullptr. There is a
small risk of reduced performance if the initialization is done
frequently, but I think the risk is worth it since uvgRTP is already
one of the fastest RTP libraries in the world and there are issues with
reliability.

The member variable initialization was introduced in C++11 which is the
lowest we support at the moment.
2021-06-03 11:12:02 +03:00
Joni Räsänen 4413a65da4 build: Add missing network headers needed on Linux 2021-06-02 14:02:15 +03:00
Joni Räsänen 399f74e772 build: Rename defines so they don't conflict with crypto++ 2021-06-02 13:32:24 +03:00
Joni Räsänen cb99edb203 common: Reduce include dependencies in header files
I removed as many dependencies as I could. I tried to preserve the API
by including the necessary headers for library usage in lib.hh file.
2021-06-02 13:14:41 +03:00
Joni Räsänen ba8b0cba80 common: Reverse the order of the header includes
I tried to make the headers be included in local to global order. This
way any potential missing includes are detected making it easier to
make changes to header location and includes.
2021-06-02 11:06:17 +03:00
Joni Räsänen ae57fb6ce9 build: Also accept correct MSVC version
This is needed because MSVC doesn't always define cplusplus version.
2021-06-02 11:02:21 +03:00
Le Clech Philippe f1169cdc57
build: support for CentOS7
The 2.0.0 release of uvgRTP fails to build on CentOS7, because :
- the gcc-c++ compiler doesn't support the c++17 standard, which is
  required to compile the crypto.hh file
- the getrandom() function isn't available in the libc

This pull request adds CentOS7 build support.

The modified files are :

- CMakeLists.txt : the availability of the getrandom() function is checked.
  If it exists, the HAVE_GETRANDOM preprocessor definition is added

- src/random.cc : if HAVE_GETRANDOM isn't defined, a syscall equivalent to
  the getrandom() functions is called

- include/crypto.hh : the c++17 code is replaced by a code that compiles with
  the CentOS7 compiler (c++11)
2021-05-25 21:33:52 +02:00
Aaro Altonen c7216c02a4 formats/media: Adjust fragment buffer offset correctly
Fragmented generic frames whose sequence numbers crossed the overflow
boundary were incorrectly reconstructed as the last fragments of the
frame were in the beginning of the buffer.
2021-04-23 08:57:56 +03:00
Aaro Altonen 6e53f686f9 rtcp: Extract fraction and lost fields correctly from the report 2021-04-22 13:25:04 +03:00
Aaro Altonen bfaa3536c5 crypto: Add 192/256-bit key support for SRTP 2021-04-22 12:43:05 +03:00
Aaro Altonen 5c3f76f04d doc: Document NTP clock interface 2021-04-22 07:00:04 +03:00
Aaro Altonen 0806522ab9 doc: Add documentation for RTCP 2021-04-19 12:15:23 +03:00
Aaro Altonen 367a8ad465 Allow pkt_dispatcher thread access to pkt_dispatcher's state
This makes the code and interface cleaner
2021-03-23 01:19:47 +02:00
Aaro Altonen 2dadd7b937 Implement free_resources() 2021-03-23 01:19:47 +02:00
Aaro Altonen 238cf77f64 Implement create_media() helper function 2021-03-23 01:19:47 +02:00
Aaro Altonen b5aabb06c7 Update push_frame()/pull_frame() documentation 2021-03-23 01:19:47 +02:00
Aaro Altonen c2e6207698 Document set_ts_info() 2021-03-23 01:19:47 +02:00
Aaro Altonen 5bdb283193 Document add_srtp_ctx() 2021-03-23 01:19:47 +02:00
Aaro Altonen d80abd580e Document pull_frame() 2021-03-23 01:19:47 +02:00
Aaro Altonen 53f8afbdb2 Document push_frame() 2021-03-23 01:19:47 +02:00
Aaro Altonen 59b4eb4b27 Document install_receive_hook() 2021-03-23 01:19:47 +02:00
Aaro Altonen 4bacbaf36d Update VVC packet handler
Save the frame info to the media object and fetch it from there
when a packet is received, update the code to better handle out-of-order
packets and add support for RCE_H26X_PREPEND_SC
2021-03-23 01:18:59 +02:00
Aaro Altonen e574a2a786 Rename RCE_HEVC_NO_INTRA_DELAY to RCE_NO_H26X_INTRA_DELAY
Now the functionality of all three (AVC, HEVC and VVC) can be controlled
through one flag
2021-03-23 01:18:59 +02:00
Aaro Altonen 0e12e57a47 Rename uvg_rtp to uvgrtp
I have no idea why the name had an underscore but now it's gone.
The old namespace is kept as an alias for backwards-compatibility
but it may be removed in the future
2021-03-23 01:18:59 +02:00
Aaro Altonen 13989c66f1 Add Doxygen documentation support
Some of the API is still undocumented
2021-03-23 01:18:59 +02:00
Aaro Altonen 41011487ba Implement RCE_HOLEPUNCH_KEEPALIVE 2021-03-23 01:18:59 +02:00
Aaro Altonen 4d561a5b28 Implement RCC_MTU_SIZE 2021-03-23 01:18:59 +02:00
Aaro Altonen b1ccd7f788 Increase MAX_PAYLOAD by 3 bytes
1443 is the maximum payload size for H26X Fragmentation Units but
for generic frames there is no NAL + FU header meaning the 3 bytes
can be used for payload data
2021-03-23 01:18:59 +02:00
Aaro Altonen c950179790 Implement RCC_DYN_PAYLOAD_TYPE
This change removes set_dynamic_payload() as ctx_configure() function
should be used for all context configuration instead of separate functions
for some configurations
2021-03-23 01:16:42 +02:00
Aaro Altonen ca66f6f8dc Implement RCC_PKT_MAX_DELAY 2021-03-23 01:16:42 +02:00
Aaro Altonen 755fe99d88 Implement RCE_H26X_PREPEND_SC 2021-03-23 01:16:42 +02:00
Aaro Altonen f87b4e8e72 Use __has_include to detect the presence of Crypto++ automatically
Use __has_include to check if all needed headers are present in the
system and if so, build uvgRTP with crypto enabled.

Introduce new define, __RTP_NO_CRYPTO__ which disables SRTP/ZRTP
support even if Crypto++ is present in the system
2020-12-11 07:56:02 +02:00
Aaro Altonen b99c0711ce Fix SRTP ROC calculation near sequence number overflow boundary 2020-12-11 07:37:16 +02:00
Aaro Altonen 2833161d3a Add support for H.266/VVC
This code is based on the most recent draft of VVC RTP payload
format and is subjet to changes as the draft evolves
2020-12-11 07:37:16 +02:00
Aaro Altonen 601209e295 Fix ZRTP header padding for MSVC 2020-11-23 09:18:58 +02:00
Aaro Altonen d61a6cf4dc Protect access to create_stream() with a mutex
Multiple threads may access create_stream() for the same session
simultaneously which can cause problems if the access is not protected.
2020-11-18 08:39:53 +02:00
Aaro Altonen 3195a271e9 Use NTP to calculate RTP timestamps 2020-10-26 07:28:10 +02:00
Aaro Altonen e185160f94 Implement RTP_SLICE 2020-10-22 14:38:59 +03:00
Aaro Altonen c74d6a75a7 Implement RCE_FRAGMENT_GENERIC for the new architecture 2020-10-13 03:39:19 +03:00
Aaro Altonen 4253f636bf Remove the old HEVC receiver
This thread-based approach is no longer supported and optimistic
packet reception isn't possible to implement properly using the
new packet dispatcher architecture
2020-10-12 18:46:52 +03:00
Aaro Altonen 2a2baf88fa Implement STAP-A support for H.264 2020-10-10 03:02:35 +03:00
Aaro Altonen 3541212cc1 Remove SEND_ONLY/RECV_ONLY options from media_stream
The media_stream object acts as uni-/bidirectional based on usage
so there is no need to explicitly define it as send/recv only
2020-10-09 04:09:07 +03:00
Aaro Altonen eea453efd6 Implement frame getter support for packet dispatcher
If a media format needs to return multiple frames, it can install
a frame getter that is called by the packet dispatcher until all
frames have been queried and returned to user.
2020-10-07 13:33:43 +03:00
Aaro Altonen 6381ca5e23 Extend sequence number of the fragments map to 32 bits
Because the receiver adds an offset to those sequence numbers which
cross the 0xfff boundary, the key must be extended to 32 bits so
the frames are reconstructible
2020-10-07 12:11:14 +03:00
Aaro Altonen a1981dfdfa Implement Aggregation Packet construction for HEVC 2020-10-06 07:15:45 +03:00
Aaro Altonen 6317abb58b Set ZRTP timeout properly on both platforms 2020-10-06 07:15:45 +03:00
Aaro Altonen 1ad489620e Implement cross-platform structure packing 2020-10-06 07:15:45 +03:00
Aaro Altonen 645078ee73 Implement blocked_recv()
blocked_recv() is a Windows-only function that is used to implement
a blocking socket that blocks only a certain amount of time.

This is quite an ugly hack and hopefully a better solution for
"semi-blocking" socket is implemented in the future
2020-10-06 07:15:45 +03:00
Aaro Altonen 9328b9dd1c Use platform-generic socket API with ZRTP 2020-10-06 07:15:45 +03:00
Aaro Altonen ee303ac818 Fix MSVC-related warnings 2020-10-06 06:23:05 +03:00
Aaro Altonen 5b4c6f814d Use 64-bit digests for SRTP replay list 2020-10-06 06:23:01 +03:00
Aaro Altonen f2f3a48e42 Update H.264 to use private frame info 2020-10-06 06:22:14 +03:00
Aaro Altonen b85e35ded1 Maintain the order for fragments when saving them to fragment buffer
Previous implementation did not consider the fact that sequence number
could overflow and start fragment would thus appear later than the end
fragment.

This caused distortions in the video as the frames were constructed
incorrectly. By adjusting the overflown sequence number, the fragments
can be stored efficiently to std::map while maintaining their order.
2020-10-06 06:21:29 +03:00
Aaro Altonen be760dbdf2 Merge branch 'windows-fixes' into new-develop 2020-10-06 06:20:22 +03:00
Aaro Altonen 5374a79a28 Add support for H.264/AVC 2020-09-25 10:23:12 +03:00
Aaro Altonen d293039870 Set ZRTP message type enum size to 64 bits for MSVC 2020-09-25 08:36:12 +03:00
Aaro Altonen ee92f22a3a Fix Windows compilation issues 2020-09-17 12:45:20 +03:00
Aaro Altonen 2d1c6bd79c Save Media frame info to the Media object 2020-09-16 11:31:35 +03:00
Aaro Altonen 7559482a84 Save HEVC frame info to the HEVC object 2020-09-16 11:04:41 +03:00
Aaro Altonen 7b50e99aa0 Update project files
Add all new source and header files to Visual Studio, CMake and
QtCreator project files.

Rename rtcp/runner.cc and zrtp/receiver.cc files because they
caused linking problems with QtCreator
2020-09-16 10:56:57 +03:00
Aaro Altonen d60b240341 Separate HEVC code into H265 and H26x
H26x shall contain all code common to H26{4,5,6} and H26{4,5,6}
files shall contain format-specific code which is mainly just
NAL unit fragmentation.

This commit also changes the HEVC RTP format name from RTP_FORMAT_HEVC
to RTP_FORMAT_H265 to unify naming with upcoming AVC/VVC support
2020-09-08 09:01:45 +03:00
Aaro Altonen e37add13db Remove private frame queue from HEVC 2020-09-07 12:37:41 +03:00
Aaro Altonen 29fb88d2ed Proctect CryptoPP calls with __RTP_CRYPTO__
Add __RTP_CRYPTO__ around CryptoPP code and remove from all other
places. This should provide a cleaner way of compiling and linking
to the library.

Not sure if I'm totally happy with this solution either but it's
a step to a better direction at least.
2020-09-04 11:37:06 +03:00
Aaro Altonen 86d16e9855 Use 80 bits long authentication tags
RFC 3711 dictates that SRTCP/SRTP authentication must be at least
80 bits long
2020-09-04 10:49:49 +03:00
Aaro Altonen 793ab80fce Implement packet replay protection 2020-09-04 09:17:15 +03:00
Aaro Altonen 2a4e45032a Implement Secure RTCP for Sender Reports 2020-09-03 12:03:50 +03:00
Aaro Altonen cc9438da40 Implement RTCP authentication routines 2020-09-03 11:34:55 +03:00
Aaro Altonen ffa7ed5770 Fix RTP/RTCP authentication tag length
The tag is truncated from 20 bytes to 4 bytes
2020-09-03 10:59:26 +03:00
Aaro Altonen 1efc8b6049 Store pointer to the datagram in the rtp_frame structure
Auxiliary handlers may need access to the original block of memory
(such as SRTP) so instead of relaying that parameter to every handler,
store pointer to the block inside the RTP frame. The pointer is valid
as long as the packet is being processed and the last handler should
set it to nullptr.

Some changes to the public frame should be made because a lot of
the fields in the frames used by uvgRTP are not important outside
the library.
2020-09-03 08:34:58 +03:00
Aaro Altonen de3e72e97f Implement RCE_SRTP_INPLACE_ENCRYPTION
By default uvgRTP assumes that the memory it gets from user is not
writable and if user doesn't explictly specify that the memory
is writable (RCE_SRTP_INPLACE_ENCRYPTION) or that encryption is
not necessary (RCE_SRTP_NULL_CIPHER), a copy of the memory block is
made before it is pushed into the frame queue.
2020-09-02 12:30:30 +03:00
Aaro Altonen 85bb4c6eef Create separate SRTP and SRTCP objects for each MediaStream 2020-09-02 11:55:34 +03:00
Aaro Altonen bb826570ef Separate Secure RTP code into SRTP and SRTCP
Create separate classes for SRTP and SRTCP because even though
they are quite similar, they require some different actions when
en/decrypting the packets and create a whole bunch of if-elses
is ugly
2020-09-02 10:07:20 +03:00
Aaro Altonen be74a58ab1 Remove terminate_self()
This function no longer serves any purpose
2020-08-26 15:54:47 +03:00
Aaro Altonen b1168d8175 Remove unused code from src/frame.cc
Remove all unused (de)allocation code from src/frame.cc and remove
the RTCP-related PACKED_STRUCT definitions from include/frame.hh
2020-08-26 15:53:41 +03:00
Aaro Altonen 8f55079e62 Fix RTCP BYE generation/reception code
Operate on a raw block of memory and remove all participants from
the active session that are indicated in the BYE packet by their SSRCs
2020-08-26 15:52:19 +03:00
Aaro Altonen e586a007be Fix RTCP APP generation/reception code
Operate on a raw block of memory, extract interesting fields from the
packet and create user-friendly struct for the APP packet that
can be queried using SSRC

Caller must remember to free the memory occupied by the APP payload
2020-08-26 15:36:56 +03:00
Aaro Altonen 2807ccc83b Fix RTCP SDES generation/reception code
Operate on a raw block of memory, extract interesting fields from the
packet and create user-friendly struct for the SDES packet that
can be queried using SSRC

Caller must remember to free the memory occupied by the SDES items
2020-08-26 15:34:06 +03:00
Aaro Altonen c90fdd8d5c Call vectored packet handlers in sendtov() 2020-08-26 15:34:03 +03:00
Aaro Altonen 49575ed1ca Fix RTCP Sender Report generation/reception code
Operate on a raw block of memory, extract interesting fields from the
packet and create user-friendly struct for the Sender Report that
can be queried using SSRC
2020-08-26 15:33:59 +03:00
Aaro Altonen 7992224325 Move SET_NEXT_FIELD_32 to include/util.hh 2020-08-26 15:33:57 +03:00
Aaro Altonen fc117e6eba Fix RTCP Receiver Report reception code
Craft user-friendly rtcp_receiver_report struct from the raw
message which can be fetched using SSRC
2020-08-26 15:33:52 +03:00
Aaro Altonen 47b17bb1d1 Handle incoming RTCP reports as raw memory blocks
PACKED_STRUCT is quite an ugly hack if it must be cross-platform
so better to process the incoming (and soon outgoing) RTCP data
as raw memory and craft user-friendly RTCP packets from those
memory blocks which do not including strict padding or truncated fields.
2020-08-26 07:33:02 +03:00
Aaro Altonen 09caee904f Relay RTP context flags to RTCP object 2020-08-25 09:14:34 +03:00
Aaro Altonen 5d680d454b Add example code for custom timestamping 2020-08-20 11:36:33 +03:00
Aaro Altonen b51fef61ee Merge branch 'security-fixes' into develop 2020-08-18 10:11:19 +03:00
Aaro Altonen 5dcb9e68ec Implement RTP packet authentication using the frame queue
The authentication tag for each packet is stored inside the active
transaction and they are destroyed when the transaction is deallocated.

This way neither Socket nor SRTP needs to worry about (de)allocation
of those tags.

The authentication tag occupies the last slot in the pkt_vec structure
of each packet so it's easily accessible for the security layer when
calculating the checksum and guaranteed to be there if
RCE_SRTP_AUTHENTICATE_RTP has been provided.
2020-08-18 09:38:16 +03:00
Aaro Altonen 12ac580290 Deprecate the single buffer based sendto(2) for RTP packets
All RTP packets use buf_vec/pkt_vec style I/O and thus the old
single buffer based approach is no longer needed.
2020-08-18 09:38:16 +03:00
Aaro Altonen 1a36eebc99 Use frame queue with all media formats
Move frame queue to Media object and implement the generic push API
using a frame queue

This change temporarily disable the fragmentation of generic frames
2020-08-18 09:38:16 +03:00
Aaro Altonen 079c3ab23c Implement cross-platform frame queue
Introduce buf_vec and pkt_vec structures which enable cross-platform
scatter/gather I/O. This supersedes the previous Linux-only mmsghdr
hack. Buf_vec contains buffers of a single RTP frame
whereas pkt_vec contains multiple buf_vec structures that are sent
all at once when flush_queue() is called.

From now on all media formats should use frame queue to implement
RTP frame sending. This is because internally the frame queue
updates RTP header information and it can inject additional fields
to the RTP frame such as an authentication tag.
2020-08-18 09:38:16 +03:00
Aaro Altonen bfc6283f91 Pass RTP context flags to frame queue 2020-08-18 09:38:16 +03:00
Aaro Altonen ef2a27e3b6 Remove all SRTP-related code from src/socket.cc
SRTP functionality is provided to packet handlers
2020-08-18 09:38:16 +03:00
Aaro Altonen b6595822cb Fix warnings 2020-08-18 09:38:16 +03:00
Aaro Altonen 6b5ec3b5c0 Create socket as a pointer in src/media_stream.cc
All the other MediaStream objects are pointers and they also
only accept the socket as a pointer so it makes sense to covert
that to a pointer
2020-08-18 09:38:16 +03:00
Aaro Altonen 0bbe6966f1 Implement decryption handler for SRTP 2020-08-18 09:38:16 +03:00
Aaro Altonen 359e84076c Implement encryption/authentication handlers for SRTP 2020-08-18 09:38:16 +03:00
Aaro Altonen 9060ec9859 Merge SRTP context and SRTP key context structures
Packet handlers need both general context and session keys so it's
easier to store both in one struct. Keys are anyways part of
the larger context.
2020-08-18 09:38:16 +03:00
Aaro Altonen 29d274d72b Fix Media Stream initialization when ZRTP is used 2020-08-18 09:38:16 +03:00
Aaro Altonen 007ba4cb5c Move ZRTP packet handler to src/zrtp.cc 2020-08-18 09:38:16 +03:00
Aaro Altonen 953621eca8 Rename role enums for RTCP and ZRTP 2020-08-18 09:38:16 +03:00
Aaro Altonen 34b07066b3 Implement RTCP sender packet handler
This handler only grabs the packet size and changes the role
from receiver to sender if that hasn't been done yet
2020-08-15 04:05:42 +03:00
Aaro Altonen 906f6e6853 Implement packet handler support for outgoing frames
uvgRTP can install handler f.ex. for collecting RTCP sender statistics
information or to install SRTP encryption handler.

This way these unrelated objects don't have to be passed to src/socket.cc
and it will only contain code pertaining to actual socket operations
2020-08-15 04:05:42 +03:00
Aaro Altonen 9ee2318384 Remove low-level socket handlers
This kind of functionality is now provided by RTP packet dispatcher
for receive-functionality and similar kind of send functionality
is implemented very soon
2020-08-15 04:05:42 +03:00
Aaro Altonen ad4edc9747 Refactor RTCP code
Move RTCP runner related code to a separate file for clarity and
reorder code in src/rtcp.cc to move related code close to each other
2020-08-15 04:05:42 +03:00
Aaro Altonen 034315a013 Implement RTCP packet handler 2020-08-15 04:05:42 +03:00
Aaro Altonen 863d3a825e Add optional argument for auxiliary packet handlers
Some packet handlers (such as RTCP) may need access to the parent
object or they may require some additional data from outside the
packet handler that is required when processing the packet.
2020-08-15 04:05:42 +03:00
Aaro Altonen 7927f3682d Simplify RTCP code 2020-08-15 04:05:42 +03:00
Aaro Altonen d98757758c Split RTCP code into different files
Having a 1100 lines long file is not manageable so split RTCP
code into different files by packet type and leave all the
session-related code to src/rtcp.cc
2020-08-15 04:05:42 +03:00
Aaro Altonen f964201c12 Separate packet handlers into primary and auxiliary
Because most packet handlers do not require the raw UDP datagram
received through the socket, it makes little sense to relay those
parameters to them.

Additionally, there's a clear distinction between crafting
an RTP frame and operating on it so having one handler type
for both operations is not the best design choice.

Thus the packet handlers are divided into primary and auxiliary
handlers. Primary handlers are responsible for creating a packet
that the auxiliary handlers can operate on and auxiliary handlers
are responsible for doing all other operations on the packet such as
gathering sessions statistic information or decrypting the packet.
2020-08-15 04:05:42 +03:00
Aaro Altonen d06eed5833 Create RTCP for the media stream unconditionally
RTCP is used to gather session statistics and detect SSRC collisions
so all packets should be relayd to the RTCP layer for monitoring
even if RTCP packets are not being sent.

If RTCP Sender/Receiver reports are needed, RCE_RTCP should be given
when creating a media stream.
2020-08-15 04:05:42 +03:00
Aaro Altonen fb4c781233 Remove Opus code from the project 2020-08-15 04:05:42 +03:00
Aaro Altonen 529544cc81 Use RTP context to determine payload type in src/queue.cc 2020-08-15 04:05:42 +03:00
Aaro Altonen effc2f7b22 Exit from RTP packet dispatcher gracefully
Indicate to the main thread through a mutex that the packet dispatcher
object can be destroyed. If this is not done, there's race condition
that can result into a segmentation fault as the dispatcher object
could be destroyed before it stops running.
2020-08-15 04:05:42 +03:00
Aaro Altonen b9ea6558d5 Implement frame return functionality 2020-08-15 04:05:42 +03:00
Aaro Altonen ddef2b4c71 Do not pass socket reference to RTP packet dispatcher's constructor
Packet dispatcher does not need to store the socket because it
is passed to the actual runner when the packet dispatcher is started.

This also fixes a bug where the socket's destructor is called right
after the packet dispatcher's constructor
2020-08-15 04:05:42 +03:00
Aaro Altonen 1dd628d927 Start the RTP packet dispatcher in pkt_dispatch.cc 2020-08-15 04:05:42 +03:00
Aaro Altonen 96ba50a159 Fix includes in formats/media.hh 2020-08-15 04:05:42 +03:00
Aaro Altonen 95ebd4289d Spawn thread for RTP packet dispatcher 2020-08-15 04:05:42 +03:00
Aaro Altonen 42aeccfaa1 Implement RTP packet handler for generic frames
Remove the old generic interface and replace it with the push_frame()
implemented in some previous commit and with the new packet handler
implemented in this commit.

All media formats that do not require extra processing (such as Opus)
should use the generic interface.
2020-08-15 04:05:42 +03:00
Aaro Altonen f5a73f5b64 Pass RTP context flags to RTP packet dispatcher and handlers
Context flags may contain important information about how a packet
should be handled (such as RCE_FRAGMENT_GENERIC or RCE_HEVC_NO_INTRA_DELAY)
2020-08-15 04:05:42 +03:00
Aaro Altonen 3d0a77fb16 Move Media object code to formats directory 2020-08-15 04:05:42 +03:00
Aaro Altonen 9d820d5953 Implement RTP packet handler 2020-08-15 04:05:42 +03:00
Aaro Altonen 53e6c72d17 Implement memdup() utility function 2020-08-15 04:05:42 +03:00
Aaro Altonen 6b812cddc8 Add RTP packet dispatcher and Media object to Media Stream
Deprecate the old sender/receiver architecture from vanilla uvgRTP
and start using RTP packet dispatcher for incoming frames and Media
object for outgoing frames.
2020-08-15 04:05:42 +03:00
Aaro Altonen 9cc21ebf35 Implement push_frame() for HEVC 2020-08-15 04:05:42 +03:00
Aaro Altonen 3eb02207d9 Add ability to return an RTP frame from packet handler
When a complete RTP frame has been received, the packet handler
must return the frame to RTP packet dispatcher which then returns
the frame to user either through frame queue or receive hook
2020-08-15 04:05:42 +03:00
Aaro Altonen 2bbe34924f Remove RTP receiver
Media objects and RTP packet dispatcher shall perform all the needed
functionality of RTP receiver in the near future.
2020-08-15 04:05:42 +03:00
Aaro Altonen 08bb44207d Implement pull_frame() for RTP packet dispatcher 2020-08-15 04:05:42 +03:00
Aaro Altonen d721a52a3d Add receive hook to RTP packet dispatcher 2020-08-15 04:05:42 +03:00
Aaro Altonen 9e49ad4b09 Remove old send interface
This interface was hardly used and it provided very little benefit
over using the socket API directly.
2020-08-15 04:05:42 +03:00
Aaro Altonen 8f0e746e59 Introduce Media object
Media is the base class from which all other media formats inherit
the common operations.

Media object contains two push_frame()s: one for normal pointers and
one for smart pointers. It also contains a packet handler which is
called by the RTP packet dispatcher when a UDP datagram is received.

All media formats must implement packet_handler() and __push_frame()
methods. If the media media format does not require any extra processing
(such as Opus), it can directly use the Media object and its implementation
of __push_frame() and packet_handler().

Media object implements the generic interface which supports sending
any kind of data and a uvgRTP-specific way of fragmenting/reconstructing
generic RTP frames which can be enabled with RCE_FRAGMENT_GENERIC.
2020-08-15 04:05:42 +03:00
Aaro Altonen 2c4b02dfa6 Remove RTP sender
Media-specific object is going to handle all send operations in the near
future, thus deprecating sender
2020-08-15 04:05:42 +03:00
Aaro Altonen e2c4006972 Pass socket and RTP context to frame queue
Only RTP context and socketa are needed for the operations performed
by the frame queue so passing them to a constructor is much simpler
than passing sender to every function call and accessing the
context/socket through that.
2020-08-15 04:05:42 +03:00
Aaro Altonen 3312a0b559 Add getter for RTP payload format 2020-08-15 04:05:42 +03:00
Aaro Altonen 157b21a05c Create ZRTP packet handler 2020-08-15 04:05:42 +03:00
Aaro Altonen 14ecd34fdd Implement RTP packet dispatcher
Packet dispatcher is responsible for doing receive-related socket operations
and dispatching the received UDP datagram to the installed packet handlers.

Packet dispatcher goes through all installed handlers until a suitable
handler for the packet is found.
2020-08-15 04:05:42 +03:00
Aaro Altonen 66a4c2a412 Create log_platform_error() utility function 2020-08-15 04:05:42 +03:00
Aaro Altonen 693c5331c3 Add support for RTP packet authentication
By default authentication is disabled for RTP but in can be enabled
by giving RCE_SRTP_AUTHENTICATE_RTP when creating a media stream.

When security layer gets a packet, outgoing or incoming, it will add
an authentication tag to the packet or verify the tag, respectively.

This implementation is not perfect. The largest issue is
that there is no proper packet dispatcher so late ZRTP packets
can cause some real trouble.

This and a few other issues will be addresses later on when the
architecture of packet reception and the whole socket layer is improved.
2020-08-15 04:05:42 +03:00
Aaro Altonen 484c626ba4 Pass context flags directly to SRTP 2020-08-15 04:05:42 +03:00
Aaro Altonen 1a3dd9ca43 Store maximum payload size to RTP context
Store the size to context because different streams may have different
maximum payload sizes. For example, an SRTP stream with RTP authentication
enabled has a smaller payload size than a normal RTP stream.
2020-08-15 04:05:42 +03:00
Aaro Altonen 77fc7df078 Add support for SRTP NULL cipher 2020-08-15 04:05:42 +03:00
Aaro Altonen 61f7ef0416 Update SRTP code 2020-08-15 04:05:42 +03:00
Aaro Altonen 0d033cda59 Create TIME_DIFF macro 2020-08-15 04:05:42 +03:00
Aaro Altonen 00d10cd0b7 Add Multistream mode key generation 2020-08-15 04:05:42 +03:00
Aaro Altonen ffc24e6b49 Protect access to ZRTP state by a mutex 2020-08-15 04:05:42 +03:00
Aaro Altonen b1a072b9f0 Fix Preshared and Multistream names 2020-08-15 04:05:42 +03:00
Aaro Altonen e8b2947072 Give key agreement type for init_session() as a parameter 2020-08-15 04:05:42 +03:00
Aaro Altonen f4024dd730 Implement RTCP sender packet handler
This handler only grabs the packet size and changes the role
from receiver to sender if that hasn't been done yet
2020-08-12 11:47:12 +03:00
Aaro Altonen 49ddc269db Implement packet handler support for outgoing frames
uvgRTP can install handler f.ex. for collecting RTCP sender statistics
information or to install SRTP encryption handler.

This way these unrelated objects don't have to be passed to src/socket.cc
and it will only contain code pertaining to actual socket operations
2020-08-12 11:34:41 +03:00
Aaro Altonen 0cb55baaad Remove low-level socket handlers
This kind of functionality is now provided by RTP packet dispatcher
for receive-functionality and similar kind of send functionality
is implemented very soon
2020-08-12 11:08:14 +03:00
Aaro Altonen 7fae21db8c Refactor RTCP code
Move RTCP runner related code to a separate file for clarity and
reorder code in src/rtcp.cc to move related code close to each other
2020-08-12 10:18:57 +03:00
Aaro Altonen c05eadbced Implement RTCP packet handler 2020-08-10 12:11:59 +03:00
Aaro Altonen d32b2b82b9 Add optional argument for auxiliary packet handlers
Some packet handlers (such as RTCP) may need access to the parent
object or they may require some additional data from outside the
packet handler that is required when processing the packet.
2020-08-10 08:58:23 +03:00
Aaro Altonen 3ee835a305 Simplify RTCP code 2020-08-06 13:03:18 +03:00
Aaro Altonen 6067a2ed18 Split RTCP code into different files
Having a 1100 lines long file is not manageable so split RTCP
code into different files by packet type and leave all the
session-related code to src/rtcp.cc
2020-08-06 10:39:54 +03:00
Aaro Altonen 39e9b07726 Separate packet handlers into primary and auxiliary
Because most packet handlers do not require the raw UDP datagram
received through the socket, it makes little sense to relay those
parameters to them.

Additionally, there's a clear distinction between crafting
an RTP frame and operating on it so having one handler type
for both operations is not the best design choice.

Thus the packet handlers are divided into primary and auxiliary
handlers. Primary handlers are responsible for creating a packet
that the auxiliary handlers can operate on and auxiliary handlers
are responsible for doing all other operations on the packet such as
gathering sessions statistic information or decrypting the packet.
2020-08-06 08:43:18 +03:00
Aaro Altonen 9a59dd0cc8 Create RTCP for the media stream unconditionally
RTCP is used to gather session statistics and detect SSRC collisions
so all packets should be relayd to the RTCP layer for monitoring
even if RTCP packets are not being sent.

If RTCP Sender/Receiver reports are needed, RCE_RTCP should be given
when creating a media stream.
2020-08-06 07:39:55 +03:00
Aaro Altonen 9cba1af32a Remove Opus code from the project 2020-08-06 07:39:55 +03:00
Aaro Altonen 5cc862ac9d Use RTP context to determine payload type in src/queue.cc 2020-08-06 07:39:41 +03:00
Aaro Altonen eb33b7edf7 Exit from RTP packet dispatcher gracefully
Indicate to the main thread through a mutex that the packet dispatcher
object can be destroyed. If this is not done, there's race condition
that can result into a segmentation fault as the dispatcher object
could be destroyed before it stops running.
2020-08-06 07:39:41 +03:00
Aaro Altonen bdfe027352 Implement frame return functionality 2020-08-06 07:39:41 +03:00
Aaro Altonen d70c077d77 Do not pass socket reference to RTP packet dispatcher's constructor
Packet dispatcher does not need to store the socket because it
is passed to the actual runner when the packet dispatcher is started.

This also fixes a bug where the socket's destructor is called right
after the packet dispatcher's constructor
2020-08-05 09:50:23 +03:00
Aaro Altonen f938750194 Start the RTP packet dispatcher in pkt_dispatch.cc 2020-08-05 09:10:16 +03:00
Aaro Altonen b1d73dad36 Fix includes in formats/media.hh 2020-08-05 09:09:33 +03:00
Aaro Altonen 0dd3d67655 Spawn thread for RTP packet dispatcher 2020-08-05 08:18:29 +03:00
Aaro Altonen 4b9f06acd4 Implement RTP packet handler for generic frames
Remove the old generic interface and replace it with the push_frame()
implemented in some previous commit and with the new packet handler
implemented in this commit.

All media formats that do not require extra processing (such as Opus)
should use the generic interface.
2020-08-04 13:28:26 +03:00
Aaro Altonen 43e0452bfa Pass RTP context flags to RTP packet dispatcher and handlers
Context flags may contain important information about how a packet
should be handled (such as RCE_FRAGMENT_GENERIC or RCE_HEVC_NO_INTRA_DELAY)
2020-08-04 13:10:54 +03:00
Aaro Altonen e92529bf41 Move Media object code to formats directory 2020-08-04 11:32:50 +03:00
Aaro Altonen 4af15727cf Implement RTP packet handler 2020-08-04 10:43:56 +03:00
Aaro Altonen 494765a2fa Implement memdup() utility function 2020-08-04 10:16:38 +03:00
Aaro Altonen 574580c0f8 Add RTP packet dispatcher and Media object to Media Stream
Deprecate the old sender/receiver architecture from vanilla uvgRTP
and start using RTP packet dispatcher for incoming frames and Media
object for outgoing frames.
2020-08-04 08:53:27 +03:00
Aaro Altonen 858ac54b13 Implement push_frame() for HEVC 2020-08-04 08:39:12 +03:00
Aaro Altonen 91a12af92d Add ability to return an RTP frame from packet handler
When a complete RTP frame has been received, the packet handler
must return the frame to RTP packet dispatcher which then returns
the frame to user either through frame queue or receive hook
2020-08-04 08:39:12 +03:00
Aaro Altonen 7e16140e85 Remove RTP receiver
Media objects and RTP packet dispatcher shall perform all the needed
functionality of RTP receiver in the near future.
2020-08-04 08:39:12 +03:00
Aaro Altonen c2bdf3a4fd Implement pull_frame() for RTP packet dispatcher 2020-08-04 08:39:12 +03:00
Aaro Altonen fc597fd2f8 Add receive hook to RTP packet dispatcher 2020-08-04 08:39:12 +03:00
Aaro Altonen 00259dbcc7 Remove old send interface
This interface was hardly used and it provided very little benefit
over using the socket API directly.
2020-08-04 08:39:08 +03:00
Aaro Altonen 3519378821 Introduce Media object
Media is the base class from which all other media formats inherit
the common operations.

Media object contains two push_frame()s: one for normal pointers and
one for smart pointers. It also contains a packet handler which is
called by the RTP packet dispatcher when a UDP datagram is received.

All media formats must implement packet_handler() and __push_frame()
methods. If the media media format does not require any extra processing
(such as Opus), it can directly use the Media object and its implementation
of __push_frame() and packet_handler().

Media object implements the generic interface which supports sending
any kind of data and a uvgRTP-specific way of fragmenting/reconstructing
generic RTP frames which can be enabled with RCE_FRAGMENT_GENERIC.
2020-08-03 10:10:29 +03:00
Aaro Altonen 86837e82d5 Remove RTP sender
Media-specific object is going to handle all send operations in the near
future, thus deprecating sender
2020-08-03 10:07:45 +03:00
Aaro Altonen 95f103eac1 Pass socket and RTP context to frame queue
Only RTP context and socketa are needed for the operations performed
by the frame queue so passing them to a constructor is much simpler
than passing sender to every function call and accessing the
context/socket through that.
2020-08-02 13:19:07 +03:00
Aaro Altonen e8da36b113 Add getter for RTP payload format 2020-08-02 10:50:12 +03:00
Aaro Altonen a5c8adde48 Create ZRTP packet handler 2020-08-01 15:15:53 +03:00
Aaro Altonen ff583c3cdd Implement RTP packet dispatcher
Packet dispatcher is responsible for doing receive-related socket operations
and dispatching the received UDP datagram to the installed packet handlers.

Packet dispatcher goes through all installed handlers until a suitable
handler for the packet is found.
2020-08-01 15:15:49 +03:00
Aaro Altonen 5a53f8d563 Create log_platform_error() utility function 2020-07-31 12:42:18 +03:00
Aaro Altonen 7c2142dddf Merge branch 'secure-rtp' into develop 2020-07-31 11:29:24 +03:00
Aaro Altonen b1a48f6b2c Add support for RTP packet authentication
By default authentication is disabled for RTP but in can be enabled
by giving RCE_SRTP_AUTHENTICATE_RTP when creating a media stream.

When security layer gets a packet, outgoing or incoming, it will add
an authentication tag to the packet or verify the tag, respectively.

This implementation is not perfect. The largest issue is
that there is no proper packet dispatcher so late ZRTP packets
can cause some real trouble.

This and a few other issues will be addresses later on when the
architecture of packet reception and the whole socket layer is improved.
2020-07-31 09:56:06 +03:00
Aaro Altonen 74cf102df2 Pass context flags directly to SRTP 2020-07-30 19:19:20 +03:00
Aaro Altonen dc494747a4 Store maximum payload size to RTP context
Store the size to context because different streams may have different
maximum payload sizes. For example, an SRTP stream with RTP authentication
enabled has a smaller payload size than a normal RTP stream.
2020-07-30 14:03:28 +03:00
Aaro Altonen 7d31f0ba08 Add support for SRTP NULL cipher 2020-07-30 11:47:11 +03:00
Aaro Altonen 3207713c24 Update SRTP code 2020-07-30 09:41:01 +03:00
Aaro Altonen 568b40a70b Create TIME_DIFF macro 2020-07-28 10:35:21 +03:00
Aaro Altonen e12a329fbc Add Multistream mode key generation 2020-07-23 13:21:27 +03:00
Aaro Altonen ef0c074d80 Protect access to ZRTP state by a mutex 2020-07-23 13:05:55 +03:00
Aaro Altonen ec30260763 Fix Preshared and Multistream names 2020-06-26 08:19:38 +03:00
Aaro Altonen 8d786d1217 Give key agreement type for init_session() as a parameter 2020-06-26 08:18:55 +03:00
Aaro Altonen 5217d42814 Add RTCP support to RTP receiver
Receiver calls RTCP after every received frame to update
session statistics
2020-06-18 09:33:41 +03:00
Aaro Altonen 73f5c4a35a Add ability to create unidirectional senders/receivers
This may be useful in situations where a user wishes to join a
conference call but does not wish to send any data only receiver or
vice versa.

This unidirectionality will also dictate the role for the media_stream's
RTCP object
2020-06-17 08:23:50 +03:00
Aaro Altonen 06f2891b86 Create RTCP gettter 2020-06-17 07:55:47 +03:00
Aaro Altonen b243d7d47e Remove RTCP forwards from media_stream
RTCP state should be modified only through the RTCP object allocated
for each media_stream
2020-06-17 07:55:02 +03:00
Aaro Altonen a522c81324 Add RTCP support for media_stream 2020-06-16 06:41:16 +03:00
Aaro Altonen 2af23d653e Add get_clock_rate() to rtp.cc 2020-06-16 06:41:14 +03:00
Aaro Altonen c997a94c2a Add ability to use custom timestamps for media
Instead of using uvgRTP's internal RTP timestamps, let user specify
timestamp for the media when push_frame() is called.

Instead of propagating the timestamp through the send stack, store
the timestamp value temporarily to the RTP context of the media
stream and reset it after push_frame() is done.

User should not mix and match uvgRTP's internal RTP timestamps with
custom timestamps so either all of the calls or none of the calls should
given a timestamp to push_frame().

Custom timestamps should be increased in accordance with the media clock
rate, otherwise problems may occur with media reception.
2020-06-02 08:25:34 +03:00
Aaro Altonen 574592cb10 Make System Call Clustering optional 2020-05-28 12:41:08 +03:00
Aaro Altonen 7b73aede33 Add pull_frame(timeout)
Instead of blocking until the library is destroyed, add ability
to block at most N milliseconds before returning.

The code returns early if a frame is received within the specified
timeframe but will block at most "timeout "milliseconds
2020-05-11 17:36:13 +03:00
Aaro Altonen 867aa02dbd Rename debug() to uvgrtp_debug()
Prevent name clahes with other software, debug is after all
quite a common symbol name
2020-05-06 06:46:13 +03:00
Aaro Altonen c2438e3017 Add support for user-managed SRTP session
Because the architecture has changed a bit, the context is initialized
only after add_srtp_ctx() has been called to prevent the user from
sending unencrypted messages.
2020-04-30 01:45:28 +03:00
Aaro Altonen 649be450e5 Enable runtime configuration functionality
Remove old context configuration flags that are no longer used,
convert configure_ctx() to work as a handler for all RCC_* flags
and use default values in sender/receiver/queue during initialization
2020-04-28 11:18:13 +03:00
Aaro Altonen c62194aea2 Add ability to specify custom payload type 2020-04-28 11:18:13 +03:00
Aaro Altonen c2e7eb1bc1 Rename kvzRTP to uvgRTP 2020-04-28 11:18:07 +03:00
Aaro Altonen df4c96c072 Removed unused Opus function 2020-04-27 12:57:00 +03:00
Aaro Altonen 29749c3623 Create RCE_INPLACE_ENCRYPTION flag
This flag indicates to kvzRTP that the input data given to push_frame()
is writable and the encryption can be done in-place.

By default kvzRTP assumes that the input cannot be modified and creates
a copy of the input data.
2020-04-27 12:22:28 +03:00
Aaro Altonen 98404d9316 Increase the MAX_PAYLOAD to 1443
There's 2 bytes left in the budget after all media headers
2020-04-26 21:04:28 +03:00
Aaro Altonen 5cedd36641 Add ability to fragment/reconstruct generic frames 2020-04-24 21:51:12 +03:00
Aaro Altonen 082372fba1 Merge RTP context configuration flags into one enum
Having separate enums for general configuration and media configuration
might be too confusing given that they are passed to kvzRTP using same
variable and the configuration values must not clash with each other
so the second enum's values would have to start from RCE_LAST which
might look weird
2020-04-24 21:51:12 +03:00
Aaro Altonen 8409706749 Create separate include directory
Create separate include directory which follows the kvzRTP include
style to make it easy for external applications to use kvzRTP
2020-04-22 04:58:41 +03:00