check for terminating before locking packetqueue. Handle when pre_event_count==0
This commit is contained in:
parent
e4831909d6
commit
e73e6aaabc
|
@ -428,6 +428,8 @@ int zm_packetqueue::packet_count(int stream_id) {
|
||||||
|
|
||||||
// Returns a packet. Packet will be locked
|
// Returns a packet. Packet will be locked
|
||||||
ZMPacket *zm_packetqueue::get_packet(packetqueue_iterator *it) {
|
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",
|
Debug(4, "Locking in get_packet using it %p queue end? %d, packet %p",
|
||||||
*it, (*it == pktQueue.end()), *(*it));
|
*it, (*it == pktQueue.end()), *(*it));
|
||||||
|
@ -494,20 +496,22 @@ std::list<ZMPacket *>::iterator zm_packetqueue::get_event_start_packet_it(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
std::list<ZMPacket *>::iterator it = snapshot_it;
|
std::list<ZMPacket *>::iterator it = snapshot_it;
|
||||||
dumpPacket( &((*it)->packet ) );
|
dumpPacket(&((*it)->packet));
|
||||||
// Step one count back pre_event_count frames as the minimum
|
// Step one count back pre_event_count frames as the minimum
|
||||||
// Do not assume that snapshot_it is video
|
// 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
|
// snapshot it might already point to the beginning
|
||||||
while ( ( it != pktQueue.begin() ) and pre_event_count ) {
|
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 ) );
|
dumpPacket(&((*it)->packet));
|
||||||
if ( (*it)->packet.stream_index != video_stream_id ) {
|
if ( (*it)->packet.stream_index == video_stream_id ) {
|
||||||
pre_event_count --;
|
pre_event_count --;
|
||||||
|
if ( ! pre_event_count )
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
it--;
|
it--;
|
||||||
}
|
}
|
||||||
|
// it either points to beginning or we have seen pre_event_count video packets.
|
||||||
|
|
||||||
if ( it == pktQueue.begin() ) {
|
if ( it == pktQueue.begin() ) {
|
||||||
Debug(1, "Hit begin");
|
Debug(1, "Hit begin");
|
||||||
// hit end, the first packet in the queue should ALWAYS be a video keyframe.
|
// hit end, the first packet in the queue should ALWAYS be a video keyframe.
|
||||||
|
@ -523,21 +527,20 @@ std::list<ZMPacket *>::iterator zm_packetqueue::get_event_start_packet_it(
|
||||||
}
|
}
|
||||||
return 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 ) {
|
if ( (*it)->keyframe ) {
|
||||||
Debug(1, "Returning");
|
dumpPacket(&((*it)->packet), "Found video keyframe, Returning");
|
||||||
Debug(1, "Previous packet pre %d index %d keyframe %d", pre_event_count, (*it)->image_index, (*it)->keyframe);
|
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
Debug(1, "Wasnt Checking for keyframe");
|
|
||||||
|
|
||||||
while ( ( it-- != pktQueue.begin() ) and ! (*it)->keyframe ) {
|
while ( it-- != pktQueue.begin() ) {
|
||||||
Debug(1, "No keyframe");
|
dumpPacket(&((*it)->packet), "No keyframe");
|
||||||
dumpPacket( &((*it)->packet ) );
|
if ( (*it)->packet.stream_index == video_stream_id and (*it)->keyframe )
|
||||||
|
return it; // Success
|
||||||
}
|
}
|
||||||
Debug(1, "Checking for keyframe");
|
|
||||||
if ( !(*it)->keyframe ) {
|
if ( !(*it)->keyframe ) {
|
||||||
Warning("Hit end of packetqueue before satisfying pre_event_count. Needed %d more video frames", pre_event_count);
|
Warning("Hit end of packetqueue before satisfying pre_event_count. Needed %d more video frames", pre_event_count);
|
||||||
}
|
}
|
||||||
return it;
|
return it;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue