ZoneMi...Memory(3pm)
π ZoneMinder::MappedMem π
okay bestie, welcome to ZoneMinder::MappedMem β the ZoneMinder Mapped Memory access module, straight out of the User Contributed Perl Documentation (that's the 3pm manual, iykyk). She's long, she's powerful, and she's about to make your life so much easier. let's GO π¦
β¨ NAME β¨
ZoneMinder::MappedMem β the ZoneMinder Mapped Memory access module. literally what it says on the tin, no cap.
πΈ SYNOPSIS πΈ
here's the vibe, in code, exactly as it goes down:
use ZoneMinder::MappedMem; use ZoneMinder::MappedMem qw(:all);
if ( zmMemVerify( $monitor ) ) {
$state = zmGetMonitorState( $monitor );
if ( $state == STATE_ALARM ) {
...
} }
( $lri, $lwi ) = zmMemRead( $monitor, [ 'shared_data:last_read_index',
'shared_data:last_write_index' ] ); zmMemWrite( $monitor, {
'trigger_data:trigger_showtext' => "Some Text" } );
see? iconic behaviour. π
π DESCRIPTION π
so, ZoneMinder::MappedMem is packed with methods for reading from and writing to mapped memory, plus a whole lil squad of helper methods for the common stuff you're gonna do over and over.
the core elements of ZoneMinder use mapped memory so that multiple things can access resources at the same time β like, shared access, main character energy for the whole system. and yes, ZoneMinder scripts have used this info before, but ngl, up until now it was difficult to access and prone to errors. π a mess. this module comes in and introduces a common API for mapped memory access β both reading and writing β which makes customising scripts, or even building your own, soooo much easier. obsessed.
the one thing you must remember: all the methods listed below need a 'monitor' parameter. this has to be a reference to a hash with at least the 'Id' field set to the monitor id of the mapped memory you wanna poke at. using database methods to select the monitor details will also return this kind of data, so you're covered there. and heads up β some of the mapped memory methods will add and amend new fields to this hash. so don't be shocked when it grows. π
π METHODS π
every single one, in order, no skips:
zmMemVerify ( $monitor );β verify that the mapped memory of the monitor given exists and is valid. it returns an undefined value if it's not valid. you should generally call this one first before using any of the others, but most of the remaining methods will also do it for you if the memory hasn't already been verified. considerate queens. πzmMemInvalidate ( $monitor );β after an error, this resets the mapped memory ids and attempts to reverify on the next operation. mostly used when a mapped memory segment has gone away and been recreated with a different id. the glow-up after the crisis. β¨zmMemRead ( $monitor, $readspec );β used to read data from the mapped memory attached to the given monitor. the mapped memory will be verified if it hasn't been already. the'readspec'must either be a string of the form"<section>:<field>"or a reference to an array of strings of that same format. first case β a single value comes back. latter case β a list of values comes back. errors cause undefined to be returned. the allowable sections and field names are described below, keep scrolling. πzmMemWrite ( $monitor, $writespec );β used to write data to the mapped memory attached to the given monitor. the mapped memory will be verified if it hasn't been already. the'writespec'must be a reference to a hash with keys of the form"<section>:<field>"and values as the data to be written. errors cause undefined to be returned, otherwise a non-undefined value comes back. allowable sections and field names are described below. π$state = zmGetMonitorState ( $monitor );β returns the current state of the given monitor. it's an integer value, and you can compare it with the STATE constants given below. β$event_id = zmGetLastEvent ( $monitor );β returns the event id of the last event that the monitor generated, or0if no event has been generated by the current monitor process.zmIsAlarmed ( $monitor );β returns1if the monitor given is currently in an alarm state,0otherwise.zmInAlarm ( $monitor );β returns1if the monitor given is currently in an alarm or alerted state,0otherwise.zmHasAlarmed ( $monitor );β returns1if the given monitor is in an alarm state, or has been in an alarm state since the last call to this method. it remembers. π( $x, $y ) = zmGetAlarmLocation ( $monitor );β returns an x,y pair showing the image co-ordinates of the centre of the last motion event generated by the given monitor. if no event has been generated by the current monitor process, or the alarm wasn't motion related, it returns-1,-1. πzmGetLastWriteTime ( $monitor );β returns the time (in utc seconds) since the last image was captured by the given monitor and written to shared memory, or0otherwise.zmGetLastReadTime ( $monitor );β returns the time (in utc seconds) since the last image was read from shared memory by the analysis daemon of the given monitor, or0otherwise, or if the monitor is in monitor only mode.zmMonitorSuspend ( $monitor );β suspend the given monitor from generating events caused by motion. you'd use this to stop camera actions like panning or zooming from triggering events. and if it's configured to do so, the monitor may automatically resume after a defined period. self-care era. π§zmMonitorResume ( $monitor );β allow the given monitor to resume generating events caused by motion. welcome back babe. π«ΆzmTriggerEventOn ( $monitor, $score, $cause [, $text, $showtext ] );β trigger the given monitor to generate an event. you must supply an event score and a cause string explaining the reason for the event. you may also supply a text string with further details about the event, and a showtext string which may be included in the timestamp annotation on any images captured during the event β if it's configured to do so. π₯zmTriggerEventOff ( $monitor );β trigger the given monitor to not generate any events. this method does not cancelzmTriggerEventOn, it's exclusive to it. the point is to let external triggers prevent normal events being generated by monitors, same way aszmMonitorSuspenddoes β but this one applies to all events, not just motion, and it's intended for longer timescales than are appropriate for suspension. big-picture blocking, periodt.zmTriggerEventCancel ( $monitor );β cancel any previous trigger on or off requests. this stops a triggered alarm, if one exists from a previous'on', and lets events be generated once more following a previous'off'. the reset button, the clean slate. πzmTriggerShowtext ( $monitor, $showtest );β indicate that the given text should be displayed in the timestamp annotation on any images captured, if the format of the annotation string defined for the monitor permits. β¨
π DATA π
the data fields in mapped memory that may be accessed go a lil something like this. there are two main sections: shared_data, which is general data, and trigger_data, which is used for event triggering. reading from these fields is harmless, but extreme care must be taken when writing to mapped memory β especially in the shared_data section, because that's normally written to only by monitor capture and analysis processes. do not be reckless bestie, that's not the vibe. π
π shared_data β the general mapped memory section
sizeβ the size, in bytes, of this sectionvalidβ flag indicating whether this section has been initialisedactiveβ flag indicating whether this monitor is active (enabled/disabled)signalβ flag indicating whether this monitor is receiving a valid signalstateβ the current monitor state, see the STATE constants belowlast_write_indexβ the last index, in the image buffer, that an image has been saved tolast_read_indexβ the last index, in the image buffer, that an image has been analysed fromlast_write_timeβ the time (in utc seconds) when the last image was capturedlast_read_timeβ the time (in utc seconds) when the last image was analysedlast_eventβ the id of the last event generated by the monitor analysis process,0if noneactionβ the monitor actions bitmask, see the ACTION constants belowbrightnessβ read/write location for the current monitor brightnesshueβ read/write location for the current monitor huecolourβ read/write location for the current monitor colourcontrastβ read/write location for the current monitor contrastalarm_xβ image x co-ordinate (from left) of the centre of the last motion event,-1if nonealarm_yβ image y co-ordinate (from top) of the centre of the last motion event,-1if nonealarm_causeβ the current alarm event cause string along with zone names(s) alarmed
π¦ trigger_data β the triggered event mapped memory section
sizeβ the size, in bytes of this sectiontrigger_stateβ the current trigger state, see the TRIGGER constants belowtrigger_scoreβ the current triggered event scoretrigger_causeβ the current triggered event cause stringtrigger_textβ the current triggered event descriptive text stringtrigger_showtextβ the triggered text that will be displayed on captured image timestamps
π CONSTANTS π
these constants are used by the methods above, but they're also up for grabs by user scripts if you need them. sharing is caring. π
STATE_IDLESTATE_PREALARMSTATE_ALARMSTATE_ALERTSTATE_TAPEβ these constants define the state of the monitor with respect to alarms and events. they're used in theshared_data:statefield.ACTION_GETACTION_SETACTION_RELOADACTION_SUSPENDACTION_RESUMEβ these constants define the various values that can exist in theshared_data:actionfield. this is a bitmask which, when non-zero, defines an action that an executing monitor process should take.ACTION_GETrequires that the current values ofbrightness,contrast,colourandhueare taken from the camera and written to the equivalent mapped memory fields.ACTION_SETimplies the reverse β that the values in mapped memory should be written to the camera.ACTION_RELOADsignals that the monitor process should reload itself from the database in case any settings have changed there.ACTION_SUSPENDsignals that a monitor should stop examining images for motion, though other alarms may still occur.ACTION_RESUMEsignals that a monitor should resume motion detection.
TRIGGER_CANCELTRIGGER_ONTRIGGER_OFFβ these constants are used in the definition of external triggers.TRIGGER_CANCELindicates that any previous trigger settings should be cancelled,TRIGGER_ONsignals that an alarm should be created (or continued) as a result of the current trigger, andTRIGGER_OFFsignals that the trigger should prevent any alarms from being generated. see the trigger methods above for further details. π
π EXPORT π
none by default, bestie. as in, nothing.
- the
:constantstag will export the mapped memory constants, which mostly define enumerations for the variables held in memory - the
:functionstag will export the mapped memory access functions - the
:alltag will export all above symbols
pick your fighter. β¨
π₯ SEE ALSO π₯
http://www.zoneminder.com β go, explore, slay.
π«Ά AUTHOR π«Ά
Philip Coombes, <philip.coombes@zoneminder.com>
and that's only part 1, so don't you dare close the tab β more is coming. πΈ
π COPYRIGHT AND LICENSE π
Okay bestie, legal moment but make it cute. β¨
Copyright (C) 2001-2008 Philip Coombes
This library is free software β like, actually free, not "free trial" free. You can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available. π
So fr fr: pick whichever Perl 5 version works for you, 5.8.3 or newer, and you're golden. π«Ά
And that's the whole page, bestie!! π You made it to the end of ZoneMi...Memory(3pm) β this version comes to you courtesy of perl v5.40.1, dated 2026-02-01. Go forth and memory-zone slay. ππ
π¦ where this page comes from
- ubuntu resolute: zoneminder 1.36.37+dfsg1-1 Β· GPL-2.0-or-later
- ubuntu stonking: zoneminder 1.36.37+dfsg1-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms