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

Encoding multiple frames at once as oppose to per-frame encoding to save user<>kernel switches resulting from many fread(...) calls #88

Open
vadimkantorov opened this issue Dec 6, 2023 · 0 comments

Comments

@vadimkantorov
Copy link

vadimkantorov commented Dec 6, 2023

https://github.com/xiph/opus-tools/blob/master/src/opusenc.c#L1116-L1119 :

/*Main encoding loop (one frame per iteration)*/
  while (1) {
    nb_samples = inopt.read_samples(inopt.readdata,input,frame_size);
    ret = ope_encoder_write_float(enc, input, nb_samples);

Currently read_samples would do an fread(...) call for every frame, and IIUC each such call results in a
read-syscall and user<>kernel switch. I wonder if it would speed up if a large buffer is first read and then encoded at once - the underlying libopus API seems to support encoding multiple frames at once.

Would it be faster to do this?

If so, maybe a bufsize option can be introduced or even a command line switch for a regime where whole input is read in-memory / or input is open as mmap.

Also every read_samples/wav_read call alloca-tes a buffer dynamically for every frame.

@vadimkantorov vadimkantorov changed the title Encoding multiple frames at once as oppose to per-frame encoding Encoding multiple frames at once as oppose to per-frame encoding to save user<>kernel switches resulting from many fread(...) calls Dec 6, 2023
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