Commit adbddd5eb0c016f1a00fd9db7b05502f4012c41d
Committed by
GitHub
Merge pull request #837 from keDaYao/featur-jt1078
新增1078信令,修复BUG
Showing
12 changed files
with
744 additions
and
13 deletions
src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java
| 1 | package com.genersoft.iot.vmp.jt1078.cmd; | 1 | package com.genersoft.iot.vmp.jt1078.cmd; |
| 2 | 2 | ||
| 3 | import com.genersoft.iot.vmp.jt1078.proc.entity.Cmd; | 3 | import com.genersoft.iot.vmp.jt1078.proc.entity.Cmd; |
| 4 | -import com.genersoft.iot.vmp.jt1078.proc.response.J9101; | ||
| 5 | -import com.genersoft.iot.vmp.jt1078.proc.response.J9102; | 4 | +import com.genersoft.iot.vmp.jt1078.proc.response.*; |
| 6 | import com.genersoft.iot.vmp.jt1078.session.SessionManager; | 5 | import com.genersoft.iot.vmp.jt1078.session.SessionManager; |
| 7 | 6 | ||
| 8 | import java.util.Random; | 7 | import java.util.Random; |
| @@ -16,6 +15,15 @@ public class JT1078Template { | @@ -16,6 +15,15 @@ public class JT1078Template { | ||
| 16 | 15 | ||
| 17 | private final Random random = new Random(); | 16 | private final Random random = new Random(); |
| 18 | 17 | ||
| 18 | + private static final String H9101 = "9101"; | ||
| 19 | + private static final String H9102 = "9102"; | ||
| 20 | + private static final String H9201 = "9201"; | ||
| 21 | + private static final String H9202 = "9202"; | ||
| 22 | + private static final String H9205 = "9205"; | ||
| 23 | + | ||
| 24 | + private static final String H0001 = "0001"; | ||
| 25 | + private static final String H1205 = "1205"; | ||
| 26 | + | ||
| 19 | /** | 27 | /** |
| 20 | * 开启直播视频 | 28 | * 开启直播视频 |
| 21 | * | 29 | * |
| @@ -26,8 +34,8 @@ public class JT1078Template { | @@ -26,8 +34,8 @@ public class JT1078Template { | ||
| 26 | Cmd cmd = new Cmd.Builder() | 34 | Cmd cmd = new Cmd.Builder() |
| 27 | .setDevId(devId) | 35 | .setDevId(devId) |
| 28 | .setPackageNo(randomInt()) | 36 | .setPackageNo(randomInt()) |
| 29 | - .setMsgId("9101") | ||
| 30 | - .setRespId("0001") | 37 | + .setMsgId(H9101) |
| 38 | + .setRespId(H0001) | ||
| 31 | .setRs(j9101) | 39 | .setRs(j9101) |
| 32 | .build(); | 40 | .build(); |
| 33 | return SessionManager.INSTANCE.request(cmd, timeOut); | 41 | return SessionManager.INSTANCE.request(cmd, timeOut); |
| @@ -43,13 +51,64 @@ public class JT1078Template { | @@ -43,13 +51,64 @@ public class JT1078Template { | ||
| 43 | Cmd cmd = new Cmd.Builder() | 51 | Cmd cmd = new Cmd.Builder() |
| 44 | .setDevId(devId) | 52 | .setDevId(devId) |
| 45 | .setPackageNo(randomInt()) | 53 | .setPackageNo(randomInt()) |
| 46 | - .setMsgId("9102") | ||
| 47 | - .setRespId("0001") | 54 | + .setMsgId(H9102) |
| 55 | + .setRespId(H0001) | ||
| 48 | .setRs(j9102) | 56 | .setRs(j9102) |
| 49 | .build(); | 57 | .build(); |
| 50 | return SessionManager.INSTANCE.request(cmd, timeOut); | 58 | return SessionManager.INSTANCE.request(cmd, timeOut); |
| 51 | } | 59 | } |
| 52 | 60 | ||
| 61 | + /** | ||
| 62 | + * 查询音视频列表 | ||
| 63 | + * | ||
| 64 | + * @param devId 设备号 | ||
| 65 | + * @param j9205 查询音视频列表 | ||
| 66 | + */ | ||
| 67 | + public String queryBackTime(String devId, J9205 j9205, Integer timeOut) { | ||
| 68 | + Cmd cmd = new Cmd.Builder() | ||
| 69 | + .setDevId(devId) | ||
| 70 | + .setPackageNo(randomInt()) | ||
| 71 | + .setMsgId(H9205) | ||
| 72 | + .setRespId(H1205) | ||
| 73 | + .setRs(j9205) | ||
| 74 | + .build(); | ||
| 75 | + return SessionManager.INSTANCE.request(cmd, timeOut); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * 开启视频回放 | ||
| 80 | + * | ||
| 81 | + * @param devId 设备号 | ||
| 82 | + * @param j9201 视频回放参数 | ||
| 83 | + */ | ||
| 84 | + public String startBackLive(String devId, J9201 j9201, Integer timeOut) { | ||
| 85 | + Cmd cmd = new Cmd.Builder() | ||
| 86 | + .setDevId(devId) | ||
| 87 | + .setPackageNo(randomInt()) | ||
| 88 | + .setMsgId(H9201) | ||
| 89 | + .setRespId(H1205) | ||
| 90 | + .setRs(j9201) | ||
| 91 | + .build(); | ||
| 92 | + return SessionManager.INSTANCE.request(cmd, timeOut); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 视频回放控制 | ||
| 97 | + * | ||
| 98 | + * @param devId 设备号 | ||
| 99 | + * @param j9202 控制视频回放参数 | ||
| 100 | + */ | ||
| 101 | + public String controlBackLive(String devId, J9202 j9202, Integer timeOut) { | ||
| 102 | + Cmd cmd = new Cmd.Builder() | ||
| 103 | + .setDevId(devId) | ||
| 104 | + .setPackageNo(randomInt()) | ||
| 105 | + .setMsgId(H9202) | ||
| 106 | + .setRespId(H0001) | ||
| 107 | + .setRs(j9202) | ||
| 108 | + .build(); | ||
| 109 | + return SessionManager.INSTANCE.request(cmd, timeOut); | ||
| 110 | + } | ||
| 111 | + | ||
| 53 | private Long randomInt() { | 112 | private Long randomInt() { |
| 54 | return (long) random.nextInt(1000) + 1; | 113 | return (long) random.nextInt(1000) + 1; |
| 55 | } | 114 | } |
src/main/java/com/genersoft/iot/vmp/jt1078/config/TcpAutoConfiguration.java renamed to src/main/java/com/genersoft/iot/vmp/jt1078/config/JT1078AutoConfiguration.java
| @@ -16,7 +16,7 @@ import org.springframework.core.annotation.Order; | @@ -16,7 +16,7 @@ import org.springframework.core.annotation.Order; | ||
| 16 | @Order(Integer.MIN_VALUE) | 16 | @Order(Integer.MIN_VALUE) |
| 17 | @Configuration | 17 | @Configuration |
| 18 | @ConditionalOnProperty(value = "jt1078.enable", havingValue = "true") | 18 | @ConditionalOnProperty(value = "jt1078.enable", havingValue = "true") |
| 19 | -public class TcpAutoConfiguration { | 19 | +public class JT1078AutoConfiguration { |
| 20 | 20 | ||
| 21 | @Bean(initMethod = "start", destroyMethod = "stop") | 21 | @Bean(initMethod = "start", destroyMethod = "stop") |
| 22 | public TcpServer jt1078Server(@Value("${jt1078.port}") Integer port) { | 22 | public TcpServer jt1078Server(@Value("${jt1078.port}") Integer port) { |
src/main/java/com/genersoft/iot/vmp/jt1078/config/JT1078Controller.java
| 1 | package com.genersoft.iot.vmp.jt1078.config; | 1 | package com.genersoft.iot.vmp.jt1078.config; |
| 2 | 2 | ||
| 3 | import com.genersoft.iot.vmp.jt1078.cmd.JT1078Template; | 3 | import com.genersoft.iot.vmp.jt1078.cmd.JT1078Template; |
| 4 | -import com.genersoft.iot.vmp.jt1078.proc.response.J9101; | 4 | +import com.genersoft.iot.vmp.jt1078.proc.response.*; |
| 5 | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | 5 | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; |
| 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| 7 | import org.springframework.web.bind.annotation.GetMapping; | 7 | import org.springframework.web.bind.annotation.GetMapping; |
| @@ -26,6 +26,9 @@ public class JT1078Controller { | @@ -26,6 +26,9 @@ public class JT1078Controller { | ||
| 26 | @Resource | 26 | @Resource |
| 27 | JT1078Template jt1078Template; | 27 | JT1078Template jt1078Template; |
| 28 | 28 | ||
| 29 | + /** | ||
| 30 | + * jt1078Template 调用示例 | ||
| 31 | + */ | ||
| 29 | @GetMapping("/start/live/{deviceId}/{channelId}") | 32 | @GetMapping("/start/live/{deviceId}/{channelId}") |
| 30 | public WVPResult<?> startLive(@PathVariable String deviceId, @PathVariable String channelId) { | 33 | public WVPResult<?> startLive(@PathVariable String deviceId, @PathVariable String channelId) { |
| 31 | J9101 j9101 = new J9101(); | 34 | J9101 j9101 = new J9101(); |
| @@ -35,12 +38,14 @@ public class JT1078Controller { | @@ -35,12 +38,14 @@ public class JT1078Controller { | ||
| 35 | j9101.setTcpPort(7618); | 38 | j9101.setTcpPort(7618); |
| 36 | j9101.setUdpPort(7618); | 39 | j9101.setUdpPort(7618); |
| 37 | j9101.setType(0); | 40 | j9101.setType(0); |
| 38 | - | 41 | + // TODO 分配ZLM,获取IP、端口 |
| 39 | String s = jt1078Template.startLive(deviceId, j9101, 6); | 42 | String s = jt1078Template.startLive(deviceId, j9101, 6); |
| 43 | + // TODO 设备响应成功后,封装拉流结果集 | ||
| 40 | WVPResult<String> wvpResult = new WVPResult<>(); | 44 | WVPResult<String> wvpResult = new WVPResult<>(); |
| 41 | wvpResult.setCode(200); | 45 | wvpResult.setCode(200); |
| 42 | wvpResult.setData(String.format("http://192.168.1.1/rtp/%s_%s.live.mp4", deviceId, channelId)); | 46 | wvpResult.setData(String.format("http://192.168.1.1/rtp/%s_%s.live.mp4", deviceId, channelId)); |
| 43 | return wvpResult; | 47 | return wvpResult; |
| 44 | } | 48 | } |
| 49 | + | ||
| 45 | } | 50 | } |
| 46 | 51 |
src/main/java/com/genersoft/iot/vmp/jt1078/proc/entity/Cmd.java
| @@ -102,4 +102,15 @@ public class Cmd { | @@ -102,4 +102,15 @@ public class Cmd { | ||
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | + | ||
| 106 | + @Override | ||
| 107 | + public String toString() { | ||
| 108 | + return "Cmd{" + | ||
| 109 | + "devId='" + devId + '\'' + | ||
| 110 | + ", packageNo=" + packageNo + | ||
| 111 | + ", msgId='" + msgId + '\'' + | ||
| 112 | + ", respId='" + respId + '\'' + | ||
| 113 | + ", rs=" + rs + | ||
| 114 | + '}'; | ||
| 115 | + } | ||
| 105 | } | 116 | } |
src/main/java/com/genersoft/iot/vmp/jt1078/proc/request/J1205.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.jt1078.proc.request; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson2.JSON; | ||
| 4 | +import com.genersoft.iot.vmp.jt1078.annotation.MsgId; | ||
| 5 | +import com.genersoft.iot.vmp.jt1078.proc.Header; | ||
| 6 | +import com.genersoft.iot.vmp.jt1078.proc.response.J8001; | ||
| 7 | +import com.genersoft.iot.vmp.jt1078.proc.response.Rs; | ||
| 8 | +import com.genersoft.iot.vmp.jt1078.session.Session; | ||
| 9 | +import com.genersoft.iot.vmp.jt1078.session.SessionManager; | ||
| 10 | +import io.netty.buffer.ByteBuf; | ||
| 11 | +import io.netty.buffer.ByteBufUtil; | ||
| 12 | + | ||
| 13 | +import java.util.ArrayList; | ||
| 14 | +import java.util.List; | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * 终端上传音视频资源列表 | ||
| 18 | + * | ||
| 19 | + * @author QingtaiJiang | ||
| 20 | + * @date 2023/4/28 10:36 | ||
| 21 | + * @email qingtaij@163.com | ||
| 22 | + */ | ||
| 23 | +@MsgId(id = "1205") | ||
| 24 | +public class J1205 extends Re { | ||
| 25 | + Integer respNo; | ||
| 26 | + | ||
| 27 | + private List<JRecordItem> recordList = new ArrayList<JRecordItem>(); | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + protected Rs decode0(ByteBuf buf, Header header, Session session) { | ||
| 31 | + respNo = buf.readUnsignedShort(); | ||
| 32 | + long size = buf.readUnsignedInt(); | ||
| 33 | + | ||
| 34 | + for (int i = 0; i < size; i++) { | ||
| 35 | + JRecordItem item = new JRecordItem(); | ||
| 36 | + item.setChannelId(buf.readUnsignedByte()); | ||
| 37 | + item.setStartTime(ByteBufUtil.hexDump(buf.readSlice(6))); | ||
| 38 | + item.setEndTime(ByteBufUtil.hexDump(buf.readSlice(6))); | ||
| 39 | + item.setWarn(buf.readLong()); | ||
| 40 | + item.setMediaType(buf.readUnsignedByte()); | ||
| 41 | + item.setStreamType(buf.readUnsignedByte()); | ||
| 42 | + item.setStorageType(buf.readUnsignedByte()); | ||
| 43 | + item.setSize(buf.readUnsignedInt()); | ||
| 44 | + recordList.add(item); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + return null; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + @Override | ||
| 51 | + protected Rs handler(Header header, Session session) { | ||
| 52 | + SessionManager.INSTANCE.response(header.getDevId(), "1205", (long) respNo, JSON.toJSONString(this)); | ||
| 53 | + | ||
| 54 | + J8001 j8001 = new J8001(); | ||
| 55 | + j8001.setRespNo(header.getSn()); | ||
| 56 | + j8001.setRespId(header.getMsgId()); | ||
| 57 | + j8001.setResult(J8001.SUCCESS); | ||
| 58 | + return j8001; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + public Integer getRespNo() { | ||
| 63 | + return respNo; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public void setRespNo(Integer respNo) { | ||
| 67 | + this.respNo = respNo; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public List<JRecordItem> getRecordList() { | ||
| 71 | + return recordList; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public void setRecordList(List<JRecordItem> recordList) { | ||
| 75 | + this.recordList = recordList; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public static class JRecordItem { | ||
| 79 | + | ||
| 80 | + // 逻辑通道号 | ||
| 81 | + private int channelId; | ||
| 82 | + | ||
| 83 | + // 开始时间 | ||
| 84 | + private String startTime; | ||
| 85 | + | ||
| 86 | + // 结束时间 | ||
| 87 | + private String endTime; | ||
| 88 | + | ||
| 89 | + // 报警标志 | ||
| 90 | + private long warn; | ||
| 91 | + | ||
| 92 | + // 音视频资源类型 | ||
| 93 | + private int mediaType; | ||
| 94 | + | ||
| 95 | + // 码流类型 | ||
| 96 | + private int streamType = 1; | ||
| 97 | + | ||
| 98 | + // 存储器类型 | ||
| 99 | + private int storageType; | ||
| 100 | + | ||
| 101 | + // 文件大小 | ||
| 102 | + private long size; | ||
| 103 | + | ||
| 104 | + public int getChannelId() { | ||
| 105 | + return channelId; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public void setChannelId(int channelId) { | ||
| 109 | + this.channelId = channelId; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public String getStartTime() { | ||
| 113 | + return startTime; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public void setStartTime(String startTime) { | ||
| 117 | + this.startTime = startTime; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + public String getEndTime() { | ||
| 121 | + return endTime; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + public void setEndTime(String endTime) { | ||
| 125 | + this.endTime = endTime; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public long getWarn() { | ||
| 129 | + return warn; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public void setWarn(long warn) { | ||
| 133 | + this.warn = warn; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public int getMediaType() { | ||
| 137 | + return mediaType; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public void setMediaType(int mediaType) { | ||
| 141 | + this.mediaType = mediaType; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + public int getStreamType() { | ||
| 145 | + return streamType; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + public void setStreamType(int streamType) { | ||
| 149 | + this.streamType = streamType; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + public int getStorageType() { | ||
| 153 | + return storageType; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public void setStorageType(int storageType) { | ||
| 157 | + this.storageType = storageType; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + public long getSize() { | ||
| 161 | + return size; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + public void setSize(long size) { | ||
| 165 | + this.size = size; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + @Override | ||
| 169 | + public String toString() { | ||
| 170 | + return "JRecordItem{" + | ||
| 171 | + "channelId=" + channelId + | ||
| 172 | + ", startTime='" + startTime + '\'' + | ||
| 173 | + ", endTime='" + endTime + '\'' + | ||
| 174 | + ", warn=" + warn + | ||
| 175 | + ", mediaType=" + mediaType + | ||
| 176 | + ", streamType=" + streamType + | ||
| 177 | + ", storageType=" + storageType + | ||
| 178 | + ", size=" + size + | ||
| 179 | + '}'; | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + @Override | ||
| 184 | + public String toString() { | ||
| 185 | + return "J1205{" + | ||
| 186 | + "respNo=" + respNo + | ||
| 187 | + ", recordList=" + recordList + | ||
| 188 | + '}'; | ||
| 189 | + } | ||
| 190 | +} |
src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J9101.java
| @@ -6,6 +6,8 @@ import io.netty.buffer.Unpooled; | @@ -6,6 +6,8 @@ import io.netty.buffer.Unpooled; | ||
| 6 | import io.netty.util.CharsetUtil; | 6 | import io.netty.util.CharsetUtil; |
| 7 | 7 | ||
| 8 | /** | 8 | /** |
| 9 | + * 实时音视频传输请求 | ||
| 10 | + * | ||
| 9 | * @author QingtaiJiang | 11 | * @author QingtaiJiang |
| 10 | * @date 2023/4/27 18:25 | 12 | * @date 2023/4/27 18:25 |
| 11 | * @email qingtaij@163.com | 13 | * @email qingtaij@163.com |
src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J9102.java
| 1 | package com.genersoft.iot.vmp.jt1078.proc.response; | 1 | package com.genersoft.iot.vmp.jt1078.proc.response; |
| 2 | 2 | ||
| 3 | +import com.genersoft.iot.vmp.jt1078.annotation.MsgId; | ||
| 3 | import io.netty.buffer.ByteBuf; | 4 | import io.netty.buffer.ByteBuf; |
| 4 | import io.netty.buffer.Unpooled; | 5 | import io.netty.buffer.Unpooled; |
| 5 | 6 | ||
| 6 | /** | 7 | /** |
| 8 | + * 音视频实时传输控制 | ||
| 9 | + * | ||
| 7 | * @author QingtaiJiang | 10 | * @author QingtaiJiang |
| 8 | * @date 2023/4/27 18:49 | 11 | * @date 2023/4/27 18:49 |
| 9 | * @email qingtaij@163.com | 12 | * @email qingtaij@163.com |
| 10 | */ | 13 | */ |
| 14 | +@MsgId(id = "9102") | ||
| 11 | public class J9102 extends Rs { | 15 | public class J9102 extends Rs { |
| 12 | 16 | ||
| 13 | // 通道号 | 17 | // 通道号 |
| @@ -47,7 +51,7 @@ public class J9102 extends Rs { | @@ -47,7 +51,7 @@ public class J9102 extends Rs { | ||
| 47 | buffer.writeByte(command); | 51 | buffer.writeByte(command); |
| 48 | buffer.writeByte(closeType); | 52 | buffer.writeByte(closeType); |
| 49 | buffer.writeByte(streamType); | 53 | buffer.writeByte(streamType); |
| 50 | - return null; | 54 | + return buffer; |
| 51 | } | 55 | } |
| 52 | 56 | ||
| 53 | 57 | ||
| @@ -82,4 +86,14 @@ public class J9102 extends Rs { | @@ -82,4 +86,14 @@ public class J9102 extends Rs { | ||
| 82 | public void setStreamType(Integer streamType) { | 86 | public void setStreamType(Integer streamType) { |
| 83 | this.streamType = streamType; | 87 | this.streamType = streamType; |
| 84 | } | 88 | } |
| 89 | + | ||
| 90 | + @Override | ||
| 91 | + public String toString() { | ||
| 92 | + return "J9102{" + | ||
| 93 | + "channel=" + channel + | ||
| 94 | + ", command=" + command + | ||
| 95 | + ", closeType=" + closeType + | ||
| 96 | + ", streamType=" + streamType + | ||
| 97 | + '}'; | ||
| 98 | + } | ||
| 85 | } | 99 | } |
src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J9201.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.jt1078.proc.response; | ||
| 2 | + | ||
| 3 | +import com.genersoft.iot.vmp.jt1078.annotation.MsgId; | ||
| 4 | +import io.netty.buffer.ByteBuf; | ||
| 5 | +import io.netty.buffer.ByteBufUtil; | ||
| 6 | +import io.netty.buffer.Unpooled; | ||
| 7 | +import io.netty.util.CharsetUtil; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 回放请求 | ||
| 11 | + * | ||
| 12 | + * @author QingtaiJiang | ||
| 13 | + * @date 2023/4/28 10:37 | ||
| 14 | + * @email qingtaij@163.com | ||
| 15 | + */ | ||
| 16 | +@MsgId(id = "9201") | ||
| 17 | +public class J9201 extends Rs { | ||
| 18 | + // 服务器IP地址 | ||
| 19 | + private String ip; | ||
| 20 | + | ||
| 21 | + // 实时视频服务器TCP端口号 | ||
| 22 | + private int tcpPort; | ||
| 23 | + | ||
| 24 | + // 实时视频服务器UDP端口号 | ||
| 25 | + private int udpPort; | ||
| 26 | + | ||
| 27 | + // 逻辑通道号 | ||
| 28 | + private int channel; | ||
| 29 | + | ||
| 30 | + // 音视频资源类型:0.音视频 1.音频 2.视频 3.视频或音视频 | ||
| 31 | + private int type; | ||
| 32 | + | ||
| 33 | + // 码流类型:0.所有码流 1.主码流 2.子码流(如果此通道只传输音频,此字段置0) | ||
| 34 | + private int rate; | ||
| 35 | + | ||
| 36 | + // 存储器类型:0.所有存储器 1.主存储器 2.灾备存储器" | ||
| 37 | + private int storageType; | ||
| 38 | + | ||
| 39 | + // 回放方式:0.正常回放 1.快进回放 2.关键帧快退回放 3.关键帧播放 4.单帧上传 | ||
| 40 | + private int playbackType; | ||
| 41 | + | ||
| 42 | + // 快进或快退倍数:0.无效 1.1倍 2.2倍 3.4倍 4.8倍 5.16倍 (回放控制为1和2时,此字段内容有效,否则置0) | ||
| 43 | + private int playbackSpeed; | ||
| 44 | + | ||
| 45 | + // 开始时间YYMMDDHHMMSS,回放方式为4时,该字段表示单帧上传时间 | ||
| 46 | + private String startTime; | ||
| 47 | + | ||
| 48 | + // 结束时间YYMMDDHHMMSS,回放方式为4时,该字段无效,为0表示一直回放 | ||
| 49 | + private String endTime; | ||
| 50 | + | ||
| 51 | + @Override | ||
| 52 | + public ByteBuf encode() { | ||
| 53 | + ByteBuf buffer = Unpooled.buffer(); | ||
| 54 | + buffer.writeByte(ip.getBytes().length); | ||
| 55 | + buffer.writeCharSequence(ip, CharsetUtil.UTF_8); | ||
| 56 | + buffer.writeShort(tcpPort); | ||
| 57 | + buffer.writeShort(udpPort); | ||
| 58 | + buffer.writeByte(channel); | ||
| 59 | + buffer.writeByte(type); | ||
| 60 | + buffer.writeByte(rate); | ||
| 61 | + buffer.writeByte(storageType); | ||
| 62 | + buffer.writeByte(playbackType); | ||
| 63 | + buffer.writeByte(playbackSpeed); | ||
| 64 | + buffer.writeBytes(ByteBufUtil.decodeHexDump(startTime)); | ||
| 65 | + buffer.writeBytes(ByteBufUtil.decodeHexDump(endTime)); | ||
| 66 | + return buffer; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public String getIp() { | ||
| 70 | + return ip; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public void setIp(String ip) { | ||
| 74 | + this.ip = ip; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public int getTcpPort() { | ||
| 78 | + return tcpPort; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public void setTcpPort(int tcpPort) { | ||
| 82 | + this.tcpPort = tcpPort; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + public int getUdpPort() { | ||
| 86 | + return udpPort; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public void setUdpPort(int udpPort) { | ||
| 90 | + this.udpPort = udpPort; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + public int getChannel() { | ||
| 94 | + return channel; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + public void setChannel(int channel) { | ||
| 98 | + this.channel = channel; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public int getType() { | ||
| 102 | + return type; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + public void setType(int type) { | ||
| 106 | + this.type = type; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + public int getRate() { | ||
| 110 | + return rate; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + public void setRate(int rate) { | ||
| 114 | + this.rate = rate; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + public int getStorageType() { | ||
| 118 | + return storageType; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + public void setStorageType(int storageType) { | ||
| 122 | + this.storageType = storageType; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + public int getPlaybackType() { | ||
| 126 | + return playbackType; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + public void setPlaybackType(int playbackType) { | ||
| 130 | + this.playbackType = playbackType; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public int getPlaybackSpeed() { | ||
| 134 | + return playbackSpeed; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + public void setPlaybackSpeed(int playbackSpeed) { | ||
| 138 | + this.playbackSpeed = playbackSpeed; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + public String getStartTime() { | ||
| 142 | + return startTime; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + public void setStartTime(String startTime) { | ||
| 146 | + this.startTime = startTime; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public String getEndTime() { | ||
| 150 | + return endTime; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public void setEndTime(String endTime) { | ||
| 154 | + this.endTime = endTime; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + @Override | ||
| 158 | + public String toString() { | ||
| 159 | + return "J9201{" + | ||
| 160 | + "ip='" + ip + '\'' + | ||
| 161 | + ", tcpPort=" + tcpPort + | ||
| 162 | + ", udpPort=" + udpPort + | ||
| 163 | + ", channel=" + channel + | ||
| 164 | + ", type=" + type + | ||
| 165 | + ", rate=" + rate + | ||
| 166 | + ", storageType=" + storageType + | ||
| 167 | + ", playbackType=" + playbackType + | ||
| 168 | + ", playbackSpeed=" + playbackSpeed + | ||
| 169 | + ", startTime='" + startTime + '\'' + | ||
| 170 | + ", endTime='" + endTime + '\'' + | ||
| 171 | + '}'; | ||
| 172 | + } | ||
| 173 | +} |
src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J9202.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.jt1078.proc.response; | ||
| 2 | + | ||
| 3 | +import com.genersoft.iot.vmp.jt1078.annotation.MsgId; | ||
| 4 | +import io.netty.buffer.ByteBuf; | ||
| 5 | +import io.netty.buffer.ByteBufUtil; | ||
| 6 | +import io.netty.buffer.Unpooled; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 平台下发远程录像回放控制 | ||
| 10 | + * | ||
| 11 | + * @author QingtaiJiang | ||
| 12 | + * @date 2023/4/28 10:37 | ||
| 13 | + * @email qingtaij@163.com | ||
| 14 | + */ | ||
| 15 | +@MsgId(id = "9202") | ||
| 16 | +public class J9202 extends Rs { | ||
| 17 | + // 逻辑通道号 | ||
| 18 | + private int channel; | ||
| 19 | + | ||
| 20 | + // 回放控制:0.开始回放 1.暂停回放 2.结束回放 3.快进回放 4.关键帧快退回放 5.拖动回放 6.关键帧播放 | ||
| 21 | + private int playbackType; | ||
| 22 | + | ||
| 23 | + // 快进或快退倍数:0.无效 1.1倍 2.2倍 3.4倍 4.8倍 5.16倍 (回放控制为3和4时,此字段内容有效,否则置0) | ||
| 24 | + private int playbackSpeed; | ||
| 25 | + | ||
| 26 | + // 拖动回放位置(YYMMDDHHMMSS,回放控制为5时,此字段有效) | ||
| 27 | + private String playbackTime; | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public ByteBuf encode() { | ||
| 31 | + ByteBuf buffer = Unpooled.buffer(); | ||
| 32 | + buffer.writeByte(channel); | ||
| 33 | + buffer.writeByte(playbackType); | ||
| 34 | + buffer.writeByte(playbackSpeed); | ||
| 35 | + buffer.writeBytes(ByteBufUtil.decodeHexDump(playbackTime)); | ||
| 36 | + return buffer; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public int getChannel() { | ||
| 40 | + return channel; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setChannel(int channel) { | ||
| 44 | + this.channel = channel; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public int getPlaybackType() { | ||
| 48 | + return playbackType; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setPlaybackType(int playbackType) { | ||
| 52 | + this.playbackType = playbackType; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public int getPlaybackSpeed() { | ||
| 56 | + return playbackSpeed; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setPlaybackSpeed(int playbackSpeed) { | ||
| 60 | + this.playbackSpeed = playbackSpeed; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public String getPlaybackTime() { | ||
| 64 | + return playbackTime; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setPlaybackTime(String playbackTime) { | ||
| 68 | + this.playbackTime = playbackTime; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Override | ||
| 72 | + public String toString() { | ||
| 73 | + return "J9202{" + | ||
| 74 | + "channel=" + channel + | ||
| 75 | + ", playbackType=" + playbackType + | ||
| 76 | + ", playbackSpeed=" + playbackSpeed + | ||
| 77 | + ", playbackTime='" + playbackTime + '\'' + | ||
| 78 | + '}'; | ||
| 79 | + } | ||
| 80 | +} |
src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J9205.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.jt1078.proc.response; | ||
| 2 | + | ||
| 3 | +import com.genersoft.iot.vmp.jt1078.annotation.MsgId; | ||
| 4 | +import io.netty.buffer.ByteBuf; | ||
| 5 | +import io.netty.buffer.ByteBufUtil; | ||
| 6 | +import io.netty.buffer.Unpooled; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 查询资源列表 | ||
| 10 | + * | ||
| 11 | + * @author QingtaiJiang | ||
| 12 | + * @date 2023/4/28 10:36 | ||
| 13 | + * @email qingtaij@163.com | ||
| 14 | + */ | ||
| 15 | +@MsgId(id = "9205") | ||
| 16 | +public class J9205 extends Rs { | ||
| 17 | + // 逻辑通道号 | ||
| 18 | + private int channelId; | ||
| 19 | + | ||
| 20 | + // 开始时间YYMMDDHHMMSS,全0表示无起始时间 | ||
| 21 | + private String startTime; | ||
| 22 | + | ||
| 23 | + // 结束时间YYMMDDHHMMSS,全0表示无终止时间 | ||
| 24 | + private String endTime; | ||
| 25 | + | ||
| 26 | + // 报警标志 | ||
| 27 | + private final int warnType = 0; | ||
| 28 | + | ||
| 29 | + // 音视频资源类型:0.音视频 1.音频 2.视频 3.视频或音视频 | ||
| 30 | + private int mediaType; | ||
| 31 | + | ||
| 32 | + // 码流类型:0.所有码流 1.主码流 2.子码流 | ||
| 33 | + private int streamType = 0; | ||
| 34 | + | ||
| 35 | + // 存储器类型:0.所有存储器 1.主存储器 2.灾备存储器 | ||
| 36 | + private int storageType = 0; | ||
| 37 | + | ||
| 38 | + @Override | ||
| 39 | + public ByteBuf encode() { | ||
| 40 | + ByteBuf buffer = Unpooled.buffer(); | ||
| 41 | + | ||
| 42 | + buffer.writeByte(channelId); | ||
| 43 | + buffer.writeBytes(ByteBufUtil.decodeHexDump(startTime)); | ||
| 44 | + buffer.writeBytes(ByteBufUtil.decodeHexDump(endTime)); | ||
| 45 | + buffer.writeLong(warnType); | ||
| 46 | + buffer.writeByte(mediaType); | ||
| 47 | + buffer.writeByte(streamType); | ||
| 48 | + buffer.writeByte(storageType); | ||
| 49 | + | ||
| 50 | + return buffer; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + | ||
| 54 | + public void setChannelId(int channelId) { | ||
| 55 | + this.channelId = channelId; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + public void setStartTime(String startTime) { | ||
| 59 | + this.startTime = startTime; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public void setEndTime(String endTime) { | ||
| 63 | + this.endTime = endTime; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public void setMediaType(int mediaType) { | ||
| 67 | + this.mediaType = mediaType; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public void setStreamType(int streamType) { | ||
| 71 | + this.streamType = streamType; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public void setStorageType(int storageType) { | ||
| 75 | + this.storageType = storageType; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public int getWarnType() { | ||
| 79 | + return warnType; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + @Override | ||
| 83 | + public String toString() { | ||
| 84 | + return "J9205{" + | ||
| 85 | + "channelId=" + channelId + | ||
| 86 | + ", startTime='" + startTime + '\'' + | ||
| 87 | + ", endTime='" + endTime + '\'' + | ||
| 88 | + ", warnType=" + warnType + | ||
| 89 | + ", mediaType=" + mediaType + | ||
| 90 | + ", streamType=" + streamType + | ||
| 91 | + ", storageType=" + storageType + | ||
| 92 | + '}'; | ||
| 93 | + } | ||
| 94 | +} |
src/main/java/com/genersoft/iot/vmp/jt1078/session/SessionManager.java
| @@ -76,13 +76,13 @@ public enum SessionManager { | @@ -76,13 +76,13 @@ public enum SessionManager { | ||
| 76 | Session session = this.get(cmd.getDevId()); | 76 | Session session = this.get(cmd.getDevId()); |
| 77 | if (session == null) { | 77 | if (session == null) { |
| 78 | log.error("DevId: {} not online!", cmd.getDevId()); | 78 | log.error("DevId: {} not online!", cmd.getDevId()); |
| 79 | - return "-1"; | 79 | + return null; |
| 80 | } | 80 | } |
| 81 | String requestKey = requestKey(cmd.getDevId(), cmd.getRespId(), cmd.getPackageNo()); | 81 | String requestKey = requestKey(cmd.getDevId(), cmd.getRespId(), cmd.getPackageNo()); |
| 82 | SynchronousQueue<String> subscribe = subscribe(requestKey); | 82 | SynchronousQueue<String> subscribe = subscribe(requestKey); |
| 83 | if (subscribe == null) { | 83 | if (subscribe == null) { |
| 84 | log.error("DevId: {} key:{} send repaid", cmd.getDevId(), requestKey); | 84 | log.error("DevId: {} key:{} send repaid", cmd.getDevId(), requestKey); |
| 85 | - return "-1"; | 85 | + return null; |
| 86 | } | 86 | } |
| 87 | session.writeObject(cmd); | 87 | session.writeObject(cmd); |
| 88 | try { | 88 | try { |
| @@ -105,7 +105,7 @@ public enum SessionManager { | @@ -105,7 +105,7 @@ public enum SessionManager { | ||
| 105 | log.error("{}", e.getMessage(), e); | 105 | log.error("{}", e.getMessage(), e); |
| 106 | } | 106 | } |
| 107 | } | 107 | } |
| 108 | - log.warn("未找到对应回复指令,key:{} 消息:{} ", requestKey, data); | 108 | + log.warn("Not find response,key:{} data:{} ", requestKey, data); |
| 109 | return false; | 109 | return false; |
| 110 | } | 110 | } |
| 111 | 111 |
src/test/java/com/genersoft/iot/vmp/jt1078/JT1078ServerTest.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.jt1078; | ||
| 2 | + | ||
| 3 | +import com.genersoft.iot.vmp.jt1078.cmd.JT1078Template; | ||
| 4 | +import com.genersoft.iot.vmp.jt1078.codec.netty.TcpServer; | ||
| 5 | +import com.genersoft.iot.vmp.jt1078.proc.response.J9102; | ||
| 6 | +import com.genersoft.iot.vmp.jt1078.proc.response.J9201; | ||
| 7 | +import com.genersoft.iot.vmp.jt1078.proc.response.J9202; | ||
| 8 | +import com.genersoft.iot.vmp.jt1078.proc.response.J9205; | ||
| 9 | + | ||
| 10 | +import java.util.Scanner; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * @author QingtaiJiang | ||
| 14 | + * @date 2023/4/28 14:22 | ||
| 15 | + * @email qingtaij@163.com | ||
| 16 | + */ | ||
| 17 | +public class JT1078ServerTest { | ||
| 18 | + | ||
| 19 | + private static final JT1078Template jt1078Template = new JT1078Template(); | ||
| 20 | + | ||
| 21 | + public static void main(String[] args) { | ||
| 22 | + System.out.println("Starting jt1078 server..."); | ||
| 23 | + TcpServer tcpServer = new TcpServer(21078); | ||
| 24 | + tcpServer.start(); | ||
| 25 | + System.out.println("Start jt1078 server success!"); | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + Scanner s = new Scanner(System.in); | ||
| 29 | + while (true) { | ||
| 30 | + String code = s.nextLine(); | ||
| 31 | + switch (code) { | ||
| 32 | + case "1": | ||
| 33 | + test9102(); | ||
| 34 | + break; | ||
| 35 | + case "2": | ||
| 36 | + test9201(); | ||
| 37 | + break; | ||
| 38 | + case "3": | ||
| 39 | + test9202(); | ||
| 40 | + break; | ||
| 41 | + case "4": | ||
| 42 | + test9205(); | ||
| 43 | + break; | ||
| 44 | + default: | ||
| 45 | + break; | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + private static void test9102() { | ||
| 51 | + J9102 j9102 = new J9102(); | ||
| 52 | + j9102.setChannel(1); | ||
| 53 | + j9102.setCommand(0); | ||
| 54 | + j9102.setCloseType(0); | ||
| 55 | + j9102.setStreamType(0); | ||
| 56 | + | ||
| 57 | + String s = jt1078Template.stopLive("18864197066", j9102, 6); | ||
| 58 | + System.out.println(s); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + private static void test9201() { | ||
| 62 | + J9201 j9201 = new J9201(); | ||
| 63 | + j9201.setIp("192.168.1.1"); | ||
| 64 | + j9201.setChannel(1); | ||
| 65 | + j9201.setTcpPort(7618); | ||
| 66 | + j9201.setUdpPort(7618); | ||
| 67 | + j9201.setType(0); | ||
| 68 | + j9201.setRate(0); | ||
| 69 | + j9201.setStorageType(0); | ||
| 70 | + j9201.setPlaybackType(0); | ||
| 71 | + j9201.setPlaybackSpeed(0); | ||
| 72 | + j9201.setStartTime("230428134100"); | ||
| 73 | + j9201.setEndTime("230428134200"); | ||
| 74 | + | ||
| 75 | + String s = jt1078Template.startBackLive("18864197066", j9201, 6); | ||
| 76 | + System.out.println(s); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + private static void test9202() { | ||
| 80 | + J9202 j9202 = new J9202(); | ||
| 81 | + | ||
| 82 | + j9202.setChannel(1); | ||
| 83 | + j9202.setPlaybackType(2); | ||
| 84 | + j9202.setPlaybackSpeed(0); | ||
| 85 | + j9202.setPlaybackTime("230428134100"); | ||
| 86 | + | ||
| 87 | + String s = jt1078Template.controlBackLive("18864197066", j9202, 6); | ||
| 88 | + System.out.println(s); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + private static void test9205() { | ||
| 92 | + J9205 j9205 = new J9205(); | ||
| 93 | + j9205.setChannelId(1); | ||
| 94 | + j9205.setStartTime("230428134100"); | ||
| 95 | + j9205.setEndTime("230428134100"); | ||
| 96 | + j9205.setMediaType(0); | ||
| 97 | + j9205.setStreamType(0); | ||
| 98 | + j9205.setStorageType(0); | ||
| 99 | + | ||
| 100 | + String s = jt1078Template.queryBackTime("18864197066", j9205, 6); | ||
| 101 | + System.out.println(s); | ||
| 102 | + } | ||
| 103 | +} |