v4l2启用
This commit is contained in:
@@ -19,13 +19,18 @@
|
||||
#include <QThread>
|
||||
#include <QImage>
|
||||
#include <QMap>
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
|
||||
// 协议定义
|
||||
// OpenCV for YUYV conversion
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
#include "protocol.h"
|
||||
|
||||
/**
|
||||
@@ -55,13 +60,37 @@ struct FrameBuffer {
|
||||
|
||||
/**
|
||||
* @brief 将所有分片合并为一个字节数组
|
||||
* @return 合并后的数据,如果分片不完整返回空vector
|
||||
*/
|
||||
std::vector<uint8_t> merge() const {
|
||||
std::vector<uint8_t> result;
|
||||
// 预分配空间以提高性能
|
||||
size_t estimated_size = chunks.size() * 500; // 估算每个分片约500字节
|
||||
result.reserve(estimated_size);
|
||||
|
||||
// 调试:检查分片顺序
|
||||
QString chunk_indices;
|
||||
for (const auto& pair : chunks) {
|
||||
chunk_indices += QString::number(pair.first) + " ";
|
||||
}
|
||||
qDebug() << "帧" << frame_id << "合并前,分片索引:" << chunk_indices;
|
||||
|
||||
for (uint16_t i = 0; i < total_chunks; i++) {
|
||||
auto it = chunks.find(i);
|
||||
if (it != chunks.end()) {
|
||||
// 调试:如果是第一个分片,打印前几个字节
|
||||
if (i == 0 && !it->second.empty()) {
|
||||
QString hex_preview;
|
||||
for (size_t j = 0; j < std::min((size_t)8, it->second.size()); j++) {
|
||||
hex_preview += QString::number(it->second[j], 16).rightJustified(2, '0') + " ";
|
||||
}
|
||||
qDebug() << "帧" << frame_id << "合并时,分片0前8字节:" << hex_preview;
|
||||
}
|
||||
result.insert(result.end(), it->second.begin(), it->second.end());
|
||||
} else {
|
||||
// 如果缺少分片,返回空vector表示不完整
|
||||
qWarning() << "帧" << frame_id << "合并时缺少分片" << i;
|
||||
return std::vector<uint8_t>();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -195,6 +224,15 @@ private:
|
||||
*/
|
||||
QImage decode_jpeg(const std::vector<uint8_t>& data);
|
||||
|
||||
/**
|
||||
* @brief 从 YUYV 数据转换为 QImage
|
||||
* @param yuyv_data YUYV格式的原始数据
|
||||
* @param width 图像宽度
|
||||
* @param height 图像高度
|
||||
* @return 转换后的QImage
|
||||
*/
|
||||
QImage decode_yuyv(const std::vector<uint8_t>& yuyv_data, int width, int height);
|
||||
|
||||
/**
|
||||
* @brief 清理超时的帧缓冲区
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user