1 背景

前文已经判断出了支持的通道,对于主通道子通道都支持的摄像头,优先选择主通道获取流媒体地址。实际应用中只要取得一个通道的RTSP即可。

2 GetStreamUri

获取流媒体地址的函数是GetStreamUri,我的版本中是:

SOAP_FMAC5 int SOAP_FMAC6 soap_call___ns8__GetStreamUri(struct soap *soap, const char *soap_endpoint, const char *soap_action, struct _ns8__GetStreamUri *ns8__GetStreamUri, struct _ns8__GetStreamUriResponse *ns8__GetStreamUriResponse)

请求指针中必须填写profile的ProfileToken字段,就是要指明哪一个通道的流媒体地址。

我的代码实例是:

BOOL MyGetStreamUri(struct soap *soap, int index)
{   
    BOOL bret=FALSE;
    int result = 0;
    int i=-1;
   
    DEVICENODE * deviceode = DLFindbyIndex(index);
    if(!deviceode)
    {
        printf("--Error: DLFindbyIndex(%d) return NULL! \n", index);
        return FALSE;
    }
    if(deviceode->mediauri==NULL || strlen(deviceode->mediauri)==0)
    {
        printf("--Error: deviceode->mediauri is NULL! \n");
        return FALSE;
    }

    for(i=0;i<2;i++)
    {
        struct ns3__Transport Transport;
        Transport.Protocol = ns3__TransportProtocol__UDP;
        Transport.Tunnel=NULL;
        struct ns3__StreamSetup  StreamSetup;
        StreamSetup.Stream = ns3__StreamType__RTP_Unicast;
        StreamSetup.Transport= &Transport;
        StreamSetup.__size = 0;
        StreamSetup.__any=NULL;
        StreamSetup.__anyAttribute=NULL;
       
        struct _ns8__GetStreamUri getStreamUriReq;
        struct _ns8__GetStreamUriResponse getStreamUriResponse;  
       
        getStreamUriReq.StreamSetup  = &StreamSetup;
        getStreamUriReq.ProfileToken = deviceode->profile[i].token;

        result = soap_call___ns8__GetStreamUri(soap, deviceode->mediauri, NULL, &getStreamUriReq, &getStreamUriResponse);
        if(result==-1)       
        {
            printf("soap error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
            result = soap->error;
            bret = FALSE;       
        }
        else
        {
            printf(" GetStreamUri(%s) OK! \n", getStreamUriReq.ProfileToken);        
            //printf(" MediaUri->Uri=%s \n", getStreamUriResponse.MediaUri->Uri);

            memset(deviceode->profile[i].rtsp, 0, sizeof(MAXSTRLEN));
            strncpy(deviceode->profile[i].rtsp, getStreamUriResponse.MediaUri->Uri, MAXSTRLEN);
            bret = TRUE;     
        }          
    }
   
    soap_end(soap);
    return bret;
   
}

3 完整的请求、应答报文:略

Logo

更多推荐