[*] 优化logger
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package com.acgist.taoyao.signal.listener;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.acgist.taoyao.signal.event.ApplicationEventAdapter;
|
||||
import com.acgist.taoyao.signal.media.MediaRouterManager;
|
||||
|
||||
/**
|
||||
* 媒体事件监听适配器
|
||||
@@ -14,7 +11,4 @@ import com.acgist.taoyao.signal.media.MediaRouterManager;
|
||||
*/
|
||||
public abstract class MediaListenerAdapter<E extends ApplicationEventAdapter> extends ApplicationListenerAdapter<E> {
|
||||
|
||||
@Autowired
|
||||
protected MediaRouterManager mediaRouterManager;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
package com.acgist.taoyao.signal.media;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.acgist.taoyao.boot.annotation.Manager;
|
||||
import com.acgist.taoyao.signal.media.processor.ProcessorChain;
|
||||
import com.acgist.taoyao.signal.media.router.MediaRouter;
|
||||
import com.acgist.taoyao.signal.media.router.MediaRouterHandler;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 媒体路由管理
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
@Manager
|
||||
public class MediaRouterManager {
|
||||
|
||||
/**
|
||||
* 路由集合
|
||||
* ID=路由器
|
||||
* ID=LiveId/MeetingId
|
||||
*/
|
||||
private Map<Long, MediaRouter> routers = new ConcurrentHashMap<>();
|
||||
|
||||
@Autowired(required = false)
|
||||
private ProcessorChain processorChain;
|
||||
|
||||
/**
|
||||
* 创建路由
|
||||
*
|
||||
* @param id ID
|
||||
*
|
||||
* @return 路由
|
||||
*/
|
||||
public MediaRouter build(Long id) {
|
||||
return this.routers.computeIfAbsent(id, key -> {
|
||||
final MediaRouter router = new MediaRouterHandler();
|
||||
router.build();
|
||||
router.processorChain(this.processorChain);
|
||||
log.debug("创建路由:{}-{}", id, router);
|
||||
return router;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id ID
|
||||
*
|
||||
* @return 路由
|
||||
*/
|
||||
public MediaRouter router(Long id) {
|
||||
return this.routers.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭路由
|
||||
*
|
||||
* @param id ID
|
||||
*/
|
||||
public void close(Long id) {
|
||||
final MediaRouter router = this.router(id);
|
||||
if(router == null) {
|
||||
return;
|
||||
}
|
||||
router.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.acgist.taoyao.signal.media.processor;
|
||||
|
||||
public class MediaMixProcessor {
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.acgist.taoyao.signal.media.processor;
|
||||
|
||||
/**
|
||||
* 媒体流处理器:混音、美颜等等
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public interface MediaProcessor {
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.acgist.taoyao.signal.media.processor;
|
||||
|
||||
/**
|
||||
* 媒体流处理器责任链
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public class ProcessorChain {
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.acgist.taoyao.signal.media.router;
|
||||
|
||||
import com.acgist.taoyao.signal.media.stream.MediaHandlerAdapter;
|
||||
|
||||
/**
|
||||
* 终端媒体发布者
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public class MediaPublisher extends MediaHandlerAdapter {
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package com.acgist.taoyao.signal.media.router;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.acgist.taoyao.signal.media.processor.ProcessorChain;
|
||||
import com.acgist.taoyao.signal.media.stream.MediaStream;
|
||||
|
||||
/**
|
||||
* 媒体流路由器
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public interface MediaRouter {
|
||||
|
||||
/**
|
||||
* 初始路由
|
||||
*/
|
||||
void build();
|
||||
|
||||
/**
|
||||
* @return 媒体发布者
|
||||
*/
|
||||
MediaPublisher publisher();
|
||||
|
||||
/**
|
||||
* @return 媒体订阅者
|
||||
*/
|
||||
MediaSubscriber subscriber();
|
||||
|
||||
/**
|
||||
* @param processorChain 媒体流处理器责任链
|
||||
*/
|
||||
void processorChain(ProcessorChain processorChain);
|
||||
|
||||
/**
|
||||
* @return 发布者媒体流
|
||||
*/
|
||||
List<MediaStream> streamPublisher();
|
||||
|
||||
/**
|
||||
* @param sns 订阅者终端标识
|
||||
*
|
||||
* @return 订阅者媒体流
|
||||
*/
|
||||
List<MediaStream> streamSubscriber(String ... sns);
|
||||
|
||||
/**
|
||||
* @param type 媒体类型
|
||||
*
|
||||
* @return 发布者媒体流
|
||||
*/
|
||||
List<MediaStream> streamPublisher(MediaStream.Type type);
|
||||
|
||||
/**
|
||||
* @param type 媒体类型
|
||||
* @param sns 订阅者终端标识
|
||||
*
|
||||
* @return 发布者媒体流
|
||||
*/
|
||||
List<MediaStream> streamSubscriber(MediaStream.Type type, String ... sns);
|
||||
|
||||
/**
|
||||
* 关闭路由
|
||||
*/
|
||||
void close();
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package com.acgist.taoyao.signal.media.router;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import com.acgist.taoyao.signal.media.processor.ProcessorChain;
|
||||
import com.acgist.taoyao.signal.media.stream.MediaStream;
|
||||
import com.acgist.taoyao.signal.media.stream.MediaStream.Type;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 媒体流路由器处理器
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
public class MediaRouterHandler implements MediaRouter {
|
||||
|
||||
/**
|
||||
* 媒体流处理器责任链
|
||||
*/
|
||||
private ProcessorChain processorChain;
|
||||
/**
|
||||
* 发布者
|
||||
*/
|
||||
private MediaPublisher mediaPublisher;
|
||||
/**
|
||||
* 订阅者
|
||||
*/
|
||||
private MediaSubscriber mediaSubscriber;
|
||||
|
||||
@Override
|
||||
public void build() {
|
||||
this.mediaPublisher = new MediaPublisher();
|
||||
this.mediaSubscriber = new MediaSubscriber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPublisher publisher() {
|
||||
return this.mediaPublisher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaSubscriber subscriber() {
|
||||
return this.mediaSubscriber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processorChain(ProcessorChain processorChain) {
|
||||
this.processorChain = processorChain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MediaStream> streamPublisher() {
|
||||
return this.mediaPublisher.getStreams();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MediaStream> streamSubscriber(String ... sns) {
|
||||
return this.mediaSubscriber.getStreams().stream()
|
||||
.filter(v -> ArrayUtils.contains(sns, v.subscriber()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MediaStream> streamPublisher(Type type) {
|
||||
return this.mediaPublisher.getStreams().stream()
|
||||
.filter(v -> v.type() == type)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MediaStream> streamSubscriber(Type type, String... sns) {
|
||||
return this.mediaSubscriber.getStreams().stream()
|
||||
.filter(v -> v.type() == type)
|
||||
.filter(v -> ArrayUtils.contains(sns, v.subscriber()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
this.mediaPublisher.close();
|
||||
} catch (IOException e) {
|
||||
log.error("关闭发布者异常", e);
|
||||
}
|
||||
try {
|
||||
this.mediaSubscriber.close();
|
||||
} catch (IOException e) {
|
||||
log.error("关闭订阅者异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.acgist.taoyao.signal.media.router;
|
||||
|
||||
import com.acgist.taoyao.signal.media.stream.MediaHandlerAdapter;
|
||||
|
||||
/**
|
||||
* 终端媒体订阅者
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public class MediaSubscriber extends MediaHandlerAdapter {
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package com.acgist.taoyao.signal.media.stream;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 终端媒体处理器
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public interface MediaHandler {
|
||||
|
||||
/**
|
||||
* 打开
|
||||
* 注意:用于打开媒体流
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
void open() throws IOException;
|
||||
|
||||
/**
|
||||
* 打开
|
||||
* 注意:用于管理媒体流
|
||||
*
|
||||
* @param stream 媒体流
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
void open(MediaStream stream) throws IOException;
|
||||
|
||||
/**
|
||||
* 暂停
|
||||
* 注意:暂停时发送心跳防止通道关闭
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
void pause() throws IOException;
|
||||
|
||||
/**
|
||||
* 恢复
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
void resume() throws IOException;
|
||||
|
||||
/**
|
||||
* 关闭
|
||||
*
|
||||
* @param id 终端媒体流ID
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
void close() throws IOException;
|
||||
|
||||
/**
|
||||
* 打开
|
||||
*
|
||||
* @param type 媒体类型
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
void open(MediaStream.Type type) throws IOException;
|
||||
|
||||
/**
|
||||
* 暂停
|
||||
* 注意:暂停时发送心跳防止通道关闭
|
||||
*
|
||||
* @param type 媒体类型
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
void pause(MediaStream.Type type) throws IOException;
|
||||
|
||||
/**
|
||||
* 恢复
|
||||
*
|
||||
* @param type 媒体类型
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
void resume(MediaStream.Type type) throws IOException;
|
||||
|
||||
/**
|
||||
* 关闭
|
||||
*
|
||||
* @param type 媒体类型
|
||||
*
|
||||
* @param id 终端媒体流ID
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
void close(MediaStream.Type type) throws IOException;
|
||||
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package com.acgist.taoyao.signal.media.stream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.acgist.taoyao.boot.model.MessageCodeException;
|
||||
import com.acgist.taoyao.signal.media.stream.MediaStream.Type;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 终端媒体处理器适配器
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
@Getter
|
||||
@Setter
|
||||
public class MediaHandlerAdapter implements MediaHandler {
|
||||
|
||||
/**
|
||||
* 媒体流集合
|
||||
*/
|
||||
protected List<MediaStream> streams = new CopyOnWriteArrayList<>();
|
||||
|
||||
@Override
|
||||
public void open() throws IOException {
|
||||
throw MessageCodeException.of("禁止使用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(MediaStream stream) throws IOException {
|
||||
log.debug("打开媒体流:{}", stream);
|
||||
this.streams.add(stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() throws IOException {
|
||||
this.streams.forEach(v -> {
|
||||
try {
|
||||
v.pause();
|
||||
} catch (IOException e) {
|
||||
log.error("暂停媒体流异常:{}", v, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() throws IOException {
|
||||
this.streams.forEach(v -> {
|
||||
try {
|
||||
v.resume();
|
||||
} catch (IOException e) {
|
||||
log.error("恢复媒体流异常:{}", v, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
this.streams.forEach(v -> {
|
||||
try {
|
||||
v.close();
|
||||
} catch (IOException e) {
|
||||
log.error("关闭媒体流异常:{}", v, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(Type type) throws IOException {
|
||||
throw MessageCodeException.of("禁止使用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause(Type type) throws IOException {
|
||||
this.streams.stream().filter(v -> v.type() == type).forEach(v -> {
|
||||
try {
|
||||
v.pause();
|
||||
} catch (IOException e) {
|
||||
log.error("暂停媒体流异常:{}", v, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume(Type type) throws IOException {
|
||||
this.streams.stream().filter(v -> v.type() == type).forEach(v -> {
|
||||
try {
|
||||
v.resume();
|
||||
} catch (IOException e) {
|
||||
log.error("恢复媒体流异常:{}", v, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(Type type) throws IOException {
|
||||
this.streams.stream().filter(v -> v.type() == type).forEach(v -> {
|
||||
try {
|
||||
v.close();
|
||||
} catch (IOException e) {
|
||||
log.error("关闭媒体流异常:{}", v, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package com.acgist.taoyao.signal.media.stream;
|
||||
|
||||
/**
|
||||
* 终端媒体流
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public interface MediaStream extends MediaHandler {
|
||||
|
||||
/**
|
||||
* 终端媒体类型
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public enum Type {
|
||||
|
||||
/**
|
||||
* 混合:音视频
|
||||
*/
|
||||
MIX,
|
||||
/**
|
||||
* 音频
|
||||
*/
|
||||
AUDIO,
|
||||
/**
|
||||
* 视频
|
||||
*/
|
||||
VIDEO;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 终端媒体流状态
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public enum Status {
|
||||
|
||||
/**
|
||||
* 没有激活
|
||||
*/
|
||||
IDLE,
|
||||
/**
|
||||
* 已经激活
|
||||
*/
|
||||
BUSY,
|
||||
/**
|
||||
* 已经暂停
|
||||
*/
|
||||
PAUSE,
|
||||
/**
|
||||
* 已经关闭
|
||||
*/
|
||||
CLOSE;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 终端媒体流ID
|
||||
*/
|
||||
String id();
|
||||
|
||||
/**
|
||||
* @return 终端媒体流类型
|
||||
*/
|
||||
Type type();
|
||||
|
||||
/**
|
||||
* @return 终端媒体流状态
|
||||
*/
|
||||
Status status();
|
||||
|
||||
/**
|
||||
* @return 发布者
|
||||
*/
|
||||
String publisher();
|
||||
|
||||
/**
|
||||
* @return 订阅者
|
||||
*/
|
||||
String subscriber();
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package com.acgist.taoyao.signal.media.stream;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.acgist.taoyao.boot.model.MessageCodeException;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* 终端媒体流适配器
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(of = {"id", "type", "status", "publisher", "subscriber"})
|
||||
public abstract class MediaStreamAdapter<T> implements MediaStream {
|
||||
|
||||
/**
|
||||
* 标识
|
||||
*/
|
||||
protected String id;
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
protected Type type;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
protected Status status;
|
||||
/**
|
||||
* 发布者
|
||||
*/
|
||||
private String publisher;
|
||||
/**
|
||||
* 订阅者
|
||||
*/
|
||||
private String subscriber;
|
||||
/**
|
||||
* 真实流
|
||||
*/
|
||||
protected T stream;
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status status() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String publisher() {
|
||||
return this.publisher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String subscriber() {
|
||||
return this.subscriber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(MediaStream stream) throws IOException {
|
||||
throw MessageCodeException.of("禁止套娃");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user