Skip to content
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

Av::Timestamp overflow #140

Open
nijiancong opened this issue Aug 13, 2024 · 0 comments
Open

Av::Timestamp overflow #140

nijiancong opened this issue Aug 13, 2024 · 0 comments

Comments

@nijiancong
Copy link

During an audio live stream transcoding, after utilizing AudioResampler::pop() for approximately 12 hours, the returned AudioSamples::pts() restarted from 0(

m_nextPts = dst.pts() + Timestamp{dst.samplesCount(), dst.timeBase()};
), prompting me to test the Timestamp addition operation.
After a certain number of iterations, the results obtained from "+=" and "+" operations differ.
"+=" continues to increment, whereas "+" operations result in overflow.

#include <avcpp/timestamp.h>
#include <avcpp/audioresampler.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char* argv[])
{
    int64_t i = 0;
    av::Timestamp t(0, av::Rational{1, 48000});
    while (true) {
        t = t + av::Timestamp{1024, t.timebase()};
        // t += av::Timestamp{1024, t.timebase()};
        if (t.seconds() < 1) {
            printf("[%" PRId64 "]++++t=%0.3lf\n", i, t.seconds());
        }
        if (i % 1000000 == 0) {
            printf("t=%0.3lf\n", t.seconds());
        }
        i++;
    }
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant