diff --git a/src/main/java/com/sonic/agent/tests/android/InputSocketThread.java b/src/main/java/com/sonic/agent/tests/android/InputSocketThread.java index 140e29e3..4cde3f9e 100644 --- a/src/main/java/com/sonic/agent/tests/android/InputSocketThread.java +++ b/src/main/java/com/sonic/agent/tests/android/InputSocketThread.java @@ -12,6 +12,7 @@ import java.io.InputStream; import java.net.Socket; import java.util.Queue; +import java.util.concurrent.BlockingQueue; import static com.sonic.agent.tools.AgentTool.subByteArray; @@ -33,7 +34,7 @@ public class InputSocketThread extends Thread { private IDevice iDevice; - private Queue dataQueue; + private BlockingQueue dataQueue; private SonicLocalThread miniCapPro; @@ -41,7 +42,7 @@ public class InputSocketThread extends Thread { private Session session; - public InputSocketThread(IDevice iDevice, Queue dataQueue, SonicLocalThread miniCapPro, Session session) { + public InputSocketThread(IDevice iDevice, BlockingQueue dataQueue, SonicLocalThread miniCapPro, Session session) { this.iDevice = iDevice; this.dataQueue = dataQueue; this.miniCapPro = miniCapPro; @@ -57,7 +58,7 @@ public IDevice getiDevice() { return iDevice; } - public Queue getDataQueue() { + public BlockingQueue getDataQueue() { return dataQueue; } diff --git a/src/main/java/com/sonic/agent/tests/android/OutputSocketThread.java b/src/main/java/com/sonic/agent/tests/android/OutputSocketThread.java index 1a45ee82..c0016c1e 100644 --- a/src/main/java/com/sonic/agent/tests/android/OutputSocketThread.java +++ b/src/main/java/com/sonic/agent/tests/android/OutputSocketThread.java @@ -8,6 +8,7 @@ import java.util.Arrays; import java.util.List; import java.util.Queue; +import java.util.concurrent.BlockingQueue; import java.util.concurrent.atomic.AtomicReference; import static com.sonic.agent.tools.AgentTool.*; @@ -73,12 +74,15 @@ public void run() { byte[] frameBody = new byte[0]; byte[] oldBytes = new byte[0]; int count = 0; + BlockingQueue dataQueue = sendImg.getDataQueue(); while (sendImg.isAlive()) { - Queue dataQueue = sendImg.getDataQueue(); - if (dataQueue.isEmpty()) { - continue; + byte[] buffer = new byte[0]; + try { + buffer = dataQueue.take(); + } catch (InterruptedException e) { + log.error("获取数据流失败:{}", e.getMessage()); + e.printStackTrace(); } - byte[] buffer = dataQueue.poll(); int len = buffer.length; for (int cursor = 0; cursor < len; ) { int byte10 = buffer[cursor] & 0xff;