Stream 从支持ONVIF协议的网络IP摄像机获取实时流?

Stream 从支持ONVIF协议的网络IP摄像机获取实时流?,stream,camera,video-streaming,protocols,onvif,Stream,Camera,Video Streaming,Protocols,Onvif,我有网络IP摄像头(佳能VB-M40)。此摄像头支持ONVIF协议。我正在用C语言在windows中实现它的ONVIF功能。我使用以下请求获得了它的RTSPURI snprintf(postData, sizeof(postData), "<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envel

我有网络IP摄像头(佳能VB-M40)。此摄像头支持ONVIF协议。我正在用C语言在windows中实现它的ONVIF功能。我使用以下请求获得了它的RTSPURI

snprintf(postData, sizeof(postData),
      "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
      "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" "
      "xmlns:tds=\"http://www.onvif.org/ver10/media/wsdl\""
      "xmlns:tt=\"http://www.onvif.org/ver10/schema\">"             
      "<soap:Body>"
      "<tds:GetStreamUri>"
        "<tds:StreamSetup>"
          "<tt:Stream>0</tt:Stream>" 
          "<tt:Transport>" 
            "<tt:Protocol>HTTP</tt:Protocol>" 
          "</tt:Transport>"
        "</tds:StreamSetup>"
        "<tds:ProfileToken>profile1</tds:ProfileToken>"
      "</tds:GetStreamUri>"
        "</soap:Body></soap:Envelope>",
      username, digest_str, nonce_str, time_str); 
snprintf(postData,sizeof(postData),
""
""             
""
""
""
"0" 
"" 
“HTTP”
""
""
“档案1”
""
"",
用户名、摘要、暂时、时间);
答复是:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope  xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" 
                    xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" 
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                    xmlns:wsa5="http://www.w3.org/2005/08/addressing" 
                    xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#" 
                    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
                    xmlns:ds="http://www.w3.org/2000/09/xmldsig#" 
                    xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
                    xmlns:MC2="http://www.onvif.org/ver10/schema" 
                    xmlns:MC3="http://www.w3.org/2005/05/xmlmime" 
                    xmlns:MC4="http://docs.oasis-open.org/wsn/b-2" 
                    xmlns:MC10="http://www.w3.org/2004/08/xop/include" 
                    xmlns:MC5="http://docs.oasis-open.org/wsrf/bf-2" 
                    xmlns:MC6="http://docs.oasis-open.org/wsn/t-1" 
                    xmlns:CC="http://www.canon.com/ns/networkcamera/onvif/va/schema" 
                    xmlns:MC1="http://www.onvif.org/ver10/media/wsdl" 
                    xmlns:MC8="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding" 
                    xmlns:MC9="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding" 
                    xmlns:MC7="http://www.onvif.org/ver20/analytics/wsdl" 
                    xmlns:ter="http://www.onvif.org/ver10/error" 
                    xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" 
                    xmlns:tns1="http://www.onvif.org/ver10/topics">
    <SOAP-ENV:Header></SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <MC1:GetStreamUriResponse>
            <MC1:MediaUri>
                <MC2:Uri>rtsp://192.168.5.53:8090/profile1=r</MC2:Uri>
                <MC2:InvalidAfterConnect>false</MC2:InvalidAfterConnect>
                <MC2:InvalidAfterReboot>true</MC2:InvalidAfterReboot>
                <MC2:Timeout>PT0M0S</MC2:Timeout>
            </MC1:MediaUri>
        </MC1:GetStreamUriResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

rtsp://192.168.5.53:8090/profile1=r
假的
真的
pT00ms
根据ONVIF规范,一旦获得流URI,我就应该向设备发送“descripe”请求。我使用这个过程是因为我需要TCP上的流

我的问题是如何向设备发送“描述”请求,以及在哪个套接字上


我是否应该在发送GetStreamURI请求的同一套接字上发送此请求。或者我必须创建另一个。请求的格式是什么

将其发送到与端口554(或设备中为RTSP配置的其他端口)上的GetStreamUri请求相同的主机。然后您必须在描述之前发送选项请求。它可能会在其主体中返回401 Unauthorized status和nonce+realm值。(我使用的是您在GetStreamUri响应中收到的不同地址。)

读取此领域和nonce值,因为您需要它进行自动化并发送另一个授权选项请求

OPTIONS http://192.168.128.99:80/profile1/media.smp RTSP/1.0\r\n
CSeq: 2\r\n
Authorization: Digest username="admin", realm="iPOLiS", nonce="00000000000000000000000048E02F14", uri="http://192.168.128.99:80/profile1/media.smp", response="23a5a81fb98b6cb29368eba060ba31b9"\r\n
User-Agent: MyAgent\r\n\r\n
响应是生成的

然后来描述一下你的要求

DESCRIBE http://192.168.128.99:80/profile1/media.smp RTSP/1.0\r\n
CSeq: 3\r\n
User-Agent: MyAgent\r\n\r\n
及回应

RTSP/1.0 200 OK
CSeq: 3
Date: Thu Jun 28 05:46:20 2012 GMT
Expires: Thu Jun 28 05:46:20 2012 GMT
Content-Base: http://192.168.128.99:554/profile1/media.smp/
Content-Type: application/sdp
Content-Length: 498
x-Accept-Retransmit: our-retransmit
x-Accept-Dynamic-Rate: 1
Cache-Control: must-revalidate

v=0
o=- 0 0 IN IP4 192.168.128.9
s=Media Presentation
i=samsung
c=IN IP4 0.0.0.0
b=AS:384128
t=0 0
a=control:http://192.168.128.99:554/profile1/media.smp
a=range:npt=now-
m=video 40336 RTP/AVP 26
b=AS:384000
a=rtpmap:26 JPEG/90000
a=control:http://192.168.128.99:554/profile1/media.smp/trackID=v
a=cliprect:0,0,768,1024
a=framesize:26 1024-768
a=framerate:5.0
m=audio 40338 RTP/AVP 0
b=AS:64
a=rtpmap:0 PCMU/8000
a=control:http://192.168.128.99:554/profile1/media.smp/trackID=a

从a=控件中的此响应地址:http://192.168.128.99:554/profile1/media.smp/trackID=v 应针对媒体m=视频(其为SDP协议)进行分析。这就是我走了多远。下一个步骤应该是使用传输信息发出设置请求,然后发送播放请求。您必须在安装请求中指定的端口上侦听以接收图像

作为GetStreamUri返回
rtsp://192.168.5.53:8090/profile1=r
,要联系的RTSP服务器不在端口554上。
RTSP/1.0 200 OK
CSeq: 3
Date: Thu Jun 28 05:46:20 2012 GMT
Expires: Thu Jun 28 05:46:20 2012 GMT
Content-Base: http://192.168.128.99:554/profile1/media.smp/
Content-Type: application/sdp
Content-Length: 498
x-Accept-Retransmit: our-retransmit
x-Accept-Dynamic-Rate: 1
Cache-Control: must-revalidate

v=0
o=- 0 0 IN IP4 192.168.128.9
s=Media Presentation
i=samsung
c=IN IP4 0.0.0.0
b=AS:384128
t=0 0
a=control:http://192.168.128.99:554/profile1/media.smp
a=range:npt=now-
m=video 40336 RTP/AVP 26
b=AS:384000
a=rtpmap:26 JPEG/90000
a=control:http://192.168.128.99:554/profile1/media.smp/trackID=v
a=cliprect:0,0,768,1024
a=framesize:26 1024-768
a=framerate:5.0
m=audio 40338 RTP/AVP 0
b=AS:64
a=rtpmap:0 PCMU/8000
a=control:http://192.168.128.99:554/profile1/media.smp/trackID=a