Skip to content

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

Open
@vadimkantorov

Description

@vadimkantorov

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions