[*] 日常优化
This commit is contained in:
@@ -783,6 +783,7 @@ public final class Taoyao implements ITaoyao {
|
||||
private void controlConfigAudio(Message message, Map<String, Object> body) {
|
||||
final MediaAudioProperties mediaAudioProperties = JSONUtils.toJava(JSONUtils.toJSON(body), MediaAudioProperties.class);
|
||||
this.mediaManager.updateAudioConfig(mediaAudioProperties);
|
||||
this.push(message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -794,6 +795,7 @@ public final class Taoyao implements ITaoyao {
|
||||
private void controlConfigVideo(Message message, Map<String, Object> body) {
|
||||
final MediaVideoProperties mediaVideoProperties = JSONUtils.toJava(JSONUtils.toJSON(body), MediaVideoProperties.class);
|
||||
this.mediaManager.updateVideoConfig(mediaVideoProperties);
|
||||
this.push(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -274,11 +274,9 @@ class Room {
|
||||
const me = this;
|
||||
// 静音监控
|
||||
me.audioLevelObserver.on("silence", () => {
|
||||
signalChannel.push(
|
||||
protocol.buildMessage("media::audio::volume", {
|
||||
roomId: me.roomId,
|
||||
})
|
||||
);
|
||||
signalChannel.push(protocol.buildMessage("media::audio::volume", {
|
||||
roomId: me.roomId,
|
||||
}));
|
||||
});
|
||||
// me.audioLevelObserver.observer.on("silence", () => {});
|
||||
// 音量监控
|
||||
@@ -291,12 +289,10 @@ class Room {
|
||||
clientId: producer.clientId
|
||||
});
|
||||
}
|
||||
signalChannel.push(
|
||||
protocol.buildMessage("media::audio::volume", {
|
||||
roomId : me.roomId,
|
||||
volumes: notifyVolumes
|
||||
})
|
||||
);
|
||||
signalChannel.push(protocol.buildMessage("media::audio::volume", {
|
||||
roomId : me.roomId,
|
||||
volumes: notifyVolumes
|
||||
}));
|
||||
});
|
||||
// me.audioLevelObserver.observer.on("volumes", (volumes) => {});
|
||||
}
|
||||
@@ -702,8 +698,9 @@ class Taoyao {
|
||||
}
|
||||
if(videoConsumer) {
|
||||
await videoConsumer.resume();
|
||||
// 请求录像关键帧
|
||||
me.requestKeyFrameForRecord(0, filepath, videoConsumer);
|
||||
}
|
||||
this.requestKeyFrameForRecord(0, filepath, videoConsumer);
|
||||
message.body = {
|
||||
roomId : roomId,
|
||||
audioConsumerId : audioConsumerId,
|
||||
@@ -725,9 +722,6 @@ class Taoyao {
|
||||
* @param {*} videoConsumer 视频消费者
|
||||
*/
|
||||
requestKeyFrameForRecord(index, filepath, videoConsumer) {
|
||||
if(!filepath || !videoConsumer) {
|
||||
return;
|
||||
}
|
||||
const {
|
||||
requestKeyFrameMaxIndex,
|
||||
requestKeyFrameFileSize
|
||||
@@ -1715,7 +1709,7 @@ class Taoyao {
|
||||
const mediasoupRouter = await mediasoupWorker.createRouter({ mediaCodecs });
|
||||
// 音量监控
|
||||
const audioLevelObserver = await mediasoupRouter.createAudioLevelObserver({
|
||||
interval : 2000,
|
||||
interval : 500,
|
||||
// 范围:-127~0
|
||||
threshold : -80,
|
||||
// 监控数量
|
||||
|
||||
@@ -817,10 +817,10 @@ class Taoyao extends RemoteClient {
|
||||
me.defaultMediaConsumerClose(message);
|
||||
break;
|
||||
case "media::consumer::pause":
|
||||
this.defaultMediaConsumerPause(message);
|
||||
me.defaultMediaConsumerPause(message);
|
||||
break;
|
||||
case "media::consumer::resume":
|
||||
this.defaultMediaConsumerResume(message);
|
||||
me.defaultMediaConsumerResume(message);
|
||||
break;
|
||||
case "media::data::consumer::close":
|
||||
me.defaultMediaDataConsumerClose(message);
|
||||
@@ -1392,25 +1392,31 @@ class Taoyao extends RemoteClient {
|
||||
*/
|
||||
defaultMediaAudioVolume(message) {
|
||||
const me = this;
|
||||
const { roomId, volumes } = message.body;
|
||||
// 静音
|
||||
if (!volumes || volumes.length <= 0) {
|
||||
const {
|
||||
roomId,
|
||||
volumes
|
||||
} = message.body;
|
||||
if (volumes && volumes.length > 0) {
|
||||
// 声音
|
||||
volumes.forEach(v => {
|
||||
const {
|
||||
volume,
|
||||
clientId
|
||||
} = v;
|
||||
if (me.clientId === clientId) {
|
||||
me.setVolume(volume);
|
||||
} else {
|
||||
const remoteClient = me.remoteClients.get(clientId);
|
||||
remoteClient?.setVolume(volume);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 静音
|
||||
me.volume = 0;
|
||||
me.remoteClients.forEach(v => {
|
||||
v.volume = 0;
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 声音
|
||||
volumes.forEach(v => {
|
||||
const { volume, clientId } = v;
|
||||
if (me.clientId === clientId) {
|
||||
me.setVolume(volume);
|
||||
} else {
|
||||
const remoteClient = me.remoteClients.get(clientId);
|
||||
remoteClient?.setVolume(volume);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1900,7 +1906,10 @@ class Taoyao extends RemoteClient {
|
||||
console.debug("消费者关闭(无效)", consumer.id, streamId);
|
||||
}
|
||||
});
|
||||
const { spatialLayers, temporalLayers } = mediasoupClient.parseScalabilityMode(
|
||||
const {
|
||||
spatialLayers,
|
||||
temporalLayers
|
||||
} = mediasoupClient.parseScalabilityMode(
|
||||
consumer.rtpParameters.encodings[0].scalabilityMode
|
||||
);
|
||||
console.debug("时间层空间层", spatialLayers, temporalLayers);
|
||||
|
||||
@@ -19,33 +19,33 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID",
|
||||
"roomId" : "房间ID",
|
||||
"volumes" : [
|
||||
{
|
||||
"volume": 音量,
|
||||
"volume" : 音量,
|
||||
"clientId": "终端ID"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
""",
|
||||
flow = "媒体服务->信令服务->终端"
|
||||
flow = "媒体服务->信令服务-)终端"
|
||||
)
|
||||
public class MediaAudioVolumeProtocol extends ProtocolRoomAdapter {
|
||||
|
||||
public static final String SIGNAL = "media::audio::volume";
|
||||
public static final String SIGNAL = "media::audio::volume";
|
||||
|
||||
public MediaAudioVolumeProtocol() {
|
||||
super("终端音量信令", SIGNAL);
|
||||
}
|
||||
public MediaAudioVolumeProtocol() {
|
||||
super("终端音量信令", SIGNAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Room room, Client client, Client mediaClient, Message message, Map<String, Object> body) {
|
||||
if(clientType.mediaServer()) {
|
||||
room.broadcast(message);
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Room room, Client client, Client mediaClient, Message message, Map<String, Object> body) {
|
||||
if(clientType.mediaServer()) {
|
||||
room.broadcast(message);
|
||||
} else {
|
||||
this.logNoAdapter(clientType);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,14 +39,14 @@ import lombok.extern.slf4j.Slf4j;
|
||||
""",
|
||||
body = """
|
||||
{
|
||||
"roomId": "房间ID"
|
||||
"roomId" : "房间ID"
|
||||
"producerId": "生产者ID"
|
||||
}
|
||||
""",
|
||||
flow = {
|
||||
"终端-[生产媒体]>信令服务-[其他终端消费])信令服务",
|
||||
"终端-[创建WebRTC消费通道]>信令服务-[消费其他终端])信令服务",
|
||||
"终端->信令服务->媒体服务=>信令服务->终端->信令服务->媒体服务"
|
||||
"终端-[生产媒体]>信令服务-[消费媒体])信令服务=>信令服务->终端",
|
||||
"终端-[创建WebRTC通道]>信令服务-[消费媒体])信令服务=>信令服务->终端",
|
||||
"终端->信令服务->媒体服务=>信令服务->终端"
|
||||
}
|
||||
)
|
||||
public class MediaConsumeProtocol extends ProtocolRoomAdapter implements ApplicationListener<MediaConsumeEvent> {
|
||||
@@ -63,12 +63,12 @@ public class MediaConsumeProtocol extends ProtocolRoomAdapter implements Applica
|
||||
final Room room = event.getRoom();
|
||||
if(event.getProducer() != null) {
|
||||
// 生产媒体:其他终端消费
|
||||
final Producer producer = event.getProducer();
|
||||
final Producer producer = event.getProducer();
|
||||
final ClientWrapper produceClientWrapper = producer.getProducerClient();
|
||||
room.getClients().values().stream()
|
||||
.filter(v -> v != produceClientWrapper)
|
||||
.filter(v -> v.getRecvTransport() != null)
|
||||
.filter(v -> v.getSubscribeType().canConsume(producer))
|
||||
.filter(v -> v != produceClientWrapper)
|
||||
.filter(v -> v.getRecvTransport() != null)
|
||||
.filter(v -> v.getSubscribeType().canConsume(producer))
|
||||
.forEach(v -> this.consume(room, v, producer, this.build()));
|
||||
} else if(event.getClientWrapper() != null) {
|
||||
// 创建WebRTC消费通道:消费其他终端
|
||||
@@ -78,9 +78,9 @@ public class MediaConsumeProtocol extends ProtocolRoomAdapter implements Applica
|
||||
return;
|
||||
}
|
||||
room.getClients().values().stream()
|
||||
.filter(v -> v != consumeClientWrapper)
|
||||
.filter(v -> v != consumeClientWrapper)
|
||||
.flatMap(v -> v.getProducers().values().stream())
|
||||
.filter(v -> consumeClientWrapper.getSubscribeType().canConsume(v))
|
||||
.filter(v -> consumeClientWrapper.getSubscribeType().canConsume(v))
|
||||
.forEach(producer -> this.consume(room, consumeClientWrapper, producer, this.build()));
|
||||
} else {
|
||||
throw MessageCodeException.of("消费媒体失败");
|
||||
@@ -121,10 +121,10 @@ public class MediaConsumeProtocol extends ProtocolRoomAdapter implements Applica
|
||||
/**
|
||||
* 消费媒体
|
||||
*
|
||||
* @param room 房间
|
||||
* @param room 房间
|
||||
* @param consumerClientWrapper 消费者终端包装器
|
||||
* @param producer 生产者
|
||||
* @param message 消息
|
||||
* @param producer 生产者
|
||||
* @param message 消息
|
||||
*/
|
||||
private void consume(Room room, ClientWrapper consumerClientWrapper, Producer producer, Message message) {
|
||||
final Client mediaClient = room.getMediaClient();
|
||||
|
||||
Reference in New Issue
Block a user