To get tracks using GO, do the following:
- Install GO (see Go programming language).
Run the code example:
| Expand |
|---|
|
| Code Block |
|---|
client := metadata.NewMetadataServiceClient(conn)
stream, err := client.PullMetadata(context.Background())
ch := make(chan int, 8)
go func() {
for {
in, err := stream.Recv()
if err == io.EOF {
close(ch)
return
}
if err != nil {
log.Fatal(err)
}
switch data := in.Data.(type) {
case *metadata.PullMetadataResponse_Heartbeat:
//
case *metadata.PullMetadataResponse_ConfigUpdate:
//
case *metadata.PullMetadataResponse_Sample:
switch sampleData := data.Sample.Data.(type) {
case *metadata.MetadataSample_Tracklets:
log.Printf("Time: %v\nTracklets: %v", data.Sample.Timestamp, sampleData.Tracklets)
}
}
ch <- 1 // notify the main thread about receiving the sample
}
}()
endpoint := media.EndpointRef{AccessPoint: "hosts/SERVER/AVDetector.1/SourceEndpoint.vmda"}
req := metadata.PullMetadataRequest{
Count: 8, // ask for several samples, so that they are not lost while server waits for another response from client
Endpoint: &endpoint,
ProposedChannelIdleMs: 15000,
}
if err := stream.Send(&req); err != nil {
log.Fatal(err)
}
for {
// whenever a sample is received ask for another sample keeping the total samples requested to a fixed value > 1
<-ch
req := metadata.PullMetadataRequest{
Count: 1,
}
if err := stream.Send(&req); err != nil {
log.Fatal(err)
}
} |
|
As a result, you will get the possible response options.
Response examples:
| Code Block |
|---|
| title | Message about the received tracks: |
|---|
|
{
"sample": {
"timestamp": "20230914T133656.981000",
"tracklets": {
"tracklets": [
{
"id": 70,
"state": "OBJECT_STATE_NORMAL",
"rectangle": {
"x": 0.10248079895973206,
"y": 0.3568287789821625,
"w": 0.17517775297164917,
"h": 0.257714182138443
},
"logicalCenter": {
"x": 0.19006967544555664,
"y": 0.6145429611206055
},
"color": {
"hue": 222.47191011235952,
"saturation": 0.3093524946210368,
"value": 0.49719319611902735
}
}
]
}
}
} |
where
- timestamp—time corresponding to the video frame for which tracks are formed;
- tracklets—list of tracks.
| Code Block |
|---|
| title | Message about the Server activity when the Server has no other messages: |
|---|
|
{
"heartbeat": {}
} |
| Code Block |
|---|
| title | Message about the time during which the Server is active and you can receive data from it: |
|---|
|
{
"configUpdate": {
"maxChannelIdleMs": 15000
}
} |