rtsptools 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/rtsptools.rb +146 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b86ed8e316a052abb7e55d25326be700868c9f0b
|
4
|
+
data.tar.gz: 0dd8b6c307a20b885428265dd54ac590b15acef6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a76271c8d6791eab809385bb545c9c2438ebb97fafc334a236eeef4a0d0a3b4fc34bbe2f131c259fd0ef2968df9175ca95d480cfa41c6d9f1b5d0130716f4781
|
7
|
+
data.tar.gz: f8a946c4898a67135e2bae5b82fc062ec478c8351fc8cf4e4f2e74241c2332c67c3940ac8b4668c53d0360f58f50967dce63e72c3c1312633e65ff764f24c886
|
data/lib/rtsptools.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'uri'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
##
|
6
|
+
# rtsptools is a simple module for testing RTSP media sources.
|
7
|
+
# Initiallly, this is intended to be used by applications that need to
|
8
|
+
# constantly check the status of RTSP media sources, such as IP Cameras.
|
9
|
+
#
|
10
|
+
# Author:: Mario Gasparoni Jr (mailto:mario@mgasp.info)
|
11
|
+
# License:: GNU General Public License 2 (GPL-2.0)
|
12
|
+
module RTSPTools
|
13
|
+
|
14
|
+
##
|
15
|
+
# RTSPConnectionTester is a simple class to test RTSP connectivity.
|
16
|
+
# This was intended to be used by applications that need to constantly
|
17
|
+
# check the status of RTSP media sources, such as IP Cameras.
|
18
|
+
#
|
19
|
+
class RTSPConnectionTester
|
20
|
+
attr_reader :uri, :host, :port, :timeout, :logging #:nodoc:
|
21
|
+
LOG = "[logger] - " #:nodoc:
|
22
|
+
LOG_WARNING = LOG + "WARNING: " #:nodoc:
|
23
|
+
|
24
|
+
#RTSP user agent
|
25
|
+
USER_AGENT = "RTSPConnectionTester-beta" #:nodoc:
|
26
|
+
#Current RTSP version
|
27
|
+
RTSP_VERSION = 1.0 #:nodoc:
|
28
|
+
#RTSP status code OK
|
29
|
+
RTSP_STATUS_CODE_OK = 200 #:nodoc:
|
30
|
+
|
31
|
+
#RTSP Successfull response string
|
32
|
+
RTSP_SUCCESSFULL_RESPONSE_LINE =
|
33
|
+
"RTSP/#{RTSP_VERSION} #{RTSP_STATUS_CODE_OK} OK\r\n" #:nodoc:
|
34
|
+
|
35
|
+
#Default connection timeout
|
36
|
+
DEFAULT_TIMEOUT = 5
|
37
|
+
#Default RTSP port
|
38
|
+
RTSP_DEFAULT_PORT = 554
|
39
|
+
|
40
|
+
## Creates an RTSPConnectionTester instance.
|
41
|
+
# ==== Params
|
42
|
+
#
|
43
|
+
# * +:uri+ - An RTSP URI to be tested
|
44
|
+
# * +:timeout+ - A timeout for connection test
|
45
|
+
# * +:logging+ - Set this flag to enable logging
|
46
|
+
#
|
47
|
+
# === Alternative params
|
48
|
+
#
|
49
|
+
# Instead of passing an RTSP URI, you can pass the following parameters,
|
50
|
+
# for testing port connectivity only
|
51
|
+
# * +:host+ - The media source host
|
52
|
+
# * +:port+ - The media source port
|
53
|
+
def initialize(params = {})
|
54
|
+
@uri = params[:uri]
|
55
|
+
@cseq = 0
|
56
|
+
if @uri
|
57
|
+
@p_uri = URI(@uri)
|
58
|
+
@host = @p_uri.host
|
59
|
+
@port = @p_uri.port || RTSP_DEFAULT_PORT
|
60
|
+
else
|
61
|
+
@host = params[:host]
|
62
|
+
@port = params[:port] || RTSP_DEFAULT_PORT
|
63
|
+
end
|
64
|
+
raise ArgumentError.new("Missing arguments") unless @host
|
65
|
+
@timeout = params[:timeout] || DEFAULT_TIMEOUT
|
66
|
+
@logging = params[:logging]
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Test connectivity against media source..
|
71
|
+
# When deep_check is set, RTSP protocol is check using OPTIONS
|
72
|
+
# message. This method blocks until finishes it test, or timeout
|
73
|
+
# exceeds
|
74
|
+
#
|
75
|
+
# ==== Options
|
76
|
+
#
|
77
|
+
# * +:deep_check+
|
78
|
+
# Set this flag to test connectivity using OPTIONS
|
79
|
+
# message. You must set an RTSP URI to use this option
|
80
|
+
def test_rtsp_connectivity(options = {})
|
81
|
+
@deep_check = options[:deep_check]
|
82
|
+
initialize_socket()
|
83
|
+
begin
|
84
|
+
@socket.connect_nonblock(@saddress)
|
85
|
+
rescue IO::WaitWritable
|
86
|
+
if IO.select([@socket],[@socket],nil,@timeout)
|
87
|
+
begin
|
88
|
+
@socket.connect_nonblock(@saddress)
|
89
|
+
rescue Errno::EISCONN
|
90
|
+
rescue => error
|
91
|
+
@socket.close
|
92
|
+
raise error
|
93
|
+
end
|
94
|
+
else
|
95
|
+
@socket.close
|
96
|
+
raise "Error: connection timed out after #{@timeout} seconds"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
result = true
|
101
|
+
|
102
|
+
if (@deep_check)
|
103
|
+
if (@p_uri)
|
104
|
+
send_options_message()
|
105
|
+
if RTSP_SUCCESSFULL_RESPONSE_LINE != @socket.gets
|
106
|
+
result = false
|
107
|
+
end
|
108
|
+
else
|
109
|
+
if @logging
|
110
|
+
puts LOG_WARNING + "skipping deep_check, since no " \
|
111
|
+
"RTSP uri was given"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
@socket.close
|
117
|
+
return result
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def initialize_socket
|
123
|
+
@socket = Socket.new(Socket::AF_INET,Socket::SOCK_STREAM,0)
|
124
|
+
@saddress = Socket.sockaddr_in(@port,@host)
|
125
|
+
end
|
126
|
+
|
127
|
+
def send_options_message
|
128
|
+
@cseq = @cseq + 1
|
129
|
+
options_message = "OPTIONS #{@uri} RTSP/1.0\r\n" \
|
130
|
+
"CSeq: #{@cseq}\r\n" \
|
131
|
+
"User-Agent: #{USER_AGENT}\r\n"
|
132
|
+
|
133
|
+
if @p_uri.userinfo
|
134
|
+
options_message = options_message +
|
135
|
+
"Authorization: Basic " + Base64.encode64(@p_uri.userinfo) + "\r\n"
|
136
|
+
end
|
137
|
+
|
138
|
+
options_message = options_message + "\r\n"
|
139
|
+
@socket.write(options_message)
|
140
|
+
end
|
141
|
+
|
142
|
+
attr_accessor :socket, :saddress, :cseq, :user_agent
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rtsptools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mario Gasparoni
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-13 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
rtsptools is a simple module for testing RTSP media sources.
|
15
|
+
Initiallly, this is intended to be used by applications that need to
|
16
|
+
constantly check the status of RTSP media sources, such as IP Cameras.
|
17
|
+
email: mariogasparoni@mgmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/rtsptools.rb
|
23
|
+
homepage: https://github.com/mariogasparoni/rtsptools
|
24
|
+
licenses:
|
25
|
+
- GPL-2.0
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.5.1
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: A set of tools for testing RTSP media sources
|
47
|
+
test_files: []
|