Skip to content

ESP32‑P4 port: crash in add_idct8x8 when decoding High Profile streams #28

Description

@youkorr

Hello edge264 team,
I’m porting edge264 to ESP32‑P4 (RISC‑V, 400 MHz dual‑core) to decode H.264 High Profile streams from IP cameras in an embedded project.I’ve compiled edge264 myself for ESP32‑P4 and integrated it as a C++ wrapper component in an ESPHome‑based project.
Project context

My project: https://github.com/youkorr/ip-camera-viewer (branch claude/test-coverage-analysis-2viujv)
I compiled edge264 for ESP32‑P4 using [brief description of your toolchain/flags, e.g., ESP‑IDF 5.x, RISC‑V toolchain, -Os, etc.].
The decoder is wrapped in a C++ class (H264HpDecoder) that calls edge264_alloc, edge264_decode_NAL, edge264_get_frame, etc.
Memory is allocated in PSRAM via heap_caps_aligned_alloc with 64‑byte alignment (see psram_alloc_cb below).
I’m using single‑thread mode (n_threads=0) to avoid FreeRTOS stack issues.

Relevant code snippets:

// h264_hp_decoder.cpp
void *psram_alloc_cb(size_t size, size_t align, void *user) {
size_t effective_align = (align < 64) ? 64 : align;
return heap_caps_aligned_alloc(effective_align, size, MALLOC_CAP_SPIRAM);
}

bool H264HpDecoder::begin(int n_threads) {
// Force single-thread for stability
n_threads = 0;
dec_ = edge264_alloc(n_threads, psram_alloc_cb, psram_free_cb, nullptr, nullptr);
// ...
}

Problem
When decoding a High Profile stream (profile_idc=100, level_idc=51), the ESP32‑P4 crashes inside add_idct8x8:

PC: 0x400D9A82 → add_idct8x8 at edge264.c
Reason: Fault - Unknown
Crashed core: 1

Baseline profiles work fine. The crash happens after the first IDR frame is decoded.
What I’ve tried

Forcing n_threads=0 in edge264_alloc.
Using PSRAM with 64‑byte alignment for sample and MB buffers.
Increasing FreeRTOS task stack sizes.
Adding argument checks before calling edge264_decode_NAL.
Testing with a simpler High Profile stream (low resolution, low bitrate) — same crash.

Questions

Are there any known issues or recommendations for running edge264 on RISC‑V targets, especially regarding IDCT 8×8 and High Profile decoding?
Are there specific alignment requirements for buffers passed to edge264_decode_NAL / add_idct8x8 that I might be missing?
Could the crash be related to assumptions about SIMD instructions or cache behavior that don’t hold on ESP32‑P4?
Do you have any suggestions for debugging add_idct8x8 on a non‑x86/ARM64 target?

I’m happy to share my build configuration, memory layout, and more detailed logs if that helps.
Thanks for your work on edge264 — it’s a great decoder, and I’d love to make it work reliably on ESP32‑P4!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions