android设备直播白屏的问题
parent
9d528d2229
commit
112ba61d92
|
@ -144,27 +144,12 @@ public class AndroidScreenResponseThread extends ImageScreenResponse {
|
|||
logger.warn("设备【{}】响应到上位机的屏幕线程退出..........................", adbDevice.getSerial());
|
||||
}
|
||||
|
||||
// public void sendConnectInfo2Web() {
|
||||
// //新连接需要先发送状态
|
||||
// if (null != screenOnRequest) { //只发第一次screen_on指令
|
||||
// //向前端推送之前缓存的最新帧
|
||||
// if (null != adbDevice) {
|
||||
// if (null != lastData && lastData.length > 0) {
|
||||
// SessionUtils.sendBinary(wsSession, lastData);
|
||||
// logger.debug("上位机发送缓存帧成功,大小:{}", lastData.length);
|
||||
// Map<String, Object> result = new HashMap<>();
|
||||
// result.put(ResponseCmd.DeviceStatus.STATUS, ResponseCmd.DeviceStatus.CONNECTED);
|
||||
// SessionUtils.sendMessageInitiative(wsSession, ResponseCmd.DEVICE_STATUS, adbDevice.getSerial(), result, "设备连接失败");
|
||||
// sendDeviceStatus = false;
|
||||
// } else {
|
||||
// logger.warn("设备【{}】缓存帧获取为空...", adbDevice.getSerial());
|
||||
// }
|
||||
// }
|
||||
// //向前端推送之前缓存的最新帧后发screenOn回复
|
||||
// SessionUtils.sendSuccessData(wsSession, screenOnRequest, null, "开启屏幕成功");
|
||||
// setScreenOnRequest(null);
|
||||
// }
|
||||
// }
|
||||
@Override
|
||||
public void changeScreenSize() {
|
||||
logger.info("改变设备【{}】屏幕的宽高..........................", adbDevice.getSerial());
|
||||
ScreenStreamCommand screenStreamCommand = new ScreenStreamCommand(true, catchParam.getRotation(), catchParam.getWidth(), catchParam.getHeight(), catchParam.getFrameRate(), catchParam.getQuality());
|
||||
this.asyncAgentSession.send(screenStreamCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopFetchPic() {
|
||||
|
|
|
@ -9,6 +9,9 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.websocket.Session;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -71,26 +74,44 @@ public abstract class ImageScreenResponse extends Thread{
|
|||
}
|
||||
|
||||
public void startSendScreenToWeb(Session session, CatchParam catchParam) {
|
||||
this.catchParam = catchParam;
|
||||
logger.info("设备【{}】当前连接了{}个web客户端...............",deviceId,this.webSessions.size());
|
||||
if (this.webSessions.size() > 3) {
|
||||
if (this.webSessions.size() > 1) {
|
||||
//通知前端断开连接,最多只能连接三个
|
||||
Map<String, Object> messageMap = new HashMap<>();
|
||||
messageMap.put(ResponseCmd.DeviceStatus.STATUS, ResponseCmd.DeviceStatus.DISCONNECT);
|
||||
SessionUtils.sendMessageInitiative(session, ResponseCmd.DEVICE_STATUS, deviceId, messageMap, "最多支持三个客户端同时浏览手机");
|
||||
SessionUtils.sendMessageInitiative(session, ResponseCmd.DEVICE_STATUS, deviceId, messageMap, "最多支持一个客户端观察直播");
|
||||
return;
|
||||
}
|
||||
this.catchParam = catchParam;
|
||||
this.webSessions.add(session);
|
||||
//先发一个改变屏幕宽高的指令过去
|
||||
changeScreenSize();
|
||||
//通知前端开始连接
|
||||
Map<String, Object> messageMap = new HashMap<>();
|
||||
messageMap.put(ResponseCmd.DeviceStatus.STATUS, ResponseCmd.DeviceStatus.CONNECTING);
|
||||
SessionUtils.sendMessageInitiative(session, ResponseCmd.DEVICE_STATUS, deviceId, messageMap, "设备掉线了");
|
||||
logger.info("发送设备【{}】最后一张图片到前端..............",deviceId);
|
||||
if (null != this.lastData) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(ResponseCmd.DeviceStatus.STATUS, ResponseCmd.DeviceStatus.CONNECTED);
|
||||
SessionUtils.sendMessageInitiative(session, ResponseCmd.DEVICE_STATUS, deviceId, result, "设备已连接");
|
||||
SessionUtils.sendBinary(session, this.lastData);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
logger.info("开始压缩设备【{}】最后一张图片到前端,宽:{},高:{}..............",deviceId,catchParam.getWidth(),catchParam.getHeight());
|
||||
Thumbnails.of(new ByteArrayInputStream(this.lastData)).forceSize(catchParam.getWidth(), catchParam.getHeight()).toOutputStream(outputStream);
|
||||
logger.info("压缩完毕设备【{}】最后一张图片到前端..............",deviceId);
|
||||
byte[] data = outputStream.toByteArray();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put(ResponseCmd.DeviceStatus.STATUS, ResponseCmd.DeviceStatus.CONNECTED);
|
||||
SessionUtils.sendMessageInitiative(session, ResponseCmd.DEVICE_STATUS, deviceId, result, "设备已连接");
|
||||
SessionUtils.sendBinary(session, data);
|
||||
} catch (Exception e) {
|
||||
logger.info("设备【{}】在编码第一张图片的时候出现了错误,等一下张图片再发..............",deviceId,e);
|
||||
this.sendDeviceStatus = true;
|
||||
}finally {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.info("发送设备【{}】最后一张图片是空,获取到了再发..............",deviceId);
|
||||
this.sendDeviceStatus = true;
|
||||
|
@ -98,6 +119,8 @@ public abstract class ImageScreenResponse extends Thread{
|
|||
|
||||
}
|
||||
|
||||
public abstract void changeScreenSize();
|
||||
|
||||
public void setSendDeviceStatus(boolean sendDeviceStatus) {
|
||||
this.sendDeviceStatus = sendDeviceStatus;
|
||||
}
|
||||
|
|
|
@ -291,5 +291,10 @@ public class IosScreenResponseThread extends ImageScreenResponse {
|
|||
interrupt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeScreenSize() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -829,7 +829,7 @@ public class AndroidDebuggerServiceImpl extends AbstractDebuggerService {
|
|||
catchParam.setRealHeight(screenSizeMap.get("height"));
|
||||
catchParam.setRealWidth(screenSizeMap.get("width"));
|
||||
catchParam.setWidth(screenSizeMap.get("width")/2);
|
||||
catchParam.setHeight(screenSizeMap.get("width")/2);
|
||||
catchParam.setHeight(screenSizeMap.get("height")/2);
|
||||
catchParam.setFrameRate(30);
|
||||
catchParam.setQuality(75);
|
||||
catchParam.setRotation(screenSizeMap.get("rotation"));
|
||||
|
|
Loading…
Reference in New Issue