#include "VideoStructMonitor.h" #include #include "hiredis.h" // // CVideoParseMonitor // CVideoStructMonitor::CVideoStructMonitor(void) { } CVideoStructMonitor::~CVideoStructMonitor(void) { } // 关闭任务监测器 void CVideoStructMonitor::uninit(void) { // 退出前完成回收 // 退出监测线程 cleanup(); } int CVideoStructMonitor::get_value(const std::string& key_postfix) { int value = 0; std::string key = job_uuid_ + key_postfix; if (ping()) { redisContext * ctx = connector_ptr_->get(); value = CBaseRedisJobMonitor::get_job_val(ctx, key, 0); } return value; } bool CVideoStructMonitor::set_value(const std::string& key_postfix, const int& value) { std::string key = job_uuid_ + key_postfix; if (ping()) { redisContext * ctx = connector_ptr_->get(); return CBaseRedisJobMonitor::set_job_val(ctx, key, value); } return false; } bool CVideoStructMonitor::add_segment(const std::string& segment_json) { std::string key = job_uuid_ + KEY_VIDEO_STRUCT_RESULT_POSTFIX; if (ping()) { redisContext * ctx = connector_ptr_->get(); if (ctx) { redisReply * reply = (redisReply *)redisCommand(ctx, "RPUSH %s %b", key.c_str(), segment_json.c_str(), sizeof(segment_json)); if (reply) { freeReplyObject(reply); return true; } } } return false; } bool CVideoStructMonitor::retrieve_new_segment_list(int old_item_count, int new_item_count, std::vector& segment_list) { std::string key = job_uuid_ + KEY_VIDEO_STRUCT_RESULT_POSTFIX; if (ping()) { redisContext * ctx = connector_ptr_->get(); if (ctx) { redisReply * reply = (redisReply *)redisCommand(ctx, "LRANGE %s %d %d", key.c_str(), old_item_count, new_item_count); if (reply) { std::string segment; for (int j = 0; j < reply->elements; j++) { redisReply * reply_item = reply->element[j]; if (reply_item->type == REDIS_REPLY_STRING) { segment = reply_item->str; segment_list.push_back(segment); } } freeReplyObject(reply); return true; } } } return false; } //bool CVideoStructMonitor::add_tracks(const int& obj_id, const DxSqliteInterface::OBJECT_INFO_LIST& obj_tracks) //{ // char str[25]; // itoa(obj_id, str, 25); // std::string key = job_uuid_ + "." + str + KEY_VIDEO_STRUCT_TRACK_POSTFIX; // // if (ping()) // { // redisContext * ctx = connector_ptr_->get(); // // if (ctx) // { // for each (DxSqliteInterface::OBJECT_INFO var in obj_tracks) // { // redisAppendCommand(ctx, "RPUSH %s %b", key.c_str(), &var, sizeof(var)); // } // // for (int i = 0; i < obj_tracks.size(); i++) // { // redisReply* reply = nullptr; // int reply_status = redisGetReply(ctx, (void **)&reply); // if (reply_status != REDIS_OK || reply == nullptr) // { // return false; // } // freeReplyObject(reply); // } // // return true; // } // } // // return false; //} // //bool CVideoStructMonitor::retrieve_tracks(const int& obj_id, DxSqliteInterface::OBJECT_INFO_LIST& obj_tracks) //{ // char str[25]; // itoa(obj_id, str, 25); // std::string key = job_uuid_ + "." + str + KEY_VIDEO_STRUCT_TRACK_POSTFIX; // // if (ping()) // { // redisContext * ctx = connector_ptr_->get(); // // if (ctx) // { // redisReply * reply = (redisReply *)redisCommand(ctx, "LRANGE %s %d %d", key.c_str(), 0, -1); // if (reply) // { // DxSqliteInterface::OBJECT_INFO obj; // for (int j = 0; j < reply->elements; j++) // { // memset(&obj, 0, sizeof(obj)); // redisReply * reply_item = reply->element[j]; // if (reply_item->len > 0 && reply_item->len <= sizeof(obj)) // { // memcpy(&obj, reply_item->str, reply_item->len); // obj_tracks.push_back(obj); // } // } // // freeReplyObject(reply); // return true; // } // } // } // // return false; //}