for (i = 0; i < size; i++)
{
ONVIF_DBPRINTF(MSG_NOTICE, "analytic config channel cycle curr is: %d\n", i);
for (j = 0; j < MAX_CHM_NUM; j++)
{
if (profiles[j].channel == 0)
{
j = MAX_CHM_NUM;
break;
}
else if (profiles[j].motion_support == 0 && profiles[j].tamper_support == 0 && profiles[j].crossed_support == 0)
{
j = MAX_CHM_NUM;
break;
}
else if (profiles[j].channel == (i + 1))
{
break;
}
}
ONVIF_DBPRINTF(MSG_NOTICE, "analytic config channel j is: %d\n", j);
if (j == MAX_CHM_NUM)
{
i--;
continue;
}
if (profiles[j].motion_support || profiles[j].tamper_support || profiles[j].crossed_support)
{
ONVIF_DBPRINTF(MSG_NOTICE, "start create analytic config channel is %d\n", j);
vaconf = &res->Configurations[i];
vaconf->UseCount = SOURCE_USER;
snprintf(temp_str, LEN_INFO, VIDEO_ANALYTICS_NAME, profiles[j].channel);
vaconf->Name = soap_strdup(soap, temp_str);
snprintf(temp_str, LEN_INFO, VIDEO_ANALYTICS_TOKEN, profiles[j].channel);
vaconf->token = soap_strdup(soap, temp_str);
vaconf->AnalyticsEngineConfiguration = tMalloc(struct tt__AnalyticsEngineConfiguration);
if (vaconf->AnalyticsEngineConfiguration == NULL)
return SOAP_SVR_FAULT;
bzero(vaconf->AnalyticsEngineConfiguration, sizeof(struct tt__AnalyticsEngineConfiguration));
vaconf->AnalyticsEngineConfiguration->__sizeAnalyticsModule = profiles[j].motion_support + profiles[j].tamper_support + profiles[j].crossed_support;
ONVIF_DBPRINTF(MSG_NOTICE, "num of supported analy module %d\n", vaconf->AnalyticsEngineConfiguration->__sizeAnalyticsModule);
vaconf->AnalyticsEngineConfiguration->AnalyticsModule = lMalloc(struct tt__Config,
sizeof(struct tt__Config) * vaconf->AnalyticsEngineConfiguration->__sizeAnalyticsModule);
if (vaconf->AnalyticsEngineConfiguration->AnalyticsModule == NULL)
return SOAP_FAULT;
bzero(vaconf->AnalyticsEngineConfiguration->AnalyticsModule, sizeof(struct tt__Config) *
vaconf->AnalyticsEngineConfiguration->__sizeAnalyticsModule);
index = 0;
if (profiles[j].motion_support)
{
/* AnalyticsModule-MyCellMotionModule*/
struct tt__Config *MotionAnalyticsModule = &(vaconf->AnalyticsEngineConfiguration->AnalyticsModule[index]);
snprintf(temp_str, LEN_INFO, MODULE_TOKEN, ANALYTICS_MOTION, profiles[j].channel);
MotionAnalyticsModule->Name = soap_strdup(soap, temp_str);
MotionAnalyticsModule->Type = soap_strdup(soap, "tt:CellMotionEngine");
MotionAnalyticsModule->Parameters = tMalloc(struct tt__ItemList);
if (MotionAnalyticsModule->Parameters == NULL)
return SOAP_FAULT;
bzero(MotionAnalyticsModule->Parameters, sizeof(struct tt__ItemList));
MotionAnalyticsModule->Parameters->__sizeElementItem = 1;
MotionAnalyticsModule->Parameters->__sizeSimpleItem = 1; // for hik motion detect support
MotionAnalyticsModule->Parameters->SimpleItem = lMalloc(struct _tt__ItemList_SimpleItem,
sizeof(struct _tt__ItemList_SimpleItem) * MotionAnalyticsModule->Parameters->__sizeSimpleItem);
if (MotionAnalyticsModule->Parameters->SimpleItem == NULL)
return SOAP_FAULT;
bzero(MotionAnalyticsModule->Parameters->SimpleItem,
sizeof(struct _tt__ItemList_SimpleItem) * MotionAnalyticsModule->Parameters->__sizeSimpleItem);
MotionAnalyticsModule->Parameters->SimpleItem[0].Name = soap_strdup(soap, "Sensitivity");
sensitivity = get_motion_sensitivity(i / 2 + 1);
snprintf(temp_str, LEN_INFO, "%d", sensitivity);
MotionAnalyticsModule->Parameters->SimpleItem[0].Value = soap_strdup(soap, temp_str);
/* for hik MD support */
MotionAnalyticsModule->Parameters->ElementItem = tMalloc(struct _tt__ItemList_ElementItem);
if (MotionAnalyticsModule->Parameters->ElementItem == NULL)
return SOAP_FAULT;
bzero(MotionAnalyticsModule->Parameters->ElementItem, sizeof(struct _tt__ItemList_ElementItem));
MotionAnalyticsModule->Parameters->ElementItem->Name = soap_strdup(soap, "Layout");
/* celllayout */
struct tt__CellLayout *cellLayout = tMalloc(struct tt__CellLayout);
if (cellLayout == NULL)
return SOAP_FAULT;
bzero(cellLayout, sizeof(struct tt__CellLayout));
sprintf(temp_str, "%d", CELL_LAYOUT_COLS);
cellLayout->Columns = soap_strdup(soap, temp_str);
sprintf(temp_str, "%d", CELL_LAYOUT_ROWS);
cellLayout->Rows = soap_strdup(soap, temp_str);
cellLayout->Transformation = tMalloc(struct tt__Transformation);
if (cellLayout->Transformation == NULL)
return SOAP_FAULT;
bzero(cellLayout->Transformation, sizeof(struct tt__Transformation));
cellLayout->Transformation->Translate = tMalloc(struct tt__Vector);
if (cellLayout->Transformation->Translate == NULL)
return SOAP_FAULT;
cellLayout->Transformation->Translate->x = tMalloc(float);
cellLayout->Transformation->Translate->y = tMalloc(float);
bzero(cellLayout->Transformation->Translate->x, sizeof(float));
bzero(cellLayout->Transformation->Translate->y, sizeof(float));
*(cellLayout->Transformation->Translate->x) = -1;
*(cellLayout->Transformation->Translate->y) = -1;
cellLayout->Transformation->Scale = tMalloc(struct tt__Vector);
if (cellLayout->Transformation->Scale == NULL)
return SOAP_FAULT;
cellLayout->Transformation->Scale->x = tMalloc(float);
cellLayout->Transformation->Scale->y = tMalloc(float);
bzero(cellLayout->Transformation->Scale->x, sizeof(float));
bzero(cellLayout->Transformation->Scale->y, sizeof(float));
// 有效位数
*(cellLayout->Transformation->Scale->x) = 0.09f;
*(cellLayout->Transformation->Scale->y) = 0.11f;
t = get_xml((pFunOut)soap_out_tt__CellLayout, soap, "tt", NULL, "tt:CellLayout", (void *)cellLayout, 0, "");
MotionAnalyticsModule->Parameters->ElementItem->__any = t;
t = NULL;
index++;
}
if (profiles[j].tamper_support)
{
/* AnalyticsModule-MyTamperDetecModule*/
struct tt__Config *TamperAnalyticsModule = &(vaconf->AnalyticsEngineConfiguration->AnalyticsModule[index]);
snprintf(temp_str, LEN_INFO, MODULE_TOKEN, ANALYTICS_TAMPER, profiles[j].channel);
TamperAnalyticsModule->Name = soap_strdup(soap, temp_str);
TamperAnalyticsModule->Type = soap_strdup(soap, "tt:TamperEngine");
TamperAnalyticsModule->Parameters = tMalloc(struct tt__ItemList);
if (TamperAnalyticsModule->Parameters == NULL)
return SOAP_FAULT;
bzero(TamperAnalyticsModule->Parameters, sizeof(struct tt__ItemList));
TamperAnalyticsModule->Parameters->__sizeElementItem = 2;
TamperAnalyticsModule->Parameters->__sizeSimpleItem = 1;
TamperAnalyticsModule->Parameters->SimpleItem = lMalloc(struct _tt__ItemList_SimpleItem,
sizeof(struct _tt__ItemList_SimpleItem) * TamperAnalyticsModule->Parameters->__sizeSimpleItem);
if (TamperAnalyticsModule->Parameters->SimpleItem == NULL)
return SOAP_FAULT;
bzero(TamperAnalyticsModule->Parameters->SimpleItem,
sizeof(struct _tt__ItemList_SimpleItem) * TamperAnalyticsModule->Parameters->__sizeSimpleItem);
TamperAnalyticsModule->Parameters->SimpleItem[0].Name = soap_strdup(soap, "Sensitivity");
sensitivity = get_tamper_sensitivity(i / 2 + 1);
snprintf(temp_str, LEN_INFO, "%d", sensitivity);
TamperAnalyticsModule->Parameters->SimpleItem[0].Value = soap_strdup(soap, temp_str);
TamperAnalyticsModule->Parameters->ElementItem = lMalloc(struct _tt__ItemList_ElementItem,
sizeof(struct _tt__ItemList_ElementItem) * TamperAnalyticsModule->Parameters->__sizeElementItem);
if (TamperAnalyticsModule->Parameters->ElementItem == NULL)
return SOAP_FAULT;
bzero(TamperAnalyticsModule->Parameters->ElementItem, sizeof(struct _tt__ItemList_ElementItem));
/* Element 0 */
TamperAnalyticsModule->Parameters->ElementItem[0].Name = soap_strdup(soap, "Transformation");
struct tt__Transformation *Transformation = tMalloc(struct tt__Transformation);
if (Transformation == NULL)
return SOAP_FAULT;
bzero(Transformation, sizeof(struct tt__Transformation));
Transformation->Translate = tMalloc(struct tt__Vector);
if (Transformation->Translate == NULL)
return SOAP_FAULT;
Transformation->Translate->x = tMalloc(float);
Transformation->Translate->y = tMalloc(float);
bzero(Transformation->Translate->x, sizeof(float));
bzero(Transformation->Translate->y, sizeof(float));
*(Transformation->Translate->x) = -1;
*(Transformation->Translate->y) = -1;
Transformation->Scale = tMalloc(struct tt__Vector);
if (Transformation->Scale == NULL)
return SOAP_FAULT;
Transformation->Scale->x = tMalloc(float);
Transformation->Scale->y = tMalloc(float);
bzero(Transformation->Scale->x, sizeof(float));
bzero(Transformation->Scale->y, sizeof(float));
*(Transformation->Scale->x) = 0.0002f;
*(Transformation->Scale->y) = 0.0002f;
t = get_xml((pFunOut)soap_out_tt__Transformation, soap, "tt", NULL, "tt:Transformation", (void *)Transformation, 0, "");
TamperAnalyticsModule->Parameters->ElementItem[0].__any = t;
t = NULL;
/* Element 1 */
TamperAnalyticsModule->Parameters->ElementItem[1].Name = soap_strdup(soap, "Field");
TamperAnalyticsModule->Parameters->ElementItem[1].__any = "<tt:PolygonConfiguration>"
"<tt:Polygon>"
"<tt:Point x=\"0\" y=\"0\" />"
"<tt:Point x=\"0\" y=\"10000\"/>"
"<tt:Point x=\"10000\" y=\"10000\"/>"
"<tt:Point x=\"1000\" y=\"0\"/>"
"</tt:Polygon>"
"</tt:PolygonConfiguration>";
index++;
}
if (profiles[j].crossed_support)
{
/* AnalyticsModule-MylinecrossingModule*/
struct tt__Config *CrossedAnalyticsModule = &(vaconf->AnalyticsEngineConfiguration->AnalyticsModule[index]);
// if (CrossedAnalyticsModule == NULL)
// return SOAP_FAULT;
// bzero(CrossedAnalyticsModule, sizeof(struct tt__Config));
snprintf(temp_str, LEN_INFO, MODULE_TOKEN, ANALYTICS_CROSSED, profiles[j].channel);
CrossedAnalyticsModule->Name = soap_strdup(soap, temp_str);
CrossedAnalyticsModule->Type = soap_strdup(soap, "tt:LineDetector");
CrossedAnalyticsModule->Parameters = tMalloc(struct tt__ItemList);
if (CrossedAnalyticsModule->Parameters == NULL)
return SOAP_FAULT;
bzero(CrossedAnalyticsModule->Parameters, sizeof(struct tt__ItemList));
CrossedAnalyticsModule->Parameters->__sizeElementItem = 1;
CrossedAnalyticsModule->Parameters->__sizeSimpleItem = 1;
/* for Direction */
CrossedAnalyticsModule->Parameters->SimpleItem = lMalloc(struct _tt__ItemList_SimpleItem,
sizeof(struct _tt__ItemList_SimpleItem) * CrossedAnalyticsModule->Parameters->__sizeSimpleItem);
if (CrossedAnalyticsModule->Parameters->SimpleItem == NULL)
return SOAP_FAULT;
bzero(CrossedAnalyticsModule->Parameters->SimpleItem,
sizeof(struct _tt__ItemList_SimpleItem) * CrossedAnalyticsModule->Parameters->__sizeSimpleItem);
CrossedAnalyticsModule->Parameters->SimpleItem[0].Name = soap_strdup(soap, "Direction");
int direction = 2;
float pt_coord[4] = {0.0f, 0.0f, 1000.0f, 1000.0f};
/* ret = get_crossed_info(channel, &direction, pt_coord);
if (ret < 0)
return SOAP_FAULT;*/
snprintf(temp_str, LEN_INFO, "%d", direction);
CrossedAnalyticsModule->Parameters->SimpleItem[0].Value = soap_strdup(soap, temp_str);
/* for Segments */
CrossedAnalyticsModule->Parameters->ElementItem = tMalloc(struct _tt__ItemList_ElementItem);
if (CrossedAnalyticsModule->Parameters->ElementItem == NULL)
return SOAP_FAULT;
bzero(CrossedAnalyticsModule->Parameters->ElementItem, sizeof(struct _tt__ItemList_ElementItem));
CrossedAnalyticsModule->Parameters->ElementItem[0].Name = soap_strdup(soap, "Segments");
struct tt__Polyline *segmets = lMalloc(struct tt__Polyline, sizeof(struct tt__Polyline));
if (segmets == NULL)
return SOAP_FAULT;
bzero(segmets, sizeof(struct tt__Polyline));
segmets->__sizePoint = 2;
segmets->Point = lMalloc(struct tt__Vector,
sizeof(struct tt__Vector) * segmets->__sizePoint);
if (segmets->Point == NULL)
return SOAP_FAULT;
bzero(segmets->Point,
sizeof(struct tt__Vector) * segmets->__sizePoint);
segmets->Point[0].x = &pt_coord[0];
segmets->Point[0].y = &pt_coord[1];
segmets->Point[1].x = &pt_coord[2];
segmets->Point[1].y = &pt_coord[3];
t = get_xml((pFunOut)soap_out_tt__Polyline, soap, "tt", NULL, "tt:polyline", (void *)segmets, 0, "");
ONVIF_DBPRINTF(MSG_NOTICE, "create polyline xml \n");
CrossedAnalyticsModule->Parameters->ElementItem->__any = t;
t = NULL;
index++;
}
vaconf->RuleEngineConfiguration = tMalloc(struct tt__RuleEngineConfiguration);
if (vaconf->RuleEngineConfiguration == NULL)
return SOAP_SVR_FAULT;
bzero(vaconf->RuleEngineConfiguration, sizeof(struct tt__RuleEngineConfiguration));
if (profiles[j].motion_support)
{
result = get_motion_detect_region_info(i / 2 + 1);
if (result == NULL)
{
ONVIF_DBPRINTF(MSG_ERROR, "get NULL result from json API");
return SOAP_SVR_FAULT;
}
json_recv = json_tokener_parse(result);
free(result);
if (is_error(json_recv))
{
ONVIF_DBPRINTF(MSG_ERROR, "error parsing json: %s",
json_tokener_errors[-(unsigned long)json_recv]);
return SOAP_SVR_FAULT;
}
json_data = json_object_object_get(json_recv, "region_info");
if (json_data == NULL)
{
JSON_FREE(json_recv);
ONVIF_DBPRINTF(MSG_ERROR, "json_parse module get NULL from LuCI");
return SOAP_SVR_FAULT;
}
md_region_tmp = get_motion_detect_cells(json_data);
if (md_region_tmp == NULL)
{
JSON_FREE(json_recv);
ONVIF_DBPRINTF(MSG_ERROR, "get active cells failed");
return SOAP_SVR_FAULT;
}
md_region = soap_strdup(soap, md_region_tmp);
free(md_region_tmp);
JSON_FREE(json_recv);
vaconf->RuleEngineConfiguration->__sizeRule = 1;
/* RuleEngineConfiguration */
vaconf->RuleEngineConfiguration->Rule = lMalloc(struct tt__Config, sizeof(struct tt__Config) * vaconf->RuleEngineConfiguration->__sizeRule);
if (vaconf->RuleEngineConfiguration->Rule == NULL)
return SOAP_FAULT;
bzero(vaconf->RuleEngineConfiguration->Rule, sizeof(struct tt__Config) * vaconf->RuleEngineConfiguration->__sizeRule);
/* MyMotionDetectorRule */
struct tt__Config *MotionRule = vaconf->RuleEngineConfiguration->Rule;
snprintf(temp_str, LEN_INFO, RULE_TOKEN, ANALYTICS_MOTION, profiles[j].channel);
MotionRule->Name = soap_strdup(soap, temp_str);
MotionRule->Type = soap_strdup(soap, "tt:CellMotionDetector");
MotionRule->Parameters = tMalloc(struct tt__ItemList);
if (MotionRule->Parameters == NULL)
return SOAP_FAULT;
bzero(MotionRule->Parameters, sizeof(struct tt__ItemList));
MotionRule->Parameters->__sizeElementItem = 0;
MotionRule->Parameters->__sizeSimpleItem = 4;
MotionRule->Parameters->SimpleItem = lMalloc(struct _tt__ItemList_SimpleItem, sizeof(struct _tt__ItemList_SimpleItem) * 4);
if (MotionRule->Parameters->SimpleItem == NULL)
return SOAP_FAULT;
bzero(MotionRule->Parameters->SimpleItem, sizeof(struct _tt__ItemList_SimpleItem) * MotionRule->Parameters->__sizeSimpleItem);
/* for hik MD support */
MotionRule->Parameters->SimpleItem[0].Name = soap_strdup(soap, "ActiveCells");
MotionRule->Parameters->SimpleItem[0].Value = md_region;
MotionRule->Parameters->SimpleItem[1].Name = soap_strdup(soap, "MinCount");
MotionRule->Parameters->SimpleItem[1].Value = soap_strdup(soap, "5");
MotionRule->Parameters->SimpleItem[2].Name = soap_strdup(soap, "AlarmOnDelay");
MotionRule->Parameters->SimpleItem[2].Value = soap_strdup(soap, "1000");
MotionRule->Parameters->SimpleItem[3].Name = soap_strdup(soap, "AlarmOffDelay");
MotionRule->Parameters->SimpleItem[3].Value = soap_strdup(soap, "1000");
}
}
}为什么这个会陷入死循环