Refactored RTP forwarder internals as a core feature #3155
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As the title says, this PR refactors the internals of the RTP forwarders functionality, moving it away from the plugins where it was implemented (VideoRoom, AudioBridge) and to the core instead. Nothing changes with respect to the APIs and how you use them, they're still created and destroyed as before: it's how they're implemented under the hood that this PR impacts.
The main motivation for this effort is that there was a lot of duplicated code in the two plugins to implement what, apart from a few differences, really was the same thing. Moving the bulk of the code to the core as a new feature allowed us to clean up the AudioBridge and VideoRoom code considerably, since we now just have to invoke a couple of functions to do what before needed hundreds of lines of inline code. Most importantly, now that RTP forwarders are a functionality exposed by the Janus core, this means that it will be much easier to add RTP forwarders to other plugins as well, if needed, since we won't have to duplicate code once more; it also means that, at least in theory, RTP forwarders could be added at the core level too (e.g., for plugin-agnostic monitoring of streams), should a need come for that in the future.
Functionally speaking, as anticipated nothing should change with this patch. The only thing that did indeed change is that, with this new approach, you can't share the same encryption context across multiple RTP forwarders: this was a feature that someone in the past used for optimization purposes (for SRTP forwarders belonging to the same publisher, you encrypted the payload once and sent it to all destinations), but I'm not sure if anyone actually even knew it was a thing; to be honest, the simplification this patch gives us makes me thing it's not a big loss, especially considering it would be rare to have that many forwarders for the same source anyway (and SRTP shouldn't weigh too much anyway).
Apart from this, I tried to ensure that what both VideoRoom and AudioBridge were able to do before is still possible to do now. I've done a few functional tests and they all seemed to be fine. That said, I still need to make tests on some edge cases, mostly the ones involving the different ways you can do simulcast with RTP forwarders. Another important thing to validate before merging is that this won't introduce race conditions: in the VideoRoom, for instance, we had custom references in place when using RTCP support for forwarders, and with the RTCP thread now under the responsibility of the core rather than the plugin, we should double check that this won't cause any issues.
If you're on version
1.x
of Janus and you're using RTP forwarders for anything, please do take the time to test this feature and provide feedback. The sooner we know the changes are safe, the sooner we'll be able to merge it.