RTSP Sink

From RidgeRun Developer Connection
Jump to: navigation, search

Overview

RTSP Sink is a GStreamer element which permits high performance streaming to multiple computers using the RTSP / RTP protocols. The rtspsink element leverages previous logic from RidgeRun's RTSP server with extensions to create a GStreamer sink element providing benefits like greater flexibility to application integrate and easy gst-launch based testing.

With RTSP Sink you have the flexibility to stream different content to the same client, such as streaming audio and video to a client. You also can send different streams to different clients. This means that within a single GStreamer pipeline you can stream multiple videos, multiple audios and multiple lip-sync audio+video streams, each one to a different client using a different RTSP mapping. In the examples section different streaming possibilities are shown.

Features

The rtspsink GStreamer element supports the following features:

  • Available for GStreamer-1.0 and Gstreamer-0.10 versions
  • Configurable mappings for each stream. The mapping is the text string used at the end of the RTSP URL: rtsp://$SERVER_IP/$MAPPING
  • Configurable TCP port number
  • Automatic payloader detection according to the negotiated pipeline capabilities
  • Multiple independent video-only streams
  • Multiple independent audio-only streams
  • Multiple independent audio+video streams
  • Support for:
    • H264 video encoding
    • MPEG4 video encoding
    • MJPEG video encoding
    • AAC audio encoding
    • TRANSPORT STREAM A/V encoding
  • Designed for use in embedded products; supports zero-copy pipelines
  • Multicast networking support

The number of simultaneous streams is limited by the hardware capabilities.

Getting the code

RTSP Sink is an add-on to RidgeRun's professional SDK. You can purchase RTSP Sink, with full source code, from the RidgeRun Store.

RidgeRun also makes a binary-only evaluation version available.

Evaluating RTSP Sink

To help you test RTSP Sink, RidgeRun can provide an evaluation version of the plug-in. The following table summarizes the features available in both the professional and evaluation version of the element.

Feature Professional Evaluation
Video Streaming Y Y
Audio Streaming Y Y
A/V Streaming Y Y
Multiple Parallel Streams Y Y
Multiple Encoding Formats Y Y
Unlimited Streaming Time Y N
Source Code Y N

The evaluation version will limit the streaming time of each pad to 5 minutes (at 30fps).

To use the binary provided by RidgeRun, append the following environment variable:

GST_PLUGIN_PATH=$PATH_TO_BINARY_DIRECTORY gst-inspect-1.0 rtspsink
GST_PLUGIN_PATH=$PATH_TO_BINARY_DIRECTORY gst-launch-1.0 ...

Additionally, you may just copy the binary into the standard GStreamer plug-in search path. Refer to the examples section for possible combinations and use cases.

Building the plug-in

Although rtspsink source code is delivered ready to be built along with RidgeRun's SDK, the code is platform independent and can be built on a host PC or other build environment that is configured to build GStreamer plug-ins.

Building rtspsink using RidgeRun SDK

The source code for RTSP sink can be found in

$DEVDIR/proprietary/gst-rtsp-sink

The element will be built along with the SDK if selected on the configuration menu.

make config
 '-> Proprietary software
       '-> [*] RidgeRun RTSP GStreamer sink element
             '-> [] Enable Multicast support


The RTSP Sink can be built manually by:

cd $DEVDIR/proprietary/gst-rtsp-sink
make
make install

Notes:

  • Building the gst-rtsp-sink as a standalone may fail if the package dependencies are not first built properly.
  • Enable the Enable Multicast support option to build the element with multicast support.

Building for a host PC

  • Build the code
cd $DEVDIR/proprietary/rr_rtsp_sink/src # Note the src subdirectory
./autogen.sh
./configure --libdir=/usr/lib/x86_64-linux-gnu/     # GStreamer will look for its plug-ins in this standard location
make
  • Install the plugin
sudo make install                       # You will need root privileges to install the plugin

Note: The default port used by RTSP is 554. Running RTSP Sink on a host PC may require root privileges to open the appropriate sockets (port numbers less than 1024). If the debug reveals a permission problem, then run the pipeline using sudo. You should be able to run GStreamer pipelines with rtspsink if the specified port number is 1024 or greater.

Basic usage

RTSP Sink is a GStreamer element which supports consuming the stream from multiple pipeline branches, each one describing a different media to stream.

Requesting pads

The RTSP Sink pads are requested using regular GStreamer notation. For example, using GStreamer textual pipeline notation, attaching three different h.264 encoded video branches to the sink the pipeline looks like the following:

gst-launch rtspsink name=sink \
< branch 1 > ! sink. \
< branch 2 > ! sink. \
< branch 3 > ! sink. 

Programatically, the pads would be requested as the following:

rtspsinkpad1 = gst_element_get_request_pad(rtspsink, "sink_%d");
gst_pad_link (branch1pad, rtspsinkpad1);
 
rtspsinkpad2 = gst_element_get_request_pad(rtspsink, "sink_%d");
gst_pad_link (branch2pad, rtspsinkpad2);

rtspsinkpad3 = gst_element_get_request_pad(rtspsink, "sink_%d");
gst_pad_link (branch3pad, rtspsinkpad3);

Graphically, the pipeline would look something like:

Rtspsink wiki1.png

Since we didn't specifying the mapping, which is described below, all three pipelines would be mapped to /test.

Combining and naming streams

Each stream needs to be mapped to a different URL so the different clients can access them independently. This is called the mapping of the stream. The RTSP Sink element will try to read the mapping from the caps it negotiates with the upstream element. This means that assigning a mapping to a stream is as simple as setting it in the caps, using the mapping= value. The only rule is that the mapping must always start with a leading slash "/". If no mapping is explicitly provided the it will default to /test.

Each mapping will be treated as an individual stream. This means that if you want to combine an audio and a video branch within a single A/V stream, it is as simple as using the same mapping name. The following pipeline will produce 3 independent streams: a video mapped to "/video", an audio mapped to "/audio" and an audio+video mapped to "/audiovideo".

gst-launch rtspsink name=sink \
< branch 1  > ! capsfilter caps="video/x-h264, mapping=/video" ! sink. \
< branch 2  > ! capsfilter caps="audio/mpeg, mapping=/audio" ! sink. \
< branch 3v > ! capsfilter caps="video/x-h264, mapping=/audiovideo" ! sink. \
< branch 3a > ! capsfilter caps="audio/mpeg, mapping=/audiovideo" ! sink.

This will combine branches 3v and 3a as a single streaming under the name of "/audiovideo". This can be shown graphically on figure 2.

Rtspsink wiki2.png

Supported formats

The following table conveniently summarizes the supported encoding formats and their respective mimetypes for you to build as

gst-launch ... ! mimetype, mapping="/test" ! rtspsink
Supported formats and their mimetypes
Format Mimetype
H264 video video/x-h264
MPEG4 video video/mpeg
MJPEG video image/jpeg
MPEG TS video/mpegts
AAC audio audio/mpeg
TRANSPORT STREAM video/mpegts

Service configuration

RTSP is high level protocol that negotiates streaming internals with every client that intends to connect to a mapping. In order to request a stream, the client must connect to the server at a specific port where the RTSP server is up and waiting for connections. The port at which the server is listening to, and the clients must talk to is called the service and it is typically set to TCP port 554. RTSP Sink allows to configure the service by means of a GStreamer property as follows:

gst-launch audiotestsrc ! ffenc_aac ! capsfilter caps="audio/mpeg, mapping=/mystream" ! rtspsink service=3000

If no service is specified then it default to 554. Since all ports below 1024 require root priority to use, port 554 could cause the pipeline to fail. Specify a port number 1024 or above, i.e. 3000, to run the pipeline at normal user priority. There are other methods that are possible to avoid the need to have root privileges.

Multicast

Multicast property has the ability to send data from a single server to multiple clients without the need of know who will receive the data. To enable multicast mode, the client must set on true, if no multicast is specified then it default to false

Multicast has some properties:

Multicast properties
Properties set name Default value
Multicast multicast false
Minimum address multicast-ip-min 254.2.0.1
Maximum address multicast-ip-man 254.2.0.10
Minimum port multicast-port-min 5000
Maximum port multicast-port-max 5010
TTL multicast-ttl 16

Minimum and maximum address is the address range that multicast can take to connect a single server. If the first address is already use, connect to the next address, that is not in use. Port range has similar function, it has minimum and maximum port, and connect a port in range that is not in use.

Time-to-live 'ttl' property in only available when multicast is set on true, it can takes values in range 0 to 255.

Examples

The following section provides various RTSP Sink use cases. For all of them, the different streams can be viewed on a host PC using VLC as follows:

SERVER_IP=localhost
PORT=554
MAPPING=stream

vlc rtsp://$SERVER_IP:$PORT/$MAPPING

where $SERVER_IP is the IP address of the RTSP server, $MAPPING is the name of the mapping that the client wants to connect to, and $PORT is the service at which the server is listening to.

Single MPEG4 video streaming

gst-launch v4l2src ! ffenc_mpeg4 ! capsfilter caps="video/mpeg, mapping=/stream" ! rtspsink

Single AAC audio streaming

gst-launch alsasrc ! ffenc_aac ! capsfilter caps="audio/mpeg, mapping=/stream" ! rtspsink

Dual H264 video streaming

gst-launch rtspsink name=sink \
v4l2src ! x264enc ! capsfilter caps=""video/x-h264, mapping=/stream1" ! sink.
videotestsrc ! x264enc ! capsfilter caps="video/xh264, mapping=/stream2" ! sink.

Audio+Video Streaming

gst-launch rtspsink name=sink \
v4l2src ! x264enc ! capsfilter caps="video/x-h264, mapping=/stream" ! sink.
alsasrc ! ffenc_aac ! capsfilter caps="audio/mpeg, mapping=/stream" ! sink.

Audio+Video streaming plus H264 single streaming

gst-launch rtspsink name=sink \
v4l2src ! x264enc ! capsfilter caps="video/x-h264, mapping=/stream1" ! sink.
alsasrc ! ffenc_aac ! capsfilter caps="audio/mpeg, mapping=/stream1" ! sink.
videotestsrc ! x264enc ! capsfilter caps="video/x-h264, mapping=stream2" ! sink.

Transport Stream payloader

Often RTSP is used with the RTP payloader encoding. It is also possible to use RTSP with the Transport Stream (TS) payloader. This pipeline was tested on a Leopardboard 368 with an Aptina mt9p031 sensor.

Video test RTSPsink multicast

MULTICAST_SETTINGS= multicast-ip-min=239.255.255.253 multicast-ip-max=239.255.255.255 multicast-port-min=5000 multicast-port-max=6000  multicast-ttl=128

gst-launch-1.0 videotestsrc ! x264enc ! video/x-h264, mapping=/stream1  ! rtspsink\
service=5000 multicast=true $MULTICAST_SETTINGS

Pipeline to run on target hardware

RAW_CAPS='video/x-raw-yuv, width=1920, height=1088, framerate=(fraction)30/1'
ENCODER_SETTINGS='encodingpreset=2 ratecontrol=2 targetbitrate=2000000 intraframeinterval=30 idrinterval=90 bytestream=true'

gst-launch v4l2src input-src=camera always-copy=false ! capsfilter caps=$RAW_CAPS ! dmaiaccel ! dmaiperf ! /
           dmaienc_h264 $ENCODER_SETTINGS ! queue ! mpegtsmux ! capsfilter caps="video/mpegts,mapping=/stream" ! rtspsink

Pipeline to run on host PC

TARGET_IP_ADDRESS=192.168.0.10 # replace with the IP address of your target hardware

gst-launch rtspsrc location="rtsp://$TARGET_IP_ADDRESS/stream" ! rtpmp2tdepay ! mpegtsdemux ! queue ! \
           ffdec_h264 ! xvimagesink sync=false


Using VLC or mplayer to view streaming video

TARGET_IP_ADDRESS=192.168.0.10 # replace with the IP address of your target hardware

vlc rtsp://$TARGET_IP_ADDRESS/stream

mplayer rtsp://$TARGET_IP_ADDRESS/stream

Performance

iMX6

RTSP sink was tested on iMX6 Nitrogen board, with v5640 MIPI camera, using perf you can get CPU load, BPS and FPS, as shown below:

Pipeline

gst-launch-1.0 -e imxfslv4l2src device=/dev/video1 ! videoconvert ! queue ! vpuenc ! "video/x-h264, mapping=/stream1" ! \
perf print-arm-load=true ! rtspsink service=5000 multicast=true
Timestamp: 0:06:06.671329376; Bps: 14060; fps: 25.4; CPU: 1; 
Timestamp: 0:06:07.706948043; Bps: 14494; fps: 25.12; CPU: 2; 
Timestamp: 0:06:08.744248709; Bps: 94080; fps: 25.7; CPU: 1; 
Timestamp: 0:06:09.781531376; Bps: 97170; fps: 25.7; CPU: 0; 
Timestamp: 0:06:10.818393710; Bps: 78921; fps: 25.9; CPU: 3; 
Timestamp: 0:06:11.855817376; Bps: 33416; fps: 25.7; CPU: 0;

Additional documentation

Access the full plugin documentation by making a gst-inspect of the rtspsink

gst-inspect rtspsink

Legacy RTSP Sink

The old version of RTSP Sink maintains the same idea of integrating an RTSP server into a gstreamer pipeline but its developed to support a single video stream. The main difference is that the service is specified by means of a property rather than on the caps.

On target board

gst-launch videotestsrc ! dmaienc_h264 idrinterval=30 targetbitrate=2500000 single-nalu=false ! rtspsink mapping="/mystream" service=554

On host PC

On the host PC you might need to use root privileges to access the respective sockets.

sudo gst-launch videotestsrc ! x264enc ! rtspsink mapping="/mystream" service=554

Client

As an RTSP client vlc may be used as the following:

vlc rtsp://<target.or.host.pc.ip.address>:554/mystream

See also