Commit Graph

759 Commits

Author SHA1 Message Date
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 35174d142c Remove double loop from __sendtov()
The loop accidentally processed the pkt_vec twice which in turn
sent twice as large RTP packets
2020-08-26 07:30:18 +03:00
Aaro Altonen 65affa16a5 Do not deinitialize the transaction twice
flush_queue() deinitializes the transaction before it returns
2020-08-26 07:28:06 +03:00
Aaro Altonen 7d7aac0c18 Remove packets from the transaction when it's completed 2020-08-26 07:18:55 +03:00
Aaro Altonen b832db00c3 Make sure the active transaction is not empty 2020-08-25 12:05:59 +03:00
Aaro Altonen 19ba6e1c5c Deprecate RTCP Receive Report support from src/frame.cc
The frame (de)allocation is handled internally by each message
handler and include/frame.hh shall only provide the structure
format for RTCP Receive Report.
2020-08-25 12:05:59 +03:00
Aaro Altonen 43cbc0bef3 Create RTCP Receiver Report manually
This makes it a little simpler to add support Secure RTCP later on,
enables us to deprecate the Receiver Report interface from src/frame.cc
and makes it automatically cross-platform (previously PACKED_STRUCT
was a GCC-only feature)
2020-08-25 12:05:56 +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 e1a28d095a Stop RTCP runner in MediaStream destructor 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 e4bc199c90 Fix Media Stream initialization when user-mananged keys are used 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 0ed771d562 Copy fields from correct packet for Receiver/Sender frames 2020-08-15 04:05:42 +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 7bf70b730c Fix RTCP example code 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 dd4bf1249e Create RTCP participant right away in src/media_stream.cc 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 9d893532b7 Fix double-free
The loop above that merges the RTP frames deallocates the latest frame
also so this extra free caused a segmentation fault
2020-08-15 04:05:42 +03:00
Aaro Altonen 875542e9d5 Use correct size for the final RTP frame 2020-08-15 04:05:42 +03:00
Aaro Altonen 7764f580f5 Install correct media handler for RTP packet dispatcher 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 9fc5bc2b87 Set out to null to indicate that the packet was handled 2020-08-15 04:05:42 +03:00
Aaro Altonen e1c8a43961 Update the total frame size for the first frame too 2020-08-15 04:05:42 +03:00
Aaro Altonen 6b1773eb42 Increase the sequence number after each sendto(2) 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