[+] RTP接入

This commit is contained in:
acgist
2023-03-12 17:22:23 +08:00
parent ab8646a21f
commit 72e4b34630
11 changed files with 176 additions and 44 deletions

View File

@@ -12,7 +12,7 @@ import com.acgist.taoyao.boot.model.Message;
import com.acgist.taoyao.signal.config.camera.AiProperties;
import com.acgist.taoyao.signal.config.camera.BeautyProperties;
import com.acgist.taoyao.signal.config.camera.WatermarkProperties;
import com.acgist.taoyao.signal.model.control.PtzControl;
import com.acgist.taoyao.signal.model.control.PtzModel;
import com.acgist.taoyao.signal.protocol.control.ControlAiProtocol;
import com.acgist.taoyao.signal.protocol.control.ControlBeautyProtocol;
import com.acgist.taoyao.signal.protocol.control.ControlBellProtocol;
@@ -79,8 +79,8 @@ public class ControlController {
@Operation(summary = "PTZ", description = "PTZ控制")
@GetMapping("/ptz/{clientId}")
public Message ptz(@PathVariable String clientId, @Valid PtzControl ptzControl) {
return Message.success(this.controlPtzProtocol.execute(clientId, ptzControl));
public Message ptz(@PathVariable String clientId, @Valid PtzModel ptzModel) {
return Message.success(this.controlPtzProtocol.execute(clientId, ptzModel));
}
@Operation(summary = "响铃", description = "响铃控制")

View File

@@ -5,12 +5,11 @@ import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.Scanner;
import javax.crypto.Cipher;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import com.acgist.taoyao.boot.config.SocketProperties.Encrypt;
@@ -26,13 +25,10 @@ public class SocketSignalTest {
void testSocket() throws Exception {
final Socket socket = new Socket();
socket.connect(new InetSocketAddress("127.0.0.1", 9999));
final AtomicInteger recvIndex = new AtomicInteger();
final InputStream inputStream = socket.getInputStream();
final OutputStream outputStream = socket.getOutputStream();
// 随机密码https://localhost:8888/config/socket
final String secret = """
Oi7ZvxZEcOU=
""".strip();
final String secret = "TSFXzB7hcfE=".strip();
final Cipher encrypt = CipherUtils.buildCipher(Cipher.ENCRYPT_MODE, Encrypt.DES, secret);
final Cipher decrypt = CipherUtils.buildCipher(Cipher.DECRYPT_MODE, Encrypt.DES, secret);
// 接收
@@ -68,7 +64,6 @@ public class SocketSignalTest {
buffer.get(message);
buffer.compact();
log.debug("收到消息:{}", new String(decrypt.doFinal(message)));
recvIndex.incrementAndGet();
}
}
}
@@ -78,30 +73,41 @@ public class SocketSignalTest {
}
}).start();
// 发送
final AtomicInteger sendIndex = new AtomicInteger();
final Executor executor = Executors.newFixedThreadPool(10);
for (int index = 0; index < 100; index++) {
executor.execute(() -> {
try {
final byte[] bytes = ("{\"time\":" + System.nanoTime() + "}").getBytes();
final byte[] encryptBytes = encrypt.doFinal(bytes);
final ByteBuffer buffer = ByteBuffer.allocateDirect(Short.BYTES + encryptBytes.length);
buffer.putShort((short) encryptBytes.length);
buffer.put(encryptBytes);
buffer.flip();
final byte[] message = new byte[buffer.capacity()];
buffer.get(message);
outputStream.write(message);
sendIndex.incrementAndGet();
} catch (Exception e) {
log.error("发送异常", e);
}
});
}
Thread.sleep(5000);
log.info("发送数据:{}", sendIndex.get());
log.info("接收数据:{}", recvIndex.get());
String line = """
{
"header":{"v":"1.0.0","id":1215293599999001,"signal":"client::register"},
"body":{"clientId":"ffmpeg","name":"ffmpeg","clientType":"WEB","battery":100,"charging":true,"username":"taoyao","password":"taoyao"}
}
""";
// {"header":{"v":"1.0.0","id":1215310510002009,"signal":"room::enter"},"body":{"roomId":"8260e615-3081-4bfc-96a8-574f4dd780d9"}}
// {"header":{"v":"1.0.0","id":1215310510002010,"signal":"media::transport::plain::in"},"body":{"roomId":"8260e615-3081-4bfc-96a8-574f4dd780d9","rtcpMux":false,"comedia":true}}
// {"header":{"v":"1.0.0","id":1215375110006012,"signal":"media::produce"},"body":{"kind":"video","roomId":"8260e615-3081-4bfc-96a8-574f4dd780d9","transportId":"14dc9307-bf9c-4442-a9ad-ce6a97623ef4","appData":{},"rtpParameters":{"codecs":[{"mimeType":"video/vp8","clockRate":90000,"payloadType":102,"rtcpFeedback":[]}],"encodings":[{"ssrc":123123}]}}}
// ffplay -protocol_whitelist "file,udp,rtp" taoyao.sdp
// ffmpeg -re -i video.mp4 -vcodec copy -map 0:0 -f rtp rtp://localhost:6666 > taoyao.sdp
// ffmpeg不支持rtcpMux
// ffmpeg -re -i video.mp4 -c:v libvpx -map 0:0 -f tee "[select=v:f=rtp:ssrc=123123:payload_type=102]rtp://192.168.1.110:40793?rtcpport=47218"
// ffmpeg -re -i video.mp4 -vcodec vp8 -map 0:0 -f tee "[select=v:f=rtp:ssrc=123123:payload_type=102]rtp://192.168.1.110:40793?rtcpport=47218"
final Scanner scanner = new Scanner(System.in);
do {
if(StringUtils.isEmpty(line)) {
break;
}
try {
final byte[] bytes = line.getBytes();
final byte[] encryptBytes = encrypt.doFinal(bytes);
final ByteBuffer buffer = ByteBuffer.allocateDirect(Short.BYTES + encryptBytes.length);
buffer.putShort((short) encryptBytes.length);
buffer.put(encryptBytes);
buffer.flip();
final byte[] message = new byte[buffer.capacity()];
buffer.get(message);
outputStream.write(message);
} catch (Exception e) {
log.error("发送异常", e);
}
} while((line = scanner.next()) != null);
socket.close();
scanner.close();
}
}