The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

RTSP::Lite - Lightweight RTSP implementation

SYNOPSIS

  use RTSP::Lite;
  $rtsp = new RTSP::Lite;
  $rtsp->open("192.168.0.1",554);
  $rtsp->method("DESCRIBE");
  $rtsp->request("rtsp://192.168.0.1/realqt.mov");
  $status_code = $rtsp->status();
  $status_message = $rtsp->status_message();
  print "$status_code $status_message\n";
  print $rtsp->body();

DESCRIPTION

RTSP::Lite is a stand-alone lightweight RTSP/1.0 module for Perl. It is based on Roy Hooper's HTTP::Lite (RTSP protocol is very similar to HTTP protocol. I simply modified it to support RTSP).

The main focus of the module is to help you write simple RTSP clients for monitoring and debugging streaming server. So far, full streaming clients that need RTP handling are out of my scope.

The main modifications from the HTTP::Lite 2.1.4 are: + Supports continuous requests. Therefore explicit open operation is now required. + Supports multiple debug level. + Callback function is not supported. + Deletes http style proxy support. Because RTSP requests to proxy are the same style of requests to server.

METHODS

debug ( $level)

Set the debug level. 0: no debug message (default), 1: display all network write and read 2: display all debug message

open ( $host, $port )

Open a connection to $host:$port. $port can be left out.

method ( $method )

Set the method name (OPTIONS, DESCRIBE, PLAY, ...).

add_req_header ( $header, $value )
get_req_header ( $header )
delete_req_header ( $header )

Add, Delete, or get RTSP header(s) for the request.

user_agent( $agent_name)

Set the agent name (Default is "RTSP::Lite 0.1").

request ( $url )

Send a request to the connected host. If an I/O error is encountered, it returns undef, otherwise RTSP status code is returned.

Note: user-agent and cseq headers are automatically added. If user agent header is specified by add_req_header (), it overwrites the user_agent () variable;

body ()

Returns the body of the response.

status ()

Returns the status code received from the RTSP server

status_message ()

Returns the textual description of the status code received from the RTSP server.

headers_array ()

Returns an array of the RTSP headers received from the RTSP server.

headers_string

Returns a string representation of the RTSP headers received from the RTSP server.

get_header ( $header )

Returns an array of values for the received response.

reset ()

You must call this prior to re-using an RTSP::Lite file handle, otherwise the results are undefined.

local_addr ( $ip )
local_port ( $port )

Explicitly select the local IP address (default 0.0.0.0) and the local port (default 0: automatic selected by system).

EXAMPLES

rtsp-request: command line RTSP request tool (http://www.kosho.org/tools/rtsp-request/).

sample scripts that included in the distribution file describe.pl play.pl

SETUP & PLAY sample #!/usr/bin/perl use RTSP::Lite; $url = "rtsp://192.168.0.1/realqt.mov"; $rtsp = new RTSP::Lite; ## open the connection $req = $rtsp->open("192.168.0.1",554) or die "Unable to open: $!";

  ## SETUP
  $rtsp->method("SETUP");
  $rtsp->add_req_header("Transport","RTP/AVP;unicast;client_port=6970-6971");
  $req = $rtsp->request($url."/streamid=0");

  my $se = $rtsp->get_header("Session");
  $session = @$se[0];
  print $rtsp->status_message();
  print_headers();
  ## Play
  $rtsp->reset();
  $rtsp->method("PLAY");
  $rtsp->add_req_header("Session","$session");
  $rtsp->add_req_header("Range","npt=0.000000-5.200000");
  $req = $rtsp->request($url);
  print $rtsp->status_message();
  print_headers();
  ## You will get RTP/RTCP packets, you need to have codes for them.
  exit;
  sub print_headers {
    my @headers = $rtsp->headers_array();
    my $body = $rtsp->body();
    foreach $header (@headers) {
      print "$header\n";
    }
  }

AUTHOR

Masaaki NABESHIMA <http://www.kosho.org/>

SEE ALSO

 RFC 2326 - Real Time Streaming Protocol (RTSP)
 HTTP::Lite module (http://www.thetoybox.org/http-lite/)

ACKNOWLEDGEMENTS

This module is a deviation of HTTP::Lite, maintained by Roy Hooper. Without it this module never exist.

COPYRIGHT

Copyright (c) 2003, Masaaki NABESHIMA. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AVAILABILITY

The latest version of this module is available at: http://www.kosho.org/tools/rtsp-lite/

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 730:

'=item' outside of any '=over'

Around line 803:

You forgot a '=back' before '=head1'