Commit Graph

1805 Commits

Author SHA1 Message Date
Aaro Altonen 3a11d18e03 Create functions for generating better random numbers
According to spec, simply calling random() is not enough without
initializing the state properly. We can tap into OS's entropy pool
and get good and secure random number using the platform-dependent
random() functions.

As a fallback, PSRNG of standard library is also initialize
though it should not be needed
2019-08-15 08:45:26 +03:00
Aaro Altonen 5c6d7ac97c Send sender reports only if there are other send participants 2019-08-15 07:57:57 +03:00
Aaro Altonen 4fd5490145 Update gitignore 2019-08-15 07:24:09 +03:00
Aaro Altonen e3fc05a13a Detect and resolve SSRC conflicts
If an SSRC conflic is detected, new SSRC must be generated and
all RTCP statistics zeroed out. The collision is detected for every
incoming RTP packet.
2019-08-14 10:26:15 +03:00
Aaro Altonen 4bf8104f7b Remove warnings 2019-08-14 09:14:28 +03:00
Aaro Altonen ac644ee90d Add support for extension headers
Required by the spec
2019-08-14 08:38:21 +03:00
Aaro Altonen 0e2343f1a8 Remove deprecated data pointer from RTP frame struct
RTP header is stored separately so the start of the data is
the start of payload too
2019-08-14 08:26:34 +03:00
Aaro Altonen 6d1412b11e Rewrite frame allocation
RTP header is no longer part of the payload so there's no need to
allocate space for it
2019-08-13 08:01:19 +03:00
Aaro Altonen 15a1fbc006 Give the socket object as parameter to installed handlers 2019-08-12 10:12:37 +03:00
Aaro Altonen 748a1d72f0 Check the validity of override function using assert 2019-08-12 10:03:16 +03:00
Aaro Altonen 654ba01700 Create unique frame receivers for different media types
HEVC requires a lot of processing per frame whereas generic and Opus
don't require almost any. Creating a separate frame receiver where
all media-specifc processing can be done is the cleanest solution.

This is especially needed because receiving HEVC requires finer control
on the receiving side (recvfrom/WSARecvFrom) but opus/generic don't
so they actually can't be processed by the same receiver.
2019-08-12 09:29:52 +03:00
Aaro Altonen a2503cfa7d Add ability to override the default send/recv functions
Some media types may require finer control over the sending/receiving
process.
2019-08-12 09:29:52 +03:00
Aaro Altonen 7e9f2d6b04 Unify Windows and Linux frame queue implementations 2019-08-12 09:29:49 +03:00
Aaro Altonen 5c752c94d2 Fix memory leaks in reader.cc 2019-08-10 10:01:23 +03:00
Aaro Altonen 414b712090 Rewrite Windows __recvfrom() implementation using Winsock 2019-08-10 07:44:10 +03:00
Aaro Altonen 5e4086d56b Fix frame queue implementation for Linux
The new frame receiver requires (as does the spec) that RTP packets
have unique RTP sequence numbers.

We must store separate RTP header for each fragment and update only
the RTP sequence of each packet. This creates some spatial overhead by it's
negligible considering we need only one system call per full HEVC frame
2019-08-09 12:13:38 +03:00
Aaro Altonen 5443765daa Remove the type from push_frame() routines
Type of the frame is already specified in namespace, no need to repeat
it
2019-08-09 08:42:46 +03:00
Aaro Altonen 5d957736c8 Enable win_get_last_error() 2019-08-09 08:09:36 +03:00
Aaro Altonen d85f9d3409 Set the socket buffer size to 65536
We don't know how large frames remote is sending us so increasing
the buffer size (default size is 8KB on Windows) should give us some
leeway.
Too small buffer causes the OS to drop packets.
2019-08-09 08:03:48 +03:00
Aaro Altonen d9665501bc Disable LOG_DEBUG() by default 2019-08-02 09:50:50 +03:00
Aaro Altonen 0629074684 Clear the frame vector in reader destructor 2019-08-02 09:50:41 +03:00
Aaro Altonen eaeb201617 Clear the connections gracefully in context desctructor
Looping through the map while deleting items from it was not a good idea
2019-08-02 08:11:57 +03:00
Aaro Altonen 3abdda48dd Fix windows erros 2019-07-30 10:53:28 +03:00
Aaro Altonen 034c8f6f15 Handle incoming frames more gracefully
Because UDP packets may not arrive in order, we need to reorder as
they're received. The problem of previous implementation was that
it assumed that packets were ordered correctly and if it detected
a "stray packet", it dropped the whole frame which was suboptimal

We also need to keep track of much time it has taken to receive
the fragments and if a certain threshold is crossed, discard the frame.

There's still room for improvement because now the incoming frame is
copied to a temporary RTP frame and when all fragments have been received,
these fragment are merged together to a larger RTP frame. This extra copy
should be eliminated.
2019-07-30 08:33:21 +03:00
Aaro Altonen 65adaa3a09 Increase the maximum payload size 2019-07-30 08:21:28 +03:00
Aaro Altonen 6c82f375de Update RTP session statistics for each send() 2019-07-30 07:36:33 +03:00
Aaro Altonen b16956d953 Update RTP sequence after each send
While there, disable the linux frame queue implementation for now.
I need think of a way to store a unique RTP sequence for each buffer
2019-07-27 09:17:22 +03:00
Aaro Altonen b5d07cc0eb Create function for updating RTP sequence of an RTP header buffer 2019-07-26 10:52:34 +03:00
Aaro Altonen 516bb70c8b Add license 2019-07-26 09:29:04 +03:00
Aaro Altonen 6caf52564a Update readme 2019-07-26 09:28:47 +03:00
Aaro Altonen 5292ffbec5 Move NTP and high-resolution clock to separate namespace
This makes the code look cleaner as now function names don't contain
information about the clock type.
2019-07-25 08:35:53 +03:00
Aaro Altonen f5bc6bb350 Remove useless warning 2019-07-24 12:23:14 +03:00
Aaro Altonen fb8d4a0397 Use the new send API on Windows 2019-07-24 10:18:37 +03:00
Aaro Altonen 291533b9ef Deallocate CSRC entries 2019-07-24 10:04:34 +03:00
Aaro Altonen 22a9deb222 Improve how incoming RTP frames are handled
Make sure that header is correct, copy the CSRCs if present, and
make sure padding is discarded if the frame has been padded

Extension checking missing
2019-07-24 10:04:09 +03:00
Aaro Altonen 839285b0dd Create new RTP Frame structure with separate header field 2019-07-24 09:51:26 +03:00
Aaro Altonen fa1c82fb0f Make sure the received RTP frame is valid 2019-07-23 09:06:47 +03:00
Aaro Altonen 46e0842d1f Save the outgoing address to private variable in queue.cc
This fixes the bug where outgoing address was saved to stack and
the msg_name pointer pointed to garbage when flush_queue() was called
2019-07-23 08:49:49 +03:00
Aaro Altonen 8760bd97ce Initially set the wall clock start to 0 2019-07-23 08:47:41 +03:00
Aaro Altonen 138d7e8271 Remove some warnings 2019-07-23 08:19:35 +03:00
Aaro Altonen 37d8ee9f1a Include RTP header size to frame total length 2019-07-22 09:26:11 +03:00
Aaro Altonen 942e6ce05c Send correct buffers in __sendtov() 2019-07-19 09:32:54 +03:00
Aaro Altonen 0ed923e5a0 Implement frame queue for windows
This isn't quite optimal solution just yet. All copying should be
deleted but that requires some extensive studying of the winsock
documentation and it has to do for now
2019-07-19 09:31:07 +03:00
Aaro Altonen 6b89c779d7 Create new send API
This API is used to send small messages. The message may consist of
several smaller buffers or it may just be one buffer containing all the
data.

The total size of buffers must not exceed the MAX_PAYLOAD limit
2019-07-18 12:11:15 +03:00
Aaro Altonen 9484444699 Create routines for sending multiple buffers at once
This is very similar to using frame queue but if there's no need for
caching the frames ie. all the needed buffers are ready, it easier to use these
functions than to enqeueu and then flush the queue
2019-07-18 11:55:21 +03:00
Aaro Altonen 07e2d822cf Add Winsock-related cleanup stuff 2019-07-16 11:47:58 +03:00
Aaro Altonen 4e54a0a8d2 Create helper function for printing the latest error on Windows 2019-07-16 11:43:38 +03:00
Aaro Altonen b919574be9 Use WSASendTo instead of WSASend
Because we're using unconnected sockets, the destination must be
defined explicitly
2019-07-16 11:37:17 +03:00
Aaro Altonen ec8619864e Disable ANSI colors on Windows 2019-07-16 10:37:18 +03:00
Aaro Altonen 4fe5b38caf Update library instructions 2019-07-16 10:14:01 +03:00