Bladeren bron

V0.6.10
1、修改了CurlFtp库,添加了检查本地文件夹的方式,不使用C++17则改为使用Qt的QDir检查创建
2、修改了视频播放组件,添加了对C++11的兼容

Apple 3 maanden geleden
bovenliggende
commit
c30e8d3eff

+ 1 - 0
Libraries/Libraries.cmake

@@ -6,6 +6,7 @@
 message(STATUS "==================================================")
 message(STATUS "系统: ${CMAKE_SYSTEM_NAME}")
 message(STATUS "编译器: ${CMAKE_CXX_COMPILER_ID} 版本: ${CMAKE_CXX_COMPILER_VERSION}")
+message(STATUS "C++版本: ${CMAKE_CXX_STANDARD}")
 message(STATUS "编译类型: ${CMAKE_BUILD_TYPE}")
 if(CMAKE_SIZEOF_VOID_P MATCHES 8)
     message(STATUS "系统位数: 64-bit")

+ 68 - 2
common/CurlFtp/CurlFtp.cpp

@@ -2,12 +2,19 @@
 #include "CurlFtp.h"
 #include <regex>
 #include <iosfwd>
-#include <filesystem>
 #include <fstream>
 
 #include "stdlog.h"
 
 
+#if (__cplusplus >= 201703L)
+    #include <filesystem>
+#else
+    #include <QDir>
+    #include <QFileInfo>
+#endif /* (__cplusplus >= 201703L) */
+
+
 #if defined(_WIN32)
 
 #endif /* _WIN32 */
@@ -896,15 +903,18 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
         LOG_ERROR("Url is empty");
         return false;
     }
+    // printf("uploadFile: %d\n", __LINE__);
     /* 检查本地文件是否存在 */
-    if(!std::filesystem::exists(localFile))
+    if(!checkLocalFileExist(localFile))
     {
         LOG_ERROR("Local file is not exist: " << localFile);
         return false;
     }
+    // printf("uploadFile: %d\n", __LINE__);
     /* 检查FTP文件名是否符合规范 */
     std::string remoteFileTmp = checkFilePath(remoteFile);
     std::string remoteDirTmp = remoteFileTmp.substr(0, remoteFileTmp.find_last_of("/"));
+    // printf("uploadFile: %d\n", __LINE__);
     /* 检查远程FTP上的文件夹是否存在,不存在则创建 */
     if(!isDirExist(remoteDirTmp))
     {
@@ -920,6 +930,7 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
             return false;
         }
     }
+    // printf("uploadFile: %d\n", __LINE__);
         
     /* 拼接远程文件的url */
     std::string ftpUrl = m_ftpUrl + remoteFileTmp;
@@ -932,6 +943,7 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
         LOG_ERROR("Failed to open local file: " << localFile);
         return false;
     }
+    // printf("uploadFile: %d\n", __LINE__);
     /* 获取文件大小 */
     // auto startPos = ifs.tellg();
     ifs.seekg(0, std::ios::end);
@@ -953,6 +965,7 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
         ifs.close();
         return false;
     }
+    // printf("uploadFile: %d\n", __LINE__);
     /* 设置FTP地址 */
     curl_easy_setopt(m_curl, CURLOPT_URL, ftpUrl.c_str());
     curl_easy_setopt(m_curl, CURLOPT_PORT, m_port);
@@ -986,14 +999,17 @@ bool CurlFtp::uploadFile(const std::string& localFile, const std::string& remote
     }
     /* 启用持久连接 */
     curl_easy_setopt(m_curl, CURLOPT_TCP_KEEPALIVE, 1L);
+    // printf("uploadFile: %d\n", __LINE__);
     /* 发送请求 */
     bool ret = performCurl(m_curl);
     if(!ret)
     {
         LOG_ERROR("Upload file failed, Url = " << ftpUrl);
     }
+    // printf("uploadFile: %d\n", __LINE__);
     /* 关闭文件,清理curl */
     ifs.close();
+    // printf("uploadFile: %d\n", __LINE__);
     // curl_easy_cleanup(curl);
     /* 打印一个换行符 */
     printf("\n");
@@ -1232,12 +1248,20 @@ bool CurlFtp::checkLocalDir(const std::string& localDir)
     std::regex reg(R"([.]*/$)");
     std::string localDirTmp = std::regex_replace(localDir, reg, "");
     /* 检查文件夹是否存在 */
+#if (__cplusplus >= 201703L)
     if(std::filesystem::exists(localDirTmp))
+#else
+    if(QDir(localDirTmp.c_str()).exists())
+#endif /* (__cplusplus >= 201703L) */
     {
         return true;
     }
     /* 创建文件夹 */
+#if (__cplusplus >= 201703L)
     if(!std::filesystem::create_directories(localDirTmp))
+#else
+    if(!QDir().mkpath(localDirTmp.c_str()))
+#endif /* (__cplusplus >= 201703L) */
     {
         LOG_ERROR("Failed to create local dir: " << localDirTmp);
         return false;
@@ -1246,6 +1270,40 @@ bool CurlFtp::checkLocalDir(const std::string& localDir)
     return true;
 }
 
+/* 检查本地文件夹是否存在,不会创建 */
+bool CurlFtp::checkLocalDirExist(const std::string& localDir)
+{
+    /* 去掉最后的‘/’ */
+    std::regex reg(R"([.]*/$)");
+    std::string localDirTmp = std::regex_replace(localDir, reg, "");
+    /* 检查文件夹是否存在 */
+    bool result = false;
+#if (__cplusplus >= 201703L)
+    result = std::filesystem::exists(localDirTmp);
+#else
+    result = QDir(localDirTmp.c_str()).exists();
+#endif /* (__cplusplus >= 201703L) */
+
+    return result;
+}
+
+/* 检查本地文件是否存在 */
+bool CurlFtp::checkLocalFileExist(const std::string& localFile)
+{
+    /* 去掉最后的‘/’ */
+    std::regex reg(R"([.]*/$)");
+    std::string localDirTmp = std::regex_replace(localFile, reg, "");
+    /* 检查文件是否存在 */
+    bool result = false;
+#if (__cplusplus >= 201703L)
+    result = std::filesystem::exists(localFile)
+#else
+    result = QFile(localFile.c_str()).exists();
+#endif /* (__cplusplus >= 201703L) */
+
+    return result;
+}
+
 
 /* 执行curl,添加重试机制 */
 bool CurlFtp::performCurl(CURL* curl)
@@ -1368,7 +1426,11 @@ bool CurlFtp::checkFtpDirExist(const std::string& dir)
 bool CurlFtp::checkSftpDirExist(const std::string& dir)
 {
     /* 取出上一层文件夹路径 */
+#if (__cplusplus >= 201703L)
     std::string parentDir = std::filesystem::path(dir).parent_path().string();
+#else
+    std::string parentDir = QFileInfo(QString::fromStdString(dir)).path().toStdString();
+#endif /* (__cplusplus >= 201703L) */
     // LOG_DEBUG("Parent dir: {}", parentDir);
     std::vector<std::string> vecDir;
     bool ret = getDirList(parentDir, vecDir);
@@ -1378,7 +1440,11 @@ bool CurlFtp::checkSftpDirExist(const std::string& dir)
         return false;
     }
     /* 取出本层文件夹名称 */
+#if (__cplusplus >= 201703L)
     std::string dirName = std::filesystem::path(dir).filename().string();
+#else
+    std::string dirName = QFileInfo(QString::fromStdString(dir)).fileName().toStdString();
+#endif /* (__cplusplus >= 201703L) */
     // LOG_DEBUG("Dir name: {}", dirName);
     /* 判断是否存在 */
     bool result = false;

+ 5 - 0
common/CurlFtp/CurlFtp.h

@@ -19,6 +19,7 @@
  *     5.这里使用了filesystem,需要C++17支持,uos默认的gcc版本是8.3,支持C++17,但是需要手动开启
  *       这个库的支持,在项目文件里添加“stdc++fs”这个库,如下:
  *          target_link_libraries(${this_exe} PRIVATE stdc++fs)
+ *     6. 如果C++版本低于C++17,会改为Qt的QDir
  */
 
 
@@ -72,6 +73,10 @@ private:
     std::string checkFilePath(const std::string& file);
     /* 检查本地文件夹是否存在,不存在则创建 */
     bool checkLocalDir(const std::string& localDir);
+    /* 检查本地文件夹是否存在,不会创建 */
+    bool checkLocalDirExist(const std::string& localDir);
+    /* 检查本地文件是否存在 */
+    bool checkLocalFileExist(const std::string& localFile);
     /* 执行curl,添加重试机制 */
     bool performCurl(CURL* curl);
     /* 重置curl设置 */

+ 10 - 0
common/VideoPlayer/DecodeVedio.cpp

@@ -48,6 +48,16 @@ AVPixelFormat get_hw_format(AVCodecContext *ctx, const AVPixelFormat *pix_fmts)
  */
 DecodeVedio::DecodeVedio(QThread* thread, QObject* parent) : QObject(parent) , m_thread(thread)
 {
+    /* 初始化成员变量 */
+    m_threadRuning = false;       
+    m_initFFmpeg = false;  
+    m_pauseDecode = false; 
+    m_decodeStatus = false;
+    m_isSeek = false;      
+    m_flushDecoder = false;
+    m_decodeState = DecodeState::NONE;
+
+    m_pts.store(0);
     /* 在连接之前调用,移动到新的线程 */
     this->moveToThread(thread);
     connect(this, &DecodeVedio::signal_startDecode, this, &DecodeVedio::do_startDecodeVedio);

+ 8 - 8
common/VideoPlayer/DecodeVedio.h

@@ -119,13 +119,13 @@ private slots:
 private:
     QThread* m_thread = nullptr;                    /* 解码线程 */
     /* 线程状态 */
-    std::atomic_bool m_threadRuning = false;        /* 解码线程是运行标志 */
-    std::atomic_bool m_initFFmpeg = false;          /* ffmpeg初始化标志 */
-    std::atomic_bool m_pauseDecode = false;         /* 暂停解码 */
-    std::atomic_bool m_decodeStatus = false;        /* 解码状态,这里主要是检测是否暂停解码 */
-    std::atomic_bool m_isSeek = false;              /* 是否在跳转中 */
-    std::atomic_bool m_flushDecoder = false;        /* 刷新解码器 */
-    std::atomic<DecodeState> m_decodeState = DecodeState::NONE;
+    std::atomic_bool m_threadRuning;                /* 解码线程是运行标志 */
+    std::atomic_bool m_initFFmpeg;                  /* ffmpeg初始化标志 */
+    std::atomic_bool m_pauseDecode;                 /* 暂停解码 */
+    std::atomic_bool m_decodeStatus;                /* 解码状态,这里主要是检测是否暂停解码 */
+    std::atomic_bool m_isSeek;                      /* 是否在跳转中 */
+    std::atomic_bool m_flushDecoder;                /* 刷新解码器 */
+    std::atomic<DecodeState> m_decodeState;
     /* 视频解码相关变量信息 */
     QString m_fileName;                             /* 解码的视频文件名称 */
     AVFormatContext *m_pFormatContext = nullptr;    /* 格式上下文,贯穿全局 */
@@ -148,7 +148,7 @@ private:
     int m_fps = 0;                                  /* 每秒的帧数 */
     qint64 m_duration = 0;                          /* 视频时长,单位毫秒 */
     qint64 m_startPos = 0;                          /* 开始播放的位置,摄像机视频的位置不是从0开始的,需要在初始化的时候取出这个值 */
-    std::atomic<qint64> m_pts = 0;                  /* 当前帧显示时间,也就是当前的进度时间 */
+    std::atomic<qint64> m_pts;                      /* 当前帧显示时间,也就是当前的进度时间 */
     
     qint64 m_targetPos = -1;                        /* 跳转的目标播放位置 */
     qint64 m_currentFrame = 0;                      /* 当前已播放的帧数 */