648540858
4 years ago
20 changed files with 675 additions and 353 deletions
@ -0,0 +1,88 @@ |
|||||
|
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.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import java.math.BigInteger; |
||||
|
import java.text.DecimalFormat; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @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 HashMap<>(); |
||||
|
|
||||
|
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,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