Home > other >  Python implementation the client sends the setup message when meet problem
Python implementation the client sends the setup message when meet problem

Time:10-06

Use python implementation RTSP client setup message is sent when the return a status code of 503; Now I don't know how to solve, hence ask for help, the paid + wx: ww1194609610 (RMB 10)

` ` `
The import socket
The from urllib. Parse the import urlparse
Config_dict={' cseq: 2, 'the user_agent' : 'LibVLC/3.0.2 (LIVE555 Streaming Media v2016.11.28)', 'timeout' : 3, 'recvbite: 4096,' res_status' : '200 OK', 'rtsp_status' :' flase '
}

Clientports=[60784, 60785]
def options_get(url): ''' options请求检测 url: rtsp流地址 return: options请求相应 ''' url=urlparse(url) host=url.netloc hostname=url.hostname path=url.path port=url.port str_options='OPTIONS rtsp://' + str(host) + \ path + ' RTSP/1.0\r\n' str_options +='CSeq: ' + str(config_dict['cseq']) + '\r\n' str_options +='User-Agent: ' + config_dict['user_agent'] + '\r\n' str_options +='\r\n' print(str_options) client=socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.settimeout(config_dict['timeout']) client.connect((hostname, port)) client.send(str_options.encode()) d=client.recv(config_dict['recvbite']) return d
def describe_get(url): ''' describe请求检测 url: rtsp流地址 return: describe请求相应 ''' url=urlparse(url) host=url.netloc hostname=url.hostname path=url.path port=url.port str_describe='DESCRIBE rtsp://' + str(host) + \ path + ' RTSP/1.0\r\n' str_describe +='CSeq: ' + str(config_dict['cseq'] + 1) + '\r\n' str_describe +='User-Agent: ' + config_dict['user_agent'] + '\r\n' str_describe +='\r\n' client=socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.settimeout(config_dict['timeout']) client.connect((hostname, port)) client.send(str_describe.encode()) d=client.recv(config_dict['recvbite']) return d
Def setup_get (url) : "' the setup request test url: RTSP stream address return: setup requests corresponding ' 'url=urlparse (url) host=url.net loc hostname=url. The hostname path=url. The url path port=. Port str_setup=" setup RTSP://"+ STR (host) + path +'/' + 'streamid=0' + 'RTSP/1.0 \ r \ n' str_setup +=" CSeq: "+ STR (config_dict [' CSeq] + 2) + '\ r \ n' str_setup +='the user-agent: + config_dict [' user_agent] +' \ r \ n '# config_dict [' user_agent] str_setup +=' Transport: RTP/AVP; Unicast. Client_port=61740-61741 \ r \ n \ r \ n \ r \ 'str_setup +=' n 'client=socket. The socket (socket. AF_INET, socket. SOCK_STREAM) client. The settimeout (config_dict [' timeout']). Client connect ((hostname, port)) client. Send str_setup. Encode () () d=client. Recv (config_dict [' recvbite ']) return d
def teardown_get(url): ''' teardown请求检测 url: rtsp流地址 return: teardown请求相应 ''' url=urlparse(url) host=url.netloc hostname=url.hostname path=url.path port=url.port str_teardown='TEARDOWN rtsp://' + str(host) + path + ' RTSP/1.0\r\n' str_teardown +='CSeq: ' + str(config_dict['cseq'] + 4) + '\r\n' str_teardown +='User-Agent: ' + config_dict['user_agent'] + '\r\n' str_teardown +='\r\n' print(str_teardown) client=socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.settimeout(config_dict['timeout']) client.connect((hostname, port)) client.send(str_teardown.encode()) d=client.recv(config_dict['recvbite']) return d
Def send_main (url) : try: str_options=STR (options_get (url)) print (str_options) if config_dict [' res_status] in str_options: str_des=STR (describe_get (url)) print (str_des) if config_dict [' res_status] in str_des: str_setup=STR (setup_get (url)) str_teardown=STR (teardown_get (url)) print (str_setup) print (str_teardown) if config_dict [' res_status] in str_teardown: config_dict [' rtsp_status]='true' return true except Exception: return False else: return False
Print (send_main (" RTSP://192.168.10.214:554/live/av0 '))
` ` `

The above code for me,
B 'RTSP/1.0 503 Service Unavailable \ r \ nCSeq: 4 \ r \ nDate: Thu, 01 Jan 1970 07:11:16 GMT \ r \ n \ r \ n' this message for the setup request return information, I've seen RTSP related documents, said the describe request returns the SDP information of the client to analysis the SDP, and for each flow in session to send a RTSP based command (setup), that I don't understand, also don't know how to write, here to consult,
Here is my a normal RTSP interactive information,

` ` `
The OPTIONS RTSP://192.168.10.214:554/live/av0 RTSP/1.0
CSeq: 2
The user-agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)

RTSP/1.0 200 OK
CSeq: 2
Public: OPTIONS, the DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE,

The DESCRIBE RTSP://192.168.10.214:554/live/av0 RTSP/1.0
CSeq: 3
The user-agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)
Accept: application/SDP

RTSP/1.0 200 OK
CSeq: 3
Date: Thu, 01 Jan 1970 07:05:17 GMT
The Content - Base: RTSP://192.168.10.214:554/live/av0/
The content-type: application/SDP
The Content - Length: 315

V=0
O=0 0 IN IP4 127.0.0.1
S=No Title
C=IN IP4 0.0.0.0
T=0 0
A=tool: libavformat 55.12.100
M=0 video RTP/AVP 96
A=rtpmap: 96 H264/90000
A=FMTP: 96 packetization - mode=1; Sprop - parameter - sets=Z2QAKq2EAQwgCGEAQwgCGEAQwgCEK1A8ARPyzcBAQFAAAAMAEAAAAwPIQA==, aO48sA==; Profile - level - id=64002 a
A=control: streamid=0
The SETUP RTSP://192.168.10.214:554/live/av0/streamid=0 RTSP/1.0
CSeq: 4
The user-agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP; Unicast. Client_port=61740-61741

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related