mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-05-24 14:36:09 -04:00
Merge branch 'master' into reorder_queue
This commit is contained in:
@@ -11,7 +11,6 @@ AnalysisThread::AnalysisThread(Monitor *monitor) :
|
||||
|
||||
AnalysisThread::~AnalysisThread() {
|
||||
Stop();
|
||||
if (thread_.joinable()) thread_.join();
|
||||
}
|
||||
|
||||
void AnalysisThread::Start() {
|
||||
@@ -21,6 +20,11 @@ void AnalysisThread::Start() {
|
||||
thread_ = std::thread(&AnalysisThread::Run, this);
|
||||
}
|
||||
|
||||
void AnalysisThread::Stop() {
|
||||
terminate_ = true;
|
||||
if (thread_.joinable()) thread_.join();
|
||||
}
|
||||
|
||||
void AnalysisThread::Run() {
|
||||
while (!(terminate_ or zm_terminate)) {
|
||||
// Some periodic updates are required for variable capturing framerate
|
||||
|
||||
@@ -15,7 +15,7 @@ class AnalysisThread {
|
||||
AnalysisThread(AnalysisThread &&rhs) = delete;
|
||||
|
||||
void Start();
|
||||
void Stop() { terminate_ = true; }
|
||||
void Stop();
|
||||
bool Stopped() const { return terminate_; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -10,7 +10,6 @@ DecoderThread::DecoderThread(Monitor *monitor) :
|
||||
|
||||
DecoderThread::~DecoderThread() {
|
||||
Stop();
|
||||
if (thread_.joinable()) thread_.join();
|
||||
}
|
||||
|
||||
void DecoderThread::Start() {
|
||||
@@ -18,6 +17,12 @@ void DecoderThread::Start() {
|
||||
terminate_ = false;
|
||||
thread_ = std::thread(&DecoderThread::Run, this);
|
||||
}
|
||||
|
||||
void DecoderThread::Stop() {
|
||||
terminate_ = true;
|
||||
if (thread_.joinable()) thread_.join();
|
||||
}
|
||||
|
||||
void DecoderThread::Run() {
|
||||
Debug(2, "DecoderThread::Run() for %d", monitor_->Id());
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class DecoderThread {
|
||||
DecoderThread(DecoderThread &&rhs) = delete;
|
||||
|
||||
void Start();
|
||||
void Stop() { terminate_ = true; }
|
||||
void Stop();
|
||||
|
||||
private:
|
||||
void Run();
|
||||
|
||||
@@ -2215,9 +2215,9 @@ bool Monitor::Analyse() {
|
||||
shared_data->state = state = IDLE;
|
||||
} // end if ( trigger_data->trigger_state != TRIGGER_OFF )
|
||||
|
||||
packetqueue.clearPackets(snap);
|
||||
|
||||
if (snap->codec_type == AVMEDIA_TYPE_VIDEO) {
|
||||
packetqueue.clearPackets(snap);
|
||||
// Only do these if it's a video packet.
|
||||
shared_data->last_read_index = snap->image_index;
|
||||
analysis_image_count++;
|
||||
@@ -3144,8 +3144,14 @@ int Monitor::PrimeCapture() {
|
||||
int Monitor::PreCapture() const { return camera->PreCapture(); }
|
||||
int Monitor::PostCapture() const { return camera->PostCapture(); }
|
||||
int Monitor::Close() {
|
||||
Debug(1, "Stopping packetqueue");
|
||||
// Wake everyone up
|
||||
packetqueue.stop();
|
||||
Debug(1, "Stopped packetqueue");
|
||||
|
||||
// Because the stream indexes may change we have to clear out the packetqueue
|
||||
if (decoder) {
|
||||
Debug(1, "Decoder stopping");
|
||||
decoder->Stop();
|
||||
Debug(1, "Decoder stopped");
|
||||
}
|
||||
@@ -3187,10 +3193,6 @@ int Monitor::Close() {
|
||||
video_fifo = nullptr;
|
||||
}
|
||||
|
||||
Debug(1, "Stopping packetqueue");
|
||||
// Wake everyone up
|
||||
packetqueue.stop();
|
||||
Debug(1, "Stopped packetqueue");
|
||||
|
||||
if (close_event_thread.joinable()) {
|
||||
Debug(1, "Joining event thread");
|
||||
|
||||
@@ -87,54 +87,17 @@ bool PacketQueue::queuePacket(std::shared_ptr<ZMPacket> add_packet) {
|
||||
{
|
||||
std::unique_lock<std::mutex> lck(mutex);
|
||||
if (deleting or zm_terminate) return false;
|
||||
#if 0
|
||||
bool have_out_of_order = false;
|
||||
auto rit = pktQueue.rbegin();
|
||||
if (add_packet->packet.dts != AV_NOPTS_VALUE) {
|
||||
// Find the previous packet for the stream, and check dts
|
||||
while (rit != pktQueue.rend()) {
|
||||
if ((*rit)->packet.stream_index == add_packet->packet.stream_index) {
|
||||
if ((*rit)->packet.dts <= add_packet->packet.dts) {
|
||||
Debug(1, "Found in order packet");
|
||||
ZM_DUMP_PACKET((*rit)->packet, "queued_packet");
|
||||
ZM_DUMP_PACKET(add_packet->packet, "add_packet");
|
||||
// packets are in order, everything is fine
|
||||
break;
|
||||
} else {
|
||||
ZM_DUMP_PACKET((*rit)->packet, "queued_packet");
|
||||
ZM_DUMP_PACKET(add_packet->packet, "add_packet");
|
||||
have_out_of_order = true;
|
||||
}
|
||||
}
|
||||
rit++;
|
||||
} // end while
|
||||
}
|
||||
if (have_out_of_order) {
|
||||
//auto it = rit.base(); it++; // insert inserts BEFORE the it, so we need to
|
||||
pktQueue.insert(rit.base(), add_packet);
|
||||
if (rit == pktQueue.rend()) {
|
||||
Warning("Unable to re-order packet");
|
||||
} else {
|
||||
Debug(1, "Found out of order packet");
|
||||
dumpQueue();
|
||||
pktQueue.push_back(add_packet);
|
||||
for (
|
||||
auto iterators_it = iterators.begin();
|
||||
iterators_it != iterators.end();
|
||||
++iterators_it
|
||||
) {
|
||||
packetqueue_iterator *iterator_it = *iterators_it;
|
||||
if (*iterator_it == pktQueue.end()) {
|
||||
--(*iterator_it);
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
pktQueue.push_back(add_packet);
|
||||
for (
|
||||
auto iterators_it = iterators.begin();
|
||||
iterators_it != iterators.end();
|
||||
++iterators_it
|
||||
) {
|
||||
packetqueue_iterator *iterator_it = *iterators_it;
|
||||
if (*iterator_it == pktQueue.end()) {
|
||||
--(*iterator_it);
|
||||
}
|
||||
} // end foreach iterator
|
||||
#if 0
|
||||
}
|
||||
#endif
|
||||
|
||||
} // end foreach iterator
|
||||
|
||||
packet_counts[add_packet->packet.stream_index] += 1;
|
||||
Debug(2, "packet counts for %d is %d",
|
||||
|
||||
Reference in New Issue
Block a user