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 445e1e6a..bd2a7be6 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 @@ -1,10 +1,13 @@ package com.genersoft.iot.vmp.media.abl; import com.genersoft.iot.vmp.common.CommonCallback; +import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.media.service.IMediaNodeServerService; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import org.springframework.stereotype.Service; +import java.util.List; + @Service("abl") public class ABLMediaNodeServerService implements IMediaNodeServerService { @@ -47,4 +50,19 @@ public class ABLMediaNodeServerService implements IMediaNodeServerService { public MediaServerItem checkMediaServer(String ip, int port, String secret) { return null; } + + @Override + public boolean stopSendRtp(MediaServerItem mediaInfo, String app, String stream, String ssrc) { + return false; + } + + @Override + public boolean deleteRecordDirectory(MediaServerItem mediaServerItem, String app, String stream, String date, String fileName) { + return false; + } + + @Override + public List getMediaList(MediaServerItem mediaServerItem, String app, String stream, String callId) { + return null; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/bean/Track.java b/src/main/java/com/genersoft/iot/vmp/media/bean/Track.java index e95e7954..963474ea 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/bean/Track.java +++ b/src/main/java/com/genersoft/iot/vmp/media/bean/Track.java @@ -1,7 +1,12 @@ package com.genersoft.iot.vmp.media.bean; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; + /** * 视频信息 */ @@ -22,6 +27,97 @@ public class Track { @Schema(description = "音频采样率") private Integer audioSampleRate; + public static Track getInstance(JSONObject jsonObject) { + Track track = new Track(); + Integer totalReaderCount = jsonObject.getInteger("totalReaderCount"); + if (totalReaderCount != null) { + track.setReaderCount(totalReaderCount); + } + JSONArray jsonArray = jsonObject.getJSONArray("tracks"); + if (jsonArray.isEmpty()) { + return null; + } + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject trackJson = jsonArray.getJSONObject(i); + Integer channels = trackJson.getInteger("channels"); + Integer codecId = trackJson.getInteger("codec_id"); + Integer codecType = trackJson.getInteger("codec_type"); + Integer sampleRate = trackJson.getInteger("sample_rate"); + Integer height = trackJson.getInteger("height"); + Integer width = trackJson.getInteger("height"); + if (channels != null) { + track.setAudioChannels(channels); + } + if (sampleRate != null) { + track.setAudioSampleRate(sampleRate); + } + if (height != null) { + track.setHeight(height); + } + if (width != null) { + track.setWidth(width); + } + if (codecId != null) { + switch (codecId) { + case 0: + track.setVideoCodec("H264"); + break; + case 1: + track.setVideoCodec("H265"); + break; + case 2: + track.setAudioCodec("AAC"); + break; + case 3: + track.setAudioCodec("G711A"); + break; + case 4: + track.setAudioCodec("G711U"); + break; + } + } + } + return track; + } + + public static Track getInstance(OnStreamChangedHookParam param) { + List tracks = param.getTracks(); + Track track = new Track(); + track.setReaderCount(param.getTotalReaderCount()); + for (OnStreamChangedHookParam.MediaTrack mediaTrack : tracks) { + switch (mediaTrack.getCodec_id()) { + case 0: + track.setVideoCodec("H264"); + break; + case 1: + track.setVideoCodec("H265"); + break; + case 2: + track.setAudioCodec("AAC"); + break; + case 3: + track.setAudioCodec("G711A"); + break; + case 4: + track.setAudioCodec("G711U"); + break; + } + if (mediaTrack.getSample_rate() > 0) { + track.setAudioSampleRate(mediaTrack.getSample_rate()); + } + if (mediaTrack.getChannels() > 0) { + track.setAudioChannels(mediaTrack.getChannels()); + } + if (mediaTrack.getHeight() > 0) { + track.setHeight(mediaTrack.getHeight()); + } + if (mediaTrack.getWidth() > 0) { + track.setWidth(mediaTrack.getWidth()); + } + } + return track; + } + public Integer getReaderCount() { return readerCount; } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index ac68bfea..f5d664af 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -369,40 +369,6 @@ public class ZLMHttpHookListener { subscribe.response(mediaInfo, param); } - List tracks = param.getTracks(); - Track track = new Track(); - track.setReaderCount(param.getTotalReaderCount()); - for (OnStreamChangedHookParam.MediaTrack mediaTrack : tracks) { - switch (mediaTrack.getCodec_id()) { - case 0: - track.setVideoCodec("H264"); - break; - case 1: - track.setVideoCodec("H265"); - break; - case 2: - track.setAudioCodec("AAC"); - break; - case 3: - track.setAudioCodec("G711A"); - break; - case 4: - track.setAudioCodec("G711U"); - break; - } - if (mediaTrack.getSample_rate() > 0) { - track.setAudioSampleRate(mediaTrack.getSample_rate()); - } - if (mediaTrack.getChannels() > 0) { - track.setAudioChannels(mediaTrack.getChannels()); - } - if (mediaTrack.getHeight() > 0) { - track.setHeight(mediaTrack.getHeight()); - } - if (mediaTrack.getWidth() > 0) { - track.setWidth(mediaTrack.getWidth()); - } - } // TODO 重构此处逻辑 if (param.isRegist()) { // 处理流注册的鉴权信息, 流注销这里不再删除鉴权信息,下次来了新的鉴权信息会对就的进行覆盖 @@ -506,7 +472,7 @@ public class ZLMHttpHookListener { callId = streamAuthorityInfo.getCallId(); } StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaInfo, - param.getApp(), param.getStream(), track, callId); + param.getApp(), param.getStream(), Track.getInstance(param), callId); param.setStreamInfo(new StreamContent(streamInfoByAppAndStream)); redisCatchStorage.addStream(mediaInfo, type, param.getApp(), param.getStream(), param); if (param.getOriginType() == OriginType.RTSP_PUSH.ordinal() diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaNodeServerService.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaNodeServerService.java index 6d55ac05..686981e6 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaNodeServerService.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaNodeServerService.java @@ -158,9 +158,8 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService { return null; } JSONObject mediaJSON = data.getJSONObject(0); - JSONArray tracks = mediaJSON.getJSONArray("tracks"); - - StreamInfo streamInfo = getStreamInfoByAppAndStream(mediaServerItem, app, stream, tracks, null, callId, true); + Track track = Track.getInstance(mediaJSON); + StreamInfo streamInfo = getStreamInfoByAppAndStream(mediaServerItem, app, stream, track, callId, true); if (streamInfo != null) { streamInfoList.add(streamInfo); } @@ -169,14 +168,11 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService { return streamInfoList; } - public StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Track track, String addr, String callId, boolean isPlay) { + public StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Track track, String callId, boolean isPlay) { StreamInfo streamInfoResult = new StreamInfo(); streamInfoResult.setStream(stream); streamInfoResult.setApp(app); - if (addr == null) { - addr = mediaInfo.getStreamIp(); - } - + String addr = mediaInfo.getStreamIp(); streamInfoResult.setIp(addr); streamInfoResult.setMediaServerId(mediaInfo.getId()); String callIdParam = ObjectUtils.isEmpty(callId)?"":"?callId=" + callId; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3f478442..3d36b847 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,4 +2,4 @@ spring: application: name: wvp profiles: - active: local \ No newline at end of file + active: abl \ No newline at end of file