[1078] 优化多媒体数据上传处理

This commit is contained in:
lin
2025-07-14 11:03:45 +08:00
parent 9d47fe30f5
commit 04bcb6dcb8
4 changed files with 32 additions and 15 deletions

View File

@@ -37,14 +37,14 @@ public class JTMediaEventInfo {
jtMediaEventInfo.setCode(buf.readUnsignedByte());
jtMediaEventInfo.setEventCode(buf.readUnsignedByte());
jtMediaEventInfo.setChannelId(buf.readUnsignedByte());
if (buf.readableBytes() > 0) {
ByteBuf byteBuf = buf.readSlice(28);
jtMediaEventInfo.setPositionBaseInfo(JTPositionBaseInfo.decode(byteBuf));
ByteBuf byteBuf = buf.readSlice(28);
jtMediaEventInfo.setPositionBaseInfo(JTPositionBaseInfo.decode(byteBuf));
byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
jtMediaEventInfo.setMediaData(bytes);
byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
jtMediaEventInfo.setMediaData(bytes);
}
return jtMediaEventInfo;
}
@@ -56,7 +56,7 @@ public class JTMediaEventInfo {
", code=" + code +
", eventCode=" + eventCode +
", channelId=" + channelId +
", fileSize=" + mediaData.length +
", fileSize=" + (mediaData == null ? 0 : mediaData.length) +
'}';
}
}

View File

@@ -1,6 +1,7 @@
package com.genersoft.iot.vmp.jt1078.codec.decode;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.CompositeByteBuf;
import io.netty.buffer.Unpooled;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,6 +34,7 @@ public enum MultiPacketManager {
// 所有分包接收完毕,排序后返回
multiPackets.sort(Comparator.comparing(MultiPacket::getNumber));
ByteBuf byteBuf = Unpooled.buffer();
System.out.println(byteBuf.maxFastWritableBytes());
for (MultiPacket multiPacket : multiPackets) {
byteBuf.writeBytes(multiPacket.getByteBuf());
}
@@ -48,7 +50,7 @@ public enum MultiPacketManager {
timer.schedule(new TimerTask() {
@Override
public void run() {
long expireTime = System.currentTimeMillis() - 2 * 1000;
long expireTime = System.currentTimeMillis() - 20 * 1000;
if (!packetTimeMap.isEmpty()) {
for (String key : packetTimeMap.keySet()) {
if (packetTimeMap.get(key) < expireTime) {

View File

@@ -31,6 +31,16 @@ public class J0801 extends Re {
protected Rs decode0(ByteBuf buf, Header header, Session session) {
JTMediaEventInfo mediaEventInfo = JTMediaEventInfo.decode(buf);
log.info("[JT-多媒体数据上传]: {}", mediaEventInfo);
File file = new File("/home/lin/" + header.getSn() + ".jpg");
try {
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(mediaEventInfo.getMediaData());
fileOutputStream.flush();
fileOutputStream.close();
}catch (Exception e) {
}
SessionManager.INSTANCE.response(header.getPhoneNumber(), "0801", null, mediaEventInfo);
return null;
}

View File

@@ -737,8 +737,8 @@ public class jt1078ServiceImpl implements Ijt1078Service {
shootingCommand.setCommand(1);
shootingCommand.setTime(0);
shootingCommand.setSave(0);
shootingCommand.setResolvingPower(0xff);
shootingCommand.setQuality(1);
shootingCommand.setResolvingPower(0x03);
shootingCommand.setQuality(5);
shootingCommand.setBrightness(125);
shootingCommand.setContrastRatio(60);
shootingCommand.setSaturation(60);
@@ -749,19 +749,24 @@ public class jt1078ServiceImpl implements Ijt1078Service {
@SuppressWarnings("unchecked")
List<Long> ids = (List<Long>) jt1078Template.shooting(phoneNumber, j8801, 300);
log.info("[JT-抓图] 抓图编号: {} 设备编号: {} 通道编号: {}", ids.get(0), phoneNumber, channelId);
log.info("[JT-抓图] 请求上传图片,抓图编号: {} 设备编号: {} 通道编号: {}", ids.get(0), phoneNumber, channelId);
J8805 j8805 = new J8805();
j8805.setMediaId(ids.get(0));
j8805.setDelete(1);
log.info("[JT-抓图] 请求上传图片,抓图编号: {} 设备编号: {} 通道编号: {}", ids.get(0), phoneNumber, channelId);
JTMediaEventInfo mediaEventInfo = (JTMediaEventInfo)jt1078Template.uploadMediaDataForSingle(phoneNumber, j8805, 300);
JTMediaEventInfo mediaEventInfo = (JTMediaEventInfo)jt1078Template.uploadMediaDataForSingle(phoneNumber, j8805, 600);
if (mediaEventInfo == null) {
log.info("[]");
throw new ControllerException(ErrorCode.ERROR100.getCode(), ErrorCode.ERROR100.getMsg());
}
log.info("[JT-抓图] 图片上传完成,抓图编号: {} 设备编号: {} 通道编号: {}", ids.get(0), phoneNumber, channelId);
try {
outputStream.write(mediaEventInfo.getMediaData());
outputStream.flush();
if (outputStream.isReady()) {
outputStream.write(mediaEventInfo.getMediaData());
outputStream.flush();
}else {
log.info("[JT-抓图] 请求可能已经结束,抓图编号: {} 设备编号: {} 通道编号: {}", ids.get(0), phoneNumber, channelId);
}
} catch (IOException e) {
log.info("[JT-抓图] 数据写入异常,抓图编号: {} 设备编号: {} 通道编号: {}", ids.get(0), phoneNumber, channelId, e);
throw new ControllerException(ErrorCode.ERROR100.getCode(), "数据写入异常");