zhangmeng
2023-02-01 e2c5d5b0bf2d3f0fe04222fb62b2c9d2c58bfe6f
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
#ifndef _smartai_shm_struct_parser_h
#define _smartai_shm_struct_parser_h
 
#include <stdint.h>
#include "std_target.h"
 
struct stimg{
    uint64_t id;
    unsigned char* data;
    uint64_t data_size;
    uint32_t width;
    uint32_t height;
    char* timestamp;
    uint32_t timestamp_size;
    char* camera_id;
    uint32_t camera_id_size;
    char* camera_name;
    uint32_t camera_name_size;
};
 
//////////////////////////////////////////////
// sdk result
 
struct strc{
    int32_t left;
    int32_t top;
    int32_t right;
    int32_t bottom;
};
 
struct sttgt{
    uint64_t id;
    char* type;
    uint32_t type_size;
    int32_t confidence;
    struct strc rect;
    unsigned char* feature;
    uint32_t feature_size;
    unsigned char* attribute;
    uint32_t attribute_size;
};
 
struct stsdk{
    char* sdktype;
    uint32_t sdktype_size;
    char* sdkid;
    uint32_t sdkid_size;
    char* sdkname;
    uint32_t sdkname_size;
    char* timestamp;
    uint32_t timestamp_size;
 
    uint32_t tgt_count;
    // targets [struct sttgt]
    struct sttgt* tgt;
};
 
struct strule{
    char* handletrack;
    uint32_t handletrack_size;
    char* datatype;
    uint32_t datatype_size;
 
    uint32_t sdk_count;
    // struct stsdk
    struct stsdk* sdk;
};
 
#ifdef __cplusplus
extern "C"{
#endif
 
/*
    以下api提供将image放入shm和从shm取出的功能
    make_image_ref 将 image 信息组装成 stimg 结构,不发生内存拷贝,参数生命周期由外部管理保证
    image2shm 将 stimg 放入共享内存 shm 中,由外部保证 shm 足够大
        也可以不使用 make_image_ref 自己组装 struct stimg
    shm2image 将共享内存 shm 的内容组装成 stimg 结构,不产生内存拷贝,仅移动指针
        返回一个 struct stimg 结构的指针,需要调用 free_stimg 释放
    free_stimg 释放 shm2image 返回的指针
*/
struct stimg make_image_ref(const uint64_t id, const unsigned char* data, const uint32_t size,
                            const uint32_t width, const uint32_t height,
                            const char* timestamp, const uint32_t ts_size,
                            const char* camera_id, const uint32_t cid_size,
                            const char* camera_name,const uint32_t cname_size);
void image2shm(void* shm, struct stimg* img);
struct stimg* shm2image(void* shm);
void free_stimg(struct stimg* img);
 
/*
    rule2shm 在 decoder 中调用,初始化一个 rulemsg 给后续 analysis 使用
    add_result2rule_in_shm 将 tresult 加入到 shm 中保存的 rule 中使用的结构体中
    shm2rule 获取 shm 中保存的 rule 结构体,不产生内存拷贝
        返回一个 struct strule 结构的指针,需要调用 free_strule 释放
    free_strule 释放 shm2rule 返回的指针
*/
void rule2shm(void* shm, const char* handletrack, const uint32_t ht_size);
void add_result2rule_in_shm(void* shm, const TResult* res,
                            const char* sdktype, const uint32_t st_size,
                            const char* timestamp, const uint32_t ts_size);
struct strule* shm2rule(void* shm);
void free_strule(struct strule* rule);
 
#ifdef __cplusplus
}
#endif
#endif