|
@@ -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);
|