Skip to content

Conversation

vikramdattu
Copy link
Contributor

@vikramdattu vikramdattu commented May 23, 2025

*** This is a placeholder PR: Not to be merged ****

This PR is meant to showcase the work which will bring the support for ESP-IDF build support and hence the Espressif chipsets.

Structure:

  • Changes specific to ESP-IDF are put under esp_port directory.
  • Go to the example webrtc_classic and build it as ESP-IDF example.

Setup ESP-IDF

Setup ESP_IDF with release/v5.4 branch: https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/linux-macos-setup.html

BUILD

cd esp_port/examples/webrtc_classic
idf.py set-target esp32s3 # Or esp32p4 etc
idf.py build

Flash the code on chip and run monitor

idf.py flash
idf.py monitor

The work is under progress, will keep rebasing as and when common functionality code keeps getting into main repository.

@sirknightj @unicornss

We have two options:

  1. Upstream and merge all the changes to this repo: Not as-is of course and will have reviews from structure and code point of view
  2. The esp_port maintained by Espressif with some suitable name under espressif/ organisation. It will use amazon-kinesis-video-sdk-c as a submodule or need developer to set path of cloned repo.

We can keep this PR for discussion ground continue discussion on other aspects of how best we can go about this. I prefer the option 1, simply because it remains maintained under single roof without needing to constant rebasing.

@vikramdattu vikramdattu force-pushed the esp_amazon_kvs_sdk_c branch 2 times, most recently from d9ab49b to b3e9d05 Compare May 28, 2025 11:57
@vikramdattu
Copy link
Contributor Author

@sirknightj @unicornss do you have comments on this?
If you look at my solution, I have added a esp_port directory containing extra needed components and examples specific to ESP-IDF build system. (There are a few, very few, changes in the common source files specific to ESP-IDF under macro checks)
I would like to know if you want to suggest adding a generic port layer which can be leveraged by other platforms to build solutions based on this SDK? For example, this might have port directory and different platform ports can stay in the directory etc.

I would like to speed up the porting process as per your comments, so that the repo can then be used in-time for ESP-IDF based open-source solutions, viz., esp-rainmaker and esp-matter etc.

@vikramdattu vikramdattu force-pushed the esp_amazon_kvs_sdk_c branch 4 times, most recently from 4ff89b5 to b96ece0 Compare June 4, 2025 13:55
@aggarg
Copy link
Contributor

aggarg commented Jun 5, 2025

You may want to review the reference integration for the Realtek Ameba Pro2 Mini board at: https://github.com/awslabs/freertos-webrtc-reference-on-amebapro-for-amazon-kinesis-video-streams.

This reference integration utilizes our OS-agnostic libraries. You can adopt a similar approach to develop an integration for the ESP platform.

@vikramdattu
Copy link
Contributor Author

You may want to review the reference integration for the Realtek Ameba Pro2 Mini board at: https://github.com/awslabs/freertos-webrtc-reference-on-amebapro-for-amazon-kinesis-video-streams.

This reference integration utilizes our OS-agnostic libraries. You can adopt a similar approach to develop an integration for the ESP platform.

@aggarg

This solution in my particular PR is the working one. Only requiring the discussion on the final structure of the code to make it acceptable.

The approach you have shared is completely different take from what I've achieved. The particular ameba implementation does not use this repo, and hence I cannot go yet another implementation approach using multiple components. My goal is to get this repo adopted on ESP platforms and make the existing sources/APIs generic enough as is to be able to be used for ESP chipsets.

@vikramdattu vikramdattu force-pushed the esp_amazon_kvs_sdk_c branch 4 times, most recently from 6ad13b1 to 7f787a0 Compare June 12, 2025 05:45
@vikramdattu vikramdattu force-pushed the esp_amazon_kvs_sdk_c branch 3 times, most recently from 278e573 to ea74bf0 Compare June 18, 2025 15:26
### Install pkg-config

```bash
sudo apt-get install pkg-config
Copy link
Contributor

Choose a reason for hiding this comment

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

Would recommend adding the sudo apt-get update step just in case.

- AWS_KVS_LOG_LEVEL

- You may override the above settings in `main/app_main.c` file of the example also.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest also adding the commands to use the idf.py to:

  • Connect the board to your computer (micro usb)
  • Build the project
  • Flash project onto the ESP board (and any buttons that need to be pressed or held down during the flash, any LED indicators that we can look for)

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps also some links to troubleshooting documentation in case there is something blocking USB access in the computer (the board is not reachable)


- ESP_WIFI_SSID
- ESP_WIFI_PASSWORD
- ESP_MAXIMUM_RETRY
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the majority of the fields here are self explanatory, except ESP_MAXIMUM_RETRY.

Perhaps we can make a table with the options along with a description.

@@ -0,0 +1,92 @@
@startuml
Copy link
Contributor

Choose a reason for hiding this comment

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

I saw this which you might want to look at -- to get these displayed in one of the readmes: https://github.com/Zingam/UML-in-Markdown

Alternatively, GitHub supports mermaid diagrams - https://github.blog/developer-skills/github/include-diagrams-markdown-files-mermaid/

- AWS_SECRET_ACCESS_KEY
- AWS_DEFAULT_REGION
- AWS_KVS_CHANNEL
- AWS_KVS_LOG_LEVEL
Copy link
Contributor

Choose a reason for hiding this comment

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

I saw some sample frames in one of the folders, would it make sense to have an option to use the camera sensor vs. pre-generated frames?

frame.frameData = pSampleConfiguration->pVideoFrameBuffer;
frame.size = frameSize;

CHK_STATUS(app_media_read_frame_from_disk(frame.frameData, &frameSize, filePath));
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the frames being read from here

 - Handle partial writes by sending data in multiple iterations
 - Use retries when message send fails
 - Track and handle message receive if in parts using `receiveMessage` var
 - Retries increased from 3 to 10
 - Consider ENOMEM or PBUF errors also for retries

These changes help to retain sockets longer for embedded devices
 - Use dynamically allocated WSS URL
 - Use dynamic allocations for singaling payload
 - Use required only allocations in LwsApiCalls instead large static arrays
 - Added ifaddr altenate for ESP-IDF
 - Created abstracted API for IDF_CMAKE platform to query local IP
 - Do not treat SO_SNDBUF not available as fatal
 - Use custom thread implementation for receiveLwsMessageWrapper
 - Custom thread implementation for connectionListener
 - esp_hosted + esp_wifi_remote enabled chipsets not having wifi/BT to use it via n/w adapter
 - network_coprocessor component can be use with network_adapter
 - Cleanly added the support under esp_port directory
 - Added ESP specific components, submodules and an webrtc_classic example
 - Added `app_common` needed as a common functionality for webrtc example/s.
 - Added network_adapter example: Needed when we want to use the webrtc_classic on P4+C6 board
 - Added esp_websocket_client over libwebsockets for ESP-IDF
 - Using this as default for ESP port as it provides better flexibility for ESP-IDF
 - It helps packing and unpacking of signaling messages
 - These serialized messages then can be transfered on any transport
 - Added streaming_only and signaling_only examples
 - streaming_only can be flashed on P4 and signaling only on C6
 - The message exchange between the two happens over webrtc_bridge
 - esp_port/README.md: Added complete description and setup guide for ESP chipsets
 - esp_port/README.md: Describe two solutions: webrtc_classic and split mode
 - Added puml diagrams under esp_port/docs showcasing the workflow in both modes
 - Added a README under example/app_common/spiffs/certs/
 - Patch1: Support LWIP in split_mode. Allows port filtering in lwip_opts.h
 - Patch2: Work-around for STATUS define. KVS too uses `STATUS` for return values. Guard the IDF STATUS under `#ifndef STATUS`
 - e.g., config structure can be inited with most common config and fine tuned thereon
```c
    WebRtcAppConfig webrtcConfig = WEBRTC_APP_CONFIG_DEFAULT();
```
 - Bugfix: make a copy of `awsCredentialOptions` so that it can be re-used out of scope
…webrtcAppRun

 - This allows us keep webrtcAppInit lighter and move webrtcAppRun to different task
 - Application should not need to take care of fitting the message received from webrtc_bridge into SDK's structure format
 - The message will simply be deserialized and passed to SDK using `webrtcAppSignalingMessageReceived` API
 - Messages from SDK are received via callback and we can send to webrtc_bridge from application
 - hosted: Fixed build for IDF release/v5.5
…leio

 - This is helpful where our cert files are actually in NVS
 - Also updated the README for esp_webrtc_utils component
 - app_webrtc.c: Use fileIO wrapper functions instead of direct file ops
…ient

 - We simply store the server time globally when we do http requests
 - Use that gloabal time for aws signature and Date header while websocket connect
 - Can be useful for provisioning workflows OR any other use cases where host needs BT
 - Aggressive timeout makes board reboot prematurely.
 - Wait for max 10 seconds before SDIO transport is ready
 - New API `webrtcAppCreateAndSendOffer`, can be called to initiate the offer
 - Also, spin the mediaSender thread in handlerAnswer
 - Works in Viewer mode of KVS WebRTC
 - The camera registers to a room and initiates the sdp offer
 - The client can join the room(this sends the sdp answer to camera)
 - peer connection is established and feed can be viewed
 - TURN servers are not `MUST` for the peer connection
 - The device can still continue with the STUN server
 - In cases where, server is configured to not allow IceServers, we can continue
 - Application should not need to take care of fitting the message received from webrtc_bridge into SDK's structure format
 - The message will simply be deserialized and passed to SDK using `webrtcAppSignalingMessageReceived` API
 - Messages from SDK are received via callback and we can send to webrtc_bridge from application
 - New API `webrtcAppCreateAndSendOffer`, can be called to initiate the offer
 - Also, spin the mediaSender thread in handlerAnswer
 - Attempt reconnections from webrtc task when disconnections happen
   - Reconnections are handled with new task in LwsApiCalls.c
   - Workflow was broken with LwsApiCallsESP.c: We now handle it from webrtc_task itself
 - Do not reboot the device when using wifi-set CLI command
@vikramdattu vikramdattu force-pushed the esp_amazon_kvs_sdk_c branch from ea74bf0 to f65eeca Compare August 1, 2025 15:20
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