[*] 日常优化

This commit is contained in:
acgist
2023-10-04 21:03:23 +08:00
parent 809a938867
commit 4abb437c01
4 changed files with 84 additions and 61 deletions

View File

@@ -921,17 +921,15 @@ class Taoyao {
});
consumer.observer.on("resume", () => {
console.debug("消费者恢复", consumer.id, streamId);
me.push(
protocol.buildMessage("media::consumer::resume", {
me.push(protocol.buildMessage("media::consumer::resume", {
roomId,
consumerId: consumer.id
})
);
}));
});
// await consumer.enableTraceEvent([ 'pli', 'fir', 'rtp', 'nack', 'keyframe' ]);
// consumer.observer.on("trace", fn(trace));
// consumer.on("trace", (trace) => {
// console.info("消费者跟踪事件trace", consumer.id, streamId, trace);
// console.debug("消费者跟踪事件trace", consumer.id, streamId, trace);
// });
// 等待终端准备就绪可以不用等待直接使用push方法
await me.request(protocol.buildMessage("media::consume", {
@@ -1021,21 +1019,23 @@ class Taoyao {
/**
* 恢复消费者信令
*
* @param {*} message 消息
* @param {*} message 信令消息
* @param {*} body 消息主体
*/
async mediaConsumerResume(message, body) {
const me = this;
const { roomId, consumerId } = body;
const room = me.rooms.get(roomId);
const {
roomId,
consumerId
} = body;
const room = this.rooms.get(roomId);
const consumer = room?.consumers.get(consumerId);
if(consumer) {
if(!consumer) {
console.warn("恢复消费者(消费者无效)", consumerId);
return;
}
consumer.localPaused = false;
console.debug("恢复消费者", consumerId);
await consumer.resume();
} else {
console.debug("恢复消费者(无效)", consumerId);
}
}
/**

View File

@@ -1600,48 +1600,6 @@ class Taoyao extends RemoteClient {
}));
}
/**
* 恢复消费者信令
*
* @param {*} consumerId 消费者ID
*/
mediaConsumerResume(consumerId) {
const me = this;
const consumer = me.consumers.get(consumerId);
if(consumer) {
if(!consumer.paused) {
return;
}
console.debug("恢复消费者", consumerId);
me.push(protocol.buildMessage("media::consumer::resume", {
roomId : me.roomId,
consumerId: consumerId,
}));
} else {
console.debug("恢复消费者无效", consumerId);
}
}
/**
* 恢复消费者信令
*
* @param {*} message 信令消息
*/
defaultMediaConsumerResume(message) {
const me = this;
const {
roomId,
consumerId
} = message.body;
const consumer = me.consumers.get(consumerId);
if (consumer) {
console.debug("恢复消费者", consumerId);
consumer.resume();
} else {
console.debug("恢复消费者无效", consumerId);
}
}
/**
* 消费媒体信令
*
@@ -1748,6 +1706,50 @@ class Taoyao extends RemoteClient {
}
}
/**
* 恢复消费者信令
*
* @param {*} consumerId 消费者ID
*/
mediaConsumerResume(consumerId) {
const consumer = this.consumers.get(consumerId);
if(!consumer) {
console.debug("恢复消费者(消费者无效)", consumerId);
return;
}
if(!consumer.paused) {
console.debug("恢复消费者(消费者已经恢复)", consumerId);
return;
}
console.debug("恢复消费者", consumerId);
this.push(protocol.buildMessage("media::consumer::resume", {
consumerId,
roomId: this.roomId,
}));
}
/**
* 恢复消费者信令
*
* @param {*} message 信令消息
*/
defaultMediaConsumerResume(message) {
const {
consumerId
} = message.body;
const consumer = this.consumers.get(consumerId);
if (!consumer) {
console.debug("恢复消费者(消费者无效)", consumerId);
return;
}
if(!consumer.paused) {
console.debug("恢复消费者(消费者已经恢复)", consumerId);
return;
}
console.debug("恢复消费者", consumerId);
consumer.resume();
}
/**
* 媒体消费者评分信令
*

View File

@@ -30,6 +30,24 @@ import lombok.extern.slf4j.Slf4j;
* VP8 = 101
* H264 = 107
*
* 注意:媒体格式和录制格式一致可以直接使用`copy`代替格式参数减小`CPU`占用
*
* OPUS/VP8->AAC/H264(TS)
* ffmpeg -y -protocol_whitelist "file,rtp,udp" -thread_queue_size 1024 -c:a libopus -c:v libvpx -r:v 30 -i taoyao.sdp -c:a aac -c:v h264 -f mpegts taoyao.ts
* ffmpeg -y -protocol_whitelist "file,rtp,udp" -thread_queue_size 1024 -c:a libopus -c:v libvpx -r:v 30 -i taoyao.sdp -c:a aac -c:v h264 -f mpegts taoyao.ts
*
* OPUS/VP8->AAC/H264(MP4)
* ffmpeg -y -protocol_whitelist "file,rtp,udp" -thread_queue_size 1024 -c:a libopus -c:v libvpx -r:v 30 -i taoyao.sdp -c:a aac -c:v h264 taoyao.mp4
* ffmpeg -y -protocol_whitelist "file,rtp,udp" -thread_queue_size 1024 -c:a libopus -c:v libvpx -r:v 30 -i taoyao.sdp -c:a aac -c:v h264 taoyao.mp4
*
* PCMU/H264->AAC/H264(TS)
* ffmpeg -y -protocol_whitelist "file,rtp,udp" -thread_queue_size 1024 -i taoyao.sdp -c:a aac -c:v h264 -f mpegts taoyao.ts
* ffmpeg -y -protocol_whitelist "file,rtp,udp" -thread_queue_size 1024 -i taoyao.sdp -c:a aac -c:v h264 -f mpegts taoyao.ts
*
* PCMU/H264->AAC/H264(MP4)
* ffmpeg -y -protocol_whitelist "file,rtp,udp" -thread_queue_size 1024 -i taoyao.sdp -c:a aac -c:v copy taoyao.mp4
* ffmpeg -y -protocol_whitelist "file,rtp,udp" -thread_queue_size 1024 -i taoyao.sdp -c:a aac -c:v copy taoyao.mp4
*
* @author acgist
*/
@Slf4j

View File

@@ -33,7 +33,10 @@ import lombok.extern.slf4j.Slf4j;
"consumerId": "消费者ID"
}
""",
flow = "终端->信令服务->媒体服务->信令服务->终端"
flow = {
"终端->信令服务->媒体服务->信令服务->终端",
"终端-[恢复生产者]>信令服务->媒体服务-[恢复消费者]>信令服务->终端"
}
)
public class MediaConsumerResumeProtocol extends ProtocolRoomAdapter implements ApplicationListener<MediaConsumerResumeEvent> {