2016-04-04 18:04:14 +08:00
|
|
|
//ZoneMinder Packet Queue Interface Class
|
|
|
|
//Copyright 2016 Steve Gilvarry
|
|
|
|
//
|
|
|
|
//This file is part of ZoneMinder.
|
|
|
|
//
|
|
|
|
//ZoneMinder is free software: you can redistribute it and/or modify
|
|
|
|
//it under the terms of the GNU General Public License as published by
|
|
|
|
//the Free Software Foundation, either version 3 of the License, or
|
|
|
|
//(at your option) any later version.
|
|
|
|
//
|
|
|
|
//ZoneMinder is distributed in the hope that it will be useful,
|
|
|
|
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
//GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
//You should have received a copy of the GNU General Public License
|
|
|
|
//along with ZoneMinder. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef ZM_PACKETQUEUE_H
|
|
|
|
#define ZM_PACKETQUEUE_H
|
|
|
|
|
2016-09-17 03:54:13 +08:00
|
|
|
//#include <boost/interprocess/managed_shared_memory.hpp>
|
|
|
|
//#include <boost/interprocess/containers/map.hpp>
|
|
|
|
//#include <boost/interprocess/allocators/allocator.hpp>
|
2017-04-13 01:39:47 +08:00
|
|
|
#include <list>
|
2017-02-19 04:22:56 +08:00
|
|
|
#include "zm_packet.h"
|
2017-12-08 23:39:57 +08:00
|
|
|
#include "zm_thread.h"
|
2020-12-10 04:01:24 +08:00
|
|
|
#include <mutex>
|
|
|
|
#include <condition_variable>
|
2016-04-04 18:04:14 +08:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
}
|
|
|
|
class zm_packetqueue {
|
2017-12-01 03:37:36 +08:00
|
|
|
public: // For now just to ease development
|
|
|
|
std::list<ZMPacket *> pktQueue;
|
|
|
|
std::list<ZMPacket *>::iterator analysis_it;
|
|
|
|
|
2017-12-01 20:26:34 +08:00
|
|
|
int video_stream_id;
|
2017-12-01 03:37:36 +08:00
|
|
|
int video_packet_count; // keep track of how many video packets we have, because we shouldn't have more than image_buffer_count
|
2017-12-08 23:39:57 +08:00
|
|
|
int first_video_packet_index;
|
2017-12-06 05:16:52 +08:00
|
|
|
int max_video_packet_count; // allow a negative value to someday mean unlimited
|
2018-10-21 05:31:14 +08:00
|
|
|
int max_stream_id;
|
|
|
|
int *packet_counts; /* packet count for each stream_id, to keep track of how many video vs audio packets are in the queue */
|
2020-12-10 04:01:24 +08:00
|
|
|
bool deleting;
|
2017-12-01 03:37:36 +08:00
|
|
|
|
2020-12-10 04:01:24 +08:00
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable condition;
|
2017-12-08 23:39:57 +08:00
|
|
|
|
2018-10-21 05:31:14 +08:00
|
|
|
public:
|
|
|
|
zm_packetqueue(int p_max_video_packet_count, int p_video_stream_id, int p_audio_stream_id);
|
2016-05-08 13:25:18 +08:00
|
|
|
virtual ~zm_packetqueue();
|
2017-12-08 23:39:57 +08:00
|
|
|
|
2018-10-15 22:51:56 +08:00
|
|
|
bool queuePacket(ZMPacket* packet);
|
|
|
|
ZMPacket * popPacket();
|
2017-02-19 04:22:56 +08:00
|
|
|
bool popVideoPacket(ZMPacket* packet);
|
|
|
|
bool popAudioPacket(ZMPacket* packet);
|
2018-10-15 22:51:56 +08:00
|
|
|
unsigned int clearQueue(unsigned int video_frames_to_keep, int stream_id);
|
2019-11-02 05:29:55 +08:00
|
|
|
unsigned int clearQueue(struct timeval *duration, int streamid);
|
2018-10-15 22:51:56 +08:00
|
|
|
void clearQueue();
|
2019-06-21 03:14:20 +08:00
|
|
|
void dumpQueue();
|
2016-09-21 04:59:43 +08:00
|
|
|
unsigned int size();
|
2017-11-22 00:58:15 +08:00
|
|
|
unsigned int get_video_packet_count();
|
2019-08-23 00:57:00 +08:00
|
|
|
|
2019-06-27 23:11:14 +08:00
|
|
|
void clear_unwanted_packets(timeval *recording, int pre_event_count, int mVideoStreamId);
|
2018-10-15 22:51:56 +08:00
|
|
|
int packet_count(int stream_id);
|
2016-04-04 18:04:14 +08:00
|
|
|
|
2017-12-01 03:37:36 +08:00
|
|
|
// Functions to manage the analysis frame logic
|
|
|
|
bool increment_analysis_it();
|
|
|
|
ZMPacket *get_analysis_packet();
|
2020-12-22 23:20:44 +08:00
|
|
|
std::list<ZMPacket *>::iterator get_analysis_it() const { return analysis_it; }
|
|
|
|
std::list<ZMPacket *>::iterator get_event_start_packet_it(
|
|
|
|
std::list<ZMPacket *>::iterator snapshot_it,
|
|
|
|
unsigned int pre_event_count
|
|
|
|
);
|
2016-04-04 18:04:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* ZM_PACKETQUEUE_H */
|