我有以下问题。我为自己修改了这个示例:
Webcam Capture Live Streaming Example
此时,通信看起来像是client1将映像发送到服务器,而来自服务器的映像则发送到client2。如果我只使用一个摄像头,就没有问题。如果我从两个不同的摄像头播放流媒体,就会出现问题。我希望client1将映像发送到特定端口上的服务器,并且只有在该端口上,服务器才会将映像发送到客户端。2目前(我不知道为什么)服务器得到的是什么,例如,在端口2000上,它发送到所有端口,而不仅仅是端口2000。你能帮帮我吗?
来自服务器的一些代码:
@Override
public void start(SocketAddress streamAddress) {
logger.info("server started:{}", streamAddress);
Channel channel = serverBootstrap.bind(streamAddress);
channelGroup.add(channel);
}
。
this.serverBootstrap = new ServerBootstrap();
this.serverBootstrap.setFactory(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
this.serverBootstrap.setPipelineFactory(new StreamServerChannelPipelineFactory(new StreamServerListenerIMPL(), streamFrameListener));
。
public static void send(BufferedImage image) throws Exception {
Object msg = h264StreamEncoder.encode(image);
channelGroup.write(msg);
}
来自客户端1的代码:
public static void init(String host, int port) {
Webcam webcam = Webcam.getWebcams().get(0);
Dimension sizeVideo = WebcamResolution.QVGA.getSize();
webcam.setViewSize(sizeVideo);
StreamAtmAgent atmAgent = new StreamAtmAgent(webcam, sizeVideo);
atmAgent.connect(new InetSocketAddress(host, port));
}
。
来自客户端2的代码:
public static void init(String host, int port, ImageListener il) {
displayWindow.setVisible(true);
logger.info("Ustawione wymiary :{}", dimension);
StreamClientAgent clientAgent = new StreamClientAgent(il, dimension);
clientAgent.connect(new InetSocketAddress(host, port));
}
你能帮帮我吗?如果您需要更多代码,请告诉我。
P、 当我在start server中执行类似操作时:
init("localhost",2000)
init("localhost",2001)
我用端口2000将client1连接到服务器,并将client2连接到端口2001。我仍然看到2000端口的图像。