Skip to content

Commit

Permalink
Fix Frame::GetSamplesPerFrame when channels = 0
Browse files Browse the repository at this point in the history
This function is relying on the implementation defined
behavior of x86_64 to work properly.

On x86_64,  `fmod` returns -NaN when `channels = 0`, it is handled by
`if (samples_per_frame < 0)`.

But on other architectures(like riscv64), `fmod` may return a positive
NaN which will cause this function to return a bad value.

It is causing several tests to spin forever on riscv64.

This PR fixes it by directly return 0 when `channels == 0` so that we do
not need to deal with NaNs.
  • Loading branch information
kxxt committed May 30, 2023
1 parent e91bd82 commit bc73ede
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ void Frame::SetFrameNumber(int64_t new_number)
// Calculate the # of samples per video frame (for a specific frame number and frame rate)
int Frame::GetSamplesPerFrame(int64_t number, Fraction fps, int sample_rate, int channels)
{
// Directly return 0 if there are no channels
// so that we do not need to deal with NaNs later
if (channels == 0) return 0;

// Get the total # of samples for the previous frame, and the current frame (rounded)
double fps_rate = fps.Reciprocal().ToDouble();

Expand Down

0 comments on commit bc73ede

Please sign in to comment.