[+] RTP接入
This commit is contained in:
@@ -2,6 +2,7 @@ package com.acgist.taoyao.signal.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -25,6 +26,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
* @author acgist
|
||||
*/
|
||||
@Tag(name = "房间", description = "房间管理")
|
||||
@Validated
|
||||
@RestController
|
||||
@RequestMapping("/room")
|
||||
public class RoomController {
|
||||
|
||||
@@ -9,7 +9,7 @@ import jakarta.validation.constraints.NotNull;
|
||||
* @author acgist
|
||||
*/
|
||||
@Schema(title = "PTZ控制参数", description = "PTZ控制参数")
|
||||
public class PtzControl {
|
||||
public class PtzModel {
|
||||
|
||||
/**
|
||||
* PTZ类型
|
||||
@@ -7,7 +7,7 @@ import com.acgist.taoyao.boot.annotation.Protocol;
|
||||
import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.signal.client.Client;
|
||||
import com.acgist.taoyao.signal.client.ClientType;
|
||||
import com.acgist.taoyao.signal.model.control.PtzControl;
|
||||
import com.acgist.taoyao.signal.model.control.PtzModel;
|
||||
import com.acgist.taoyao.signal.protocol.ProtocolControlAdapter;
|
||||
|
||||
/**
|
||||
@@ -43,12 +43,12 @@ public class ControlPtzProtocol extends ProtocolControlAdapter {
|
||||
|
||||
/**
|
||||
* @param clientId 终端标识
|
||||
* @param ptzControl PTZ控制参数
|
||||
* @param ptzModel PTZ控制参数
|
||||
*
|
||||
* @return 执行结果
|
||||
*/
|
||||
public Message execute(String clientId, PtzControl ptzControl) {
|
||||
return this.request(clientId, this.build(ptzControl));
|
||||
public Message execute(String clientId, PtzModel ptzModel) {
|
||||
return this.request(clientId, this.build(ptzModel));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.acgist.taoyao.signal.protocol.media;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.acgist.taoyao.boot.annotation.Description;
|
||||
import com.acgist.taoyao.boot.annotation.Protocol;
|
||||
import com.acgist.taoyao.boot.config.Constant;
|
||||
import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.boot.utils.MapUtils;
|
||||
import com.acgist.taoyao.boot.utils.NetUtils;
|
||||
import com.acgist.taoyao.signal.client.Client;
|
||||
import com.acgist.taoyao.signal.client.ClientType;
|
||||
import com.acgist.taoyao.signal.party.media.ClientWrapper;
|
||||
import com.acgist.taoyao.signal.party.media.Room;
|
||||
import com.acgist.taoyao.signal.party.media.Transport;
|
||||
import com.acgist.taoyao.signal.party.media.Transport.Direction;
|
||||
import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 创建RTP输入通道信令
|
||||
* TODO:srtp
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
@Protocol
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID",
|
||||
"rtcpMux": RTP和RTCP端口复用(true|false),
|
||||
"comedia": 自动终端端口(true|false),
|
||||
}
|
||||
"""
|
||||
)
|
||||
public class MediaTransportPlainInProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
public static final String SIGNAL = "media::transport::plain::in";
|
||||
|
||||
public MediaTransportPlainInProtocol() {
|
||||
super("创建RTP输入通道信令", SIGNAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Room room, Client client, Client mediaClient, Message message, Map<String, Object> body) {
|
||||
body.put(Constant.CLIENT_ID, clientId);
|
||||
final Message response = room.request(message);
|
||||
final Map<String, Object> responseBody = response.body();
|
||||
final Map<String, Transport> transports = room.getTransports();
|
||||
final String transportId = MapUtils.get(responseBody, Constant.TRANSPORT_ID);
|
||||
// 重写地址
|
||||
this.rewriteIp(client.ip(), responseBody);
|
||||
// 处理逻辑
|
||||
final ClientWrapper clientWrapper = room.clientWrapper(client);
|
||||
// 生产者
|
||||
Transport sendTransport = clientWrapper.getSendTransport();
|
||||
if(sendTransport == null) {
|
||||
sendTransport = new Transport(transportId, Direction.SEND, room, client);
|
||||
transports.put(transportId, sendTransport);
|
||||
} else {
|
||||
log.warn("发送通道已经存在:{}", transportId);
|
||||
}
|
||||
clientWrapper.setSendTransport(sendTransport);
|
||||
// 拷贝属性
|
||||
sendTransport.copy(responseBody);
|
||||
client.push(response);
|
||||
log.info("{}创建RTP信令通道:{}", clientId, transportId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写IP地址
|
||||
*
|
||||
* @param clientIp 终端IP
|
||||
* @param body 消息主体
|
||||
*/
|
||||
private void rewriteIp(String clientIp, Map<String, Object> body) {
|
||||
// 媒体服务返回IP
|
||||
final String mediaIp = (String) body.get(Constant.IP);
|
||||
if(StringUtils.isNotEmpty(mediaIp)) {
|
||||
final String rewriteIp = NetUtils.rewriteIp(mediaIp, clientIp);
|
||||
log.debug("重写地址:{} + {} -> {}", mediaIp, clientIp, rewriteIp);
|
||||
body.put(Constant.IP, rewriteIp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.acgist.taoyao.signal.protocol.media;
|
||||
|
||||
/**
|
||||
* 创建RTP通道信令
|
||||
* 创建RTP输出通道信令
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public class MediaTransportPlainCreateProtocol {
|
||||
|
||||
public class MediaTransportPlainOutProtocol {
|
||||
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class MediaTransportWebRtcConnectProtocol extends ProtocolRoomAdapter {
|
||||
final Map<String, Object> responseBody = response.body();
|
||||
client.push(response);
|
||||
final String transportId = MapUtils.get(responseBody, Constant.TRANSPORT_ID);
|
||||
log.info("{}连接WebRTC信令通道:{}", clientId, transportId);
|
||||
log.info("{}连接WebRTC通道信令:{}", clientId, transportId);
|
||||
} else {
|
||||
// 忽略其他情况
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class MediaTransportWebRtcCreateProtocol extends ProtocolRoomAdapter {
|
||||
sendTransport.copy(responseBody);
|
||||
}
|
||||
client.push(response);
|
||||
log.info("{}创建WebRTC信令通道:{}", clientId, transportId);
|
||||
log.info("{}创建WebRTC通道信令:{}", clientId, transportId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user