token防盜鏈:用戶在播放時(shí),必須先申請(qǐng)token,SRS會(huì)回調(diào)http檢查這個(gè)token合法性。
# push gb28181 stream to SRS.
listen 1935;
max_connections 1000;
daemon off;
srs_log_tank console;
http_api {
enabled on;
listen 1985;
}
http_server {
enabled on;
listen 8080;
dir ./objs/nginx/html;
}
stats {
network 0;
}
stream_caster {
enabled on;
caster gb28181;
# 轉(zhuǎn)發(fā)流到rtmp服務(wù)器地址與端口
# TODO: https://github.com/ossrs/srs/pull/1679/files#r400875104
# [stream] is VideoChannelCodecID(視頻通道編碼ID) for sip
# 自動(dòng)創(chuàng)建的道通[stream] 是‘chid[ssrc]’ [ssrc]是rtp的ssrc
# [ssrc] rtp中的ssrc
output rtmp://127.0.0.1:1935/live/[stream];
# 接收設(shè)備端rtp流的多路復(fù)用端口
listen 9000;
# rtp接收監(jiān)聽端口范圍,最小值
rtp_port_min 58200;
# rtp接收監(jiān)聽端口范圍,最大值
rtp_port_max 58300;
# 是否等待關(guān)鍵幀之后,再轉(zhuǎn)發(fā),
# off:不需等待,直接轉(zhuǎn)發(fā)
# on:等第一個(gè)關(guān)鍵幀后,再轉(zhuǎn)發(fā)
wait_keyframe off;
# rtp包空閑等待時(shí)間,如果指定時(shí)間沒有收到任何包
# rtp監(jiān)聽連接自動(dòng)停止,發(fā)送BYE命令
rtp_idle_timeout 30;
# 是否轉(zhuǎn)發(fā)音頻流
# 目前只支持aac格式,所以需要設(shè)備支持aac格式
# on:轉(zhuǎn)發(fā)音頻
# off:不轉(zhuǎn)發(fā)音頻,只有視頻
# *注意*!!!:flv 只支持11025 22050 44100 三種
# 如果設(shè)備端沒有三種中任何一個(gè),轉(zhuǎn)發(fā)時(shí)為自動(dòng)選擇一種格式
# 同時(shí)也會(huì)將adts的頭封裝在flv aac raw數(shù)據(jù)中
# 這樣的話播放器為自動(dòng)通過adts頭自動(dòng)選擇采樣頻率
# 像ffplay, vlc都可以,但是flash是沒有聲音,
# 因?yàn)閒lash,只支持11025 22050 44100
audio_enable on;
# 服務(wù)器主機(jī)號(hào),可以域名或ip地址
# 也就是設(shè)備端將媒體發(fā)送的地址,如果是服務(wù)器是內(nèi)外網(wǎng)
# 需要寫外網(wǎng)地址,
# 調(diào)用api創(chuàng)建stream session時(shí)返回ip地址也是host
# $CANDIDATE 是系統(tǒng)環(huán)境變量,從環(huán)境變量獲取地址,如果沒有配置,用*
# *代表指定stats network 的網(wǎng)卡號(hào)地址,如果沒有配置network,默認(rèn)則是第0號(hào)網(wǎng)卡地址
# TODO: https://github.com/ossrs/srs/pull/1679/files#r400917594
host 192.168.2.100;
#根據(jù)收到ps rtp包自帶創(chuàng)建rtmp媒體通道,不需要api接口創(chuàng)建
#rtmp地址參數(shù)[stream] 就是通道id 格式chid[ssrc]
auto_create_channel off;
sip {
# 是否啟用srs內(nèi)部sip信令
# 為on信令走srs, off 只轉(zhuǎn)發(fā)ps流
enabled on;
# sip監(jiān)聽udp端口
listen 5060;
# SIP server ID(SIP服務(wù)器ID).
# 設(shè)備端配置編號(hào)需要與該值一致,否則無(wú)法注冊(cè)
serial 34020000002000000001;
# SIP server domain(SIP服務(wù)器域)
realm 3402000000;
# 服務(wù)端發(fā)送ack后,接收回應(yīng)的超時(shí)時(shí)間,單位為秒
# 如果指定時(shí)間沒有回應(yīng),認(rèn)為失敗
ack_timeout 30;
# 設(shè)備心跳維持時(shí)間,如果指定時(shí)間內(nèi)(秒)沒有接收一個(gè)心跳
# 認(rèn)為設(shè)備離線
keepalive_timeout 120;
# 注冊(cè)之后是否自動(dòng)給設(shè)備端發(fā)送invite
# on: 是 off 不是,需要通過api控制
auto_play on;
# 設(shè)備將流發(fā)送的端口,是否固定
# on 發(fā)送流到多路復(fù)用端口 如9000
# off 自動(dòng)從rtp_mix_port - rtp_max_port 之間的值中
# 選一個(gè)可以用的端口
invite_port_fixed on;
# 向設(shè)備或下級(jí)域查詢?cè)O(shè)備列表的間隔,單位(秒)
# 默認(rèn)60秒
query_catalog_interval 60;
}
}
rtc_server {
enabled on;
# Listen at udp://8000
listen 8000;
#
# The $CANDIDATE means fetch from env, if not configed, use * as default.
#
# The * means retrieving server IP automatically, from all network interfaces,
# @see https://github.com/ossrs/srs/issues/307#issuecomment-599028124
candidate 192.168.2.100;
}
vhost __defaultVhost__ {
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
}
rtc {
enabled on;
bframe discard;
rtmp_to_rtc on;
}
http_hooks {
# whether the http hooks enable.
# default off.
enabled on;
# when client connect to vhost/app, call the hook,
# the request in the POST data string is a object encode by json:
# {
# "action": "on_connect",
# "client_id": 1985,
# "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",
# "tcUrl": "rtmp://video.test.com/live?key=d2fa801d08e3f90ed1e1670e6e52651a",
# "pageUrl": "http://www.test.com/live.html"
# }
# if valid, the hook must return HTTP code 200(Status OK) and response
# an int value specifies the error code(0 corresponding to success):
# 0
# support multiple api hooks, format:
# on_connect http://xxx/api0 http://xxx/api1 http://xxx/apiN
on_connect http://192.168.2.200:8080/srs;
# when client close/disconnect to vhost/app/stream, call the hook,
# the request in the POST data string is a object encode by json:
# {
# "action": "on_close",
# "client_id": 1985,
# "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",
# "send_bytes": 10240, "recv_bytes": 10240
# }
# if valid, the hook must return HTTP code 200(Status OK) and response
# an int value specifies the error code(0 corresponding to success):
# 0
# support multiple api hooks, format:
# on_close http://xxx/api0 http://xxx/api1 http://xxx/apiN
on_close http://192.168.2.200:8080/srs;
# when client(encoder) publish to vhost/app/stream, call the hook,
# the request in the POST data string is a object encode by json:
# {
# "action": "on_publish",
# "client_id": 1985,
# "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",
# "stream": "livestream"
# }
# if valid, the hook must return HTTP code 200(Status OK) and response
# an int value specifies the error code(0 corresponding to success):
# 0
# support multiple api hooks, format:
# on_publish http://xxx/api0 http://xxx/api1 http://xxx/apiN
on_publish http://192.168.2.200:8080/srs;
# when client(encoder) stop publish to vhost/app/stream, call the hook,
# the request in the POST data string is a object encode by json:
# {
# "action": "on_unpublish",
# "client_id": 1985,
# "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",
# "stream": "livestream", "param":"?token=xxx&salt=yyy"
# }
# if valid, the hook must return HTTP code 200(Status OK) and response
# an int value specifies the error code(0 corresponding to success):
# 0
# support multiple api hooks, format:
# on_unpublish http://xxx/api0 http://xxx/api1 http://xxx/apiN
on_unpublish http://127.0.0.1:8085/api/v1/streams http://localhost:8085/api/v1/streams;
# when client start to play vhost/app/stream, call the hook,
# the request in the POST data string is a object encode by json:
# {
# "action": "on_play",
# "client_id": 1985,
# "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",
# "stream": "livestream", "param":"?token=xxx&salt=yyy",
# "pageUrl": "http://www.test.com/live.html"
# }
# if valid, the hook must return HTTP code 200(Status OK) and response
# an int value specifies the error code(0 corresponding to success):
# 0
# support multiple api hooks, format:
# on_play http://xxx/api0 http://xxx/api1 http://xxx/apiN
on_play http://192.168.2.200:8080/srs;
# when client stop to play vhost/app/stream, call the hook,
# the request in the POST data string is a object encode by json:
# {
# "action": "on_stop",
# "client_id": 1985,
# "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",
# "stream": "livestream", "param":"?token=xxx&salt=yyy"
# }
# if valid, the hook must return HTTP code 200(Status OK) and response
# an int value specifies the error code(0 corresponding to success):
# 0
# support multiple api hooks, format:
# on_stop http://xxx/api0 http://xxx/api1 http://xxx/apiN
on_stop http://192.168.2.200:8080/srs;
# when srs reap a dvr file, call the hook,
# the request in the POST data string is a object encode by json:
# {
# "action": "on_dvr",
# "client_id": 1985,
# "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",
# "stream": "livestream", "param":"?token=xxx&salt=yyy",
# "cwd": "/usr/local/srs",
# "file": "./objs/nginx/html/live/livestream.1420254068776.flv"
# }
# if valid, the hook must return HTTP code 200(Status OK) and response
# an int value specifies the error code(0 corresponding to success):
# 0
on_dvr http://127.0.0.1:8085/api/v1/dvrs http://localhost:8085/api/v1/dvrs;
# when srs reap a ts file of hls, call the hook,
# the request in the POST data string is a object encode by json:
# {
# "action": "on_hls",
# "client_id": 1985,
# "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",
# "stream": "livestream", "param":"?token=xxx&salt=yyy",
# "duration": 9.36, // in seconds
# "cwd": "/usr/local/srs",
# "file": "./objs/nginx/html/live/livestream/2015-04-23/01/476584165.ts",
# "url": "live/livestream/2015-04-23/01/476584165.ts",
# "m3u8": "./objs/nginx/html/live/livestream/live.m3u8",
# "m3u8_url": "live/livestream/live.m3u8",
# "seq_no": 100
# }
# if valid, the hook must return HTTP code 200(Status OK) and response
# an int value specifies the error code(0 corresponding to success):
# 0
on_hls http://127.0.0.1:8085/api/v1/hls http://localhost:8085/api/v1/hls;
# when srs reap a ts file of hls, call this hook,
# used to push file to cdn network, by get the ts file from cdn network.
# so we use HTTP GET and use the variable following:
# [app], replace with the app.
# [stream], replace with the stream.
# [param], replace with the param.
# [ts_url], replace with the ts url.
# ignore any return data of server.
# @remark random select a url to report, not report all.
on_hls_notify http://127.0.0.1:8085/api/v1/hls/[app]/[stream]/[ts_url][param];
}
}
參考:
【1】DRM:https://github.com/ossrs/srs/wiki/v3_CN_DRM#token-authentication