VideoStructMonitor.cpp
3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "VideoStructMonitor.h"
#include <winsock2.h>
#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<std::string>& 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;
//}