= 0 ? $value : null; if (!is_string($value) || !preg_match('/^[0-9]{1,20}$/', $value)) return null; $value = ltrim($value, '0'); if ($value === '') return 0; $max = (string)PHP_INT_MAX; if (strlen($value) > strlen($max) || (strlen($value) == strlen($max) && strcmp($value, $max) > 0)) return null; return intval($value); } // Big-endian uint64 as two 32-bit words, so it works on 32-bit PHP, where // pack('J') is not available. function packEventId64($id) { if (PHP_INT_SIZE >= 8) { return pack('NN', ($id >> 32) & 0xFFFFFFFF, $id & 0xFFFFFFFF); } return pack('NN', 0, $id); } // The low 48 bits, big-endian: a 16-bit then a 32-bit word. zms compares the // same 48 bits of the event it is playing. function packEventId48($id) { if (PHP_INT_SIZE >= 8) { return pack('nN', ($id >> 32) & 0xFFFF, $id & 0xFFFFFFFF); } return pack('nN', 0, $id); } // The message for zms: MSG_CMD, the command, the direction (0 next, 1 prev), // the target (0 when the filter has no neighbour) and the event it was computed // for. See MsgCommand in src/zm_stream.h. function packSetEventMessage($msg_cmd, $command, $prev, $event_id, $source_event_id) { return pack('lcC', $msg_cmd, $command, $prev ? 1 : 0) .packEventId64($event_id) .packEventId48($source_event_id); } // A command carrying seconds for zms (CMD_SEEK, CMD_MAXFPS): whole seconds then // microseconds, each a big-endian uint32. The fraction is rounded, not // truncated: 2.3 - 2 is 0.29999999999999982, which truncated to 299999us and // seeked to the frame before the one at 2.3s. function packSecondsMessage($msg_cmd, $command, $seconds) { // Round only the fraction, so whole seconds past 2147 still fit a 32-bit PHP int. $s = floatval($seconds); $sec = (int)floor($s); $us = (int)round(($s - $sec) * 1000000); if ($us >= 1000000) { $sec += 1; $us = 0; } return pack('lcNN', $msg_cmd, $command, $sec, $us); } ?>