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