Attach metadata from MIP Driver into Camera using code

Hello,

I’m trying to attach metadata from MIP Driver into Camera. Using management client, I’m doing:

RecordServer > Camera > Client > Related metadata > Add.

But I need to do it automatically. So after grabbing my Item Camera using Configuration.Instance.GetItemsByKind(Kind.Camera),

I’m trying to add an “related item”, but nothing happens.

myCamera.GetRelated().Add(item);

How can I save and broadcast it to management server?

Thanks.

You cannot add items the way you suggest. The way it should be done would be by using the Configuration API but unfortunately the Configuration API misses the capability to work with related devices.

it is on Milestone Devlopment’s wish list to ammend the Configuration API with the capability to manage related devices.

Hello, Bo!

Are there any updates on this?

Is there a way to automate the communication process for 200+ devices using the SDK?

Yes. XProtect 2018R1 and newer..

It is now possible to configure a camera’s related devices via the class VideoOS.Platform.ConfigurationItems.ClientSettings under each device (e.g. VideoOS.Platform.ConfigurationItems.Camera).

https://doc.developer.milestonesys.com/html/index.html?base=gettingstarted/mip2018r1_intro.html&tree=tree_search.html?search=related

Thanks!

Hello, Bo!

We tried to use the ClientSettings class in XProtect 2019R1 and failed.

If we define camera as a related object of hardware using “var Cam = CamHW.GetRelated()[0];” we can see the “_related” as list of related Metadataprovider which we manually added in Milestone Mng Client.

But if we construct class using ServerID and CameraPath “var CamProps = new ClientSettings(ServerID, CameraPath);” the “related” property returs NULL. And we cannot get and set related using ClientSettings.

May be you have any working examples?

I can read the related devices like this:

ManagementServer ms = new ManagementServer(EnvironmentManager.Instance.MasterSite.ServerId);
var hw = ms.RecordingServerFolder.RecordingServers.FirstOrDefault().HardwareFolder.Hardwares.FirstOrDefault(x => x.Name == "Stable103");
var cam = hw.CameraFolder.Cameras.FirstOrDefault(c => c.Name == "LPR camera1");
string related = cam.ClientSettingsFolder.ClientSettings.FirstOrDefault().Related;

I was unable to update and save new information in the Related field. I am currently investigating this.

This code works for me..

private void AddToRelated()
{
    // This code finds the item to add as related
    ManagementServer ms = new ManagementServer(EnvironmentManager.Instance.MasterSite.ServerId);
    string pathToBeAddedAsRelated = ms.RecordingServerFolder.RecordingServers.FirstOrDefault().HardwareFolder.Hardwares.FirstOrDefault(x => x.Name == "S01").MetadataFolder.Metadatas.FirstOrDefault(x => x.Name == "S01 - Metadata 2").Path;
 
    // This code adds the related item while not removing the existing. Note that there can be multiple Metadata items but not multiple microphones or speakers
    var hw = ms.RecordingServerFolder.RecordingServers.FirstOrDefault().HardwareFolder.Hardwares.FirstOrDefault(x => x.Name == "S01");
    var cam = hw.CameraFolder.Cameras.FirstOrDefault(c => c.Name == "S01 - Camera 1");
    var clientSettings = cam.ClientSettingsFolder.ClientSettings.FirstOrDefault();
    string path = clientSettings.Path;
    string related = clientSettings.Related;
    string newRelated = related + "," + pathToBeAddedAsRelated; ;
    clientSettings.Related = newRelated;
    clientSettings.Save();
 
    // This code is here for verification but also shows another way to find the ClientSettings if you know the path
    var readClientSettingsAgain = new ClientSettings(EnvironmentManager.Instance.MasterSite.ServerId, path);
    string readbackRelated = readClientSettingsAgain.Related;   
}

Hay Bo,

does your sample also add a metadata Driver to each camera?

I have 200 cameras on my system, already preconfig.

I want to add a metadata driver for each camera so i can send specific metadata to each of them.

The code snippet adds one metadata stream to one camera as related device. Here some of the prerequisites are: The camera exists and is already added to the XProtect VMS. The metadata device exists and is already added to the VMS.

If you already have 200 cameras and already have 200 metadata channels then the code can be modified and used to run 200 times and do the configuration needed to make the metadata channels “related” to the cameras.