blue-debug opened a new pull request, #21623:
URL: https://github.com/apache/nuttx/pull/21623

   *Note: Please adhere to [Contributing 
Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).*
   
   ## Summary
   
   When playback or recording glitches, the first question is whether the 
glitch is already in the data the application exchanged with the driver, or is 
added by the driver and the hardware below it. This PR adds AUDIOIOC_DUMP, 
which records the data passing through an audio device into a file, so the 
recording can be compared with the source or listened to.
   
   - audio: AUDIOIOC_DUMP takes a file path; the upper half creates the file 
and writes every buffer the lower half returns into it: the samples a playback 
buffer carried, before the buffer is cleared, or the samples a capture buffer 
received. A NULL path stops the recording, and a new path closes the previous 
file first. The recording belongs to the device, not to the open file that 
started it, so a separate tool can start and stop it while an application plays 
or records on its own open file. The write happens in `audio_dequeuebuffer()` 
before the spinlock is taken, and is skipped when a buffer is returned in 
interrupt context, since writing a file may block.
   - Documentation/audio: describe AUDIOIOC_DUMP.
   
   ## Impact
   
   Affects: audio upper half (audio/audio.c, include/nuttx/audio/audio.h), 
Documentation/os/audio.
   
   Behavior: nothing changes until AUDIOIOC_DUMP is issued. While a recording 
runs, each returned buffer costs a file write in the context that returns it, 
and a lower half that returns its buffers in interrupt context gets no 
recording.
   
   Compatibility: adds the AUDIOIOC_DUMP ioctl (`_AUDIOIOC(25)`); no struct or 
Kconfig changes.
   
   ## Testing
   
   Simulator (sim:alsa, 64-bit: CONFIG_SIM_M32 disabled because the host has no 
32-bit libasound). Every commit builds on its own with apache/nuttx-apps 
master, the tip also builds with CONFIG_AUDIO_MULTI_SESSION and with `-Werror`, 
and checkpatch passes.
   
   The host ALSA configuration is replaced with `ALSA_CONFIG_PATH`: playback 
goes into a `file` plugin so the data ALSA received can be compared, and 
capture reads from a file. A small test program (not part of this PR, built as 
`hello`) drives /dev/audio/pcm0p and /dev/audio/pcm0c. Steps:
   
   - `hello dump`: AUDIOIOC_DUMP(NULL) without a recording, and with a path in 
a directory that does not exist; play 16 buffers of 8 KiB with a recording to 
/host/dump_p.raw; record 16 buffers from /dev/audio/pcm0c with a recording to 
/host/dump_c.raw; compare each recording with the data the test queued or 
received
   - `hello dumpx`: start the recording on one open file and close it, play on 
a second open file, stop the recording on a third
   
   Logs (excerpt):
   
   ```
   nsh> uname -a
   NuttX 13.1.0 71fb276030c Nov 10 2026 14:23:35 sim sim
   nsh> mount -t hostfs -o fs=/tmp/upw/audiort/out /host
   nsh> hello dump
   === audtest dump
   PASS: DUMP(NULL) while not dumping ret 0
   PASS: DUMP("/nonexist/d.raw") ret -2
   PASS: playback: DUMP("/host/dump_p.raw") ret 0
   PASS: playback: 16 buffers played to COMPLETE
   PASS: playback: DUMP(NULL) ret 0
   PASS: playback dump: /host/dump_p.raw is 131072 bytes, expected 131072, 
identical
   PASS: playback ALSA: /host/alsa_played.raw is 131072 bytes, expected 131072, 
identical
   PASS: capture: CONFIGURE input ret 0
   PASS: capture: DUMP("/host/dump_c.raw") ret 0
   PASS: capture: 16 buffers, 131072 bytes received, ret 0
   PASS: capture: STOP ret 0, COMPLETE
   PASS: capture dump: /host/dump_c.raw is 131072 bytes, expected 131072, 
identical
   PASS: capture data vs ALSA infile: first 131072 bytes of /host/in.raw 
identical
   === audtest dump: PASS (0 failed)
   nsh> hello dumpx
   === audtest dumpx
   PASS: tool: open, DUMP("/host/dump_x.raw") ret 0, close
   PASS: app: 16 buffers played to COMPLETE
   PASS: tool: open, DUMP(NULL) ret 0, close
   PASS: dump started by another open: /host/dump_x.raw is 131072 bytes, 
expected 131072, identical
   === audtest dumpx: PASS (0 failed)
   ```
   
   Result: PASS. The playback recording is byte-identical to the data the 
application queued and to what ALSA received; the capture recording is 
byte-identical to the data the application received, which matches the ALSA 
input file. A recording started and stopped from other open files captures the 
application's stream completely.
   
   Additional platform coverage:
   
   - BES platform (Cortex-M55): Vela's audio stack uses AUDIOIOC_DUMP from a 
command-line tool that starts and stops the recording of a device while the 
media framework plays or records.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to