pion / rtp

A Go implementation of RTP
https://pion.ly/
MIT License
349 stars 111 forks source link

Optimize the performance of H264 packaging #239

Closed ziminghua closed 11 months ago

ziminghua commented 12 months ago

Optimize the performance of H264 packaging

Description

Sending package H264 in my program is quite performance intensive. Then through ppfrof, it was found that the range of nalu is relatively slow, and it will create slices multiple times. Use bytes.Index lookup index can significantly improve performance

Before: image

After: image

Sean-Der commented 12 months ago

Great change @ziminghua!

It is possible to support both start codes? https://learn.microsoft.com/en-us/windows/win32/directshow/h-264-video-types#h264-bitstream-with-start-codes

ziminghua commented 12 months ago

Sorry, I didn't consider annex B originally, so I optimized the original performance. If I want to support both start codes, I think this is possible.

ziminghua commented 11 months ago

@Sean-Der Hello, what do you think of the current update.

Sean-Der commented 11 months ago

@ziminghua great work! Lets merge it. I am out of time, I will merge first thing tomorrow

Code is much easier to read also :)

codecov[bot] commented 11 months ago

Codecov Report

Patch coverage is 100.00% of modified lines.

Files Changed Coverage
codecs/h264_packet.go 100.00%

:loudspeaker: Thoughts on this report? Let us know!.

Sean-Der commented 11 months ago

@ziminghua I tagged v1.8.2 so you can use this now! Thank you so much for the contribution :)