无法在ONVIF中实现事件订阅

Nav*_*rma 1 c# camera onvif

我正在使用 Onvif 设备管理器 dll( onvif.services、discovery、session 和 utils.async、common、diagnostic、fsharp dll )实现 ONVIF。

到目前为止,我能够发现 onvif 设备,获取范围(设备信息)及其配置文件,以流式传输视频并实现 ptz 控制。

现在我正在实现事件订阅,但我无法订阅任何特定事件。

这是我的事件订阅代码。我不知道下一步该做什么。

OnvifParam deviceparam = ONVIFDevices[listBox1.SelectedIndex];
deviceparam.Account = new NetworkCredential { UserName = "admin", Password = "admin" };
var sessionFactory = new NvtSessionFactory(deviceparam.Account);

int listenport = 8085;
string EventListeningPort = null;
int.TryParse(EventListeningPort, out listenport);
Uri uri = new Uri(deviceparam.Uris[0].ToString());
deviceparam.URL = uri.ToString();
Profile[] profiles = null;
var f = sessionFactory.CreateSession(uri);
profiles = f.GetProfiles().RunSynchronously();
deviceparam.Profiles = profiles;

OdmSession o = new OdmSession(f);

var subs = o.GetBaseEvents(listenport).Subscribe();

var eventprop = f.GetEventProperties();

FilterType filter = new FilterType();
Run Code Online (Sandbox Code Playgroud)

谁能告诉我如何实现事件订阅?

Nav*_*rma 6

经过大量阅读和搜索后,我使用 Onvif 设备管理器 dll 实现了事件。

我们可以通过三种方式订阅事件。

1.实时拉点通知接口。(拉点机制)

2.基本通知接口(推送机制)

3.通知流接口。(元数据流)

实时拉点通知界面

该接口提供防火墙友好的通知接口。在此客户端中,将定期从摄像头拉取拉取事件的消息。因此,我们创建一个拉点订阅,然后从相机中拉取事件。

代码

class Events
{
   public void GenerateEvent()
    {
        // for this device must be discoverable and and its account and uri must be known

        var sessionFactory = new NvtSessionFactory(deviceparam.Account); // deviceparam is camera and account contaion its username and password
        var sess = sessionFactory.CreateSession(uri);
        OdmSession os = new OdmSession(sess);
        os.GetPullPointEvents()// this function contains function for the subscription and pull messages
            .Subscribe(
            evnt =>
            {
                Console.WriteLine(EventParse.ParseTopic(evnt.topic));
                var messages = EventParse.ParseMessage(evnt.message);
                messages.ForEach(msg => Console.WriteLine(msg));
            }, err =>
            {
                Console.WriteLine(err.Message);
            }
            );

    } 
}

public static class EventParse
{
    public static string ParseTopic(TopicExpressionType topic) 
    {
        string topicString = "";

        topic.Any.ForEach(node => {
            topicString += "value: " + node.Value;
            });

            return topicString;
    }

    public static string[] ParseMessage(Message message) 
    {
        List<string> messageStrings = new List<string>();

        messageStrings.Add("messge id: " + message.key);

        if(message.source!= null)
            message.source.simpleItem.ForEach(sitem => 
            {
                string txt = sitem.name + " " + sitem.value;
                messageStrings.Add(txt);
            });

        if (message.data != null)
            message.data.simpleItem.ForEach(sitem => 
            {
                string txt = sitem.name + " " + sitem.value;
                messageStrings.Add(txt);
            });

        return messageStrings.ToArray();
    }
}
Run Code Online (Sandbox Code Playgroud)

基本通知接口。(推送机制)

在此界面中,摄像机将通知客户端有关事件的信息。发送通知的连接是由摄像机发起的,建立在TCP协议上,所以这里需要防火墙的许可。

该接口的优点是客户端不需要是设置订阅的同一实体,即相机可以在订阅完成后将事件发送到任何客户端。

代码

class Events
{
    public void GenerateBaseEvent()
    {
        // for this device must be discoverable and and its account and uri must be known

        var sessionFactory = new NvtSessionFactory(deviceparam.Account); // deviceparam is camera and account contaion its username and password
        var sess = sessionFactory.CreateSession(uri);
        OdmSession os = new OdmSession(sess);
        os.GetBaseEvents(9865)// some random port number
            .Subscribe(
            evnt =>
            {
                Console.WriteLine(EventParse.ParseTopic(evnt.topic));
                var messages = EventParse.ParseMessage(evnt.message);
                messages.ForEach(msg => Console.WriteLine(msg));
            }, err =>
            {
                Console.WriteLine(err.Message);
            }
            );

    }
}
Run Code Online (Sandbox Code Playgroud)

通知流接口

在此界面中,我们通过 RTP 或 RTSP 流实时接收事件通知。首先,设置一个媒体配置文件,其中包含具有所需事件过滤器的 MetadataConfiguration。之后,可以获取并使用该配置文件的流 URI。

我还没有尝试过这个界面。

上面的代码没有过滤器,因此它会发出所有事件的通知。