Commit Graph

432 Commits

Author SHA1 Message Date
Joni Räsänen 1c31592851 build: Rename files in anticipation of future wrappers
This way all the wrappers are gathered together if more show up.
2022-07-14 13:03:03 +03:00
Joni Räsänen f4461f6dc3 rtcp: APP and BYE compound packets
It is no longer possible to send APP packets alone as RFC 3550 does
not permit this. Instead they are sent together with SR and RR as they
are supposed to.
2022-07-14 09:30:27 +03:00
Joni Räsänen af1b94adbe rtcp: Remove duplicate function from API to set SDES items 2022-07-11 14:43:04 +03:00
Joni Räsänen 97baf19437 rtcp: Refactor rtcp so compound packets are read correctly 2022-07-09 17:41:54 +03:00
Joni Räsänen e8586e8550 rtcp: Add possibility for the user to provide SDES items 2022-07-09 13:36:13 +03:00
Joni Räsänen a08d92e848 rtcp: Move SR and RR construction to rtcp packets module 2022-07-08 09:53:49 +03:00
Joni Räsänen 55ce9aa419 rtcp: Move rtcp header construction to rtcp packets module 2022-07-07 19:51:13 +03:00
Joni Räsänen 8581ac512a rtcp: Refactor the encryption functions to common place 2022-07-07 19:32:44 +03:00
Joni Räsänen 2341238e7e rtcp: Get cname to rtcp for SDES packet 2022-07-07 19:29:08 +03:00
Guillaume GAUTIER 9e7e8e6b67 Limited C api wrapper 2022-07-07 11:58:47 +03:00
Joni Räsänen 0b7f4604c9 formats: Make reference discarding disabled by default 2022-07-07 10:55:40 +03:00
Joni Räsänen bca3bdb18e formats: Add RTP flag that can be used to disable SCL
This obsoletes the old RCE flag, that did not work.
2022-07-04 12:01:49 +03:00
Joni Räsänen 94293ea368 rtcp: Fix wrong type when saving jitter estimation
RFC 3550 A.8 says that jitter should be saved as float and sampled to
32-bit unsigned integer. This commit fixes this and seems to improve
the accuracy of jitter estimation (previously it often showed just
15 or 10).
2022-06-17 12:00:17 +03:00
Joni Räsänen 41af90b1cf rtcp: Use session bandwidth to calculate interval
This is not full implementation of RTCP interval calculation, but it is
a step in the right direction.
2022-06-17 12:00:17 +03:00
Joni Räsänen b7ff2777b5 formats: Have only one system of timeout in h26x
The garbage collection is now the only system of timing out frames, the
old one did not make sense to me.
2022-06-17 10:33:22 +03:00
Joni Räsänen 57f7440c80 formats: Increase timout 2022-06-17 10:29:46 +03:00
Joni Räsänen bfd6d3eff5 formats: Add frag for disabling no reference frame drops 2022-06-17 08:26:18 +03:00
Joni Räsänen 088fc585ed common: Add const qualifiers where applicable 2022-05-16 12:02:37 +03:00
Joni Räsänen a6f9afcd28 common: Add function for getting SSRC of media_stream
Came across needing to know the local SSRC when trying to separate
media streams from one another.
2022-05-16 10:52:55 +03:00
Joni Räsänen 519b535ecb rtcp: Improve thread safety in rtcp 2022-05-13 14:32:42 +03:00
Joni Räsänen a4b45ecd5f rtcp: Add unique_ptr interface to getting rtcp packets 2022-05-13 09:45:19 +03:00
Joni Räsänen 84c66b7c1c formats: Add a way to disable H26x SCL 2022-04-01 08:24:37 +03:00
Joni Räsänen 4ecfedcdc8 formats: Fix dropped frames based on size bug
The allowed payload sizes were calculated slightly incorrectly and
this caused frames with sizes near the allowed frame size to be not
sent or sent incorrectly. Now all these errors should be fixed.
2022-03-31 10:05:41 +03:00
Joni Räsänen 2fcdd3cc63 formats: Rename variables to reflect RFC specification
uvgRTP was using incorrect terms in few places which made the code more
difficult to understand. This commit fixes this by changing NAL header
(incorrect) to payload header (correct).
2022-03-29 14:55:13 +03:00
Joni Räsänen 3a9e3b1757 common: Remove runner class as it is not needed
Integrated runner into holepuncher since it was the only remaining class
still using it and they both are small classes where separation does more
harm than good.
2022-03-03 13:38:41 +02:00
Joni Räsänen 48bab5a54f common: Try releasing reserved memory
If a frame was caught in a buffer without querying by user, it would
not get deleted. This commit tries to free those frame buffers.
2022-03-03 13:28:10 +02:00
Joni Räsänen ced9ea4271 common: Use unique_ptr to manage holepuncher memory 2022-03-03 11:52:15 +02:00
Joni Räsänen 468e9d82e5 common: Use unique_ptr for managing memory of media_ 2022-03-03 11:48:50 +02:00
Joni Räsänen 737898d5dc common: Use unique_ptr for managing reception_flow memory 2022-03-03 11:43:26 +02:00
Joni Räsänen e62e59af9f common: Remove duplicate code in media_stream in init 2022-03-03 11:39:12 +02:00
Joni Räsänen 8e05f3dbc7 rtcp: Use shared_ptr to manage rtcp memory 2022-03-03 10:48:51 +02:00
Joni Räsänen 97317fed22 srtp: Use shared_ptr to manage srtp and srtcp memory 2022-03-03 10:44:04 +02:00
Joni Räsänen 32839127f4 common: Use shared_ptr for managing socket memory 2022-03-03 10:31:36 +02:00
Joni Räsänen de639fe861 common: Manage rtp memory using shared_ptr 2022-03-03 10:20:21 +02:00
Joni Räsänen cce653b9b7 common: Rename pkt_dispatch to reception_flow
The dispatching is what technique the class uses, but it does not
describe its responsibilities at all making it very hard to figure out
what role it plays in the architecture just by looking at the name.

Also removed all references to obsolete System call dispatcher
(different concept) in all the comments.
2022-03-03 09:16:09 +02:00
Joni Räsänen 06c14ace97 common: Add more debug prints to track lost packets 2022-03-01 12:24:49 +02:00
Joni Räsänen f4352358bb build: Separate common header file lib.hh from context class
With this separation, the user has the option of not including all
the classes with lib.hh, where as previously it was mandatory because
context is always needed.
2022-02-28 10:43:16 +02:00
Joni Räsänen 3437e194aa common: Remove extra ; from end of namespaces
This was correctly giving warnings with GCC --pedantic
2022-02-28 08:51:38 +02:00
Joni Räsänen f62ade9c70 Merge branch 'example_improvements'
# Conflicts:
#	CMakeLists.txt
#	src/formats/h264.hh
#	src/formats/h265.hh
#	src/formats/h266.hh
#	src/formats/h26x.cc
#	src/formats/h26x.hh
#	src/lib.cc
#	src/pkt_dispatch.hh
#	src/rtp.cc
#	uvgRTP.pro
2022-02-22 14:03:49 +02:00
Joni Räsänen 819d8acee8 common: Add missing memory include, fixes Linux build 2022-02-21 10:20:07 +02:00
Joni Räsänen d97079ffbb common: Use shared ptr for zrtp module 2022-02-07 10:42:37 +02:00
Joni Räsänen 5a7d8377d1 common: Print the library name in debug 2021-09-30 10:31:42 +03:00
Joni Räsänen 8f438c57d0 common: Vastly improve the pull_frame timing
The previous implementation had the pull_frame take around 20x longer
than what the user specifies (no matter how long the user specified.
Now the excess should only be max 30 ms, which is an improvement.
2021-09-16 12:04:38 +03:00
Joni Räsänen 5fe0116327 tests: Add initial unit tests
These tests are mostly just placeholders until something more
substantial is added. They are good tests, but it would be better to
also test the functions in different kinds of scenarios.

Note: the Crypto++ is causing problems in tests on Windows, because the
CMake is rerun often and this causes the Crypto++ linking to disappear.
2021-09-07 12:23:40 +03:00
Joni Räsänen ea55f655ea version: Rename header to follow same hh format as other headers 2021-09-02 12:28:53 +03:00
Joni Räsänen d5c2212b40 api: Adjust and fix version stuff
Update correct version number. Remove extra uvgrtp from file/function
names.
2021-08-30 15:25:29 +03:00
Joni Räsänen c265fdbd41
Merge pull request #68 from db-tech/CMakeRebuild
build: Completely Redesigned CMake files (#44)
2021-08-30 14:47:09 +03:00
Joni Räsänen 6a8880929d common: Make sure all linux compilers are covered 2021-08-27 11:35:23 +03:00
Joni Räsänen 3aedf8ccde build: Try to make Mac compilation more likely to succeed
I just switched all __linux to not _WIN32 in the hopes that Unix/Linux
API would be more likely to be found on Mac OS. This has not been
tested on Mac so it may or may not work.
2021-08-27 11:19:38 +03:00
dennis 837b58351e build: Completely Redesigned CMake files (#44)
Primary changes are:
- Versioning integrated in cmake build system with library for version usage in end user programs
- New minimum CMAke required version is 3.14
- Created install capabilities. Allows uvgRTP to be used in different scenarios for win and lin (mac-os still missing)
- Added testing environment with automatically fetched google test and some example test code.
- Added packaging capabilities (and some placeholders that have to be changed)
- Create Shared library with -DBUILD_SHARED_LIBS=TRUE
2021-08-08 22:18:40 +02:00
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