pansen
2019-02-25 8d1ead663449e6bf508d4d703b6d56381141daeb
QiaoJiaSystem/DataManagerServer/http_configserver.cpp
@@ -22,6 +22,7 @@
#include <time.h>
#include <dirent.h>
#include "basic/pipe_element/ffmpeg/basic_struct_for_video_image.h"
using namespace std;
devHttpServer_c::devHttpServer_c()
@@ -1004,8 +1005,10 @@
    std::string out = value.size() > 0 ? value.toStyledString() : "[]";
    return out;
}
#define ADD_CAMERA 0
#define EDIT_CAMERA 1
//编辑摄像机
std::string devHttpServer_c::cam_edit(std::string ip, unsigned int port, std::string content, PResponse &response) {
    DBG("ip:" << ip << "; port:" << port);
@@ -1051,36 +1054,25 @@
//        rec_sdk.str_det_thr = QString::fromStdString(value["str_det_thr"].asString());
//        rec_sdk.str_cmp_thr = QString::fromStdString(value["str_cmp_thr"].asString());
        bool is_exist=db_c.searchCamDevByCamId(rec.str_cam_dev_id);
        if(ADD_CAMERA == type )
        {
           if(is_exist)
           {
        if (ADD_CAMERA == type) {
            if (is_exist) {
               return "{\"ret_status\": \"请勿重复添加!\"}";
           }
           else
           {
            } else {
               ret =db_c.insertCamDevTable(rec);
               if (!ret) {
                   return "err_db_content";
               }
           }
        }
        else if(EDIT_CAMERA == type )
        {
            if(is_exist)
            {
        } else if (EDIT_CAMERA == type) {
            if (is_exist) {
                ret = db_c.updateCamDevTable(rec);
                if (!ret) {
                    return "err_db_content";
                }
            }
            else
            {
            } else {
                 return "{\"ret_status\": \"内容有误,请检查!\"}";
            }
        }
        else
        {
        } else {
             return "{\"ret_status\": \"内容有误,请检查!\"}";
        }
@@ -2413,8 +2405,7 @@
std::string devHttpServer_c::getAlarmImageByPicDateAndDevId(const std::string& picDate,const std::string& devId,
                                                        PResponse &response) {
    try {
        if(!devId.empty() && !picDate.empty())
        {
        if (!devId.empty() && !picDate.empty()) {
            std::string videoPath;
            qint64 sub;
            std::string path = getVideoPathByPicDate(picDate, devId, sub);
@@ -2524,7 +2515,6 @@
}
std::string devHttpServer_c::getAlarmImageFromVideoFile(std::string ip, unsigned int port, std::string content,
                                                        PResponse &response)  {
    INFO("ip:" << ip << "; port:" << port << "content: " << content);
@@ -2536,16 +2526,14 @@
            std::string picDate = value["picDate"].asString();
            std::string imgKey = value["imgKey"].asString();
            //兼容旧版本
            if(imgKey=="undefined" || imgKey.empty())
            {
            if (imgKey == "undefined" || imgKey.empty()) {
                DBG("getAlarmImageByPicDateAndDevId " << imgKey);
                return getAlarmImageByPicDateAndDevId(picDate,devId,response);
            }
            else
            {
            } else {
                DBG("getAlarmImageByImageKeyAndDevId " << imgKey);
                return getAlarmImageByImageKeyAndDevId(imgKey,devId,response);
            }    
        }
        else{
        } else {
            response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"传输错误,请检查!\"}");
            ERR("ImageURL:传输错误,请检查");
            return "";
@@ -2559,7 +2547,6 @@
        return "";
    }
}
std::string devHttpServer_c::getAlarmImageByImageKeyAndDevId(const std::string& imgKey,const std::string& devId,
@@ -2586,11 +2573,11 @@
            std::string strSelectTemplate=R"#( -vf "select=eq(n\,%d)")#";
            sprintf(selectExpBuff,strSelectTemplate.c_str(),frameIdDiff-1);
            if(videoSt.Valid() && imgSt.Valid() ) {
                std::string cmd("ffmpeg -i '" + videoPath+"'"+std::string(selectExpBuff)+" -vframes 1" +" -y '" + str_imgName + "'");
                std::string cmd("ffmpeg -i '" + videoPath + "'" + std::string(selectExpBuff) + " -vframes 1" + " -y '" +
                                str_imgName + "'");
                INFO("Video To Image Cmd: "<<cmd);
                system(cmd.c_str());
            }
            else {
            } else {
                ERR("Parse Video and Image Failed Path: "<<path <<" ImageId: "<<imgKey);
                return "{\"error\":\"未查到视频路径\"}";
            }
@@ -2652,13 +2639,10 @@
        std::string path;
        //兼容旧版本
        if(imgKey=="undefined"||imgKey.empty())
        {
        if (imgKey == "undefined" || imgKey.empty()) {
            qint64 sub;
            path = getVideoPathByPicDate(picDate,devId,sub);
        }
        else
        {
        } else {
            path = getVideoPathByImgKey(imgKey,devId);
        }
        //std::string path = getVideoPathByImgKey(imgKey, devId, sub);
@@ -2823,8 +2807,7 @@
    std::lock_guard<std::mutex> lock(g_mutex);
    std::vector<std::string> vec = forEachFileByImgKey(strPath);
    ImageName_s_t imgSt = ImageName_s_t::fromString(imgKey);
    if(!imgSt.Valid())
    {
    if (!imgSt.Valid()) {
        ERR("ParseImageName Failed : "<<imgKey);
        return "";
    }
@@ -2843,7 +2826,8 @@
                    ERR("Image " << imgKey << "   Video: " << item << " Not Match");
                }
            } else{
                ERR("ImageID: "<<imgSt.m_frameId <<" VideoRange: "<<videoParseResult.m_startFrameId<<" , "<<videoParseResult.m_endFrameId);
                ERR("ImageID: " << imgSt.m_frameId << " VideoRange: " << videoParseResult.m_startFrameId << " , "
                                << videoParseResult.m_endFrameId);
            }
        } else {
@@ -2857,8 +2841,7 @@
        return strVideoName;
    } else {
        ERR("ImageName: "<<imgKey<<"  MatchVideoCount: "<<videoStVec.size());
        for(auto& item:vec)
        {
        for (auto &item:vec) {
            ERR("VideoName: "<<item);
        }
        return "";
@@ -2866,8 +2849,7 @@
}
//新的根据图片名称获取路径的方法
std::string devHttpServer_c::getVideoPathByImgKey(const std::string &imgKey, const std::string &camId)
{
std::string devHttpServer_c::getVideoPathByImgKey(const std::string &imgKey, const std::string &camId) {
    INFO("GetVideoFor: "<<imgKey<<" CamID:"<<camId);
    ImageName_s_t imgSt= ImageName_s_t::fromString(imgKey);
@@ -2881,7 +2863,6 @@
    std::string videoPath = t_FilePath+"/"+camId+"/"+std::string(curFolder);
    return GetVideoNameByImgKey(imgKey,videoPath);
}
qint64 devHttpServer_c::getVideoTime(/*const std::string &videoPath,*/std::string &str_tmpTime) {
@@ -3271,8 +3252,7 @@
        std::string pass = value["str_password"].asString();
        std::string brand = value["str_brand"].asString();
        std::string rtsp_url = rtspAddrBuild(ip, port, username, pass, brand);
        if (rtsp_url.empty() )
        {
        if (rtsp_url.empty()) {
            return "{\"ret_status\":\"内容有误,请检查!\"}";
        }
//        unsigned char serialnumber[SERIALNO_LEN] = {0};
@@ -3294,7 +3274,9 @@
        str_imgName +="-";
        str_imgName += "snapshot.jpg";
        //admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream -r 1/25 -f image2 -s 1920*1080 /home/basic/work_src/a.jpg
        std::string cmd("ffmpeg -i " + rtsp_url + " -vf select='eq(pict_type\\,I)',setpts='N/(25*TB)' -f image2 -s 1920*1080 -y " + str_imgName);
        std::string cmd(
            "ffmpeg -i " + rtsp_url + " -vf select='eq(pict_type\\,I)',setpts='N/(25*TB)' -f image2 -s 1920*1080 -y " +
            str_imgName);
//        std::string cmd("ffmpeg -i " + rtsp_url + " -r 1/25  -f image2 -s 1920*1080 -y " + str_imgName);
        DBG(cmd);
        system(cmd.c_str());