Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRT: Support multiple querystring for authentication. #2893

Closed
winlinvip opened this issue Jan 28, 2022 · 5 comments · Fixed by #2908
Closed

SRT: Support multiple querystring for authentication. #2893

winlinvip opened this issue Jan 28, 2022 · 5 comments · Fixed by #2908
Assignees
Labels
SRT It's about SRT protocol. TransByAI Translated by AI/GPT.
Milestone

Comments

@winlinvip
Copy link
Member

winlinvip commented Jan 28, 2022

Because SRT does not defines the querystring, or because streamid IS actually a querystring, so it's hard to use authentication in SRT URL. For example, a general SRT url defines as bellow:

srt://127.0.0.1:10080?streamid=#!::r=live/livestream,m=publish

How to pass something like secret=xxx in the URL? It's undefined, so we defined as:

srt://127.0.0.1:10080?streamid=#!::r=live/livestream,secret=xxx,m=publish

It also allows us to pass more than one querystring, for example:

srt://127.0.0.1:10080?streamid=#!::r=live/livestream,secret=xxx,token=yyy,other=zzz,m=publish

SRT does not define QueryString, so there will be problems when switching to RTMP, and authentication cannot be done.

Usage

OBS streaming address:

  • RTMP: rtmp://127.0.0.1/live/livestream?key1=value1&key2=value2
  • SRT: srt://127.0.0.1:10080?streamid=#!::r=live/livestream,key1=value1,key2=value2,m=publish

With VHOST parameter:

  • RTMP: rtmp://127.0.0.1/live/livestream?vhost=host.com&key1=value1&key2=value2
  • SRT: srt://127.0.0.1:10080?streamid=#!::h=host.com,r=live/livestream,key1=value1,key2=value2,m=publish

FFPLAY playback address:

  • RTMP: rtmp://127.0.0.1/live/livestream?key1=value1&key2=value2
  • SRT: srt://127.0.0.1:10080?streamid=#!::r=live/livestream,key1=value1,key2=value2,m=request

With authentication information:

  • RTMP: rtmp://127.0.0.1/live/livestream?secret=xxx
  • SRT: srt://127.0.0.1:10080?streamid=#!::r=live/livestream,secret=xxx,m=publish

Publish by FFmpeg:

ffmpeg -re -i doc/source.flv -c copy -f mpegts \
    'srt://127.0.0.1:10080?streamid=#!::r=live/livestream,secret=xxx,m=publish'

Play by ffplay:

ffplay -fflags nobuffer -flags low_delay \
  -i 'srt://127.0.0.1:10080?streamid=#!::r=live/livestream,latency=20,m=request'

Solution

If using domain (vhost) for push-pull streaming, the general correspondence between RTMP and SRT is:

  • RTMP: rtmp://host.com/app/stream?key1=value1&key2=value2
  • SRT: srt://host.com:10080?streamid=#!::h=host.com,r=app/stream,key1=value1,key2=value2

It is also possible to directly use the IP to specify the domain for push-pull streaming.

  • RTMP: rtmp://1.2.3.4/app/stream?vhost=host.com&key1=value1&key2=value2
  • SRT: srt://1.2.3.4:10080?streamid=#!::h=host.com,r=app/stream,key1=value1,key2=value2

Sometimes (often), SRS does not have a domain name (domain/vhost) and directly uses IP for push-pull streaming. In such cases:

  • RTMP address: rtmp://1.2.3.4/app/stream?key1=value1&key2=value2
  • SRT address: srt://1.2.3.4:10080?streamid=#!::r=app/stream,key1=value1,key2=value2

Key points:

  1. In the SRT URL, the & symbol should not be used, as it will be treated as a parameter separator by ffmpeg and OBS, resulting in the loss of input parameters.
  2. For SRT, the h=hostname parameter needs to be included again in the streamid, whereas for RTMP, it is not required. This is because RTMP automatically includes the hostname in the tcUrl, while in SRT, it needs to be manually specified to differentiate the business domain.
  3. m=request|publish represents whether it is a pull or push stream. The default is a pull stream.

Note: SRS also supports multiple ports, and different ports have different default values for m. This allows for scenarios where m does not need to be specified, which is effective when there is port redundancy on the broadcasting system but the URL needs to be kept simple. However, in the internet environment, ports are usually restricted by firewalls or security groups, so it is preferable to open fewer ports and specify more information in the URL.

Regarding the definitions of h and r, please refer to SRT: Standard Keys.

  • r: Resource Name identifies the name of the resource and facilitates
    selection should the listener party be able to serve multiple resources.
  • h: Host Name identifies the hostname of the resource. For example,
    to request a stream with the URI somehost.com/videos/querry.php?vid=366 the hostname field should have somehost.com, and the resource name can have videos/querry.php?vid=366 or simply 366. Note that this is still a key to be specified explicitly. Support tools that apply simplifications and URI extraction are expected to insert only the host portion of the URI here.
  • m: Mode expected for this connection:
    • request (default): the caller wants to receive the stream
    • publish: the caller wants to send the stream data
    • bidirectional: bidirectional data exchange is expected

Reference document:

PS: The URL of Bilibili is not informative, as the stream itself is empty, ?streamname=live_430256302_28738971, which corresponds to the RTMP stream.

Compatible

The previously defined old URL format mainly included the stream information in the h parameter. It is currently still compatible, but it will be removed in the future. Please refrain from using it.

Based on the article from the official SRT website: AccessControl

The latest modification to the SRT streaming address specification is:

URL for defaultVhost

# https://github.com/Haivision/srt/blob/master/docs/AccessControl.md
# Publish stream by SRT:
#               srt://127.0.0.1:10080?streamid=#!::h=live/livestream,m=publish
# Play stream by SRT
#               srt://127.0.0.1:10080?streamid=#!::h=live/livestream,m=request
# Play stream by RTMP:
#               rtmp://127.0.0.1/live/livestream

URL for vhost

# To use vhost in SRS.
# Publish stream by SRT:
#               srt://127.0.0.1:10080?streamid=#!::h=srs.srt.com.cn/live/livestream,m=publish
# Play stream by SRT:
#               srt://127.0.0.1:10080?streamid=#!::h=srs.srt.com.cn/live/livestream,m=request
# Play stream by RTMP:
#               rtmp://127.0.0.1/live/livestream?vhost=srs.srt.com.cn

Based on the SRT official website, the format of the stream ID has Standard Keys. The SRT service in SRS should strive to comply with the official website standards.

The Stream ID value can be used as free-form, but there is a recommended convention so that all SRT users speak the same language. The intent of the convention is to:
1. promote readability and consistency among free-form names
2. interpret some typical data in the key-value style

Comply with the YAML format, starting with #!::.
The key "h" represents the vhost and appname/stream.
The key "m" represents publishing (publish) or requesting (request) a stream.

TRANS_BY_GPT3

@zhouxiaojun2008

This comment was marked as resolved.

@winlinvip
Copy link
Member Author

winlinvip commented Feb 10, 2022

The parameters of RTMP must all be placed in the stream, not in the app.

Originally, Adobe placed them in the app, but this looks messy.

rtmp://127.0.0.1/live?secret=xxx&token=yyy?vhost=live.test.com/livestream

It's better to place them naturally in the stream.

rtmp://127.0.0.1/live/livestream?secret=xxx&token=yyy?vhost=live.test.com

Therefore, the parameters of RTMP must not be placed in the app anymore. SRS supports placing them in the app for compatibility purposes, but the new ones cannot be placed here anymore.

TRANS_BY_GPT3

@winlinvip

This comment was marked as resolved.

@xiaozhihong
Copy link
Collaborator

xiaozhihong commented Feb 10, 2022

Moved to #2893 (comment)

@ossrs ossrs deleted a comment from xiaozhihong Feb 11, 2022
zhouxiaojun2008 added a commit to zhouxiaojun2008/srs that referenced this issue Feb 13, 2022
@winlinvip winlinvip linked a pull request Mar 19, 2022 that will close this issue
winlinvip added a commit that referenced this issue Mar 19, 2022
* SRT:  parse srt url to supports multiple QueryStrings.(#2893)

* SRT:  url supports multiple QueryStrings by  comma-separated key-value pairs with no nesting  (#2893)

* SRT:  url supports multiple QueryStrings by comma-separated key-value pairs with no nesting  (#2893)

* SRT: Add comments for url.

* Add utest for SRT URL parsing.

* Update README.

Co-authored-by: winlin <winlin@vip.126.com>
@winlinvip
Copy link
Member Author

Thanks @xiaozhihong @zhouxiaojun2008

@winlinvip winlinvip changed the title SRT支持多QueryString,传递到RTMP,实现鉴权等能力 SRT: Support multiple querystrings for authentication. Mar 19, 2022
@winlinvip winlinvip changed the title SRT: Support multiple querystrings for authentication. SRT: Support multiple querystring for authentication. Mar 19, 2022
@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SRT It's about SRT protocol. TransByAI Translated by AI/GPT.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants