-
Notifications
You must be signed in to change notification settings - Fork 9
Enhance memory management and reliability in RTSP server #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
3b3c63d
to
8a24609
Compare
When it comes to SharpOnvifServer library changes, the only concern I have regarding these new APIs is the netstandard2.0 (in)compatibility. It might require using a polyfill such as https://github.com/[meziantou/Meziantou.Polyfill](https://github.com/meziantou/Meziantou.Polyfill) - this should be the same one SharpRTSP is already using, so it will not introduce any additional dependency if possible. |
Making these changes helps me understand the library. 😄 |
Hy @jimm98y, can you have a look at this? There's some extra copying, but it's all pooled and preserves memory ownership. |
7bdd55b
to
5645c18
Compare
Awesome work, thank you very much! I'll have to try it out and understand how it works before merging it, I hope to get to later this week, or early next week. Just one minor thing I noticed by briefly looking at the changes: using System.Drawing; in ProxyTrack.cs was probably not intentional :) |
I've submitted ngraziano/SharpRTSP#136. This will make it easier for this library.
Definitely not intentional. |
- Replaced `List<byte[]>` with `ReadOnlySequence<byte>` for RTP packets and raw samples, enhancing memory management and performance. - Introduced `PooledByteBuffer` class implementing `IBufferWriter<byte>` for efficient byte data writing using an array pool. - Updated `CreateRtpPackets` method signatures to return `IByteBuffer`, streamlining the API and reducing memory overhead. - Modified `FeedInRawSamples` to accept `ReadOnlySequence<byte>`, improving flexibility in sample feeding. - Added `MemoryExtensions` class for utility methods related to `ReadOnlySequence<byte>`. - Improved error handling and logging consistency. - Refactored code for better readability, maintainability, and alignment with modern C# practices, including standardized `using` statements and the use of `Span<byte>`.
Fixed! |
I have a pending PR on SharpRTSP. I'll ping you when it's done. |
This might look a bit extreme, but the intention is to assure to the caller that the data provided won't be modified by using
ReadOnlySequence<byte>
instead ofList<byte[]>
and reduce memory allocated byITrack
implementations.Changes:
ReadOnlySequence<byte>
for better performance and memory efficiency.AdjustedSizeMemoryOwner
for effective memory allocation.ReadOnlySequence<byte>
, ensuring consistency and optimizing memory usage.RTPPacketUtil
to read timestamps fromReadOnlySpan<byte>
, enhancing performance.