diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index 881ef5209..ae68a8de9 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -126,6 +126,35 @@ public class ZLMHttpHookListener { @Autowired private RedisTemplate redisTemplate; + + /** + * 流量统计事件,播放器或推流器断开时并且耗用流量超过特定阈值时会触发此事件,阈值通过配置文件general.flowThreshold配置;此事件对回复不敏感。 + * + */ + @ResponseBody + @PostMapping(value = "/on_flow_report", produces = "application/json;charset=UTF-8") + public HookResult onFlowReport(@RequestBody OnFlowReportHookParam param){ + if (logger.isDebugEnabled()) { + logger.debug("[ ZLM HOOK ] on_flow_report API调用,参数:{}" , param); + } + + return HookResult.SUCCESS(); + } + + /** + * 访问http文件服务器上hls之外的文件时触发。 + * + */ + @ResponseBody + @PostMapping(value = "/on_http_access", produces = "application/json;charset=UTF-8") + public HookResult onHttpAccess(@RequestBody JSONObject json){ + if (logger.isDebugEnabled()) { + logger.debug("[ ZLM HOOK ] on_http_access API调用,参数:{}" , json); + } + + return HookResult.SUCCESS(); + } + /** * 服务器定时上报时间,上报间隔可配置,默认10s上报一次 */ @@ -133,7 +162,9 @@ public class ZLMHttpHookListener { @PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8") public HookResult onServerKeepalive(@RequestBody OnServerKeepaliveHookParam param) { - + if (logger.isDebugEnabled()) { + logger.debug("[ ZLM HOOK ] on_server_keepalive API调用,参数:{}" , param); + } taskExecutor.execute(() -> { List subscribes = this.subscribe.getSubscribes(HookType.on_server_keepalive); @@ -187,10 +218,10 @@ public class ZLMHttpHookListener { @ResponseBody @PostMapping(value = "/on_publish", produces = "application/json;charset=UTF-8") public HookResultForOnPublish onPublish(@RequestBody OnPublishHookParam param) { - JSONObject json = (JSONObject) JSON.toJSON(param); - - logger.info("[ZLM HOOK]推流鉴权:{}->{}", param.getMediaServerId(), param); + if (logger.isDebugEnabled()) { + logger.debug("[ZLM HOOK]推流鉴权:{}->{}", param.getMediaServerId(), param); + } String mediaServerId = json.getString("mediaServerId"); MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); @@ -306,11 +337,82 @@ public class ZLMHttpHookListener { result.setEnable_mp4(true); } } - logger.info("[ZLM HOOK]推流鉴权 响应:{}->{}->>>>{}", param.getMediaServerId(), param, result); + if (logger.isDebugEnabled()) { + logger.debug("[ZLM HOOK]推流鉴权 响应:{}->{}->>>>{}", param.getMediaServerId(), param, result); + } return result; } + /** + * 录制mp4完成后通知事件;此事件对回复不敏感。 + * + */ + @ResponseBody + @PostMapping(value = "/on_record_mp4", produces = "application/json;charset=UTF-8") + public HookResult onRecordMp4(@RequestBody OnRecordHookParam param){ + if (logger.isDebugEnabled()) { + logger.debug("[ ZLM HOOK ] on_record_mp4 API调用,参数:" + param.toString()); + } + + return HookResult.SUCCESS(); + } + /** + * 录制hls完成后通知事件;此事件对回复不敏感。 + * + */ + @ResponseBody + @PostMapping(value = "/on_record_ts", produces = "application/json;charset=UTF-8") + public HookResult onRecordTs(@RequestBody OnRecordHookParam param){ + if (logger.isDebugEnabled()) { + logger.debug("[ ZLM HOOK ] on_record_ts API调用,参数:" + param.toString()); + } + + return HookResult.SUCCESS(); + } + + /** + * rtsp专用的鉴权事件,先触发on_rtsp_realm事件然后才会触发on_rtsp_auth事件。 + * + */ + @ResponseBody + @PostMapping(value = "/on_rtsp_realm", produces = "application/json;charset=UTF-8") + public HookResult onRtspRealm(@RequestBody OnRtspRealmHookParam param){ + if (logger.isDebugEnabled()) { + logger.debug("[ ZLM HOOK ] on_rtsp_realm API调用,参数:{}" , param.toString()); + } + + return HookResult.SUCCESS(); + } + + /** + * 该rtsp流是否开启rtsp专用方式的鉴权事件,开启后才会触发on_rtsp_auth事件。需要指出的是rtsp也支持url参数鉴权,它支持两种方式鉴权。 + * + */ + @ResponseBody + @PostMapping(value = "/on_rtsp_auth", produces = "application/json;charset=UTF-8") + public HookResult onRtspAuth(@RequestBody OnRtspAuthHookParam param){ + if (logger.isDebugEnabled()) { + logger.debug("[ ZLM HOOK ] on_rtsp_auth API调用,参数:{}" , param.toString()); + } + + return HookResult.SUCCESS(); + } + + /** + * shell登录鉴权,ZLMediaKit提供简单的telnet调试方式,使用telnet 127.0.0.1 9000能进入MediaServer进程的shell界面。 + * + */ + @ResponseBody + @PostMapping(value = "/on_shell_login", produces = "application/json;charset=UTF-8") + public HookResult onShellLogin(@RequestBody OnShellLoginHookParam param){ + if (logger.isDebugEnabled()) { + logger.debug("[ ZLM HOOK ] on_shell_login API调用,参数:{}" , param.toString()); + } + + return HookResult.SUCCESS(); + } + /** * rtsp/rtmp流注册或注销时触发此事件;此事件对回复不敏感。 */ @@ -703,6 +805,19 @@ public class ZLMHttpHookListener { return HookResult.SUCCESS(); } + /** + * 服务器退出报告,当服务器正常退出时触发。 + * + */ + @ResponseBody + @PostMapping(value = "/on_server_exited", produces = "application/json;charset=UTF-8") + public HookResult onServerExited(@RequestBody OnServerExitedHookParam param){ + if (logger.isDebugEnabled()) { + logger.debug("[ ZLM HOOK ] on_server_exited API调用,参数:{}" , param.toString()); + } + + return HookResult.SUCCESS(); + } /** * 发送rtp(startSendRtp)被动关闭时回调 */ diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/ServerKeepaliveData.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/ServerKeepaliveData.java index 0cc81f270..e6d1f83b6 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/ServerKeepaliveData.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/ServerKeepaliveData.java @@ -1,4 +1,166 @@ package com.genersoft.iot.vmp.media.zlm.dto; +import com.fasterxml.jackson.annotation.JsonProperty; + public class ServerKeepaliveData { + @JsonProperty("Buffer") + public int buffer; + @JsonProperty("BufferLikeString") + public int bufferLikeString; + @JsonProperty("BufferList") + public int bufferList; + @JsonProperty("BufferRaw") + public int bufferRaw; + @JsonProperty("Frame") + public int frame; + @JsonProperty("FrameImp") + public int frameImp; + @JsonProperty("MediaSource") + public int mediaSource; + @JsonProperty("MultiMediaSourceMuxer") + public int multiMediaSourceMuxer; + @JsonProperty("RtmpPacket") + public int rtmpPacket; + @JsonProperty("RtpPacket") + public int rtpPacket; + @JsonProperty("Socket") + public int socket; + @JsonProperty("TcpClient") + public int tcpClient; + @JsonProperty("TcpServer") + public int tcpServer; + @JsonProperty("TcpSession") + public int tcpSession; + @JsonProperty("UdpServer") + public int udpServer; + @JsonProperty("UdpSession") + public int udpSession; + + public int getBuffer() { + return buffer; + } + + public void setBuffer(int buffer) { + this.buffer = buffer; + } + + public int getBufferLikeString() { + return bufferLikeString; + } + + public void setBufferLikeString(int bufferLikeString) { + this.bufferLikeString = bufferLikeString; + } + + public int getBufferList() { + return bufferList; + } + + public void setBufferList(int bufferList) { + this.bufferList = bufferList; + } + + public int getBufferRaw() { + return bufferRaw; + } + + public void setBufferRaw(int bufferRaw) { + this.bufferRaw = bufferRaw; + } + + public int getFrame() { + return frame; + } + + public void setFrame(int frame) { + this.frame = frame; + } + + public int getFrameImp() { + return frameImp; + } + + public void setFrameImp(int frameImp) { + this.frameImp = frameImp; + } + + public int getMediaSource() { + return mediaSource; + } + + public void setMediaSource(int mediaSource) { + this.mediaSource = mediaSource; + } + + public int getMultiMediaSourceMuxer() { + return multiMediaSourceMuxer; + } + + public void setMultiMediaSourceMuxer(int multiMediaSourceMuxer) { + this.multiMediaSourceMuxer = multiMediaSourceMuxer; + } + + public int getRtmpPacket() { + return rtmpPacket; + } + + public void setRtmpPacket(int rtmpPacket) { + this.rtmpPacket = rtmpPacket; + } + + public int getRtpPacket() { + return rtpPacket; + } + + public void setRtpPacket(int rtpPacket) { + this.rtpPacket = rtpPacket; + } + + public int getSocket() { + return socket; + } + + public void setSocket(int socket) { + this.socket = socket; + } + + public int getTcpClient() { + return tcpClient; + } + + public void setTcpClient(int tcpClient) { + this.tcpClient = tcpClient; + } + + public int getTcpServer() { + return tcpServer; + } + + public void setTcpServer(int tcpServer) { + this.tcpServer = tcpServer; + } + + public int getTcpSession() { + return tcpSession; + } + + public void setTcpSession(int tcpSession) { + this.tcpSession = tcpSession; + } + + public int getUdpServer() { + return udpServer; + } + + public void setUdpServer(int udpServer) { + this.udpServer = udpServer; + } + + public int getUdpSession() { + return udpSession; + } + + public void setUdpSession(int udpSession) { + this.udpSession = udpSession; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/HookParam.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/HookParam.java index 46ccf2271..2a3ef7e71 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/HookParam.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/HookParam.java @@ -6,7 +6,7 @@ package com.genersoft.iot.vmp.media.zlm.dto.hook; */ public class HookParam { private String mediaServerId; - + private int hook_index; public String getMediaServerId() { return mediaServerId; } @@ -14,4 +14,12 @@ public class HookParam { public void setMediaServerId(String mediaServerId) { this.mediaServerId = mediaServerId; } + + public int getHook_index() { + return hook_index; + } + + public void setHook_index(int hook_index) { + this.hook_index = hook_index; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnFlowReportHookParam.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnFlowReportHookParam.java new file mode 100644 index 000000000..8645aa19c --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnFlowReportHookParam.java @@ -0,0 +1,125 @@ +package com.genersoft.iot.vmp.media.zlm.dto.hook; + +/** + * zlm hook事件中的on_flow_report事件的参数 + * @author AlphaWu + */ +public class OnFlowReportHookParam extends HookParam{ + private String app; + private int duration; + private String params; + private boolean player; + private String schema; + private String stream; + private int totalBytes; + private String vhost; + private String ip; + private int port; + private String id; + + public String getApp() { + return app; + } + + public void setApp(String app) { + this.app = app; + } + + public int getDuration() { + return duration; + } + + public void setDuration(int duration) { + this.duration = duration; + } + + public String getParams() { + return params; + } + + public void setParams(String params) { + this.params = params; + } + + public boolean isPlayer() { + return player; + } + + public void setPlayer(boolean player) { + this.player = player; + } + + public String getSchema() { + return schema; + } + + public void setSchema(String schema) { + this.schema = schema; + } + + public String getStream() { + return stream; + } + + public void setStream(String stream) { + this.stream = stream; + } + + public int getTotalBytes() { + return totalBytes; + } + + public void setTotalBytes(int totalBytes) { + this.totalBytes = totalBytes; + } + + public String getVhost() { + return vhost; + } + + public void setVhost(String vhost) { + this.vhost = vhost; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public String toString() { + return "OnFlowReportHookParam{" + + "mediaServerId='" + super.getMediaServerId() + '\'' + + "app='" + app + '\'' + + ", duration=" + duration + + ", params='" + params + '\'' + + ", player=" + player + + ", schema='" + schema + '\'' + + ", stream='" + stream + '\'' + + ", totalBytes=" + totalBytes + + ", vhost='" + vhost + '\'' + + ", ip='" + ip + '\'' + + ", port=" + port + + ", id='" + id + '\'' + + '}'; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnRecordHookParam.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnRecordHookParam.java new file mode 100644 index 000000000..99269618a --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnRecordHookParam.java @@ -0,0 +1,115 @@ +package com.genersoft.iot.vmp.media.zlm.dto.hook; + +/** + * zlm hook事件中的on_record_mp4和on_record_ts事件的参数 + * @author AlphaWu + */ +public class OnRecordHookParam extends HookParam{ + private String app; + private String file_name; + private String file_path; + private int file_size; + private String folder; + private int start_time; + private String stream; + private double time_len; + private String url; + private String vhost; + + public String getApp() { + return app; + } + + public void setApp(String app) { + this.app = app; + } + + public String getFile_name() { + return file_name; + } + + public void setFile_name(String file_name) { + this.file_name = file_name; + } + + public String getFile_path() { + return file_path; + } + + public void setFile_path(String file_path) { + this.file_path = file_path; + } + + public int getFile_size() { + return file_size; + } + + public void setFile_size(int file_size) { + this.file_size = file_size; + } + + public String getFolder() { + return folder; + } + + public void setFolder(String folder) { + this.folder = folder; + } + + public int getStart_time() { + return start_time; + } + + public void setStart_time(int start_time) { + this.start_time = start_time; + } + + public String getStream() { + return stream; + } + + public void setStream(String stream) { + this.stream = stream; + } + + public double getTime_len() { + return time_len; + } + + public void setTime_len(double time_len) { + this.time_len = time_len; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getVhost() { + return vhost; + } + + public void setVhost(String vhost) { + this.vhost = vhost; + } + + @Override + public String toString() { + return "OnRecordHookParam{" + + "mediaServerId='" + super.getMediaServerId() + '\'' + + "app='" + app + '\'' + + ", file_name='" + file_name + '\'' + + ", file_path='" + file_path + '\'' + + ", file_size=" + file_size + + ", folder='" + folder + '\'' + + ", start_time=" + start_time + + ", stream='" + stream + '\'' + + ", time_len=" + time_len + + ", url='" + url + '\'' + + ", vhost='" + vhost + '\'' + + '}'; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnRtspAuthHookParam.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnRtspAuthHookParam.java new file mode 100644 index 000000000..86fd855f4 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnRtspAuthHookParam.java @@ -0,0 +1,125 @@ +package com.genersoft.iot.vmp.media.zlm.dto.hook; + +/** + * zlm hook事件中的on_rtsp_auth事件的参数 + * @author AlphaWu + */ +public class OnRtspAuthHookParam extends HookParam{ + private String app; + private String id; + private String ip; + private boolean must_no_encrypt; + private String params; + private int port; + private String realm; + private String schema; + private String stream; + private String user_name; + private String vhost; + + public String getApp() { + return app; + } + + public void setApp(String app) { + this.app = app; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public boolean isMust_no_encrypt() { + return must_no_encrypt; + } + + public void setMust_no_encrypt(boolean must_no_encrypt) { + this.must_no_encrypt = must_no_encrypt; + } + + public String getParams() { + return params; + } + + public void setParams(String params) { + this.params = params; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getRealm() { + return realm; + } + + public void setRealm(String realm) { + this.realm = realm; + } + + public String getSchema() { + return schema; + } + + public void setSchema(String schema) { + this.schema = schema; + } + + public String getStream() { + return stream; + } + + public void setStream(String stream) { + this.stream = stream; + } + + public String getUser_name() { + return user_name; + } + + public void setUser_name(String user_name) { + this.user_name = user_name; + } + + public String getVhost() { + return vhost; + } + + public void setVhost(String vhost) { + this.vhost = vhost; + } + + @Override + public String toString() { + return "OnRtspAuthHookParam{" + + "mediaServerId='" + super.getMediaServerId() + '\'' + + "app='" + app + '\'' + + ", id='" + id + '\'' + + ", ip='" + ip + '\'' + + ", must_no_encrypt=" + must_no_encrypt + + ", params='" + params + '\'' + + ", port=" + port + + ", realm='" + realm + '\'' + + ", schema='" + schema + '\'' + + ", stream='" + stream + '\'' + + ", user_name='" + user_name + '\'' + + ", vhost='" + vhost + '\'' + + '}'; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnRtspRealmHookParam.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnRtspRealmHookParam.java new file mode 100644 index 000000000..bd13b24f1 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnRtspRealmHookParam.java @@ -0,0 +1,95 @@ +package com.genersoft.iot.vmp.media.zlm.dto.hook; + +/** + * zlm hook事件中的on_rtsp_realm事件的参数 + * @author AlphaWu + */ +public class OnRtspRealmHookParam extends HookParam{ + private String app; + private String id; + private String ip; + private String params; + private int port; + private String schema; + private String stream; + private String vhost; + + public String getApp() { + return app; + } + + public void setApp(String app) { + this.app = app; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getParams() { + return params; + } + + public void setParams(String params) { + this.params = params; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getSchema() { + return schema; + } + + public void setSchema(String schema) { + this.schema = schema; + } + + public String getStream() { + return stream; + } + + public void setStream(String stream) { + this.stream = stream; + } + + public String getVhost() { + return vhost; + } + + public void setVhost(String vhost) { + this.vhost = vhost; + } + + @Override + public String toString() { + return "OnRtspRealmHookParam{" + + "mediaServerId='" + super.getMediaServerId() + '\'' + + "app='" + app + '\'' + + ", id='" + id + '\'' + + ", ip='" + ip + '\'' + + ", params='" + params + '\'' + + ", port=" + port + + ", schema='" + schema + '\'' + + ", stream='" + stream + '\'' + + ", vhost='" + vhost + '\'' + + '}'; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnServerExitedHookParam.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnServerExitedHookParam.java new file mode 100644 index 000000000..28419ecd9 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnServerExitedHookParam.java @@ -0,0 +1,9 @@ +package com.genersoft.iot.vmp.media.zlm.dto.hook; + +/** + * zlm hook事件中的on_server_exited事件的参数 + * @author AlphaWu + */ +public class OnServerExitedHookParam extends HookParam{ + +} diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnServerKeepaliveHookParam.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnServerKeepaliveHookParam.java index 5439f20f2..c12521022 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnServerKeepaliveHookParam.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnServerKeepaliveHookParam.java @@ -1,9 +1,10 @@ package com.genersoft.iot.vmp.media.zlm.dto.hook; +import com.alibaba.fastjson2.JSONObject; import com.genersoft.iot.vmp.media.zlm.dto.ServerKeepaliveData; /** - * zlm hook事件中的on_play事件的参数 + * zlm hook事件中的 on_server_keepalive 事件的参数 * @author lin */ public class OnServerKeepaliveHookParam extends HookParam{ @@ -20,8 +21,6 @@ public class OnServerKeepaliveHookParam extends HookParam{ @Override public String toString() { - return "OnServerKeepaliveHookParam{" + - "data=" + data + - '}'; + return JSONObject.toJSONString(this); } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnShellLoginHookParam.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnShellLoginHookParam.java new file mode 100644 index 000000000..5875e4c43 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnShellLoginHookParam.java @@ -0,0 +1,65 @@ +package com.genersoft.iot.vmp.media.zlm.dto.hook; + +/** + * zlm hook事件中的on_shell_login事件的参数 + * @author AlphaWu + */ +public class OnShellLoginHookParam extends HookParam{ + private String id; + private String ip; + private String passwd; + private float port; + private String user_name; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getPasswd() { + return passwd; + } + + public void setPasswd(String passwd) { + this.passwd = passwd; + } + + public float getPort() { + return port; + } + + public void setPort(float port) { + this.port = port; + } + + public String getUser_name() { + return user_name; + } + + public void setUser_name(String user_name) { + this.user_name = user_name; + } + + @Override + public String toString() { + return "OnShellLoginHookParam{" + + "mediaServerId='" + super.getMediaServerId() + '\'' + + "id='" + id + '\'' + + ", ip='" + ip + '\'' + + ", passwd='" + passwd + '\'' + + ", port=" + port + + ", user_name='" + user_name + '\'' + + '}'; + } +}