[*] 日常优化

This commit is contained in:
acgist
2023-07-24 08:11:48 +08:00
parent 16ff2e7f34
commit c0657770e8
9 changed files with 108 additions and 114 deletions

View File

@@ -2,7 +2,6 @@ package com.acgist.taoyao.signal.party.media;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import com.acgist.taoyao.signal.client.Client;
@@ -11,8 +10,7 @@ import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
/**
* 终端包装器Peer
* 视频房间使用
* 终端包装器
*
* @author acgist
*/
@@ -30,11 +28,11 @@ public class ClientWrapper implements AutoCloseable {
*/
private final Client client;
/**
* 房间标识
* 房间ID
*/
private final String roomId;
/**
* 终端标识
* 终端ID
*/
private final String clientId;
/**
@@ -52,7 +50,7 @@ public class ClientWrapper implements AutoCloseable {
*/
private Object sctpCapabilities;
/**
* 媒体录像
* 服务端媒体录像
*/
private Recorder recorder;
/**
@@ -65,7 +63,7 @@ public class ClientWrapper implements AutoCloseable {
private Transport recvTransport;
/**
* 生产者
* 其他终端消费当前终端的消费
* 其他终端消费当前终端的生产
*/
private final Map<String, Producer> producers;
/**
@@ -75,7 +73,7 @@ public class ClientWrapper implements AutoCloseable {
private final Map<String, Consumer> consumers;
/**
* 数据生产者
* 其他终端消费当前终端的消费
* 其他终端消费当前终端的生产
*/
private final Map<String, DataProducer> dataProducers;
/**
@@ -95,33 +93,26 @@ public class ClientWrapper implements AutoCloseable {
this.dataConsumers = new ConcurrentHashMap<>();
}
/**
* @return 生产者数量
*/
public Integer producerSize() {
return this.producers.size();
}
/**
* @return 消费者数量
*/
public Integer consumerSize() {
return this.producers.values().stream()
.map(producer -> producer.getConsumers().size())
.collect(Collectors.counting())
.intValue();
}
/**
* @param producer 生产者
*
* @return 是否已经消费
* @return 是否已经消费生产者
*/
public boolean consumed(Producer producer) {
return this.consumers.values().stream()
.anyMatch(v -> v.getProducer() == producer);
}
/**
* @param dataProducer 数据生产者
*
* @return 是否已经消费数据生产者
*/
public boolean consumedData(DataProducer dataProducer) {
return this.dataConsumers.values().stream()
.anyMatch(v -> v.getDataProducer() == dataProducer);
}
@Override
public void close() {
// 注意:不要关闭终端(只是离开房间)

View File

@@ -28,7 +28,7 @@ public class Consumer extends OperatorAdapter {
*/
private final String streamId;
/**
* 消费者标识
* 消费者ID
*/
private final String consumerId;
/**
@@ -72,19 +72,19 @@ public class Consumer extends OperatorAdapter {
@Override
public void pause() {
log.info("暂停消费者:{} - {}", this.streamId, this.consumerId);
log.debug("暂停消费者:{} - {}", this.streamId, this.consumerId);
EventPublisher.publishEvent(new MediaConsumerPauseEvent(this.consumerId, this.room));
}
@Override
public void resume() {
log.info("恢复消费者:{} - {}", this.streamId, this.consumerId);
log.debug("恢复消费者:{} - {}", this.streamId, this.consumerId);
EventPublisher.publishEvent(new MediaConsumerResumeEvent(this.consumerId, this.room));
}
@Override
public void log() {
log.debug("当前消费者:{} - {} - {}", this.consumerId, this.kind, this.streamId);
log.info("当前消费者:{} - {} - {}", this.streamId, this.consumerId, this.kind);
}
}

View File

@@ -22,7 +22,7 @@ public class DataConsumer extends OperatorAdapter {
*/
private final String streamId;
/**
* 消费者标识
* 消费者ID
*/
private final String consumerId;
/**
@@ -65,7 +65,7 @@ public class DataConsumer extends OperatorAdapter {
@Override
public void log() {
log.debug("当前数据消费者:{} - {}", this.consumerId, this.streamId);
log.info("当前数据消费者:{} - {}", this.streamId, this.consumerId);
}
}

View File

@@ -25,7 +25,7 @@ public class DataProducer extends OperatorAdapter {
*/
private final String streamId;
/**
* 生产者标识
* 生产者ID
*/
private final String producerId;
/**
@@ -69,7 +69,7 @@ public class DataProducer extends OperatorAdapter {
@Override
public void log() {
log.debug("当前数据生产者:{} - {}", this.producerId, this.streamId);
log.info("当前数据生产者:{} - {}", this.streamId, this.producerId);
this.dataConsumers.values().forEach(DataConsumer::log);
}

View File

@@ -24,7 +24,8 @@ public enum Kind {
* @return 类型
*/
public static final Kind of(String value) {
for (Kind kind : Kind.values()) {
final Kind[] values = Kind.values();
for (Kind kind : values) {
if(kind.name().equalsIgnoreCase(value)) {
return kind;
}

View File

@@ -1,7 +1,7 @@
package com.acgist.taoyao.signal.party.media;
/**
* 关闭移除接口适配器
* 操作接口适配器
*
* @author acgist
*/

View File

@@ -31,7 +31,7 @@ public class Producer extends OperatorAdapter {
*/
private final String streamId;
/**
* 生产者标识
* 生产者ID
*/
private final String producerId;
/**
@@ -76,19 +76,19 @@ public class Producer extends OperatorAdapter {
@Override
public void pause() {
log.info("暂停生产者:{} - {}", this.streamId, this.producerId);
log.debug("暂停生产者:{} - {}", this.streamId, this.producerId);
EventPublisher.publishEvent(new MediaProducerPauseEvent(this.producerId, this.room));
}
@Override
public void resume() {
log.info("恢复生产者:{} - {}", this.streamId, this.producerId);
log.debug("恢复生产者:{} - {}", this.streamId, this.producerId);
EventPublisher.publishEvent(new MediaProducerResumeEvent(this.producerId, this.room));
}
@Override
public void log() {
log.info("当前生产者:{} - {} - {}", this.producerId, this.kind, this.streamId);
log.info("当前生产者:{} - {} - {}", this.streamId, this.producerId, this.kind);
this.consumers.values().forEach(Consumer::log);
}

View File

@@ -23,7 +23,7 @@ import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
/**
* 媒体录像机
* 服务端媒体录像机
*
* OPUS = 100
* VP8 = 101

View File

@@ -22,6 +22,8 @@ import lombok.extern.slf4j.Slf4j;
/**
* 消费数据信令
*
* TODO防止重复消费
*
* @author acgist
*/
@Slf4j