Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New recording sink for an in-memory binary stream #6241

Closed
jleibs opened this issue May 6, 2024 · 0 comments · Fixed by #6242
Closed

New recording sink for an in-memory binary stream #6241

jleibs opened this issue May 6, 2024 · 0 comments · Fixed by #6242
Assignees
Labels
enhancement New feature or request 🐍 Python API Python logging API

Comments

@jleibs
Copy link
Member

jleibs commented May 6, 2024

memory_recording() has a drain API, but the way it's structured it makes more sense for it to return self-contained RRD files.

Other usages (in rust), also take advantage of the fact that it exposes APIs to directly consume buffered messages, rather than a raw stream of bytes.

The call to drain also incurs non-trivial overhead since we lazily do the encode at this step rather than eagerly encoding in a dedicated thread as with the File/Tcp sinks.

@jleibs jleibs added enhancement New feature or request 🐍 Python API Python logging API labels May 6, 2024
@jleibs jleibs self-assigned this May 7, 2024
jleibs added a commit that referenced this issue May 7, 2024
…ded bytes (#6242)

### What
- Resolves: #6241

This effectively combines the guts of FileSink and MemorySink. Like the
FileSink, this runs file-encoding on its own thread so that all we need
to do when we're ready to read is move out the bytes.

The downside relative to memory_sink is the stream is a singular RRD.
You have no way of accessing information about individual messages,
draining from the backlog, etc.

This is designed to be as easy as possible to wire into a gradio output
stream.

Example usage in a Gradio Component:
```python
@rr.thread_local_stream("rerun_example_live")
def start_stream_direct(state):

    state['streaming'] = True

    cap = cv2.VideoCapture(0)
    frame_nr = 0
    stream = rr.binary_stream()

    while state.get('streaming', False):
        ret, img = cap.read()

        frame_time_ms = cap.get(cv2.CAP_PROP_POS_MSEC)
        if frame_time_ms != 0:
            rr.set_time_nanos("frame_time", int(frame_time_ms * 1_000_000))

        rr.set_time_sequence("frame_nr", frame_nr)
        frame_nr += 1

        print("Processing frame", frame_nr)

        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

        # Log the original image
        rr.log("image/rgb", rr.Image(img).compress())

        # Convert to grayscale
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        rr.log("image/gray", rr.Image(gray).compress())

        # Run the canny edge detector
        canny = cv2.Canny(gray, 50, 200)
        rr.log("image/canny", rr.Image(canny).compress())

        yield stream.read()
```

### 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/6242?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/6242?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)!

- [PR Build Summary](https://build.rerun.io/pr/6242)
- [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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 🐍 Python API Python logging API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant