fujuntang
2022-04-28 51ccd8155f029d66366d0df8e2baf886ffd50000
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
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
 
#include "capabilities/capa.h"
#include "proto_comm.h"
#include "proto_dbg.h"
 
/************************************************************************
  * Get the video and audio configurations
  *
        [in] MediaXAddr: the media service address
        [out] profiles: the parsed cfg data and it should be freed by the customer after finished
  *
************************************************************************/
int proto_GetProfiles(const char *MediaXAddr, struct tagProfile **profiles, const char *username, const char *passwd)
{
    int i = 0;
    int result = 0;
    struct soap *soap = NULL;
    struct _trt__GetProfiles            req;
    struct _trt__GetProfilesResponse    rep;
 
    SOAP_ASSERT(NULL != MediaXAddr);
    SOAP_ASSERT(NULL != (soap = proto_soap_new(SOAP_SOCK_TIMEOUT)));
 
    proto_SetAuthInfo(soap, username, passwd);
 
    memset(&req, 0x00, sizeof(req));
    memset(&rep, 0x00, sizeof(rep));
    result = soap_call___trt__GetProfiles(soap, MediaXAddr, NULL, &req, &rep);
    SOAP_CHECK_ERROR(result, soap, "GetProfiles");
 
    dump_trt__GetProfilesResponse(&rep);
 
    if (rep.__sizeProfiles > 0) {                                         
        (*profiles) = (struct tagProfile *)malloc(rep.__sizeProfiles * sizeof(struct tagProfile));
        SOAP_ASSERT(NULL != (*profiles));
        memset((*profiles), 0x00, rep.__sizeProfiles * sizeof(struct tagProfile));
    }
 
    for(i = 0; i < rep.__sizeProfiles; i++) {                     
        struct tt__Profile *ttProfile = &rep.Profiles[i];
        struct tagProfile *plst = &(*profiles)[i];
 
        if (NULL != ttProfile->token) {           
          strncpy(plst->token, ttProfile->token, sizeof(plst->token) - 1);
        }
 
        if (NULL != ttProfile->VideoSourceConfiguration) {
          struct tt__VideoSourceConfiguration *vsc = ttProfile->VideoSourceConfiguration;
      
          if (NULL != vsc->token) {
            strncpy(plst->videoCfg.token, vsc->token, sizeof(plst->videoCfg.token) - 1);
          }
 
          if (NULL != vsc->SourceToken) { 
            strncpy(plst->videoCfg.sourceToken, vsc->SourceToken, sizeof(plst->videoCfg.sourceToken) - 1);
          }
 
          if (NULL != vsc->Bounds) {
            plst->videoCfg.x = vsc->Bounds->x;
            plst->videoCfg.y = vsc->Bounds->y;
            plst->videoCfg.Width = vsc->Bounds->width;
            plst->videoCfg.Height = vsc->Bounds->height;
          }
        }
 
        if (NULL != ttProfile->VideoEncoderConfiguration) {                     
            if (NULL != ttProfile->VideoEncoderConfiguration->token) {  
                strncpy(plst->venc.token, ttProfile->VideoEncoderConfiguration->token, sizeof(plst->venc.token) - 1);
            }
 
            if (NULL != ttProfile->VideoEncoderConfiguration->Resolution) {     // 视频编码器分辨率
                plst->venc.Width  = ttProfile->VideoEncoderConfiguration->Resolution->Width;
                plst->venc.Height = ttProfile->VideoEncoderConfiguration->Resolution->Height;
            }
        }
    }
 
EXIT:
 
    if (NULL != soap) {
        proto_soap_delete(soap);
    }
 
    return rep.__sizeProfiles;
}
 
int proto_GetCapabilities(const char *DeviceXAddr, struct tagCapabilities *capa, const char *username, const char *passwd)
{
    int result = 0;
    struct soap *soap = NULL;
    struct _tds__GetCapabilities            req;
    struct _tds__GetCapabilitiesResponse    rep;
 
    SOAP_ASSERT(NULL != DeviceXAddr);
    SOAP_ASSERT(NULL != capa);
    SOAP_ASSERT(NULL != (soap = proto_soap_new(SOAP_SOCK_TIMEOUT)));
 
    proto_SetAuthInfo(soap, username, passwd);
 
    memset(&req, 0x00, sizeof(req));
    memset(&rep, 0x00, sizeof(rep));
    result = soap_call___tds__GetCapabilities(soap, DeviceXAddr, NULL, &req, &rep);
    SOAP_CHECK_ERROR(result, soap, "GetCapabilities");
 
    dump_tds__GetCapabilitiesResponse(&rep);
 
    memset(capa, 0x00, sizeof(struct tagCapabilities));
    if (NULL != rep.Capabilities) {
        if (NULL != rep.Capabilities->Media) {
            if (NULL != rep.Capabilities->Media->XAddr) {
                strncpy(capa->MediaXAddr, rep.Capabilities->Media->XAddr, sizeof(capa->MediaXAddr) - 1);
            }
        }
 
        if (NULL != rep.Capabilities->Events) {
            if (NULL != rep.Capabilities->Events->XAddr) {
                strncpy(capa->EventXAddr, rep.Capabilities->Events->XAddr, sizeof(capa->EventXAddr) - 1);
            }
        }
 
        if (NULL != rep.Capabilities->Analytics) {
            if (NULL != rep.Capabilities->Analytics->XAddr) {
                strncpy(capa->AnalyticsXAddr, rep.Capabilities->Analytics->XAddr, sizeof(capa->AnalyticsXAddr) - 1);
            }
        }
 
        if (NULL != rep.Capabilities->Device) {
            if (NULL != rep.Capabilities->Device->XAddr) {
                strncpy(capa->DeviceXAddr, rep.Capabilities->Device->XAddr, sizeof(capa->DeviceXAddr) - 1);
            }
        }
 
        if (NULL != rep.Capabilities->Imaging) {
            if (NULL != rep.Capabilities->Imaging->XAddr) {
                strncpy(capa->ImageXAddr, rep.Capabilities->Imaging->XAddr, sizeof(capa->ImageXAddr) - 1);
            }
        }
 
        if (NULL != rep.Capabilities->PTZ) {
            if (NULL != rep.Capabilities->PTZ->XAddr) {
                strncpy(capa->PTZXAddr, rep.Capabilities->PTZ->XAddr, sizeof(capa->PTZXAddr) - 1);
            }
        }
    }
 
EXIT:
 
    if (NULL != soap) {
        proto_soap_delete(soap);
    }
 
    return result;
}