Zynq UltraScale+ MPSoC VCU TRD 2019.2 - SDI Video Capture and SDI Display with PLDDR

Zynq UltraScale+ MPSoC VCU TRD 2019.2 - SDI Video Capture and SDI Display with PLDDR

Table of Contents

1 Overview

The primary goal of this Design is to demonstrate the capabilities of VCU hard block present in Zynq UltraScale+ EV devices. The TRD will serve as a platform to tune the performance parameters of VCU and arrive at optimal configurations for encoder and decoder blocks. 

This design supports the following video interfaces:

Sources:

  • SDI-Rx capture pipeline implemented in the PL.
  • File source (SD card, USB storage, SATA hard disk).
  • Stream-In from network or internet.

Sinks:

  • DP Tx display pipeline in the PS.
  • SDI-Tx display pipeline implemented in the PL.

VCU Codec:

  • Video Encode/Decode capability using VCU hard block in PL 
    • AVC/HEVC encoding.
    • Encoder/decoder parameter configuration.

Streaming Interfaces:

  • 1G Ethernet PS GEM 

Video format:

  • XV20

Audio Configuration:

  • Codec: AAC
  • Format: S24_32LE
  • Channel: 2
  • Sampling rate: 48kHz

Supported Resolution

The table below provides the supported resolution from GUI and command-line app in this design.

Resolution
GUICommand Line
Single StreamSingle Stream
4kp60X
4kp30X
1080p60X

√ - Supported
NA – Not applicable
x – Not supported

The below table gives information about the features supported in this design. 

PipelineInput sourceOutput TypeALSA driversResolutionAudio Codec TypeAudio ConfigurationVideo encode/Decoder type Deliverables
 Record/Stream-Out pipeline SDI-Rx File Sink/ Stream-Out SDI-Rx ALSA drivers 4K/1080p AAC 2 channel @ 48 kHz HEVC/AVCSDI Rx Audio encode with soft codec and video with VCU and store it in a container format.
Playback pipelineFile Source/ Stream-InSDI-TxSDI-Tx ALSA drivers4K/1080pAAC2 channel @ 48 kHzHEVC/AVCPlayback of the local-file/stream-in with video decoded using VCU and Audio using GStreamer soft codec.
Capture--> DisplaySDI-RxSDI-TxSDI-Rx ALSA drivers and SDI-Tx ALSA drivers4K/1080pNA2 channel @ 48 kHzHEVC/AVCSDI-Rx Audio /Video pass to SDI-Tx without VCU/Audio-Codec.
Capture→ Encode--> Decode--> Display SDI-Rx SDI-Tx SDI-Rx ALSA drivers and SDI-Tx ALSA drivers 4K/1080p NA 2 channel @ 48 kHz HEVC/AVCSDI Rx raw audio and video with VCU encoder and decode to achieve AV sync.


The below figure shows the SDI Video Capture and SDI Display with Audio design hardware block diagram.



The below figure shows the SDI Video Capture and SDI Display with Audio design software block diagram.

1.1 Board Setup

Refer below link for board setup


1.2 Run Flow

The TRD package is released with the source code, Vivado project, Petalinux BSP, and SD card image that enables the user to run the demonstration. It also includes the binaries necessary to configure and boot the ZCU106 board. Prior to running the steps mentioned in this wiki page, download the TRD package and extract its contents to a directory referred to as ‘TRD_HOME' which is the home directory.

Refer below link to download all TRD contents.

TRD package contents specific to SDI Video Capture and SDI Display with Audio design are placed in the following directory structure. The user needs to copy all the files from the $TRD_HOME/images/vcu_sdi_xv20 to FAT32 formatted SD card directory.


configuration files(input.cfg) for various Resolutions are placed in the following directory structure in /media/card.

1.2.1 GStreamer Application (vcu_gst_app)

The vcu_gst_app is a command-line multi-threaded Linux application. The command-line application requires an input configuration file (input.cfg) to be provided in the plain text.

Execution of the application is shown below:


Example:

4kp60 HEVC_HIGH Display Pipeline execution

4kp60 HEVC_HIGH Record Pipeline execution

4kp60 HEVC_HIGH Stream-out Pipeline execution

4kp60 HEVC_HIGH Stream-in Pipeline execution

NOTE: Make sure SDI-Rx should be configured to 4kp60 mode.

To measure the latency of the pipeline, run the below command. The latency data is huge, so dump it to a file.

Refer below link for detailed run flow steps

1.3 Build Flow

Refer below link for build flow




2 Other Information

2.1 Known Issues

2.2 Limitations

2.3 Optimum VCU Encoder parameters for use-cases:

Video streaming:

  • Video streaming use-case requires a very stable bitrate graph for all pictures.
  • It is good to avoid periodic large Intra pictures during the encoding session
  • Low-latency rate control (hardware RC) is the preferred control-rate for video streaming, it tries to maintain equal amount frame sizes for all pictures.
  • Good to avoid periodic Intra frames instead use low-delay-p (IPPPPP…)
  • VBR is not a preferred mode of streaming.

Performance: AVC Encoder settings:

  • It is preferred to use 8 or higher slices for better AVC encoder performance.
  • AVC standard does not support Tile mode processing which results in the processing of MB rows sequentially for entropy coding.

Quality: Low bitrate AVC encoding:

  • Enable profile=high and use qp-mode=auto for low-bitrate encoding use-cases.
  • The high profile enables 8x8 transform which results in better video quality at low bitrates.

2.4 Audio-Video Synchronization

Clocks and synchronization in GStreamer

When playing complex media, each sound and video sample must be played in a specific order at a specific time. For this purpose, GStreamer provides a synchronization mechanism.

GStreamer provides support for the following use cases:

  • Non-live sources with access faster than playback rate. This is the case where one is reading media from a file and playing it back in a synchronized fashion. In this case, multiple streams need to be synchronized, like audio, video and subtitles.
  • Capture and synchronized muxing/mixing of media from multiple live sources. This is a typical use case where you record audio and video from a microphone/camera and mux it into a file for storage.
  • Streaming from (slow) network streams with buffering. This is the typical web streaming case where you access content from a streaming server using HTTP.
  • Capture from live source and playback with configurable latency. This is used, for example, when capturing from a camera, applying an effect and displaying the result. It is also used when streaming low latency content over a network with UDP.
  • Simultaneous live capture and playback from prerecorded content. This is used in audio recording cases where you play a previously recorded audio and record new samples, the purpose is to have the new audio perfectly in sync with the previously recorded data.

GStreamer uses a GstClock object, buffer timestamps and a SEGMENT event to synchronize streams in a pipeline as we will see in the next sections.

Clock running-time

In a typical computer, there are many sources that can be used as a time source, e.g., the system time, soundcards, CPU performance counters, etc. For this reason, GStreamer has many GstClock implementations available. Note that clock time doesn't have to start from 0 or any other known value. Some clocks start counting from a particular start date, others from the last reboot, etc.

A GstClock returns the absolute-time according to that clock with gst_clock_get_time (). The absolute-time (or clock time) of a clock is monotonically increasing.

running-time is the difference between a previous snapshot of the absolute-time called the base-time, and any other absolute-time.

running-time = absolute-time - base-time

A GStreamer GstPipeline object maintains a GstClock object and a base-time when it goes to the PLAYING state. The pipeline gives a handle to the selected GstClock to each element in the pipeline along with selected base-time. The pipeline will select a base-time in such a way that the running-time reflects the total time spent in the PLAYING state. As a result, when the pipeline is PAUSED, the running-time stands still.

Because all objects in the pipeline have the same clock and base-time, they can thus all calculate the running-time according to the pipeline clock.

Buffer running-time

To calculate a buffer running-time, we need a buffer timestamp and the SEGMENT event that preceded the buffer. First we can convert the SEGMENT event into a GstSegment object and then we can use the gst_segment_to_running_time () function to perform the calculation of the buffer running-time.

Synchronization is now a matter of making sure that a buffer with a certain running-time is played when the clock reaches the same running-time. Usually, this task is performed by sink elements. These elements also have to take into account the configured pipeline's latency and add it to the buffer running-time before synchronizing to the pipeline clock.

Non-live sources timestamp buffers with a running-time starting from 0. After a flushing seek, they will produce buffers again from a running-time of 0.

Live sources need to timestamp buffers with a running-time matching the pipeline running-time when the first byte of the buffer was captured.

Buffer stream-time

The buffer stream-time, also known as the position in the stream, is a value between 0 and the total duration of the media and it's calculated from the buffer timestamps and the preceding SEGMENT event.

The stream-time is used in:

  • Report the current position in the stream with the POSITION query.
  • The position used in the seek events and queries.
  • The position used to synchronize controlled values.

The stream-time is never used to synchronize streams, this is only done with the running-time.

Time overview

Here is an overview of the various timelines used in GStreamer.

The image below represents the different times in the pipeline when playing a 100ms sample and repeating the part between 50ms and 100ms.

You can see how the running-time of a buffer always increments monotonically along with the clock-time. Buffers are played when their running-time is equal to the clock-time - base-time. The stream-time represents the position in the stream and jumps backwards when repeating.

Clock providers

A clock provider is an element in the pipeline that can provide a GstClock object. The clock object needs to report an absolute-time that is monotonically increasing when the element is in the PLAYING state. It is allowed to pause the clock while the element is PAUSED.

Clock providers exist because they play back media at some rate, and this rate is not necessarily the same as the system clock rate. For example, a soundcard may play back at 44.1 kHz, but that doesn't mean that after exactly 1 second according to the system clock, the soundcard has played back 44100 samples. This is only true by approximation. In fact, the audio device has an internal clock based on the number of samples played that we can expose.

If an element with an internal clock needs to synchronize, it needs to estimate when a time according to the pipeline clock will take place according to the internal clock. To estimate this, it needs to slave its clock to the pipeline clock.

If the pipeline clock is exactly the internal clock of an element, the element can skip the slaving step and directly use the pipeline clock to schedule playback. This can be both faster and more accurate. Therefore, generally, elements with an internal clock like audio input or output devices will be a clock provider for the pipeline.

When the pipeline goes to the PLAYING state, it will go over all elements in the pipeline from sink to source and ask each element if they can provide a clock. The last element that can provide a clock will be used as the clock provider in the pipeline. This algorithm prefers a clock from an audio sink in a typical playback pipeline and a clock from source elements in a typical capture pipeline.

There exist some bus messages to let you know about the clock and clock providers in the pipeline. You can see what clock is selected in the pipeline by looking at the NEW_CLOCK message on the bus. When a clock provider is removed from the pipeline, a CLOCK_LOST message is posted and the application should go to PAUSED and back to PLAYING to select a new clock.

For more detail please refer: https://gstreamer.freedesktop.org/documentation/application-development/advanced/clocks.html?gi-language=c


3 Appendix A - Input Configuration File (input.cfg)

The example configuration files are stored at /media/card/config/ folder.

Common Configuration:
It is the starting point of common configuration.

Num of Input:
Provide the number of inputs. This is always 1 for this design.

Output:
Select the video interface.
Options: SDI or DP

Out Type:
Options: display, record, and stream

Display Rate:
Pipeline frame rate.
Options: 30 FPS or 60 FPS for each stream.

Exit:
It indicates to the application that the configuration is over.

Input Configuration:
It is the starting point of the input configuration.

Input Num:
Starting Nth input configuration.
Options: 1

Input Type:
Input source type.
Options: SDI, File, Stream

Uri:
File path or Network URL. Applicable for file playback and Stream-in pipeline only. Supported file formats for playback are ts, mp4, and mkv.
Options: file:///media/usb/abc.ts (for file path), udp://192.168.25.89:5004/ (for Network streaming, Here 192.168.25.89 is IP address and 5004 is port no)

Raw:
To tell the pipeline is processed or pass-through.
Options: True, False

Width:
The width of the live source.
Options: 3840, 1920

Height:
The height of the live source.
Options: 2160, 1080

Exit:
It indicates to the application that the configuration is over.

Encoder Configuration:
It is the starting point of encoder configuration.

Encoder Num:
Starting Nth encoder configuration.
Options: 1.

Encoder Name:
Name of the encoder.
Options: AVC, HEVC

Profile:
Name of the profile.
Options: baseline, main or high for AVC. Main for HEVC.

Rate Control:
Rate control options.
Options: CBR, VBR, and low-latency.

Filler Data:
Filler Data NAL units for CBR rate control.
Options: True, False

QP:
QP control mode used by the VCU encoder.
Options: Uniform or Auto

L2 Cache:
Enable or Disable L2Cache buffer in encoding process.
Options: True, False

Latency Mode:
Encoder latency mode.
Options: normal, sub_frame

Low Bandwidth:
If enabled, decrease the vertical search range used for P-frame motion estimation to reduce the bandwidth.
Options: True, False

Gop Mode:
Group of Pictures mode.
Options: Basic, low_delay_p, low_delay_b

Bitrate:
Target bitrate in Kbps
Options: 1-60000

B Frames:
Number of B-frames between two consecutive P-frames
Options: 0-4

Slice:
The number of slices produced for each frame. Each slice contains one or more complete macroblock/CTU row(s). Slices are distributed over the frame as regularly as possible. If slice-size is defined as well more slices may be produced to fit the slice-size requirement
Options:
4-22 4kp resolution with HEVC codec
4-32 4kp resolution with AVC codec
4-32 1080p resolution with HEVC codec
4-32 1080p resolution with AVC codec

GoP Length:
The distance between two consecutive I frames
Options: 1-1000

Format:
The format of input data is  XV20

Preset:
Options: HEVC_HIGH, HEVC_MEDIUM, HEVC_LOW, AVC_HIGH, AVC_MEDIUM, AVC_LOW, Custom

Exit
It indicates to the application that the configuration is over.

Record Configuration:
It is the starting point of record configuration.

Record Num:
Starting Nth record configuration.
Options: 1

Out File Name:
Record file path.
Options: /media/usb/abc.ts

Duration:
Duration in minutes.
Options: 1-3

Exit
It indicates to the application that the configuration is over.

Streaming Configuration:
It is the starting point of streaming configuration.

Streaming Num:
Starting Nth Streaming configuration.
Options: 1.

Host IP:
The host to send the packets to
Options: 192.168.25.89 or Windows PC IP.

Port:
The port to send the packets to
Options: 5004,5008,5012 and 5016.

Exit
It indicates to the application that the configuration is over.


Audio Configuration:

It is the starting point of the audio configuration.


Audio Enable:

Enable or Disable audio in pipeline.

Options: True, False.


Audio Format:

The format of the audio.

Options: S24_32LE.


Sampling Rate:

To set the audio sampling rate.

Options: 48000.


Num Of Channel:

The number of audio channels.

Options: 2.


Volume:

To set the volume level. The default value is 2.0.

Options: 0.0-10.0.


Exit

It indicates to the application that the configuration is over.



Trace Configuration:
It is the starting point of trace configuration.

FPS Info:
To display fps info on the console.
Options: True, False

APM Info:
To display the APM counter number on the console.
Options: True, False

Pipeline Info:
To display pipeline info on console.
Options: True, False

Exit
It indicates to the application that the configuration is over.


4 Appendix B SDI Link Status

Run the below command to check the SDI link status and output format of the SDI input source. Run the below command for all media nodes to print media device topology where "mediaX" represents different media nodes. In the topology, log look for the “v_smpte_uhdsdi_rx_ss” string to identify the SDI input source media node.

NOTE: Check resolution and frame-rate of "v_smpte_uhdsdi_rx_ss" node.

When SDI source is connected to 4KP60 resolution, it shows:

NOTE: Check resolution and frame-rate of "dv.detect" under "v_smpte_uhdsdi_rx_ss" node.

When the SDI source is not connected, it shows:

NOTE: Check resolution and frame-rate of "v_smpte_uhdsdi_rx_ss" node.

Notes for modetest commands:

  • Modetest command for 4kp60 Display
  • Modetest command for 4kp30 Display
  • Modetest command for 1080p60 Display


  • Follow the below steps to switch the SDI-Rx resolution from 1080p60 to 4kp60.
    • Check current SDI Input Source Resolution (1080p60) by following the above-mentioned steps.
    • Run vcu_gst_app for current SDI resolution (1080p60) by executing the following command.

Below configurations needs to be set in input.cfg for SDI-1080p60.

    • Change Resolution of SDI Input Source from 1080p60 to 4kp60 by following the below steps.
      • Set the SDI source resolution to 4kp60 (Home page → settings → display & Sound → Resolution → change to 4kp60).
      • Save the configuration to take place the change.
    • Verify desired SDI Input Source Resolution (4kp60) by following the above-mentioned steps.
  • Run the following gst-launch-1.0 command to display raw SDI video using the GStreamer pipeline.
  • Run the following gst-launch-1.0 command to display processed(capture → encode → decode → display) SDI video using the GStreamer pipeline.
  • Run the following gst-launch-1.0 command to record SDI video using the GStreamer pipeline.

NOTE: File location should be USB-3.0 to avoid the read-write bandwidth issue.

  • Run the following gst-launch-1.0 command to play the recorded file using the GStreamer pipeline.

NOTE: File location should be USB-3.0 to avoid the read-write bandwidth issue.

  • Run the following gst-launch-1.0 command to stream-out SDI video using the GStreamer pipeline.

NOTE: Here 192.168.25.89 is host/client IP address and 5004 is port no.

  • Run the following gst-launch-1.0 command to display stream-in video using the Gstreamer pipeline where 5004 is port no.

Note: Low latency stream-in pipeline cannot be launched with vcu-gst-app. Hence use below gst-launch pipelines.

  • Run the following gst-launch-1.0 command for low-latency stream-out pipeline. 

NOTE:Here 192.168.25.89 is host/client IP address and 5004 is port no.

  • Run the following gst-launch-1.0 command to display low-latency stream-in on SDI-Tx video using the Gstreamer pipeline where 5004 is port no.

Commands to run interlaced mode