...
Code Block | ||
---|---|---|
| ||
location ~* ^.+.(ts)$ { proxy_pass https://localhost:8445; proxy_http_version 1.1; proxy_set_header Host $server_name:$server_port; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_cache proxy_cache; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 2m; } location ~* ^.+.(m3u8)$ { proxy_pass https://localhost:8445; proxy_http_version 1.1; proxy_set_header Host $server_name:$server_port; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_cache off; expires -1; } |
Returning of static HTML pages on HLS port
Another way to workaround cross domain requests restrictions in browser is to return a static content, player page for example, on the same port that returns HLS content. To enable this feature, the following parameter should be set in flashphoner.properties file
Code Block | ||
---|---|---|
| ||
hls_static_enabled=true |
...
Passing a custom parameters when requesting a playlist
A custom parameters should be passed when requesting a playlist if reverse proxy authentication is set up:
Code Block | ||
---|---|---|
| ||
hls_static_dir=client2/examples/demo/streaming/hls_static |
...
https://wcs:8445/test/test.m3u8?key1=value1&key2=value2 |
The feature is supported since build 5.2.1959. The parameters passed will be returned in every playlist for every segment, this allows to authorize a viewer correctly on proxy server.
There will be an additional parameter sessionId
in playlists, for example
Code Block | ||
---|---|---|
| ||
hlsav_statictest_dir=/var/www/html/hls_static |
If static content returning is enabled, browser will display the HLS player page by URL https://host:8445/hls-player.html. If this feature is disabled, server will return 404 Not found error by such URL.
Preloader for HLS stream playback
...
o/av_test_o.m3u8?sessionId=11&key1=value1&key2=value2 |
This is the internal WCS parameter to identify the subscriber for statistical purposes.
Returning of static HTML pages on HLS port
Another way to workaround cross domain requests restrictions in browser is to return a static content, player page for example, on the same port that returns HLS content. To enable this feature, the following parameter should be set in flashphoner.properties file
Code Block | ||
---|---|---|
| ||
hls_static_enabled=true |
The player page should be in directory defined by the following parameter
Code Block | ||
---|---|---|
| ||
hls_static_dir=client2/examples/demo/streaming/hls_static |
In this case (by default) the path to the player page files is set relative to WCS installation directory. A full path may also be set, for example
Code Block | ||
---|---|---|
| ||
hls_static_dir=/var/www/html/hls_static |
If static content returning is enabled, browser will display the HLS player page by URL https://host:8445/hls-player.html. If this feature is disabled, server will return 404 Not found error by such URL.
Preloader for HLS stream playback
When first HLS subscribes connects to a stream on WCS server, especilally to CDN stream, it may take a time to split a stream to HLS segmets and to form a playlist. As a result, Safari browser on iOS devices may not be able to play HLS stream on the first attempt. To successfully play HLS stream in this case, the HLS preloader was added since build 5.2.371. The default preloader looks like this:
...
REST query | Body example | Response example | Response state | Desctiption | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
/hls/startup |
| 200 - OK 404 - Stream not found 500 - Internal error | Start HLS agent for the stream | |||||||||||||||
/hls/find_all |
|
| 200 – OK 404 – Not found | Find all streams having HLS agents | ||||||||||||||
/hls/terminate |
| 200 – OK 404 – Not found | Stop or restart HLS agent for the stream | |||||||||||||||
/hls/profiles |
|
| 200 – OK 400 – Bad request 404 – Not found | Get HLS profile statistics | ||||||||||||||
/hls/subscribers |
|
| 200 – OK 400 – Bad request 404 – Not found | Get HLS subscribers statistics | ||||||||||||||
/hls/enableRecordingconnections |
|
| 200 – OK 400 – Bad request 404 – Not found 500 - Internal server error | Get a list of HLS clients connected to the server | ||||||||||||||
/hls/enableRecording |
| 200 – OK 400 – Bad request 404 – Not found 409 - Conflict 500 - Internal server error | Enable HLS stream debug segments recording | |||||||||||||||
/hls/disableRecording |
| 200 – OK 400 – Bad request 404 – Not found | Disable HLS stream debug segments recording |
...
Code Block | ||||
---|---|---|---|---|
| ||||
[
{
"id": "192.168.0.83-59000-Mozilla/5.0 (X11; Linux x86_64) Chrome/118.0.0.0",
"ip": "192.168.0.83",
"port": 59000,
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) Chrome/118.0.0.0",
"active": true,
"metrics": {
"profileTime": {
"test": 71,
"v_test": 541353
},
"requestsNumber": 5930,
"requestsStatuses": {
"200 OK": 5930
},
"profileSwitches": 1,
"maxResponseTime": 29,
"minResponseTime": 0,
"avgResponseTime": 0.4436762225969646
}
}
] |
Where:
- id - subscriber identifier
- ip - subscriber IP address
- port - subscriber source port
- userAgent -
User-Agent
header sent by subscriber - active - subscriber is active
- metrics - current subscriber metrics:
- profileTime - the time the subscriber requested the profile shown by profile
- requestsNumber - subscribers requests number
- requestStatuses - response status codes count sent to the subscriber shown by response status code
- profileSwitches - HLS ABR profile switches count for the subscriber
- maxResponseTime - maximum response time
- minResponseTime - minimum response time
- avgResponseTime - average response time
HLS subscribers and connections displaying issues
In the response to the /hls/find_all
, /hls/profiles
, /hls/subscribers
queries a current HLS subscribers count and information are returned as per browser tabs. But HLS network connections count displaying at WCS statistics page
Code Block | ||||
---|---|---|---|---|
| ||||
curl -s http://localhost:8081/?action=stat¶ms=connections_hls |
may differ from HLS subscribers count. In the most cases, HLS subscribers use HTTP 2 protocol to connect and download a segments, then all the browser tabs receiving HLS streams from the same WCS server will use the same network connection.
In this case connections count displayed by connections_hls
parameter is usually equal to HLS port connections count displayed by netstat
command:
Code Block | ||||
---|---|---|---|---|
| ||||
sudo netstat -np | grep ESTABLISHED | grep java | grep 8445 |
Where 8445 is HTTPS HLS port of WCS server
Displaying a list of HLS clients connected to the server
Since build 5.2.1968 it is possible to display a list of HLS clients connected to the server. The list is returned in response to the /hls/connections
query:
Code Block | ||||
---|---|---|---|---|
| ||||
[ { "200 OKip": 5930 }, "profileSwitches": 1"192.168.0.83", "maxResponseTimeport": 2951708, "minResponseTimeuserAgent": "Mozilla/5.0, (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, "avgResponseTime": 0.4436762225969646 }like Gecko) Chrome/125.0.0.0 Safari/537.36" } ] |
Where:
- id - subscriber identifier
- ip - subscriber IP address
- port - subscriber source port
- userAgent -
User-Agent
header sent by subscriber - active - subscriber is active
- metrics - current subscriber metrics:
- profileTime - the time the subscriber requested the profile shown by profile
- requestsNumber - subscribers requests number
- requestStatuses - response status codes count sent to the subscriber shown by response status code
- profileSwitches - HLS ABR profile switches count for the subscriber
- maxResponseTime - maximum response time
- minResponseTime - minimum response time
- avgResponseTime - average response time
HLS subscribers and connections displaying issues
In the response to the /hls/find_all
, /hls/profiles
, /hls/subscribers
queries a current HLS subscribers count and information are returned as per browser tabs. But HLS network connections count displaying at WCS statistics page:
- ip - client address
- port - client source port
- userAgent -
User-Agent
header sent by the client
For HTTPS clients all the tabs of the same browser window on the same PC will be displayed at one position because HTTP/2 uses the same TCP connection for all HTTPS connections.
A clients count in the list will be the same as the statistics page value
Code Block | ||||
---|---|---|---|---|
| ||||
curl -s 'http://localhostwcs:8081/?action=stat¶ms=connections_hls |
may differ from HLS subscribers count. In the most cases, HLS subscribers use HTTP 2 protocol to connect and download a segments, then all the browser tabs receiving HLS streams from the same WCS server will use the same network connection.
In this case connections count displayed by connections_hls
parameter is usually equal to HLS port connections count displayed by netstat
command:
Code Block | ||||
---|---|---|---|---|
| ||||
sudo netstat -np | grep ESTABLISHED | grep java | grep 8445 |
...
connections_hls' |
HLS stream segments recording to disk for debugging purposes
...
Parameter | Description | Default value |
---|---|---|
ll_hls_max_number_of_parent_segments_containing_partials | A maximum partial segments number per one full parent segment | 5 |
ll_hls_part_hold_back_count | PART-HOLD-BACK attribute value in playlist | 6 |
ll_hls_partial_time_max | A maximum partial segment size in milliseconds | 400 |
...
Since build 5.2.1920 it is possible to control HLS provider shutdown when a source stream publishing on the server is stopped. By default, the HLS provider is stopped with a delay
Code Block | ||
---|---|---|
| ||
hls_delayed_shutdown=true |
The delay depends on playlist size
Code Block | ||
---|---|---|
| ||
hls_list_size=8 |
Thus, a subscribers playing the HLS stream may play a rest of playlist if the source stream is stopped.
The delayed shutdown may be disabled if needed
Code Block | ||
---|---|---|
| ||
hls_delayed_shutdown=false |
In this case HLS provider is stopped with a delaywill be stopped right after the source stream is stopped.
HLS segments size control
By default HLS segments will be cut either by key frame receiving or by reaching the size set by the following parameter (2000 ms by default)
Code Block | ||
---|---|---|
| ||
hls_delayedtime_shutdownmin=true |
...
2000 |
Since build 5.2.1974 it is possible to enable HLS segments cutting by key frame receiving only
Code Block | ||
---|---|---|
| ||
hls_list_size=8 |
Thus, a subscribers playing the HLS stream may play a rest of playlist if the source stream is stopped.
...
always_start_segment_with_key_frame=true |
In this case a segment size may exceed hls_time_min
value, bur a minimal segment size may be less. The following parameter is used to strictly limit the minimal segments size
Code Block | ||
---|---|---|
| ||
hls_delayed_shutdown=falsekeep_min_segment_duration=true |
In this case HLS provider a segment size will be stopped right after the source stream is stoppednot be less than hls_time_min
.
Known issues
1. Non-recoverable freeze of HLS stream played in iOS Safari through a CDN
...