Commit Graph
86 Commits
Author SHA1 Message Date
Isaac ConnorandClaude Opus 4.8 3b633a281b fix: Rotate/Flip honor borrowed source linesize; size Flip dest for 32-aligned planes
get_y_image() wraps the decoder Y plane zero-copy but recorded
FFALIGN(width,32) as the Image stride instead of the frame's real
linesize[0]. For widths that are not a multiple of 32 the decoder packs
the plane tighter than FFALIGN, so:

- Image::Rotate/Flip re-derived the source stride via
  av_image_fill_arrays(...,32) and read past the end of the borrowed
  plane (and skewed Y-channel motion analysis, which reads the same
  buffer).
- Image::Flip sized its destination from this->size, which is tight for a
  borrowed plane and smaller than the 32-aligned layout the planes are
  written at, overrunning the destination.

Record the frame's real linesize in get_y_image(); use the Image's own
linesize for the source plane-0 stride in Rotate/Flip; size Flip's
destination from av_image_get_buffer_size(...,32). All are no-ops for
self-consistent ZM-allocated (32-aligned) images.

tests/zm_image_linesize.cpp: Rotate 90/180/270 and Flip H/V over a tight,
non-32-aligned GRAY8 source verifying correct output.

refs #4788

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-13 09:35:40 -04:00
Isaac ConnorandClaude Opus 4.6 21d0e68673 perf: add monotonic queue_index to ZMPacket for O(1) iterator lookup
Add a uint64_t queue_index field to ZMPacket, assigned by PacketQueue
on enqueue via a monotonic counter. This lets clearPackets() find the
earliest iterator-pointed packet with a single min() over the 2-3
iterators, then check each scanned packet with one integer comparison
instead of searching a vector of shared_ptrs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 23:41:48 -05:00
Isaac Connor 63410fbd20 Cleanup recieve_frame 2026-02-07 16:49:53 -05:00
Isaac ConnorandClaude Opus 4.5 94f3a5771b fix: release GPU surfaces immediately after hw transfer
The nvidia-vaapi-driver would fail with "list argument exceeds maximum
number" when decoding HEVC because GPU surfaces were being held in the
packet queue after transfer, exhausting the VAAPI surface pool.

Changes:
- Transfer hw frames to software immediately in receive_frame() while
  the VA context is still valid, then release the GPU surface
- Check hw_frames_ctx in needs_hw_transfer() to detect already-transferred
  frames
- Remove extra_hw_frames and thread_count settings (not needed with
  immediate surface release)
- Fix EAGAIN handling in send_packet to wait instead of busy-loop

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 22:51:21 -05:00
Isaac Connor da13e5f1a7 Clean up error case return code 2026-01-27 09:00:01 -05:00
Isaac Connor 70c4d7bacd Remove ::decode which is no good. Move hw transfer stuff to transfer_hwframe and needs_hw_transfer 2026-01-26 15:11:38 -05:00
Isaac Connor 31c76557be Return a y-image for any suitable format that has a y-plane. Specifically this allows NV12 to work. 2026-01-26 13:18:14 -05:00
Isaac Connor b79f8b7b51 Add get_y-image 2026-01-26 12:54:31 -05:00
Isaac Connor 518c8d8de0 Fixup hwtransfer when using hwaccel 2026-01-25 18:00:49 -05:00
Isaac Connor e8adc89e0c Add send_packet and receive_frame, as we move towards deprecating send_packet_receive_frame 2026-01-22 21:43:19 -05:00
Isaac Connor db4cb94455 Add analyzed to zm_packet 2026-01-16 15:48:56 -05:00
Isaac Connor 509e189bfd Handle unlocking an unlocked packet 2026-01-16 11:55:03 -05:00
Isaac Connor ca375c11ab Fix Whitespace 2026-01-15 12:46:23 -05:00
Isaac Connor 131b5caee0 Update to RAII style ZMPacketLock. Rename snap to packet in zm_monitor. Keep hw_frame in packet." 2026-01-15 12:46:23 -05:00
Isaac Connor 643fe97b25 Deprecate zm_av_frame_alloc 2025-09-18 14:48:52 -04:00
Isaac Connor 8cdc173cbb Join lines 2025-07-08 17:45:20 -04:00
Aaron Kling c4683d90a9 Format code using astyle google format
Commands used:
astyle --style=google --indent=spaces=2 --keep-one-line-blocks src/*.cpp
astyle --style=google --indent=spaces=2 --keep-one-line-blocks src/*.h
2024-03-26 13:43:58 -05:00
Isaac Connor b3a262fc9b Fix crash due to using unrotated y-channel image. Put the y-image creation in ::Decode, stored in ZMPacket. 2022-11-22 12:38:48 -05:00
Doug Nazar f4dd897ef4 Convert AVFrame* to custom unique_ptr (av_frame_ptr).
Switch all owning AVFrame* variables to av_frame_ptr for
automatic cleanup.

Use AVBufferRef to store frame data in AVFrame where appropriate
so that it can be freed automatically with it's AVFrame.

Handle allocation errors.
2022-07-30 13:21:11 -04:00
Doug Nazar 110cc436a3 Switch from av_init_packet() to av_packet_alloc()
Remove all uses of deprecated av_init_packet() and switch any stack
based AVPackets to unique_ptrs allocated with av_packet_alloc().

Ensure that all code paths call av_packet_unref() after use to reset
before next usage.
2022-07-29 14:56:26 -04:00
Isaac Connor a7bed00275 Introduce a quick function to return the amount of ram a zmpacket is using 2022-06-17 13:26:49 -04:00
Isaac Connor 4154731f13 test for ctx->sw_pix_fmt being AV_PIX_FMT_NONE before trying to do do hwdevice transfer 2022-04-18 18:06:05 -04:00
Isaac Connor 30fa641186 initialize video_first_pts and when setting it need to specify microseconds otherwise we get nanoseconds. White space. 2021-09-21 14:29:05 -04:00
Peter Keresztes Schmidt 707975e567 Monitor: Convert API to std::chrono 2021-06-13 23:22:49 +02:00
Isaac Connor 84035ef4f7 Adjust debug logging 2021-06-08 16:54:41 -04:00
Peter Keresztes Schmidt 2d71743372 FFmpeg: Remove code paths required only by 2.8 and older
With Xenial support dropped we require FFmpeg 3.2 and newer.
2021-06-05 20:40:12 +02:00
Isaac Connor 4fcdeb7287 Fix alignment in get_out_frame. Fixes #3233. If width % 32 then we can't use the more efficient 32 aligned scaling. 2021-05-21 10:37:51 -04:00
Isaac Connor 68fb87c861 Remove debug 2021-05-17 16:32:33 -04:00
Isaac Connor 3cd9bdccd5 style and performance improvements reported by cppcheck 2021-05-09 16:39:38 -04:00
Isaac Connor 2cf6ad8089 Switch ZMPacket * to a shared_ptr<ZMPacket>. This is so that in LockedPacket we can unlock and then notify and be confident that packet_ won't have been deleted. Change ZMPacket->timestamp to be a timeval instead of timeval *. This might not have been necessary but I like it. No longer cuse the ZMPacket object to wrap the shared image buffers and timestamps. Use a vector for image_buffers. 2021-05-08 21:14:20 -04:00
Isaac Connor 3645ccea1b Make vaapi accelerated encoding work 2021-05-04 20:20:33 -04:00
Isaac Connor b6af846664 add missing initializers 2021-04-20 17:09:14 -04:00
Isaac Connor 9903e909af Rework locking in ZMPacket by using a new class called ZMLockedPacket. 2021-03-15 17:05:30 -04:00
Isaac Connor b238a2bc25 Implement decoder thread, locking is broken 2021-03-15 15:08:43 -04:00
Isaac Connor e0d54a6d11 remove deprecated reset and tidy up a bit 2021-03-13 16:30:41 -05:00
Isaac Connor b87d859f72 Set the packet's stream_index to the packetqueue stream. Rename get_ functions to get 2021-03-03 12:06:34 -05:00
Isaac Connor 64c601fc7b Must fix_deprecations on both values 2021-02-22 20:40:30 -05:00
Isaac Connor 730cd815d3 Add frame format to debug logging. Use fix_deprecated_fmt to fix when ctx->fmt is yuvj420p instead of yuv420p 2021-02-22 15:48:16 -05:00
Isaac Connor e562888ed0 Fix crash when decoder returns 0 and when are using hwaccel 2021-02-19 21:03:10 -05:00
Isaac Connor ed6fc9fca6 use av_frame_copy_props to copy frame members instead of doing it manually 2021-02-19 12:44:24 -05:00
Peter Keresztes Schmidt 938676b129 ffmpeg: exit dumpPacket early if debug logging is not enabled 2021-02-07 11:58:17 +01:00
Peter Keresztes Schmidt 0dbc39ee25 Cleanup and reorganize includes
With this commit a unified structure for includes is introduced.
The general rules:
 * Only include what you need
 * Include wherever possible in the cpp and forward-declare in the header

 The includes are sorted in a local to global fashion. This means for the include order:
  0. If cpp file: The corresponding h file and an empty line
  1. Includes from the project sorted alphabetically
  2. System/library includes sorted alphabetically
  3. Conditional includes
2021-02-04 18:02:01 +01:00
Isaac Connor fdadacac6c set packet.size and data because av_init_packet don't do that 2021-01-31 21:31:33 -05:00
Isaac Connor b93aab6a11 turn off hwtransfer direct to image. Too compliated for now with not enough benefit 2021-01-30 12:34:29 -05:00
Isaac Connor 4bd813d980 Don't try to transfer image when there is no image available 2021-01-28 10:22:14 -05:00
Isaac Connor 2baa22dc85 Fix case when hwaccel not compiled in 2021-01-28 10:16:58 -05:00
Isaac Connor 608afcbbd2 return bytes consumed by decode 2021-01-27 16:12:49 -05:00
Isaac Connor 5b7fc210fe Only use direct to rgb0 when image colours are 4 2021-01-12 14:12:09 -05:00
Isaac Connor f7be54fe11 Add detecting target pixfmt and if rgb0 is supported, use it to do the transfer direct to the Image. 2021-01-11 13:46:50 -05:00
Isaac Connor 09264a52ff use zm_av_send_packet_receive_frame and fixup hwaccel support 2021-01-11 13:46:50 -05:00