rtsp_server 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77b1c4b86a85675da639393964752c3197adf745
4
- data.tar.gz: 55b4a43b06260e899293283b5f2395517f0d4092
3
+ metadata.gz: 151ab5a38e1667cf874f111ee48c7d94743a4b05
4
+ data.tar.gz: fe1958651325fb1ca9321202f4b47c7d276136cf
5
5
  SHA512:
6
- metadata.gz: 88e84cdb94758caa71064a75101bc660094db2eee6542bbe9bc5f52b9f3a4577de135fec7973d70551c98f94c0fa83d74afb00238beb062a4a18cbba348c7d4d
7
- data.tar.gz: e83171aa472d1810dade7ca92a412c323390f9d9f3b1306fd5b7052c9e59dd954e71c7300a6fdfe24d5077617560c7cfa955077dcfbc3d254215ff6fe64c2a19
6
+ metadata.gz: 03c9d9c6038029902871d95ca7e8c6c04e71059b607a6e30d67bbc2569632c27954ed96ed81547d5eb8820f841faf7f31a608c66a33258611a656abd69857dd3
7
+ data.tar.gz: 737f15c8a7cb198e27faedf9a47f72e7e6b30bde6d929773cb91f2ca2a2e7d672ceb47d7b916b9bc51de5fdd4b50b1dac8ae612883083d087fe9caa2fb572d54
data/lib/rtsp/common.rb CHANGED
@@ -145,4 +145,4 @@ module RTSP
145
145
  self.instance_eval "def #{name}; @#{name}; end"
146
146
  end
147
147
  end
148
- end
148
+ end
data/lib/rtsp/server.rb CHANGED
@@ -155,10 +155,11 @@ module RTSP
155
155
  def setup(request)
156
156
  RTSP::Server.log "Received SETUP request from #{request.remote_host}"
157
157
  @session = @session.next
158
+ multicast_check = request.transport.include?('multicast')
158
159
  server_port = @stream_server.setup_streamer(@session,
159
- request.transport_url, request.stream_index)
160
+ request.transport_url, request.stream_index, multicast_check)
160
161
  response = []
161
- transport = generate_transport(request, server_port)
162
+ transport = generate_transport(request, server_port, request.stream_index)
162
163
  response << "Transport: #{transport.join}"
163
164
  response << "Session: #{@session}"
164
165
  response << "\r\n"
@@ -289,13 +290,20 @@ module RTSP
289
290
  #
290
291
  # @param [RTSP::Request] Request object.
291
292
  # @param [Fixnum] server_port Port on which the stream_server is streaming from.
292
- def generate_transport request, server_port
293
- port_specifier = request.transport.include?("unicast") ? "client_port" : "port"
293
+ def generate_transport request, server_port, index=1
294
+ port_specifier = 'client_port'
294
295
  transport = request.transport.split(port_specifier)
295
- transport[0] << "destination=#{request.remote_host};"
296
- transport[0] << "source=#{@stream_server.interface_ip};"
297
296
  transport[1] = port_specifier + transport[1]
298
- transport[1] << ";server_port=#{server_port}-#{server_port+1}"
297
+
298
+ if request.transport.include?("unicast")
299
+ transport[0] << "destination=#{request.remote_host};"
300
+ transport[1] << ";server_port=#{server_port}-#{server_port+1}"
301
+ else
302
+ transport[0] << "destination=#{@stream_server.source_ip[index - 1]};"
303
+ transport[1] << ";ttl=10"
304
+ end
305
+
306
+ transport[0] << "source=#{@stream_server.interface_ip};"
299
307
 
300
308
  transport
301
309
  end
@@ -68,26 +68,34 @@ module RTSP
68
68
  # @param [String] transport_url Destination IP:port.
69
69
  # @param [Fixnum] index Stream index.
70
70
  # @return [Fixnum] The port the streamer will stream on.
71
- def setup_streamer(sid, transport_url, index=1)
71
+ def setup_streamer(sid, transport_url, index=1, multicast=false)
72
72
  dest_ip, dest_port = transport_url.split ":"
73
- @rtcp_source_identifier ||= RTCP_SOURCE.pack("H*")
74
- local_port = free_port(true)
75
-
76
- @rtcp_threads[sid] = Thread.start do
77
- s = UDPSocket.new
78
- s.bind(@interface_ip, local_port+1)
79
73
 
80
- loop do
81
- begin
82
- _, sender = s.recvfrom(36)
83
- s.send(@rtcp_source_identifier, 0, sender[3], sender[1])
74
+ @rtcp_source_identifier ||= RTCP_SOURCE.pack("H*")
75
+ local_port = multicast ? @source_port[index - 1] : free_port(true)
76
+
77
+ unless multicast
78
+ @rtcp_threads[sid] = Thread.start do
79
+ s = UDPSocket.new
80
+ s.bind(@interface_ip, local_port+1)
81
+
82
+ loop do
83
+ begin
84
+ _, sender = s.recvfrom(36)
85
+ s.send(@rtcp_source_identifier, 0, sender[3], sender[1])
86
+ end
84
87
  end
85
88
  end
86
89
  end
87
90
 
88
91
  @cleaner ||= Thread.start { cleanup_defunct }
89
92
  @processes ||= Sys::ProcTable.ps.map { |p| p.cmdline }
90
- @sessions[sid] = build_socat(dest_ip, dest_port, local_port, index)
93
+
94
+ if multicast
95
+ @sessions[sid] = :multicast
96
+ else
97
+ @sessions[sid] = build_socat(dest_ip, dest_port, local_port, index)
98
+ end
91
99
 
92
100
  local_port
93
101
  end
@@ -100,7 +108,7 @@ module RTSP
100
108
  #
101
109
  # @param [String] session ID.
102
110
  def start_streaming sid
103
- spawn_socat(sid, @sessions[sid])
111
+ spawn_socat(sid, @sessions[sid]) unless @sessions[sid] == :multicast
104
112
  end
105
113
 
106
114
  # Stop streaming for the requested session.
@@ -128,15 +136,15 @@ module RTSP
128
136
  v=0\r
129
137
  o=- 1345481255966282 1 IN IP4 #{@interface_ip}\r
130
138
  s=Session streamed by "Streaming Server"\r
131
- i=stream1\r
139
+ i=stream1#{multicast ? 'm' : ''}\r
132
140
  t=0 0\r
133
141
  a=tool:LIVE555 Streaming Media v2007.07.09\r
134
142
  a=type:broadcast\r
135
143
  a=control:*\r
136
144
  a=range:npt=0-\r
137
145
  a=x-qt-text-nam:Session streamed by "Streaming Server"\r
138
- a=x-qt-text-inf:stream1\r
139
- m=video 0 RTP/AVP 96\r
146
+ a=x-qt-text-inf:stream1#{multicast ? 'm' : ''}\r
147
+ m=video #{multicast ? @source_port[stream_index - 1] : 0} RTP/AVP 96\r
140
148
  c=IN IP4 #{multicast ? "#{multicast_ip(stream_index)}/10" : "0.0.0.0"}\r
141
149
  a=rtpmap:#{rtp_map}\r
142
150
  a=fmtp:#{fmtp}\r
@@ -219,7 +227,10 @@ EOF
219
227
 
220
228
  # Disconnects all streams that are currently streaming.
221
229
  def disconnect_all_streams
222
- @pids.values.each { |pid| Process.kill(9, pid.to_i) if pid.to_i > 1000 }
230
+ @pids.values.each do |pid|
231
+ Process.kill(9, pid.to_i) if pid.to_i > 1000 rescue Errno::ESRCH
232
+ end
233
+
223
234
  @sessions.clear
224
235
  @pids.clear
225
236
  end
data/lib/rtsp/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module RTSP
2
2
  # rtsp version
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtsp_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Loveless, Mike Kirby