Skip to content

Commit 6fb673b

Browse files
authored
Require nasm for AV1 decoding, unless on arm64 macOS (#7742)
### What * Closes #7669 * Closes #7671 * Disable AV1 decoding unless the `nasm` feature is turned on * Turn on the `nasm` feature when building pre-built binaries * Print enabled video features with `rerun --version` to make testing of the above easy ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using examples from latest `main` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7742?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [rerun.io/viewer](https://rerun.io/viewer/pr/7742?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! * [x] If have noted any breaking changes to the log API in `CHANGELOG.md` and the migration guide - [PR Build Summary](https://build.rerun.io/pr/7742) - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html) To run all checks from `main`, comment on the PR with `@rerun-bot full-check`.
1 parent 57b15b0 commit 6fb673b

File tree

11 files changed

+144
-110
lines changed

11 files changed

+144
-110
lines changed

.github/workflows/contrib_rerun_py.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ jobs:
6161
# this stops `re_web_viewer_server/build.rs` from running
6262
RERUN_IS_PUBLISHING: true
6363
run: |
64-
cargo build \
64+
pixi run cargo build \
6565
--locked \
6666
-p rerun-cli \
6767
--no-default-features \
68-
--features native_viewer,web_viewer \
68+
--features release \
6969
--release \
7070
--target x86_64-unknown-linux-gnu
7171

.github/workflows/reusable_build_and_upload_rerun_cli.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ jobs:
176176
# this stops `re_web_viewer_server/build.rs` from running
177177
RERUN_IS_PUBLISHING: true
178178
run: |
179-
cargo build \
179+
pixi run cargo build \
180180
--locked \
181181
-p rerun-cli \
182182
--no-default-features \
183-
--features native_viewer,web_viewer \
183+
--features release \
184184
--release \
185185
--target ${{ needs.set-config.outputs.TARGET }}
186186

crates/store/re_video/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ av1 = ["dep:dav1d"]
3030

3131
## Enable faster native video decoding with assembly.
3232
## You need to install [nasm](https://nasm.us/) to compile with this feature.
33-
# TODO(#7671): this feature flag currently does nothing on Linux.
3433
nasm = [
35-
# The default feature set of our dav1d fork has asm enabled (except on Linux, see above)
34+
# The default feature set of our dav1d fork has asm enabled
3635
"dav1d?/default",
3736
]
3837

crates/store/re_video/src/decode/av1.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,22 @@ impl SyncDav1dDecoder {
3737
pub fn new(debug_name: String) -> Result<Self> {
3838
re_tracing::profile_function!();
3939

40-
// TODO(#7671): enable this warning again on Linux when the `nasm` feature actually does something
41-
#[allow(clippy::overly_complex_bool_expr)]
42-
if !cfg!(target_os = "linux") && !cfg!(feature = "nasm") {
43-
re_log::warn_once!(
44-
"NOTE: native AV1 video decoder is running extra slowly. \
45-
Speed it up by compiling Rerun with the `nasm` feature enabled. \
46-
You'll need to also install nasm: https://nasm.us/"
47-
);
40+
if !cfg!(feature = "nasm") {
41+
// The `nasm` feature makes AV1 decoding much faster.
42+
// On Linux the difference is huge (~25x).
43+
// On Windows, the difference was also pretty big (unsure how big).
44+
// On an M3 Mac the difference is smalelr (2-3x),
45+
// and ever without `nasm` emilk can play an 8k video at 2x speed.
46+
47+
if cfg!(target_os = "macos") && cfg!(target_arch = "aarch64") {
48+
re_log::warn_once!(
49+
"The native AV1 video decoder is unnecessarily slow. \
50+
Speed it up by compiling Rerun with the `nasm` feature enabled."
51+
);
52+
} else {
53+
// Better to return an error than to be perceived as being slow
54+
return Err(Error::Dav1dWithoutNasm);
55+
}
4856
}
4957

5058
// See https://videolan.videolan.me/dav1d/structDav1dSettings.html for settings docs

crates/store/re_video/src/decode/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ pub enum Error {
100100
#[cfg(not(target_arch = "wasm32"))]
101101
#[error("dav1d: {0}")]
102102
Dav1d(#[from] dav1d::Error),
103+
104+
#[cfg(feature = "av1")]
105+
#[cfg(not(target_arch = "wasm32"))]
106+
#[error("To enabled native AV1 decoding, compile Rerun with the `nasm` feature enabled.")]
107+
Dav1dWithoutNasm,
103108
}
104109

105110
pub type Result<T = (), E = Error> = std::result::Result<T, E>;

crates/store/re_video/src/lib.rs

Lines changed: 16 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,27 @@
11
//! Video decoding library.
22
3+
mod time;
4+
35
pub mod decode;
46
pub mod demux;
57

6-
pub use decode::{Chunk, Frame, PixelFormat};
7-
pub use demux::{Config, Sample, VideoData, VideoLoadError};
88
pub use re_mp4::{TrackId, TrackKind};
99

10-
/// A value in time units.
11-
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
12-
pub struct Time(i64);
13-
14-
impl Time {
15-
pub const ZERO: Self = Self(0);
16-
pub const MAX: Self = Self(i64::MAX);
17-
18-
/// Create a new value in _time units_.
19-
///
20-
/// ⚠️ Don't use this for regular timestamps in seconds/milliseconds/etc.,
21-
/// use the proper constructors for those instead!
22-
/// This only exists for cases where you already have a value expressed in time units,
23-
/// such as those received from the `WebCodecs` APIs.
24-
#[inline]
25-
pub fn new(v: i64) -> Self {
26-
Self(v)
27-
}
28-
29-
#[inline]
30-
pub fn from_secs(v: f64, timescale: Timescale) -> Self {
31-
Self((v * timescale.0 as f64).round() as i64)
32-
}
33-
34-
#[inline]
35-
pub fn from_millis(v: f64, timescale: Timescale) -> Self {
36-
Self::from_secs(v / 1e3, timescale)
37-
}
38-
39-
#[inline]
40-
pub fn from_micros(v: f64, timescale: Timescale) -> Self {
41-
Self::from_secs(v / 1e6, timescale)
42-
}
43-
44-
#[inline]
45-
pub fn from_nanos(v: i64, timescale: Timescale) -> Self {
46-
Self::from_secs(v as f64 / 1e9, timescale)
47-
}
48-
49-
/// Convert to a duration
50-
#[inline]
51-
pub fn duration(self, timescale: Timescale) -> std::time::Duration {
52-
std::time::Duration::from_nanos(self.into_nanos(timescale) as _)
53-
}
54-
55-
#[inline]
56-
pub fn into_secs(self, timescale: Timescale) -> f64 {
57-
self.0 as f64 / timescale.0 as f64
58-
}
10+
pub use self::{
11+
decode::{Chunk, Frame, PixelFormat},
12+
demux::{Config, Sample, VideoData, VideoLoadError},
13+
time::{Time, Timescale},
14+
};
5915

60-
#[inline]
61-
pub fn into_millis(self, timescale: Timescale) -> f64 {
62-
self.into_secs(timescale) * 1e3
16+
/// Which features was this crate compiled with?
17+
pub fn features() -> Vec<&'static str> {
18+
// TODO(emilk): is there a helper crate for this?
19+
let mut features = vec![];
20+
if cfg!(feature = "av1") {
21+
features.push("av1");
6322
}
64-
65-
#[inline]
66-
pub fn into_micros(self, timescale: Timescale) -> f64 {
67-
self.into_secs(timescale) * 1e6
68-
}
69-
70-
#[inline]
71-
pub fn into_nanos(self, timescale: Timescale) -> i64 {
72-
(self.into_secs(timescale) * 1e9).round() as i64
73-
}
74-
}
75-
76-
impl std::ops::Add for Time {
77-
type Output = Self;
78-
79-
#[inline]
80-
fn add(self, rhs: Self) -> Self::Output {
81-
Self(self.0.saturating_add(rhs.0))
82-
}
83-
}
84-
85-
impl std::ops::Sub for Time {
86-
type Output = Self;
87-
88-
#[inline]
89-
fn sub(self, rhs: Self) -> Self::Output {
90-
Self(self.0.saturating_sub(rhs.0))
91-
}
92-
}
93-
94-
/// The number of time units per second.
95-
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
96-
pub struct Timescale(u64);
97-
98-
impl Timescale {
99-
pub(crate) fn new(v: u64) -> Self {
100-
Self(v)
23+
if cfg!(feature = "nasm") {
24+
features.push("nasm");
10125
}
26+
features
10227
}

crates/store/re_video/src/time.rs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/// The number of time units per second.
2+
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
3+
pub struct Timescale(u64);
4+
5+
impl Timescale {
6+
pub(crate) fn new(v: u64) -> Self {
7+
Self(v)
8+
}
9+
}
10+
11+
/// A value in time units.
12+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
13+
pub struct Time(pub i64);
14+
15+
impl Time {
16+
pub const ZERO: Self = Self(0);
17+
pub const MAX: Self = Self(i64::MAX);
18+
19+
/// Create a new value in _time units_.
20+
///
21+
/// ⚠️ Don't use this for regular timestamps in seconds/milliseconds/etc.,
22+
/// use the proper constructors for those instead!
23+
/// This only exists for cases where you already have a value expressed in time units,
24+
/// such as those received from the `WebCodecs` APIs.
25+
#[inline]
26+
pub fn new(v: i64) -> Self {
27+
Self(v)
28+
}
29+
30+
#[inline]
31+
pub fn from_secs(v: f64, timescale: Timescale) -> Self {
32+
Self((v * timescale.0 as f64).round() as i64)
33+
}
34+
35+
#[inline]
36+
pub fn from_millis(v: f64, timescale: Timescale) -> Self {
37+
Self::from_secs(v / 1e3, timescale)
38+
}
39+
40+
#[inline]
41+
pub fn from_micros(v: f64, timescale: Timescale) -> Self {
42+
Self::from_secs(v / 1e6, timescale)
43+
}
44+
45+
#[inline]
46+
pub fn from_nanos(v: i64, timescale: Timescale) -> Self {
47+
Self::from_secs(v as f64 / 1e9, timescale)
48+
}
49+
50+
/// Convert to a duration
51+
#[inline]
52+
pub fn duration(self, timescale: Timescale) -> std::time::Duration {
53+
std::time::Duration::from_nanos(self.into_nanos(timescale) as _)
54+
}
55+
56+
#[inline]
57+
pub fn into_secs(self, timescale: Timescale) -> f64 {
58+
self.0 as f64 / timescale.0 as f64
59+
}
60+
61+
#[inline]
62+
pub fn into_millis(self, timescale: Timescale) -> f64 {
63+
self.into_secs(timescale) * 1e3
64+
}
65+
66+
#[inline]
67+
pub fn into_micros(self, timescale: Timescale) -> f64 {
68+
self.into_secs(timescale) * 1e6
69+
}
70+
71+
#[inline]
72+
pub fn into_nanos(self, timescale: Timescale) -> i64 {
73+
(self.into_secs(timescale) * 1e9).round() as i64
74+
}
75+
}
76+
77+
impl std::ops::Add for Time {
78+
type Output = Self;
79+
80+
#[inline]
81+
fn add(self, rhs: Self) -> Self::Output {
82+
Self(self.0.saturating_add(rhs.0))
83+
}
84+
}
85+
86+
impl std::ops::Sub for Time {
87+
type Output = Self;
88+
89+
#[inline]
90+
fn sub(self, rhs: Self) -> Self::Output {
91+
Self(self.0.saturating_sub(rhs.0))
92+
}
93+
}

crates/top/rerun-cli/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ path = "src/bin/rerun.rs"
3737
doc = false
3838

3939
[features]
40-
# The default is what the user gets when they call `cargo install rerun-cli --locked`,
41-
# so wer have all the bells and wistles here
40+
## The default is what the user gets when they call `cargo install rerun-cli --locked`,
41+
## so we have all the bells and wistles here, except those that may require extra tools
42+
## (like "nasm").
43+
## That is: `cargo install rerun-cli --locked` should work for _everyone_.
4244
default = ["native_viewer", "web_viewer"]
4345

46+
## The features we enable when we build the pre-built binaries during our releases.
47+
## This may enable features that require extra build tools that not everyone heas.
48+
release = ["default", "nasm"]
49+
4450
## Enable faster native video decoding with assembly.
4551
## You need to install [nasm](https://nasm.us/) to compile with this feature.
46-
# TODO(#7671): this feature flag currently does nothing on linux.
4752
nasm = ["rerun/nasm"]
4853

4954
## Support spawning a native viewer.

crates/top/rerun/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ log = ["dep:env_logger", "dep:log"]
7373

7474
## Enable faster native video decoding with assembly.
7575
## You need to install [nasm](https://nasm.us/) to compile with this feature.
76-
# TODO(#7671): this feature flag currently does nothing on linux.
7776
nasm = ["re_video/nasm"]
7877

7978
## Support spawning a native viewer.

crates/top/rerun/src/commands/entrypoint.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ where
553553

554554
if args.version {
555555
println!("{build_info}");
556+
println!("Video features: {}", re_video::features().join(" "));
556557
return Ok(0);
557558
}
558559

0 commit comments

Comments
 (0)