Commit 676a722241116fd53e9f6063484a966dcabe5b48
1 parent
91e49745
修复心跳异常,支持通道列表,推流列表,拉流代理列表直接查看对应的云端录像,兼容大于INT的ssrc的格式化
Showing
3 changed files
with
297 additions
and
0 deletions
src/main/java/com/genersoft/iot/vmp/vmanager/bean/PageInfo.java
0 → 100755
| 1 | +package com.genersoft.iot.vmp.vmanager.bean; | |
| 2 | + | |
| 3 | +import java.util.ArrayList; | |
| 4 | +import java.util.List; | |
| 5 | + | |
| 6 | +public class PageInfo<T> { | |
| 7 | + //当前页 | |
| 8 | + private int pageNum; | |
| 9 | + //每页的数量 | |
| 10 | + private int pageSize; | |
| 11 | + //当前页的数量 | |
| 12 | + private int size; | |
| 13 | + //总页数 | |
| 14 | + private int pages; | |
| 15 | + //总数 | |
| 16 | + private int total; | |
| 17 | + | |
| 18 | + private List<T> resultData; | |
| 19 | + | |
| 20 | + private List<T> list; | |
| 21 | + | |
| 22 | + public PageInfo(List<T> resultData) { | |
| 23 | + this.resultData = resultData; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public PageInfo() { | |
| 27 | + } | |
| 28 | + | |
| 29 | + public void startPage(int page, int count) { | |
| 30 | + if (count <= 0) count = 10; | |
| 31 | + if (page <= 0) page = 1; | |
| 32 | + this.pageNum = page; | |
| 33 | + this.pageSize = count; | |
| 34 | + this.total = resultData.size(); | |
| 35 | + | |
| 36 | + this.pages = total % count == 0 ? total / count : total / count + 1; | |
| 37 | + int fromIndx = (page - 1) * count; | |
| 38 | + if (fromIndx > this.total - 1) { | |
| 39 | + this.list = new ArrayList<>(); | |
| 40 | + this.size = 0; | |
| 41 | + return; | |
| 42 | + } | |
| 43 | + | |
| 44 | + int toIndx = page * count; | |
| 45 | + if (toIndx > this.total) { | |
| 46 | + toIndx = this.total; | |
| 47 | + } | |
| 48 | + this.list = this.resultData.subList(fromIndx, toIndx); | |
| 49 | + this.size = this.list.size(); | |
| 50 | + } | |
| 51 | + | |
| 52 | + public int getPageNum() { | |
| 53 | + return pageNum; | |
| 54 | + } | |
| 55 | + | |
| 56 | + public void setPageNum(int pageNum) { | |
| 57 | + this.pageNum = pageNum; | |
| 58 | + } | |
| 59 | + | |
| 60 | + public int getPageSize() { | |
| 61 | + return pageSize; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public void setPageSize(int pageSize) { | |
| 65 | + this.pageSize = pageSize; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public int getSize() { | |
| 69 | + return size; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public void setSize(int size) { | |
| 73 | + this.size = size; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public int getPages() { | |
| 77 | + return pages; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public void setPages(int pages) { | |
| 81 | + this.pages = pages; | |
| 82 | + } | |
| 83 | + | |
| 84 | + public int getTotal() { | |
| 85 | + return total; | |
| 86 | + } | |
| 87 | + | |
| 88 | + public void setTotal(int total) { | |
| 89 | + this.total = total; | |
| 90 | + } | |
| 91 | + | |
| 92 | + public List<T> getList() { | |
| 93 | + return list; | |
| 94 | + } | |
| 95 | + | |
| 96 | + public void setList(List<T> list) { | |
| 97 | + this.list = list; | |
| 98 | + } | |
| 99 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/bean/RecordFile.java
0 → 100755
| 1 | +package com.genersoft.iot.vmp.vmanager.bean; | |
| 2 | + | |
| 3 | +public class RecordFile { | |
| 4 | + private String app; | |
| 5 | + private String stream; | |
| 6 | + | |
| 7 | + private String fileName; | |
| 8 | + | |
| 9 | + private String mediaServerId; | |
| 10 | + | |
| 11 | + private String date; | |
| 12 | + | |
| 13 | + | |
| 14 | + public String getApp() { | |
| 15 | + return app; | |
| 16 | + } | |
| 17 | + | |
| 18 | + public void setApp(String app) { | |
| 19 | + this.app = app; | |
| 20 | + } | |
| 21 | + | |
| 22 | + public String getStream() { | |
| 23 | + return stream; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public void setStream(String stream) { | |
| 27 | + this.stream = stream; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public String getFileName() { | |
| 31 | + return fileName; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public void setFileName(String fileName) { | |
| 35 | + this.fileName = fileName; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public String getMediaServerId() { | |
| 39 | + return mediaServerId; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void setMediaServerId(String mediaServerId) { | |
| 43 | + this.mediaServerId = mediaServerId; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public String getDate() { | |
| 47 | + return date; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void setDate(String date) { | |
| 51 | + this.date = date; | |
| 52 | + } | |
| 53 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java
0 → 100755
| 1 | +package com.genersoft.iot.vmp.vmanager.cloudRecord; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.conf.DynamicTask; | |
| 4 | +import com.genersoft.iot.vmp.conf.UserSetting; | |
| 5 | +import com.genersoft.iot.vmp.conf.exception.ControllerException; | |
| 6 | +import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager; | |
| 7 | +import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory; | |
| 8 | +import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | |
| 9 | +import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | |
| 10 | +import com.genersoft.iot.vmp.service.IMediaServerService; | |
| 11 | +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; | |
| 12 | +import com.genersoft.iot.vmp.vmanager.bean.PageInfo; | |
| 13 | +import com.genersoft.iot.vmp.vmanager.bean.RecordFile; | |
| 14 | +import io.swagger.v3.oas.annotations.Operation; | |
| 15 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 16 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 17 | +import org.apache.commons.lang3.ObjectUtils; | |
| 18 | +import org.slf4j.Logger; | |
| 19 | +import org.slf4j.LoggerFactory; | |
| 20 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 21 | +import org.springframework.data.redis.core.RedisTemplate; | |
| 22 | +import org.springframework.web.bind.annotation.*; | |
| 23 | + | |
| 24 | +import java.util.ArrayList; | |
| 25 | +import java.util.Calendar; | |
| 26 | +import java.util.List; | |
| 27 | + | |
| 28 | +@SuppressWarnings("rawtypes") | |
| 29 | +@Tag(name = "云端录像接口") | |
| 30 | + | |
| 31 | +@RestController | |
| 32 | +@RequestMapping("/api/cloud/record") | |
| 33 | +public class CloudRecordController { | |
| 34 | + | |
| 35 | + @Autowired | |
| 36 | + private ZLMServerFactory zlmServerFactory; | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + private SendRtpPortManager sendRtpPortManager; | |
| 40 | + | |
| 41 | + private final static Logger logger = LoggerFactory.getLogger(CloudRecordController.class); | |
| 42 | + | |
| 43 | + @Autowired | |
| 44 | + private ZlmHttpHookSubscribe hookSubscribe; | |
| 45 | + | |
| 46 | + @Autowired | |
| 47 | + private IMediaServerService mediaServerService; | |
| 48 | + | |
| 49 | + @Autowired | |
| 50 | + private UserSetting userSetting; | |
| 51 | + | |
| 52 | + @Autowired | |
| 53 | + private DynamicTask dynamicTask; | |
| 54 | + | |
| 55 | + @Autowired | |
| 56 | + private RedisTemplate<Object, Object> redisTemplate; | |
| 57 | + | |
| 58 | + @ResponseBody | |
| 59 | + @GetMapping("/date/list") | |
| 60 | + @Operation(summary = "查询存在云端录像的日期") | |
| 61 | + @Parameter(name = "app", description = "应用名", required = true) | |
| 62 | + @Parameter(name = "stream", description = "流ID", required = true) | |
| 63 | + @Parameter(name = "year", description = "年,置空则查询当年", required = false) | |
| 64 | + @Parameter(name = "month", description = "月,置空则查询当月", required = false) | |
| 65 | + @Parameter(name = "mediaServerId", description = "流媒体ID,置空则查询全部", required = false) | |
| 66 | + public List<String> openRtpServer( | |
| 67 | + @RequestParam String app, | |
| 68 | + @RequestParam String stream, | |
| 69 | + @RequestParam(required = false) int year, | |
| 70 | + @RequestParam(required = false) int month, | |
| 71 | + @RequestParam(required = false) String mediaServerId | |
| 72 | + | |
| 73 | + ) { | |
| 74 | + logger.info("[云端录像] 查询存在云端录像的日期 app->{}, stream->{}, mediaServerId->{}, year->{}, month->{}", | |
| 75 | + app, stream, mediaServerId, year, month); | |
| 76 | + Calendar calendar = Calendar.getInstance(); | |
| 77 | + if (ObjectUtils.isEmpty(year)) { | |
| 78 | + year = calendar.get(Calendar.YEAR); | |
| 79 | + } | |
| 80 | + if (ObjectUtils.isEmpty(month)) { | |
| 81 | + month = calendar.get(Calendar.MONTH) + 1; | |
| 82 | + } | |
| 83 | + List<MediaServerItem> mediaServerItems; | |
| 84 | + if (!ObjectUtils.isEmpty(mediaServerId)) { | |
| 85 | + mediaServerItems = new ArrayList<>(); | |
| 86 | + MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId); | |
| 87 | + if (mediaServerItem == null) { | |
| 88 | + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到流媒体: " + mediaServerId); | |
| 89 | + } | |
| 90 | + mediaServerItems.add(mediaServerItem); | |
| 91 | + } else { | |
| 92 | + mediaServerItems = mediaServerService.getAll(); | |
| 93 | + } | |
| 94 | + if (mediaServerItems.isEmpty()) { | |
| 95 | + return new ArrayList<>(); | |
| 96 | + } | |
| 97 | + | |
| 98 | + return mediaServerService.getRecordDates(app, stream, year, month, mediaServerItems); | |
| 99 | + } | |
| 100 | + | |
| 101 | + @ResponseBody | |
| 102 | + @GetMapping("/list") | |
| 103 | + @Operation(summary = "分页查询云端录像") | |
| 104 | + @Parameter(name = "app", description = "应用名", required = true) | |
| 105 | + @Parameter(name = "stream", description = "流ID", required = true) | |
| 106 | + @Parameter(name = "page", description = "当前页", required = false) | |
| 107 | + @Parameter(name = "count", description = "每页查询数量", required = false) | |
| 108 | + @Parameter(name = "startTime", description = "开始时间(yyyy-MM-dd HH:mm:ss)", required = true) | |
| 109 | + @Parameter(name = "endTime", description = "结束时间(yyyy-MM-dd HH:mm:ss)", required = true) | |
| 110 | + @Parameter(name = "mediaServerId", description = "流媒体ID,置空则查询全部流媒体", required = false) | |
| 111 | + public PageInfo<RecordFile> openRtpServer( | |
| 112 | + @RequestParam String app, | |
| 113 | + @RequestParam String stream, | |
| 114 | + @RequestParam int page, | |
| 115 | + @RequestParam int count, | |
| 116 | + @RequestParam String startTime, | |
| 117 | + @RequestParam String endTime, | |
| 118 | + @RequestParam(required = false) String mediaServerId | |
| 119 | + | |
| 120 | + ) { | |
| 121 | + logger.info("[云端录像] 查询 app->{}, stream->{}, mediaServerId->{}, page->{}, count->{}, startTime->{}, endTime->{}", | |
| 122 | + app, stream, mediaServerId, page, count, startTime, endTime); | |
| 123 | + | |
| 124 | + List<MediaServerItem> mediaServerItems; | |
| 125 | + if (!ObjectUtils.isEmpty(mediaServerId)) { | |
| 126 | + mediaServerItems = new ArrayList<>(); | |
| 127 | + MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId); | |
| 128 | + if (mediaServerItem == null) { | |
| 129 | + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到流媒体: " + mediaServerId); | |
| 130 | + } | |
| 131 | + mediaServerItems.add(mediaServerItem); | |
| 132 | + } else { | |
| 133 | + mediaServerItems = mediaServerService.getAll(); | |
| 134 | + } | |
| 135 | + if (mediaServerItems.isEmpty()) { | |
| 136 | + return new PageInfo<>(); | |
| 137 | + } | |
| 138 | + List<RecordFile> records = mediaServerService.getRecords(app, stream, startTime, endTime, mediaServerItems); | |
| 139 | + PageInfo<RecordFile> pageInfo = new PageInfo<>(records); | |
| 140 | + pageInfo.startPage(page, count); | |
| 141 | + return pageInfo; | |
| 142 | + } | |
| 143 | + | |
| 144 | + | |
| 145 | +} | ... | ... |