From 09561786f090ff38978e323394b6bbd6bdb4ccf7 Mon Sep 17 00:00:00 2001 From: JayWenStar <1599603313@qq.com> Date: Sun, 16 Jan 2022 02:07:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=BA:=20=E4=BC=98=E5=8C=96=E8=BF=9C?= =?UTF-8?q?=E6=8E=A7=E6=97=B6CPU=E5=8D=A0=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sonic/agent/tests/android/InputSocketThread.java | 7 ++++--- .../agent/tests/android/OutputSocketThread.java | 12 ++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) 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;