check for terminating before locking packetqueue. Handle when pre_event_count==0

This commit is contained in:
Isaac Connor 2021-01-26 12:23:44 -05:00
parent e4831909d6
commit e73e6aaabc
1 changed files with 18 additions and 15 deletions

View File

@ -428,6 +428,8 @@ int zm_packetqueue::packet_count(int stream_id) {
// Returns a packet. Packet will be locked
ZMPacket *zm_packetqueue::get_packet(packetqueue_iterator *it) {
if ( deleting or zm_terminate )
return nullptr;
Debug(4, "Locking in get_packet using it %p queue end? %d, packet %p",
*it, (*it == pktQueue.end()), *(*it));
@ -497,17 +499,19 @@ std::list<ZMPacket *>::iterator zm_packetqueue::get_event_start_packet_it(
dumpPacket(&((*it)->packet));
// Step one count back pre_event_count frames as the minimum
// Do not assume that snapshot_it is video
Debug(1, "Checking for keyframe %p", *it);
Debug(1, "Checking for keyframe begin %p", *(pktQueue.begin()));
// snapshot it might already point to the beginning
while ( ( it != pktQueue.begin() ) and pre_event_count ) {
Debug(1, "Previous packet pre %d index %d keyframe %d", pre_event_count, (*it)->packet.stream_index, (*it)->keyframe);
Debug(1, "Previous packet pre_event_count %d stream_index %d keyframe %d", pre_event_count, (*it)->packet.stream_index, (*it)->keyframe);
dumpPacket(&((*it)->packet));
if ( (*it)->packet.stream_index != video_stream_id ) {
if ( (*it)->packet.stream_index == video_stream_id ) {
pre_event_count --;
if ( ! pre_event_count )
break;
}
it--;
}
// it either points to beginning or we have seen pre_event_count video packets.
if ( it == pktQueue.begin() ) {
Debug(1, "Hit begin");
// hit end, the first packet in the queue should ALWAYS be a video keyframe.
@ -523,19 +527,18 @@ std::list<ZMPacket *>::iterator zm_packetqueue::get_event_start_packet_it(
}
return it;
}
Debug(1, "Checking for keyframe %p", *it);
// Not at beginning, so must be pointing at a video keyframe or maybe pre_event_count == 0
if ( (*it)->keyframe ) {
Debug(1, "Returning");
Debug(1, "Previous packet pre %d index %d keyframe %d", pre_event_count, (*it)->image_index, (*it)->keyframe);
dumpPacket(&((*it)->packet), "Found video keyframe, Returning");
return it;
}
Debug(1, "Wasnt Checking for keyframe");
while ( ( it-- != pktQueue.begin() ) and ! (*it)->keyframe ) {
Debug(1, "No keyframe");
dumpPacket( &((*it)->packet ) );
while ( it-- != pktQueue.begin() ) {
dumpPacket(&((*it)->packet), "No keyframe");
if ( (*it)->packet.stream_index == video_stream_id and (*it)->keyframe )
return it; // Success
}
Debug(1, "Checking for keyframe");
if ( !(*it)->keyframe ) {
Warning("Hit end of packetqueue before satisfying pre_event_count. Needed %d more video frames", pre_event_count);
}