fix: zms limits the playback buffer in the URL to the monitor's StreamReplayBuffer refs #7536 (#7537)

This commit is contained in:
Jash Ambaliya authored and GitHub committed 2026-11-25 18:15:57 -05:00
1 parent 7d0a578ae7
commit 0cfe982cba
4 files changed
+33

No files matched your search

+1
View File
@@ -1197,6 +1197,7 @@ class Monitor : public std::enable_shared_from_this<Monitor> {
AVCodecContext *GetVideoCodecContext() const { return mVideoCodecContext; };
std::string GetSecondPath() const { return second_path; };
int GetStreamReplayBuffer() const { return stream_replay_buffer; }
std::string GetStreamSocketPath() const { return shared_data ? shared_data->stream_socket_path : ""; };
std::string GetRTSPStreamName() const { return rtsp_streamname; };
+1
View File
@@ -561,6 +561,7 @@ void MonitorStream::runStream() {
TimePoint last_mem_report = stream_start_time;
const Seconds mem_report_interval = Seconds(30);
playback_buffer = MonitorStreamClampBuffer(playback_buffer, monitor->GetStreamReplayBuffer());
temp_image_buffer_count = playback_buffer;
temp_read_index = temp_image_buffer_count.load();
temp_write_index = temp_image_buffer_count.load();
+9
View File
@@ -37,6 +37,15 @@ inline int MonitorStreamBufferLevel(int write_index, int read_index, int buffer_
return (((write_index - read_index + buffer_count) % buffer_count) * 100) / buffer_count;
}
// The buffer= value in the zms URL sizes an allocation, so a client may not ask
// for more than the monitor's own StreamReplayBuffer (a negative request, such
// as an unsigned value that wrapped, gets none).
inline int MonitorStreamClampBuffer(int requested, int allowed) {
if (requested <= 0 || allowed <= 0)
return 0;
return requested > allowed ? allowed : requested;
}
class MonitorStream : public StreamBase {
protected:
struct SwapImage {
+22
View File
@@ -23,6 +23,7 @@
#include "zm_monitor.h"
#include "zm_zone.h"
#include <climits>
#include <cstdio>
#include <fstream>
#include <iterator>
@@ -246,3 +247,24 @@ TEST_CASE("MonitorStream starts a new zoom from the whole frame after stored JPE
CHECK(used.crop().Hi().x_ == fresh.crop().Hi().x_);
CHECK(used.crop().Hi().y_ == fresh.crop().Hi().y_);
}
TEST_CASE("MonitorStreamClampBuffer") {
SECTION("a request above the monitor's replay buffer is cut to it") {
REQUIRE(MonitorStreamClampBuffer(20000000, 100) == 100);
REQUIRE(MonitorStreamClampBuffer(2000000000, 25) == 25);
}
SECTION("a request within the replay buffer is kept") {
REQUIRE(MonitorStreamClampBuffer(50, 100) == 50);
REQUIRE(MonitorStreamClampBuffer(100, 100) == 100);
}
SECTION("no buffer when either value is not positive") {
REQUIRE(MonitorStreamClampBuffer(0, 100) == 0);
REQUIRE(MonitorStreamClampBuffer(-5, 100) == 0);
REQUIRE(MonitorStreamClampBuffer(INT_MIN, 100) == 0);
REQUIRE(MonitorStreamClampBuffer(50, 0) == 0);
REQUIRE(MonitorStreamClampBuffer(50, -1) == 0);
REQUIRE(MonitorStreamClampBuffer(2000000000, 0) == 0);
}
}