From b08f00104e83ec575e0588d97936e53ecad4f3bb Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Wed, 10 Apr 2024 00:03:45 +0800 Subject: [PATCH] =?UTF-8?q?abl=E6=B7=BB=E5=8A=A0getMediaInfo=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../media/abl/ABLMediaNodeServerService.java | 70 +++++++++++++++++-- .../iot/vmp/media/abl/ABLRESTfulUtils.java | 8 +++ .../iot/vmp/media/bean/MediaInfo.java | 4 ++ 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/abl/ABLMediaNodeServerService.java b/src/main/java/com/genersoft/iot/vmp/media/abl/ABLMediaNodeServerService.java index 7aa0f982..06ebd2dc 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/abl/ABLMediaNodeServerService.java +++ b/src/main/java/com/genersoft/iot/vmp/media/abl/ABLMediaNodeServerService.java @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; import com.genersoft.iot.vmp.media.abl.bean.AblServerConfig; +import com.genersoft.iot.vmp.media.abl.bean.hook.OnStreamArriveABLHookParam; import com.genersoft.iot.vmp.media.bean.MediaInfo; import com.genersoft.iot.vmp.media.bean.MediaServer; import com.genersoft.iot.vmp.media.service.IMediaNodeServerService; @@ -15,7 +16,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -125,10 +128,50 @@ public class ABLMediaNodeServerService implements IMediaNodeServerService { } @Override - public List getMediaList(MediaServer mediaServerItem, String app, String stream, String callId) { + public List getMediaList(MediaServer mediaServer, String app, String stream, String callId) { logger.warn("[abl-getMediaList] 未实现"); + JSONObject jsonObject = ablresTfulUtils.getMediaList(mediaServer, app, stream); + if (jsonObject == null || jsonObject.getInteger("code") != 0) { + return null; + } + JSONArray mediaList = jsonObject.getJSONArray("mediaList"); + if (mediaList == null || mediaList.isEmpty()) { + return new ArrayList<>(); + } + List streamInfoList = new ArrayList<>(); + for (int i = 0; i < mediaList.size(); i++) { + JSONObject mediaJSON = mediaList.getJSONObject(i); + OnStreamArriveABLHookParam onStreamArriveABLHookParam = mediaJSON.to(OnStreamArriveABLHookParam.class); + MediaInfo mediaInfo = MediaInfo.getInstance(onStreamArriveABLHookParam, mediaServer); + StreamInfo streamInfo = getStreamInfoByAppAndStream(mediaServer, app, stream, mediaInfo, callId, true); + if (streamInfo != null) { + streamInfoList.add(streamInfo); + } + } + return streamInfoList; + } - return null; + public StreamInfo getStreamInfoByAppAndStream(MediaServer mediaServer, String app, String stream, MediaInfo mediaInfo, String callId, boolean isPlay) { + StreamInfo streamInfoResult = new StreamInfo(); + streamInfoResult.setStream(stream); + streamInfoResult.setApp(app); + String addr = mediaServer.getStreamIp(); + streamInfoResult.setIp(addr); + streamInfoResult.setMediaServerId(mediaServer.getId()); + String callIdParam = ObjectUtils.isEmpty(callId)?"":"?callId=" + callId; + streamInfoResult.setRtmp(addr, mediaServer.getRtmpPort(),mediaServer.getRtmpSSlPort(), app, stream, callIdParam); + streamInfoResult.setRtsp(addr, mediaServer.getRtspPort(),mediaServer.getRtspSSLPort(), app, stream, callIdParam); + String flvFile = String.format("%s/%s.flv%s", app, stream, callIdParam); + streamInfoResult.setFlv(addr, mediaServer.getFlvPort(),mediaServer.getHttpSSlPort(), flvFile); + streamInfoResult.setWsFlv(addr, mediaServer.getWsFlvPort(),mediaServer.getHttpSSlPort(), flvFile); + streamInfoResult.setFmp4(addr, mediaServer.getHttpPort(),mediaServer.getHttpSSlPort(), app, stream, callIdParam); + streamInfoResult.setHls(addr, mediaServer.getHttpPort(),mediaServer.getHttpSSlPort(), app, stream, callIdParam); + streamInfoResult.setTs(addr, mediaServer.getHttpPort(),mediaServer.getHttpSSlPort(), app, stream, callIdParam); + streamInfoResult.setRtc(addr, mediaServer.getHttpPort(),mediaServer.getHttpSSlPort(), app, stream, callIdParam, isPlay); + + streamInfoResult.setMediaInfo(mediaInfo); + streamInfoResult.setOriginType(mediaInfo.getOriginType()); + return streamInfoResult; } @Override @@ -143,9 +186,26 @@ public class ABLMediaNodeServerService implements IMediaNodeServerService { } @Override - public MediaInfo getMediaInfo(MediaServer mediaServerItem, String app, String stream) { - logger.warn("[abl-getMediaInfo] 未实现"); - return null; + public MediaInfo getMediaInfo(MediaServer mediaServer, String app, String stream) { + JSONObject jsonObject = ablresTfulUtils.getMediaList(mediaServer, app, stream); + if (jsonObject == null || jsonObject.getInteger("code") != 0) { + return null; + } + JSONArray mediaList = jsonObject.getJSONArray("mediaList"); + if (mediaList == null || mediaList.isEmpty()) { + return null; + } + MediaInfo mediaInfo = null; + for (int i = 0; i < mediaList.size(); i++) { + JSONObject mediaJSON = mediaList.getJSONObject(i); + OnStreamArriveABLHookParam onStreamArriveABLHookParam = mediaJSON.to(OnStreamArriveABLHookParam.class); + if (onStreamArriveABLHookParam == null) { + continue; + } + mediaInfo = MediaInfo.getInstance(onStreamArriveABLHookParam, mediaServer); + + } + return mediaInfo; } @Override diff --git a/src/main/java/com/genersoft/iot/vmp/media/abl/ABLRESTfulUtils.java b/src/main/java/com/genersoft/iot/vmp/media/abl/ABLRESTfulUtils.java index 4d0af781..d1301025 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/abl/ABLRESTfulUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/media/abl/ABLRESTfulUtils.java @@ -29,6 +29,7 @@ public class ABLRESTfulUtils { + public interface RequestCallback{ void run(JSONObject response); } @@ -322,4 +323,11 @@ public class ABLRESTfulUtils { param.put("key", key); sendPost(mediaServer,"stopSendRtp", param, null); } + + public JSONObject getMediaList(MediaServer mediaServer, String app, String stream) { + Map param = new HashMap<>(); + param.put("app", app); + param.put("stream", stream); + return sendPost(mediaServer,"getMediaList", param, null); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/bean/MediaInfo.java b/src/main/java/com/genersoft/iot/vmp/media/bean/MediaInfo.java index 8ee0eaf3..d0ea368f 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/bean/MediaInfo.java +++ b/src/main/java/com/genersoft/iot/vmp/media/bean/MediaInfo.java @@ -214,6 +214,10 @@ public class MediaInfo { return mediaInfo; } + public static MediaInfo getInstanceForAblJson(JSONObject mediaJSON, MediaServer mediaServer) { + return null; + } + public Integer getReaderCount() { return readerCount; }