convert last_read_index and last_write_index to int32_t so that we can have -1 as a value in other functions.

This commit is contained in:
Isaac Connor 2021-02-16 14:43:52 -05:00
parent 317274248b
commit 59cdf971fa
3 changed files with 19 additions and 13 deletions

View File

@ -954,7 +954,7 @@ bool Monitor::connect() {
Debug(3, "Allocating %d image buffers", image_buffer_count);
image_buffer = new ZMPacket[image_buffer_count];
for ( int i = 0; i < image_buffer_count; i++ ) {
for ( uint32_t i = 0; i < image_buffer_count; i++ ) {
image_buffer[i].image_index = i;
image_buffer[i].timestamp = &(shared_timestamps[i]);
image_buffer[i].image = new Image(width, height, camera->Colours(), camera->SubpixelOrder(), &(shared_images[i*camera->ImageSize()]));
@ -1062,7 +1062,7 @@ bool Monitor::disconnect() {
#endif // ZM_MEM_MAPPED
if (image_buffer) {
for ( int i = 0; i < image_buffer_count; i++ ) {
for ( uint32_t i = 0; i < image_buffer_count; i++ ) {
// We delete the image because it is an object pointing to space that won't be free'd.
delete image_buffer[i].image;
image_buffer[i].image = nullptr;
@ -1148,7 +1148,7 @@ void Monitor::AddPrivacyBitmask(Zone *p_zones[]) {
privacy_bitmask = privacy_image->Buffer();
}
int Monitor::GetImage(int index, int scale) {
int Monitor::GetImage(int32_t index, int scale) {
if ( index < 0 || index > image_buffer_count ) {
index = shared_data->last_write_index;
}
@ -1215,7 +1215,7 @@ uint64_t Monitor::GetLastEventId() const {
double Monitor::GetFPS() const {
return get_capture_fps();
// last_write_index is the last capture index. It starts as == image_buffer_count so that the first asignment % image_buffer_count = 0;
int index1 = shared_data->last_write_index;
uint32_t index1 = shared_data->last_write_index;
if ( index1 >= image_buffer_count ) {
// last_write_index only has this value on startup before capturing anything.
return 0.0;
@ -1229,9 +1229,9 @@ double Monitor::GetFPS() const {
}
struct timeval time1 = *snap1->timestamp;
int fps_image_count = image_buffer_count;
uint32_t fps_image_count = image_buffer_count;
int index2 = (index1+1)%image_buffer_count;
uint32_t index2 = (index1+1)%image_buffer_count;
Debug(2, "index2(%d)", index2);
ZMPacket *snap2 = &image_buffer[index2];
// the timestamp pointers are initialized on connection, so that's redundant

View File

@ -105,8 +105,8 @@ protected:
/* sizeof(SharedData) expected to be 344 bytes on 32bit and 64bit */
typedef struct {
uint32_t size; /* +0 */
uint32_t last_write_index; /* +4 */
uint32_t last_read_index; /* +8 */
int32_t last_write_index; /* +4 */
int32_t last_read_index; /* +8 */
uint32_t state; /* +12 */
double capture_fps; // Current capturing fps
double analysis_fps; // Current analysis fps
@ -286,7 +286,7 @@ protected:
char label_format[64]; // The format of the timestamp on the images
Coord label_coord; // The coordinates of the timestamp on the images
int label_size; // Size of the timestamp on the images
int image_buffer_count; // Size of circular image buffer, at least twice the size of the pre_event_count
int32_t image_buffer_count; // Size of circular image buffer, at least twice the size of the pre_event_count
int pre_event_buffer_count; // Size of dedicated circular pre event buffer used when analysis is not performed at capturing framerate,
// value is pre_event_count + alarm_frame_count - 1
int warmup_count; // How many images to process before looking for events
@ -470,7 +470,7 @@ public:
void SetVideoWriterStartTime(const struct timeval &t) { video_store_data->recording = t; }
unsigned int GetPreEventCount() const { return pre_event_count; };
int GetImageBufferCount() const { return image_buffer_count; };
int32_t GetImageBufferCount() const { return image_buffer_count; };
State GetState() const { return (State)shared_data->state; }
AVStream *GetAudioStream() const { return camera ? camera->get_AudioStream() : nullptr; };
@ -478,7 +478,7 @@ public:
AVStream *GetVideoStream() const { return camera ? camera->get_VideoStream() : nullptr; };
AVCodecContext *GetVideoCodecContext() const { return camera ? camera->get_VideoCodecContext() : nullptr; };
int GetImage( int index=-1, int scale=100 );
int GetImage(int32_t index=-1, int scale=100);
ZMPacket *getSnapshot( int index=-1 ) const;
struct timeval GetTimestamp( int index=-1 ) const;
void UpdateAdaptiveSkip();

View File

@ -487,7 +487,7 @@ void MonitorStream::runStream() {
updateFrameRate(monitor->GetFPS());
// point to end which is theoretically not a valid value because all indexes are % image_buffer_count
unsigned int last_read_index = monitor->image_buffer_count;
int32_t last_read_index = monitor->image_buffer_count;
time_t stream_start_time;
time(&stream_start_time);
@ -850,7 +850,13 @@ void MonitorStream::SingleImage(int scale) {
int img_buffer_size = 0;
static JOCTET img_buffer[ZM_MAX_IMAGE_SIZE];
Image scaled_image;
ZMPacket *snap = &(monitor->image_buffer[monitor->shared_data->last_write_index]);
while ( monitor->shared_data->last_write_index >= monitor->image_buffer_count ) {
Debug(1, "Waiting for capture to begin");
usleep(100000);
}
int index = monitor->shared_data->last_write_index % monitor->image_buffer_count;
Debug(1, "write index: %d %d", monitor->shared_data->last_write_index, index);
ZMPacket *snap = &(monitor->image_buffer[index]);
Image *snap_image = snap->image;
if ( scale != ZM_SCALE_BASE ) {