无法在ONVIF

时间:2017-01-11 11:27:47

标签: 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();

有谁能告诉我如何实现活动订阅?

1 个答案:

答案 0 :(得分:3)

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

我们可以通过三种方式订阅活动。

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

2.Basic Notification Interface。(推送机制)

3.Notification Streaming Interface。 (元数据流)

实时拉取点通知界面

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

  

CODE

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();
    }
}

基本通知界面。(推送机制)

在此界面中,摄像头将通知客户端有关该事件的信息。发送通知的连接由摄像机启动并建立在TCP协议上,因此我们需要防火墙的许可。

此界面的优点是客户端不需要是设置订阅的同一实体,即摄像头可以在订阅完成后将事件发送到任何客户端。

  

CODE

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);
            }
            );

    }
}

通知流媒体界面

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

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

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