From e6c013ab2d005c7f3e55096668895d249c62504f Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 2 Apr 2024 11:31:50 -0400 Subject: [PATCH 1/5] Use byte_offset and byte_offset_from from the std library --- README.md | 14 ++++++++++---- src/runtime.rs | 16 +++------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 0d5a83d..4f7a3bb 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,10 @@ python -m pip install acquire-imaging ``` -Acquire ([`acquire-imaging` on PyPI](https://pypi.org/project/acquire-imaging/)) provides high-speed, multi-camera, video streaming for up to **2** cameras and image acquisition with a programming interface for streaming video data directly to Python, cloud-friendly file formats, and visualization platforms, such as [napari](https://napari.org/stable/). +Acquire ([`acquire-imaging` on PyPI](https://pypi.org/project/acquire-imaging/)) provides high-speed, multi-camera, +video streaming for up to **2** cameras and image acquisition with a programming interface for streaming video data +directly to Python, cloud-friendly file formats, and visualization platforms, such +as [napari](https://napari.org/stable/). > **Note** This is an early stage project. If you find it interesting, please > reach out! @@ -33,9 +36,11 @@ For testing and demonstration purposes, Acquire provides a few simulated video s ## Usage -Check out our documentation [here](https://acquire-project.github.io/acquire-docs/). +Check out our documentation [here](https://acquire-project.github.io/acquire-docs/). -The provided [napari](https://napari.org/stable/) plugin ([code here](https://github.com/acquire-project/acquire-python/blob/main/python/acquire/__init__.py#L131)) is a good example of how to stream for visualization. +The provided [napari](https://napari.org/stable/) +plugin ([code here](https://github.com/acquire-project/acquire-python/blob/main/python/acquire/__init__.py#L131)) is a +good example of how to stream for visualization. ## Development @@ -50,7 +55,7 @@ Requires [chocolatey](https://community.chocolatey.org/packages/cmake)) - A C++20 compiler (Microsoft Visual Studio Community [download page](https://visualstudio.microsoft.com/downloads/), or clang) -- Rust (via rustup, see [install +- Rust >= 1.75 (via rustup, see [install page](https://www.rust-lang.org/tools/install)) - conda (optional; via [miniconda](https://docs.conda.io/en/latest/miniconda.html)) @@ -84,6 +89,7 @@ python -m build This package depends on a submodule ([acquire-common](https://github.com/acquire-project/acquire-common)) and binaries from the following Acquire drivers: + - [acquire-driver-hdcam](https://github.com/acquire-project/acquire-driver-hdcam) - [acquire-driver-egrabber](https://github.com/acquire-project/acquire-driver-egrabber) - [acquire-driver-zarr](https://github.com/acquire-project/acquire-driver-zarr) diff --git a/src/runtime.rs b/src/runtime.rs index 62a7ef5..c89802a 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -228,16 +228,6 @@ struct RawAvailableData { unsafe impl Send for RawAvailableData {} unsafe impl Sync for RawAvailableData {} -// Can replace this if `pointer_byte_offsets` gets stabilized. -unsafe fn byte_offset(origin: *mut T, count: isize) -> *mut T { - (origin as *const u8).offset(count) as *mut T -} - -// Can replace this if `pointer_byte_offsets` gets stabilized. -unsafe fn byte_offset_from(beg: *mut T, end: *mut T) -> isize { - (end as *const u8).offset_from(beg as *const u8) -} - impl RawAvailableData { fn get_frame_count(&self) -> usize { let mut count = 0; @@ -253,7 +243,7 @@ impl RawAvailableData { frame.bytes_of_frame ); assert!(frame.bytes_of_frame > 0); - cur = byte_offset(cur, frame.bytes_of_frame as _); + cur = cur.byte_offset(frame.bytes_of_frame as _); count += 1; } } @@ -265,7 +255,7 @@ impl Drop for RawAvailableData { fn drop(&mut self) { let consumed_bytes = self .consumed_bytes - .unwrap_or(unsafe { byte_offset_from(self.beg.as_ptr(), self.end.as_ptr()) } as usize); + .unwrap_or(unsafe { self.end.as_ptr().byte_offset_from(self.beg.as_ptr()) } as usize); log::debug!( "[stream {}] DROP read region: {:p}-{:p}:{}", self.stream_id, @@ -341,7 +331,7 @@ impl AvailableDataContext { let nbytes = if beg.is_null() || end.is_null() { 0 } else { - unsafe { byte_offset_from(beg, end) } + unsafe { end.byte_offset_from(beg) } }; log::trace!( From 15bc98805c7fdc7bbd28f3075bbf59bb22c7fd29 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 2 Apr 2024 11:44:58 -0400 Subject: [PATCH 2/5] Set up Rust toolchain in workflows. --- .github/workflows/build.yml | 3 + .github/workflows/pre-commit.yml | 3 + .github/workflows/release.yml | 3 + .github/workflows/test_pr.yml | 121 ++++++++++++++++++------------- 4 files changed, 78 insertions(+), 52 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 161f223..9295ed8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,6 +17,9 @@ jobs: with: submodules: true + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + - name: Build uses: messense/maturin-action@v1 with: diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 9ecbe53..6f5399e 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,6 +13,9 @@ jobs: with: submodules: true + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0d7af89..259f32f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,6 +42,9 @@ jobs: ref: main submodules: true + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 with: diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml index b13d348..0772a25 100644 --- a/.github/workflows/test_pr.yml +++ b/.github/workflows/test_pr.yml @@ -4,7 +4,7 @@ on: push: branches: - main - pull_request_target: + pull_request: # TODO (aliddell): revert to pull_request_target branches: - main @@ -42,6 +42,9 @@ jobs: submodules: true ref: ${{ github.event.pull_request.head.sha }} + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 with: @@ -97,6 +100,9 @@ jobs: with: cmakeVersion: 3.24.3 + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 with: @@ -111,57 +117,59 @@ jobs: run: | python -m pytest -k test_dcam - # TODO (aliddell): uncomment when we get an eGrabber runner up again - # egrabber: - # name: Python ${{ matrix.python }} (eGrabber) - # runs-on: - # - self-hosted - # - egrabber - # - VC-151MX-M6H00 - # timeout-minutes: 20 - # strategy: - # fail-fast: false - # matrix: - # python: - # - "3.8" - # - "3.9" - # - "3.10" - # - "3.11" - # - "3.12" - - # permissions: - # actions: write - # env: - # GH_TOKEN: ${{ github.token }} - # steps: - # - name: Cancel Previous Runs - # uses: styfle/cancel-workflow-action@0.11.0 - # with: - # access_token: ${{ github.token }} - - # - uses: actions/checkout@v3 - # with: - # submodules: true - # ref: ${{ github.event.pull_request.head.sha }} - - # - name: Get CMake 3.24 - # uses: lukka/get-cmake@latest - # with: - # cmakeVersion: 3.24.3 - - # - name: Set up Python ${{ matrix.python }} - # uses: actions/setup-python@v4 - # with: - # python-version: ${{ matrix.python }} - - # - name: Install - # run: | - # pip install --upgrade pip - # pip install -e .[testing] - - # - name: Test - # run: | - # python -m pytest -k test_egrabber + egrabber: + name: Python ${{ matrix.python }} (eGrabber) + runs-on: + - self-hosted + - egrabber + - VC-151MX-M6H00 + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + python: + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + + permissions: + actions: write + env: + GH_TOKEN: ${{ github.token }} + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{ github.token }} + + - uses: actions/checkout@v3 + with: + submodules: true + ref: ${{ github.event.pull_request.head.sha }} + + - name: Get CMake 3.24 + uses: lukka/get-cmake@latest + with: + cmakeVersion: 3.24.3 + + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + + - name: Set up Python ${{ matrix.python }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + + - name: Install + run: | + pip install --upgrade pip + pip install -e .[testing] + + - name: Test + run: | + python -m pytest -k test_egrabber spinnaker: name: Python ${{ matrix.python }} (Spinnaker) @@ -201,6 +209,9 @@ jobs: with: cmakeVersion: 3.24.3 + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 with: @@ -252,6 +263,9 @@ jobs: with: cmakeVersion: 3.24.3 + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 with: @@ -277,6 +291,9 @@ jobs: submodules: true ref: ${{ github.event.pull_request.head.sha }} + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + - name: Set up Python 3.10 uses: actions/setup-python@v4 with: From f518f16650f2b6fd2f89e628a9fb69904261a046 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 2 Apr 2024 11:49:59 -0400 Subject: [PATCH 3/5] Specify toolchain another way. --- .github/workflows/build.yml | 4 +++- .github/workflows/pre-commit.yml | 4 +++- .github/workflows/release.yml | 4 +++- .github/workflows/test_pr.yml | 24 ++++++++++++++++++------ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9295ed8..f564fe7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,9 @@ jobs: submodules: true - name: Set up Rust - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable - name: Build uses: messense/maturin-action@v1 diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 6f5399e..9ff8ed7 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -14,7 +14,9 @@ jobs: submodules: true - name: Set up Rust - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable - name: Set up Python 3.10 uses: actions/setup-python@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 259f32f..55a7609 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,9 @@ jobs: submodules: true - name: Set up Rust - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml index 0772a25..46e2a5e 100644 --- a/.github/workflows/test_pr.yml +++ b/.github/workflows/test_pr.yml @@ -43,7 +43,9 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} - name: Set up Rust - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 @@ -101,7 +103,9 @@ jobs: cmakeVersion: 3.24.3 - name: Set up Rust - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 @@ -155,7 +159,9 @@ jobs: cmakeVersion: 3.24.3 - name: Set up Rust - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 @@ -210,7 +216,9 @@ jobs: cmakeVersion: 3.24.3 - name: Set up Rust - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 @@ -264,7 +272,9 @@ jobs: cmakeVersion: 3.24.3 - name: Set up Rust - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 @@ -292,7 +302,9 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} - name: Set up Rust - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable - name: Set up Python 3.10 uses: actions/setup-python@v4 From 6296b22a4234d1d58e67569aade771cdb514d629 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 2 Apr 2024 16:57:08 -0400 Subject: [PATCH 4/5] Revert "Specify toolchain another way." This reverts commit f518f16650f2b6fd2f89e628a9fb69904261a046. --- .github/workflows/build.yml | 4 +--- .github/workflows/pre-commit.yml | 4 +--- .github/workflows/release.yml | 4 +--- .github/workflows/test_pr.yml | 24 ++++++------------------ 4 files changed, 9 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f564fe7..9295ed8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,9 +18,7 @@ jobs: submodules: true - name: Set up Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable + uses: dtolnay/rust-toolchain@stable - name: Build uses: messense/maturin-action@v1 diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 9ff8ed7..6f5399e 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -14,9 +14,7 @@ jobs: submodules: true - name: Set up Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable + uses: dtolnay/rust-toolchain@stable - name: Set up Python 3.10 uses: actions/setup-python@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 55a7609..259f32f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,9 +43,7 @@ jobs: submodules: true - name: Set up Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable + uses: dtolnay/rust-toolchain@stable - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml index 46e2a5e..0772a25 100644 --- a/.github/workflows/test_pr.yml +++ b/.github/workflows/test_pr.yml @@ -43,9 +43,7 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} - name: Set up Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable + uses: dtolnay/rust-toolchain@stable - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 @@ -103,9 +101,7 @@ jobs: cmakeVersion: 3.24.3 - name: Set up Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable + uses: dtolnay/rust-toolchain@stable - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 @@ -159,9 +155,7 @@ jobs: cmakeVersion: 3.24.3 - name: Set up Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable + uses: dtolnay/rust-toolchain@stable - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 @@ -216,9 +210,7 @@ jobs: cmakeVersion: 3.24.3 - name: Set up Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable + uses: dtolnay/rust-toolchain@stable - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 @@ -272,9 +264,7 @@ jobs: cmakeVersion: 3.24.3 - name: Set up Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable + uses: dtolnay/rust-toolchain@stable - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 @@ -302,9 +292,7 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} - name: Set up Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable + uses: dtolnay/rust-toolchain@stable - name: Set up Python 3.10 uses: actions/setup-python@v4 From 45ab88afcf033297fa1e5a87cdcab0630edf1a3d Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Tue, 2 Apr 2024 16:57:42 -0400 Subject: [PATCH 5/5] Revert "Set up Rust toolchain in workflows." This reverts commit 15bc98805c7fdc7bbd28f3075bbf59bb22c7fd29. --- .github/workflows/build.yml | 3 - .github/workflows/pre-commit.yml | 3 - .github/workflows/release.yml | 3 - .github/workflows/test_pr.yml | 121 +++++++++++++------------------ 4 files changed, 52 insertions(+), 78 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9295ed8..161f223 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,9 +17,6 @@ jobs: with: submodules: true - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - - name: Build uses: messense/maturin-action@v1 with: diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 6f5399e..9ecbe53 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,9 +13,6 @@ jobs: with: submodules: true - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - - name: Set up Python 3.10 uses: actions/setup-python@v4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 259f32f..0d7af89 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,9 +42,6 @@ jobs: ref: main submodules: true - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 with: diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml index 0772a25..b13d348 100644 --- a/.github/workflows/test_pr.yml +++ b/.github/workflows/test_pr.yml @@ -4,7 +4,7 @@ on: push: branches: - main - pull_request: # TODO (aliddell): revert to pull_request_target + pull_request_target: branches: - main @@ -42,9 +42,6 @@ jobs: submodules: true ref: ${{ github.event.pull_request.head.sha }} - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 with: @@ -100,9 +97,6 @@ jobs: with: cmakeVersion: 3.24.3 - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 with: @@ -117,59 +111,57 @@ jobs: run: | python -m pytest -k test_dcam - egrabber: - name: Python ${{ matrix.python }} (eGrabber) - runs-on: - - self-hosted - - egrabber - - VC-151MX-M6H00 - timeout-minutes: 20 - strategy: - fail-fast: false - matrix: - python: - - "3.8" - - "3.9" - - "3.10" - - "3.11" - - "3.12" - - permissions: - actions: write - env: - GH_TOKEN: ${{ github.token }} - steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.11.0 - with: - access_token: ${{ github.token }} - - - uses: actions/checkout@v3 - with: - submodules: true - ref: ${{ github.event.pull_request.head.sha }} - - - name: Get CMake 3.24 - uses: lukka/get-cmake@latest - with: - cmakeVersion: 3.24.3 - - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - - - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - - name: Install - run: | - pip install --upgrade pip - pip install -e .[testing] - - - name: Test - run: | - python -m pytest -k test_egrabber + # TODO (aliddell): uncomment when we get an eGrabber runner up again + # egrabber: + # name: Python ${{ matrix.python }} (eGrabber) + # runs-on: + # - self-hosted + # - egrabber + # - VC-151MX-M6H00 + # timeout-minutes: 20 + # strategy: + # fail-fast: false + # matrix: + # python: + # - "3.8" + # - "3.9" + # - "3.10" + # - "3.11" + # - "3.12" + + # permissions: + # actions: write + # env: + # GH_TOKEN: ${{ github.token }} + # steps: + # - name: Cancel Previous Runs + # uses: styfle/cancel-workflow-action@0.11.0 + # with: + # access_token: ${{ github.token }} + + # - uses: actions/checkout@v3 + # with: + # submodules: true + # ref: ${{ github.event.pull_request.head.sha }} + + # - name: Get CMake 3.24 + # uses: lukka/get-cmake@latest + # with: + # cmakeVersion: 3.24.3 + + # - name: Set up Python ${{ matrix.python }} + # uses: actions/setup-python@v4 + # with: + # python-version: ${{ matrix.python }} + + # - name: Install + # run: | + # pip install --upgrade pip + # pip install -e .[testing] + + # - name: Test + # run: | + # python -m pytest -k test_egrabber spinnaker: name: Python ${{ matrix.python }} (Spinnaker) @@ -209,9 +201,6 @@ jobs: with: cmakeVersion: 3.24.3 - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 with: @@ -263,9 +252,6 @@ jobs: with: cmakeVersion: 3.24.3 - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v4 with: @@ -291,9 +277,6 @@ jobs: submodules: true ref: ${{ github.event.pull_request.head.sha }} - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - - name: Set up Python 3.10 uses: actions/setup-python@v4 with: