Enhance memory management and reliability in RTSP server#6
Enhance memory management and reliability in RTSP server#6paulomorgado wants to merge 1 commit intojimm98y:mainfrom
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 byITrackimplementations.Changes:
ReadOnlySequence<byte>for better performance and memory efficiency.AdjustedSizeMemoryOwnerfor effective memory allocation.ReadOnlySequence<byte>, ensuring consistency and optimizing memory usage.RTPPacketUtilto read timestamps fromReadOnlySpan<byte>, enhancing performance.