Commit Graph
30 Commits
Author SHA1 Message Date
LibretroAdmin 33c6ef9258 samples: FFmpeg 8 colour tags, and the AV1 hardware tests' MP4 writer
webm_av1_hw_test and preview_av1_hw_test still called make_mp4, which
the last change removed, and took the MP4 writer through
rav1_webm_fixture.h, which now asks for the byte helpers alone. Both
include rav1_mp4_fixture.h first for the whole writer and call
make_mp4_clip(1, 0).

FFmpeg 7.1 and later take a frame's primaries and transfer into the
encoder over the -color_primaries and -color_trc output options, so
libaom, libvpx and libx265 without its own colour parameters write
untagged streams. mp4_mux's HDR sources lost their transfer and run.py
stopped on the missing key; the frames are now tagged with setparams.
The same goes for the hand-run generators that tag through those
options alone: gen_av1_decode.py's colour stream, the D3D11 HDR AV1
fixtures and mkhdrfixtures.py's VP9 movies.

FFmpeg 8's concat also converts every segment to the first one's
colour space, so the ffmpeg_live colour-metadata lane could no longer
switch from BT.709 to BT.601 inside one lavfi graph: the second half
arrived converted and labelled BT.709. The lane now plays one BT.709
segment and its receive_frame wrapper relabels the frames after the
third as BT.601, which is the transition the driver has to follow.

The webm_player timeline-gap fixtures cut their silent second with
aselect before the encoder, and FFmpeg 8 closes that gap: the next
frame takes the previous one's end, so the packets ran on unbroken and
the seek into the gap found signal. The packets are now dropped after
the encoder with the noise bitstream filter, which keeps every
timestamp and gives the same packets on FFmpeg 6.1 and 8.
2026-11-05 21:10:54 +01:00
Codex 53280a4f5a camera: honor FFmpeg frame color range and matrix
Configure the cached scaler from each decoded frame's color metadata, with decoder metadata fallback and format defaults for unlabelled RGB, gray and YUVJ. Keep direct producer-buffer conversion. Cover full-to-limited range and BT.709-to-BT.601 transitions, plus unlabelled grayscale, checking every scaled output pixel.
2026-10-14 18:06:48 +02:00
Codex 162e6b2409 camera: pace FFmpeg transient read retries by frontend demand
Park the capture worker on EAGAIN or EINTR until another frontend poll requests a frame, using an eventcount and poll epoch to avoid lost wakeups. Stop wakes parked capture before joining. End non-transient read failures after one diagnostic. Cover idle and poll-driven retries, quiet transient errors, terminal errors, parked shutdown and recovery.
2026-10-14 17:56:48 +02:00
Codex 8cab584349 camera: clean up partial FFmpeg startup safely
Avoid flushing a missing decoder when startup fails after opening the input. Free the temporary options dictionary on every failure path. Cover stream discovery failure, invalid decoder calls during cleanup, and decoded pixels after a successful restart.
2026-10-14 14:14:56 +02:00
Codex 678bb1200d camera: refresh FFmpeg scaler for decoded frame changes
Use each decoded frame's dimensions and pixel format to refresh the cached scaler. Keep the requested output size and convert directly into the producer buffer. Cover a real H.264 stream changing from 32x16 YUV420P to 64x32 YUV444P, checking uniform pixels from both segments.
2026-10-14 14:11:00 +02:00
Codex fd67da1ab0 camera: stop FFmpeg capture after device removal
Exit the capture worker on ENODEV instead of repeatedly reading and logging a removed device. Preserve existing handling of other read errors and allow explicit stop/start recovery. Cover one failed read and successful restart with the live-driver fixture.
2026-10-14 14:03:29 +02:00
Codex 9ecdcecf6f camera: interrupt FFmpeg input reads when stopping capture
Install the shutdown callback before each input-open attempt and clear stale shutdown state before reopening. Treat a requested read interruption as normal worker completion.

Cover a controlled blocking read, failed-open fallback and restart, verifying cancellation occurs without the fixture timeout.
2026-10-14 13:47:39 +02:00
Codex e1795847f5 camera: drain FFmpeg decoder output and retain blocked packets
Receive all available frames after packet submission, retry retained input after decoder output makes progress, and flush delayed frames at input EOF. Keep direct conversion into producer-owned slots and stop checks between frames.

Cover buffered multi-frame output and a real H.264 B-frame source whose final frames require decoder drain. Treat already-drained EOF as normal during teardown.
2026-10-14 13:38:00 +02:00
Codex ccebba2f61 camera: route only selected video packets to FFmpeg decoder
Retain the selected stream index and release other packets without decoding or converting them. Cover an audio-first, video-second lavfi source, verifying video pixels and packet routing without additional copies.
2026-10-14 03:23:55 +02:00
Codex 0f9945b53c camera: stop FFmpeg capture worker at end of input
Treat EOF as completion rather than retrying the finished source and logging indefinitely. Keep the last published frame available, and assert one EOF read in the finite-source fixture.
2026-10-14 03:12:30 +02:00
Codex 44e9e63e20 camera: reset FFmpeg worker shutdown state on restart
Clear the atomic shutdown flag before launching the new capture worker. Require actual converted pixels after two starts, rather than accepting the initialized black frame as restart progress.
2026-10-14 03:04:56 +02:00
Codex ab412b2ce7 camera: keep FFmpeg device options out of decoder setup
Probe streams and open the decoder using codec parameters rather than capture-device options, so requested video_size cannot replace actual input dimensions. Advance leftover-option iteration and test a 34x18 source converted to 17x9.
2026-10-14 03:04:52 +02:00
Codex c7b36e8b04 camera: convert FFmpeg frames directly into producer slots
Point swscale output at the producer-owned triple-buffer slot, eliminating the staging image and full-frame copy. Align and pad output allocations for direct conversion, and retain slot ownership through callback completion.

Guard against staging copies and check slow-callback stability and odd-size converted pixels in the synthetic camera fixture.
2026-10-14 02:46:04 +02:00
Codex 86fe410309 tests: recycle PipeWire capture storage on buffer return
Overwrite returned capture storage in the padded native-frame case, verifying the callback consumes all pixels before the producer can reuse the buffer. This guards borrowed-frame lifetime without changing production behavior.
2026-10-14 01:59:30 +02:00
Codex 5250fb770b camera: borrow native PipeWire frames during raw callbacks
Deliver aligned native ARGB frames directly from capture storage, preserving chunk offset and pitch. Hold the capture buffer until the callback returns, then queue it once. Retain scaler conversion for other formats.

Verify pointer identity, padded-row pixels, untouched conversion output and callback-before-return ownership in the scripted driver fixture.
2026-10-14 01:54:04 +02:00
Codex 88a3bd986c camera: match PipeWire formats to native pixel byte order
SPA format names describe byte order, while scaler ARGB/ABGR formats describe native 32-bit words. Advertise BGRA/RGBA on little-endian hosts and retain ARGB/ABGR on big-endian hosts. Update negotiation and pixel regressions to use the corresponding native layouts.
2026-10-14 01:44:27 +02:00
Codex 87c7802a45 camera: clear PipeWire conversion state on format removal
Release output and scaler resources when PipeWire clears the format, and suppress conversion until a new output buffer is configured. Cover stale-frame suppression, repeated clear, unrelated parameters and renegotiation.
2026-10-14 01:41:12 +02:00
Codex db99971432 camera: release PipeWire output buffers on format replacement
Free the previous output allocation before replacing it during format negotiation. Exercise repeated format and size changes with leak checking enabled.
2026-10-14 01:38:11 +02:00
Codex fcd66f7851 scaler: support direct ABGR to ARGB conversion
Reuse the symmetric red/blue swap converter for the reverse direction, allowing advertised PipeWire ABGR camera frames to convert.

Cover every alpha value with padded input/output rows in SIMD and scalar builds, and exercise ABGR format negotiation and pixels in the camera fixture.
2026-10-14 01:35:27 +02:00
Codex a8307627d4 camera: match PipeWire strides to negotiated pixel formats
Use the negotiated pixel size for both buffer requests and scaler input strides. Cover ARGB, BGR and YUY2 negotiation, with pixel-exact ARGB and BGR conversion using the packed-stride fallback.
2026-10-14 01:32:03 +02:00
Codex 65ad54d06f camera: deactivate a streaming PipeWire camera on stop
Request deactivation while streaming; a paused stream is already stopped. Cover streaming stop, paused stop, restart, and already-started behavior in the scripted driver fixture.
2026-10-14 01:27:32 +02:00
Codex 92723d9260 camera: honor PipeWire frame offsets and row strides
Use the SPA chunk offset and stride when converting camera frames, validate the contiguous image extent, and restore the negotiated stride after conversion. Return every dequeued buffer once.

Add pixel-exact coverage for offset padded rows and a subsequent packed frame with implicit stride.
2026-10-14 01:24:13 +02:00
LibretroAdmin 21635dd171 samples: build with -g1 instead of -g
The sample and test builds used full debug info. -g1 keeps what
sanitizer reports and backtraces need - function names, files and line
numbers - and drops the variable and type information nobody reads in
CI. Objects get about 30% smaller (rh265.o under ASan+UBSan: 5.1MB to
3.7MB), so the ccache caches hold more of each job's build and are
quicker to restore and save.
2026-10-13 11:50:11 +02:00
LibretroAdmin c0db9af777 camera/pipewire: one dequeue attempt per poll, return every buffer
preprocess_image() looped until pw_stream_dequeue_buffer() handed it a
buffer, which parks the main thread until the camera's next frame
lands - a full camera period on every poll a slower camera has nothing
for, and indefinitely once the stream stalls. A poll now makes one
attempt and reports no frame when the queue is empty.

A buffer without CPU-visible data was also dropped without being
queued back, so each one shrank the pool the stream has to work with.
Every dequeued buffer now goes back on every exit.

samples/camera/pipewire_poll drives the driver's poll against a
scripted stream with the pw_stream calls link-wrapped and checks each
case; it runs in the samples/cores workflow next to the ffmpeg camera
lane.
2026-10-12 20:45:08 +02:00
libretroadmin 8042f59dbc camera: frames reach the core as planar YCbCr, in place
RETRO_CAMERA_BUFFER_PLANAR hands a core the capture device's own 4:2:0
planes, untouched, for the duration of the callback; the frame
callback sits past the end of retro_camera_callback and is read only
when its caps bit is set, so older cores are never read past.

The Android driver picks the cheapest delivery the core accepts: the
SurfaceTexture for a GL hardware context, the planes for a planar
core, and XRGB8888 converted once by image_yuv_blit only for a core
that takes nothing else. Planes come from Camera2 through the NDK
(resolved at runtime, the HAL buffer mapped where it lies) and fall
back to the legacy Camera's NV21 preview buffers, rotated between the
camera and the reader without a copy. No permission is declared: a
port that declares CAMERA gets the prompt, others get no camera.
2026-10-10 19:44:44 +02:00
libretroadmin afbad7a104 samples: shared sources build into each sample's own obj/
Samples compiled shared tree sources in place, so whichever sample ran
next linked those objects with the flags they were built with, as
unity_identity did with mic_handshake's ASan objects. Every sample that
builds a source from outside its directory now includes
sample_objdir.mk and maps those objects under its own obj/; its own
objects stay where they were. The rule for the mapped objects has a
slash in its target, so make 3.81 does not strip the directory.

tools/sample_objdir_check.py dry-runs every sample Makefile and fails
on an object written outside the sample; the Samples-Objdir-Check
workflow runs it.
2026-10-10 19:43:34 +02:00
LibretroAdmin 19a164a59d camera/ffmpeg: frames go to the core through a triple buffer
A poll hands the core the newest finished frame, and the decode
thread fills the next one while the core reads, however long the
core takes. Each turn releases the packet av_read_frame() filled, and
stop() frees the conversion planes start() allocated.

ffmpeg_live_test adds a counting source whose last frame a poll must
show, and a 300 ms frame callback the thread must keep decoding
through; its ASan lane checks for leaks.
2026-10-02 09:42:11 +02:00
libretroadmin c04bc789d6 Clear warnings in thread-less, microphone-less and GL-less builds
runloop_msg_queue_off_main() is built only with HAVE_THREADS, like its
callers. WASAPI's error-string helper is built only with
HAVE_MICROPHONE, the one path that calls it, and the driver casts
GetProcAddress straight to its function-pointer types, so it builds in
the Windows C89_BUILD lane. The ffmpeg core's slot helpers for the GL
path are built only with OpenGL, and its channel-layout declaration
sits at the top of its block. The IIR filter's RIAA CD case marks its
fall into the high shelf, and the ffmpeg_live sample's GL frame
callback has the libretro signature, which GCC 14 and later require.

The compile matrix installs mingw-w64, which turns its Direct3D lanes
on, and compiles WASAPI with the C89 flags both with and without the
microphone, treating unused functions as errors. That lane compiles
for real rather than with -fsyntax-only, which never reports unused
static functions.
2026-09-23 06:36:16 +02:00
LibretroAdmin d12e50b716 camera: a driver is opened at one packed size
camera_driver_t init takes the requested frame size as one word, which
the frontend packs from the setting or the core's request. The FFmpeg
driver keeps its requested and target sizes that way, V4L2 the size
its device negotiated, and the PipeWire format builder takes the
size packed. The FFmpeg live test checks that frames arrive at the
size asked for.
2026-09-23 06:02:24 +02:00
LibretroAdmin e165fdc107 (Camera) A synthetic camera for the ffmpeg driver, and the two things it found
The camera driver had no test, because testing it meant owning a
webcam. It does not: the driver reads from a libavdevice input
format, and built with that format set to libavfilter a filter graph
is the device. The whole pipeline then runs with nothing attached -
avformat opens the source, the poll thread reads packets, the
decoder decodes them, swscale converts into the target buffer and
poll() takes the frame out under the buffer's lock. Two seams make
that possible, and both are worth having on their own account:

- FFMPEG_CAMERA_DEFAULT_BACKEND respects a definition the build has
  already made, rather than choosing by platform regardless.

- The device the frontend names is used. It was taken as an argument
  and never read: a user who picked a camera got whichever one
  enumerated first. A named device is now the source url and
  enumeration is skipped.

ffmpeg_live_test drives what the threading has to get right and what
no eyeball on a webcam would show: open, run and close; stop and
start three times over; stop while the poll thread is mid-frame,
five times with the stop at a different point each time - which is
the ordering fixed a moment ago, where the flush used to run against
a live decoding thread; free without stopping first, as a host
dropping content does; poll before starting; and a source that does
not exist. Every frame is read pixel by pixel, so a buffer that was
freed or is the wrong size shows under ASan rather than as a
wrong-looking picture.

And one in libretro-common, which UBSan found on the first run:
memalign_alloc keeps the pointer to free in the word before the
address it returns, so that address must be aligned for a pointer
whatever the caller asked for. The camera asks for 4, which on a
64-bit host put the header on a four-byte boundary - a misaligned
store of a pointer, undefined everywhere and a fault on a target
that does not allow it. A boundary is a minimum, so it is raised to
a pointer's.

Plain, ASan/UBSan and TSan all clean; in the cores samples CI.
2026-09-11 09:35:51 +02:00