|
...
|
...
|
@@ -11,7 +11,9 @@ import org.slf4j.LoggerFactory; |
|
|
|
import java.net.DatagramSocket;
|
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.net.NetworkInterface;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Enumeration;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class WebRtcService {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(App.class);
|
|
...
|
...
|
@@ -20,6 +22,19 @@ public class WebRtcService { |
|
|
|
|
|
|
|
public static JSONObject startStream(String stream,String rtspUrl,String app,String secret,String auto_close)
|
|
|
|
{
|
|
|
|
String[] rtspurls = rtspUrl.split(",");
|
|
|
|
if(rtspurls.length!=0)
|
|
|
|
{
|
|
|
|
String playurls = "";
|
|
|
|
int i = 1;
|
|
|
|
String localip = WebRtcService.getLocalIpAddress();
|
|
|
|
for(String rtspurl : rtspurls) {
|
|
|
|
String newStream = stream;
|
|
|
|
newStream = stream+"_"+i++;
|
|
|
|
String playurl = WebRtcService.getPlayUrl(localip, app, newStream);
|
|
|
|
boolean oline = WebRtcService.isMediaOnline(newStream,app, SysConfig.getWebrtcSecret());
|
|
|
|
if (!oline)
|
|
|
|
{
|
|
|
|
StringBuffer stringBuffer = getZlmApi();
|
|
|
|
stringBuffer.append("/addStreamProxy?");
|
|
|
|
stringBuffer.append("secret=");
|
|
...
|
...
|
@@ -28,9 +43,9 @@ public class WebRtcService { |
|
|
|
stringBuffer.append("&app=");
|
|
|
|
stringBuffer.append(app);
|
|
|
|
stringBuffer.append("&stream=");
|
|
|
|
stringBuffer.append(stream);
|
|
|
|
stringBuffer.append(newStream);
|
|
|
|
stringBuffer.append("&url=");
|
|
|
|
stringBuffer.append(rtspUrl);
|
|
|
|
stringBuffer.append(rtspurl);
|
|
|
|
stringBuffer.append("&enable_auto_close=1");
|
|
|
|
stringBuffer.append("&retry_count=-1&rtp_type=0&timeout_sec=10&enable_hls=false&enable_hls_fmp4=false&enable_mp4=false&enable_rtsp=true&enable_rtmp=false&enable_ts=false&enable_fmp4=true&hls_demand=false&rtsp_demand=false&rtmp_demand=false&ts_demand=false&fmp4_demand=false&enable_audio=true&add_mute_audio=true&mp4_max_second=10&mp4_as_player=false&auto_close="+auto_close);
|
|
|
|
logger.info("添加流的接口请求:"+stringBuffer.toString());
|
|
...
|
...
|
@@ -39,15 +54,38 @@ public class WebRtcService { |
|
|
|
if(jsonObject.containsKey("code") && jsonObject.getInteger("code")==0)
|
|
|
|
{
|
|
|
|
jsonObject.put("code",1);
|
|
|
|
String localip = WebRtcService.getLocalIpAddress();
|
|
|
|
String playurl = WebRtcService.getPlayUrl(localip, SysConfig.webrtc_app, stream);
|
|
|
|
jsonObject.getJSONObject("data").put("playurl",playurl);
|
|
|
|
return jsonObject;
|
|
|
|
if(!"".equals(playurls))
|
|
|
|
{
|
|
|
|
playurls += ",";
|
|
|
|
}
|
|
|
|
playurls+=playurl;
|
|
|
|
}else {
|
|
|
|
jsonObject.put("code",0);
|
|
|
|
System.out.println(str);
|
|
|
|
return jsonObject;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(!"".equals(playurls))
|
|
|
|
{
|
|
|
|
playurls += ",";
|
|
|
|
}
|
|
|
|
playurls+=playurl;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
jsonObject.put("code",1);
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
|
data.put("playurl",playurls);
|
|
|
|
data.put("key",secret);
|
|
|
|
jsonObject.put("data",data);
|
|
|
|
return jsonObject;
|
|
|
|
}
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
jsonObject.put("code",0);
|
|
|
|
jsonObject.put("msg","rtspUrl参数错误");
|
|
|
|
return jsonObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String stopStream( String stream,String app,String secret) {
|
|
|
|
String url = getZlmApi() + "/close_stream?schema=rtsp&vhost=__defaultVhost__&app=" + app + "&stream=" + stream+"&force=1&secret="+secret;
|
...
|
...
|
|