feat(rtsp/socket): Improve network comms and make RTSP component more stream agnostic, to support audio as well and not just MJPEG#633
Merged
Conversation
… types and multiple tracks
…rtsp implementation to better support multi-track use; update socket example to better test code; update python code to better test multitrack rtsp code
…nnect callback to server; improve throughput by reducing memory allocations in server
|
✅Static analysis result - no issues found! ✅ |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR modernizes the ESPP RTSP stack into a multi-track, codec-agnostic RTP framework (video + audio) and improves underlying socket reliability, with accompanying host-side Python tooling/tests and documentation updates.
Changes:
- Refactors RTSP server/client to support multiple tracks using codec-specific packetizers/depacketizers (MJPEG, H264, generic audio).
- Improves socket teardown and transient-error handling (UDP send retries, safer cleanup/close semantics).
- Updates Python wrappers, adds multitrack client/server scripts plus API/E2E tests, and refreshes RTSP/socket docs and bindings.
Reviewed changes
Copilot reviewed 49 out of 49 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| python/rtsp_server.py | Wrapper to run multitrack server with MJPEG defaults |
| python/rtsp_server_multitrack.py | New multitrack RTSP server (video + audio) |
| python/rtsp_multitrack_test.py | New subprocess E2E tests for multitrack RTSP |
| python/rtsp_client.py | Wrapper to run multitrack client with MJPEG defaults |
| python/rtsp_client_multitrack.py | New multitrack RTSP client with audio validation/playback |
| python/rtsp_api_test.py | Offline host-side API tests for RTP/RTSP helpers |
| python/requirements.txt | Adds sounddevice dependency |
| python/README.md | Documents new RTSP multitrack scripts and audio behavior |
| lib/include/espp.hpp | Exposes new RTP/packetizer headers to host bindings |
| lib/espp.cmake | Adds new RTSP source files to host library build |
| lib/autogenerate_bindings.py | Exports new RTSP/RTP headers to bindings generator |
| doc/en/rtsp.rst | Updates RTSP docs for multicodec/multitrack support |
| doc/Doxyfile | Adds new RTSP/RTP headers to Doxygen inputs |
| components/socket/src/udp_socket.cpp | Adds send retry + stop_receiving teardown path |
| components/socket/src/tcp_socket.cpp | Makes close() reset connected state and cleanup |
| components/socket/src/socket.cpp | Adjusts select() + makes cleanup() more robust |
| components/socket/README.md | Updates example description (scenario-driven self-test) |
| components/socket/include/udp_socket.hpp | Adds stop_receiving() API |
| components/socket/example/README.md | Updates example README to new scenario-test behavior |
| components/rtsp/src/rtsp_session.cpp | Adds per-track RTP/RTCP sending + SDP generator hook |
| components/rtsp/src/rtsp_server.cpp | Adds multitrack sending, SDP generation, backpressure handling |
| components/rtsp/src/rtsp_client.cpp | Adds SDP parsing, depacketizers, monitor/disconnect handling |
| components/rtsp/src/mjpeg_packetizer.cpp | New MJPEG RTP payload chunker |
| components/rtsp/src/mjpeg_depacketizer.cpp | New MJPEG depacketizer (frame reconstruction) |
| components/rtsp/src/h264_packetizer.cpp | New H264 packetizer (Annex B + FU-A) |
| components/rtsp/src/h264_depacketizer.cpp | New H264 depacketizer (STAP-A/FU-A) |
| components/rtsp/src/generic_packetizer.cpp | New generic packetizer for audio/other payloads |
| components/rtsp/src/generic_depacketizer.cpp | New generic depacketizer (marker/timestamp framing) |
| components/rtsp/README.md | Updates component README for multicodec architecture |
| components/rtsp/include/rtsp_session.hpp | Adds Track abstraction + SDP generator config |
| components/rtsp/include/rtsp_server.hpp | Adds TrackConfig + multitrack send_frame APIs |
| components/rtsp/include/rtsp_client.hpp | Adds generic on_frame callback + tracks() + depacketizers |
| components/rtsp/include/rtp_types.hpp | Introduces MediaType and RtpPayloadChunk |
| components/rtsp/include/rtp_packetizer.hpp | Introduces packetizer base class contract |
| components/rtsp/include/rtp_depacketizer.hpp | Introduces depacketizer base class contract |
| components/rtsp/include/rtp_jpeg_packet.hpp | Header include tweaks for new usage patterns |
| components/rtsp/include/mjpeg_packetizer.hpp | Declares MJPEG packetizer |
| components/rtsp/include/mjpeg_depacketizer.hpp | Declares MJPEG depacketizer |
| components/rtsp/include/jpeg_header.hpp | Header include tweaks for formatting helpers |
| components/rtsp/idf_component.yml | Adds RTSP tags for RTP/audio/H264 |
| components/rtsp/example/main/rtsp_example.cpp | Greatly expands example to cover new APIs/modes |
| components/rtsp/example/main/Kconfig.projbuild | Adds example mode selection + API-test toggle |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR refactors the RTSP component so it is no longer MJPEG-only and can support codec-specific packetizers/depacketizers and multiple tracks per session.
It also includes a broader set of fixes and follow-on work that were needed to make the refactor usable in practice:
components/rtsparound multi-track RTP packetizers/depacketizers for MJPEG, H264, and generic audio payloadssend_frame(track_id, ...)Motivation and Context
Closes #524
Enables multi-track client/server (which enables audio+video simultaneously) while also enabling other video formats besides MJPEG.
It also fixes some issues:
This PR completes that work so the RTSP stack can reliably support MJPEG video, H264 video, and PCM audio tracks, while keeping the older MJPEG-oriented workflows working.
How has this been tested?
Host / Python:
cd lib && ./build.shpython rtsp_server.pypython rtsp_server.py --use-displaypython rtsp_client.pypython rtsp_server_multitrack.pypython rtsp_client_multitrack.pyESP-IDF example builds:
cd components/rtsp/example && . ~/esp/esp-idf/export.sh && idf.py buildcd components/socket/example && . ~/esp/esp-idf/export.sh && idf.py buildHardware / manual validation:
Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):
N/A
Types of changes
Checklist:
Software
.github/workflows/build.ymlfile to add my new test to the automated cloud build github action.