Skip to content

Commit 1cbd8e4

Browse files
committed
Grouped globals by mutability, grouped example code together
1 parent 73b0b2f commit 1cbd8e4

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

rtsp.py

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,13 @@
1111
# Ported to Python3, removed GoodThread
1212
# -killian441
1313

14-
import ast, datetime, re, socket, sys, threading, time, traceback
14+
import ast, datetime, re, socket, threading, time, traceback
1515
from hashlib import md5
1616
try:
1717
from urllib.parse import urlparse
1818
except ImportError:
1919
from urlparse import urlparse # for python < 3.0
2020

21-
DEFAULT_SERVER_PORT = 554
22-
TRANSPORT_TYPE_LIST = []
23-
CLIENT_PORT_RANGE = '10014-10015'
24-
NAT_IP_PORT = ''
25-
ENABLE_ARQ = False
26-
ENABLE_FEC = False
27-
PING = False
28-
2921
TRANSPORT_TYPE_MAP = {
3022
'ts_over_tcp' : 'MP2T/TCP;%s;interleaved=0-1, ',
3123
'rtp_over_tcp' : 'MP2T/RTP/TCP;%s;interleaved=0-1, ',
@@ -35,29 +27,23 @@
3527

3628
RTSP_VERSION = 'RTSP/1.0'
3729
DEFAULT_USERAGENT = 'Python Rtsp Client 1.0'
38-
HEARTBEAT_INTERVAL = 10 # 10s
39-
30+
DEFAULT_SERVER_PORT = 554
4031
END_OF_LINE = '\r\n'
4132
HEADER_END_STR = END_OF_LINE*2
4233

43-
CUR_RANGE = 'npt=end-'
44-
CUR_SCALE = 1
45-
4634
#x-notice in ANNOUNCE, BOS-Begin of Stream, EOS-End of Stream
4735
X_NOTICE_EOS, X_NOTICE_BOS, X_NOTICE_CLOSE = 2101, 2102, 2103
4836

49-
#--------------------------------------------------------------------------
50-
# Colored Output in Console
51-
#--------------------------------------------------------------------------
52-
DEBUG = False
53-
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA,CYAN,WHITE = list(range(90, 98))
54-
def COLOR_STR(msg, color=WHITE):
55-
return '\033[%dm%s\033[0m'%(color, msg)
56-
57-
def PRINT(msg, color=WHITE, out=sys.stdout):
58-
if DEBUG and out.isatty() :
59-
out.write(COLOR_STR(msg, color) + '\n')
60-
#--------------------------------------------------------------------------
37+
#### Variables ####
38+
CUR_RANGE = 'npt=end-'
39+
CUR_SCALE = 1
40+
TRANSPORT_TYPE_LIST = []
41+
NAT_IP_PORT = ''
42+
ENABLE_ARQ = False
43+
ENABLE_FEC = False
44+
PING = False
45+
HEARTBEAT_INTERVAL = 10 # 10s
46+
CLIENT_PORT_RANGE = '10014-10015'
6147

6248
class RTSPError(Exception): pass
6349
class RTSPURLError(RTSPError): pass
@@ -431,7 +417,7 @@ def ping(self, timeout=0.01):
431417
#-----------------------------------------------------------------------
432418
# Input with autocompletion
433419
#-----------------------------------------------------------------------
434-
import readline
420+
import readline, sys
435421
from optparse import OptionParser
436422
COMMANDS = (
437423
'backward',
@@ -455,11 +441,27 @@ def input_cmd():
455441
readline.set_completer_delims(' \t\n')
456442
readline.parse_and_bind("tab: complete")
457443
readline.set_completer(complete)
458-
cmd = input(COLOR_STR('Input Command # ', CYAN))
444+
if(sys.version_info > (3, 0)):
445+
cmd = input(COLOR_STR('Input Command # ', CYAN))
446+
else:
447+
cmd = raw_input(COLOR_STR('Input Command # ', CYAN))
459448
PRINT('') # add one line
460449
return cmd
461450
#-----------------------------------------------------------------------
462451

452+
#--------------------------------------------------------------------------
453+
# Colored Output in Console
454+
#--------------------------------------------------------------------------
455+
DEBUG = False
456+
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA,CYAN,WHITE = list(range(90, 98))
457+
def COLOR_STR(msg, color=WHITE):
458+
return '\033[%dm%s\033[0m'%(color, msg)
459+
460+
def PRINT(msg, color=WHITE, out=sys.stdout):
461+
if DEBUG and out.isatty() :
462+
out.write(COLOR_STR(msg, color) + '\n')
463+
#--------------------------------------------------------------------------
464+
463465
def exec_cmd(rtsp, cmd):
464466
'''Execute the operation according to the command'''
465467
global CUR_RANGE, CUR_SCALE
@@ -489,10 +491,10 @@ def exec_cmd(rtsp, cmd):
489491
if cmd not in ('pause', 'exit', 'teardown', 'help'):
490492
rtsp.do_play(CUR_RANGE, CUR_SCALE)
491493

492-
def main(url, dest_ip):
493-
rtsp = RTSPClient(url, dest_ip, callback=PRINT)
494+
def main(url, options):
495+
rtsp = RTSPClient(url, options.dest_ip, callback=PRINT)
494496

495-
if PING:
497+
if options.ping:
496498
PRINT('PING START', YELLOW)
497499
rtsp.ping()
498500
PRINT('PING DONE', YELLOW)
@@ -562,5 +564,5 @@ def play_ctrl_help():
562564
url = args[0]
563565

564566
DEBUG = True
565-
main(url, options.dest_ip)
567+
main(url, options)
566568
# EOF #

0 commit comments

Comments
 (0)