提交 ce8bc5ee 编写于 作者: 云逸之's avatar 云逸之 💬

修改启动的主类

上级 d14b4da5
package org.btik.server.util;
import java.io.IOException;
/**
* @author lustre
* @version 1.0
......
......@@ -5,7 +5,6 @@ import org.btik.server.util.ByteUtil;
import org.btik.server.util.NamePrefixThreadFactory;
import org.btik.server.video.device.iface.DevChannel;
import org.btik.server.video.device.iface.VideoChannel;
import org.btik.server.video.device.task.AsyncTaskExecutor;
import java.io.IOException;
......
......@@ -28,8 +28,6 @@ public class MJPEGVideoChannel implements VideoChannel, HttpConstant {
private final Set<Socket> clients = Collections.newSetFromMap(new ConcurrentHashMap<>());
private final byte[] clientLock = new byte[0];
public MJPEGVideoChannel(String channelId, AsyncTaskExecutor asyncTaskExecutor) {
this.asyncTaskExecutor = asyncTaskExecutor;
this.channelId = channelId;
......@@ -40,23 +38,21 @@ public class MJPEGVideoChannel implements VideoChannel, HttpConstant {
public void sendFrame(byte[] frame, int len) {
byte[] lenStrBytes = ByteUtil.toString(len);
byte[] lenHexStrBytes = ByteUtil.toHexString(len);
synchronized (clientLock) {
for (Socket client : clients) {
try {
OutputStream outputStream = client.getOutputStream();
sendChunk(_STREAM_BOUNDARY, outputStream);
sendChunk(outputStream, _STREAM_PART, lenStrBytes, DOUBLE_LINE);
sendChunk(frame, len, lenHexStrBytes, outputStream);
outputStream.flush();
} catch (IOException e) {
checkState(client, e);
}
for (Socket client : clients) {
try {
OutputStream outputStream = client.getOutputStream();
sendChunk(_STREAM_BOUNDARY, outputStream);
sendChunk(outputStream, _STREAM_PART, lenStrBytes, DOUBLE_LINE);
sendChunk(frame, len, lenHexStrBytes, outputStream);
outputStream.flush();
} catch (IOException e) {
checkState(client, e);
}
}
}
static long l = System.currentTimeMillis();
}
@Override
public void sendFrame(byte[][] frame, int[] len, int segmentCount) {
......@@ -65,20 +61,20 @@ public class MJPEGVideoChannel implements VideoChannel, HttpConstant {
allLen += len[i];
}
byte[] lenStrBytes = ByteUtil.toString(allLen);
synchronized (clientLock) {
for (Socket client : clients) {
try {
OutputStream outputStream = client.getOutputStream();
sendChunk(_STREAM_BOUNDARY, outputStream);
sendChunk(outputStream, _STREAM_PART, lenStrBytes, DOUBLE_LINE);
sendChunk(outputStream, allLen, len, frame);
outputStream.flush();
} catch (IOException e) {
checkState(client, e);
}
for (Socket client : clients) {
try {
OutputStream outputStream = client.getOutputStream();
sendChunk(_STREAM_BOUNDARY, outputStream);
sendChunk(outputStream, _STREAM_PART, lenStrBytes, DOUBLE_LINE);
sendChunk(outputStream, allLen, len, frame);
outputStream.flush();
} catch (IOException e) {
checkState(client, e);
}
}
}
/**
......@@ -151,6 +147,7 @@ public class MJPEGVideoChannel implements VideoChannel, HttpConstant {
try {
System.err.println("close:" + socket.getRemoteSocketAddress());
socket.close();
clients.remove(socket);
} catch (IOException e0) {
System.err.println(e.getMessage());
}
......
.\jre\bin\java -classpath SimpleVideoServer org.btik.server.video.UDPMain
\ No newline at end of file
.\jre\bin\java -classpath SimpleVideoServer org.btik.server.video.UDP2Main
\ No newline at end of file
./jre/bin/java -classpath SimpleVideoServer org.btik.server.video.UDPMain
\ No newline at end of file
./jre/bin/java -classpath SimpleVideoServer org.btik.server.video.UDP2Main
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册