linux裝置上的Onvif 實現7:編寫裝置能力擷取程式__linux

來源:互聯網
上載者:User

1 背景說明 

要和網路攝影機直接通訊,第一步必須擷取webserver地址,通過該地址才能進一步獲得裝置的能力、提供的媒體頻資訊等內容。webserver地址就是在probe應答包中, 具體是XAddrs:http://192.168.15.240/onvif/device_service,接下來的擷取裝置能力函數將使用此地址進行通訊。

 2  GetCapabilities命令說明

GetCapabilities函數在不同的版本中實際名稱並不一樣,我的版本中是:

SOAP_FMAC5 int SOAP_FMAC6 soap_call___ns2__GetCapabilities(struct soap *soap, const char *soap_endpoint, const char *soap_action, struct _ns2__GetCapabilities *ns2__GetCapabilities, struct _ns2__GetCapabilitiesResponse *ns2__GetCapabilitiesResponse)

該函數需要提供請求指標、應答指標。可以指定請求裝置的全部能力還是某一部分能力:

enum ns3__CapabilityCategory { ns3__CapabilityCategory__All = 0, ns3__CapabilityCategory__Analytics = 1, ns3__CapabilityCategory__Device = 2, ns3__CapabilityCategory__Events = 3, ns3__CapabilityCategory__Imaging = 4, ns3__CapabilityCategory__Media = 5, ns3__CapabilityCategory__PTZ = 6 };

以下執行個體中指定查詢ns3__CapabilityCategory__Media能力。一般的可以選取查詢ALL能力。

最後從報文中提取出媒體資訊URI  :http://192.168.15.240/onvif/Media,將用於查詢具體的視頻源、編碼器配置參數。

如果裝置具備使用者名稱、密碼,那麼查詢裝置能力可能需要鑒權過程,本文沒有研究ONVIF的鑒權機制,預設網路攝影機無需輸入使用者名稱密碼。如果出現鑒權應答,那麼應答 getCapResponse.Capabilities就是NULL指標。soap_call___ns2__GetCapabilities函數傳回值是501。

 

具體的應用執行個體如下:

/******************************************************************************
* Name:   MyGetCapabilities
*
* Desc:  擷取指定裝置節點的能力
* Param:
    struct soap *soap,
    int index, 裝置序號

* Return: BOOL,  TRUE: success,  FALSE: fail
* Global:  
* Note:  
* Author:   Tom-hongtao.gao
* -------------------------------------
* Log:   2013/07/24, Create this function by Tom-hongtao.gao
 ******************************************************************************/
BOOL MyGetCapabilities(struct soap *soap, int index)
{   
    BOOL bret=FALSE;
    int result = 0;
   
    DEVICENODE * deviceode = DLFindbyIndex(index);
    if(!deviceode)
    {
        printf("--Error: DLFindbyIndex(%d) return NULL! \n", index);
        return FALSE;
    }
    if(deviceode->webserver==NULL || strlen(deviceode->webserver)==0)
    {
        printf("--Error: deviceode->webserver is NULL! \n");
        return FALSE;
    }
   
    struct _ns2__GetCapabilities getCapReq={0};
    struct _ns2__GetCapabilitiesResponse getCapResponse={0};
    enum ns3__CapabilityCategory  temp_category = ns3__CapabilityCategory__Media;
    getCapReq.__sizeCategory=1;
    getCapReq.Category=&temp_category;
      
    result = soap_call___ns2__GetCapabilities(soap, deviceode->webserver, NULL, &getCapReq, &getCapResponse);
    if(result==-1)       
    {
        printf("soap error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
        result = soap->error;
        bret = FALSE;       
    }
    else
    {       
        if(getCapResponse.Capabilities==NULL)
        {
            printf(" GetCapabilities  failed!  result=%d \n",result);
            bret = FALSE;            
        }
        else
        {
            printf(" GetCapabilities  OK! result=%d \n",result);
            //printf(" Media->XAddr=%s \n", getCapResponse.Capabilities->Media->XAddr);
            DLSetMediaUri(index, getCapResponse.Capabilities->Media->XAddr);
            //PrintfNodebyIndex(index);
            bret = TRUE;     
        }
    }

    soap_end(soap);
    return bret;
   
}

實際的資料報文如下: 略

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.