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
|
|
|
|
|
2021-02-04 11:47:28 +08:00
|
|
|
#include <condition_variable>
|
2017-04-13 01:39:47 +08:00
|
|
|
#include <list>
|
2020-12-10 04:01:24 +08:00
|
|
|
#include <mutex>
|
2021-05-21 03:56:31 +08:00
|
|
|
#include <memory>
|
2016-04-04 18:04:14 +08:00
|
|
|
|
2021-02-04 11:47:28 +08:00
|
|
|
class ZMPacket;
|
2021-03-16 05:05:30 +08:00
|
|
|
class ZMLockedPacket;
|
2021-02-04 11:47:28 +08:00
|
|
|
|
2021-05-09 09:14:20 +08:00
|
|
|
typedef std::list<std::shared_ptr<ZMPacket>>::iterator packetqueue_iterator;
|
2021-01-07 22:43:53 +08:00
|
|
|
|
2021-02-01 10:30:12 +08:00
|
|
|
class PacketQueue {
|
2017-12-01 03:37:36 +08:00
|
|
|
public: // For now just to ease development
|
2021-05-09 09:14:20 +08:00
|
|
|
std::list<std::shared_ptr<ZMPacket>> pktQueue;
|
|
|
|
std::list<std::shared_ptr<ZMPacket>>::iterator analysis_it;
|
2017-12-01 03:37:36 +08:00
|
|
|
|
2017-12-01 20:26:34 +08:00
|
|
|
int video_stream_id;
|
2017-12-06 05:16:52 +08:00
|
|
|
int max_video_packet_count; // allow a negative value to someday mean unlimited
|
2021-03-27 02:26:37 +08:00
|
|
|
// This is now a hard limit on the # of video packets to keep in the queue so that we can limit ram
|
|
|
|
int pre_event_video_packet_count; // Was max_video_packet_count
|
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;
|
2021-03-23 00:04:32 +08:00
|
|
|
bool keep_keyframes;
|
2021-01-07 22:43:53 +08:00
|
|
|
std::list<packetqueue_iterator *> iterators;
|
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:
|
2021-02-01 10:30:12 +08:00
|
|
|
PacketQueue();
|
|
|
|
virtual ~PacketQueue();
|
2021-05-09 09:14:20 +08:00
|
|
|
std::list<std::shared_ptr<ZMPacket>>::const_iterator end() const { return pktQueue.end(); }
|
|
|
|
std::list<std::shared_ptr<ZMPacket>>::const_iterator begin() const { return pktQueue.begin(); }
|
2017-12-08 23:39:57 +08:00
|
|
|
|
2021-03-03 22:52:13 +08:00
|
|
|
int addStream();
|
2021-02-19 00:54:50 +08:00
|
|
|
void setMaxVideoPackets(int p);
|
2021-03-27 02:26:37 +08:00
|
|
|
void setPreEventVideoPackets(int p);
|
2021-03-23 00:04:32 +08:00
|
|
|
void setKeepKeyframes(bool k) { keep_keyframes = k; };
|
2021-02-01 10:30:12 +08:00
|
|
|
|
2021-05-09 09:14:20 +08:00
|
|
|
bool queuePacket(std::shared_ptr<ZMPacket> packet);
|
2021-02-01 10:30:12 +08:00
|
|
|
void clear();
|
2019-06-21 03:14:20 +08:00
|
|
|
void dumpQueue();
|
2016-09-21 04:59:43 +08:00
|
|
|
unsigned int size();
|
2020-12-23 08:52:09 +08:00
|
|
|
unsigned int get_packet_count(int stream_id) const { return packet_counts[stream_id]; };
|
2019-08-23 00:57:00 +08:00
|
|
|
|
2021-05-09 09:14:20 +08:00
|
|
|
void clearPackets(const std::shared_ptr<ZMPacket> &packet);
|
2018-10-15 22:51:56 +08:00
|
|
|
int packet_count(int stream_id);
|
2016-04-04 18:04:14 +08:00
|
|
|
|
2021-01-07 22:43:53 +08:00
|
|
|
bool increment_it(packetqueue_iterator *it);
|
|
|
|
bool increment_it(packetqueue_iterator *it, int stream_id);
|
2021-03-16 05:05:30 +08:00
|
|
|
ZMLockedPacket *get_packet(packetqueue_iterator *);
|
2021-06-04 06:21:46 +08:00
|
|
|
ZMLockedPacket *get_packet_and_increment_it(packetqueue_iterator *);
|
2021-01-07 22:43:53 +08:00
|
|
|
packetqueue_iterator *get_video_it(bool wait);
|
|
|
|
packetqueue_iterator *get_stream_it(int stream_id);
|
2021-02-01 23:25:48 +08:00
|
|
|
void free_it(packetqueue_iterator *);
|
2021-01-07 22:43:53 +08:00
|
|
|
|
2021-02-03 03:22:38 +08:00
|
|
|
packetqueue_iterator *get_event_start_packet_it(
|
2021-01-07 22:43:53 +08:00
|
|
|
packetqueue_iterator snapshot_it,
|
2020-12-22 23:20:44 +08:00
|
|
|
unsigned int pre_event_count
|
|
|
|
);
|
2021-05-09 09:14:20 +08:00
|
|
|
bool is_there_an_iterator_pointing_to_packet(const std::shared_ptr<ZMPacket> &zm_packet);
|
2021-04-01 23:52:28 +08:00
|
|
|
void unlock(ZMLockedPacket *lp);
|
2016-04-04 18:04:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* ZM_PACKETQUEUE_H */
|