Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Parameter

Default value

Type

Description

cdn_enabled

false

Boolean

Enable/disable CDN

cdn_ip

Empty

String

Server address in CDN

cdn_nodes_resolve_ip

false

Boolean

Resolve server names to IP addresses

cdn_point_of_enryentry

Empty

String

Address of the server, the entry point to CDN for the given server. If the server is Origin, this parameter should not be set to this servers' IP address or hostname

cdn_port

8084

Int

Port number for CDN

cdn_role

edge

String

Role of the server in CDN:

origin - source of streams for other servers in CDN

edge - can receive streams from other servers

...

Obtaining information about the current status of CDN from the WCS command line is performed with these commands:

Command

Description

Example result

show cdn-nodes

Displays the list of node servers in CDN:

ACTIVE - the server is running, responds to queries and/or sends notifications

PASSIVE - the server is stopped or unavailable

Code Block
languagebash
themeRDark
IIp                       State        
---------------------------------
edge1.flashphoner.com    ACTIVE   
edge2.flashphoner.com    ACTIVE   
origin2.flashphoner.com  PASSIVE

show cdn-routes

Shows the list of active streams in CDN

Code Block
languagebash
themeRDark
Route                       Stream     
------------------------------------
1-origin2.flashphoner.com-2 stream1
0-origin2.flashphoner.com-0 stream2
2-origin1.flashphoner.com-1 stream1

Removing stopped servers from CDN nodes list

By default, when server is stopped or unavailable, it will be displayed in CDN nodes list in PASSIVE state until it will be started again or all the CDN will be stopped. The time interval may be set if necessary to remove inactive node from nodes list. This interval should be set in seconds using the following parameter in flashphoner.properties file, for example

Code Block
languagebash
themeRDark
cdn_nodes_timeout=60

In this case inactive nodes will be removed from CDN nodes list after 60 seconds of inactivity.

Coordination of codecs on Origin and Edge servers

In order to avoid excessive transcoding when distributing streams, you need to coordinate codec settings on Origin and Edge servers. Let's take a look at three possible sound encoding configurations in the CDN intended to distribute a stream from the web camera and the RTMP encoder.

Using Opus or AAC

Image Removed

1. Distributing a stream captured from browser Chrome

1.1. Origin captures H.264+Opus stream from Chrome.
1.2. Edge pulls stream from Origin via WebRTС using H.264+Opus, there's no transcoding on Origin.
1.3. Subscriber pulls stream from Edge:
1.3.1. using H.264+Opus, there's no transcoding on Origin;
1.3.2. using H.264+AAC, there is transcoding Opus > AAC on Edge.

2. Distributing a stream captured from RTMP encoder

2.1. Origin captures H.264 stream from RTMP encoder:
2.1.1 AAC sound without transcoding:
2.1.2 Speex soind with transcoding to AAC.
2.2. Edge pulls stream from Origin via WebRTС using H.264+AAC.
2.3. Subscriber pulls stream from Edge:
2.3.1. using H.264+Opus, there is transcoding AAC > Opus Edge;
2.3.2. using H.264+AAC, there's no transcoding on Edge.

For this CDN to work, codecs should be configures as follows:

on Origin server

flash_handler_publish.sdp file should be created

Code Block
themeRDark
v=0
o=- 1988962254 1988962254 IN IP4 0.0.0.0
c=IN IP4 0.0.0.0
t=0 0
a=sdplang:en
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 profile-level-id=42e01f;packetization-mode=1
a=sendonly
m=audio 0 RTP/AVP 108
a=rtpmap:108 mpeg4-generic/48000/1
a=sendonly

on Edge server

this parameter shuold be set in flashphoner.properties file

Code Block
languagebash
themeRDark
codecs_exclude_cdn=alaw,ulaw,g729,speex16,g722,telephone-event,flv

and flash_handler_play.sdp file should be created

...

themeRDark

...

Using REST API

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

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

Where:

  • test.flashphoner.com - is the address of the WCS server
  • 8081 - is the standard REST / HTTP port of the WCS server
  • 8444 - is the standard HTTPS port
  • rest-api - is the required part of the URL
  • /cdn/show_routes - REST-method to use

REST queries and response statuses

REST query

REST query example

REST response example

Response states

Description

/cdn/show_routes


Code Block
languagejs
themeRDark
{
 "1-origin2.flashphoner.com-2": "stream1",
 "0-origin2.flashphoner.com-0": "stream2",
 "2-origin1.flashphoner.com-1": "stream1"
}

200 – OK

500 – Internal Server Error

Show active CDN routes

Parameters

Description

Example

Route identifier

1-origin2.flashphoner.com-2

Stream name in CDN

stream1

Removing stopped servers from CDN nodes list

By default, when server is stopped or unavailable, it will be displayed in CDN nodes list in PASSIVE state until it will be started again or all the CDN will be stopped. The time interval may be set if necessary to remove inactive node from nodes list. This interval should be set in seconds using the following parameter in flashphoner.properties file, for example

Code Block
languagebash
themeRDark
cdn_nodes_timeout=60

In this case inactive nodes will be removed from CDN nodes list after 60 seconds of inactivity.

Choosing audio codecs for stream forwarding through CDN

Forwarding audio through CDN

When forwarding audio through CDN, a set of available codecs is formed with the

  • codec used to publish stream (as preferred), and
  • codecs supported on Origin and Edge servers (codecs setting in flashphoner.properties file) 

excluding codecs listed in codecs_exclude_cdn setting on Edge.

By default, if AAC is not excluded, the following AAC sample rates are defined in SDP: 48, 44.1, 32, 24, 22.05, 16, 12, 8 kHz.

For example, if Edge requests from Origin RTMP stteam published with AAC 48 kHZ, audio SDP will be following

Code Block
themeRDark
m=audio 31006 RTP/SAVPF 102 111 8 18 100 9 103 104 105 106 107 108 109 110
c=IN IP4 192.168.1.5
a=mid:1
a=rtpmap:102 mpeg4-generic/48000/2
a=rtpmap:111 opus/48000/2
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:100 speex/16000
a=rtpmap:9 G722/8000
a=rtpmap:103 mpeg4-generic/44100/2
a=rtpmap:104 mpeg4-generic/32000/2
a=rtpmap:105 mpeg4-generic/24000/2
a=rtpmap:106 mpeg4-generic/22050/2
a=rtpmap:107 mpeg4-generic/16000/2
a=rtpmap:108 mpeg4-generic/4800012000/12
a=recvonly

Using Opus only

Image Removed

1. Distributing a stream captured from browser Chrome

1.1. Origin captures H.264+Opus stream from Chrome.
1.2. Edge pulls H.264+Opus stream from Origin via WebRTC, there's no transcoding on Origin.
1.3. Subscriber pulls H.264+Opus stream from Edge, there's no transcoding on Edge.

2. Distributing a stream captured from RTMP encoder

2.1. Origin captures H.264 stream from RTMP encoder:
2.1.1 AAC sound with transcoding to Opus:
2.1.2 Speex sound with transcoding to Opus.
2.2. Edge pulls H.264+Opus stream from Origin via WebRTC.
2.3. Subscriber pulls H.264+Opus stream from Edge, there's no transcoding on Edge.

For this CDN to work, codecs should be configures as follows:

on Origin server

codecs setting should be default

on Edge server

this parameter shuold be set in flashphoner.properties file

Code Block
languagebash
themeRDark
codecs_exclude_cdn=alaw,ulaw,g729,speex16,g722,mpeg4-generic,telephone-event,flv

Using AAC only

Image Removed

1. Distributing a stream captured from browser Chrome

1.1. Origin captures H.264+Opus stream from Chrome with transcoding Opus > AAC.
1.2. Edge pulls H.264+AAC stream from Origin via WebRTС.
1.3. Subscriber pulls H.264+AAC stream from Edge, there's no transcoding on Edge.

2. Distributing a stream captured from RTMP encoder

2.1. Origin captures H.264 stream from RTMP encoder:
2.1.1 AAC sound without transcoding:
2.1.2 Speex sound with transcoding to AAC.
2.2. Edge pulls H.264+AAC stream from Origin via WebRTС.
2.3. Subscriber pulls H.264+AAC stream from Edge, there's no transcoding on Edge.

For this CDN to work, codecs should be configures as follows:

on Origin server

flash_handler_publish.sdp file should be created

Code Block
themeRDark
v=0
o=- 1988962254 1988962254 IN IP4 0.0.0.0
c=IN IP4 0.0.0.0
t=0 0
a=sdplang:en
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 profile-level-id=42e01f;packetization-mode=1
a=sendonly
m=audio 0 RTP/AVP 108
a=rtpmap:108 mpeg4-generic/48000/1
a=sendonly

on Edge server

this parameter shuold be set in flashphoner.properties file

Code Block
languagebash
themeRDark
codecs_exclude_cdn=opus,alaw,ulaw,g729,speex16,g722,telephone-event,flv

Quick manual on testing

1. For testing we use:

  • two WCS servers;
  • the Two Way Streaming web application to publish the stream;
  • the Player web application to play the stream.

Configuring WCS

2. For the test, configure CDN in the minimum configuration: one Origin and one Edge server

Origin settings:

Code Block
languagebash
themeRDark
cdn_enabled=true
cdn_nodes_resolve_ip=true
cdn_ip=origin.flashphoner.com
cdn_role=origin

Edge settings:

Code Block
languagebash
themeRDark
cdn_enabled=true
cdn_nodes_resolve_ip=true
cdn_point_of_entry=origin.flashphoner.com
cdn_ip=edge.flashphoner.com
cdn_role=edge

Here origin.flashphoner.com and edge.flashphoner.com - are examples names of the WCS servers.

Restart Origin and Edge servers. Enter the command line interface of the Edge server, authorize and enter this command

Code Block
languagebash
themeRDark
show cdn-nodes

...

rtpmap:109 mpeg4-generic/11025/2
a=rtpmap:110 mpeg4-generic/8000/2

PCMU is not available by default and will be enabled only when PCMA is excluded:

Code Block
languagebash
themeRDark
codecs_exclude_cdn=alaw

Custom SDP settings for RTMP (flash_handler_publish.sdp and flash_handler_play.sdp) does not affect SDP for sound forwarding through CDN.

With the default settings, transcoding will not occur, for example, in the following cases.:

  • WebRTC (Opus) stream published on Origin is played as WebRTC on Edge (Opus)
  • RTMP (AAC, any of sample rates listed above) stream published on Origin is played as RTMP on Edge (AAC with the same sample rate without resampling)
  • RTMP (Speex) stream published on Origin is played as RTMP on Edge (Speex)

If there is no codec used to publish a stream in the subscribers codecs set, then transcoding will be on Edge server:

  • WebRTC (Opus) stream published on Origin is played as RTMP on Edge (AAC): Opus-AAC transcoding on Edge
  • RTMP (AAC stream published on Origin is played as WebRTC on Edge (Opus): AAC-Opus transcoding on Edge
  • RTMP (Speex) stream published on Origin is played as WebRTC on Edge (Opus): Speex-Opus transcoding on Edge
  • RTMP (Speex) stream published on Origin is played as RTMP on Edge (AAC): Speex-AAC transcoding on Edge

If the subscribers codecs set includes no only AAC, then Speex for example may be used to playback RTMP as RTMP without transcoding.

Image Added

If the subscribers codecs set is limited to AAC only (flash_handler_play.sdp on Edge includes AAC only), then transcoding will be on Edge if another codec is used to publish RTMP stream:

Image Added

To exclude codecs while stream forwarding trough CDN, to escape transcoding on Edge server,codecs_exclude_cdn setting should be used on Edge. Then the only remaining codec will be used to forward a stream trough CDN, and if stream is published with another codec transcoding will be on Origin server.

For example, if supposed to be connected to Edge

1. RTMP subscribers with AAC only: all the codecs should be excluded except mpeg4-generic:

Code Block
languagebash
themeRDark
codecs_exclude_cdn=opus,alaw,ulaw,g729,speex16,g722,telephone-event,flv

Image Added

2. WebRTC subscribers with Opus only:  all the codecs should be excluded except opus:

Code Block
languagebash
themeRDark
codecs_exclude_cdn=mpeg4-generic,alaw,ulaw,g729,speex16,g722,telephone-event,flv

Image Added

Custom SDP setting to publish and play RTMP stream in CDN

flash_handler_publish.sdp

flash_handler_publish.sdp is used as publish SDP when subscriber connects to stream before WCS get audio and video from publishing client (i.e. before the real codec used by publisher is known).

In this case codecs priority will be determined in order set in flash_handler_publish.sdp. If there is no flash_handler_publish.sdp, then the default priority audio codec will be Speex.

For example, with default settings (without flash_handler_publish.sdp), when RTMP (AAC) stream published on Origin is played as WebRTC (Opus) on Edge through CDN

  • if subscriber connects after receiving audio from publisher (i.e. it is known that AAC is used): AAC-Opus transcoding on Edge
  • if subscriber connects before receiving audio from publisher (i.e. default Speex is used): AAC-Speex transcoding on Origin and Speex-Opus transcoding on Edge

If Origin has flash_handler_publish.sdp, in which AAC is set as first for example, then AAC will be used including the case when subscriber connects before receiving audio from publisher. Thus, if publication codec is known in advance then additional transcoding can be escaped by setting a codec in flash_handler_publish.sdp.

flash_handler_publish.sdp is not used to restrict publication codecs: if any codec is excluded from flash_handler_publish.sdp, it can still be used for publishing.

flash_handler_play.sdp

flash_handler_play.sdp is used for subscriber SDP only, and not affect codecs restrictions when frowarding stream through CDN. If some code is excluded from flash_handler_play.sdp, it will not be used to play RTMP stream by subscriber.

Choosing audio codec to play a stream

If there is a codec used to publish the stream in subscrbers codecs set then this codec will be used to play the stream (regardless of its priority). Otherwise, the subscribers priority codec will be used for playback, and transcoding will occur.

Read and write timeout settings in CDN for RTMP streams delivery

If CDN is used mostly for publishing and playing RTMP streams, and Keep Alive packets is disabled on CDN servers for some reason (for example, publishers and players do not support Keep Alives), it is necessary to setup read and write timeouts to control state of RTMP connections:

1. Read timeout can be set on Origin server that is used only to publish streams, which will not be played directly from the Origin

Code Block
themeRDark
keep_alive.algorithm=NONE
rtmp.server_read_socket_timeout=120

2. Write timeout can be set on Edge server that is used only to play CDN streams

Code Block
themeRDark
keep_alive.algorithm=NONE
rtmp.server_write_socket_timeout=120

3. Read and write timeout can be used both on Origin and Edge servers

Code Block
themeRDark
keep_alive.algorithm=NONE
rtmp.server_socket_timeout=120

Quick manual on testing

1. For testing we use:

  • two WCS servers;
  • the Two Way Streaming web application to publish the stream;
  • the Player web application to play the stream.

Configuring WCS

2. For the test, configure CDN in the minimum configuration: one Origin and one Edge server

Origin settings:

Code Block
languagebash
themeRDark
> show cdn-nodes
Ip                  State
---------------------------
origin.flashphoner.com ACTIVE

Running a broadcast form a web camera to the Origin server

3. Open the Two Way Streaming web application on the Origin server. Click the Connect button and specify the name of the broadcast stream testCDN:

Image Removed

4. Click the Publish button. The stream is published from the web camera:

Image Removed

Playing the stream on the Edge server

5. Open the Player web application on the Edge server. Specify the name of the stream broadcast to the Origin server, testCDN:

Image Removed

6. Click the Start button. Playing of the testCDN stream starts.

Image Removed

...

cdn_enabled=true
cdn_nodes_resolve_ip=true
cdn_ip=origin.flashphoner.com
cdn_role=origin

Edge settings:

Code Block
languagebash
themeRDark
cdn_enabled=true
cdn_nodes_resolve_ip=true
cdn_point_of_entry=origin.flashphoner.com
cdn_ip=edge.flashphoner.com
cdn_role=edge

Here origin.flashphoner.com and edge.flashphoner.com - are examples names of the WCS servers.

Restart Origin and Edge servers. Enter the command line interface of the Edge server, authorize and enter the this command

Code Block
languagebash
themeRDark
show cdn-routesnodes

The result of executing the command is as follows:

Code Block
languagebash
themeRDark
> show cdn-routesnodes
RouteIp                   StreamState
--------------------------------
0-origin.flashphoner.com-0 testCDN

Stopping broadcasting from the web camera to the Origin server

8. Click the Stop button on the stream publishing page. Publishing stops:

Image Removed

On the play page of the Edge server playing of the stream also stops and the message "Stopped by publisher stop" displays.

Image Removed

Known issues

1) Changing codec settings on the Edge server can lead to increased load on the server as a result of enabled transcoding.

Symptoms: when a large number of streams are broadcast, the load on the CPU of the Edge server increases
Solution: configure codec settings on Origin and Edge servers so to reduce excessive transcoding.

For instance, if the codec setting on the Origin server specifies the following set of codecs:

Code Block
languagejs
themeRDark
codecs=opus,mpeg4-generic,alaw,ulaw,g729,g722,telephone-event,h264,vp8

and the setting on the Edge server is

Code Block
languagejs
themeRDark
codecs=opus,speex16,mpeg4-generic,g729,g722,h264,vp8

...

-
origin.flashphoner.com ACTIVE

Running a broadcast form a web camera to the Origin server

3. Open the Two Way Streaming web application on the Origin server. Click the Connect button and specify the name of the broadcast stream testCDN:

Image Added


4. Click the Publish button. The stream is published from the web camera:

Image Added

Playing the stream on the Edge server

5. Open the Player web application on the Edge server. Specify the name of the stream broadcast to the Origin server, testCDN:

Image Added


6. Click the Start button. Playing of the testCDN stream starts.

Image Added


7. In the command line interface of the Edge server enter the command

Code Block
languagebash
themeRDark
show cdn-routes

The result of executing the command is:

Code Block
languagebash
themeRDark
> show cdn-routes
Route                   Stream
--------------------------------
0-origin.flashphoner.com-0 testCDN

Stopping broadcasting from the web camera to the Origin server

8. Click the Stop button on the stream publishing page. Publishing stops:

Image Added


On the play page of the Edge server playing of the stream also stops and the message "Stopped by publisher stop" displays.

Image Added

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, but should not be played from another Origin server in the same CDN.

Known issues

1. Changing codec settings on the Edge server can lead to increased load on the server as a result of enabled transcoding.

Symptoms: when a large number of streams are broadcast, the load on the CPU of the Edge server increases
Solution: configure codec settings on Origin and Edge servers so to reduce excessive transcoding.

For instance, if the codec setting on the Origin server specifies the following set of codecs:

Code Block
languagejs
themeRDark
codecs=opus,mpeg4-generic,alaw,ulaw,g729,g722,telephone-event,h264,vp8

and the setting on the Edge server is

Code Block
languagejs
themeRDark
codecs=opus,speex16,mpeg4-generic,g729,g722,h264,vp8

then, when a stream is broadcast through the Edge server, audio transcoding from Speex16 or AAC is activated. With a large number of streams, the load to the CPU of the server can greatly increase.

2. Stream playback on Edge server may be terminated when Keep Alive is disabled on Origin server

Symptoms: when Keep Alive is disbled on Origin server

Code Block
themeRDark
keep_alive.algorithm=NONE

stream playback on Edge server stops even with the following setting

Code Block
themeRDark
wcs_agent_session_use_keep_alive_timeout=false

Solution: turn off WebSocket read timeout on Edge server with the following setting

Code Block
themeRDark
ws_read_socket_timeout=false