decoders: fix display order of frames in non-blocking mode

Making the tests check the order of frames revealed that frames were
sometimes presented out-of-order when decoding in non-blocking mode,
i.e. when there can be more than one frame in the ready_queue of the
decoder.

The cause is that we test all the frames in the queue for readiness, and
return all those that pass the test. This leaves space for a race
condition where frame X is not ready at the time of testing, and frame
X + 1 becomes ready by the time it is tested. When this happens, frame
X + 1 is returned before frame X.

Fix this by stopping filtering on the first frame that signals it is not
ready. Since the decoder processes the jobs we give it in-order, this
guarantees that the frames will always be returned in the correct order.
3 files changed
tree: 11f2e836fd6642fdbfffc255c469158c752a69ae
  1. src/
  2. .gitignore
  3. Cargo.lock
  4. Cargo.toml
  5. CONTRIBUTING.md
  6. LICENSE
  7. README.md
README.md

Cros-codecs

A lightweight, simple, low-dependencies, and hopefully safe crate for using hardware-accelerated decoding and encoding on Linux.

It is developed for use in ChromeOS (particularly crosvm), but has no ChromeOS dependencies and should this be usable anywhere.

This crate is still under heavy development. Currently implemented features are:

  • Stateless decoder support.
  • VAAPI decoder support (using cros-libva) for H.264, VP8 and VP9.

Future features:

  • Stateful V4L2 decoder support.
  • Stateless V4L2 decoder support.
  • Vaapi encoder support.
  • V4L2 encoder support.
  • Support for stateless H.265 and AV1.
  • C API to be used in non-Rust projects.