Skip to content

Commit

Permalink
Merge branch 'main' into andreas/rav1d-windows-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf authored Oct 15, 2024
2 parents f8f14c5 + 4ceb974 commit f5f3e6f
Show file tree
Hide file tree
Showing 21 changed files with 444 additions and 144 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/contrib_rerun_py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ jobs:
# this stops `re_web_viewer_server/build.rs` from running
RERUN_IS_PUBLISHING: true
run: |
cargo build \
pixi run cargo build \
--locked \
-p rerun-cli \
--no-default-features \
--features native_viewer,web_viewer \
--features release \
--release \
--target x86_64-unknown-linux-gnu
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reusable_build_and_upload_rerun_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ jobs:
# this stops `re_web_viewer_server/build.rs` from running
RERUN_IS_PUBLISHING: true
run: |
cargo build \
pixi run cargo build \
--locked \
-p rerun-cli \
--no-default-features \
--features native_viewer,web_viewer \
--features release \
--release \
--target ${{ needs.set-config.outputs.TARGET }}
Expand Down
6 changes: 3 additions & 3 deletions crates/store/re_chunk_store/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ pub struct QueryExpression {
/// Examples: `Some(Timeline("frame"))`, `None` (only static data).
//
// TODO(cmc): this has to be a selector otherwise this is a horrible UX.
pub filtered_index: Option<Timeline>,
pub filtered_index: Option<Index>,

/// The range of index values used to filter out _rows_ from the view contents.
///
Expand Down Expand Up @@ -589,7 +589,7 @@ pub struct QueryExpression {
/// Example: `ComponentColumnSelector("rerun.components.Position3D")`.
//
// TODO(cmc): multi-pov support
pub filtered_point_of_view: Option<ComponentColumnSelector>,
pub filtered_is_not_null: Option<ComponentColumnSelector>,

/// Specifies how null values should be filled in the returned dataframe.
///
Expand Down Expand Up @@ -792,7 +792,7 @@ impl ChunkStore {
filtered_index_range: _,
filtered_index_values: _,
using_index_values: _,
filtered_point_of_view: _,
filtered_is_not_null: _,
sparse_fill_strategy: _,
selection: _,
} = query;
Expand Down
22 changes: 9 additions & 13 deletions crates/store/re_dataframe/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,7 @@ impl QueryHandle<'_> {
query: &RangeQuery,
view_contents: &[ColumnDescriptor],
) -> (Option<usize>, Vec<Vec<(AtomicU64, Chunk)>>) {
let mut view_pov_chunks_idx = self
.query
.filtered_point_of_view
.as_ref()
.map(|_| usize::MAX);
let mut view_pov_chunks_idx = self.query.filtered_is_not_null.as_ref().map(|_| usize::MAX);

let view_chunks = view_contents
.iter()
Expand All @@ -462,7 +458,7 @@ impl QueryHandle<'_> {
.fetch_chunks(query, &column.entity_path, [column.component_name])
.unwrap_or_default();

if let Some(pov) = self.query.filtered_point_of_view.as_ref() {
if let Some(pov) = self.query.filtered_is_not_null.as_ref() {
if pov.entity_path == column.entity_path
&& column.component_name.matches(&pov.component_name)
{
Expand Down Expand Up @@ -1196,7 +1192,7 @@ mod tests {
// * [x] filtered_index_values
// * [x] view_contents
// * [x] selection
// * [x] filtered_point_of_view
// * [x] filtered_is_not_null
// * [x] sparse_fill_strategy
// * [x] using_index_values
//
Expand Down Expand Up @@ -1551,7 +1547,7 @@ mod tests {
}

#[test]
fn filtered_point_of_view() -> anyhow::Result<()> {
fn filtered_is_not_null() -> anyhow::Result<()> {
re_log::setup_logging();

let store = create_nasty_store()?;
Expand All @@ -1569,7 +1565,7 @@ mod tests {
{
let query = QueryExpression {
filtered_index,
filtered_point_of_view: Some(ComponentColumnSelector {
filtered_is_not_null: Some(ComponentColumnSelector {
entity_path: "no/such/entity".into(),
component_name: MyPoint::name().to_string(),
}),
Expand Down Expand Up @@ -1598,7 +1594,7 @@ mod tests {
{
let query = QueryExpression {
filtered_index,
filtered_point_of_view: Some(ComponentColumnSelector {
filtered_is_not_null: Some(ComponentColumnSelector {
entity_path: entity_path.clone(),
component_name: "AComponentColumnThatDoesntExist".into(),
}),
Expand Down Expand Up @@ -1627,7 +1623,7 @@ mod tests {
{
let query = QueryExpression {
filtered_index,
filtered_point_of_view: Some(ComponentColumnSelector {
filtered_is_not_null: Some(ComponentColumnSelector {
entity_path: entity_path.clone(),
component_name: MyPoint::name().to_string(),
}),
Expand Down Expand Up @@ -1666,7 +1662,7 @@ mod tests {
{
let query = QueryExpression {
filtered_index,
filtered_point_of_view: Some(ComponentColumnSelector {
filtered_is_not_null: Some(ComponentColumnSelector {
entity_path: entity_path.clone(),
component_name: MyColor::name().to_string(),
}),
Expand Down Expand Up @@ -2180,7 +2176,7 @@ mod tests {
{
let query = QueryExpression {
filtered_index,
filtered_point_of_view: Some(ComponentColumnSelector {
filtered_is_not_null: Some(ComponentColumnSelector {
entity_path: entity_path.clone(),
component_name: MyPoint::name().to_string(),
}),
Expand Down
3 changes: 1 addition & 2 deletions crates/store/re_video/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ av1 = ["dep:dav1d"]

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

Expand Down
24 changes: 16 additions & 8 deletions crates/store/re_video/src/decode/av1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,22 @@ impl SyncDav1dDecoder {
pub fn new(debug_name: String) -> Result<Self> {
re_tracing::profile_function!();

// TODO(#7671): enable this warning again on Linux when the `nasm` feature actually does something
#[allow(clippy::overly_complex_bool_expr)]
if !cfg!(target_os = "linux") && !cfg!(feature = "nasm") {
re_log::warn_once!(
"NOTE: native AV1 video decoder is running extra slowly. \
Speed it up by compiling Rerun with the `nasm` feature enabled. \
You'll need to also install nasm: https://nasm.us/"
);
if !cfg!(feature = "nasm") {
// The `nasm` feature makes AV1 decoding much faster.
// On Linux the difference is huge (~25x).
// On Windows, the difference was also pretty big (unsure how big).
// On an M3 Mac the difference is smalelr (2-3x),
// and ever without `nasm` emilk can play an 8k video at 2x speed.

if cfg!(target_os = "macos") && cfg!(target_arch = "aarch64") {
re_log::warn_once!(
"The native AV1 video decoder is unnecessarily slow. \
Speed it up by compiling Rerun with the `nasm` feature enabled."
);
} else {
// Better to return an error than to be perceived as being slow
return Err(Error::Dav1dWithoutNasm);
}
}

// See https://videolan.videolan.me/dav1d/structDav1dSettings.html for settings docs
Expand Down
5 changes: 5 additions & 0 deletions crates/store/re_video/src/decode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ pub enum Error {
#[cfg(not(target_arch = "wasm32"))]
#[error("dav1d: {0}")]
Dav1d(#[from] dav1d::Error),

#[cfg(feature = "av1")]
#[cfg(not(target_arch = "wasm32"))]
#[error("To enabled native AV1 decoding, compile Rerun with the `nasm` feature enabled.")]
Dav1dWithoutNasm,
}

pub type Result<T = (), E = Error> = std::result::Result<T, E>;
Expand Down
107 changes: 16 additions & 91 deletions crates/store/re_video/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,102 +1,27 @@
//! Video decoding library.
mod time;

pub mod decode;
pub mod demux;

pub use decode::{Chunk, Frame, PixelFormat};
pub use demux::{Config, Sample, VideoData, VideoLoadError};
pub use re_mp4::{TrackId, TrackKind};

/// A value in time units.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Time(i64);

impl Time {
pub const ZERO: Self = Self(0);
pub const MAX: Self = Self(i64::MAX);

/// Create a new value in _time units_.
///
/// ⚠️ Don't use this for regular timestamps in seconds/milliseconds/etc.,
/// use the proper constructors for those instead!
/// This only exists for cases where you already have a value expressed in time units,
/// such as those received from the `WebCodecs` APIs.
#[inline]
pub fn new(v: i64) -> Self {
Self(v)
}

#[inline]
pub fn from_secs(v: f64, timescale: Timescale) -> Self {
Self((v * timescale.0 as f64).round() as i64)
}

#[inline]
pub fn from_millis(v: f64, timescale: Timescale) -> Self {
Self::from_secs(v / 1e3, timescale)
}

#[inline]
pub fn from_micros(v: f64, timescale: Timescale) -> Self {
Self::from_secs(v / 1e6, timescale)
}

#[inline]
pub fn from_nanos(v: i64, timescale: Timescale) -> Self {
Self::from_secs(v as f64 / 1e9, timescale)
}

/// Convert to a duration
#[inline]
pub fn duration(self, timescale: Timescale) -> std::time::Duration {
std::time::Duration::from_nanos(self.into_nanos(timescale) as _)
}

#[inline]
pub fn into_secs(self, timescale: Timescale) -> f64 {
self.0 as f64 / timescale.0 as f64
}
pub use self::{
decode::{Chunk, Frame, PixelFormat},
demux::{Config, Sample, VideoData, VideoLoadError},
time::{Time, Timescale},
};

#[inline]
pub fn into_millis(self, timescale: Timescale) -> f64 {
self.into_secs(timescale) * 1e3
/// Which features was this crate compiled with?
pub fn features() -> Vec<&'static str> {
// TODO(emilk): is there a helper crate for this?
let mut features = vec![];
if cfg!(feature = "av1") {
features.push("av1");
}

#[inline]
pub fn into_micros(self, timescale: Timescale) -> f64 {
self.into_secs(timescale) * 1e6
}

#[inline]
pub fn into_nanos(self, timescale: Timescale) -> i64 {
(self.into_secs(timescale) * 1e9).round() as i64
}
}

impl std::ops::Add for Time {
type Output = Self;

#[inline]
fn add(self, rhs: Self) -> Self::Output {
Self(self.0.saturating_add(rhs.0))
}
}

impl std::ops::Sub for Time {
type Output = Self;

#[inline]
fn sub(self, rhs: Self) -> Self::Output {
Self(self.0.saturating_sub(rhs.0))
}
}

/// The number of time units per second.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Timescale(u64);

impl Timescale {
pub(crate) fn new(v: u64) -> Self {
Self(v)
if cfg!(feature = "nasm") {
features.push("nasm");
}
features
}
Loading

0 comments on commit f5f3e6f

Please sign in to comment.