The MPEG encoder's size is set by the stream's first frame. When playback moved
on to an event from a monitor with another aspect ratio, PackImage scaled its
frames to that size and distorted them. Scale them to fit inside it, centred on
black, with even sizes and offsets so subsampled chroma stays aligned. The black
fill is done by hand because av_image_fill_black needs FFmpeg 4.2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A packed planar frame whose width is a multiple of 32, such as 32x16 YUV420P,
has the same luma stride as the 32-byte layout, so PackImage picked that layout
and then refused the image because it needs more bytes than the frame has. The
frame was dropped. Accept a layout only if it also fits Size(), so the packed
one is tried next.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PackImage assumed every Image has 32-byte-aligned rows. An Image that wraps a
caller's buffer is packed (width * colours), and one wrapping an AVFrame keeps
the frame's stride, so mapping them on a 32-byte stride read the wrong rows
and ran past the end of the buffer. Use LineSize() for packed formats, match it
against the 32-byte or packed layout for planar ones, and refuse a mapping
larger than Size().
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Gapless playback over zms follows the next/prev events the event view
sends with CMD_SET_EVENT. Reviewing the first version found these gaps:
- An event that ended before the UI's hint for it arrived fell back to
zms's same-monitor query and skipped the other monitors' events again.
The page needs a status poll and two requests to send that hint, and
at 10x a ten second event lasts one second. Once a UI has sent any
hint (ui_managed) zms never uses the same-monitor query: it holds on
the last frame, like a pause, until the hint arrives, and stops after
kHintWait (10s) if none does. Streams with no UI behave as before.
The choice is EventStream::ChooseNeighbour, a static so it is tested.
- A hinted event deleted since the UI found it fell back to the
same-monitor query, leaving the filter. It now stops there, as
stream.php already does for a target deleted before forwarding.
- MPEG streams copied each frame into encoder buffers sized for the
first frame's dimensions, format and packed stride. Text frames are
drawn in the monitor's colours (usually RGB32) while event frames are
RGB24, a frame from another monitor can be larger, and Image rows are
padded to 32 bytes, so all three overran those buffers. The scaling
added to StreamBase only handled size, and the live stream never set
the tracked size. VideoStream::EncodeImage now converts any Image to
the encoder's own size, format and stride with sws_scale, and every
MPEG path uses it; the tracking in StreamBase is gone.
- loadEventData kept the previous event's video decoder when the new
event had none, so a missing jpeg showed the previous camera's frame
under the new event. It now drops it.
- The MPEG path only read jpegs, so an event recorded as video only
streamed nothing. Both paths now take frames from loadFrameImage,
which falls back to the event's video as the jpeg path already did.
tests/zm_eventstream_hints.cpp covers the message decoding, which hint
applies to which event, ChooseNeighbour (including Id order
10(M1) 11(M2) 12(M1) 13(M2), which went 11 -> 13) and PackImage.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Six format-dispatch fallbacks were still printing only the legacy
`colours` value, but the dispatch in each spot is now keyed off
pixelFormat/imagePixFormat. With the GRAY8/YUV420P alias collision
(both colours=1) the legacy value frequently doesn't identify the true
format, so a "Unexpected colours: 1" log on a misroute is useless.
Updated each Panic to include the AVPixelFormat enum value and its
human-readable name (via av_get_pix_fmt_name), plus the legacy
(colours, subpixelorder) for context:
- RemoteCameraRtsp constructor
- FfmpegCamera constructor
- VncCamera constructor
- LocalCamera conversion-selection branch
- VideoStream::SetupCodec mpeg helper
- Image::Delta unknown-format fallback
refs #4788
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ZM_COLOUR_GRAY8, ZM_COLOUR_YUV420P, and ZM_COLOUR_YUVJ420P were all
defined to 1, making format identification via colours ambiguous.
LocalCamera misidentified YUV420P as GRAY8, causing V4L2 MJPEG cameras
to decode to grayscale via expensive sws_scale conversion.
Replace the legacy ZM_COLOUR_*/ZM_SUBPIX_ORDER_* integer pair with
AVPixelFormat as the single source of truth for pixel format dispatch:
- Add src/zm_pixformat.h with central format helpers:
zm_pixformat_from_colours, zm_colours_from_pixformat,
zm_bytes_per_pixel, zm_db_colours_to_pixformat, zm_is_rgb32,
zm_is_rgb24, zm_is_yuv420
- Add AVPixelFormat pixelFormat member + PixelFormat() accessor to Camera
- Add PixFormat() accessor to Image, delegate AVPixFormat methods
to shared helpers
- Migrate all ~100 format dispatch comparisons in zm_image.cpp,
zm_local_camera.cpp, zm_ffmpeg_camera.cpp, zm_remote_camera_rtsp.cpp,
zm_libvlc_camera.cpp, zm_libvnc_camera.cpp, zm_monitor.cpp,
zm_mpeg.cpp from colours/subpixelorder checks to imagePixFormat/
AVPixelFormat checks
- Deprecate GetFFMPEGPixelFormat, delegate to zm_pixformat_from_colours
- Fix DeColourise bug: imagePixFormat was not updated to GRAY8
- Deprecate ZM_COLOUR_* and ZM_SUBPIX_ORDER_* constants in zm_rgb.h
- Add deprecation notice on Monitor.Colours web UI dropdown
- Add 13 Catch2 test cases (105 assertions) for format mapping helpers
refs #4735
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
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.
FFmpeg is an integral component of ZM. Promote the appropriate libraries to required dependencies.
This reduces the possible build configurations greatly and thus maintenance burden.
FFmpeg is an integral component of ZM. Promote the appropriate libraries to required dependencies.
This reduces the possible build configurations greatly and thus maintenance burden.
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