
committed by
GitHub

30 changed files with 824 additions and 445 deletions
@ -0,0 +1,90 @@ |
|||
package com.genersoft.iot.vmp.media.zlm; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.genersoft.iot.vmp.common.StreamInfo; |
|||
import com.genersoft.iot.vmp.conf.MediaServerConfig; |
|||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
|||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.util.ConcurrentReferenceHashMap; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.math.BigInteger; |
|||
import java.text.DecimalFormat; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
|
|||
/** |
|||
* @Description:针对 ZLMediaServer的hook事件订阅 |
|||
* @author: pan |
|||
* @date: 2020年12月2日 21:17:32 |
|||
*/ |
|||
@Component |
|||
public class ZLMHttpHookSubscribe { |
|||
|
|||
private final static Logger logger = LoggerFactory.getLogger(ZLMHttpHookSubscribe.class); |
|||
|
|||
public enum HookType{ |
|||
on_flow_report, |
|||
on_http_access, |
|||
on_play, |
|||
on_publish, |
|||
on_record_mp4, |
|||
on_rtsp_auth, |
|||
on_rtsp_realm, |
|||
on_shell_login, |
|||
on_stream_changed, |
|||
on_stream_none_reader, |
|||
on_stream_not_found, |
|||
on_server_started |
|||
} |
|||
|
|||
public interface Event{ |
|||
void response(JSONObject response); |
|||
} |
|||
|
|||
private Map<HookType, Map<JSONObject, ZLMHttpHookSubscribe.Event>> allSubscribes = new ConcurrentHashMap<>(); |
|||
|
|||
public void addSubscribe(HookType type, JSONObject hookResponse, ZLMHttpHookSubscribe.Event event) { |
|||
Map<JSONObject, Event> eventMap = allSubscribes.get(type); |
|||
if (eventMap == null) { |
|||
eventMap = new HashMap<JSONObject, Event>(); |
|||
allSubscribes.put(type,eventMap); |
|||
} |
|||
eventMap.put(hookResponse, event); |
|||
} |
|||
|
|||
public ZLMHttpHookSubscribe.Event getSubscribe(HookType type, JSONObject hookResponse) { |
|||
ZLMHttpHookSubscribe.Event event= null; |
|||
Map<JSONObject, Event> eventMap = allSubscribes.get(type); |
|||
if (eventMap == null) { |
|||
return null; |
|||
} |
|||
for (JSONObject key : eventMap.keySet()) { |
|||
Boolean result = null; |
|||
for (String s : key.keySet()) { |
|||
String string = hookResponse.getString(s); |
|||
String string1 = key.getString(s); |
|||
if (result == null) { |
|||
result = key.getString(s).equals(hookResponse.getString(s)); |
|||
}else { |
|||
result = result && key.getString(s).equals(hookResponse.getString(s)); |
|||
} |
|||
|
|||
} |
|||
if (result) { |
|||
event = eventMap.get(key); |
|||
} |
|||
} |
|||
return event; |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
package com.genersoft.iot.vmp.vmanager.service; |
|||
|
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.genersoft.iot.vmp.common.StreamInfo; |
|||
|
|||
/** |
|||
* 点播处理 |
|||
*/ |
|||
public interface IPlayService { |
|||
|
|||
void onPublishHandlerForPlayBack(JSONObject resonse, String deviceId, String channelId, String uuid); |
|||
void onPublishHandlerForPlay(JSONObject resonse, String deviceId, String channelId, String uuid); |
|||
} |
@ -0,0 +1,90 @@ |
|||
package com.genersoft.iot.vmp.vmanager.service.impl; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.genersoft.iot.vmp.common.StreamInfo; |
|||
import com.genersoft.iot.vmp.conf.MediaServerConfig; |
|||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
|||
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
|||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
|||
import com.genersoft.iot.vmp.vmanager.play.PlayController; |
|||
import com.genersoft.iot.vmp.vmanager.service.IPlayService; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.text.DecimalFormat; |
|||
|
|||
@Service |
|||
public class PlayServiceImpl implements IPlayService { |
|||
|
|||
private final static Logger logger = LoggerFactory.getLogger(PlayServiceImpl.class); |
|||
|
|||
@Autowired |
|||
private IVideoManagerStorager storager; |
|||
|
|||
@Autowired |
|||
private DeferredResultHolder resultHolder; |
|||
|
|||
@Override |
|||
public void onPublishHandlerForPlay(JSONObject resonse, String deviceId, String channelId, String uuid) { |
|||
RequestMessage msg = new RequestMessage(); |
|||
msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid); |
|||
StreamInfo streamInfo = onPublishHandler(resonse, deviceId, channelId, uuid); |
|||
if (streamInfo != null) { |
|||
storager.startPlay(streamInfo); |
|||
msg.setData(JSON.toJSONString(streamInfo)); |
|||
resultHolder.invokeResult(msg); |
|||
} else { |
|||
logger.warn("设备预览API调用失败!"); |
|||
msg.setData("设备预览API调用失败!"); |
|||
resultHolder.invokeResult(msg); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void onPublishHandlerForPlayBack(JSONObject resonse, String deviceId, String channelId, String uuid) { |
|||
RequestMessage msg = new RequestMessage(); |
|||
msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid); |
|||
StreamInfo streamInfo = onPublishHandler(resonse, deviceId, channelId, uuid); |
|||
if (streamInfo != null) { |
|||
storager.startPlayback(streamInfo); |
|||
msg.setData(JSON.toJSONString(streamInfo)); |
|||
resultHolder.invokeResult(msg); |
|||
} else { |
|||
logger.warn("设备预览API调用失败!"); |
|||
msg.setData("设备预览API调用失败!"); |
|||
resultHolder.invokeResult(msg); |
|||
} |
|||
} |
|||
|
|||
public StreamInfo onPublishHandler(JSONObject resonse, String deviceId, String channelId, String uuid) { |
|||
String streamId = resonse.getString("id"); |
|||
String ssrc = new DecimalFormat("0000000000").format(Integer.parseInt(streamId, 16)); |
|||
StreamInfo streamInfo = new StreamInfo(); |
|||
streamInfo.setSsrc(ssrc); |
|||
streamInfo.setStreamId(streamId); |
|||
streamInfo.setDeviceID(deviceId); |
|||
streamInfo.setCahnnelId(channelId); |
|||
MediaServerConfig mediaServerConfig = storager.getMediaInfo(); |
|||
|
|||
streamInfo.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); |
|||
streamInfo.setWs_flv(String.format("ws://%s:%s/rtp/%s.flv", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); |
|||
|
|||
streamInfo.setFmp4(String.format("http://%s:%s/rtp/%s.live.mp4", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); |
|||
streamInfo.setWs_fmp4(String.format("ws://%s:%s/rtp/%s.live.mp4", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); |
|||
|
|||
streamInfo.setHls(String.format("http://%s:%s/rtp/%s/hls.m3u8", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); |
|||
streamInfo.setWs_hls(String.format("ws://%s:%s/rtp/%s/hls.m3u8", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); |
|||
|
|||
streamInfo.setTs(String.format("http://%s:%s/rtp/%s.live.ts", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); |
|||
streamInfo.setWs_ts(String.format("ws://%s:%s/rtp/%s.live.ts", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); |
|||
|
|||
streamInfo.setRtmp(String.format("rtmp://%s:%s/rtp/%s", mediaServerConfig.getWanIp(), mediaServerConfig.getRtmpPort(), streamId)); |
|||
streamInfo.setRtsp(String.format("rtsp://%s:%s/rtp/%s", mediaServerConfig.getWanIp(), mediaServerConfig.getRtspPort(), streamId)); |
|||
|
|||
return streamInfo; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,94 @@ |
|||
spring: |
|||
# [不需要改] |
|||
application: |
|||
name: iot-vmp-vmanager |
|||
# [不需要改] 影子数据存储方式,支持redis、jdbc,暂不支持mysql, |
|||
database: redis |
|||
# [不需要改] 通信方式,支持kafka、http |
|||
communicate: http |
|||
# REDIS数据库配置 |
|||
redis: |
|||
# [必须修改] Redis服务器IP, REDIS安装在本机的,使用127.0.0.1 |
|||
host: 127.0.0.1 |
|||
# [必须修改] 端口号 |
|||
port: 6379 |
|||
# [可选] 数据库 DB |
|||
database: 6 |
|||
# [可选] 访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接 |
|||
password: |
|||
# [可选] 超时时间 |
|||
timeout: 10000 |
|||
# [不可用] jdbc数据库配置, 暂不支持 |
|||
datasource: |
|||
name: eiot |
|||
url: jdbc:mysql://127.0.0.1:3306/eiot?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true |
|||
username: |
|||
password: |
|||
type: com.alibaba.druid.pool.DruidDataSource |
|||
driver-class-name: com.mysql.jdbc.Driver |
|||
|
|||
# [可选] WVP监听的HTTP端口, 网页和接口调用都是这个端口 |
|||
server: |
|||
port: 18080 |
|||
|
|||
# 作为28181服务器的配置 |
|||
sip: |
|||
# [必须修改] 本机的IP, 必须是网卡上的IP |
|||
ip: 192.168.0.100 |
|||
# [可选] 28181服务监听的端口 |
|||
port: 5060 |
|||
# 根据国标6.1.2中规定,domain宜采用ID统一编码的前十位编码。国标附录D中定义前8位为中心编码(由省级、市级、区级、基层编号组成,参照GB/T 2260-2007) |
|||
# 后两位为行业编码,定义参照附录D.3 |
|||
# 3701020049标识山东济南历下区 信息行业接入 |
|||
# [可选] |
|||
domain: 4401020049 |
|||
# [可选] |
|||
id: 44010200492000000001 |
|||
# [可选] 默认设备认证密码,后续扩展使用设备单独密码 |
|||
password: admin123 |
|||
|
|||
# 登陆的用户名密码 |
|||
auth: |
|||
# [可选] 用户名 |
|||
username: admin |
|||
# [可选] 密码, 默认为admin |
|||
password: 21232f297a57a5a743894a0e4a801fc3 |
|||
|
|||
#zlm服务器配置 |
|||
media: |
|||
# [必须修改] zlm服务器的内网IP |
|||
ip: 192.168.0.100 |
|||
# [可选] zlm服务器的公网IP, 内网部署置空即可 |
|||
wanIp: |
|||
# [可选] zlm服务器的hook所使用的IP, 默认使用sip.ip |
|||
hookIp: |
|||
# [必须修改] zlm服务器的http.port |
|||
port: 80 |
|||
# [可选] 是否自动配置ZLM, 如果希望手动配置ZLM, 可以设为false, 不建议新接触的用户修改 |
|||
autoConfig: true |
|||
# [可选] zlm服务器的hook.admin_params=secret |
|||
secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc |
|||
# [可选] zlm服务器的general.streamNoneReaderDelayMS |
|||
streamNoneReaderDelayMS: 18000 # 无人观看多久自动关闭流 |
|||
# [可选] 关闭等待收到流编码信息后在返回, |
|||
# 设为false可以获得更好的兼容性,保证返回后流就可以播放, |
|||
# 设为true可以快速打开播放窗口,可以获得更好的体验 |
|||
closeWaitRTPInfo: false |
|||
# 启用udp多端口模式 |
|||
rtp: |
|||
# [可选] 是否启用udp多端口模式, 开启后会在udpPortRange范围内选择端口用于媒体流传输 |
|||
enable: true |
|||
# [可选] 在此范围内选择端口用于媒体流传输, 不只是udp, 使用TCP被动传输模式时,也是从这个范围内选择端口 |
|||
udpPortRange: 30000,30500 # 端口范围 |
|||
|
|||
# [可选] 日志配置, 一般不需要改 |
|||
logging: |
|||
file: |
|||
name: logs/wvp.log |
|||
max-history: 30 |
|||
max-size: 10MB |
|||
total-size-cap: 300MB |
|||
level: |
|||
com: |
|||
genersoft: |
|||
iot: debug |
@ -1,64 +1,3 @@ |
|||
spring: |
|||
application: |
|||
name: iot-vmp-vmanager |
|||
# 影子数据存储方式,支持redis、jdbc,暂不支持mysql |
|||
database: redis |
|||
# 通信方式,支持kafka、http |
|||
communicate: http |
|||
redis: |
|||
# Redis服务器IP |
|||
host: 192.168.1.141 |
|||
#端口号 |
|||
port: 6379 |
|||
database: 6 |
|||
#访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接 |
|||
password: 4767cb971b40a1300fa09b7f87b09d1c |
|||
#超时时间 |
|||
timeout: 10000 |
|||
datasource: |
|||
name: eiot |
|||
url: jdbc:mysql://127.0.0.1:3306/eiot?useUnicode=true&characterEncoding=UTF8&rewriteBatchedStatements=true |
|||
username: |
|||
password: |
|||
type: com.alibaba.druid.pool.DruidDataSource |
|||
driver-class-name: com.mysql.jdbc.Driver |
|||
server: |
|||
port: 18080 |
|||
sip: |
|||
ip: 192.168.1.20 |
|||
port: 5060 |
|||
# 根据国标6.1.2中规定,domain宜采用ID统一编码的前十位编码。国标附录D中定义前8位为中心编码(由省级、市级、区级、基层编号组成,参照GB/T 2260-2007) |
|||
# 后两位为行业编码,定义参照附录D.3 |
|||
# 3701020049标识山东济南历下区 信息行业接入 |
|||
domain: 3402000000 |
|||
id: 34020000002000000001 |
|||
# 默认设备认证密码,后续扩展使用设备单独密码 |
|||
password: 12345678 |
|||
|
|||
auth: #32位小写md5加密(默认密码为admin) |
|||
username: admin |
|||
password: 21232f297a57a5a743894a0e4a801fc3 |
|||
|
|||
media: #zlm服务器的ip与http端口, 重点: 这是http端口 |
|||
ip: 127.0.0.1 |
|||
wanIp: 192.168.1.20 |
|||
port: 6080 |
|||
secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc |
|||
streamNoneReaderDelayMS: 600000 # 无人观看多久自动关闭流 |
|||
# 关闭等待收到流编码信息后在返回, |
|||
# 设为false可以获得更好的兼容性,保证返回后流就可以播放, |
|||
# 设为true可以快速打开播放窗口,可以获得更好的体验 |
|||
closeWaitRTPInfo: true |
|||
rtp: # 启用udp多端口模式 |
|||
enable: true |
|||
udpPortRange: 30000,30500 # 端口范围 |
|||
logging: |
|||
file: |
|||
name: logs/wvp.log |
|||
max-history: 30 |
|||
max-size: 10MB |
|||
total-size-cap: 300MB |
|||
level: |
|||
com: |
|||
genersoft: |
|||
iot: debug |
|||
profiles: |
|||
active: dev |
@ -0,0 +1,57 @@ |
|||
<template> |
|||
<div id="player"> |
|||
<div id="easyplayer"></div> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
export default { |
|||
name: 'player', |
|||
data() { |
|||
return { |
|||
easyPlayer: null |
|||
}; |
|||
}, |
|||
props: ['videoUrl', 'error', 'hasaudio'], |
|||
mounted () { |
|||
this.$nextTick(() =>{ |
|||
console.log("初始化时的地址为: " + this.videoUrl) |
|||
this.easyPlayer = new WasmPlayer(null, 'easyplayer', this.eventcallbacK) |
|||
this.easyPlayer.play(this.videoUrl, 1) |
|||
}) |
|||
}, |
|||
watch:{ |
|||
videoUrl(newData, oldData){ |
|||
this.easyPlayer.destroy() |
|||
this.easyPlayer = new WasmPlayer(null, 'easyplayer', this.eventcallbacK) |
|||
this.easyPlayer.play(newData, 1) |
|||
}, |
|||
immediate:true |
|||
}, |
|||
methods: { |
|||
play: function (url) { |
|||
this.easyPlayer = new WasmPlayer(null, 'easyplayer', this.eventcallbacK) |
|||
this.easyPlayer.play(url, 1) |
|||
}, |
|||
pause: function () { |
|||
this.easyPlayer.destroy(); |
|||
}, |
|||
eventcallbacK: function(type, message) { |
|||
console.log("player 事件回调") |
|||
console.log(type) |
|||
console.log(message) |
|||
} |
|||
}, |
|||
} |
|||
</script> |
|||
|
|||
<style> |
|||
.LodingTitle { |
|||
min-width: 70px; |
|||
} |
|||
/* 隐藏logo */ |
|||
/* .iconqingxiLOGO { |
|||
display: none !important; |
|||
} */ |
|||
|
|||
</style> |
Loading…
Reference in new issue