@@ -2223,21 +2223,24 @@ int Monitor::Analyse() {
22232223 }
22242224
22252225 int count = 10 ;
2226+ delayed_packet_lock = ai_queue.size () ? &ai_queue.front () : &packet_lock;
2227+ delayed_packet = delayed_packet_lock->packet_ ;
22262228 do {
22272229 // packet got to the card
22282230 Debug (1 , " Doing receive_detection queue size: %zu" , ai_queue.size ());
2229- delayed_packet_lock = ai_queue.size () ? &ai_queue.front () : &packet_lock;
2230- delayed_packet = delayed_packet_lock->packet_ ;
22312231
22322232 ret = quadra_yolo->receive_detection (delayed_packet);
22332233 if (0 < ret) {
2234- if (delayed_packet != packet) {
2234+ Debug (1 , " Success %d" , delayed_packet->image_index );
2235+ if (delayed_packet.get () != packet.get ()) {
22352236 Debug (1 , " Pushing packet, popping delayed" );
22362237 ai_queue.push_back (std::move (packet_lock));
22372238 packet = delayed_packet;
22382239 packet_lock = std::move (ai_queue.front ());
22392240 ai_queue.pop_front ();
22402241 packetqueue.increment_it (analysis_it);
2242+ } else {
2243+ Debug (1 , " packet %p != delayed_packet %p" , packet.get (), delayed_packet.get ());
22412244 }
22422245 if (packet->ai_frame )
22432246 zm_dump_video_frame (packet->ai_frame .get (), " after detect" );
@@ -2255,14 +2258,14 @@ int Monitor::Analyse() {
22552258
22562259 } else {
22572260 // EAGAIN
2258- Debug (1 , " ret %d EAGAIN" , ret);
2261+ Debug (1 , " ret %d EAGAIN, sleeping 10 millis " , ret);
22592262 // if (packet == delayed_packet) { // Can this be otherwise?
22602263 // ai_queue.push_back(std::move(packet_lock));
22612264 // Debug(1, "Pushing packet %d on queue, size now %zu", packet->image_index, ai_queue.size());
22622265 // packetqueue.increment_it(analysis_it);
22632266 // }
22642267 // return 0;
2265- std::this_thread::sleep_for (Milliseconds (100 ));
2268+ std::this_thread::sleep_for (Milliseconds (10 ));
22662269 count -= 1 ;
22672270 }
22682271 } while (ret == 0 and count > 0 );
@@ -2643,38 +2646,31 @@ int Monitor::Analyse() {
26432646 // Only do these if it's a video packet.
26442647 unsigned int index = shared_data->last_analysis_index ;
26452648 index++;
2646- index = index % image_buffer_count;
2649+ index = ( index+ 1 ) % image_buffer_count;
26472650 if (packet->ai_frame ) {
26482651 analysis_image_buffer[index]->AVPixFormat (static_cast <AVPixelFormat>(packet->ai_frame ->format ));
26492652 Debug (1 , " ai_frame pixformat %d, for index %d, packet %d" , packet->ai_frame ->format , index, packet->image_index );
26502653 analysis_image_buffer[index]->Assign (packet->ai_frame .get ());
26512654 analysis_image_pixelformats[index] = static_cast <AVPixelFormat>(packet->ai_frame ->format );
2652- shared_data->last_analysis_index = index;
2653-
2654- shared_data->last_read_index = packet->image_index ;
2655- shared_data->analysis_image_count ++;
26562655 } else if (packet->analysis_image ) {
26572656 analysis_image_buffer[index]->Assign (*packet->analysis_image );
26582657 analysis_image_pixelformats[index] = packet->analysis_image ->AVPixFormat ();
26592658 Debug (1 , " analysis %d, for index %d, packet %d" , analysis_image_pixelformats[index], index, packet->image_index );
2660- shared_data->last_analysis_index = index;
2661- shared_data->analysis_image_count ++;
26622659 } else if (packet->image ) {
26632660 analysis_image_buffer[index]->Assign (*packet->image );
26642661 analysis_image_pixelformats[index] = packet->image ->AVPixFormat ();
2665- shared_data->last_analysis_index = index;
26662662 Debug (1 , " image %d, for index %d" , analysis_image_pixelformats[index], index);
2667- shared_data->analysis_image_count ++;
26682663 } else if (packet->in_frame ) {
26692664 analysis_image_buffer[index]->AVPixFormat (static_cast <AVPixelFormat>(packet->in_frame ->format ));
26702665 Debug (1 , " in_frame pixformat %d, for index %d, packet %d" , packet->in_frame ->format , index, packet->image_index );
26712666 analysis_image_buffer[index]->Assign (packet->in_frame .get ());
26722667 analysis_image_pixelformats[index] = static_cast <AVPixelFormat>(packet->in_frame ->format );
2673- shared_data->last_analysis_index = index;
2674- shared_data->analysis_image_count ++;
26752668 } else {
26762669 Debug (1 , " Unable to find an image to assign for index %d" , index);
26772670 }
2671+ shared_data->last_analysis_index = index;
2672+ shared_data->last_read_index = index;
2673+ shared_data->analysis_image_count ++;
26782674 shared_analysis_timestamps[index] = zm::chrono::duration_cast<timeval>(packet->timestamp .time_since_epoch ());
26792675 } else {
26802676 Debug (3 , " Not video, not clearing packets" );
@@ -3065,6 +3061,7 @@ int Monitor::OpenDecoder() {
30653061
30663062 mVideoCodecContext = avcodec_alloc_context3 (mVideoCodec );
30673063 avcodec_parameters_to_context (mVideoCodecContext , mVideoStream ->codecpar );
3064+ mVideoCodecContext ->framerate = mVideoStream ->r_frame_rate ;
30683065
30693066#ifdef CODEC_FLAG2_FAST
30703067 mVideoCodecContext ->flags2 |= CODEC_FLAG2_FAST | CODEC_FLAG_LOW_DELAY;
@@ -3200,6 +3197,7 @@ int Monitor::Decode() {
32003197 if (packet->codec_type != AVMEDIA_TYPE_VIDEO) {
32013198 packet->decoded = true ;
32023199 Debug (4 , " Not video,probably audio" );
3200+ packetqueue.increment_it (decoder_it);
32033201 return 1 ; // Don't need decode
32043202 }
32053203 }
@@ -3215,9 +3213,10 @@ int Monitor::Decode() {
32153213 ) {
32163214 Debug (1 , " send_packet %d" , packet->image_index );
32173215 int ret;
3218- do {
3216+ // do {
32193217 ret = packet->send_packet (mVideoCodecContext );
3220- } while (!ret and !zm_terminate);
3218+ if ( 0 >=ret) return -1 ; // make it sleep?
3219+ // } while(!ret and !zm_terminate);
32213220
32223221 if (ret < 0 ) {
32233222 // No need to push because it didn't get into the decoder.
@@ -3882,7 +3881,6 @@ int Monitor::Pause() {
38823881 analysis_thread->Stop ();
38833882 Debug (1 , " Analysis stopped" );
38843883 }
3885- while (ai_queue.size ()) ai_queue.pop_front ();
38863884
38873885 Debug (1 , " Stopping packetqueue" );
38883886 // Wake everyone up
@@ -3902,6 +3900,8 @@ int Monitor::Pause() {
39023900 Debug (1 , " Joining analysis" );
39033901 analysis_thread->Join ();
39043902 }
3903+ while (decoder_queue.size ()) decoder_queue.pop_front ();
3904+ while (ai_queue.size ()) ai_queue.pop_front ();
39053905
39063906 // Must close event before closing camera because it uses in_streams
39073907 if (close_event_thread.joinable ()) {
0 commit comments