Skip to content

add new Rest api wrapper #13965

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

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

ArthurRaizIntel
Copy link

@ArthurRaizIntel ArthurRaizIntel commented Apr 28, 2025

image
Tracked on [LRS-1272]

@Nir-Az Nir-Az requested a review from Copilot April 28, 2025 08:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new REST API wrapper for interacting with RealSense devices and WebRTC streaming by introducing various endpoints and supporting code.

  • Adds core security functions and placeholder implementations for token creation and password hashing.
  • Introduces several API endpoints for devices, sensors, streams, point cloud, options, and WebRTC communications.
  • Provides dependency injection for service managers and updates documentation to include the new REST API wrapper.

Reviewed Changes

Copilot reviewed 38 out of 39 changed files in this pull request and generated no comments.

Show a summary per file
File Description
app/core/security.py Introduces token creation and password verification placeholders
app/core/errors.py Adds custom error handlers for various FastAPI exceptions
app/core/config.py Provides settings retrieval with an lru_cache decorator
app/core/auth.py Implements basic authentication logic with a fake user database
app/api/router.py Configures API routing to include various endpoint modules
app/api/endpoints/* Implements endpoints for webrtc, streams, sensors, point cloud, options, and devices
app/api/dependencies.py Supplies singleton dependencies for RealSense and WebRTC managers
wrappers/rest-api/README.md & wrappers/readme.md Updates documentation to document the new REST API capabilities
Files not reviewed (1)
  • wrappers/rest-api/.gitignore: Language not supported
Comments suppressed due to low confidence (1)

wrappers/rest-api/app/api/endpoints/point_cloud.py:32

  • Consider renaming 'get_stream_status' to 'get_point_cloud_status' for consistency with the underlying service call.
async def get_stream_status(

# LibRS Rest API server
## Overview

This Python library provides a convenient wrapper to interact with the [RealSense REST API], a FastAPI-based service that exposes the functionality of the Intel RealSense SDK (librealsense) over a network.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

This was the meaning here or missing some symbol?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to emphasize it

1. **RESTful Operations:** For device discovery, configuration, and control.
2. **WebRTC:** For efficient, browser-compatible live video streaming (RGB, Depth).
3. **Socket.IO:** For real-time streaming of frame metadata and point cloud data.
* In order to decode point cloud data in the client, follow those steps:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a python or other language you already did it on code snippet?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont have something official I can provide. it just a standard and languege agnostic socketio usage.

fake_users_db = {
"admin": {
"username": "admin",
"hashed_password": "$2b$12$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW", # "password"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this password?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just placeholders for future use in case password authentication will be required in the rest api

from typing import Any, Optional

# from jose import jwt
#from passlib.context import CryptContext
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 2 commented lines are needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just placeholders for future use in case password authentication will be required in the rest api


from app.core.config import get_settings

#pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for all other commented out lines in this file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same answer :)
I can remove but then it will be little bit more dificult to find it in the future.

from time import time
from .pyrealsense_mock import context, create_mock_device

# # Global variables for frame generation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is all of this commented out code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing code, will remove.

@Nir-Az Nir-Az requested a review from AviaAv April 29, 2025 14:25
physical_port = None

try:
usb_type = dev.get_info(rs.camera_info.usb_type_descriptor)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to wrap each get info with (dev.supports()) condition,
Here for example it will fail for MIPI devices as they do not support USB_type
I am not sure if it will throw

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np. will check it.

#!/bin/bash

# Start the FastAPI server
uvicorn main:combined_app --host 0.0.0.0 --port 8000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an option to do --reload for a fast reload, maybe adding it will make working on the wrapper easier?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reload is a flag for debugging purposes. not needed for regular usage.

* Establish a Socket.IO connection to the API.
* Receive real-time events containing:
* Frame metadata (timestamps, frame numbers, etc.).
* Point cloud data streams.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be helpful to mention that all of the endpoints and the supported features are available on the /docs endpoint

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was pretty sure I added it, probably missed that. will add.

points = self.pc.calculate(frame_data)
elif stream_type == rs.stream.color.name:
frame_data = frames.get_color_frame()
frame = frame_data.get_data()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we support pointcloud with color stream with self.pc.map_to ?

This fixture will automatically be used in all tests.
"""
# Create mock instances
rs_manager = RealSenseManager()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we initialize sio and do RealSenseManager(sio) ?

firmware_version: Optional[str] = None
physical_port: Optional[str] = None

class DeviceCreate(DeviceBase):
Copy link
Contributor

@AviaAv AviaAv May 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this class? Seeing this on the other models too

@AviaAv
Copy link
Contributor

AviaAv commented May 5, 2025

We also need to add License and Copyright on some of the files

# License: Apache 2.0. See LICENSE file in root directory.
# Copyright(c) 2025 Intel Corporation. All Rights Reserved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        if device_id not in self.devices:
            self.refresh_devices()
            if device_id not in self.devices:
                raise RealSenseError(
                    status_code=404, detail=f"Device {device_id} not found"
                )

I see this code (or similar variations) are repeated multiple times in the code, let's use get_device or a new helper function

@Nir-Az
Copy link
Collaborator

Nir-Az commented May 18, 2025

@ArthurRaizIntel can we progress here?
We want it merged in the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants