You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
captureOutput:didOutputSampleBuffer:fromConnection: allocated and freed
four full-frame scratch buffers on every callback: an intermediate
colour-converted image, a rotated image, an optional mirrored image,
and a scaled image. For a 720p BGRA camera at 30 fps that was roughly
3.5 MB × 4 allocations × 30 Hz of allocator churn on the main thread
(the delegate queue is dispatch_get_main_queue() - see
setSampleBufferDelegate:queue: in setupCameraSession).
Cache the buffers on the AVCameraManager singleton via private ivars
in a class extension. Grow on demand (realloc only when the required
size exceeds the current capacity), otherwise reuse. Camera source
resolution is effectively constant for the life of a session, so
after the first frame no allocator work happens. Scratch buffers are
freed in avfoundation_free via a new teardownScratchBuffers method,
so a driver teardown/re-init with a different target resolution does
not leak stale capacity.
The original code swapped rotatedBuffer.data = mirroredBuffer on
successful mirror; with stable per-frame buffer identities that trick
no longer fits. Replace it with a local 'scaleSource' pointer that
selects between the rotated and mirrored buffer, preserving the same
fallback semantics (mirror failure scales from the rotated buffer).
Also silence two per-frame RARCH_LOG statements (the aspect-fill
scaling dimensions and the 270-degree rotation notice) by putting
them behind #ifdef DEBUG. They duplicate information already logged
once at init and produced one log line per camera frame in release
builds.
ARC / MRC compatibility: the file is compiled under MRC in the top-
level Makefile and the RetroArch*.xcodeproj / RetroArch_OSX107 / iOS13
projects, and under ARC in the iOS6-11 projects and the iOS Theos
build. The new code uses only plain-C pointers for the scratch
buffers (invisible to ARC's memory management), no explicit
retain/release/autorelease calls, and a method name
(teardownScratchBuffers) that avoids the release/init/copy/new/
mutableCopy selector families that ARC treats specially. No
-dealloc override is added - it would require [super dealloc] under
MRC (banned under ARC), and the singleton is never dealloc'd in
practice; teardownScratchBuffers from avfoundation_free is the real
cleanup path.
Thread-safety: unchanged. The capture delegate is invoked on the
main queue and the consumer of frameBuffer reads on the main thread
as well; no new synchronization introduced. The scratch-buffer
realloc happens in the same callback that uses them.
0 commit comments