zhangmeng
2023-02-02 8c36971afa38f8a2fb058704d6c584e0ce0c2bc4
shmparser/shmparser.c
File was renamed from shmparser.c
@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
enum{
    IMG_DATA = 1,
@@ -430,7 +431,7 @@
    Put64(pheader, packHeader(RULE_HANDLETRACK, dummy_val + 3 + st_size));
    if (dummy_val + 3 + st_size > SIZEHT)
        printf("handletrack_size Must Less Than %d But Now %d\n", SIZEHT, dummy_val + 3 + st_size);
        printf("handletrack_size Must Less Than %lu But Now %lu\n", SIZEHT, dummy_val + 3 + st_size);
    // 下一个 field
    tmp += SIZEHT - dummy_val;
@@ -546,3 +547,163 @@
    free(rule->sdk);
    free(rule);
}
///////////////////////////////////////////////////////////////
// go need function
void goimage2shm(void* shm, void* img){
    struct stimg* cimg = (struct stimg*)img;
    image2shm(shm, cimg);
}
void goimageinfo(void* img, void** data, uint64_t* size,
                void** ts, uint32_t* tss,
                void** cid, uint32_t* cids,
                void** cname, uint32_t* cnames,
                uint64_t* id, uint32_t* w, uint32_t* h)
{
    struct stimg* cimg = (struct stimg*)img;
    *data = cimg->data;
    *size = cimg->data_size;
    *ts = cimg->timestamp;
    *tss = cimg->timestamp_size;
    *cid = cimg->camera_id;
    *cids = cimg->camera_id_size;
    *cname = cimg->camera_name;
    *cnames = cimg->camera_name_size;
    *id = cimg->id;
    *w = cimg->width;
    *h = cimg->height;
}
void gotargetsdel(void* tgts){
    if (tgts) {
        struct sttgt* t = (struct sttgt*)tgts;
        free(t);
    }
}
void* gotargetsnew(const uint32_t size){
    struct sttgt* t = (struct sttgt*)calloc(size, sizeof(struct sttgt));
    return t;
}
void gotargetsadd(void* tgts, int idx, uint64_t id, char* type, uint32_t tsize, int32_t confidence,
                    int left, int top, int right, int bottom,
                    unsigned char* feat, uint32_t featsize,
                    unsigned char* attr, uint32_t attrsize)
{
    struct sttgt* ts = (struct sttgt*)tgts;
    struct sttgt t;
    memset(&t, 0, sizeof(t));
    t.id = id;
    t.type = type;
    t.type_size = tsize;
    t.confidence = confidence;
    t.rect.left = left;
    t.rect.top = top;
    t.rect.right = right;
    t.rect.bottom = bottom;
    t.feature = feat;
    t.feature_size = featsize;
    t.attribute = attr;
    t.attribute_size = attrsize;
    ts[idx] = t;
}
void goruleaddsdk(void* shm, void* tgts, uint32_t tgtcnt,
                    char* type, uint32_t tsize,
                    char* timestamp, uint32_t tmsize)
{
    TResult* res = (TResult*)calloc(1, sizeof(TResult));
    res->count = tgtcnt;
    res->targets = (Target*)calloc(tgtcnt, sizeof(Target));
    struct sttgt* ts = (struct sttgt*)tgts;
    for(uint32_t i = 0; i < tgtcnt; i++){
        Target t;
        memset(&t, 0, sizeof(t));
        t.id = ts[i].id;
        t.confidence = ts[i].confidence;
        memcpy(&t.rect, &ts[i].rect, sizeof(t.rect));
        memcpy(t.type, ts[i].type, ts[i].type_size);
        t.feature = (char*)ts[i].feature;
        t.feature_size = ts[i].feature_size;
        t.attribute = (char*)ts[i].attribute;
        t.attribute_size = ts[i].attribute_size;
        res->targets[i] = t;
    }
    add_result2rule_in_shm(shm, res, type, tsize, timestamp, tmsize);
    free(res->targets);
    free(res);
}
//////////////////// unserialize
void gorulehandletrack(void* rule, void** data, uint32_t* size){
    struct strule* r = (struct strule*)rule;
    *data = r->handletrack;
    *size = r->handletrack_size;
}
void goruledatatype(void* rule, void** data, uint32_t* size){
    struct strule* r = (struct strule*)rule;
    *data = r->datatype;
    *size = r->datatype_size;
}
void gorulesdk(void* rule, void** data, uint32_t* size){
    struct strule* r = (struct strule*)rule;
    *data = r->sdk;
    *size = r->sdk_count;
}
void gorulesdkinfo(void* sdk, int idx, void** t, uint32_t* ts,
                    void** i, uint32_t* is, void** n, uint32_t* ns,
                    void** tm, uint32_t* tms, void** data, uint32_t* size)
{
    struct stsdk* s = (struct stsdk*)sdk;
    *t = s->sdktype;
    *ts = s->sdktype_size;
    *i = s->sdkid;
    *is = s->sdkid_size;
    *n = s->sdkname;
    *ns = s->sdkname_size;
    *tm = s->timestamp;
    *tms = s->timestamp_size;
    *data = s->tgt;
    *size = s->tgt_count;
}
void gorulesdktargetinfo(void* tgt, int idx, uint64_t* id, int32_t* c,
                        int32_t* l,int32_t* t,int32_t* r,int32_t* b,
                        void** tp, uint32_t* tps,
                        void** feat, uint32_t* fs, void** attr, uint32_t* attrs)
{
    struct sttgt* tt = (struct sttgt*)tgt;
    *id = tt->id;
    *c = tt->confidence;
    *l = tt->rect.left;
    *t = tt->rect.top;
    *r = tt->rect.right;
    *b = tt->rect.bottom;
    *tp = tt->type;
    *tps = tt->type_size;
    *feat = tt->feature;
    *fs = tt->feature_size;
    *attr = tt->attribute;
    *attrs = tt->attribute_size;
}