-
Notifications
You must be signed in to change notification settings - Fork 439
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
Allow for more than 32 tracks per media type #1290
Conversation
c465b3e
to
8466721
Compare
If we want to support more than 64 tracks, we need a bitset type. There are two approaches:
The dynamic approach is very elegant, especially since there are no templates in C so that the static bitset would probably be a macro mess. @erankor What are your thoughts on this? Do we need to create some benchmarks? |
Question is whether we actually need more than 64, it sounds like quite a lot to me... Few small comments regarding the existing PR (most are irrelevant if you implement for >64...) -
|
I agree that most won’t need more than 64 tracks. Static limit it is then👍 |
8466721
to
e6e9219
Compare
I revised the existing PR and replaced the track masks with an array (like it has been with the language masks before). Although it's a lot of changes and additions, the compiler is able to optimise most of it out - especially for a max track count of 64 (which fits in a single register) |
e6e9219
to
2e2fa82
Compare
I rebased and added the bitset test to the new CI pipeline. |
@JoelLinn, I briefed through the changes, and while the code seems well written, it is more complex than I'd want it to be...
|
I agree with @erankor's points. I don't think this code runs on many 32bit archs and I feel these are quite rare in general nowadays.. We shouldn't break functionality of course, but slower exec in favour of cleaner/simpler code flows is a well justified trade off, IMHO. |
2e2fa82
to
0ce8bbe
Compare
I switched to uint64_t and removed the residual handling. Added an error for |
0ce8bbe
to
d99fde9
Compare
Integrated the requested changes, I hope I didn't miss anything. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JoelLinn added a few more comments, after these are fixed, will need to run regression tests, and then we should be able to merge
d99fde9
to
9500a0e
Compare
Pushed changes. |
Any results from the regression tests yet? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JoelLinn the regression tests completed successfully!
However, I reviewed the whole thing again now, and have a couple of small comments.
We're getting there... :)
- Better efficiency by using larger type - Additional macros/functions - Convert uses for language mask
- for masks, use bitset based on array - default to 64 tracks (masks fit into single integer on 64-bit systems)
9500a0e
to
a938b34
Compare
Relieved to hear there were no regressions... |
Merged, thanks! |
Thanks for putting the work into the reviews. 👍 |
The track selection is handled by a bit mask.
This mask was 32 bit wide so the maximum number of streamable tracks was limited to 32.
If the video contained more tracks, the logic in mp4_parser.c:2867 would wrap and try to stream more than one track at once for indexes greater than 31.
This patch uses an array of
uint64_t
as bitmask.The maximum number of tracks is selected at compile time. It can be increased by adding
-DNGX_VOD_MAX_TRACK_COUNT=256
to the cc configuration options and defaults to 64. (This mechanism is used by other nginx modules as well, for example lua.)A number of macros and inline functions was added to the header which already defined the existing bitset macros. They are needed to simplify operations like
(mask1 & mask2) != 0
. With-O2
or greater they are optimized and the mentioned operation compiles to only 3 x86 instructions (for up to 256 tracks) if vector extensions are enabled (-mavx2
).I had to add a typedef for the track mask array in order to avoid array type decay when using multi dimensional arrays as function parameters (like
size_t tracks_mask[MEDIA_TYPE_COUNT][MASK_ARRAY_SIZE]
).With the python script
generate_many_tracks.py
it's possible to create a mp4 with many language tracks (≈600), which I successfully tested withNGX_VOD_MAX_TRACK_COUNT=640
and the dash reference client (vlc seems to have a bug with such a high number of tracks). Not that we need that amount of tracks but the test should prove that this PR fixes the underlying issue for good.Old text: