-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
base: development
Are you sure you want to change the base?
add new Rest api wrapper #13965
Conversation
There was a problem hiding this 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this password?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testing code, will remove.
physical_port = None | ||
|
||
try: | ||
usb_type = dev.get_info(rs.camera_info.usb_type_descriptor) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
We also need to add License and Copyright on some of the files
|
There was a problem hiding this comment.
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
@ArthurRaizIntel can we progress here? |
Tracked on [LRS-1272]