[*] 日常优化
This commit is contained in:
@@ -414,6 +414,12 @@ class Taoyao {
|
|||||||
case "media::consumer::set::preferred::layers":
|
case "media::consumer::set::preferred::layers":
|
||||||
me.mediaConsumerSetPreferredLayers(message, body);
|
me.mediaConsumerSetPreferredLayers(message, body);
|
||||||
break;
|
break;
|
||||||
|
case "media::consumer::set::priority":
|
||||||
|
me.mediaConsumerSetPriority(message, body);
|
||||||
|
break;
|
||||||
|
case "media::consumer::status":
|
||||||
|
me.mediaConsumerStatus(message, body);
|
||||||
|
break;
|
||||||
case "media::data::consume":
|
case "media::data::consume":
|
||||||
me.mediaDataConsume(message, body);
|
me.mediaDataConsume(message, body);
|
||||||
break;
|
break;
|
||||||
@@ -1060,9 +1066,9 @@ class Taoyao {
|
|||||||
console.debug("消费者评分", consumer.id, streamId, score);
|
console.debug("消费者评分", consumer.id, streamId, score);
|
||||||
me.push(
|
me.push(
|
||||||
protocol.buildMessage("media::consumer::score", {
|
protocol.buildMessage("media::consumer::score", {
|
||||||
score : score,
|
|
||||||
roomId : roomId,
|
roomId : roomId,
|
||||||
consumerId: consumer.id,
|
consumerId: consumer.id,
|
||||||
|
score : score,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -1240,18 +1246,74 @@ class Taoyao {
|
|||||||
roomId,
|
roomId,
|
||||||
consumerId,
|
consumerId,
|
||||||
spatialLayer,
|
spatialLayer,
|
||||||
temporalLayer
|
temporalLayer,
|
||||||
} = body;
|
} = body;
|
||||||
const room = me.rooms.get(roomId);
|
const room = me.rooms.get(roomId);
|
||||||
const consumer = room?.consumers.get(consumerId);
|
const consumer = room?.consumers.get(consumerId);
|
||||||
if(consumer) {
|
if(consumer) {
|
||||||
console.debug("修改最佳空间层和时间层", consumerId);
|
console.debug("修改最佳空间层和时间层", consumerId);
|
||||||
await consumer.setPreferredLayers({ spatialLayer, temporalLayer });
|
await consumer.setPreferredLayers({
|
||||||
|
spatialLayer,
|
||||||
|
temporalLayer
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
console.debug("修改最佳空间层和时间层(无效)", consumerId);
|
console.debug("修改最佳空间层和时间层(无效)", consumerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置消费者优先级信令
|
||||||
|
*
|
||||||
|
* @param {*} message 信令消息
|
||||||
|
* @param {*} body 消息主体
|
||||||
|
*/
|
||||||
|
async mediaConsumerSetPriority(message, body) {
|
||||||
|
const me = this;
|
||||||
|
const {
|
||||||
|
roomId,
|
||||||
|
consumerId,
|
||||||
|
priority,
|
||||||
|
} = body;
|
||||||
|
const room = me.rooms.get(roomId);
|
||||||
|
const consumer = room?.consumers.get(consumerId);
|
||||||
|
if(consumer) {
|
||||||
|
console.debug("设置消费者优先级", consumerId, priority);
|
||||||
|
if(priority <= 0 || priority >= 256) {
|
||||||
|
await consumer.unsetPriority();
|
||||||
|
} else {
|
||||||
|
await consumer.setPriority(priority);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.debug("设置消费者优先级(无效)", consumerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询消费者状态信令
|
||||||
|
*
|
||||||
|
* @param {*} message 信令消息
|
||||||
|
* @param {*} body 消息主体
|
||||||
|
*/
|
||||||
|
async mediaConsumerStatus(message, body) {
|
||||||
|
const me = this;
|
||||||
|
const {
|
||||||
|
roomId,
|
||||||
|
consumerId,
|
||||||
|
} = body;
|
||||||
|
const room = me.rooms.get(roomId);
|
||||||
|
const consumer = room?.consumers.get(consumerId);
|
||||||
|
if(consumer) {
|
||||||
|
console.debug("查询消费者状态", consumerId);
|
||||||
|
message.body = {
|
||||||
|
...body,
|
||||||
|
status: await consumer.getStats()
|
||||||
|
};
|
||||||
|
me.push(message);
|
||||||
|
} else {
|
||||||
|
console.debug("查询消费者状态(无效)", consumerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消费数据信令
|
* 消费数据信令
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -822,6 +822,9 @@ class Taoyao extends RemoteClient {
|
|||||||
case "media::consumer::resume":
|
case "media::consumer::resume":
|
||||||
me.defaultMediaConsumerResume(message);
|
me.defaultMediaConsumerResume(message);
|
||||||
break;
|
break;
|
||||||
|
case "media::consumer::score":
|
||||||
|
me.defaultMediaConsumerScore(message);
|
||||||
|
break;
|
||||||
case "media::data::consumer::close":
|
case "media::data::consumer::close":
|
||||||
me.defaultMediaDataConsumerClose(message);
|
me.defaultMediaDataConsumerClose(message);
|
||||||
break;
|
break;
|
||||||
@@ -1558,6 +1561,16 @@ class Taoyao extends RemoteClient {
|
|||||||
console.debug("恢复消费者无效", consumerId);
|
console.debug("恢复消费者无效", consumerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 媒体消费者评分信令
|
||||||
|
*
|
||||||
|
* @param {*} message 信令消息
|
||||||
|
*/
|
||||||
|
defaultMediaConsumerScore(message) {
|
||||||
|
console.debug("消费者评分", message);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改最佳空间层和时间层信令
|
* 修改最佳空间层和时间层信令
|
||||||
*
|
*
|
||||||
@@ -1584,6 +1597,26 @@ class Taoyao extends RemoteClient {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置消费者优先级信令
|
||||||
|
*
|
||||||
|
* @param {*} consumerId 消费者ID
|
||||||
|
* @param {*} priority 优先级:1~255
|
||||||
|
*/
|
||||||
|
mediaConsumerSetPriority(consumerId, priority) {
|
||||||
|
const me = this;
|
||||||
|
const consumer = me.consumers.get(consumerId);
|
||||||
|
if(!consumer) {
|
||||||
|
me.callbackError("设置消费者优先级消费者无效");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
me.push(protocol.buildMessage("media::consumer::set::priority", {
|
||||||
|
roomId: me.roomId,
|
||||||
|
consumerId,
|
||||||
|
priority,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询消费者状态信令
|
* 查询消费者状态信令
|
||||||
*
|
*
|
||||||
@@ -3263,6 +3296,32 @@ class Taoyao extends RemoteClient {
|
|||||||
await track.applyConstraints(Object.assign(track.getSettings(), setting));
|
await track.applyConstraints(Object.assign(track.getSettings(), setting));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计设备信息
|
||||||
|
*
|
||||||
|
* @param {*} clientId 终端ID
|
||||||
|
*
|
||||||
|
* @returns 设备信息统计
|
||||||
|
*/
|
||||||
|
async getClientStats(clientId) {
|
||||||
|
const me = this;
|
||||||
|
const stats = {};
|
||||||
|
if(clientId === me.clientId) {
|
||||||
|
stats.sendTransport = await me.sendTransport.getStats();
|
||||||
|
stats.recvTransport = await me.recvTransport.getStats();
|
||||||
|
stats.audioProducer = await me.audioProducer.getStats();
|
||||||
|
stats.videoProducer = await me.videoProducer.getStats();
|
||||||
|
} else {
|
||||||
|
const consumers = Array.from(me.consumers.values());
|
||||||
|
for(const consumer of consumers) {
|
||||||
|
if(clientId === consumer.sourceId) {
|
||||||
|
stats[consumer.kind] = await consumer.getStats();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭媒体资源
|
* 关闭媒体资源
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -19,9 +19,13 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
|||||||
@Description(
|
@Description(
|
||||||
body = """
|
body = """
|
||||||
{
|
{
|
||||||
"score": "消费者RTP流得分表示传输质量:0~10",
|
"roomId" : "房间ID"
|
||||||
"producerScore": "生产者RTP流得分表示传输质量:0~10",
|
"consumerId": "消费者ID"
|
||||||
"producerScores": [所有生产者RTP流得分]
|
"score" : {
|
||||||
|
"score" : 消费者RTP流得分表示传输质量:0~10,
|
||||||
|
"producerScore" : 生产者RTP流得分表示传输质量:0~10,
|
||||||
|
"producerScores": [Simulcast生产者RTP流得分]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
""",
|
""",
|
||||||
flow = "媒体服务->信令服务->终端"
|
flow = "媒体服务->信令服务->终端"
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import com.acgist.taoyao.boot.annotation.Description;
|
import com.acgist.taoyao.boot.annotation.Description;
|
||||||
import com.acgist.taoyao.boot.annotation.Protocol;
|
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.model.Message;
|
||||||
import com.acgist.taoyao.signal.client.Client;
|
import com.acgist.taoyao.signal.client.Client;
|
||||||
import com.acgist.taoyao.signal.client.ClientType;
|
import com.acgist.taoyao.signal.client.ClientType;
|
||||||
@@ -14,12 +13,12 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
|||||||
/**
|
/**
|
||||||
* 修改最佳空间层和时间层信令
|
* 修改最佳空间层和时间层信令
|
||||||
*
|
*
|
||||||
* 空间层(spatialLayer):分辨率
|
* 空间层(spatialLayer) :分辨率
|
||||||
* 时间层(temporalLayer):帧率
|
* 时间层(temporalLayer):帧率
|
||||||
*
|
*
|
||||||
* 码率:数据大小和时间的比值
|
* 码率:数据大小和时间的比值
|
||||||
*
|
*
|
||||||
* 注意:只有simulcast和SVC消费者有效
|
* 注意:只有Simulcast和SVC消费者有效
|
||||||
*
|
*
|
||||||
* @author acgist
|
* @author acgist
|
||||||
*/
|
*/
|
||||||
@@ -27,13 +26,13 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
|||||||
@Description(
|
@Description(
|
||||||
body = """
|
body = """
|
||||||
{
|
{
|
||||||
"roomId": "房间ID",
|
"roomId" : "房间ID",
|
||||||
"consumerId": "消费者ID",
|
"consumerId" : "消费者ID",
|
||||||
"spatialLayer": 最佳空间层,
|
"spatialLayer" : 最佳空间层,
|
||||||
"temporalLayer": 最佳时间层
|
"temporalLayer": 最佳时间层
|
||||||
}
|
}
|
||||||
""",
|
""",
|
||||||
flow = "终端->信令服务->媒体服务->信令服务->终端"
|
flow = "终端->信令服务->媒体服务"
|
||||||
)
|
)
|
||||||
public class MediaConsumerSetPreferredLayersProtocol extends ProtocolRoomAdapter {
|
public class MediaConsumerSetPreferredLayersProtocol extends ProtocolRoomAdapter {
|
||||||
|
|
||||||
@@ -46,7 +45,6 @@ public class MediaConsumerSetPreferredLayersProtocol extends ProtocolRoomAdapter
|
|||||||
@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.mediaClient()) {
|
if(clientType.mediaClient()) {
|
||||||
body.put(Constant.CLIENT_ID, clientId);
|
|
||||||
mediaClient.push(message);
|
mediaClient.push(message);
|
||||||
} else {
|
} else {
|
||||||
this.logNoAdapter(clientType);
|
this.logNoAdapter(clientType);
|
||||||
|
|||||||
@@ -13,17 +13,15 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
|||||||
/**
|
/**
|
||||||
* 设置消费者优先级信令
|
* 设置消费者优先级信令
|
||||||
*
|
*
|
||||||
* TODO:unsetPriority
|
|
||||||
*
|
|
||||||
* @author acgist
|
* @author acgist
|
||||||
*/
|
*/
|
||||||
@Protocol
|
@Protocol
|
||||||
@Description(
|
@Description(
|
||||||
body = """
|
body = """
|
||||||
{
|
{
|
||||||
"roomId": "房间ID",
|
"roomId" : "房间ID",
|
||||||
"consumerId": "消费者ID",
|
"consumerId": "消费者ID",
|
||||||
"priority": 优先级(1~255)
|
"priority" : 优先级(1~255)
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
@@ -38,7 +36,7 @@ public class MediaConsumerSetPriorityProtocol extends ProtocolRoomAdapter {
|
|||||||
@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.mediaClient()) {
|
if(clientType.mediaClient()) {
|
||||||
client.push(mediaClient.request(message));
|
mediaClient.push(message);
|
||||||
} else {
|
} else {
|
||||||
this.logNoAdapter(clientType);
|
this.logNoAdapter(clientType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ import com.acgist.taoyao.signal.protocol.ProtocolRoomAdapter;
|
|||||||
@Description(
|
@Description(
|
||||||
body = """
|
body = """
|
||||||
{
|
{
|
||||||
"roomId": "房间ID",
|
"roomId" : "房间ID",
|
||||||
"consumerId": "消费者ID"
|
"consumerId": "消费者ID"
|
||||||
}
|
}
|
||||||
""",
|
""",
|
||||||
flow = "终端=>信令服务->媒体服务->信令服务->终端"
|
flow = "终端=>信令服务->媒体服务"
|
||||||
)
|
)
|
||||||
public class MediaConsumerStatusProtocol extends ProtocolRoomAdapter {
|
public class MediaConsumerStatusProtocol extends ProtocolRoomAdapter {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user