zlm getSnap,restartServer api
This commit is contained in:
parent
26dcbd9b7c
commit
2d244b8b6d
@ -0,0 +1,22 @@
|
||||
package cn.skcks.docking.gb28181.media.dto.snap;
|
||||
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonNaming;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
|
||||
public class Snap {
|
||||
/**
|
||||
* 需要截图的url,可以是本机的,也可以是远程主机的
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 截图失败超时时间,防止 ffmpeg 一直等待截图
|
||||
*/
|
||||
private int timeoutSec;
|
||||
/**
|
||||
* 截图的过期时间,该时间内产生的截图都会作为缓存返回
|
||||
*/
|
||||
private int expireSec;
|
||||
}
|
@ -6,6 +6,7 @@ import cn.skcks.docking.gb28181.media.dto.proxy.AddStreamPusherProxyResp;
|
||||
import cn.skcks.docking.gb28181.media.dto.proxy.DelStreamPusherProxyResp;
|
||||
import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse;
|
||||
import cn.skcks.docking.gb28181.media.dto.rtp.*;
|
||||
import cn.skcks.docking.gb28181.media.dto.snap.Snap;
|
||||
import cn.skcks.docking.gb28181.media.dto.version.VersionResp;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -58,4 +59,10 @@ public interface ZlmMediaHttpClient {
|
||||
|
||||
@PostMapping("/index/api/stopSendRtp")
|
||||
ZlmResponse<Void> stopSendRtp(@RequestParam String secret, @RequestBody StopSendRtp params);
|
||||
|
||||
@PostMapping("/index/api/getSnap")
|
||||
ResponseEntity<byte[]> getSnap(@RequestParam String secret, @RequestBody Snap params);
|
||||
|
||||
@GetMapping("/index/api/restartServer")
|
||||
ZlmResponse<Void> restartServer(@RequestParam String secret);
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ import cn.skcks.docking.gb28181.media.dto.proxy.AddStreamPusherProxyResp;
|
||||
import cn.skcks.docking.gb28181.media.dto.proxy.DelStreamPusherProxyResp;
|
||||
import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse;
|
||||
import cn.skcks.docking.gb28181.media.dto.rtp.*;
|
||||
import cn.skcks.docking.gb28181.media.dto.snap.Snap;
|
||||
import cn.skcks.docking.gb28181.media.dto.version.VersionResp;
|
||||
import lombok.Builder;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@ -97,7 +97,7 @@ public class ZlmMediaService {
|
||||
* <p>功能:作为GB28181客户端,启动ps-rtp推流,支持rtp/udp方式;该接口支持rtsp/rtmp等协议转ps-rtp推流。</p>
|
||||
* 第一次推流失败会直接返回错误,成功一次后,后续失败也将无限重试。
|
||||
*/
|
||||
StartSendRtpResp startSendRtp(StartSendRtp params){
|
||||
public StartSendRtpResp startSendRtp(StartSendRtp params){
|
||||
return exchange.startSendRtp(secret, params);
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ public class ZlmMediaService {
|
||||
* <p>调用该接口,zlm会启动tcp服务器等待连接请求,连接建立后,zlm会关闭tcp服务器,然后源源不断的往客户端推流。</p>
|
||||
* <p>第一次推流失败会直接返回错误,成功一次后,后续失败也将无限重试(不停地建立tcp监听,超时后再关闭)。</p>
|
||||
*/
|
||||
StartSendRtpResp startSendRtpPassive(StartSendRtpPassive params){
|
||||
public StartSendRtpResp startSendRtpPassive(StartSendRtpPassive params){
|
||||
return exchange.startSendRtpPassive(secret, params);
|
||||
}
|
||||
|
||||
@ -115,8 +115,22 @@ public class ZlmMediaService {
|
||||
/**
|
||||
* 功能:停止GB28181 ps-rtp推流
|
||||
*/
|
||||
ZlmResponse<Void> stopSendRtp(StopSendRtp params){
|
||||
public ZlmResponse<Void> stopSendRtp(StopSendRtp params){
|
||||
return exchange.stopSendRtp(secret, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:获取截图或生成实时截图并返回
|
||||
*/
|
||||
public ResponseEntity<byte[]> getSnap(Snap params){
|
||||
return exchange.getSnap(secret, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能:重启服务器,只有Daemon方式才能重启,否则是直接关闭!
|
||||
*/
|
||||
public ZlmResponse<Void> restartServer(){
|
||||
return exchange.restartServer(secret);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,13 @@
|
||||
package cn.skcks.docking.gb28181.test;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.core.net.url.UrlPath;
|
||||
import cn.skcks.docking.gb28181.common.json.JsonResponse;
|
||||
import cn.skcks.docking.gb28181.common.json.JsonUtils;
|
||||
import cn.skcks.docking.gb28181.media.config.ZlmMediaConfig;
|
||||
import cn.skcks.docking.gb28181.media.dto.config.FFMpegConfig;
|
||||
import cn.skcks.docking.gb28181.media.dto.config.HookConfig;
|
||||
import cn.skcks.docking.gb28181.media.dto.config.ServerConfig;
|
||||
import cn.skcks.docking.gb28181.media.dto.proxy.AddStreamPusherProxy;
|
||||
@ -14,10 +19,12 @@ import cn.skcks.docking.gb28181.media.dto.rtp.CloseRtpServer;
|
||||
import cn.skcks.docking.gb28181.media.dto.rtp.OpenRtpServer;
|
||||
import cn.skcks.docking.gb28181.media.dto.rtp.RtpServer;
|
||||
import cn.skcks.docking.gb28181.media.dto.rtp.StartSendRtp;
|
||||
import cn.skcks.docking.gb28181.media.dto.snap.Snap;
|
||||
import cn.skcks.docking.gb28181.media.dto.version.VersionResp;
|
||||
import cn.skcks.docking.gb28181.media.proxy.ZlmMediaService;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -27,6 +34,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import java.net.URL;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
@ -39,6 +47,8 @@ import java.util.*;
|
||||
public class MediaServiceTest {
|
||||
@Autowired
|
||||
private ZlmMediaService zlmMediaService;
|
||||
@Autowired
|
||||
private ZlmMediaConfig config;
|
||||
|
||||
@Test
|
||||
void test(){
|
||||
@ -144,6 +154,28 @@ public class MediaServiceTest {
|
||||
log.info("{}",delStreamPusherProxyRespZlmResponse);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SneakyThrows
|
||||
void snapTest(){
|
||||
Snap snap = new Snap();
|
||||
// String url = UrlBuilder.of(config.getUrl())
|
||||
// .setScheme("rtmp")
|
||||
// .setPath(UrlPath.of("/live/test", null)).build();
|
||||
// log.info("url => {}", url);
|
||||
snap.setUrl("rtmp://127.0.0.1:1935/live/test");
|
||||
snap.setTimeoutSec(180);
|
||||
snap.setExpireSec(5);
|
||||
ResponseEntity<byte[]> response = zlmMediaService.getSnap(snap);
|
||||
log.info("{}", Objects.requireNonNull(response.getBody()).length);
|
||||
log.info("base64 snap => \n{}",Base64.encode(response.getBody()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void restartServer(){
|
||||
ZlmResponse<Void> response = zlmMediaService.restartServer();
|
||||
log.info("{}", response);
|
||||
}
|
||||
|
||||
@Test
|
||||
void simpleTest(){
|
||||
StartSendRtp startSendRtp = new StartSendRtp();
|
||||
|
Loading…
Reference in New Issue
Block a user