onvif协议远程调节ip摄像机码流信息

先放代码:
IpcInfo info;
    if(UI_lookup_ipc(ipc_id, info))//从数据库获取对应id的ipc信息
    {
            return -1 ;
    }
    char *xaddr = (char *)malloc(256);
    memset(xaddr, '\0', 256);
    sprintf(xaddr, "http://%s:%d/onvif/device_service", info.net_info.ip_addr1, 80);
    if( NULL == xaddr || '\0' == xaddr[0])
    {
        DBGLOG("param invalid!");
        return -1;
    }
    struct soap *soap=discovery_get_soap();  //soap_new();
    if (NULL==soap)
    {
        printf("the soap fails to create!\n");
        return -1;
    }
    struct _tds__GetCapabilities *tds__GetCapabilities = (struct _tds__GetCapabilities *)soap_mallocz( soap, sizeof(struct _tds__GetCapabilities));
    struct _tds__GetCapabilitiesResponse *tds__GetCapabilitiesResponse
                = (struct _tds__GetCapabilitiesResponse *)soap_mallocz( soap, sizeof(struct _tds__GetCapabilitiesResponse));

    struct _trt__GetProfilesResponse   *trt__GetProfilesResponse=(struct _trt__GetProfilesResponse   *)soap_mallocz( soap, sizeof(struct _trt__GetProfilesResponse));
    struct _trt__GetProfiles *trt__GetProfiles=(struct _trt__GetProfiles *)soap_mallocz( soap, sizeof(struct _trt__GetProfiles));

    char username[MAX_TOKEN_LEN] = {""};
        char password[MAX_TOKEN_LEN];
        UI_lookup_passwd(ipc_id, username, password);//从数据库中获得对应的账号密码信息
        int diffTime = onvif_get_system_time_and_date_diff(soap, xaddr);
    if('\0' != username[0])
    {
        soap_wsse_add_UsernameTokenDigest1(soap,diffTime, g_uuid, username, password);//用户验证
    }
    tds__GetCapabilities->Category = (enum tt__CapabilityCategory *)soap_mallocz( soap, sizeof(enum tt__CapabilityCategory));
    *(tds__GetCapabilities->Category) = tt__CapabilityCategory__Media;//设备鉴权,获取媒体配置
        tds__GetCapabilities->__sizeCategory = 1;
    char Xaddr[MAX_URL_LEN];
    if(soap_call___tds__GetCapabilities(soap, xaddr , NULL, tds__GetCapabilities, tds__GetCapabilitiesResponse )!=SOAP_OK )
    {
        DBGLOG("error:GetCapabilities, xddr(%s)", xaddr);
        SOAP_PRINT_FAULT(soap, stderr);
        strcpy(Xaddr, xaddr);
    }
    else
    {
        printf("success\n");
        if( NULL == tds__GetCapabilitiesResponse->Capabilities
            || NULL == tds__GetCapabilitiesResponse->Capabilities->Media
            || NULL == tds__GetCapabilitiesResponse->Capabilities->Media->XAddr
            || strlen(tds__GetCapabilitiesResponse->Capabilities->Media->XAddr) > MAX_URL_LEN)
        {
            strcpy(Xaddr, xaddr);
        }
        else
        {
            strcpy(Xaddr, tds__GetCapabilitiesResponse->Capabilities->Media->XAddr);
        }
    }
    if( '\0' != username[0] )
    {
        soap_wsse_add_UsernameTokenDigest1(soap,diffTime, g_uuid, username, password);//每次调用soap接口都需要验证
        DBGLOG("%s %s", username, password);
    }
    struct tt__Profile *Profiles;
    int protoken_size=5;
    if(soap_call___trt__GetProfiles(soap, Xaddr, NULL, trt__GetProfiles,
                                          trt__GetProfilesResponse )!=SOAP_OK )
    {
        if(NULL==trt__GetProfilesResponse)
        {
            printf("error!\n");
            return -1;
        }
        protoken_size = fiflter_profiles(soap, trt__GetProfilesResponse, &Profiles);
        if(0==protoken_size)
            return -1;
        if (protoken_size>1)
        {
            Profiles++;
        }
    }
    else
    {
        protoken_size = fiflter_profiles(soap, trt__GetProfilesResponse, &Profiles);//获取profiles文件数,并将内容取出
        if (protoken_size>1)
        {
            Profiles++;
        }
    }
    struct _trt__SetVideoEncoderConfiguration *trt__SetVideoEncoderConfiguration=(struct _trt__SetVideoEncoderConfiguration*)soap_mallocz( soap, sizeof(struct _trt__SetVideoEncoderConfiguration));
    struct _trt__SetVideoEncoderConfigurationResponse *trt__SetVideoEncoderConfigurationResponse=(struct _trt__SetVideoEncoderConfigurationResponse *)
                soap_mallocz( soap, sizeof(struct _trt__SetVideoEncoderConfigurationResponse));
    trt__SetVideoEncoderConfiguration->ForcePersistence=xsd__boolean__true_;
    if(NULL==Profiles->VideoEncoderConfiguration||NULL==Profiles->VideoEncoderConfiguration->RateControl||NULL
       ==Profiles->VideoEncoderConfiguration->RateControl->BitrateLimit||NULL==Profiles->VideoEncoderConfiguration
       ->RateControl->FrameRateLimit)
    {
        printf("error in getprofiles!\n");
        return -1;
    }
    trt__SetVideoEncoderConfiguration->Configuration=Profiles->VideoEncoderConfiguration;
    printf("%s\n%s\n",Profiles->token,trt__SetVideoEncoderConfiguration->Configuration->token);
    if(1==g_stl_enable)//码流切换控制部分,所取值须在允许范围内
    {
        trt__SetVideoEncoderConfiguration->Configuration->RateControl->FrameRateLimit=16;
        trt__SetVideoEncoderConfiguration->Configuration->RateControl->BitrateLimit=128;
    }
    else
    {
        trt__SetVideoEncoderConfiguration->Configuration->RateControl->FrameRateLimit=25;
        trt__SetVideoEncoderConfiguration->Configuration->RateControl->BitrateLimit=512;
    }
    if('\0' != username[0])
    {
        soap_wsse_add_UsernameTokenDigest1(soap,diffTime, g_uuid, username, password);
    }
    if(soap_call___trt__SetVideoEncoderConfiguration(soap, Xaddr, NULL, trt__SetVideoEncoderConfiguration,
                                      trt__SetVideoEncoderConfigurationResponse)!=SOAP_OK )
    {
        DBGLOG("error:SetVideoEncoderConfiguration, xddr(%s)", Xaddr);
        SOAP_PRINT_FAULT(soap, stderr);
        return -1;
    }
    if(NULL!=xaddr)
    {
        free(xaddr);
        xaddr=NULL;
    }
    if(NULL!=soap)
    {
        soap_destroy(soap);
    }
    if(NULL!=tds__GetCapabilities)
    {
        free(tds__GetCapabilities);
        tds__GetCapabilities=NULL;
    }
    if(NULL!=tds__GetCapabilitiesResponse)
    {
        free(tds__GetCapabilitiesResponse);
        tds__GetCapabilitiesResponse=NULL;
    }
    if(NULL!=trt__GetProfilesResponse)
    {
        free(trt__GetProfilesResponse);
        trt__GetProfilesResponse=NULL;
    }
    if(NULL!=trt__GetProfiles)
    {
        free(trt__GetProfiles);
        trt__GetProfiles=NULL;
    }
    if(NULL!=trt__SetVideoEncoderConfiguration)
    {
        free(trt__SetVideoEncoderConfiguration);
        trt__SetVideoEncoderConfiguration=NULL;
    }
    if(NULL!=trt__SetVideoEncoderConfigurationResponse)
    {
        free(trt__SetVideoEncoderConfigurationResponse);
        trt__SetVideoEncoderConfigurationResponse=NULL;
    }
    return 0;

用多种型号的ip摄像头测试时发现:雄迈ipc不支持远程onvif修改,大华ipc支持远程修改,海康ipc265编码onvif协议不支持,profiles大小超出onvif解析数据包最大数值。

对于获取不到profiles的海康ipc,如码流编码为h264,可通过soap_call___trt__GetVideoEncoderConfiguration接口,获取对应码流的配置,从而进行修改


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页