abl添加getMediaInfo接口实现

dev/abl支持
648540858 2024-04-10 00:03:45 +08:00
parent 2dc7eecb47
commit b08f00104e
3 changed files with 77 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; 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.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.MediaInfo;
import com.genersoft.iot.vmp.media.bean.MediaServer; import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.service.IMediaNodeServerService; import com.genersoft.iot.vmp.media.service.IMediaNodeServerService;
@ -15,7 +16,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -125,10 +128,50 @@ public class ABLMediaNodeServerService implements IMediaNodeServerService {
} }
@Override @Override
public List<StreamInfo> getMediaList(MediaServer mediaServerItem, String app, String stream, String callId) { public List<StreamInfo> getMediaList(MediaServer mediaServer, String app, String stream, String callId) {
logger.warn("[abl-getMediaList] 未实现"); 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<StreamInfo> 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 @Override
@ -143,9 +186,26 @@ public class ABLMediaNodeServerService implements IMediaNodeServerService {
} }
@Override @Override
public MediaInfo getMediaInfo(MediaServer mediaServerItem, String app, String stream) { public MediaInfo getMediaInfo(MediaServer mediaServer, String app, String stream) {
logger.warn("[abl-getMediaInfo] 未实现"); JSONObject jsonObject = ablresTfulUtils.getMediaList(mediaServer, app, stream);
return null; 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 @Override

View File

@ -29,6 +29,7 @@ public class ABLRESTfulUtils {
public interface RequestCallback{ public interface RequestCallback{
void run(JSONObject response); void run(JSONObject response);
} }
@ -322,4 +323,11 @@ public class ABLRESTfulUtils {
param.put("key", key); param.put("key", key);
sendPost(mediaServer,"stopSendRtp", param, null); sendPost(mediaServer,"stopSendRtp", param, null);
} }
public JSONObject getMediaList(MediaServer mediaServer, String app, String stream) {
Map<String, Object> param = new HashMap<>();
param.put("app", app);
param.put("stream", stream);
return sendPost(mediaServer,"getMediaList", param, null);
}
} }

View File

@ -214,6 +214,10 @@ public class MediaInfo {
return mediaInfo; return mediaInfo;
} }
public static MediaInfo getInstanceForAblJson(JSONObject mediaJSON, MediaServer mediaServer) {
return null;
}
public Integer getReaderCount() { public Integer getReaderCount() {
return readerCount; return readerCount;
} }