Class: RTSP::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/rtsp/session.rb

Overview

Because RTSP does not use a persistent connection to communicate over, it must maintain state of its streams and the clients using them via different means; it uses sessions for this. This differs from HTTP, which is a stateless protocol.

The RFC describes this as:

A complete RTSP "transaction", e.g., the viewing of a movie.  A session
typically consists of a client setting up a transport mechanism for the
continuous media stream (SETUP), starting the stream with PLAY or RECORD,
and closing the stream with TEARDOWN.

Objects of this type are used by RTSP::Servers and RTSP::Clients to keep track of their session state and manage the resources associated to them.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Session

Returns a new instance of Session.

Parameters:

  • stream (RTSP::Stream)


41
42
43
44
45
# File 'lib/rtsp/session.rb', line 41

def initialize(stream)
  @stream = stream
  @session_id = Time.now.to_ntp
  @state = :init
end

Instance Attribute Details

#session_idObject (readonly)

The identifier that labels this session.



23
24
25
# File 'lib/rtsp/session.rb', line 23

def session_id
  @session_id
end

#stateObject

A session’s state indicates where it’s at in the process of sending or receiving a stream. Can be:

  • :init

    • “The initial state, no valid SETUP has been received yet.”

  • :ready

    • “Last SETUP received was successful, reply sent or after playing, last PAUSE received was successful, reply sent.”“

  • :playing

    • “Last PLAY received was successful, reply sent. Data is being sent.

  • :recording

    • “The server is recording media data.”



38
39
40
# File 'lib/rtsp/session.rb', line 38

def state
  @state
end

#streamObject (readonly)

Returns the value of attribute stream.



25
26
27
# File 'lib/rtsp/session.rb', line 25

def stream
  @stream
end

Instance Method Details

#playObject



57
58
59
60
61
62
63
# File 'lib/rtsp/session.rb', line 57

def play
  unless @state == :ready
    return false
  end

  @stream.rtp_sender.start_streaming
end

#setup(broadcast_type, send_on_port) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/rtsp/session.rb', line 47

def setup(broadcast_type, send_on_port)
  if @state == :init
    @state = :ready
  end

  @stream.broadcast_type = broadcast_type
  @stream.client_rtp_port = send_on_port
  @stream.rtp_sender.setup_streamer
end