Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Overview

New CDN 2.1 implementation includes additional features comparing with CDN 2.0:

  • CDN nodes grouping by geographical (EU, US etc) or another basis
  • CDN nodes can be used for transcoding purposes only by setting Transcoder role to certain nod

CDN nodes grouping

Servers in a CDN can be grouped together by geographical (location), technical (GPU using for transcoding) and anoter basis. CDN group can be assigned to the server with the following parameter in flashphoner.properties file

cdn_groups=group1

 The same server can belong to several groups. For example, server located in Europe and used for transcoding on GPU:

cdn_groups=EU,GPU

CDN groups are used to choose a route for stream playback.

All the servers not assigned to any group are considered to belong to the same group.

Transcoder CDN nodes

In order not to load the servers used for publishing and watching videos in a CDN with transcoding tasks, it is advisable to allocate server with increased computing perfomance for these tasks. For such nodes, in addition to Origin and Edge roles, Transcoder role is added.

cdn_role=transcoder

Transcoder node cannot be used to publish or play streams. This node interacts with Origin and Edge as follows:

1. Stream is published to Origin server

2. Transcoder pulls the stream from Origin server by Edge server request.

3. Transcoder performs stream transcoding by transcoding profile set by Edge server.

4. Edge server pulls the transcoded stream from Transcoder server to play it to subscriber.

The specific node for transcoding is selected when choosing a route for stream playback

Transcoding profiles

To set up transcoding parameters, special profiles are used on Edge server. Transcoding profiles file cdn_profiles.yml should be placed in /usr/local/FlashphonerWebCallServer/conf folder:

profiles:
 
 -webrtc-144:
  audio:
    codec : opus
    rate : 48000
    channels : 2
  video:
    width : 256
    height : 144
    codecImpl : OPENH264

When stream playback is requested, transcoding profile name shoould be added to stream name to transcode this stream, for example

test-webrtc-144

It is recommended to set hyphenated profile names for convinuence.

Profile parameters

ParameterValues availableDescription
Audio parameters
codec

opus

mpeg4-generic

speex

Audio codec to use
bitrateDepends on quality required and bandwith availableAudio bitrate, bps
rate

8000

11025

12000

16000

22050

24000

32000

44100

48000

Audio sample rate, kHz
channels

1

2

Channels quantity: mono or stereo
Video parameters
codec

h264

vp8

Video codec to use
bitrateDepends on quality required and bandwith availableVideo bitrate, kbps
widthDepends on quality required and bandwith availablePicture width
heightDepends on quality required and bandwith availablePicture height
codeImpl

FF

OPENH264

Video codec used: based on FFmpeg or OpenH.264
gopDepends on quality required and bandwith availableKey frames frequency (GOP)
fpsDepends on quality required and bandwith availableFrames frequency per second
qualityDepends on quality required and bandwith availableVideo quality
preset

ultrafast

superfast

veryfast

faster

fast

medium

slow

slower

veryslow

placebo

FFmpeg preset, ultrafast by default
profileDepends on quality requiredFFmpeg profile, Baseline by default
levelDepends on quality requiredFFmpeg level, 3.1 by default

If picture width is not set or equal to 0, video will be scaled by height with aspect ratio preserving.

If both width and height are equal to 0, video will be scaled to resolution 160x120.

FFmpeg parameters management

When using FFmpeg codec, encoding preset, profile and level can be set. For example, the following parameters

 profile1:
  audio:
    codec : opus
    rate : 48000
  video:
    width : 640
    height : 360
    gop : 90
    fps : 30
    codec : h264
    profile : 77
    level : 31
    preset : veryfast

defines veryfast preset usage with Main profile and level 3.1

Picture aspect ratio preserving while stream transcoding by profile

If picture aspect ratio preserving is enabled for all CDN nodes (by default), then stream aspect ratio as published to Origin node will be preserved while transcoding the stream on Transcoder node. For example, if the following profile (16:9) is applied  to 640x480 (4:3) stream

 profile1:
  audio:
    codec : opus
    rate : 48000
  video:
    width : 320
    height : 180
    gop : 90
    fps : 30
    codec : h264

the stream will be transcoded to 320x240 (4:3).

In this case, picture width may be omitted in transcoding profile, because width will be chosen according to picture aspect ratio. For example, the following profile is allowed

 profile3:
  audio:
    codec : opus
    rate : 48000
  video:
    height : 180

When stream is transcoded on Edge server

Stream will be transcoded on Edge under the following conditions:

1. If server video codec priority is higher than profile video codec priority. For example, if the following profile is used

 -opus-vp8:
  audio:
    codec : opus
    rate : 48000
    channels : 2
  video:
    width : 320
    height : 240
    gop : 60
    fps : 30
    codec : vp8
    codecImpl : FF

and the following codec priority is set in server properties

codecs=opus,...,h264,vp8,flv,mpv

then VP8 stream will be transcoded to H264 because this codec has a higher priority.

2. If there is no audio codec or sample rate from profile in subscribers' SDP, audio track will be transcoded to one of formats supported by subscriber.

Choosing a route for stream playback

CDN routes are based on the following periodic data sendings between CDN nodes:

  • Origin sends published streams data to Transcoder and Edge;
  • Transcoder sends pulled streams data to Edge in the same group;
  • Edge sends nothing and is always an end poit of a route.


A route for stream playback on Edge server is chosen as follows:

1. If transcoding profile is set on Edge server:

1.1. If there is the stream with such name on Transcoder node in the same group with Edge:

1.1.1. If the strea, is already transcoded by this profile, Edge pulls the stream from Transcoder

1.1.2. If the stream is transcoded by another profile:

1.1.2.1. Stream will be transcoded by profile set

1.1.2.2. Edge will pull the stream from Transcoder

1.2. If Transcoder that belongs to the same group with Edge can pull the stream with such name from Origin:

1.2.1. Transcoder will pull the stream from Origin

1.2.2. The stream will be transcoded by the profile set.

1.2.3. Edge will pull the stteam from Transcoder

1.3. In other cases, Edge pulls the strea, from Origin

2. If transcoding profile is not set on Edge server, Edge pulls the stream Origin

An example of streams translation via CDN with Transcoder nodes

Where

  • stream1, stream2, stream3 – streams published to Origin server
  • stream1-P1 – stream1 stream transcoded by settings profile P1
  • stream2-P1 – stream1 stream transcoded by settings profile P2

Getting stream routes information with REST API

To get an information about CDN stream routes REST API query /cdn/stream/show_routes is used

REST query should be HTTP/HTTPS POST request as follows:

  • HTTP: http://test.flashphoner.com:8081/rest-api/cdn/stream/show_routes
  • HTTPS: https://test.flashphoner.com:8444/rest-api/cdn/stream/show_routes

Where:

  • test.flashphoner.com - WCS server address
  • 8081 - a standard WCS REST / HTTP port
  • 8444 - a standard WCS HTTPS port
  • rest-api - mandatory part of URL
  • /cdn/stream/show_routes - REST query used

REST queries and responses

REST query

REST query body example

REST response example

Response states

Description

/cdn/stream/show_routes

{
 "streamName":"test-webrtc-144"
}
{
    "REQUESTED-PROFILE": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=256, height=144, gop=null, fps=null, bitrate=0, codec='h264', codecImpl='OPENH264', quality=null}"
    ],
    "1-PROFILE-192.168.1.220": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='null', quality=null}",
        "VIDEO{width=320, height=180, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='FF', quality=null}",
        "VIDEO{width=256, height=144, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='OPENH264', quality=null}"
    ],
    "2-STREAM-192.168.1.220": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='', quality=null}",
        "VIDEO{width=320, height=180, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='FF', quality=null}",
        "VIDEO{width=256, height=144, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='OPENH264', quality=null}"
    ],
    "3-NEW-TRANSCODER-192.168.1.220": [],
    "4-PROXY-192.168.1.219": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='', quality=null}"
    ]
}

200 – OK

500 – Internal Server Error

Show CDN stream routes

Parameters

Description

Example

Stream name (including transcoding profile if necessary)

test-webrtc-144
Transcoding profile requested parameters
Profile requested parameters
REQUESTED-PROFILE
Audio parameters
AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}
Video parameters
VIDEO{width=256, height=144, gop=null, fps=null, bitrate=0, codec='h264', codecImpl='OPENH264', quality=null}
Transcoder stream parameters
Transcoding profiles used by Transcoder parameters
1-PROFILE-192.168.1.220
Stream pulled from Origin by Transcoder parameters
2-STREAM-192.168.1.220
Audio parameters
AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}
Video parameters (according to transcoding profiles used)
VIDEO{width=320, height=180, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='FF', quality=null}
Stream parameters that Transcoder can pull from Origin
3-NEW-TRANSCODER-192.168.1.220
Origin stream parameters
Stream published to Origin parameters
4-PROXY-192.168.1.219
Audio parameters
AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}
Video parameters
VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='', quality=null}

CDN routes checking examples

Let's look how to check some CDN routes build for stream playback.

For example we use three nodes CDN:

  • 192.168.1.219 - Origin
  • 192.168.1.220 - Transcoder
  • 192.168.1.221 - Edge

WebRTC H264+opus (48 kHz, stereo) stream named test is published to Origin

Stream pulling from Origin without transcoding if publishing and playback profiles are equal

Stream named test is played on Edge by profile

 -webrtc-opus-video-proxy:
  audio:
    codec : opus
    rate : 48000
    channels : 2
  video:
    codec: h264

The response to this query

http://192.168.1.221:8081/rest-api/cdn/stream/show_routes
{
    "streamName": "test-webrtc-opus-video-proxy"
}

should be interpreted as follows:

1. Profile requested parameters:

    "REQUESTED-PROFILE": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='h264', codecImpl='null', quality=null}"
    ],

2. Stream is pulled from Origin:

    "1-PROXY-PROFILE-192.168.1.219": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='', quality=null}"
    ],

3. Stream can be pulled from Transcoder

    "2-NEW-TRANSCODER-192.168.1.220": [],

4. But is pulled from Origin because stream publishing parameters are equal to requested playback parameters:

    "3-PROXY-192.168.1.219": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='', quality=null}"
    ]

Stream pulling from Transcoder with audio transcoding

Stream named test is played on Edge by profile

 -webrtc-pcma-video-proxy:
  audio:
    codec : pcma
    rate : 8000
    channels : 1

The response to this query

http://192.168.1.221:8081/rest-api/cdn/stream/show_routes
{
    "streamName": "test-webrtc-pcma-video-proxy"
}

should be interpreted as follows:

1. Profile requested parameters:

    "REQUESTED-PROFILE": [
        "AUDIO{bitrate=0, codec='pcma', rate=8000, channels=1}"
    ],

2. Transcoding profile is created on Transcoder:

    "1-PROFILE-192.168.1.220": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='null', quality=null}",
        "AUDIO{bitrate=0, codec='PCMA', rate=8000, channels=1}"
    ],

3. Stream is pulled from Transcoder

    "2-STREAM-192.168.1.220": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='null', quality=null}",
        "AUDIO{bitrate=0, codec='PCMA', rate=8000, channels=1}"
    ],
    "3-NEW-TRANSCODER-192.168.1.220": [],

4. Stream publishing to Origin parameters:

    "3-PROXY-192.168.1.219": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='', quality=null}"
    ]

Stream pulling from Transcoder with video transcoding

Stream named test is played on Edge by profile

 -opus-vp8:
  audio:
    codec : opus
    rate : 48000
    channels : 2
  video:
    width : 320
    height : 240
    gop : 60
    fps : 30
    codec : vp8
    codecImpl : FF

The response to this query

http://192.168.1.221:8081/rest-api/cdn/stream/show_routes
{
    "streamName": "test-webrtc-opus-vp8"
}

should be interpreted as follows:

1. Profile requested parameters:

    "REQUESTED-PROFILE": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=320, height=240, gop=60, fps=30, bitrate=0, codec='vp8', codecImpl='FF', quality=null}"
    ],

2. Transcoding profile is created on Transcoder:

    "1-PROFILE-192.168.1.220": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='', quality=null}",
        "VIDEO{width=320, height=240, gop=60, fps=30, bitrate=0, codec='VP8', codecImpl='FF', quality=null}"
    ],

3. Stream is pulled from Transcoder

    "2-STREAM-192.168.1.220": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='', quality=null}",
        "VIDEO{width=320, height=240, gop=60, fps=30, bitrate=0, codec='VP8', codecImpl='FF', quality=null}"
    ],
    "3-NEW-TRANSCODER-192.168.1.220": [],

4. Stream publishing to Origin parameters:

    "3-PROXY-192.168.1.219": [
        "AUDIO{bitrate=0, codec='opus', rate=48000, channels=2}",
        "VIDEO{width=0, height=0, gop=null, fps=null, bitrate=0, codec='H264', codecImpl='', quality=null}"
    ]

Transcoder node load balancing

If there are some Transcoder nodes with the same profiles in CDN, those nodes load can be balanced  by CPU load. Maximum allowed load for certain Transcoder can be defined with the following parameter

cdn_node_load_average_threshold=1.0

This value sets average CPU load (JVM SystemLoadAverage parameter) to CPU cores avalable ratio, including hyperthreading cores. When this value is exceeded, the Transcoder node is excluded from route elections for new stteams and profiles. In this case the Transcoder node is displayed in the stream route PROFILE section for profiles the stream is already transcoded by.

Node current state (if node participates in new stream route elections) can be checked with REST API. A node in NEW_STREAMS_ALLOWED state can pull new streams to transcode, a node in GROUP_CONNECTION_ALLOWED state can only push the streams already transcoded.

This parameter should be set on Transcoder nodes. Also this parameter can be set on Origin nodes, in this case their load can be checked via REST API, and if the Origin node become GROUP_CONNECTION_ALLOWED then new streams can be published to another Origin server.

Even Transcoder node load distribution

To distribute streams published to Transcoder nodes evenly, a next available node will be chosen to transcode new stream (Round Robiun algorithm). Stream name caching is used to prevent the same stream requested from couple of clients simultaneously to be spread over a numer of Transcoder nodes. Stream cache timeout is set in milliseconds with the following parameter

cdn_transcoder_for_new_connects_expire_ms=10000

In this case cache timeout is 10 seconds.

This parameter should be set on Transcoder nodes.

Prevent Origin transcoding overload

The following setting is used to prevent Origin nodes from transcoding streams if no Transcoders available

cdn_origin_allowed_to_transcode=false

In this case (by default), if no Trascoders available for new stream by certain profile, this stream will not be played with No available transcoders error.

Transcoding on Origin nodes can be enabled if necessary

cdn_origin_allowed_to_transcode=true

This parameter should be set on Edge nodes.

Node state checking with REST API

To check node state REST API query /cdn/show_nodes is used

REST query should be HTTP/HTTPS POST request as follows:

  • HTTP: http://test.flashphoner.com:8081/rest-api/cdn/show_nodes
  • HTTPS: https://test.flashphoner.com:8444/rest-api/cdn/show_nodes

Where:

  • test.flashphoner.com - WCS server address
  • 8081 - a standard WCS REST / HTTP port
  • 8444 - a standard WCS HTTPS port
  • rest-api - mandatory part of URL
  • /cdn/show_nodes - REST query used

REST queries and responses

REST query

REST query body example

REST response

Response states

Description

/cdn/show_nodes



[
    {
        "globalState": "ACTIVE", 
        "id": "192.168.1.64", 
        "processingState": "NEW_STREAMS_ALLOWED", 
        "role": "TRANSCODER"
    }, 
    {
        "globalState": "ACTIVE", 
        "id": "192.168.1.39", 
        "processingState": "NEW_STREAMS_ALLOWED", 
        "role": "ORIGIN"
    }
]

200 – OK

500 – Internal Server Error

Show CDN nodes state

Parameters

Parameter name

Description

Example

globalState

Node state: ACTIVE or PASSIVE

ACTIVE

id

Node address

192.168.1.64
processingState

If this node participates in stream playback route elections:

NEW_STREAMS_ALLOWED - participates

GROUP_CONNECTION_ALLOWED - not participates

NEW_STREAMS_ALLOWED
roleNode role: ORIGIN, TRANSCODER or EDGE
ORIGIN

REST query /cdn/show_nodes may be sent to certain node, the node responds with all visible CDN nodes state excluding itself.

CDN nodes authentication

Nodes trying to connect to CDN can be authenticated by IP address. Node addresses allowed to connect to CDN should be set in the following parameter

cdn_allowed_ips=192.168.1.39, 192.168.100.64, 192.168.101.65

This parameter can also set address masks, for example

cdn_allowed_ips=192.168.1.39, 192.168.100.1/24

Every CDN node with this setting will only accept CDN connections from nodes whose addresses match those listed, either exactly or by mask. All other CDN connections will be rejected.

Backward compatibility with CDN 2.0

CDN 2.1 backward compatibility with CDN 2.0 is supported in the following cases:

1. Edge 2.0 can pull streams from Origin 2.1

2. Edge 2.1 can pull streams from Origin 2.0

In these cases transcoding works according to codecs and SDP setup as defined for CDN 2.0.

Known limits

1. It is strongly not recommended to publish streams with same name to two Origin servers in the same CDN.

2. A stream published to one of Origin servers should be played on the same Origin server or any Edge server (through Transcoder server if necessary), but should not be played from another Origin server in the same CDN.

  • No labels