|
@@ -7,6 +7,8 @@ import java.util.Map;
|
|
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
|
import cn.hutool.core.codec.Base64Decoder;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import jakarta.validation.constraints.*;
|
|
@@ -118,31 +120,37 @@ public class TblDeviceController extends BaseController {
|
|
|
@Value("${user.ffmpegpath}")
|
|
|
private String ffmpegFilePath = "/usr/local/bin/ffmpeg";
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Value(value = "${user.mediaserver.url}")
|
|
|
+ private String mediaUrl;
|
|
|
+
|
|
|
+ @Value(value = "${user.mediaserver.secret}")
|
|
|
+ private String mediaSecret;
|
|
|
+
|
|
|
+ @Value(value = "${user.mediaserver.defaultVhost}")
|
|
|
+ private String mediavHost;
|
|
|
+
|
|
|
+
|
|
|
@GetMapping("/rtmp/{from}")
|
|
|
public R<Object> getHlsCode(@PathVariable("from") String from) {
|
|
|
Object data = "";
|
|
|
try {
|
|
|
-
|
|
|
from = Base64Decoder.decodeStr(from);
|
|
|
String p[] = from.split("/");
|
|
|
- if (rtmptohlsmap.get(from) != null && rtmptohlsmap.get(from).isAlive()) {
|
|
|
-
|
|
|
- } else {
|
|
|
- File pc = new File(path + p[p.length - 1] + "");
|
|
|
- if (!pc.exists()) {
|
|
|
- pc.mkdir();
|
|
|
- pc.setWritable(true, false);
|
|
|
- File pc1 = new File(path + p[p.length - 1] + "/playlist.m3u8");
|
|
|
- pc1.createNewFile();
|
|
|
- pc1.setWritable(true, false);
|
|
|
-
|
|
|
- }
|
|
|
- rtmptohlsmap.put(from, Utils.push(ffmpegFilePath, from, path + p[p.length - 1] + "/playlist.m3u8"));
|
|
|
+ String key = p[p.length - 1];
|
|
|
+ //添加
|
|
|
+ String res = HttpUtil.get(mediaUrl + "/index/api/addStreamProxy?secret=" + mediaSecret + "&vhost=" + mediavHost + "&app=hls&stream=" + key + "&url=" + from);
|
|
|
+ if (JSONUtil.parseObj(res).getInt("code") == 0||res.contains("exists")) {
|
|
|
+ data = url+key+"/hls.m3u8";
|
|
|
+ return R.ok(data);
|
|
|
}
|
|
|
- data = url + p[p.length - 1] + "/playlist.m3u8";
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
+ }catch (Exception e){
|
|
|
+ return R.fail("转码失败");
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
return R.ok(data);
|
|
|
}
|
|
|
|
|
@@ -153,12 +161,15 @@ public class TblDeviceController extends BaseController {
|
|
|
|
|
|
from = Base64Decoder.decodeStr(from);
|
|
|
String p[] = from.split("/");
|
|
|
- if (rtmptohlsmap.get(from) != null && rtmptohlsmap.get(from).isAlive()) {
|
|
|
- rtmptohlsmap.get(from).interrupt();
|
|
|
- rtmptohlsmap.remove(from);
|
|
|
+ String key = p[p.length - 1];
|
|
|
+ //添加
|
|
|
+ String res = HttpUtil.get(mediaUrl + "/index/api/delStreamProxy?secret=" + mediaSecret + "&key=" + (mediavHost+"hls/"+key) );
|
|
|
+ if (JSONUtil.parseObj(res).getInt("code") == 0) {
|
|
|
+ data = "success";
|
|
|
+ return R.ok(data);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
-
|
|
|
+ return R.fail("关闭转码失败");
|
|
|
}
|
|
|
return R.ok(data);
|
|
|
}
|