From 431d6f90cbe89570c281bcdfa6f5e5771e8d30eb Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Mon, 21 Aug 2023 02:22:45 +0800 Subject: [PATCH] zlm getMediaList api --- .../gb28181/media/dto/media/GetMediaList.java | 29 +++++++++ .../media/dto/media/MediaOriginSock.java | 18 ++++++ .../gb28181/media/dto/media/MediaResp.java | 63 +++++++++++++++++++ .../gb28181/media/dto/media/MediaTrack.java | 63 +++++++++++++++++++ .../media/proxy/ZlmMediaHttpClient.java | 5 ++ .../gb28181/media/proxy/ZlmMediaService.java | 11 +++- .../gb28181/test/MediaServiceTest.java | 12 ++++ 7 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/GetMediaList.java create mode 100644 zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/MediaOriginSock.java create mode 100644 zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/MediaResp.java create mode 100644 zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/MediaTrack.java diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/GetMediaList.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/GetMediaList.java new file mode 100644 index 0000000..a841bbd --- /dev/null +++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/GetMediaList.java @@ -0,0 +1,29 @@ +package cn.skcks.docking.gb28181.media.dto.media; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class GetMediaList { + /** + * 筛选协议,例如 rtsp或rtmp + */ + private String schema; + /** + * 筛选虚拟主机,例如__defaultVhost__ + */ + private String vhost; + /** + * 筛选应用名,例如 live + */ + private String app; + /** + * 筛选流id,例如 test + */ + private String stream; +} diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/MediaOriginSock.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/MediaOriginSock.java new file mode 100644 index 0000000..b231375 --- /dev/null +++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/MediaOriginSock.java @@ -0,0 +1,18 @@ +package cn.skcks.docking.gb28181.media.dto.media; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.Data; + +/** + * 客户端和服务器网络信息 + */ +@Data +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class MediaOriginSock { + private String identifier; + private String localIp; + private Integer localPort; + private String peerIp; + private Integer peerPort; +} diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/MediaResp.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/MediaResp.java new file mode 100644 index 0000000..35f8d7a --- /dev/null +++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/MediaResp.java @@ -0,0 +1,63 @@ +package cn.skcks.docking.gb28181.media.dto.media; + +import lombok.Data; + +import java.util.List; + +@Data +public class MediaResp { + /** + * 应用名 + */ + private String app; + /** + * 本协议观看人数 + */ + private Long readerCount; + /** + * 观看总人数,包括hls/rtsp/rtmp/http-flv/ws-flv + */ + private Long totalReaderCount; + /** + * 协议 + */ + private String schema; + /** + * 流id + */ + private String stream; + /** + * 客户端和服务器网络信息 + */ + private MediaOriginSock originSock; + /** + *

产生源类型

+ * unknown = 0,rtmp_push=1,rtsp_push=2,rtp_push=3,pull=4,ffmpeg_pull=5,mp4_vod=6,device_chn=7 + */ + private Integer originType; + private String originTypeStr; + /** + * 产生源的url + */ + private String originUrl; + /** + * GMT unix系统时间戳,单位秒 + */ + private Long createStamp; + /** + * 存活时间,单位秒 + */ + private Long aliveSecond; + /** + * 数据产生速度,单位byte/s + */ + private Long bytesSpeed; + /** + * 音视频轨道 + */ + private List tracks; + /** + * 虚拟主机名 + */ + private String vhost; +} diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/MediaTrack.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/MediaTrack.java new file mode 100644 index 0000000..f51996f --- /dev/null +++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/media/MediaTrack.java @@ -0,0 +1,63 @@ +package cn.skcks.docking.gb28181.media.dto.media; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.Data; + +@Data +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class MediaTrack { + /** + * 音频通道数 + */ + private Integer channels; + /** + * H264 = 0, H265 = 1, AAC = 2, G711A = 3, G711U = 4 + */ + private Integer codecId; + /** + * 编码类型名称 + */ + private String codecIdName; + /** + * Video = 0, Audio = 1 + */ + private Integer codecType; + private Integer fps; + /** + * 累计接收帧数,不包含sei/aud/sps/pps等不能解码的帧 + */ + private Long frames; + /** + * gop间隔时间,单位毫秒 + */ + private Long gopIntervalMs; + /** + * gop大小,单位帧数 + */ + private Long gopSize; + /** + * 累计接收关键帧数 + */ + private Long keyFrames; + /** + * 轨道是否准备就绪 + */ + private Boolean ready; + /** + * 视频高 + */ + private Integer height; + /** + * 视频宽 + */ + private Integer width; + /** + * 音频采样位数 + */ + private Integer sampleBit; + /** + * 音频采样率 + */ + private Integer sampleRate; +} diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaHttpClient.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaHttpClient.java index 66112ba..0d03732 100644 --- a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaHttpClient.java +++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaHttpClient.java @@ -1,6 +1,8 @@ package cn.skcks.docking.gb28181.media.proxy; import cn.skcks.docking.gb28181.media.dto.config.ServerConfig; +import cn.skcks.docking.gb28181.media.dto.media.GetMediaList; +import cn.skcks.docking.gb28181.media.dto.media.MediaResp; import cn.skcks.docking.gb28181.media.dto.proxy.*; import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse; import cn.skcks.docking.gb28181.media.dto.rtp.*; @@ -69,4 +71,7 @@ public interface ZlmMediaHttpClient { @GetMapping("/index/api/delStreamProxy") ZlmResponse delStreamProxy(@RequestParam String secret, @RequestParam String key); + + @PostMapping("/index/api/getMediaList") + ZlmResponse> getMediaList(@RequestParam String secret,@RequestBody GetMediaList params); } diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaService.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaService.java index b0f0f88..5dda05f 100644 --- a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaService.java +++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaService.java @@ -1,6 +1,8 @@ package cn.skcks.docking.gb28181.media.proxy; import cn.skcks.docking.gb28181.media.dto.config.ServerConfig; +import cn.skcks.docking.gb28181.media.dto.media.GetMediaList; +import cn.skcks.docking.gb28181.media.dto.media.MediaResp; import cn.skcks.docking.gb28181.media.dto.proxy.*; import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse; import cn.skcks.docking.gb28181.media.dto.rtp.*; @@ -86,7 +88,7 @@ public class ZlmMediaService { *

(可以使用close_streams接口关闭源直播流也可以停止推流)

* @param key addStreamPusherProxy 接口返回的key */ - public ZlmResponse delStreamPusherProxy(@RequestParam String key) { + public ZlmResponse delStreamPusherProxy(String key) { return exchange.delStreamPusherProxy(secret, key); } @@ -144,5 +146,12 @@ public class ZlmMediaService { public ZlmResponse delStreamProxy(String key){ return exchange.delStreamProxy(secret, key); } + + /** + * 功能:获取流列表,可选筛选参数 + */ + public ZlmResponse> getMediaList(GetMediaList params){ + return exchange.getMediaList(secret, params); + } } diff --git a/zlmediakit-service/src/test/java/cn/skcks/docking/gb28181/test/MediaServiceTest.java b/zlmediakit-service/src/test/java/cn/skcks/docking/gb28181/test/MediaServiceTest.java index 18f6920..175eed7 100644 --- a/zlmediakit-service/src/test/java/cn/skcks/docking/gb28181/test/MediaServiceTest.java +++ b/zlmediakit-service/src/test/java/cn/skcks/docking/gb28181/test/MediaServiceTest.java @@ -10,6 +10,8 @@ import cn.skcks.docking.gb28181.media.config.ZlmMediaConfig; import cn.skcks.docking.gb28181.media.dto.config.FFMpegConfig; import cn.skcks.docking.gb28181.media.dto.config.HookConfig; import cn.skcks.docking.gb28181.media.dto.config.ServerConfig; +import cn.skcks.docking.gb28181.media.dto.media.GetMediaList; +import cn.skcks.docking.gb28181.media.dto.media.MediaResp; import cn.skcks.docking.gb28181.media.dto.proxy.*; import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse; import cn.skcks.docking.gb28181.media.dto.response.ZlmResponseConvertor; @@ -201,4 +203,14 @@ public class MediaServiceTest { ZlmResponse delStreamProxyRespZlmResponse = zlmMediaService.delStreamProxy(key); log.info("{}", delStreamProxyRespZlmResponse); } + + @Test + void getMediaListTest() { + ZlmResponse> mediaList = zlmMediaService.getMediaList(GetMediaList.builder().build()); + List data = mediaList.getData(); + log.info("流数量 => {}", data.size()); + data.forEach((item) -> { + log.info("\n{}", JsonUtils.toJson(item)); + }); + } }