Commit Graph

74 Commits

Author SHA1 Message Date
Aaro Altonen 3d0a77fb16 Move Media object code to formats directory 2020-08-15 04:05:42 +03:00
Aaro Altonen 2619b77e47 Implement HEVC packet handler 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 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 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 66a4c2a412 Create log_platform_error() utility function 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 4449a7a56f Don't complain about incoming ZRTP frames
Right after ZRTP has finished and the media reception has been started,
there may be a few ZRTP ACK/ConfACK messages coming in which are
perfectly valid.
2020-08-15 04:05:42 +03:00
Aaro Altonen 0b92776be6 Update session statistics after before returning the frame 2020-06-18 09:34:13 +03:00
Aaro Altonen 7b8d1f06ee Make sure prev_offset is not -1
If the frame doesn't contain any start codes (raw NAL units),
prev_offset is set to -1 by the first call to __get_hevc_start().
2020-06-05 14:25: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 a46c904de0 Make sure the HEVC frame is actually too large
Failing to check this caused an infrequent error where kvzRTP
started a fragmentation unit but because there was not enough bytes
it couldn't finish it and thus the receiver never returned the frame
to user because it only received the first fragment (which was the full
frame)
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 63bbd2408b Remove the SEQ(x) and TS(x) macros 2020-04-24 21:51:12 +03:00
Aaro Altonen 7ebf1410bc Remove the frames array from HEVC receiver 2020-04-24 21:51:12 +03:00
Aaro Altonen 44b15a68c9 Drop invalid inter frame fragments before frame construction
No point in allocating space for the frame and constructing it
from fragments just to drop it a few moments later
2020-04-23 12:30:27 +03:00
Aaro Altonen 796bcf2717 Drop invalid inter/intra frames only if intra delay is enabled 2020-04-23 12:30:27 +03:00
Aaro Altonen d889893ea4 Create inter frame even if intra is in progress
Dropping new inter frames when an intra is in progress is a little
too aggressive considering the intra might be finished by the time
all inter frame packets have been received so basically we would lost
a perfectly valid frame for no reason
2020-04-23 12:30:07 +03:00
Aaro Altonen 6ce84297d8 Do not return inter if intra is still in progress 2020-04-22 09:55:22 +03:00
Aaro Altonen 0ca027f0f7 Remember dropped frames
Store the timestamps of dropped frames so if later on a late packet
is received, a new frame entry is not created for it
2020-04-22 09:52:51 +03:00
Aaro Altonen d28ceba7bb Add short explanation for the intra variable 2020-04-22 09:49:33 +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
Aaro Altonen 9d73b81659 Rewrite kvzRTP's HEVC receiver
Overall code cleanup and removal of unnecessarily complex logic.
Now the RTP frame delays are more adaptive to Kvazzup's needs:
frame delay for intra frames is the intra period so intra frame
can be late f.ex. 2s seconds whereas inter frames must be received
within the 100ms limit or they are dropped.

This change should remove the gray screens completely

Also remove the global frame array for HEVC fragments and use
frame-specific map to store them. I noticed that with high-quality streams
the number of packets used by one frame was starting to be close to UINT16_MAX,
which caused kvzRTP to overwrite previous frames' fragments
with new fragments and thus dropping frames by itself. Now each frame
has its own fragment buffer so the frame size no longer matters
2020-04-21 16:37:48 +03:00
Aaro Altonen ea570f15ee Fix compiler warnings 2020-04-21 08:57:37 +03:00
Aaro Altonen 2e94da9962 Reset select() parameters before calling it on every iteration
At least on Windows (and possibly on Linux), FD_SET must be called
always before calling select() or else it won't work and on Linux
the struct timeval values are changed to relect the amount of time
spent waiting on the file descriptors.
2020-04-21 07:43:51 +03:00
Aaro Altonen ada16b4992 Create SEQ(x) and TS(x) macros
Crate macros for getting the sequence number and timestamp values
of RTP frames.
2020-04-17 08:19:21 +03:00
Aaro Altonen fc105da611 Fix the same runner-related race conditions in frame receivers 2020-04-08 11:38:37 +03:00
Aaro Altonen 41132e6ffc Increase the RTP frame delay to 100ms
34ms is too strict a deadline for some use cases. By increasing the
default frame delay to 100ms does not hurt the cases where the frames
are anyway received within 34 milliseconds but it also allows users
to stream at high resolutions/low QP values without recompling the library.

Making this adjustment dynamic based on timestamps of the packets is
a planned future task but this shall act as a bandaid until then.
2020-04-03 10:19:33 +03:00
Aaro Altonen bc6bfe7af0 Release all partial frames when the receiver is stopped 2020-03-20 10:25:37 +02:00
Aaro Altonen 1566a0e1eb Release memory of duplicate frames 2020-03-20 10:25:18 +02:00
Aaro Altonen ccceae2713 Deallocate the transaction after the frame has been sent 2020-03-20 10:24:22 +02:00
Aaro Altonen b522bb33a4 Decrease the select() timeout to 1000 us
This seems to work the best with high-quality video stream on Windows
2020-03-12 08:27:26 +02:00
Aaro Altonen 1c7c0ab0aa Set select() parameter correctly on every iteration
The socket must be set to the read_fds on every iteration or else
the select() will fail after the first try
2020-03-11 07:41:40 +02:00
Aaro Altonen 86cf34c6e7 Set Start and End flags properly on Windows
MinGW seems to employ some very aggressive optimizations that
sometimes create invalid packets because both Start and End
flags are set simultaneously.

This fixes the problem where an intra frame seems to be dropped
every now and then. Nothing was actually dropped but kvzRTP
received an invalid packet and thus discarded the whole frame

To be honest, I have no idea why this worked but it did anyway.
2020-03-11 07:33:15 +02:00
Aaro Altonen 26e6010f62 Use select()/MSG_DONTWAIT to implement non-blocking socket 2020-03-03 08:22:29 +02:00
Aaro Altonen 54c603478d Merge branch 'VisualStudioMeme' into 'master'
Visual studio meme

See merge request TIE/ultravideo/kvz-rtplib!1
2020-03-03 07:17:57 +02:00
Aaro Altonen ffeced2ff9 Return the generic frame to user
During refactoring, this line was commented but I forgot to uncomment
it when commiting the new architecture.

Now audio should work again
2020-02-25 09:49:04 +02:00
RLamm 8ab83b415c First version, which compiles with VS 2020-02-14 14:24:42 +02:00
Aaro Altonen ed937e9957 Put SRTP/ZRTP/all crypto behind __RTP_CRYPTO__ compile flag
The initial idea was to integrate Crypto++ to kvzRTP to make usage
very easy but as it turns out, the compilation of that library is quite
complex so it's better to use the Makefiles they provide.

This means that kvzRTP shall have one extra dependency IF application
wishes to use SRTP/ZRTP: Crypto++. The compilation and linking should
be quite straight-forward and if application wants to use SRTP/ZRTP
it must make the decision when kvzRTP is compiled by providing
-D__RTP_CRYPTO__ flag for the compiler and by adding -lcryptopp to
link list of the application.
2020-02-13 08:44:18 +02:00
Aaro Altonen 2a1e3d23be Merge branch 'develop' 2020-02-12 07:31:47 +02:00
Aaro Altonen a789d98220 Uncomment send code in formats/generic.cc
During refactoring these were commented out but I forgot to
uncomment them
2020-02-10 10:25:59 +02:00
Aaro Altonen 826db93907 Do not print error message if validate_rtp_frame() failed
The chances that ZRTP is enabled are quite high and because those
messages are received to the same socket as media, the error messages
would likely flood the log so better turn them off.
2020-02-10 10:24:26 +02:00
Aaro Altonen 4e9631f160 Remove connection object from the project
It has no longer any use, all the logic is split between media_stream,
receiver and sender.
2020-02-10 09:35:06 +02:00
Aaro Altonen 6d2b856c29 Redesign kvzRTP's architecture
Now for each call (or IP) there will be a separate session which
shall contain one or more multimedia streams. Each session has a
single ZRTP object and each multimedia session shall have a single
socket which both the sender and receiver use to enable hole punching
on all platforms.

Each multimedia stream shall also have a single SRTP instance which
derives keys from the common ZRTP session.
2020-02-07 12:22:58 +02:00
Aaro Altonen e6adc09751 Do not break from the loop if an invalid fragment is received
It is highly likely that an invalid fragment will be received so
stopping the receiver after that and restarting the call after each
invalid fragment is very user-hostile
2020-02-05 08:33:36 +02:00
Aaro Altonen 95a77e0108 Fix HEVC start code lookup
__get_hevc_start() read beyond the buffer bounds, now hopefully fixed
2020-02-04 12:07:05 +02:00
Aaro Altonen 7cf1c4d36d Make dynamic configuration connection-based
Making configuration global was moronic considering there are
different types of media streams per session (f.ex Opus and HEVC)
which have very different types of needs. For example, setting
receiver's UDP buffer size to 40 MB would make no sense for Opus.

Now each connection can be configured individually which is also
a needed feature for SRTP

This change reverted the changes made earlier to global API
2020-01-13 10:02:34 +02:00
Aaro Altonen d0f18d4864 Prepare kvzRTP for SRTP/SRTCP support
The security layer is injected between reading a datagram from OS and
RTP/RTCP payload processing so the obvious place for that layer is socket.

Make all recv/send function calls go through socket API so the security
layer function calls doesn't have to be copied everywhere
2020-01-10 10:30:47 +02:00
Aaro Altonen 66f6acd0eb Add Windows support for the latest changes 2020-01-09 10:10:58 +02:00