leon 1 hónapja
szülő
commit
2623ce7ab6
2 módosított fájl, 2 hozzáadás és 34 törlés
  1. 1 27
      src/nodes/stream/streamNode.cpp
  2. 1 7
      src/nodes/stream/streamNode.hpp

+ 1 - 27
src/nodes/stream/streamNode.cpp

@@ -64,13 +64,6 @@ void StreamNode::work_gpu()
 	printf("packet_size = %d\n", packet_size);
 
     unsigned int frame_index = 0;
-
-    if (target_fps_ > 0.0) {
-        target_duration_ = std::chrono::duration_cast<std::chrono::microseconds>(
-            std::chrono::duration<double>(1.0 / fps_));
-        last_push_time_ = std::chrono::high_resolution_clock::now();
-    }
-
     while(running_)
     {
         demuxer_->demux(&packet_data, &packet_size, &pts);
@@ -90,26 +83,6 @@ void StreamNode::work_gpu()
                 continue;
             }
 
-            // ---> GPU 帧率控制逻辑 <---
-            if (target_duration_.count() > 0) {
-                auto now = std::chrono::high_resolution_clock::now();
-                auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(now - last_push_time_);
-                auto wait_duration = target_duration_ - elapsed;
-
-                if (wait_duration.count() > 0) {
-                    printf("Waiting for %lld us\n", (long long)wait_duration.count());
-                    std::this_thread::sleep_for(wait_duration);
-                } else {
-                    // 如果 elapsed 已经超过 target_duration,说明处理落后了,不需要等待
-                    // 可以选择打印警告信息
-                    // printf("Warning: Frame processing took longer than target duration (%lld us vs %lld us)\n",
-                    //        (long long)elapsed.count(), (long long)target_duration_.count());
-                }
-                 // 更新时间戳,即使等待时间为0或负数,也要更新到当前时间点之后(理论上是目标时间点)
-                 // 简单起见,我们就在 sleep 后/判断后更新到当前时间
-                 last_push_time_ = std::chrono::high_resolution_clock::now();
-            }
-
             auto metaData = std::make_shared<meta::MetaData>();
             metaData->image = frame.clone();
             metaData->from = name_;
@@ -119,6 +92,7 @@ void StreamNode::work_gpu()
                 output_buffer.second->push(metaData);
                 // printf("Node %s push data to %s\n", name_.c_str(), output_buffer.first.c_str());
             }
+            std::this_thread::sleep_for(std::chrono::milliseconds(30));
         }
     };
 	printf("C++ Demo: %d frames\n", frame_index);

+ 1 - 7
src/nodes/stream/streamNode.hpp

@@ -39,7 +39,7 @@ public:
                 return;
             }
             decoder_ = FFHDDecoder::create_cuvid_decoder(
-                false, FFHDDecoder::ffmpeg2NvCodecId(demuxer_->get_video_codec()), 100, gpu_id, nullptr, nullptr, true
+                false, FFHDDecoder::ffmpeg2NvCodecId(demuxer_->get_video_codec()), -1, gpu_id, nullptr, nullptr, true
             );
             if (decoder_ == nullptr)
             {
@@ -98,12 +98,6 @@ private:
 
     DecodeType decode_type_ = DecodeType::GPU;
     StreamStatus status_ = StreamStatus::CLOSED;
-
-
-    double target_fps_ = 25; // Desired output FPS (0 or negative means no control)
-    std::chrono::microseconds target_duration_{0}; // Duration per frame
-    std::chrono::time_point<std::chrono::high_resolution_clock> last_push_time_; // Time when the last frame was pushed
-
 };
 
 }