添加抓拍支持

dev/abl支持
648540858 2024-04-10 16:26:46 +08:00
parent b08f00104e
commit d410a3ca18
7 changed files with 34 additions and 28 deletions

View File

@ -181,8 +181,8 @@ public class ABLMediaNodeServerService implements IMediaNodeServerService {
} }
@Override @Override
public void getSnap(MediaServer mediaServerItem, String streamUrl, int timeoutSec, int expireSec, String path, String fileName) { public void getSnap(MediaServer mediaServerItem, String app, String stream, int timeoutSec, int expireSec, String path, String fileName) {
logger.warn("[abl-getSnap] 未实现"); ablresTfulUtils.getSnap(mediaServerItem, app, stream, timeoutSec, path, fileName);
} }
@Override @Override

View File

@ -250,7 +250,6 @@ public class ABLRESTfulUtils {
if (!snapFolder.mkdirs()) { if (!snapFolder.mkdirs()) {
logger.warn("{}路径创建失败", snapFolder.getAbsolutePath()); logger.warn("{}路径创建失败", snapFolder.getAbsolutePath());
} }
} }
File snapFile = new File(targetPath + File.separator + fileName); File snapFile = new File(targetPath + File.separator + fileName);
FileOutputStream outStream = new FileOutputStream(snapFile); FileOutputStream outStream = new FileOutputStream(snapFile);
@ -330,4 +329,13 @@ public class ABLRESTfulUtils {
param.put("stream", stream); param.put("stream", stream);
return sendPost(mediaServer,"getMediaList", param, null); return sendPost(mediaServer,"getMediaList", param, null);
} }
public void getSnap(MediaServer mediaServer, String app, String stream, int timeoutSec, String path, String fileName) {
Map<String, Object> param = new HashMap<>();
param.put("app", app);
param.put("stream", stream);
param.put("timeout_sec", timeoutSec);
param.put("vhost", "_defaultVhost_");
sendGetForImg(mediaServer,"getSnap", param, path, fileName);
}
} }

View File

@ -35,7 +35,7 @@ public interface IMediaNodeServerService {
Boolean connectRtpServer(MediaServer mediaServer, String address, int port, String stream); Boolean connectRtpServer(MediaServer mediaServer, String address, int port, String stream);
void getSnap(MediaServer mediaServer, String streamUrl, int timeoutSec, int expireSec, String path, String fileName); void getSnap(MediaServer mediaServer, String app, String stream, int timeoutSec, int expireSec, String path, String fileName);
MediaInfo getMediaInfo(MediaServer mediaServer, String app, String stream); MediaInfo getMediaInfo(MediaServer mediaServer, String app, String stream);

View File

@ -82,7 +82,7 @@ public interface IMediaServerService {
Boolean connectRtpServer(MediaServer mediaServerItem, String address, int port, String stream); Boolean connectRtpServer(MediaServer mediaServerItem, String address, int port, String stream);
void getSnap(MediaServer mediaServerItemInuse, String streamUrl, int timeoutSec, int expireSec, String path, String fileName); void getSnap(MediaServer mediaServerItemInuse, String app, String stream, int timeoutSec, int expireSec, String path, String fileName);
MediaInfo getMediaInfo(MediaServer mediaServerItem, String app, String stream); MediaInfo getMediaInfo(MediaServer mediaServerItem, String app, String stream);

View File

@ -610,13 +610,13 @@ public class MediaServerServiceImpl implements IMediaServerService {
} }
@Override @Override
public void getSnap(MediaServer mediaServer, String streamUrl, int timeoutSec, int expireSec, String path, String fileName) { public void getSnap(MediaServer mediaServer, String app, String stream, int timeoutSec, int expireSec, String path, String fileName) {
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType()); IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
if (mediaNodeServerService == null) { if (mediaNodeServerService == null) {
logger.info("[getSnap] 失败, mediaServer的类型 {},未找到对应的实现类", mediaServer.getType()); logger.info("[getSnap] 失败, mediaServer的类型 {},未找到对应的实现类", mediaServer.getType());
return; return;
} }
mediaNodeServerService.getSnap(mediaServer, streamUrl, timeoutSec, expireSec, path, fileName); mediaNodeServerService.getSnap(mediaServer, app, stream, timeoutSec, expireSec, path, fileName);
} }
@Override @Override

View File

@ -200,7 +200,13 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
} }
@Override @Override
public void getSnap(MediaServer mediaServer, String streamUrl, int timeoutSec, int expireSec, String path, String fileName) { public void getSnap(MediaServer mediaServer, String app, String stream, int timeoutSec, int expireSec, String path, String fileName) {
String streamUrl;
if (mediaServer.getRtspPort() != 0) {
streamUrl = String.format("rtsp://127.0.0.1:%s/%s/%s", mediaServer.getRtspPort(), app, stream);
}else {
streamUrl = String.format("http://127.0.0.1:%s/%s/%s.live.mp4", mediaServer.getHttpPort(), app, stream);
}
zlmresTfulUtils.getSnap(mediaServer, streamUrl, timeoutSec, expireSec, path, fileName); zlmresTfulUtils.getSnap(mediaServer, streamUrl, timeoutSec, expireSec, path, fileName);
} }

View File

@ -1,6 +1,5 @@
package com.genersoft.iot.vmp.service.impl; package com.genersoft.iot.vmp.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.genersoft.iot.vmp.common.*; import com.genersoft.iot.vmp.common.*;
import com.genersoft.iot.vmp.conf.DynamicTask; import com.genersoft.iot.vmp.conf.DynamicTask;
@ -17,18 +16,20 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
import com.genersoft.iot.vmp.media.bean.MediaInfo; import com.genersoft.iot.vmp.media.bean.MediaInfo;
import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.bean.RecordInfo; import com.genersoft.iot.vmp.media.bean.RecordInfo;
import com.genersoft.iot.vmp.media.event.hook.Hook; import com.genersoft.iot.vmp.media.event.hook.Hook;
import com.genersoft.iot.vmp.media.event.hook.HookSubscribe;
import com.genersoft.iot.vmp.media.event.hook.HookType; import com.genersoft.iot.vmp.media.event.hook.HookType;
import com.genersoft.iot.vmp.media.event.media.MediaArrivalEvent; import com.genersoft.iot.vmp.media.event.media.MediaArrivalEvent;
import com.genersoft.iot.vmp.media.event.media.MediaDepartureEvent; import com.genersoft.iot.vmp.media.event.media.MediaDepartureEvent;
import com.genersoft.iot.vmp.media.event.media.MediaNotFoundEvent; import com.genersoft.iot.vmp.media.event.media.MediaNotFoundEvent;
import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.media.service.IMediaServerService;
import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager; import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager;
import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory; import com.genersoft.iot.vmp.service.IDeviceChannelService;
import com.genersoft.iot.vmp.media.event.hook.HookSubscribe; import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.media.bean.MediaServer; import com.genersoft.iot.vmp.service.IInviteStreamService;
import com.genersoft.iot.vmp.service.*; import com.genersoft.iot.vmp.service.IPlayService;
import com.genersoft.iot.vmp.service.bean.*; import com.genersoft.iot.vmp.service.bean.*;
import com.genersoft.iot.vmp.service.redisMsg.RedisGbPlayMsgListener; import com.genersoft.iot.vmp.service.redisMsg.RedisGbPlayMsgListener;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
@ -57,7 +58,10 @@ import java.io.File;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.text.ParseException; import java.text.ParseException;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.Vector;
@SuppressWarnings(value = {"rawtypes", "unchecked"}) @SuppressWarnings(value = {"rawtypes", "unchecked"})
@Service @Service
@ -662,17 +666,11 @@ public class PlayServiceImpl implements IPlayService {
* @param stream ssrc * @param stream ssrc
*/ */
private void snapOnPlay(MediaServer mediaServerItemInuse, String deviceId, String channelId, String stream) { private void snapOnPlay(MediaServer mediaServerItemInuse, String deviceId, String channelId, String stream) {
String streamUrl;
if (mediaServerItemInuse.getRtspPort() != 0) {
streamUrl = String.format("rtsp://127.0.0.1:%s/%s/%s", mediaServerItemInuse.getRtspPort(), "rtp", stream);
} else {
streamUrl = String.format("http://127.0.0.1:%s/%s/%s.live.mp4", mediaServerItemInuse.getHttpPort(), "rtp", stream);
}
String path = "snap"; String path = "snap";
String fileName = deviceId + "_" + channelId + ".jpg"; String fileName = deviceId + "_" + channelId + ".jpg";
// 请求截图 // 请求截图
logger.info("[请求截图]: " + fileName); logger.info("[请求截图]: " + fileName);
mediaServerService.getSnap(mediaServerItemInuse, streamUrl, 15, 1, path, fileName); mediaServerService.getSnap(mediaServerItemInuse, "rtp", stream,15, 1, path, fileName);
} }
public StreamInfo onPublishHandlerForPlay(MediaServer mediaServerItem, MediaInfo mediaInfo, String deviceId, String channelId) { public StreamInfo onPublishHandlerForPlay(MediaServer mediaServerItem, MediaInfo mediaInfo, String deviceId, String channelId) {
@ -1581,16 +1579,10 @@ public class PlayServiceImpl implements IPlayService {
if (inviteInfo.getStreamInfo() != null) { if (inviteInfo.getStreamInfo() != null) {
// 已存在线直接截图 // 已存在线直接截图
MediaServer mediaServerItemInuse = mediaServerService.getOne(inviteInfo.getStreamInfo().getMediaServerId()); MediaServer mediaServerItemInuse = mediaServerService.getOne(inviteInfo.getStreamInfo().getMediaServerId());
String streamUrl;
if (mediaServerItemInuse.getRtspPort() != 0) {
streamUrl = String.format("rtsp://127.0.0.1:%s/%s/%s", mediaServerItemInuse.getRtspPort(), "rtp", inviteInfo.getStreamInfo().getStream());
}else {
streamUrl = String.format("http://127.0.0.1:%s/%s/%s.live.mp4", mediaServerItemInuse.getHttpPort(), "rtp", inviteInfo.getStreamInfo().getStream());
}
String path = "snap"; String path = "snap";
// 请求截图 // 请求截图
logger.info("[请求截图]: " + fileName); logger.info("[请求截图]: " + fileName);
mediaServerService.getSnap(mediaServerItemInuse, streamUrl, 15, 1, path, fileName); mediaServerService.getSnap(mediaServerItemInuse, "rtp", inviteInfo.getStreamInfo().getStream(), 15, 1, path, fileName);
File snapFile = new File(path + File.separator + fileName); File snapFile = new File(path + File.separator + fileName);
if (snapFile.exists()) { if (snapFile.exists()) {
errorCallback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), snapFile.getAbsoluteFile()); errorCallback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), snapFile.getAbsoluteFile());