From af0229ac55720dd3e68d99e96a9f36ff8f441875 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Tue, 5 Sep 2023 17:28:22 +0800 Subject: [PATCH] =?UTF-8?q?feign=20=E4=BB=A3=E7=90=86=20zlm=20=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/wvp/api/VideoController.java | 30 ++++++++++++++----- .../gb28181/wvp/proxy/ZlmProxyClient.java | 12 ++++++++ .../src/main/resources/application.yml | 8 ++--- 3 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/proxy/ZlmProxyClient.java diff --git a/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/VideoController.java b/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/VideoController.java index 575d1a0..b5012f6 100644 --- a/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/VideoController.java +++ b/gb28181-wvp-proxy-api/src/main/java/cn/skcks/docking/gb28181/wvp/api/VideoController.java @@ -1,42 +1,56 @@ package cn.skcks.docking.gb28181.wvp.api; +import cn.hutool.core.io.IoUtil; import cn.skcks.docking.gb28181.wvp.config.SwaggerConfig; +import cn.skcks.docking.gb28181.wvp.proxy.ZlmProxyClient; +import feign.Response; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; import org.springdoc.core.models.GroupedOpenApi; import org.springframework.context.annotation.Bean; -import org.springframework.core.io.FileSystemResource; import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; -import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; @Tag(name = "视频api") @Controller @RequestMapping("/video") +@RequiredArgsConstructor public class VideoController { + private final ZlmProxyClient zlmProxyClient; + @Bean public GroupedOpenApi videoApi() { return SwaggerConfig.api("VideoApi", "/video"); } @Operation(summary = "获取视频") - @GetMapping(consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) - public ResponseEntity video(HttpServletResponse response) { + @GetMapping(produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) + @ResponseBody + public void video(HttpServletResponse response) { response.reset(); // response.setHeader("Content-Type","video/mp4"); - File f = new File("E:\\#Camera\\DCIM\\100MEDIA\\20230818\\NORM0003.MP4"); +// File f = new File("E:\\#Camera\\DCIM\\100MEDIA\\20230818\\NORM0003.MP4"); // try ( // BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(f)); // BufferedOutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) { // IoUtil.copy(inputStream, outputStream); // } - FileSystemResource fileSystemResource = new FileSystemResource(f); - return ResponseEntity.ok().body(fileSystemResource); + try (Response live = zlmProxyClient.live("live", "test.live.mp4")) { + InputStream inputStream = live.body().asInputStream(); + OutputStream outputStream = response.getOutputStream(); + IoUtil.copy(inputStream, outputStream); + } catch (IOException e) { + throw new RuntimeException(e); + } } } diff --git a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/proxy/ZlmProxyClient.java b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/proxy/ZlmProxyClient.java new file mode 100644 index 0000000..9b1e5b0 --- /dev/null +++ b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/proxy/ZlmProxyClient.java @@ -0,0 +1,12 @@ +package cn.skcks.docking.gb28181.wvp.proxy; + +import feign.Response; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@FeignClient(name="zlmProxyClient", url = "${media.url}") +public interface ZlmProxyClient { + @GetMapping("/{app}/{streamId}") + Response live(@PathVariable String app,@PathVariable String streamId); +} diff --git a/gb28181-wvp-proxy-starter/src/main/resources/application.yml b/gb28181-wvp-proxy-starter/src/main/resources/application.yml index 8dc184e..b13d785 100644 --- a/gb28181-wvp-proxy-starter/src/main/resources/application.yml +++ b/gb28181-wvp-proxy-starter/src/main/resources/application.yml @@ -26,12 +26,12 @@ spring: url: jdbc:mysql://192.168.1.241:3306/gb28181_docking_platform?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai media: - ip: 192.168.3.12 - url: 'http://192.168.3.12:5081' + ip: 192.168.1.241 + url: 'http://192.168.1.241:5080' # url: 'http://10.10.10.200:12580/anything/' id: amrWMKmbKqoBjRQ9 - # secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc - secret: 4155cca6-2f9f-11ee-85e6-8de4ce2e7333 + secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc +# secret: 4155cca6-2f9f-11ee-85e6-8de4ce2e7333 proxy: wvp: